将主窗口中的组件改为悬浮模式,同时增加了一个黑色主题,想要使用的用户可以pip install qdarkstyle后再运行vn.trader

This commit is contained in:
chenxy123 2016-04-28 23:03:36 +08:00
parent 1fdddd2033
commit 55ea259af1
5 changed files with 64 additions and 38 deletions

View File

@ -3,5 +3,7 @@
"fontSize": 12,
"mongoHost": "localhost",
"mongoPort": 27017
"mongoPort": 27017,
"darkStyle": true
}

View File

@ -125,6 +125,7 @@ class BidCell(QtGui.QTableWidgetItem):
super(BidCell, self).__init__()
self.data = None
self.setForeground(QtGui.QColor('black'))
self.setBackground(QtGui.QColor(255,174,201))
if text:
@ -146,6 +147,7 @@ class AskCell(QtGui.QTableWidgetItem):
super(AskCell, self).__init__()
self.data = None
self.setForeground(QtGui.QColor('black'))
self.setBackground(QtGui.QColor(160,255,160))
if text:

View File

@ -34,41 +34,24 @@ class MainWindow(QtGui.QMainWindow):
#----------------------------------------------------------------------
def initCentral(self):
"""初始化中心区域"""
marketM = MarketMonitor(self.mainEngine, self.eventEngine)
logM = LogMonitor(self.mainEngine, self.eventEngine)
errorM = ErrorMonitor(self.mainEngine, self.eventEngine)
tradeM = TradeMonitor(self.mainEngine, self.eventEngine)
orderM = OrderMonitor(self.mainEngine, self.eventEngine)
positionM = PositionMonitor(self.mainEngine, self.eventEngine)
accountM = AccountMonitor(self.mainEngine, self.eventEngine)
tradingW = TradingWidget(self.mainEngine, self.eventEngine)
leftTab = QtGui.QTabWidget()
leftTab.addTab(logM, u'日志')
leftTab.addTab(errorM, u'错误')
leftTab.addTab(accountM, u'账户')
rightTab = QtGui.QTabWidget()
rightTab.addTab(tradeM, u'成交')
rightTab.addTab(orderM, u'委托')
rightTab.addTab(positionM, u'持仓')
widgetMarketM, dockMarketM = self.createDock(MarketMonitor, u'行情', QtCore.Qt.RightDockWidgetArea)
widgetLogM, dockLogM = self.createDock(LogMonitor, u'日志', QtCore.Qt.BottomDockWidgetArea)
widgetErrorM, dockErrorM = self.createDock(ErrorMonitor, u'错误', QtCore.Qt.BottomDockWidgetArea)
widgetTradeM, dockTradeM = self.createDock(TradeMonitor, u'成交', QtCore.Qt.BottomDockWidgetArea)
widgetOrderM, dockOrderM = self.createDock(OrderMonitor, u'委托', QtCore.Qt.RightDockWidgetArea)
widgetPositionM, dockPositionM = self.createDock(PositionMonitor, u'持仓', QtCore.Qt.BottomDockWidgetArea)
widgetAccountM, dockAccountM = self.createDock(AccountMonitor, u'资金', QtCore.Qt.BottomDockWidgetArea)
widgetTradingW, dockTradingW = self.createDock(TradingWidget, u'交易', QtCore.Qt.LeftDockWidgetArea)
self.tabifyDockWidget(dockTradeM, dockErrorM)
self.tabifyDockWidget(dockTradeM, dockLogM)
self.tabifyDockWidget(dockPositionM, dockAccountM)
dockTradeM.raise_()
dockPositionM.raise_()
hbox = QtGui.QHBoxLayout()
hbox.addWidget(tradingW)
hbox.addWidget(marketM)
grid = QtGui.QGridLayout()
grid.addLayout(hbox, 0, 0, 1, 2)
grid.addWidget(leftTab, 1, 0)
grid.addWidget(rightTab, 1, 1)
central = QtGui.QWidget()
central.setLayout(grid)
self.setCentralWidget(central)
# 连接组件之间的信号
positionM.itemDoubleClicked.connect(tradingW.closePosition)
widgetPositionM.itemDoubleClicked.connect(widgetTradingW.closePosition)
#----------------------------------------------------------------------
def initMenu(self):
@ -266,19 +249,19 @@ class MainWindow(QtGui.QMainWindow):
def openCta(self):
"""打开CTA组件"""
try:
self.widgetDict['ctaM'].show()
self.widgetDict['ctaM'].showMaximized()
except KeyError:
self.widgetDict['ctaM'] = CtaEngineManager(self.mainEngine.ctaEngine, self.eventEngine)
self.widgetDict['ctaM'].show()
self.widgetDict['ctaM'].showMaximized()
#----------------------------------------------------------------------
def openDr(self):
"""打开行情数据记录组件"""
try:
self.widgetDict['drM'].show()
self.widgetDict['drM'].showMaximized()
except KeyError:
self.widgetDict['drM'] = DrEngineManager(self.mainEngine.drEngine, self.eventEngine)
self.widgetDict['drM'].show()
self.widgetDict['drM'].showMaximized()
#----------------------------------------------------------------------
def closeEvent(self, event):
@ -294,6 +277,31 @@ class MainWindow(QtGui.QMainWindow):
event.accept()
else:
event.ignore()
#----------------------------------------------------------------------
def createDock(self, widgetClass, widgetName, widgetArea):
"""创建停靠组件"""
widget = widgetClass(self.mainEngine, self.eventEngine)
dock = QtGui.QDockWidget(widgetName)
dock.setWidget(widget)
dock.setObjectName(widgetName)
dock.setFeatures(dock.DockWidgetFloatable|dock.DockWidgetMovable)
self.addDockWidget(widgetArea, dock)
return widget, dock
#----------------------------------------------------------------------
def saveWindowSettings(self):
"""保存窗口设置"""
settings = QtCore.QSettings('vn.py', 'vn.trader')
settings.setValue('state', self.saveState())
settings.setValue('geometry', self.saveGeometry())
#----------------------------------------------------------------------
def loadWindowSettings(self):
"""载入窗口设置"""
settings = QtCore.QSettings('vn.py', 'vn.trader')
self.restoreState(settings.value('state').toByteArray())
self.restoreGeometry(settings.value('geometry').toByteArray())
########################################################################

View File

@ -5,6 +5,7 @@
"""
import decimal
import json
MAX_NUMBER = 10000000000000
MAX_DECIMAL = 4

View File

@ -12,14 +12,27 @@ def main():
# 设置底部任务栏图标win7以下请注释掉
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.py demo')
# 初始化Qt应用对象
app = QtGui.QApplication(sys.argv)
app.setWindowIcon(QtGui.QIcon('vnpy.ico'))
app.setFont(BASIC_FONT)
# 设置Qt的皮肤
try:
f = file("VT_setting.json")
setting = json.load(f)
if setting['darkStyle']:
import qdarkstyle
app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False))
except:
pass
# 初始化主引擎和主窗口对象
mainEngine = MainEngine()
mainWindow = MainWindow(mainEngine, mainEngine.eventEngine)
mainWindow.showMaximized()
# 在主线程中启动Qt事件循环
sys.exit(app.exec_())
if __name__ == '__main__':