增加了订阅合约编辑
This commit is contained in:
parent
2ee300ad2b
commit
359504b16c
@ -183,12 +183,13 @@ class DrEditWidget(QtGui.QWidget):
|
|||||||
"""行情数据记录引擎管理组件"""
|
"""行情数据记录引擎管理组件"""
|
||||||
signal = QtCore.pyqtSignal(type(Event()))
|
signal = QtCore.pyqtSignal(type(Event()))
|
||||||
|
|
||||||
def __init__(self, mainEngine, eventEngine, parent=None):
|
def __init__(self, drWidget, mainEngine, eventEngine, parent=None):
|
||||||
"""Constructor"""
|
"""Constructor"""
|
||||||
super(DrEditWidget, self).__init__(parent)
|
super(DrEditWidget, self).__init__(parent)
|
||||||
|
self.drWidget = drWidget
|
||||||
self.mainEngine = mainEngine
|
self.mainEngine = mainEngine
|
||||||
self.eventEngine = eventEngine
|
self.eventEngine = eventEngine
|
||||||
|
self.hasChanged = False
|
||||||
|
|
||||||
# 保存合约详细信息的字典
|
# 保存合约详细信息的字典
|
||||||
self.contractDict = {}
|
self.contractDict = {}
|
||||||
@ -198,6 +199,10 @@ class DrEditWidget(QtGui.QWidget):
|
|||||||
self.loadData()
|
self.loadData()
|
||||||
self.registerEvent()
|
self.registerEvent()
|
||||||
|
|
||||||
|
def closeEvent(self, QCloseEvent):
|
||||||
|
if self.hasChanged:
|
||||||
|
self.drWidget.restart()
|
||||||
|
|
||||||
def initUi(self):
|
def initUi(self):
|
||||||
|
|
||||||
vbox = QtGui.QVBoxLayout()
|
vbox = QtGui.QVBoxLayout()
|
||||||
@ -287,9 +292,9 @@ class DrEditWidget(QtGui.QWidget):
|
|||||||
if item.data(3):
|
if item.data(3):
|
||||||
setting["active"][item.parentItem.data(0)] = name
|
setting["active"][item.parentItem.data(0)] = name
|
||||||
if self.mainEngine.drEngine.saveSetting(setting):
|
if self.mainEngine.drEngine.saveSetting(setting):
|
||||||
|
self.hasChanged = True
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
def selectAllTick(self):
|
def selectAllTick(self):
|
||||||
self.selectAll(True, False, True)
|
self.selectAll(True, False, True)
|
||||||
|
|
||||||
@ -321,8 +326,7 @@ class DrEditWidget(QtGui.QWidget):
|
|||||||
def registerEvent(self):
|
def registerEvent(self):
|
||||||
"""注册事件监听"""
|
"""注册事件监听"""
|
||||||
self.signal.connect(self.updateContract)
|
self.signal.connect(self.updateContract)
|
||||||
|
self.eventEngine.register(EVENT_CONTRACT, self.signal.emit)
|
||||||
# self.eventEngine.register(EVENT_CONTRACT, self.signal.emit)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -330,7 +334,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
|
|
||||||
view = DrEditWidget(DrEngine, EventEngine)
|
view = DrEditWidget(None, DrEngine, EventEngine)
|
||||||
view.setFixedSize(650, 500)
|
view.setFixedSize(650, 500)
|
||||||
view.show()
|
view.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
@ -49,16 +49,16 @@ class DrEngineManager(QtGui.QWidget):
|
|||||||
self.mainEngine = mainEngine
|
self.mainEngine = mainEngine
|
||||||
self.drEngine = mainEngine.drEngine
|
self.drEngine = mainEngine.drEngine
|
||||||
self.eventEngine = eventEngine
|
self.eventEngine = eventEngine
|
||||||
|
|
||||||
self.initUi()
|
self.initUi()
|
||||||
self.updateSetting()
|
self.updateSetting()
|
||||||
self.registerEvent()
|
self.registerEvent()
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def initUi(self):
|
def initUi(self):
|
||||||
"""初始化界面"""
|
"""初始化界面"""
|
||||||
self.setWindowTitle(u'行情数据记录工具')
|
self.setWindowTitle(u'行情数据记录工具')
|
||||||
|
|
||||||
# 记录合约配置监控
|
# 记录合约配置监控
|
||||||
tickLabel = QtGui.QLabel(u'Tick记录')
|
tickLabel = QtGui.QLabel(u'Tick记录')
|
||||||
self.tickTable = QtGui.QTableWidget()
|
self.tickTable = QtGui.QTableWidget()
|
||||||
@ -68,14 +68,14 @@ class DrEngineManager(QtGui.QWidget):
|
|||||||
self.tickTable.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
|
self.tickTable.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
|
||||||
self.tickTable.setAlternatingRowColors(True)
|
self.tickTable.setAlternatingRowColors(True)
|
||||||
self.tickTable.setHorizontalHeaderLabels([u'合约代码', u'接口'])
|
self.tickTable.setHorizontalHeaderLabels([u'合约代码', u'接口'])
|
||||||
|
|
||||||
barLabel = QtGui.QLabel(u'Bar记录')
|
barLabel = QtGui.QLabel(u'Bar记录')
|
||||||
self.barTable = QtGui.QTableWidget()
|
self.barTable = QtGui.QTableWidget()
|
||||||
self.barTable.setColumnCount(2)
|
self.barTable.setColumnCount(2)
|
||||||
self.barTable.verticalHeader().setVisible(False)
|
self.barTable.verticalHeader().setVisible(False)
|
||||||
self.barTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
|
self.barTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
|
||||||
self.barTable.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
|
self.barTable.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
|
||||||
self.barTable.setAlternatingRowColors(True)
|
self.barTable.setAlternatingRowColors(True)
|
||||||
self.barTable.setHorizontalHeaderLabels([u'合约代码', u'接口'])
|
self.barTable.setHorizontalHeaderLabels([u'合约代码', u'接口'])
|
||||||
|
|
||||||
activeLabel = QtGui.QLabel(u'主力合约')
|
activeLabel = QtGui.QLabel(u'主力合约')
|
||||||
@ -84,17 +84,17 @@ class DrEngineManager(QtGui.QWidget):
|
|||||||
self.activeTable.verticalHeader().setVisible(False)
|
self.activeTable.verticalHeader().setVisible(False)
|
||||||
self.activeTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
|
self.activeTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
|
||||||
self.activeTable.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
|
self.activeTable.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
|
||||||
self.activeTable.setAlternatingRowColors(True)
|
self.activeTable.setAlternatingRowColors(True)
|
||||||
self.activeTable.setHorizontalHeaderLabels([u'主力代码', u'合约代码'])
|
self.activeTable.setHorizontalHeaderLabels([u'主力代码', u'合约代码'])
|
||||||
|
|
||||||
# 日志监控
|
# 日志监控
|
||||||
self.logMonitor = QtGui.QTextEdit()
|
self.logMonitor = QtGui.QTextEdit()
|
||||||
self.logMonitor.setReadOnly(True)
|
self.logMonitor.setReadOnly(True)
|
||||||
self.logMonitor.setMinimumHeight(600)
|
self.logMonitor.setMinimumHeight(600)
|
||||||
|
|
||||||
# 设置布局
|
# 设置布局
|
||||||
grid = QtGui.QGridLayout()
|
grid = QtGui.QGridLayout()
|
||||||
|
|
||||||
grid.addWidget(tickLabel, 0, 0)
|
grid.addWidget(tickLabel, 0, 0)
|
||||||
grid.addWidget(barLabel, 0, 1)
|
grid.addWidget(barLabel, 0, 1)
|
||||||
grid.addWidget(activeLabel, 0, 2)
|
grid.addWidget(activeLabel, 0, 2)
|
||||||
@ -125,43 +125,46 @@ class DrEngineManager(QtGui.QWidget):
|
|||||||
log = event.dict_['data']
|
log = event.dict_['data']
|
||||||
content = '\t'.join([log.logTime, log.logContent])
|
content = '\t'.join([log.logTime, log.logContent])
|
||||||
self.logMonitor.append(content)
|
self.logMonitor.append(content)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def registerEvent(self):
|
def registerEvent(self):
|
||||||
"""注册事件监听"""
|
"""注册事件监听"""
|
||||||
self.signal.connect(self.updateLog)
|
self.signal.connect(self.updateLog)
|
||||||
self.eventEngine.register(EVENT_DATARECORDER_LOG, self.signal.emit)
|
self.eventEngine.register(EVENT_DATARECORDER_LOG, self.signal.emit)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def updateSetting(self):
|
def updateSetting(self):
|
||||||
"""显示引擎行情记录配置"""
|
"""显示引擎行情记录配置"""
|
||||||
|
|
||||||
self.tickTable.clearContents()
|
self.tickTable.clearContents()
|
||||||
|
self.tickTable.setRowCount(0)
|
||||||
self.barTable.clearContents()
|
self.barTable.clearContents()
|
||||||
|
self.barTable.setRowCount(0)
|
||||||
self.activeTable.clearContents()
|
self.activeTable.clearContents()
|
||||||
|
self.activeTable.setRowCount(0)
|
||||||
|
|
||||||
with open(self.drEngine.settingFileName) as f:
|
with open(self.drEngine.settingFileName) as f:
|
||||||
drSetting = json.load(f)
|
drSetting = json.load(f)
|
||||||
|
|
||||||
if 'tick' in drSetting:
|
if 'tick' in drSetting:
|
||||||
l = drSetting['tick']
|
l = drSetting['tick']
|
||||||
|
|
||||||
for setting in l:
|
for setting in l:
|
||||||
self.tickTable.insertRow(0)
|
self.tickTable.insertRow(0)
|
||||||
self.tickTable.setItem(0, 0, TableCell(setting[0]))
|
self.tickTable.setItem(0, 0, TableCell(setting[0]))
|
||||||
self.tickTable.setItem(0, 1, TableCell(setting[1]))
|
self.tickTable.setItem(0, 1, TableCell(setting[1]))
|
||||||
|
|
||||||
if 'bar' in drSetting:
|
if 'bar' in drSetting:
|
||||||
l = drSetting['bar']
|
l = drSetting['bar']
|
||||||
|
|
||||||
for setting in l:
|
for setting in l:
|
||||||
self.barTable.insertRow(0)
|
self.barTable.insertRow(0)
|
||||||
self.barTable.setItem(0, 0, TableCell(setting[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:
|
if 'active' in drSetting:
|
||||||
d = drSetting['active']
|
d = drSetting['active']
|
||||||
|
|
||||||
for activeSymbol, symbol in d.items():
|
for activeSymbol, symbol in d.items():
|
||||||
self.activeTable.insertRow(0)
|
self.activeTable.insertRow(0)
|
||||||
self.activeTable.setItem(0, 0, TableCell(activeSymbol))
|
self.activeTable.setItem(0, 0, TableCell(activeSymbol))
|
||||||
@ -170,11 +173,11 @@ class DrEngineManager(QtGui.QWidget):
|
|||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
def openDr(self):
|
def openDr(self):
|
||||||
"""打开行情数据记录组件"""
|
"""打开行情数据记录组件"""
|
||||||
self.mDrEditWidget = DrEditWidget(self.mainEngine, self.eventEngine)
|
self.mDrEditWidget = DrEditWidget(self,self.mainEngine, self.eventEngine)
|
||||||
self.mDrEditWidget.setFixedSize(500, 500)
|
self.mDrEditWidget.setFixedSize(800,800)
|
||||||
self.mDrEditWidget.show()
|
self.mDrEditWidget.show()
|
||||||
QObject.connect(self.mDrEditWidget, QtCore.SIGNAL('closed()'), self, QtCore.SIGNAL('restart()'))
|
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
self.updateSetting()
|
self.drEngine.stop()
|
||||||
self.mainEngine.drEngine = DrEngine(self.mainEngine, self.mainEngine.eventEngine)
|
self.updateSetting()
|
||||||
|
self.mainEngine.drEngine = DrEngine(self.mainEngine, self.mainEngine.eventEngine)
|
||||||
|
@ -445,7 +445,7 @@ class MarketMonitor(BasicMonitor):
|
|||||||
self.setFont(BASIC_FONT)
|
self.setFont(BASIC_FONT)
|
||||||
|
|
||||||
# 设置允许排序
|
# 设置允许排序
|
||||||
self.setSorting(True)
|
self.setSorting(False)
|
||||||
|
|
||||||
# 初始化表格
|
# 初始化表格
|
||||||
self.initTable()
|
self.initTable()
|
||||||
|
@ -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, 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