diff --git a/vnpy/event/eventEngine.py b/vnpy/event/eventEngine.py index d892177f..a89c924e 100644 --- a/vnpy/event/eventEngine.py +++ b/vnpy/event/eventEngine.py @@ -7,7 +7,7 @@ from time import sleep from collections import defaultdict # 第三方模块 -from PyQt4.QtCore import QTimer +from qtpy.QtCore import QTimer # 自己开发的模块 from eventType import * diff --git a/vnpy/trader/vtClient.py b/vnpy/trader/archive/vtClient.py similarity index 80% rename from vnpy/trader/vtClient.py rename to vnpy/trader/archive/vtClient.py index 29813bc2..205a7af5 100644 --- a/vnpy/trader/vtClient.py +++ b/vnpy/trader/archive/vtClient.py @@ -1,31 +1,21 @@ # encoding: utf-8 +# 重载sys模块,设置默认字符串编码方式为utf8 import sys -import os -import ctypes -import platform +reload(sys) +sys.setdefaultencoding('utf8') -import vtPath -from uiMainWindow import * - -from vnpy.event import EventEngine +# vn.trader模块 +from vnpy.event import EventEngine2 from vnpy.rpc import RpcClient -from vnpy.trader.app.ctaStrategy.ctaEngine import CtaEngine -from vnpy.trader.app.dataRecorder.drEngine import DrEngine -from vnpy.trader.app.riskManager.rmEngine import RmEngine +from vnpy.trader.vtGlobal import globalSetting +from vnpy.trader.vtEngine import MainEngine +from vnpy.trader.uiQt import qApp +from vnpy.trader.uiMainWindow import MainWindow -# 文件路径名 -path = os.path.abspath(os.path.dirname(__file__)) -ICON_FILENAME = 'vnpy.ico' -ICON_FILENAME = os.path.join(path, ICON_FILENAME) - -SETTING_FILENAME = 'VT_setting.json' -SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) - - ######################################################################## class VtClient(RpcClient): """vn.trader客户端""" @@ -46,12 +36,14 @@ class VtClient(RpcClient): ######################################################################## -class ClientEngine(object): +class ClientEngine(MainEngine): """客户端引擎,提供和MainEngine完全相同的API接口""" #---------------------------------------------------------------------- def __init__(self, client, eventEngine): """Constructor""" + super(MainEngine, self).__init__(eventEngine) + self.client = client self.eventEngine = eventEngine @@ -148,24 +140,16 @@ class ClientEngine(object): return self.client.getAllWorkingOrders() #---------------------------------------------------------------------- - def getAllGatewayNames(self): + def getAllGatewayDetails(self): """查询所有的接口名称""" - return self.client.getAllGatewayNames() + return self.client.getAllGatewayDetails() #---------------------------------------------------------------------- def main(): """客户端主程序入口""" - # 重载sys模块,设置默认字符串编码方式为utf8 - reload(sys) - sys.setdefaultencoding('utf8') - - # 设置Windows底部任务栏图标 - if 'Windows' in platform.uname() : - ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.trader') - # 创建事件引擎 - eventEngine = EventEngine() + eventEngine = EventEngine2() eventEngine.start(timer=False) # 创建客户端 @@ -176,28 +160,13 @@ def main(): client.subscribeTopic('') client.start() - # 初始化Qt应用对象 - app = QtGui.QApplication(sys.argv) - app.setWindowIcon(QtGui.QIcon(ICON_FILENAME)) - app.setFont(BASIC_FONT) - - # 设置Qt的皮肤 - try: - f = file(SETTING_FILENAME) - setting = json.load(f) - if setting['darkStyle']: - import qdarkstyle - app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False)) - except: - pass - # 初始化主引擎和主窗口对象 mainEngine = ClientEngine(client, eventEngine) mainWindow = MainWindow(mainEngine, mainEngine.eventEngine) mainWindow.showMaximized() # 在主线程中启动Qt事件循环 - sys.exit(app.exec_()) + sys.exit(qApp.exec_()) if __name__ == '__main__': diff --git a/vnpy/trader/vtServer.py b/vnpy/trader/archive/vtServer.py similarity index 93% rename from vnpy/trader/vtServer.py rename to vnpy/trader/archive/vtServer.py index 1290e0df..f590aad8 100644 --- a/vnpy/trader/vtServer.py +++ b/vnpy/trader/archive/vtServer.py @@ -7,6 +7,7 @@ from datetime import datetime from time import sleep from threading import Thread +from vnpy.event import EventEngine2 from vnpy.rpc import RpcServer from vnpy.trader.vtEngine import MainEngine @@ -21,8 +22,11 @@ class VtServer(RpcServer): super(VtServer, self).__init__(repAddress, pubAddress) self.usePickle() + # 创建事件引擎 + self.ee = EventEngine2() + # 创建主引擎对象 - self.engine = MainEngine() + self.engine = MainEngine(self.ee) # 注册主引擎的方法到服务器的RPC函数 self.register(self.engine.connect) @@ -41,7 +45,7 @@ class VtServer(RpcServer): self.register(self.engine.getAllContracts) self.register(self.engine.getOrder) self.register(self.engine.getAllWorkingOrders) - self.register(self.engine.getAllGatewayNames) + self.register(self.engine.getAllGatewayDetails) # 注册事件引擎发送的事件处理监听 self.engine.eventEngine.registerGeneralHandler(self.eventHandler) diff --git a/vnpy/trader/uiBasicWidget.py b/vnpy/trader/uiBasicWidget.py index 4595d906..9df85770 100644 --- a/vnpy/trader/uiBasicWidget.py +++ b/vnpy/trader/uiBasicWidget.py @@ -6,45 +6,18 @@ import os import platform from collections import OrderedDict -from qtpy import QtWidgets, QtGui, QtCore - from vnpy.event import * from vnpy.trader.vtEvent import * from vnpy.trader.vtFunction import * from vnpy.trader.vtGateway import * -from vnpy.trader import vtText as vtText +from vnpy.trader import vtText +from vnpy.trader.uiQt import QtGui, QtWidgets, QtCore, BASIC_FONT COLOR_RED = QtGui.QColor('red') COLOR_GREEN = QtGui.QColor('green') -# 设置Windows底部任务栏图标 -if 'Windows' in platform.uname(): - import ctypes - ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.trader') - - -#---------------------------------------------------------------------- -def loadFont(): - """载入字体设置""" - fileName = 'VT_setting.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) - - try: - f = file(fileName) - setting = json.load(f) - family = setting['fontFamily'] - size = setting['fontSize'] - font = QtGui.QFont(family, size) - except: - font = QtGui.QFont(u'微软雅黑', 12) - return font - -BASIC_FONT = loadFont() - - ######################################################################## class BasicCell(QtWidgets.QTableWidgetItem): """基础的单元格""" diff --git a/vnpy/trader/uiMainWindow.py b/vnpy/trader/uiMainWindow.py index 8930c0e0..4b03e4d7 100644 --- a/vnpy/trader/uiMainWindow.py +++ b/vnpy/trader/uiMainWindow.py @@ -4,9 +4,6 @@ import psutil from vnpy.trader.vtGlobal import globalSetting from vnpy.trader.uiBasicWidget import * -#from vnpy.trader.ctaStrategy.uiCtaWidget import CtaEngineManager -#from vnpy.trader.dataRecorder.uiDrWidget import DrEngineManager -#from vnpy.trader.riskManager.uiRmWidget import RmEngineManager ######################################################################## @@ -17,13 +14,7 @@ class MainWindow(QtWidgets.QMainWindow): #---------------------------------------------------------------------- def __init__(self, mainEngine, eventEngine): - """Constructor""" - # 实例化主窗口对象时,设置Qt的皮肤 - if globalSetting['darkStyle']: - import qdarkstyle - app = QtWidgets.QApplication.instance() - app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False)) - + """Constructor""" super(MainWindow, self).__init__() self.mainEngine = mainEngine diff --git a/vnpy/trader/uiQt.py b/vnpy/trader/uiQt.py new file mode 100644 index 00000000..be94b4ce --- /dev/null +++ b/vnpy/trader/uiQt.py @@ -0,0 +1,36 @@ +# encoding: UTF-8 + +import platform + +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 + +# 设置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())) \ No newline at end of file diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 47978f17..8780734c 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -7,17 +7,12 @@ from datetime import datetime from pymongo import MongoClient from pymongo.errors import ConnectionFailure -from vnpy.event import * +from vnpy.event import Event from vnpy.trader.vtGlobal import globalSetting from vnpy.trader.vtEvent import * from vnpy.trader.vtGateway import * from vnpy.trader.language import text -#from vnpy.trader.gateway import GATEWAY_DICT -#from vnpy.trader.ctaStrategy.ctaEngine import CtaEngine -#from vnpy.trader.dataRecorder.drEngine import DrEngine -from vnpy.trader.app import riskManager - ######################################################################## class MainEngine(object): @@ -39,9 +34,6 @@ class MainEngine(object): # MongoDB数据库相关 self.dbClient = None # MongoDB客户端对象 - # 调用一个个初始化函数 - #self.initGateway() - # 接口实例 self.gatewayDict = OrderedDict() self.gatewayDetailList = [] @@ -52,21 +44,6 @@ class MainEngine(object): # 风控引擎实例(特殊独立对象) self.rmEngine = None - - #---------------------------------------------------------------------- - def initGateway(self): - """初始化接口对象""" - # 用来保存接口对象的字典 - self.gatewayDict = OrderedDict() - - # 遍历接口字典并自动创建所有的接口对象 - for gatewayModule in GATEWAY_DICT.values(): - try: - self.addGateway(gatewayModule.gateway, gatewayModule.gatewayName) - if gatewayModule.gatewayQryEnabled: - self.gatewayDict[gatewayModule.gatewayName].setQryEnabled(True) - except Exception, e: - print e #---------------------------------------------------------------------- def addGateway(self, gatewayModule): diff --git a/vnpy/trader/vtMain.py b/vnpy/trader/vtMain.py index d3537df2..c8e82e55 100644 --- a/vnpy/trader/vtMain.py +++ b/vnpy/trader/vtMain.py @@ -5,19 +5,12 @@ import sys reload(sys) sys.setdefaultencoding('utf8') -# Python内置模块 -import os -import platform - -# Python三方模块 -from qtpy import QtWidgets, QtGui - # vn.trader模块 from vnpy.event import EventEngine2 from vnpy.trader.vtGlobal import globalSetting from vnpy.trader.vtEngine import MainEngine -from vnpy.trader.uiMainWindow import MainWindow, BASIC_FONT -from vnpy.trader.vtFunction import loadIconPath +from vnpy.trader.uiQt import qApp +from vnpy.trader.uiMainWindow import MainWindow # 加载底层接口 from vnpy.trader.gateway import (ctpGateway, @@ -48,17 +41,12 @@ def main(): me.addApp(dataRecorder) me.addApp(ctaStrategy) - # 初始化Qt应用对象 - app = QtWidgets.QApplication(sys.argv) - app.setWindowIcon(QtGui.QIcon(loadIconPath())) - app.setFont(BASIC_FONT) - - # 初始化主引擎和主窗口对象 + # 创建主窗口 mw = MainWindow(me, ee) mw.showMaximized() # 在主线程中启动Qt事件循环 - sys.exit(app.exec_()) + sys.exit(qApp.exec_()) diff --git a/vnpy/trader/vtObject.py b/vnpy/trader/vtObject.py index e6f97a96..4d9612a4 100644 --- a/vnpy/trader/vtObject.py +++ b/vnpy/trader/vtObject.py @@ -2,7 +2,8 @@ import time -from vnpy.trader.vtConstant import EMPTY_STRING, EMPTY_UNICODE, EMPTY_FLOAT, EMPTY_INT +from vnpy.trader.vtConstant import (EMPTY_STRING, EMPTY_UNICODE, + EMPTY_FLOAT, EMPTY_INT) ########################################################################