改进MainWindow的Action增加
This commit is contained in:
parent
7d4aa9d856
commit
5ef87e7798
@ -61,132 +61,47 @@ class MainWindow(QtGui.QMainWindow):
|
||||
#----------------------------------------------------------------------
|
||||
def initMenu(self):
|
||||
"""初始化菜单"""
|
||||
# 创建操作
|
||||
connectCtpAction = QtGui.QAction(u'连接CTP', self)
|
||||
connectCtpAction.triggered.connect(self.connectCtp)
|
||||
|
||||
connectLtsAction = QtGui.QAction(u'连接LTS', self)
|
||||
connectLtsAction.triggered.connect(self.connectLts)
|
||||
|
||||
connectXtpAction = QtGui.QAction(u'连接XTP', self)
|
||||
connectXtpAction.triggered.connect(self.connectXtp)
|
||||
|
||||
connectKsotpAction = QtGui.QAction(u'连接金仕达期权', self)
|
||||
connectKsotpAction.triggered.connect(self.connectKsotp)
|
||||
|
||||
connectFemasAction = QtGui.QAction(u'连接飞马', self)
|
||||
connectFemasAction.triggered.connect(self.connectFemas)
|
||||
|
||||
connectXspeedAction = QtGui.QAction(u'连接飞创', self)
|
||||
connectXspeedAction.triggered.connect(self.connectXspeed)
|
||||
|
||||
connectQdpAction = QtGui.QAction(u'连接QDP', self)
|
||||
connectQdpAction.triggered.connect(self.connectQdp)
|
||||
|
||||
connectKsgoldAction = QtGui.QAction(u'连接金仕达黄金', self)
|
||||
connectKsgoldAction.triggered.connect(self.connectKsgold)
|
||||
|
||||
connectSgitAction = QtGui.QAction(u'连接飞鼠', self)
|
||||
connectSgitAction.triggered.connect(self.connectSgit)
|
||||
|
||||
connectWindAction = QtGui.QAction(u'连接Wind', self)
|
||||
connectWindAction.triggered.connect(self.connectWind)
|
||||
|
||||
connectIbAction = QtGui.QAction(u'连接IB', self)
|
||||
connectIbAction.triggered.connect(self.connectIb)
|
||||
|
||||
connectShzdAction = QtGui.QAction(u'连接直达', self)
|
||||
connectShzdAction.triggered.connect(self.connectShzd)
|
||||
|
||||
connectOandaAction = QtGui.QAction(u'连接OANDA', self)
|
||||
connectOandaAction.triggered.connect(self.connectOanda)
|
||||
|
||||
connectOkcoinAction = QtGui.QAction(u'连接OKCOIN', self)
|
||||
connectOkcoinAction.triggered.connect(self.connectOkcoin)
|
||||
|
||||
connectDbAction = QtGui.QAction(u'连接数据库', self)
|
||||
connectDbAction.triggered.connect(self.mainEngine.dbConnect)
|
||||
|
||||
testAction = QtGui.QAction(u'测试', self)
|
||||
testAction.triggered.connect(self.test)
|
||||
|
||||
exitAction = QtGui.QAction(u'退出', self)
|
||||
exitAction.triggered.connect(self.close)
|
||||
|
||||
aboutAction = QtGui.QAction(u'关于', self)
|
||||
aboutAction.triggered.connect(self.openAbout)
|
||||
|
||||
contractAction = QtGui.QAction(u'查询合约', self)
|
||||
contractAction.triggered.connect(self.openContract)
|
||||
|
||||
drAction = QtGui.QAction(u'行情数据记录', self)
|
||||
drAction.triggered.connect(self.openDr)
|
||||
|
||||
ctaAction = QtGui.QAction(u'CTA策略', self)
|
||||
ctaAction.triggered.connect(self.openCta)
|
||||
|
||||
rmAction = QtGui.QAction(u'风险管理', self)
|
||||
rmAction.triggered.connect(self.openRm)
|
||||
|
||||
restoreAction = QtGui.QAction(u'还原', self)
|
||||
restoreAction.triggered.connect(self.restoreWindow)
|
||||
|
||||
# 创建菜单
|
||||
menubar = self.menuBar()
|
||||
|
||||
# 设计为只显示存在的接口
|
||||
l = self.mainEngine.getAllGatewayNames()
|
||||
|
||||
sysMenu = menubar.addMenu(u'系统')
|
||||
if 'CTP' in l:
|
||||
sysMenu.addAction(connectCtpAction)
|
||||
if 'LTS' in l:
|
||||
sysMenu.addAction(connectLtsAction)
|
||||
if 'XTP' in l:
|
||||
sysMenu.addAction(connectXtpAction)
|
||||
if 'FEMAS' in l:
|
||||
sysMenu.addAction(connectFemasAction)
|
||||
if 'XSPEED' in l:
|
||||
sysMenu.addAction(connectXspeedAction)
|
||||
if 'QDP' in l:
|
||||
sysMenu.addAction(connectQdpAction)
|
||||
if 'KSOTP' in l:
|
||||
sysMenu.addAction(connectKsotpAction)
|
||||
if 'KSGOLD' in l:
|
||||
sysMenu.addAction(connectKsgoldAction)
|
||||
if 'SGIT' in l:
|
||||
sysMenu.addAction(connectSgitAction)
|
||||
self.addConnectAction(sysMenu, 'CTP')
|
||||
self.addConnectAction(sysMenu, 'LTS')
|
||||
self.addConnectAction(sysMenu, 'XTP')
|
||||
self.addConnectAction(sysMenu, 'FEMAS', u'飞马')
|
||||
self.addConnectAction(sysMenu, 'XSPEED', u'飞创')
|
||||
self.addConnectAction(sysMenu, 'QDP')
|
||||
self.addConnectAction(sysMenu, 'KSOTP', u'金仕达期权')
|
||||
self.addConnectAction(sysMenu, 'KSGOLD', u'金仕达黄金')
|
||||
self.addConnectAction(sysMenu, 'SGIT', u'飞鼠')
|
||||
sysMenu.addSeparator()
|
||||
if 'IB' in l:
|
||||
sysMenu.addAction(connectIbAction)
|
||||
if 'SHZD' in l:
|
||||
sysMenu.addAction(connectShzdAction)
|
||||
if 'OANDA' in l:
|
||||
sysMenu.addAction(connectOandaAction)
|
||||
if 'OKCOIN' in l:
|
||||
sysMenu.addAction(connectOkcoinAction)
|
||||
self.addConnectAction(sysMenu, 'IB')
|
||||
self.addConnectAction(sysMenu, 'SHZD', u'直达')
|
||||
self.addConnectAction(sysMenu, 'OANDA')
|
||||
self.addConnectAction(sysMenu, 'OKCOIN')
|
||||
sysMenu.addSeparator()
|
||||
if 'Wind' in l:
|
||||
sysMenu.addAction(connectWindAction)
|
||||
self.addConnectAction(sysMenu, 'Wind')
|
||||
|
||||
sysMenu.addSeparator()
|
||||
sysMenu.addAction(connectDbAction)
|
||||
sysMenu.addAction(self.createAction(u'连接数据库', self.mainEngine.dbConnect))
|
||||
sysMenu.addSeparator()
|
||||
sysMenu.addAction(exitAction)
|
||||
sysMenu.addAction(self.createAction(u'退出', self.close))
|
||||
|
||||
functionMenu = menubar.addMenu(u'功能')
|
||||
functionMenu.addAction(contractAction)
|
||||
functionMenu.addAction(drAction)
|
||||
functionMenu.addAction(rmAction)
|
||||
functionMenu.addAction(self.createAction(u'查询合约', self.openContract))
|
||||
functionMenu.addAction(self.createAction(u'行情记录', self.openDr))
|
||||
functionMenu.addAction(self.createAction(u'风控管理', self.openRm))
|
||||
|
||||
# 算法相关
|
||||
algoMenu = menubar.addMenu(u'算法')
|
||||
algoMenu.addAction(ctaAction)
|
||||
algoMenu.addAction(self.createAction(u'CTA策略', self.openCta))
|
||||
|
||||
# 帮助
|
||||
helpMenu = menubar.addMenu(u'帮助')
|
||||
helpMenu.addAction(restoreAction)
|
||||
helpMenu.addAction(aboutAction)
|
||||
helpMenu.addAction(testAction)
|
||||
helpMenu.addAction(self.createAction(u'还原', self.restoreWindow))
|
||||
helpMenu.addAction(self.createAction(u'关于', self.openAbout))
|
||||
helpMenu.addAction(self.createAction(u'测试', self.test))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def initStatusBar(self):
|
||||
@ -219,74 +134,26 @@ class MainWindow(QtGui.QMainWindow):
|
||||
return u'CPU使用率:%d%% 内存使用率:%d%%' % (cpuPercent, memoryPercent)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectCtp(self):
|
||||
"""连接CTP接口"""
|
||||
self.mainEngine.connect('CTP')
|
||||
def addConnectAction(self, menu, gatewayName, displayName=''):
|
||||
"""增加连接功能"""
|
||||
if gatewayName not in self.mainEngine.getAllGatewayNames():
|
||||
return
|
||||
|
||||
def connect():
|
||||
self.mainEngine.connect(gatewayName)
|
||||
|
||||
if not displayName:
|
||||
displayName = gatewayName
|
||||
actionName = u'连接' + displayName
|
||||
|
||||
menu.addAction(self.createAction(actionName, connect))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectLts(self):
|
||||
"""连接LTS接口"""
|
||||
self.mainEngine.connect('LTS')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectXtp(self):
|
||||
"""连接Xtp接口"""
|
||||
self.mainEngine.connect('XTP')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectKsotp(self):
|
||||
"""连接金仕达期权接口"""
|
||||
self.mainEngine.connect('KSOTP')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectFemas(self):
|
||||
"""连接飞马接口"""
|
||||
self.mainEngine.connect('FEMAS')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectXspeed(self):
|
||||
"""连接飞创接口"""
|
||||
self.mainEngine.connect('XSPEED')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectQdp(self):
|
||||
"""连接QDP接口"""
|
||||
self.mainEngine.connect('QDP')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectKsgold(self):
|
||||
"""连接金仕达黄金接口"""
|
||||
self.mainEngine.connect('KSGOLD')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectSgit(self):
|
||||
"""连接飞鼠接口"""
|
||||
self.mainEngine.connect('SGIT')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectWind(self):
|
||||
"""连接Wind接口"""
|
||||
self.mainEngine.connect('Wind')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectIb(self):
|
||||
"""连接Ib"""
|
||||
self.mainEngine.connect('IB')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectShzd(self):
|
||||
"""连接Ib"""
|
||||
self.mainEngine.connect('SHZD')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectOanda(self):
|
||||
"""连接OANDA"""
|
||||
self.mainEngine.connect('OANDA')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def connectOkcoin(self):
|
||||
"""连接OKCOIN"""
|
||||
self.mainEngine.connect('OKCOIN')
|
||||
def createAction(self, actionName, function):
|
||||
"""创建操作功能"""
|
||||
action = QtGui.QAction(actionName, self)
|
||||
action.triggered.connect(function)
|
||||
return action
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def test(self):
|
||||
@ -414,7 +281,7 @@ class AboutWidget(QtGui.QDialog):
|
||||
self.setWindowTitle(u'关于VnTrader')
|
||||
|
||||
text = u"""
|
||||
Developed by traders, for traders.
|
||||
Developed by Traders, for Traders.
|
||||
|
||||
License:MIT
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user