优化显示

This commit is contained in:
ares89@wind 2017-02-08 15:40:28 +08:00
parent e5ce000a7d
commit 4e49f06246
4 changed files with 61 additions and 37 deletions

View File

@ -3,12 +3,18 @@
'''
行情记录模块相关的GUI控制组件
'''
import re
import sys
from PyQt4.QtGui import QTreeView
from dataRecorder.drEngine import DrEngine
from eventEngine import *
from uiBasicWidget import QtGui, QtCore
reload(sys)
sys.setdefaultencoding("utf8")
class TreeItem(object):
def __init__(self, data, parent=None):
@ -58,7 +64,7 @@ class TreeItem(object):
class TreeModel(QtCore.QAbstractItemModel):
def __init__(self, parent=None):
super(TreeModel, self).__init__(parent)
self.rootItem = TreeItem([u"合约", u"Tick", u"Bar", u"主力"])
self.rootItem = TreeItem([u"合约", u"Tick", u"Bar", u"主力", u"交易所", u"接口"])
def rootItem(self):
return self.rootItem
@ -73,7 +79,7 @@ class TreeModel(QtCore.QAbstractItemModel):
return self.rootItem.columnCount()
def setData(self, index, value, role=None):
if index.column() != 0 and role == QtCore.Qt.CheckStateRole:
if index.column() in [1, 2, 3] and role == QtCore.Qt.CheckStateRole:
item = index.internalPointer()
if item is None:
return False
@ -101,13 +107,11 @@ class TreeModel(QtCore.QAbstractItemModel):
item = index.internalPointer()
if role == QtCore.Qt.CheckStateRole and index.column() != 0:
if role == QtCore.Qt.CheckStateRole and (
index.column() in [1, 2] or index.column() == 3 and item.parentItem != self.rootItem):
return QtCore.Qt.Checked if item.data(index.column()) == True else QtCore.Qt.Unchecked
if index.column() == 3 and item.parentItem == self.rootItem:
return None
if role != QtCore.Qt.DisplayRole:
if role != QtCore.Qt.DisplayRole or index.column() == 3 and item.parentItem == self.rootItem:
return None
return item.data(index.column())
@ -116,12 +120,12 @@ class TreeModel(QtCore.QAbstractItemModel):
if not index.isValid():
return QtCore.Qt.NoItemFlags
if index.column() == 0:
if index.column() in [0, 4, 5]:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
item = index.internalPointer()
if index.column() == 3 and item.parentItem == self.rootItem:
return QtCore.Qt.NoItemFlags
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable
@ -170,7 +174,7 @@ class TreeModel(QtCore.QAbstractItemModel):
return parentItem.childCount()
def hasIndex(self, row, column, parentIndex=None, *args, **kwargs):
if row < 0 or column > 4:
if row < 0 or column > self.rootItem.columnCount():
return False
return True
@ -179,11 +183,11 @@ class DrEditWidget(QtGui.QWidget):
"""行情数据记录引擎管理组件"""
signal = QtCore.pyqtSignal(type(Event()))
def __init__(self, drEngine, eventEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(DrEditWidget, self).__init__(parent)
self.drEngine = drEngine
self.mainEngine = mainEngine
self.eventEngine = eventEngine
# 保存合约详细信息的字典
@ -217,18 +221,42 @@ class DrEditWidget(QtGui.QWidget):
vbox.addWidget(self.qTreeView)
self.setLayout(vbox)
def getContractChineseName(self, str):
line = str.strip().decode('utf-8', 'ignore') # 处理前进行相关的处理包括转换成Unicode等
p2 = re.compile(ur'[^\u4e00-\u9fa5]') # 中文的编码范围是:\u4e00到\u9fa5
zh = " ".join(p2.split(line)).strip()
zh = ",".join(zh.split())
outStr = zh # 经过相关处理后得到中文的文本
return outStr
def loadData(self):
child = []
yumi = TreeItem([u"玉米", False, False, False], self.model.rootItem)
yumi.appendChild(TreeItem([u"c1705", False, False, False], yumi))
yumi.appendChild(TreeItem([u"c1703", False, False, False], yumi))
yumi.appendChild(TreeItem([u"c1707", False, False, False], yumi))
yumi.appendChild(TreeItem([u"c1709", False, False, False], yumi))
dianfen = TreeItem([u"淀粉", False, False, False], self.model.rootItem)
dianfen.appendChild(TreeItem([u"d1705", False, False, False], dianfen))
dianfen.appendChild(TreeItem([u"d1703", False, False, False], dianfen))
dianfen.appendChild(TreeItem([u"d1707", False, False, False], dianfen))
dianfen.appendChild(TreeItem([u"d1709", False, False, False], dianfen))
contractDict = {}
# contracts = self.mainEngine.getAllContracts()
# for contract in contracts:
# contractName = self.getContractChineseName(contract.name)
# if contractDict.has_key(contractName):
# parentItem = contractDict[contractName]
# item = TreeItem([contract.symbol, False, False, False, contract.exchange, "CTP"], parentItem)
# parentItem.appendChild(item)
# else:
# item = TreeItem([contractName, False, False, False, contract.exchange, "CTP"], self.model.rootItem)
# contractDict[contractName] = item
# child.append(item)
# subItem = TreeItem([contract.symbol, False, False, False, contract.exchange, "CTP"], item)
# item.appendChild(subItem)
yumi = TreeItem([u"玉米", False, False, False, "SH", "CTP"], self.model.rootItem)
yumi.appendChild(TreeItem([u"c1705", False, False, False, "SH", "CTP"], yumi))
yumi.appendChild(TreeItem([u"c1703", False, False, False, "SH", "CTP"], yumi))
yumi.appendChild(TreeItem([u"c1707", False, False, False, "SH", "CTP"], yumi))
yumi.appendChild(TreeItem([u"c1709", False, False, False, "SH", "CTP"], yumi))
dianfen = TreeItem([u"淀粉", False, False, False, "SH", "CTP"], self.model.rootItem)
dianfen.appendChild(TreeItem([u"d1705", False, False, False, "SH", "CTP"], dianfen))
dianfen.appendChild(TreeItem([u"d1703", False, False, False, "SH", "CTP"], dianfen))
dianfen.appendChild(TreeItem([u"d1707", False, False, False, "SH", "CTP"], dianfen))
dianfen.appendChild(TreeItem([u"d1709", False, False, False, "SH", "CTP"], dianfen))
child.append(yumi)
child.append(dianfen)
@ -276,6 +304,6 @@ if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
view = DrEditWidget(DrEngine, EventEngine)
view.setFixedSize(500, 500)
view.setFixedSize(650, 500)
view.show()
sys.exit(app.exec_())

View File

@ -7,8 +7,8 @@
import json
from dataRecorder.uiDrEdit import DrEditWidget
from uiBasicWidget import QtGui, QtCore
from eventEngine import *
from uiBasicWidget import QtGui, QtCore
########################################################################
@ -39,11 +39,12 @@ class DrEngineManager(QtGui.QWidget):
signal = QtCore.pyqtSignal(type(Event()))
#----------------------------------------------------------------------
def __init__(self, drEngine, eventEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(DrEngineManager, self).__init__(parent)
self.drEngine = drEngine
self.mainEngine = mainEngine
self.drEngine = mainEngine.drEngine
self.eventEngine = eventEngine
self.initUi()
@ -154,5 +155,6 @@ class DrEngineManager(QtGui.QWidget):
# ----------------------------------------------------------------------
def openDr(self):
"""打开行情数据记录组件"""
self.mDrEditWidget = DrEditWidget(self.drEngine, self.eventEngine)
self.mDrEditWidget.showMaximized()
self.mDrEditWidget = DrEditWidget(self.mainEngine, self.eventEngine)
self.mDrEditWidget.setFixedSize(500, 500)
self.mDrEditWidget.show()

View File

@ -1,14 +1,11 @@
# encoding: UTF-8
import json
import csv
import os
from collections import OrderedDict
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt
from eventEngine import *
from vtFunction import *
from vtGateway import *
@ -1101,9 +1098,6 @@ class ContractMonitor(BasicMonitor):
d['productClass'] = {'chinese':u'合约类型', 'cellType':BasicCell}
d['size'] = {'chinese':u'大小', 'cellType':BasicCell}
d['priceTick'] = {'chinese':u'最小价格变动', 'cellType':BasicCell}
d['tick'] = {'chinese':u'tick', 'cellType':CheckBoxCell}
d['bar'] = {'chinese':u'bar', 'cellType':CheckBoxCell}
d['main'] = {'chinese':u'主力合约', 'cellType':CheckBoxCell}
#d['strikePrice'] = {'chinese':u'期权行权价', 'cellType':BasicCell}
#d['underlyingSymbol'] = {'chinese':u'期权标的物', 'cellType':BasicCell}
#d['optionType'] = {'chinese':u'期权类型', 'cellType':BasicCell}

View File

@ -2,10 +2,10 @@
import psutil
from uiBasicWidget import *
from ctaAlgo.uiCtaWidget import CtaEngineManager
from dataRecorder.uiDrWidget import DrEngineManager
from riskManager.uiRmWidget import RmEngineManager
from uiBasicWidget import *
########################################################################
class MainWindow(QtGui.QMainWindow):
@ -194,7 +194,7 @@ class MainWindow(QtGui.QMainWindow):
try:
self.widgetDict['drM'].showMaximized()
except KeyError:
self.widgetDict['drM'] = DrEngineManager(self.mainEngine.drEngine, self.eventEngine)
self.widgetDict['drM'] = DrEngineManager(self.mainEngine, self.eventEngine)
self.widgetDict['drM'].showMaximized()
#----------------------------------------------------------------------