优化显示

This commit is contained in:
ares89@wind 2017-02-08 17:55:38 +08:00
parent 4e49f06246
commit 2ee300ad2b
3 changed files with 90 additions and 38 deletions

View File

@ -6,18 +6,15 @@
使用DR_setting.json来配置需要收集的合约以及主力合约代码 使用DR_setting.json来配置需要收集的合约以及主力合约代码
''' '''
import copy
import json import json
import os import os
import copy from datetime import datetime
from collections import OrderedDict
from datetime import datetime, timedelta
from Queue import Queue
from threading import Thread
from eventEngine import *
from vtGateway import VtSubscribeReq, VtLogData
from drBase import * from drBase import *
from eventEngine import *
from vtFunction import todayDate from vtFunction import todayDate
from vtGateway import VtSubscribeReq, VtLogData
######################################################################## ########################################################################
@ -53,6 +50,14 @@ class DrEngine(object):
# 载入设置,订阅行情 # 载入设置,订阅行情
self.loadSetting() self.loadSetting()
def saveSetting(self, setting):
"""保存设置"""
setting['working'] = self.working
with open(self.settingFileName, 'w') as f:
str = json.dumps(setting)
f.write(str)
return True
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def loadSetting(self): def loadSetting(self):
@ -61,8 +66,8 @@ class DrEngine(object):
drSetting = json.load(f) drSetting = json.load(f)
# 如果working设为False则不启动行情记录功能 # 如果working设为False则不启动行情记录功能
working = drSetting['working'] self.working = drSetting['working']
if not working: if not self.working:
return return
if 'tick' in drSetting: if 'tick' in drSetting:

View File

@ -206,11 +206,14 @@ class DrEditWidget(QtGui.QWidget):
vline.setSpacing(2) vline.setSpacing(2)
btnTickAll = QtGui.QPushButton(u"全部记录tick", self) btnTickAll = QtGui.QPushButton(u"全部记录tick", self)
btnBarAll = QtGui.QPushButton(u'全部记录bar', self) btnBarAll = QtGui.QPushButton(u'全部记录bar', self)
btnSaveAll = QtGui.QPushButton(u'保存设置', self)
btnTickAll.clicked.connect(self.selectAllTick) btnTickAll.clicked.connect(self.selectAllTick)
btnBarAll.clicked.connect(self.selectAllBar) btnBarAll.clicked.connect(self.selectAllBar)
btnSaveAll.clicked.connect(self.saveSetting)
vline.addWidget(btnTickAll) vline.addWidget(btnTickAll)
vline.addWidget(btnBarAll) vline.addWidget(btnBarAll)
vline.addWidget(btnSaveAll)
vbox.addLayout(vline) vbox.addLayout(vline)
@ -233,36 +236,60 @@ class DrEditWidget(QtGui.QWidget):
child = [] child = []
contractDict = {} contractDict = {}
# contracts = self.mainEngine.getAllContracts() contracts = self.mainEngine.getAllContracts()
# for contract in contracts: for contract in contracts:
# contractName = self.getContractChineseName(contract.name) contractName = self.getContractChineseName(contract.name)
# if contractDict.has_key(contractName): if contractDict.has_key(contractName):
# parentItem = contractDict[contractName] parentItem = contractDict[contractName]
# item = TreeItem([contract.symbol, False, False, False, contract.exchange, "CTP"], parentItem) item = TreeItem([contract.symbol, False, False, False, contract.exchange, "CTP"], parentItem)
# parentItem.appendChild(item) parentItem.appendChild(item)
# else: else:
# item = TreeItem([contractName, False, False, False, contract.exchange, "CTP"], self.model.rootItem) item = TreeItem([contractName, False, False, False, contract.exchange, "CTP"], self.model.rootItem)
# contractDict[contractName] = item contractDict[contractName] = item
# child.append(item) child.append(item)
# subItem = TreeItem([contract.symbol, False, False, False, contract.exchange, "CTP"], item) subItem = TreeItem([contract.symbol, False, False, False, contract.exchange, "CTP"], item)
# item.appendChild(subItem) item.appendChild(subItem)
yumi = TreeItem([u"玉米", False, False, False, "SH", "CTP"], self.model.rootItem) # 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"c1705", False, False, False, "SH", "CTP"], yumi))
yumi.appendChild(TreeItem([u"c1703", 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"c1707", False, False, False, "SH", "CTP"], yumi))
yumi.appendChild(TreeItem([u"c1709", 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 = 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"d1705", False, False, False, "SH", "CTP"], dianfen))
dianfen.appendChild(TreeItem([u"d1703", 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"d1707", False, False, False, "SH", "CTP"], dianfen))
dianfen.appendChild(TreeItem([u"d1709", 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)
self.model.setDataSource(child) self.model.setDataSource(child)
self.qTreeView.expandAll() self.qTreeView.expandAll()
def saveSetting(self):
setting = {}
setting["tick"] = []
setting["bar"] = []
setting["active"] = {}
queue = Queue()
queue.put(self.model.rootItem)
while queue.qsize() > 0:
item = queue.get()
for child in item.childItems:
queue.put(child)
if item.parentItem is not None and item.parentItem != self.model.rootItem:
name = item.data(0)
interface = item.data(5)
if item.data(1):
setting["tick"].append([name, interface])
if item.data(2):
setting["bar"].append([name, interface])
if item.data(3):
setting["active"][item.parentItem.data(0)] = name
if self.mainEngine.drEngine.saveSetting(setting):
self.close()
def selectAllTick(self): def selectAllTick(self):
self.selectAll(True, False, True) self.selectAll(True, False, True)

View File

@ -6,6 +6,9 @@
import json import json
from PyQt4.QtCore import QObject
from dataRecorder.drEngine import DrEngine
from dataRecorder.uiDrEdit import DrEditWidget from dataRecorder.uiDrEdit import DrEditWidget
from eventEngine import * from eventEngine import *
from uiBasicWidget import QtGui, QtCore from uiBasicWidget import QtGui, QtCore
@ -99,15 +102,22 @@ class DrEngineManager(QtGui.QWidget):
grid.addWidget(self.barTable, 1, 1) grid.addWidget(self.barTable, 1, 1)
grid.addWidget(self.activeTable, 1, 2) grid.addWidget(self.activeTable, 1, 2)
btn = QtGui.QPushButton(u'编辑', self) btnEdit = QtGui.QPushButton(u'编辑', self)
btnRestart = QtGui.QPushButton(u'更新数据', self)
vbox = QtGui.QVBoxLayout() vbox = QtGui.QVBoxLayout()
vbox.addLayout(grid) vbox.addLayout(grid)
vbox.addWidget(btn)
vline = QtGui.QHBoxLayout()
vline.addWidget(btnEdit)
vline.addWidget(btnRestart)
vbox.addLayout(vline)
vbox.addWidget(self.logMonitor) vbox.addWidget(self.logMonitor)
self.setLayout(vbox) self.setLayout(vbox)
btn.clicked.connect(self.openDr) btnEdit.clicked.connect(self.openDr)
btnRestart.clicked.connect(self.restart)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def updateLog(self, event): def updateLog(self, event):
@ -125,6 +135,11 @@ class DrEngineManager(QtGui.QWidget):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def updateSetting(self): def updateSetting(self):
"""显示引擎行情记录配置""" """显示引擎行情记录配置"""
self.tickTable.clearContents()
self.barTable.clearContents()
self.activeTable.clearContents()
with open(self.drEngine.settingFileName) as f: with open(self.drEngine.settingFileName) as f:
drSetting = json.load(f) drSetting = json.load(f)
@ -158,3 +173,8 @@ class DrEngineManager(QtGui.QWidget):
self.mDrEditWidget = DrEditWidget(self.mainEngine, self.eventEngine) self.mDrEditWidget = DrEditWidget(self.mainEngine, self.eventEngine)
self.mDrEditWidget.setFixedSize(500, 500) self.mDrEditWidget.setFixedSize(500, 500)
self.mDrEditWidget.show() self.mDrEditWidget.show()
QObject.connect(self.mDrEditWidget, QtCore.SIGNAL('closed()'), self, QtCore.SIGNAL('restart()'))
def restart(self):
self.updateSetting()
self.mainEngine.drEngine = DrEngine(self.mainEngine, self.mainEngine.eventEngine)