From e8ae262660c851f3d8adc0b3d1cdea8fe935bbfd Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 25 Jul 2017 13:37:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9QApp=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=94=A8=E6=88=B7=E6=98=BE=E5=BC=8F=E8=B0=83?= =?UTF-8?q?=E7=94=A8createQApp=E5=87=BD=E6=95=B0=E5=90=8E=E5=88=9B?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++- examples/VnTrader/run.py | 5 ++- vnpy/trader/archive/vtClient.py | 5 ++- vnpy/trader/uiQt.py | 57 ++++++++++++++++++--------------- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index b54549f2..8641c5c7 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ sys.setdefaultencoding('utf8') # vn.trader模块 from vnpy.event import EventEngine from vnpy.trader.vtEngine import MainEngine -from vnpy.trader.uiQt import qApp +from vnpy.trader.uiQt import createQApp from vnpy.trader.uiMainWindow import MainWindow # 加载底层接口 @@ -77,6 +77,9 @@ from vnpy.trader.app import riskManager, ctaStrategy #---------------------------------------------------------------------- def main(): """主程序入口""" + # 创建Qt应用对象 + qApp = createQApp() + # 创建事件引擎 ee = EventEngine() diff --git a/examples/VnTrader/run.py b/examples/VnTrader/run.py index 28aadddf..179a1edb 100644 --- a/examples/VnTrader/run.py +++ b/examples/VnTrader/run.py @@ -12,7 +12,7 @@ system = platform.system() # vn.trader模块 from vnpy.event import EventEngine from vnpy.trader.vtEngine import MainEngine -from vnpy.trader.uiQt import qApp +from vnpy.trader.uiQt import createQApp from vnpy.trader.uiMainWindow import MainWindow # 加载底层接口 @@ -30,6 +30,9 @@ from vnpy.trader.app import (riskManager, ctaStrategy, spreadTrading) #---------------------------------------------------------------------- def main(): """主程序入口""" + # 创建Qt应用对象 + qApp = createQApp() + # 创建事件引擎 ee = EventEngine() diff --git a/vnpy/trader/archive/vtClient.py b/vnpy/trader/archive/vtClient.py index 205a7af5..88d62cfe 100644 --- a/vnpy/trader/archive/vtClient.py +++ b/vnpy/trader/archive/vtClient.py @@ -11,7 +11,7 @@ from vnpy.rpc import RpcClient from vnpy.trader.vtGlobal import globalSetting from vnpy.trader.vtEngine import MainEngine -from vnpy.trader.uiQt import qApp +from vnpy.trader.uiQt import createQApp from vnpy.trader.uiMainWindow import MainWindow @@ -148,6 +148,9 @@ class ClientEngine(MainEngine): #---------------------------------------------------------------------- def main(): """客户端主程序入口""" + # 创建Qt对象 + qApp = createQApp() + # 创建事件引擎 eventEngine = EventEngine2() eventEngine.start(timer=False) diff --git a/vnpy/trader/uiQt.py b/vnpy/trader/uiQt.py index c8ca4f0c..227ffc55 100644 --- a/vnpy/trader/uiQt.py +++ b/vnpy/trader/uiQt.py @@ -7,30 +7,37 @@ from qtpy import QtWidgets, QtGui, QtCore from vnpy.trader.vtGlobal import globalSetting from vnpy.trader.vtFunction import loadIconPath -# 创建Qt应用对象 -qApp = QtWidgets.QApplication([]) -# 设置Qt的皮肤 -if globalSetting['darkStyle']: - try: - import qdarkstyle - qApp.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False)) - except ImportError: - pass +#---------------------------------------------------------------------- +def createQApp(): + """创建PyQt应用对象""" + # 创建Qt应用对象 + qApp = QtWidgets.QApplication([]) -# 设置Windows底部任务栏图标 -if 'Windows' in platform.uname(): - import ctypes - ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.trader') - -# 设置Qt字体 -try: - family = globalSetting['fontFamily'] - size = globalSetting['fontSize'] - BASIC_FONT = QtGui.QFont(family, size) -except: - BASIC_FONT = QtGui.QFont(u'微软雅黑', 12) -qApp.setFont(BASIC_FONT) - -# 设置Qt图标 -qApp.setWindowIcon(QtGui.QIcon(loadIconPath('vnpy.ico'))) \ No newline at end of file + # 设置Qt的皮肤 + if globalSetting['darkStyle']: + try: + import qdarkstyle + qApp.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False)) + except ImportError: + pass + + # 设置Windows底部任务栏图标 + if 'Windows' in platform.uname(): + import ctypes + ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.trader') + + # 设置Qt字体 + try: + family = globalSetting['fontFamily'] + size = globalSetting['fontSize'] + BASIC_FONT = QtGui.QFont(family, size) + except: + BASIC_FONT = QtGui.QFont(u'微软雅黑', 12) + qApp.setFont(BASIC_FONT) + + # 设置Qt图标 + qApp.setWindowIcon(QtGui.QIcon(loadIconPath('vnpy.ico'))) + + # 返回创建好的QApp对象 + return qApp \ No newline at end of file