def searchButtonClicked(self): f = FETCH() try: if self.searchEdit.text() == "": self.init_data = f.fetch_backtest_history() self.totalRecord = len(self.init_data) self.totalPage = self.totalRecord // 10 + 1 self.currentPage = 1 self.pageLabel.setText("/" + str(self.totalPage) + "页") self.updateQueryModel() elif self.condisionComboBox.currentText() == "按回测编号查找": self.init_data = f.fuzzy_fetch_backtest_history( self.searchEdit.text(), "ac_id") self.totalRecord = len(self.init_data) self.totalPage = self.totalRecord // 10 + 1 self.currentPage = 1 self.pageLabel.setText("/" + str(self.totalPage) + "页") self.updateQueryModel() elif self.condisionComboBox.currentText() == "按回测类型查找": self.init_data = f.fuzzy_fetch_backtest_history( self.searchEdit.text(), "type") self.totalRecord = len(self.init_data) self.totalPage = self.totalRecord // 10 + 1 self.currentPage = 1 self.pageLabel.setText("/" + str(self.totalPage) + "页") self.updateQueryModel() except KeyError: print( QMessageBox.warning(self, "警告", "没有记录与之匹配", QMessageBox.Yes, QMessageBox.Yes))
def searchButtonClicked(self): f = FETCH() try: if self.searchEdit.text() == "": self.stock_data = f.fetch_stock_list() self.totalRecord = len(self.stock_data) self.totalPage = self.totalRecord // 10 + 1 self.currentPage = 1 self.pageLabel.setText("/" + str(self.totalPage) + "页") self.updateQueryModel() elif self.condisionComboBox.currentText() == "按股票编号查找": self.stock_data = f.fuzzy_fetch_stock_list( self.searchEdit.text(), "code") self.totalRecord = len(self.stock_data) self.totalPage = self.totalRecord // 10 + 1 self.currentPage = 1 self.pageLabel.setText("/" + str(self.totalPage) + "页") self.updateQueryModel() elif self.condisionComboBox.currentText() == "按股票名称查找": self.stock_data = f.fuzzy_fetch_stock_list( self.searchEdit.text(), "name") self.totalRecord = len(self.stock_data) self.totalPage = self.totalRecord // 10 + 1 self.currentPage = 1 self.pageLabel.setText("/" + str(self.totalPage) + "页") self.updateQueryModel() except KeyError: print( QMessageBox.warning(self, "警告", "没有记录与之匹配", QMessageBox.Yes, QMessageBox.Yes))
def initUI(self): self.titlelabel = QLabel(self) self.titleimage = QPixmap('static/title.png') self.titlelabel.setPixmap(self.titleimage) self.hbox = QHBoxLayout() self.hbox.addStretch(1) self.hbox.addWidget(self.titlelabel) self.hbox.addStretch(1) f = FETCH() data = f.fetch_stock_info(self.code) data['股票名称'] = self.name self.grid = QGridLayout() keys = list(data.keys()) values = list(data.values()) for i in range(len(data)): row = i // 4 col = i % 4 label = QLabel() label.setText(keys[i] + ":" + str(values[i])) label.setFont(QFont("仿宋", 15)) self.grid.addWidget(label, row, col) self.vbox = QVBoxLayout() self.vbox.addStretch(1) self.vbox.addLayout(self.hbox) self.vbox.addStretch(1) self.vbox.addLayout(self.grid) self.vbox.addStretch(1) self.setLayout(self.vbox)
def addCode(self): f = FETCH() code = self.pooledit.toPlainText() if code in self.codepool: print(QMessageBox.information(self, "提示", "该股票已经存在于股票池中!", QMessageBox.Yes, QMessageBox.Yes)) elif code not in list(f.fetch_stock_list()['code']): print(QMessageBox.information(self, "提示", "该股票代码不存在!", QMessageBox.Yes, QMessageBox.Yes)) else: self.codepool.append(code) self.pooledit.clear() self.pooltb.setPlainText(' '.join(self.codepool))
def updateKlines(self): self.code = self.codeedit.toPlainText() def change_name(s): l = s.split('/') if len(l[1]) == 1: l[1] = "0" + l[1] if len(l[2]) == 1: l[2] = "0" + l[2] return ("-".join(l)) self.fromtime = change_name(self.fromtimeedit.text()) self.totime = change_name(self.totimeedit.text()) f = FETCH() stock_list = list(f.fetch_stock_list()['code']) if self.code not in stock_list: print(QMessageBox.information(self, "提示", "您输入了不正确的或是已下架的代码!", QMessageBox.Yes, QMessageBox.Yes)) else: self.klineswindow.close() self.klineswindow = KlinesDialog(type="A",code=self.code,fromtime=self.fromtime,totime=self.totime) self.v1box.addWidget(self.klineswindow)
def initUI(self): f = FETCH() self.init_data = f.fetch_backtest_history() self.totalRecord = len(self.init_data) self.totalPage = self.totalRecord // 10 + 1 self.vbox = QVBoxLayout() self.h1box = QHBoxLayout() self.h2box = QHBoxLayout() self.searchEdit = QLineEdit() self.searchEdit.setFixedHeight(32) self.searchEdit.setFont(QFont("仿宋", 15)) self.searchButton = QPushButton("查询") self.searchButton.setFixedHeight(32) self.searchButton.setFont(QFont("仿宋", 15)) self.condisionComboBox = QComboBox() searchCondision = ["按回测编号查找", "按回测类型查找"] self.condisionComboBox.setFixedHeight(32) self.condisionComboBox.setFont(QFont("仿宋", 15)) self.condisionComboBox.addItems(searchCondision) self.h1box.addWidget(self.searchEdit) self.h1box.addWidget(self.condisionComboBox) self.h1box.addWidget(self.searchButton) self.currentPageLabel = QLabel(self) self.currentPageLabel.setFixedWidth(140) self.currentPageLabel.setFont(QFont("仿宋", 12)) self.jumpToLabel = QLabel(self) self.jumpToLabel.setText("跳转到第") self.jumpToLabel.setFont(QFont("仿宋", 12)) self.jumpToLabel.setFixedWidth(90) self.pageEdit = QLineEdit() self.pageEdit.setFixedWidth(30) self.pageEdit.setFont(QFont("仿宋", 12)) self.pageLabel = QLabel(self) self.pageLabel.setText("/" + str(self.totalPage) + "页") self.pageLabel.setFont(QFont("仿宋", 12)) self.pageLabel.setFixedWidth(60) self.jumpToButton = QPushButton(self) self.jumpToButton.setText("跳转") self.jumpToButton.setFont(QFont("仿宋", 12)) self.jumpToButton.setFixedHeight(30) self.jumpToButton.setFixedWidth(60) self.prevButton = QPushButton("前一页") self.prevButton.setFont(QFont("仿宋", 12)) self.prevButton.setFixedHeight(30) self.prevButton.setFixedWidth(80) self.backButton = QPushButton("后一页") self.backButton.setFont(QFont("仿宋", 12)) self.backButton.setFixedHeight(30) self.backButton.setFixedWidth(80) self.prevButton.clicked.connect(self.prevButtonClicked) self.backButton.clicked.connect(self.backButtonClicked) self.jumpToButton.clicked.connect(self.jumpToButtonClicked) self.searchButton.clicked.connect(self.searchButtonClicked) self.detailbutton = QPushButton(self) self.detailbutton.setText("详细信息") self.detailbutton.setFixedWidth(90) self.detailbutton.setFont(QFont("仿宋", 12)) self.detailbutton.clicked.connect(self.detailInfo) self.hbox = QHBoxLayout() self.hbox.addWidget(self.currentPageLabel) self.hbox.addStretch(1) self.hbox.addWidget(self.jumpToLabel) self.hbox.addWidget(self.pageEdit) self.hbox.addWidget(self.pageLabel) self.hbox.addWidget(self.jumpToButton) self.hbox.addStretch(1) self.hbox.addWidget(self.detailbutton) self.hbox.addStretch(1) self.hbox.addWidget(self.prevButton) self.hbox.addWidget(self.backButton) widget = QWidget() widget.setLayout(self.hbox) self.h2box.addWidget(widget) self.tableView = QTableView() self.tableView.horizontalHeader().setStretchLastSection(True) # self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.tableView.horizontalHeader().setSectionResizeMode( QHeaderView.Interactive) self.tableView.verticalHeader().setSectionResizeMode( QHeaderView.Stretch) self.tableView.verticalHeader().setSectionResizeMode( 0, QHeaderView.ResizeToContents) self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers) self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows) self.tableView.setFont(QFont("仿宋", 10)) self.tableView.horizontalHeader().setFont(QFont("仿宋", 12)) self.queryModel = QStandardItemModel(self.pageRecord, 2) self.updateQueryModel() self.vbox.addLayout(self.h1box) self.vbox.addWidget(self.tableView) self.vbox.addLayout(self.h2box) self.setLayout(self.vbox)
def __init__(self, ACid): super().__init__() f = FETCH() self.risk = f.fetch_risk(AC_id=ACid) self.account = f.fetch_account(AC_id=ACid) self.initUI()