优化显示
This commit is contained in:
parent
e5ce000a7d
commit
4e49f06246
@ -3,12 +3,18 @@
|
|||||||
'''
|
'''
|
||||||
行情记录模块相关的GUI控制组件
|
行情记录模块相关的GUI控制组件
|
||||||
'''
|
'''
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
from PyQt4.QtGui import QTreeView
|
from PyQt4.QtGui import QTreeView
|
||||||
|
|
||||||
from dataRecorder.drEngine import DrEngine
|
from dataRecorder.drEngine import DrEngine
|
||||||
from eventEngine import *
|
from eventEngine import *
|
||||||
from uiBasicWidget import QtGui, QtCore
|
from uiBasicWidget import QtGui, QtCore
|
||||||
|
|
||||||
|
reload(sys)
|
||||||
|
sys.setdefaultencoding("utf8")
|
||||||
|
|
||||||
|
|
||||||
class TreeItem(object):
|
class TreeItem(object):
|
||||||
def __init__(self, data, parent=None):
|
def __init__(self, data, parent=None):
|
||||||
@ -58,7 +64,7 @@ class TreeItem(object):
|
|||||||
class TreeModel(QtCore.QAbstractItemModel):
|
class TreeModel(QtCore.QAbstractItemModel):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(TreeModel, self).__init__(parent)
|
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):
|
def rootItem(self):
|
||||||
return self.rootItem
|
return self.rootItem
|
||||||
@ -73,7 +79,7 @@ class TreeModel(QtCore.QAbstractItemModel):
|
|||||||
return self.rootItem.columnCount()
|
return self.rootItem.columnCount()
|
||||||
|
|
||||||
def setData(self, index, value, role=None):
|
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()
|
item = index.internalPointer()
|
||||||
if item is None:
|
if item is None:
|
||||||
return False
|
return False
|
||||||
@ -101,13 +107,11 @@ class TreeModel(QtCore.QAbstractItemModel):
|
|||||||
|
|
||||||
item = index.internalPointer()
|
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
|
return QtCore.Qt.Checked if item.data(index.column()) == True else QtCore.Qt.Unchecked
|
||||||
|
|
||||||
if index.column() == 3 and item.parentItem == self.rootItem:
|
if role != QtCore.Qt.DisplayRole or index.column() == 3 and item.parentItem == self.rootItem:
|
||||||
return None
|
|
||||||
|
|
||||||
if role != QtCore.Qt.DisplayRole:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return item.data(index.column())
|
return item.data(index.column())
|
||||||
@ -116,12 +120,12 @@ class TreeModel(QtCore.QAbstractItemModel):
|
|||||||
if not index.isValid():
|
if not index.isValid():
|
||||||
return QtCore.Qt.NoItemFlags
|
return QtCore.Qt.NoItemFlags
|
||||||
|
|
||||||
if index.column() == 0:
|
if index.column() in [0, 4, 5]:
|
||||||
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
|
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
|
||||||
|
|
||||||
item = index.internalPointer()
|
item = index.internalPointer()
|
||||||
if index.column() == 3 and item.parentItem == self.rootItem:
|
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
|
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable
|
||||||
|
|
||||||
@ -170,7 +174,7 @@ class TreeModel(QtCore.QAbstractItemModel):
|
|||||||
return parentItem.childCount()
|
return parentItem.childCount()
|
||||||
|
|
||||||
def hasIndex(self, row, column, parentIndex=None, *args, **kwargs):
|
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 False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -179,11 +183,11 @@ class DrEditWidget(QtGui.QWidget):
|
|||||||
"""行情数据记录引擎管理组件"""
|
"""行情数据记录引擎管理组件"""
|
||||||
signal = QtCore.pyqtSignal(type(Event()))
|
signal = QtCore.pyqtSignal(type(Event()))
|
||||||
|
|
||||||
def __init__(self, drEngine, eventEngine, parent=None):
|
def __init__(self, mainEngine, eventEngine, parent=None):
|
||||||
"""Constructor"""
|
"""Constructor"""
|
||||||
super(DrEditWidget, self).__init__(parent)
|
super(DrEditWidget, self).__init__(parent)
|
||||||
|
|
||||||
self.drEngine = drEngine
|
self.mainEngine = mainEngine
|
||||||
self.eventEngine = eventEngine
|
self.eventEngine = eventEngine
|
||||||
|
|
||||||
# 保存合约详细信息的字典
|
# 保存合约详细信息的字典
|
||||||
@ -217,18 +221,42 @@ class DrEditWidget(QtGui.QWidget):
|
|||||||
vbox.addWidget(self.qTreeView)
|
vbox.addWidget(self.qTreeView)
|
||||||
self.setLayout(vbox)
|
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):
|
def loadData(self):
|
||||||
child = []
|
child = []
|
||||||
yumi = TreeItem([u"玉米", False, False, False], self.model.rootItem)
|
|
||||||
yumi.appendChild(TreeItem([u"c1705", False, False, False], yumi))
|
contractDict = {}
|
||||||
yumi.appendChild(TreeItem([u"c1703", False, False, False], yumi))
|
# contracts = self.mainEngine.getAllContracts()
|
||||||
yumi.appendChild(TreeItem([u"c1707", False, False, False], yumi))
|
# for contract in contracts:
|
||||||
yumi.appendChild(TreeItem([u"c1709", False, False, False], yumi))
|
# contractName = self.getContractChineseName(contract.name)
|
||||||
dianfen = TreeItem([u"淀粉", False, False, False], self.model.rootItem)
|
# if contractDict.has_key(contractName):
|
||||||
dianfen.appendChild(TreeItem([u"d1705", False, False, False], dianfen))
|
# parentItem = contractDict[contractName]
|
||||||
dianfen.appendChild(TreeItem([u"d1703", False, False, False], dianfen))
|
# item = TreeItem([contract.symbol, False, False, False, contract.exchange, "CTP"], parentItem)
|
||||||
dianfen.appendChild(TreeItem([u"d1707", False, False, False], dianfen))
|
# parentItem.appendChild(item)
|
||||||
dianfen.appendChild(TreeItem([u"d1709", False, False, False], dianfen))
|
# 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(yumi)
|
||||||
child.append(dianfen)
|
child.append(dianfen)
|
||||||
@ -276,6 +304,6 @@ if __name__ == '__main__':
|
|||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
|
|
||||||
view = DrEditWidget(DrEngine, EventEngine)
|
view = DrEditWidget(DrEngine, EventEngine)
|
||||||
view.setFixedSize(500, 500)
|
view.setFixedSize(650, 500)
|
||||||
view.show()
|
view.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from dataRecorder.uiDrEdit import DrEditWidget
|
from dataRecorder.uiDrEdit import DrEditWidget
|
||||||
from uiBasicWidget import QtGui, QtCore
|
|
||||||
from eventEngine import *
|
from eventEngine import *
|
||||||
|
from uiBasicWidget import QtGui, QtCore
|
||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
@ -39,11 +39,12 @@ class DrEngineManager(QtGui.QWidget):
|
|||||||
signal = QtCore.pyqtSignal(type(Event()))
|
signal = QtCore.pyqtSignal(type(Event()))
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def __init__(self, drEngine, eventEngine, parent=None):
|
def __init__(self, mainEngine, eventEngine, parent=None):
|
||||||
"""Constructor"""
|
"""Constructor"""
|
||||||
super(DrEngineManager, self).__init__(parent)
|
super(DrEngineManager, self).__init__(parent)
|
||||||
|
|
||||||
self.drEngine = drEngine
|
self.mainEngine = mainEngine
|
||||||
|
self.drEngine = mainEngine.drEngine
|
||||||
self.eventEngine = eventEngine
|
self.eventEngine = eventEngine
|
||||||
|
|
||||||
self.initUi()
|
self.initUi()
|
||||||
@ -154,5 +155,6 @@ class DrEngineManager(QtGui.QWidget):
|
|||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
def openDr(self):
|
def openDr(self):
|
||||||
"""打开行情数据记录组件"""
|
"""打开行情数据记录组件"""
|
||||||
self.mDrEditWidget = DrEditWidget(self.drEngine, self.eventEngine)
|
self.mDrEditWidget = DrEditWidget(self.mainEngine, self.eventEngine)
|
||||||
self.mDrEditWidget.showMaximized()
|
self.mDrEditWidget.setFixedSize(500, 500)
|
||||||
|
self.mDrEditWidget.show()
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
|
|
||||||
import json
|
|
||||||
import csv
|
import csv
|
||||||
import os
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
from PyQt4.QtCore import Qt
|
from PyQt4.QtCore import Qt
|
||||||
|
|
||||||
from eventEngine import *
|
|
||||||
from vtFunction import *
|
from vtFunction import *
|
||||||
from vtGateway import *
|
from vtGateway import *
|
||||||
|
|
||||||
@ -1101,9 +1098,6 @@ class ContractMonitor(BasicMonitor):
|
|||||||
d['productClass'] = {'chinese':u'合约类型', 'cellType':BasicCell}
|
d['productClass'] = {'chinese':u'合约类型', 'cellType':BasicCell}
|
||||||
d['size'] = {'chinese':u'大小', 'cellType':BasicCell}
|
d['size'] = {'chinese':u'大小', 'cellType':BasicCell}
|
||||||
d['priceTick'] = {'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['strikePrice'] = {'chinese':u'期权行权价', 'cellType':BasicCell}
|
||||||
#d['underlyingSymbol'] = {'chinese':u'期权标的物', 'cellType':BasicCell}
|
#d['underlyingSymbol'] = {'chinese':u'期权标的物', 'cellType':BasicCell}
|
||||||
#d['optionType'] = {'chinese':u'期权类型', 'cellType':BasicCell}
|
#d['optionType'] = {'chinese':u'期权类型', 'cellType':BasicCell}
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
from uiBasicWidget import *
|
|
||||||
from ctaAlgo.uiCtaWidget import CtaEngineManager
|
from ctaAlgo.uiCtaWidget import CtaEngineManager
|
||||||
from dataRecorder.uiDrWidget import DrEngineManager
|
from dataRecorder.uiDrWidget import DrEngineManager
|
||||||
from riskManager.uiRmWidget import RmEngineManager
|
from riskManager.uiRmWidget import RmEngineManager
|
||||||
|
from uiBasicWidget import *
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
class MainWindow(QtGui.QMainWindow):
|
class MainWindow(QtGui.QMainWindow):
|
||||||
@ -194,7 +194,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
try:
|
try:
|
||||||
self.widgetDict['drM'].showMaximized()
|
self.widgetDict['drM'].showMaximized()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.widgetDict['drM'] = DrEngineManager(self.mainEngine.drEngine, self.eventEngine)
|
self.widgetDict['drM'] = DrEngineManager(self.mainEngine, self.eventEngine)
|
||||||
self.widgetDict['drM'].showMaximized()
|
self.widgetDict['drM'].showMaximized()
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user