增加了订阅合约编辑

This commit is contained in:
sunlit@home 2017-02-08 23:05:33 +08:00
parent 2ee300ad2b
commit 359504b16c
4 changed files with 38 additions and 31 deletions

View File

@ -183,12 +183,13 @@ class DrEditWidget(QtGui.QWidget):
"""行情数据记录引擎管理组件"""
signal = QtCore.pyqtSignal(type(Event()))
def __init__(self, mainEngine, eventEngine, parent=None):
def __init__(self, drWidget, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(DrEditWidget, self).__init__(parent)
self.drWidget = drWidget
self.mainEngine = mainEngine
self.eventEngine = eventEngine
self.hasChanged = False
# 保存合约详细信息的字典
self.contractDict = {}
@ -198,6 +199,10 @@ class DrEditWidget(QtGui.QWidget):
self.loadData()
self.registerEvent()
def closeEvent(self, QCloseEvent):
if self.hasChanged:
self.drWidget.restart()
def initUi(self):
vbox = QtGui.QVBoxLayout()
@ -287,9 +292,9 @@ class DrEditWidget(QtGui.QWidget):
if item.data(3):
setting["active"][item.parentItem.data(0)] = name
if self.mainEngine.drEngine.saveSetting(setting):
self.hasChanged = True
self.close()
def selectAllTick(self):
self.selectAll(True, False, True)
@ -321,8 +326,7 @@ class DrEditWidget(QtGui.QWidget):
def registerEvent(self):
"""注册事件监听"""
self.signal.connect(self.updateContract)
# self.eventEngine.register(EVENT_CONTRACT, self.signal.emit)
self.eventEngine.register(EVENT_CONTRACT, self.signal.emit)
if __name__ == '__main__':
@ -330,7 +334,7 @@ if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
view = DrEditWidget(DrEngine, EventEngine)
view = DrEditWidget(None, DrEngine, EventEngine)
view.setFixedSize(650, 500)
view.show()
sys.exit(app.exec_())

View File

@ -49,16 +49,16 @@ class DrEngineManager(QtGui.QWidget):
self.mainEngine = mainEngine
self.drEngine = mainEngine.drEngine
self.eventEngine = eventEngine
self.initUi()
self.updateSetting()
self.registerEvent()
self.registerEvent()
#----------------------------------------------------------------------
def initUi(self):
"""初始化界面"""
self.setWindowTitle(u'行情数据记录工具')
# 记录合约配置监控
tickLabel = QtGui.QLabel(u'Tick记录')
self.tickTable = QtGui.QTableWidget()
@ -68,14 +68,14 @@ class DrEngineManager(QtGui.QWidget):
self.tickTable.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
self.tickTable.setAlternatingRowColors(True)
self.tickTable.setHorizontalHeaderLabels([u'合约代码', u'接口'])
barLabel = QtGui.QLabel(u'Bar记录')
self.barTable = QtGui.QTableWidget()
self.barTable.setColumnCount(2)
self.barTable.verticalHeader().setVisible(False)
self.barTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
self.barTable.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
self.barTable.setAlternatingRowColors(True)
self.barTable.setAlternatingRowColors(True)
self.barTable.setHorizontalHeaderLabels([u'合约代码', u'接口'])
activeLabel = QtGui.QLabel(u'主力合约')
@ -84,17 +84,17 @@ class DrEngineManager(QtGui.QWidget):
self.activeTable.verticalHeader().setVisible(False)
self.activeTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
self.activeTable.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
self.activeTable.setAlternatingRowColors(True)
self.activeTable.setAlternatingRowColors(True)
self.activeTable.setHorizontalHeaderLabels([u'主力代码', u'合约代码'])
# 日志监控
self.logMonitor = QtGui.QTextEdit()
self.logMonitor.setReadOnly(True)
self.logMonitor.setMinimumHeight(600)
# 设置布局
grid = QtGui.QGridLayout()
grid.addWidget(tickLabel, 0, 0)
grid.addWidget(barLabel, 0, 1)
grid.addWidget(activeLabel, 0, 2)
@ -125,43 +125,46 @@ class DrEngineManager(QtGui.QWidget):
log = event.dict_['data']
content = '\t'.join([log.logTime, log.logContent])
self.logMonitor.append(content)
#----------------------------------------------------------------------
def registerEvent(self):
"""注册事件监听"""
self.signal.connect(self.updateLog)
self.eventEngine.register(EVENT_DATARECORDER_LOG, self.signal.emit)
#----------------------------------------------------------------------
def updateSetting(self):
"""显示引擎行情记录配置"""
self.tickTable.clearContents()
self.tickTable.setRowCount(0)
self.barTable.clearContents()
self.barTable.setRowCount(0)
self.activeTable.clearContents()
self.activeTable.setRowCount(0)
with open(self.drEngine.settingFileName) as f:
drSetting = json.load(f)
if 'tick' in drSetting:
l = drSetting['tick']
for setting in l:
self.tickTable.insertRow(0)
self.tickTable.setItem(0, 0, TableCell(setting[0]))
self.tickTable.setItem(0, 1, TableCell(setting[1]))
if 'bar' in drSetting:
l = drSetting['bar']
for setting in l:
self.barTable.insertRow(0)
self.barTable.setItem(0, 0, TableCell(setting[0]))
self.barTable.setItem(0, 1, TableCell(setting[1]))
self.barTable.setItem(0, 1, TableCell(setting[1]))
if 'active' in drSetting:
d = drSetting['active']
for activeSymbol, symbol in d.items():
self.activeTable.insertRow(0)
self.activeTable.setItem(0, 0, TableCell(activeSymbol))
@ -170,11 +173,11 @@ class DrEngineManager(QtGui.QWidget):
# ----------------------------------------------------------------------
def openDr(self):
"""打开行情数据记录组件"""
self.mDrEditWidget = DrEditWidget(self.mainEngine, self.eventEngine)
self.mDrEditWidget.setFixedSize(500, 500)
self.mDrEditWidget = DrEditWidget(self,self.mainEngine, self.eventEngine)
self.mDrEditWidget.setFixedSize(800,800)
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)
self.drEngine.stop()
self.updateSetting()
self.mainEngine.drEngine = DrEngine(self.mainEngine, self.mainEngine.eventEngine)

View File

@ -445,7 +445,7 @@ class MarketMonitor(BasicMonitor):
self.setFont(BASIC_FONT)
# 设置允许排序
self.setSorting(True)
self.setSorting(False)
# 初始化表格
self.initTable()

View File

@ -194,7 +194,7 @@ class MainWindow(QtGui.QMainWindow):
try:
self.widgetDict['drM'].showMaximized()
except KeyError:
self.widgetDict['drM'] = DrEngineManager(self.mainEngine, self.eventEngine)
self.widgetDict['drM'] = DrEngineManager(self.mainEngine, self.eventEngine)
self.widgetDict['drM'].showMaximized()
#----------------------------------------------------------------------