def initUi(self): """初始化界面""" self.setWindowTitle(u'股票策略回测') # 按钮 newButton = QtGui.QPushButton(u'新建策略') loadButton = QtGui.QPushButton(u'加载策略') newButton.clicked.connect(self.new) loadButton.clicked.connect(self.load) # 滚动区域,放置所有的CtaStrategyManager self.scrollArea = QtGui.QScrollArea() self.scrollArea.setWidgetResizable(True) # 回测结果区域,Tab显示各项报告 self.tabWidget = QtGui.QTabWidget(self) self.model = QtGui.QStandardItemModel(self) self.summaryView = QtGui.QTableView(self) self.summaryView.setModel(self.model) self.summaryView.horizontalHeader().setStretchLastSection(True) self.summaryView.setEditTriggers(self.summaryView.NoEditTriggers) self.summaryView.setMaximumHeight(400) self.summaryView.resizeColumnsToContents() self.model2 = QtGui.QStandardItemModel(self) self.total_portfoliosView = QtGui.QTableView(self) self.total_portfoliosView.setModel(self.model2) self.total_portfoliosView.horizontalHeader().setStretchLastSection( True) self.total_portfoliosView.setEditTriggers( self.total_portfoliosView.NoEditTriggers) self.total_portfoliosView.setMaximumHeight(400) self.total_portfoliosView.resizeColumnsToContents() self.model3 = QtGui.QStandardItemModel(self) self.future_portfoliosView = QtGui.QTableView(self) self.future_portfoliosView.setModel(self.model3) self.future_portfoliosView.horizontalHeader().setStretchLastSection( True) self.future_portfoliosView.setEditTriggers( self.future_portfoliosView.NoEditTriggers) self.future_portfoliosView.setMaximumHeight(400) self.future_portfoliosView.resizeColumnsToContents() self.model4 = QtGui.QStandardItemModel(self) self.future_positionsView = QtGui.QTableView(self) self.future_positionsView.setModel(self.model4) self.future_positionsView.horizontalHeader().setStretchLastSection( True) self.future_positionsView.setEditTriggers( self.future_positionsView.NoEditTriggers) self.future_positionsView.setMaximumHeight(400) self.future_positionsView.resizeColumnsToContents() self.model5 = QtGui.QStandardItemModel(self) self.tradesView = QtGui.QTableView(self) self.tradesView.setModel(self.model5) self.tradesView.horizontalHeader().setStretchLastSection(True) self.tradesView.horizontalHeader().setVisible(False) self.tradesView.setEditTriggers(self.tradesView.NoEditTriggers) self.tradesView.setMaximumHeight(400) self.tradesView.resizeColumnsToContents() self.tabWidget.addTab(self.summaryView, "summary") self.tabWidget.addTab(self.total_portfoliosView, "total_portfolios") self.tabWidget.addTab(self.future_portfoliosView, "stock_portfolios") self.tabWidget.addTab(self.future_positionsView, "stock_positions") self.tabWidget.addTab(self.tradesView, "trades") # 回测图表 Button1 = QtGui.QPushButton(u'交易资料') Button2 = QtGui.QPushButton(u'周期分析') Button3 = QtGui.QPushButton(u'策略分析') Button4 = QtGui.QPushButton(u'交易分析') # Button1.clicked.connect(self.show1) # Button2.clicked.connect(self.show2) # Button3.clicked.connect(self.show3) # Button4.clicked.connect(self.show4) # 回测组件的日志监控 self.bktLogMonitor = QtGui.QTextEdit() self.bktLogMonitor.setReadOnly(True) self.bktLogMonitor.setMaximumHeight(100) # 设置布局 hbox2 = QtGui.QHBoxLayout() hbox2.addWidget(newButton) hbox2.addWidget(loadButton) hbox2.addStretch() vbox2 = QtGui.QVBoxLayout() vbox2.addWidget(Button1) vbox2.addWidget(Button2) vbox2.addWidget(Button3) vbox2.addWidget(Button4) vbox2.addStretch() hbox3 = QtGui.QHBoxLayout() hbox3.addLayout(vbox2) hbox3.addWidget(self.tabWidget) vbox = QtGui.QVBoxLayout() vbox.addLayout(hbox2) vbox.addWidget(self.scrollArea) vbox.setSpacing(20) vbox.addLayout(hbox3) # vbox.addWidget(self.tabWidget) vbox.setSpacing(20) vbox.addWidget(self.bktLogMonitor) self.setLayout(vbox)
def initUi(self): """初始化界面""" self.setWindowTitle(text.DATA_RECORDER) # 记录合约配置监控 tickLabel = QtGui.QLabel(text.TICK_RECORD) self.tickTable = QtGui.QTableWidget() self.tickTable.setColumnCount(2) self.tickTable.verticalHeader().setVisible(False) self.tickTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers) self.tickTable.horizontalHeader().setResizeMode( QtGui.QHeaderView.Stretch) self.tickTable.setAlternatingRowColors(True) self.tickTable.setHorizontalHeaderLabels( [text.CONTRACT_SYMBOL, text.GATEWAY]) barLabel = QtGui.QLabel(text.BAR_RECORD) 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.setHorizontalHeaderLabels( [text.CONTRACT_SYMBOL, text.GATEWAY]) activeLabel = QtGui.QLabel(text.DOMINANT_CONTRACT) self.activeTable = QtGui.QTableWidget() self.activeTable.setColumnCount(2) self.activeTable.verticalHeader().setVisible(False) self.activeTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers) self.activeTable.horizontalHeader().setResizeMode( QtGui.QHeaderView.Stretch) self.activeTable.setAlternatingRowColors(True) self.activeTable.setHorizontalHeaderLabels( [text.DOMINANT_SYMBOL, text.CONTRACT_SYMBOL]) # 日志监控 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) grid.addWidget(self.tickTable, 1, 0) grid.addWidget(self.barTable, 1, 1) grid.addWidget(self.activeTable, 1, 2) # 原有的布局结构 -> 备份 # vbox = QtGui.QVBoxLayout() # vbox.addLayout(grid) # vbox.addWidget(self.logMonitor) # self.setLayout(vbox) vbox = QtGui.QVBoxLayout() vbox.addLayout(grid) # 在底部增加的一个可切换组件,有价格图和行情两个界面 bottomWidget = QtGui.QTabWidget() priceWidget = PriceWidget(self.eventEngine, self.drEngine) bottomWidget.addTab(priceWidget, u'Price') bottomWidget.addTab(self.logMonitor, u'行情') vbox.addWidget(bottomWidget) self.setLayout(vbox)