From 531818ac5fd4972ed703085600bb1b97b25e9014 Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Wed, 15 Mar 2017 23:33:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=88=E7=BA=A6=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=BB=84=E4=BB=B6=E7=9A=84=E8=BF=87=E6=BB=A4=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/uiBasicWidget.py | 59 ++++++++++++++++++++++++++++++++++++-- vn.trader/uiMainWindow.py | 2 +- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index f7f4eb63..6b41788a 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -1090,6 +1090,9 @@ class ContractMonitor(BasicMonitor): #d['optionType'] = {'chinese':u'期权类型', 'cellType':BasicCell} self.setHeaderDict(d) + # 过滤显示用的字符串 + self.filterContent = EMPTY_STRING + self.initUi() #---------------------------------------------------------------------- @@ -1113,6 +1116,10 @@ class ContractMonitor(BasicMonitor): row = 0 for key in l2: + # 如果设置了过滤信息且合约代码中不含过滤信息,则不显示 + if self.filterContent and self.filterContent not in key: + continue + contract = d[key] for n, header in enumerate(self.headerList): @@ -1123,9 +1130,9 @@ class ContractMonitor(BasicMonitor): if self.font: cell.setFont(self.font) # 如果设置了特殊字体,则进行单元格设置 - self.setItem(row, n, cell) + self.setItem(row, n, cell) - row = row + 1 + row = row + 1 #---------------------------------------------------------------------- def refresh(self): @@ -1148,5 +1155,53 @@ class ContractMonitor(BasicMonitor): """显示""" super(ContractMonitor, self).show() self.refresh() + + #---------------------------------------------------------------------- + def setFilterContent(self, content): + """设置过滤字符串""" + self.filterContent = content + + +######################################################################## +class ContractManager(QtGui.QWidget): + """合约管理组件""" + + #---------------------------------------------------------------------- + def __init__(self, mainEngine, parent=None): + """Constructor""" + super(ContractManager, self).__init__(parent=parent) + + self.mainEngine = mainEngine + + self.initUi() + + #---------------------------------------------------------------------- + def initUi(self): + """初始化界面""" + self.setWindowTitle(u'合约查询') + + self.lineFilter = QtGui.QLineEdit() + self.buttonFilter = QtGui.QPushButton(u'查询') + self.buttonFilter.clicked.connect(self.filterContract) + self.monitor = ContractMonitor(self.mainEngine) + self.monitor.refresh() + + hbox = QtGui.QHBoxLayout() + hbox.addWidget(self.lineFilter) + hbox.addWidget(self.buttonFilter) + hbox.addStretch() + + vbox = QtGui.QVBoxLayout() + vbox.addLayout(hbox) + vbox.addWidget(self.monitor) + + self.setLayout(vbox) + + #---------------------------------------------------------------------- + def filterContract(self): + """显示过滤后的合约""" + content = str(self.lineFilter.text()) + self.monitor.setFilterContent(content) + self.monitor.refresh() diff --git a/vn.trader/uiMainWindow.py b/vn.trader/uiMainWindow.py index 007fd8b1..35613db3 100644 --- a/vn.trader/uiMainWindow.py +++ b/vn.trader/uiMainWindow.py @@ -179,7 +179,7 @@ class MainWindow(QtGui.QMainWindow): try: self.widgetDict['contractM'].show() except KeyError: - self.widgetDict['contractM'] = ContractMonitor(self.mainEngine) + self.widgetDict['contractM'] = ContractManager(self.mainEngine) self.widgetDict['contractM'].show() #----------------------------------------------------------------------