From f87d95d982a3de6c6bfeea21aac2f42d9d5bb5da Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Fri, 28 Oct 2016 22:34:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0NumCell=E8=A7=A3=E5=86=B3Trad?= =?UTF-8?q?eID=E5=92=8COrderID=E6=8E=92=E5=BA=8F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/uiBasicWidget.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index 9cf52a50..be38fae4 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -48,6 +48,31 @@ class BasicCell(QtGui.QTableWidgetItem): self.setText(text) +######################################################################## +class NumCell(QtGui.QTableWidgetItem): + """用来显示数字的单元格""" + + #---------------------------------------------------------------------- + def __init__(self, text=None, mainEngine=None): + """Constructor""" + super(NumCell, self).__init__() + self.data = None + if text: + self.setContent(text) + + #---------------------------------------------------------------------- + def setContent(self, text): + """设置内容""" + # 考虑到NumCell主要用来显示OrderID和TradeID之类的整数字段, + # 这里的数据转化方式使用int类型。但是由于部分交易接口的委托 + # 号和成交号可能不是纯数字的形式,因此补充了一个try...except + try: + num = int(text) + self.setData(QtCore.Qt.DisplayRole, num) + except ValueError: + self.setText(text) + + ######################################################################## class DirectionCell(QtGui.QTableWidgetItem): """用来显示买卖方向的单元格""" @@ -464,8 +489,8 @@ class TradeMonitor(BasicMonitor): super(TradeMonitor, self).__init__(mainEngine, eventEngine, parent) d = OrderedDict() - d['tradeID'] = {'chinese':u'成交编号', 'cellType':BasicCell} - d['orderID'] = {'chinese':u'委托编号', 'cellType':BasicCell} + d['tradeID'] = {'chinese':u'成交编号', 'cellType':NumCell} + d['orderID'] = {'chinese':u'委托编号', 'cellType':NumCell} d['symbol'] = {'chinese':u'合约代码', 'cellType':BasicCell} d['vtSymbol'] = {'chinese':u'名称', 'cellType':NameCell} d['direction'] = {'chinese':u'方向', 'cellType':DirectionCell} @@ -478,6 +503,8 @@ class TradeMonitor(BasicMonitor): self.setEventType(EVENT_TRADE) self.setFont(BASIC_FONT) + self.setSorting(True) + self.initTable() self.registerEvent() @@ -494,7 +521,7 @@ class OrderMonitor(BasicMonitor): self.mainEngine = mainEngine d = OrderedDict() - d['orderID'] = {'chinese':u'委托编号', 'cellType':BasicCell} + d['orderID'] = {'chinese':u'委托编号', 'cellType':NumCell} d['symbol'] = {'chinese':u'合约代码', 'cellType':BasicCell} d['vtSymbol'] = {'chinese':u'名称', 'cellType':NameCell} d['direction'] = {'chinese':u'方向', 'cellType':DirectionCell} @@ -514,10 +541,10 @@ class OrderMonitor(BasicMonitor): self.setEventType(EVENT_ORDER) self.setFont(BASIC_FONT) self.setSaveData(True) + self.setSorting(True) self.initTable() self.registerEvent() - self.connectSignal() #----------------------------------------------------------------------