增加uiQt文件
1. uiQt.py用于初始化vt中的QApplication对象 2. 将vtServer.py和vtClient.py移动到保留文件夹archive中,后续计划重新实现
This commit is contained in:
parent
1fb9eaf3ab
commit
016f26a19a
@ -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 *
|
||||
|
@ -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__':
|
@ -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)
|
@ -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):
|
||||
"""基础的单元格"""
|
||||
|
@ -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
|
||||
|
36
vnpy/trader/uiQt.py
Normal file
36
vnpy/trader/uiQt.py
Normal file
@ -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()))
|
@ -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):
|
||||
|
@ -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_())
|
||||
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
########################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user