期货日数据维护与使用_日数据维护_界面代码

发布时间:2024年01月06日

目录

写在前面

界面图示

?编辑?代码

执行代码


写在前面

本文默认已经创建了项目,如果不知道如何创建一个空项目的,请参看以下两篇博文

PyQt5将项目搬到一个新的虚拟环境中
https://blog.csdn.net/m0_37967652/article/details/122625280
python_PyQt5开发工具结构基础
https://blog.csdn.net/m0_37967652/article/details/131969032

界面图示

?代码

class DailyUpdateWidget(QtWidgets.QWidget):
    signal_excute = QtCore.pyqtSignal(object)
    def __init__(self):
        super().__init__()
        self.thread: Thread = None
        self.init_data()
        self.init_ui()
        self.register_event()
        self.init_start()
        pass
    def init_data(self):
        self.left_table_headers = ['品种代码', '合约', '交割年', '最新日期']
        pass
    def init_ui(self):
        self.setWindowTitle('日数据更新(优矿)')
        self.setMinimumHeight(600)
        self.setMinimumWidth(800)

        self.caculate_progress = QtWidgets.QProgressBar()
        self.caculate_status_label = QtWidgets.QLabel()

        layout_progress = QtWidgets.QHBoxLayout()
        layout_progress.addWidget(self.caculate_progress)
        layout_progress.addWidget(self.caculate_status_label)

        deliYear_tip = QtWidgets.QLabel('设置计算要使用的交割年份:')
        self.deliYear_spinbox = QtWidgets.QSpinBox()
        self.deliYear_spinbox.setMinimum(1900)
        self.deliYear_spinbox.setMaximum(9999)
        self.deliYear_spinbox.setValue(datetime.datetime.now().year)
        layout_one = QtWidgets.QHBoxLayout()
        layout_one.addWidget(deliYear_tip)
        layout_one.addWidget(self.deliYear_spinbox)
        layout_one.addStretch(1)

        choice_symbol_dir_btn = QtWidgets.QPushButton('选择合约所在目录')
        choice_symbol_dir_btn.clicked.connect(self.choice_symbol_dir_btn_clicked)
        self.choice_symbol_dir_lineedit = QtWidgets.QLineEdit()
        self.choice_symbol_dir_lineedit.setReadOnly(True)
        excute_step_one_btn = QtWidgets.QPushButton('执行')
        excute_step_one_btn.clicked.connect(self.excute_step_one_btn_clicked)

        layout_two = QtWidgets.QHBoxLayout()
        layout_two.addWidget(choice_symbol_dir_btn)
        layout_two.addWidget(self.choice_symbol_dir_lineedit)
        layout_two.addWidget(excute_step_one_btn)

        self.new_symbol_json_down_btn = QtWidgets.QPushButton('新增合约json下载')
        self.new_symbol_json_down_btn.clicked.connect(self.new_symbol_json_down_btn_clicked)
        self.append_symbol_json_down_btn = QtWidgets.QPushButton('追加合约json下载')
        self.append_symbol_json_down_btn.clicked.connect(self.append_symbol_json_down_btn_clicked)
        self.new_symbol_json_down_btn.setDisabled(True)
        self.append_symbol_json_down_btn.setDisabled(True)
        layout_three = QtWidgets.QHBoxLayout()
        layout_three.addWidget(self.new_symbol_json_down_btn)
        layout_three.addWidget(self.append_symbol_json_down_btn)

        choice_symbol_dir_label = QtWidgets.QLabel('提示:从优矿中下载最新的合约列表,放在一个目录中,选择该目录。执行完后,下载要更新的合约json文件')

        # 分界线 s
        h_line_one = QtWidgets.QFrame()
        h_line_one.setFrameShape(QtWidgets.QFrame.HLine)
        h_line_one.setFrameShadow(QtWidgets.QFrame.Sunken)
        # 分界线 e

        self.choice_daily_dir_btn = QtWidgets.QPushButton('选择日数据所在目录')
        self.choice_daily_dir_btn.clicked.connect(self.choice_daily_dir_btn_clicked)
        self.choice_daily_dir_btn.setDisabled(True)
        self.choice_daily_dir_lineedit = QtWidgets.QLineEdit()
        self.choice_daily_dir_lineedit.setReadOnly(True)
        excute_step_two_btn = QtWidgets.QPushButton('执行')
        excute_step_two_btn.clicked.connect(self.excute_step_two_btn_clicked)
        layout_four = QtWidgets.QHBoxLayout()
        layout_four.addWidget(self.choice_daily_dir_btn)
        layout_four.addWidget(self.choice_daily_dir_lineedit)
        layout_four.addWidget(excute_step_two_btn)

        choice_daily_dir_label = QtWidgets.QLabel('提示:从优矿在下载待更新的日数据,放在一个目录中,选择该目录')

        # 分界线 s
        h_line_two = QtWidgets.QFrame()
        h_line_two.setFrameShape(QtWidgets.QFrame.HLine)
        h_line_two.setFrameShadow(QtWidgets.QFrame.Sunken)
        # 分界线 e

        tip_label = QtWidgets.QLabel('当前在线合约:')
        refresh_btn = QtWidgets.QPushButton('刷新')
        refresh_btn.clicked.connect(self.refresh_btn_clicked)
        download_btn = QtWidgets.QPushButton('下载')
        download_btn.clicked.connect(self.download_btn_clicked)

        layout_five = QtWidgets.QHBoxLayout()
        layout_five.addWidget(tip_label)
        layout_five.addStretch(1)
        layout_five.addWidget(refresh_btn)
        layout_five.addWidget(download_btn)

        self.left_table = QtWidgets.QTableWidget()
        self.left_table.setColumnCount(len(self.left_table_headers))
        self.left_table.setHorizontalHeaderLabels(self.left_table_headers)

        layout_six = QtWidgets.QVBoxLayout()
        layout_six.addLayout(layout_five)
        layout_six.addWidget(self.left_table)

        log_label = QtWidgets.QLabel('日志:')
        self.log_textedit = QtWidgets.QTextEdit()
        self.log_textedit.setReadOnly(True)
        layout_seven = QtWidgets.QVBoxLayout()
        layout_seven.addWidget(log_label)
        layout_seven.addWidget(self.log_textedit)

        layout_eight = QtWidgets.QHBoxLayout()
        layout_eight.addLayout(layout_six)
        layout_eight.addLayout(layout_seven)

        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(layout_progress)
        layout.addLayout(layout_one)
        layout.addLayout(layout_two)
        layout.addLayout(layout_three)
        layout.addWidget(choice_symbol_dir_label)
        layout.addWidget(h_line_one)
        layout.addLayout(layout_four)
        layout.addWidget(choice_daily_dir_label)
        layout.addWidget(h_line_two)
        layout.addLayout(layout_eight)
        self.setLayout(layout)
        pass
    def register_event(self):
        self.signal_excute.connect(self.process_excute_event)
        pass
    def process_excute_event(self,data:Dict):
        mark_str = data['mark_str']
        pass
    def init_start(self):
        self.progress_init()
        pass
    def choice_symbol_dir_btn_clicked(self):
        pass
    def excute_step_one_btn_clicked(self):
        pass
    def new_symbol_json_down_btn_clicked(self):
        pass
    def append_symbol_json_down_btn_clicked(self):
        pass
    def choice_daily_dir_btn_clicked(self):
        pass
    def excute_step_two_btn_clicked(self):
        pass
    def refresh_btn_clicked(self):
        pass
    def download_btn_clicked(self):
        pass
    def start_caculate_thread(self,mark_str:str,data:Dict[str,Any]=None):
        if self.thread:
            QtWidgets.QMessageBox.information(
                self,
                '提示',
                '线程正在执行任务,请稍后...',
                QtWidgets.QMessageBox.Yes
            )
            return
        self.thread = Thread(
            target=self.running_caculate_thread,
            args=(
                mark_str,data,
            )
        )
        self.thread.start()
        self.progress_busy()
        pass
    def running_caculate_thread(self,mark_str:str,data:Dict[str,Any]):
        pass
    def progress_init(self) -> None:
        self.caculate_progress.setValue(0)
        self.caculate_status_label.setText('无任务')
    def progress_busy(self) -> None:
        self.caculate_progress.setRange(0, 0)
        self.caculate_status_label.setText('正在执行')
    def progress_finished(self) -> None:
        self.caculate_progress.setRange(0, 100)
        self.caculate_progress.setValue(100)
        self.caculate_status_label.setText('执行完毕')
        pass
    def closeEvent(self, a0: typing.Optional[QtGui.QCloseEvent]) -> None:
        self.close()
    pass

执行代码

if __name__ == '__main__':
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    app = QtWidgets.QApplication(sys.argv)

    main_window = DailyUpdateWidget()
    main_window.show()
    app.exec()
    pass
文章来源:https://blog.csdn.net/m0_37967652/article/details/135428779
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。