- 删除破损文件: main.py/main.ui/main_ui.py - 删除 runtime_hook.py(归宿主维护),清除 tools/ 目录 - 合并 export_runtime/pack_zip/verify_companions 到 build_pyd.py - 修复注释: docstring 参数与实际签名不一致、过时引用、拼写错误 - 修复日志: 消除静默吞异常、删冗余 log+raise、补缺失日志 - 精简 .gitignore
195 lines
7.2 KiB
Python
195 lines
7.2 KiB
Python
import os
|
|
import logging
|
|
|
|
from pathlib import Path
|
|
from .mil_tool_ui import Ui_FrameMILTool
|
|
from PySide6.QtGui import *
|
|
from PySide6.QtCore import *
|
|
from PySide6.QtWidgets import *
|
|
|
|
from .mil_project import MILProject
|
|
|
|
from mil.core import Config
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
CONF = "mil.json"
|
|
|
|
class FrameMILTool(QFrame,Ui_FrameMILTool):
|
|
def __init__(self,workspace:Path, parent=None):
|
|
super().__init__(parent)
|
|
self.setupUi(self)
|
|
|
|
self.initUI(workspace)
|
|
|
|
|
|
def initUI(self, workspace:Path):
|
|
self.workspace = workspace
|
|
if not self.workspace.exists():
|
|
os.mkdir(self.workspace)
|
|
self.conf = self.workspace.joinpath(CONF)
|
|
|
|
self.config = Config(self.conf)
|
|
if self.config.check_path():
|
|
self.config.load_config()
|
|
self.checkBox.setChecked(self.config.AddTimeEn)
|
|
if self.config.GeratePath:
|
|
self.radioButtonData.setChecked(True)
|
|
else:
|
|
self.radioButtonFile.setChecked(True)
|
|
else:
|
|
self.config.save_config()
|
|
self.update_config()
|
|
|
|
for key in self.config.ItemConfigs.keys():
|
|
self.add_pro_event(key)
|
|
|
|
self.menu = QMenu(self.listWidget)
|
|
self.new_pro_acction = QAction("新建项目", self)
|
|
self.new_pro_acction.triggered.connect(self.on_new_pro_event)
|
|
|
|
self.del_pro_acction = QAction("删除项目", self)
|
|
self.del_pro_acction.triggered.connect(self.on_del_pro_event)
|
|
self.menu.addAction(self.new_pro_acction)
|
|
self.menu.addAction(self.del_pro_acction)
|
|
|
|
self.DataPath.setReadOnly(True)
|
|
self.FilePath.setReadOnly(True)
|
|
|
|
self.DataButton.clicked.connect(self.on_load_data_path)
|
|
self.FileButton.clicked.connect(self.on_load_file_path)
|
|
|
|
self.checkBox.toggled.connect(self.on_select_add_time_en)
|
|
self.radioButtonData.toggled.connect(self.on_select_gerate_path)
|
|
self.comboBox.currentTextChanged.connect(self.on_text_changed_event)
|
|
self.listWidget.customContextMenuRequested.connect(self.on_ContextMenuRequested)
|
|
|
|
def update_config(self):
|
|
self.comboBox.clear()
|
|
if self.config.ItemConfigs.keys().__len__() == 0:
|
|
return
|
|
|
|
self.lock_event = True
|
|
for key in self.config.ItemConfigs.keys():
|
|
self.comboBox.addItem(key)
|
|
self.lock_event = False
|
|
|
|
|
|
if self.config.CurrProject == "":
|
|
self.config.CurrProject = self.comboBox.currentText()
|
|
self.config.save_config()
|
|
|
|
self.DataPath.setText(self.config.ItemConfigs[self.comboBox.currentText()]["DataPath"])
|
|
self.FilePath.setText(self.config.ItemConfigs[self.comboBox.currentText()]["FilePath"])
|
|
else:
|
|
self.comboBox.setCurrentText(self.config.CurrProject)
|
|
self.DataPath.setText(self.config.ItemConfigs[self.config.CurrProject]["DataPath"])
|
|
self.FilePath.setText(self.config.ItemConfigs[self.config.CurrProject]["FilePath"])
|
|
|
|
def on_update_data_path_event(self,name,data_path):
|
|
if name == self.comboBox.currentText():
|
|
self.DataPath.setText(data_path)
|
|
|
|
def on_update_file_path_event(self,name,file_path):
|
|
if name == self.comboBox.currentText():
|
|
self.FilePath.setText(file_path)
|
|
|
|
def on_select_gerate_path(self,checked):
|
|
self.config.GeratePath = checked
|
|
self.config.save_config()
|
|
|
|
def on_select_add_time_en(self,checked):
|
|
self.config.AddTimeEn = checked
|
|
self.config.save_config()
|
|
|
|
def on_ContextMenuRequested(self,point:QPoint):
|
|
self.menu.exec_(QCursor.pos())
|
|
|
|
def on_text_changed_event(self,text:str):
|
|
if text == "" or self.lock_event:
|
|
return
|
|
|
|
self.config.CurrProject = text
|
|
self.config.save_config()
|
|
|
|
self.DataPath.setText(self.config.ItemConfigs[self.config.CurrProject]["DataPath"])
|
|
self.FilePath.setText(self.config.ItemConfigs[self.config.CurrProject]["FilePath"])
|
|
|
|
def on_new_pro_event(self):
|
|
item = QListWidgetItem()
|
|
mil_project = MILProject(self.config)
|
|
mil_project.update_item_name_signal.connect(self.update_config)
|
|
mil_project.update_item_data_path_signal.connect(self.on_update_data_path_event)
|
|
mil_project.update_item_file_path_signal.connect(self.on_update_file_path_event)
|
|
|
|
item.setSizeHint(QSize(mil_project.sizeHint().width(), 150))
|
|
self.listWidget.addItem(item)
|
|
self.listWidget.setCurrentItem(item)
|
|
self.listWidget.setItemWidget(item, mil_project)
|
|
|
|
def add_pro_event(self, name):
|
|
item = QListWidgetItem()
|
|
mil_project = MILProject(self.config, name=name)
|
|
mil_project.update_item_name_signal.connect(self.update_config)
|
|
mil_project.update_item_data_path_signal.connect(self.on_update_data_path_event)
|
|
mil_project.update_item_file_path_signal.connect(self.on_update_file_path_event)
|
|
|
|
item.setSizeHint(QSize(mil_project.sizeHint().width(), 150))
|
|
self.listWidget.addItem(item)
|
|
self.listWidget.setCurrentItem(item)
|
|
self.listWidget.setItemWidget(item, mil_project)
|
|
|
|
def on_del_pro_event(self):
|
|
mil_project = self.listWidget.itemWidget(self.listWidget.currentItem())
|
|
if not isinstance(mil_project, MILProject):
|
|
logger.error("on_del_pro_event: 当前项不是 MILProject 实例")
|
|
return
|
|
|
|
if self.config.CurrProject == mil_project.name:
|
|
self.config.CurrProject = ""
|
|
|
|
self.listWidget.takeItem(self.listWidget.currentRow())
|
|
self.config.ItemConfigs.pop(mil_project.name)
|
|
self.config.save_config()
|
|
|
|
self.update_config()
|
|
|
|
def search_mil_pro_item(self, name):
|
|
for mil_project in self.listWidget.findChildren(MILProject):
|
|
if not isinstance(mil_project,MILProject):
|
|
return
|
|
if mil_project.name == name:
|
|
return mil_project
|
|
return None
|
|
|
|
def on_load_data_path(self):
|
|
data_path = self.DataPath.text()
|
|
if os.path.exists(data_path):
|
|
path,type = QFileDialog.getOpenFileName(self, "选择文件", data_path,"Excel工作簿(*.xlsx)")
|
|
else:
|
|
path,type = QFileDialog.getOpenFileName(self, "选择文件", os.getcwd(),"Excel工作簿(*.xlsx)")
|
|
self.DataPath.setText(path)
|
|
if not path:
|
|
return
|
|
|
|
self.config.ItemConfigs[self.config.CurrProject]["DataPath"] = path
|
|
mil_project = self.search_mil_pro_item(self.config.CurrProject)
|
|
mil_project.lineEditDataPath.setText(path)
|
|
self.config.save_config()
|
|
|
|
|
|
def on_load_file_path(self):
|
|
file_path = self.FilePath.text()
|
|
if os.path.exists(file_path):
|
|
path,type = QFileDialog.getOpenFileName(self, "选择文件", file_path,"Excel工作簿(*.xlsx)")
|
|
else:
|
|
path,type = QFileDialog.getOpenFileName(self, "选择文件", os.getcwd(),"Excel工作簿(*.xlsx)")
|
|
self.FilePath.setText(path)
|
|
if not path:
|
|
return
|
|
|
|
self.config.ItemConfigs[self.config.CurrProject]["FilePath"] = path
|
|
mil_project = self.search_mil_pro_item(self.config.CurrProject)
|
|
mil_project.lineEditFilePath.setText(path)
|
|
self.config.save_config()
|