From 55ea259af1a2bd4f87f9d9a4fcc9802a51276177 Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Thu, 28 Apr 2016 23:03:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=B8=BB=E7=AA=97=E5=8F=A3=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E7=BB=84=E4=BB=B6=E6=94=B9=E4=B8=BA=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=EF=BC=8C=E5=90=8C=E6=97=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=AA=E9=BB=91=E8=89=B2=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E6=83=B3=E8=A6=81=E4=BD=BF=E7=94=A8=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=8F=AF=E4=BB=A5pip=20install=20qdarkstyle=E5=90=8E?= =?UTF-8?q?=E5=86=8D=E8=BF=90=E8=A1=8Cvn.trader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/VT_setting.json | 4 +- vn.trader/uiBasicWidget.py | 2 + vn.trader/uiMainWindow.py | 82 +++++++++++++++++++++----------------- vn.trader/vtFunction.py | 1 + vn.trader/vtMain.py | 13 ++++++ 5 files changed, 64 insertions(+), 38 deletions(-) diff --git a/vn.trader/VT_setting.json b/vn.trader/VT_setting.json index c794cd52..a6e5a1c7 100644 --- a/vn.trader/VT_setting.json +++ b/vn.trader/VT_setting.json @@ -3,5 +3,7 @@ "fontSize": 12, "mongoHost": "localhost", - "mongoPort": 27017 + "mongoPort": 27017, + + "darkStyle": true } \ No newline at end of file diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index 9701dac3..3e9e94bf 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -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: diff --git a/vn.trader/uiMainWindow.py b/vn.trader/uiMainWindow.py index 1db5f885..4f9fa02e 100644 --- a/vn.trader/uiMainWindow.py +++ b/vn.trader/uiMainWindow.py @@ -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()) ######################################################################## diff --git a/vn.trader/vtFunction.py b/vn.trader/vtFunction.py index 89a70df8..c752708e 100644 --- a/vn.trader/vtFunction.py +++ b/vn.trader/vtFunction.py @@ -5,6 +5,7 @@ """ import decimal +import json MAX_NUMBER = 10000000000000 MAX_DECIMAL = 4 diff --git a/vn.trader/vtMain.py b/vn.trader/vtMain.py index 60c5dbca..35e094b8 100644 --- a/vn.trader/vtMain.py +++ b/vn.trader/vtMain.py @@ -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__':