2024-02-11 11:38:52 +00:00
|
|
|
# -*- coding:utf-8 -*-
|
2024-02-12 14:19:56 +00:00
|
|
|
import os
|
2024-02-11 13:08:12 +00:00
|
|
|
import sys
|
2024-02-12 09:24:19 +00:00
|
|
|
import fileDataCreating
|
2024-02-12 14:19:56 +00:00
|
|
|
import global_var
|
2024-02-12 09:24:19 +00:00
|
|
|
|
2024-02-11 11:38:52 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from PySide6.QtUiTools import loadUiType
|
2024-02-12 09:24:19 +00:00
|
|
|
from PySide6.QtCore import Slot,Signal,QThread,QMutex,QWaitCondition,QMutexLocker
|
2024-02-11 13:08:12 +00:00
|
|
|
|
2024-02-12 14:19:56 +00:00
|
|
|
global_var._init()
|
2024-02-11 11:38:52 +00:00
|
|
|
# 定义公共路径
|
|
|
|
path = Path(__file__)
|
2024-02-11 13:08:12 +00:00
|
|
|
ui_file_patch = path.parent.parent / "ui" / "ui_main.ui"
|
2024-02-11 11:38:52 +00:00
|
|
|
# 从文件中加载UI定义
|
|
|
|
formType, baseType = loadUiType(str(ui_file_patch))
|
|
|
|
|
2024-02-12 14:19:56 +00:00
|
|
|
class FileThread(QThread):
|
2024-02-12 09:24:19 +00:00
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super().__init__(parent=parent)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
fileDataCreating.main()
|
|
|
|
|
2024-02-11 11:38:52 +00:00
|
|
|
|
|
|
|
class Window(formType, baseType):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(Window, self).__init__()
|
|
|
|
self.setupUi(self)
|
2024-02-12 09:24:19 +00:00
|
|
|
self.setup_thread()
|
|
|
|
|
2024-02-11 11:38:52 +00:00
|
|
|
|
2024-02-11 13:08:12 +00:00
|
|
|
# 输出设置
|
|
|
|
self.Log_Output.document().setMaximumBlockCount(100)
|
|
|
|
self.Log_Output.ensureCursorVisible()
|
|
|
|
|
2024-02-12 09:24:19 +00:00
|
|
|
@Slot() #声明槽函数
|
2024-02-11 13:08:12 +00:00
|
|
|
def start(self):
|
|
|
|
self.Log_Output.append('点击了开始按钮')
|
2024-02-11 14:06:23 +00:00
|
|
|
# 输入框参数校验
|
|
|
|
num = self.tabWidget.currentIndex()
|
|
|
|
if num == 0:
|
|
|
|
self.check_file_input()
|
|
|
|
else:
|
|
|
|
self.conntest()
|
|
|
|
# 开始运行
|
|
|
|
if num == 0:
|
2024-02-12 09:24:19 +00:00
|
|
|
self.start_thread()
|
2024-02-11 14:06:23 +00:00
|
|
|
else:
|
|
|
|
self.start_run_db()
|
2024-02-12 14:28:36 +00:00
|
|
|
# 按钮置灰
|
|
|
|
self.startButton.setEnabled(not self.startButton.isEnabled())
|
|
|
|
|
2024-02-11 13:08:12 +00:00
|
|
|
|
2024-02-12 09:24:19 +00:00
|
|
|
@Slot()
|
2024-02-11 13:08:12 +00:00
|
|
|
def stop(self):
|
|
|
|
self.Log_Output.append('点击了停止按钮')
|
2024-02-11 14:06:23 +00:00
|
|
|
num = self.tabWidget.currentIndex()
|
|
|
|
if num == 0:
|
|
|
|
self.stop_run_file()
|
|
|
|
else:
|
|
|
|
self.stop_run_db()
|
2024-02-12 14:28:36 +00:00
|
|
|
# 按钮恢复
|
|
|
|
self.startButton.setEnabled(not self.startButton.isEnabled())
|
2024-02-11 13:08:12 +00:00
|
|
|
|
2024-02-12 09:24:19 +00:00
|
|
|
@Slot()
|
2024-02-11 13:08:12 +00:00
|
|
|
def conntest(self):
|
|
|
|
self.Log_Output.append('点击了测试连接按钮')
|
2024-02-11 14:06:23 +00:00
|
|
|
self.check_db_input()
|
|
|
|
# TODO(MH):校验连接信息
|
|
|
|
self.Log_Output.append('数据库连接成功')
|
|
|
|
|
2024-02-12 09:24:19 +00:00
|
|
|
|
|
|
|
def setup_thread(self):
|
2024-02-12 14:19:56 +00:00
|
|
|
self.thread = FileThread()
|
|
|
|
global_var.set_value('start_flag',True)
|
|
|
|
self.thread_running = global_var.get_value('start_flag')
|
|
|
|
|
2024-02-12 09:24:19 +00:00
|
|
|
|
|
|
|
def start_thread(self):
|
|
|
|
if self.thread_running:
|
|
|
|
self.thread.start()
|
2024-02-12 14:19:56 +00:00
|
|
|
else:
|
|
|
|
self.setup_thread()
|
|
|
|
self.thread.start()
|
2024-02-12 09:24:19 +00:00
|
|
|
|
|
|
|
|
2024-02-11 14:06:23 +00:00
|
|
|
def check_file_input(self):
|
|
|
|
self.Log_Output.append('文件参数校验通过')
|
|
|
|
|
|
|
|
|
|
|
|
def check_db_input(self):
|
|
|
|
self.Log_Output.append('数据库参数校验通过,开始连接数据库测试。。。')
|
|
|
|
|
|
|
|
|
|
|
|
def start_run_file(self):
|
2024-02-12 09:24:19 +00:00
|
|
|
|
|
|
|
# 调用文件处理脚本
|
|
|
|
self.Log_Output.append('开始生成文件。。。')
|
|
|
|
|
2024-02-11 14:06:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
def start_run_db(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def stop_run_file(self):
|
2024-02-12 14:28:36 +00:00
|
|
|
# 终止线程的事件循环
|
2024-02-12 14:19:56 +00:00
|
|
|
global_var.set_value('start_flag',False)
|
2024-02-12 14:28:36 +00:00
|
|
|
self.thread.quit()
|
|
|
|
# 标记线程停止
|
|
|
|
self.thread_running = global_var.get_value('start_flag')
|
2024-02-12 09:24:19 +00:00
|
|
|
|
2024-02-11 14:06:23 +00:00
|
|
|
|
2024-02-11 11:38:52 +00:00
|
|
|
|
2024-02-11 14:06:23 +00:00
|
|
|
def stop_run_db(self):
|
|
|
|
pass
|
2024-02-11 11:38:52 +00:00
|
|
|
|