From af7529b529bda08f7c2cc95790d959c20f4a7b39 Mon Sep 17 00:00:00 2001 From: Robofish <1683502971@qq.com> Date: Mon, 4 Aug 2025 20:52:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BA=86=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/code_configuration_interface.py | 48 ++++++++++++++++++++++++++--- app/code_generate_interface.py | 21 +++++++++++++ app/main_window.py | 32 ------------------- app/mini_tool_interface.py | 3 ++ app/tools/analyzing_ioc.py | 7 +++++ app/tools/code_generate.py | 0 6 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 app/code_generate_interface.py create mode 100644 app/tools/analyzing_ioc.py create mode 100644 app/tools/code_generate.py diff --git a/app/code_configuration_interface.py b/app/code_configuration_interface.py index b5f0b33..259d49d 100644 --- a/app/code_configuration_interface.py +++ b/app/code_configuration_interface.py @@ -2,11 +2,13 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QStackedWidget, QSizePolicy from PyQt5.QtCore import Qt from qfluentwidgets import PushSettingCard, FluentIcon, TabBar from qfluentwidgets import TitleLabel, BodyLabel, PushButton, FluentIcon - +from PyQt5.QtWidgets import QFileDialog +import os from .function_fit_interface import FunctionFitInterface from .ai_interface import AIInterface from qfluentwidgets import InfoBar from .tools.update_code import update_code +from .code_generate_interface import CodeGenerateInterface class CodeConfigurationInterface(QWidget): def __init__(self, parent=None): @@ -28,9 +30,10 @@ class CodeConfigurationInterface(QWidget): self.mainPage = QWidget(self) mainLayout = QVBoxLayout(self.mainPage) mainLayout.setAlignment(Qt.AlignTop) - mainLayout.setSpacing(28) - mainLayout.setContentsMargins(48, 48, 48, 48) + mainLayout.setSpacing(28) # 设置间距 + mainLayout.setContentsMargins(48, 48, 48, 48) # 设置内容边距 + #添加空行 title = TitleLabel("MRobot 代码生成") title.setAlignment(Qt.AlignCenter) mainLayout.addWidget(title) @@ -64,10 +67,10 @@ class CodeConfigurationInterface(QWidget): # 信号连接 self.stackedWidget.currentChanged.connect(self.onCurrentIndexChanged) self.tabBar.tabCloseRequested.connect(self.onCloseTab) - # 你可以在此处连接按钮的槽函数 - # self.choose_btn.clicked.connect(self.choose_project_folder) + self.choose_btn.clicked.connect(self.choose_project_folder) # 启用选择项目路径按钮 self.update_template_btn.clicked.connect(self.on_update_template) + def on_update_template(self): def info(parent): InfoBar.success( @@ -85,6 +88,38 @@ class CodeConfigurationInterface(QWidget): ) update_code(parent=self, info_callback=info, error_callback=error) + def choose_project_folder(self): + folder = QFileDialog.getExistingDirectory(self, "选择CUBEMX工程目录") + if not folder: + return + ioc_files = [f for f in os.listdir(folder) if f.endswith('.ioc')] + if ioc_files: + # 检查是否已存在 codeGenPage 标签页 + for i in range(self.stackedWidget.count()): + widget = self.stackedWidget.widget(i) + if widget is not None and widget.objectName() == "codeGenPage": + # 如果已存在,则切换到该标签页,并更新路径显示 + if hasattr(widget, "project_path"): + widget.project_path = folder + if hasattr(widget, "refresh"): + widget.refresh() + self.stackedWidget.setCurrentWidget(widget) + self.tabBar.setCurrentTab("codeGenPage") + return + # 不存在则新建 + code_gen_page = CodeGenerateInterface(folder, self) + self.addSubInterface(code_gen_page, "codeGenPage", "代码生成") + self.stackedWidget.setCurrentWidget(code_gen_page) + self.tabBar.setCurrentTab("codeGenPage") + else: + InfoBar.error( + title="未找到.ioc文件", + content="所选文件夹不是有效的CUBEMX工程目录,请重新选择。", + parent=self, + duration=3000 + ) + + def addSubInterface(self, widget: QWidget, objectName: str, text: str): widget.setObjectName(objectName) self.stackedWidget.addWidget(widget) @@ -104,6 +139,9 @@ class CodeConfigurationInterface(QWidget): def onCloseTab(self, index: int): item = self.tabBar.tabItem(index) widget = self.findChild(QWidget, item.routeKey()) + # 禁止关闭主页 + if widget.objectName() == "mainPage": + return self.stackedWidget.removeWidget(widget) self.tabBar.removeTab(index) widget.deleteLater() diff --git a/app/code_generate_interface.py b/app/code_generate_interface.py new file mode 100644 index 0000000..eb754d6 --- /dev/null +++ b/app/code_generate_interface.py @@ -0,0 +1,21 @@ +from PyQt5.QtWidgets import QWidget, QVBoxLayout +from PyQt5.QtCore import Qt +from qfluentwidgets import TitleLabel, BodyLabel + +class CodeGenerateInterface(QWidget): + def __init__(self, project_path, parent=None): + super().__init__(parent) + self.setObjectName("CodeGenerateInterface") + self.project_path = project_path + + layout = QVBoxLayout(self) + layout.setAlignment(Qt.AlignTop) + layout.setContentsMargins(10, 10, 10, 10) + + title = TitleLabel("代码生成页面") + title.setAlignment(Qt.AlignCenter) + layout.addWidget(title) + + desc = BodyLabel(f"当前工程路径: {self.project_path}") + desc.setAlignment(Qt.AlignCenter) + layout.addWidget(desc) \ No newline at end of file diff --git a/app/main_window.py b/app/main_window.py index 5fafecf..eac4ffc 100644 --- a/app/main_window.py +++ b/app/main_window.py @@ -65,17 +65,6 @@ class MainWindow(FluentWindow): self.addSubInterface(AboutInterface(self), FIF.INFO, self.tr('关于'), position=NavigationItemPosition.BOTTOM) - # self.navigationInterface.addWidget( - # 'startGameButton', - # NavigationBarPushButton(FIF.PLAY, '启动游戏', isSelectable=False), - # self.startGame, - # NavigationItemPosition.BOTTOM) - - # self.navigationInterface.addWidget( - # 'themeButton', - # NavigationBarPushButton(FIF.BRUSH, '主题', isSelectable=False), - # lambda: toggleTheme(lazy=True), - # NavigationItemPosition.BOTTOM) self.themeBtn = NavigationPushButton(FIF.BRUSH, "切换主题", False, self.navigationInterface) self.themeBtn.clicked.connect(lambda: toggleTheme(lazy=True)) @@ -86,27 +75,6 @@ class MainWindow(FluentWindow): NavigationItemPosition.BOTTOM ) - # self.navigationInterface.addWidget( - # 'avatar', - # NavigationBarPushButton(FIF.HEART, '赞赏', isSelectable=False), - # lambda: MessageBoxSupport( - # '支持作者🥰', - # '此程序为免费开源项目,如果你付了钱请立刻退款\n如果喜欢本项目,可以微信赞赏送作者一杯咖啡☕\n您的支持就是作者开发和维护项目的动力🚀', - # './assets/app/images/sponsor.jpg', - # self - # ).exec(), - # NavigationItemPosition.BOTTOM - # ) - - # self.addSubInterface(self.settingInterface, FIF.SETTING, self.tr('设置'), position=NavigationItemPosition.BOTTOM) - - # self.splashScreen.finish() # 结束启动画面 - # self.themeListener = checkThemeChange(self) - - # if not cfg.get_value(base64.b64decode("YXV0b191cGRhdGU=").decode("utf-8")): - # disclaimer(self) - - # main_window.py 只需修改关闭事件 def closeEvent(self, e): # if self.themeListener and self.themeListener.isRunning(): diff --git a/app/mini_tool_interface.py b/app/mini_tool_interface.py index 8e4faea..f2b4b3f 100644 --- a/app/mini_tool_interface.py +++ b/app/mini_tool_interface.py @@ -73,6 +73,9 @@ class MiniToolInterface(QWidget): def onCloseTab(self, index: int): item = self.tabBar.tabItem(index) widget = self.findChild(QWidget, item.routeKey()) + # 禁止关闭主页 + if widget.objectName() == "mainPage": + return self.stackedWidget.removeWidget(widget) self.tabBar.removeTab(index) widget.deleteLater() diff --git a/app/tools/analyzing_ioc.py b/app/tools/analyzing_ioc.py new file mode 100644 index 0000000..e629679 --- /dev/null +++ b/app/tools/analyzing_ioc.py @@ -0,0 +1,7 @@ + + +class analyzing_ioc: + def __init__(self, ioc_data): # 初始化方法,接收IOC数据 + self.ioc_data = ioc_data # 存储IOC数据 + + \ No newline at end of file diff --git a/app/tools/code_generate.py b/app/tools/code_generate.py new file mode 100644 index 0000000..e69de29