改进MainWindow的Action增加

This commit is contained in:
chenxy123 2017-01-04 21:52:20 +08:00
parent 7d4aa9d856
commit 5ef87e7798

View File

@ -61,132 +61,47 @@ class MainWindow(QtGui.QMainWindow):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def initMenu(self): 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() menubar = self.menuBar()
# 设计为只显示存在的接口 # 设计为只显示存在的接口
l = self.mainEngine.getAllGatewayNames()
sysMenu = menubar.addMenu(u'系统') sysMenu = menubar.addMenu(u'系统')
if 'CTP' in l: self.addConnectAction(sysMenu, 'CTP')
sysMenu.addAction(connectCtpAction) self.addConnectAction(sysMenu, 'LTS')
if 'LTS' in l: self.addConnectAction(sysMenu, 'XTP')
sysMenu.addAction(connectLtsAction) self.addConnectAction(sysMenu, 'FEMAS', u'飞马')
if 'XTP' in l: self.addConnectAction(sysMenu, 'XSPEED', u'飞创')
sysMenu.addAction(connectXtpAction) self.addConnectAction(sysMenu, 'QDP')
if 'FEMAS' in l: self.addConnectAction(sysMenu, 'KSOTP', u'金仕达期权')
sysMenu.addAction(connectFemasAction) self.addConnectAction(sysMenu, 'KSGOLD', u'金仕达黄金')
if 'XSPEED' in l: self.addConnectAction(sysMenu, 'SGIT', u'飞鼠')
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)
sysMenu.addSeparator() sysMenu.addSeparator()
if 'IB' in l: self.addConnectAction(sysMenu, 'IB')
sysMenu.addAction(connectIbAction) self.addConnectAction(sysMenu, 'SHZD', u'直达')
if 'SHZD' in l: self.addConnectAction(sysMenu, 'OANDA')
sysMenu.addAction(connectShzdAction) self.addConnectAction(sysMenu, 'OKCOIN')
if 'OANDA' in l:
sysMenu.addAction(connectOandaAction)
if 'OKCOIN' in l:
sysMenu.addAction(connectOkcoinAction)
sysMenu.addSeparator() sysMenu.addSeparator()
if 'Wind' in l: self.addConnectAction(sysMenu, 'Wind')
sysMenu.addAction(connectWindAction)
sysMenu.addSeparator() sysMenu.addSeparator()
sysMenu.addAction(connectDbAction) sysMenu.addAction(self.createAction(u'连接数据库', self.mainEngine.dbConnect))
sysMenu.addSeparator() sysMenu.addSeparator()
sysMenu.addAction(exitAction) sysMenu.addAction(self.createAction(u'退出', self.close))
functionMenu = menubar.addMenu(u'功能') functionMenu = menubar.addMenu(u'功能')
functionMenu.addAction(contractAction) functionMenu.addAction(self.createAction(u'查询合约', self.openContract))
functionMenu.addAction(drAction) functionMenu.addAction(self.createAction(u'行情记录', self.openDr))
functionMenu.addAction(rmAction) functionMenu.addAction(self.createAction(u'风控管理', self.openRm))
# 算法相关 # 算法相关
algoMenu = menubar.addMenu(u'算法') algoMenu = menubar.addMenu(u'算法')
algoMenu.addAction(ctaAction) algoMenu.addAction(self.createAction(u'CTA策略', self.openCta))
# 帮助 # 帮助
helpMenu = menubar.addMenu(u'帮助') helpMenu = menubar.addMenu(u'帮助')
helpMenu.addAction(restoreAction) helpMenu.addAction(self.createAction(u'还原', self.restoreWindow))
helpMenu.addAction(aboutAction) helpMenu.addAction(self.createAction(u'关于', self.openAbout))
helpMenu.addAction(testAction) helpMenu.addAction(self.createAction(u'测试', self.test))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def initStatusBar(self): def initStatusBar(self):
@ -219,74 +134,26 @@ class MainWindow(QtGui.QMainWindow):
return u'CPU使用率%d%% 内存使用率:%d%%' % (cpuPercent, memoryPercent) return u'CPU使用率%d%% 内存使用率:%d%%' % (cpuPercent, memoryPercent)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def connectCtp(self): def addConnectAction(self, menu, gatewayName, displayName=''):
"""连接CTP接口""" """增加连接功能"""
self.mainEngine.connect('CTP') 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): def createAction(self, actionName, function):
"""连接LTS接口""" """创建操作功能"""
self.mainEngine.connect('LTS') action = QtGui.QAction(actionName, self)
action.triggered.connect(function)
#---------------------------------------------------------------------- return action
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 test(self): def test(self):
@ -414,7 +281,7 @@ class AboutWidget(QtGui.QDialog):
self.setWindowTitle(u'关于VnTrader') self.setWindowTitle(u'关于VnTrader')
text = u""" text = u"""
Developed by traders, for traders. Developed by Traders, for Traders.
LicenseMIT LicenseMIT