From df95e7d0b00d4382f003b7ea6d1099254331d651 Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Fri, 2 Aug 2024 20:59:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E7=8B=AC=E5=B0=81=E8=A3=85=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=AE=9E=E7=8E=B0=E7=AA=97=E5=8F=A3=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E7=BB=84=E4=BB=B6=E5=92=8C=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 1 + WindowModule.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 2 +- mainwindow.py | 32 +-------------------------- 4 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 WindowModule.py diff --git a/Makefile b/Makefile index e450108..c0e19d3 100755 --- a/Makefile +++ b/Makefile @@ -137,6 +137,7 @@ copy-files: cp -rv InstallRuntime deb/opt/apps/deepin-wine-runner cp -rv globalenv.py deb/opt/apps/deepin-wine-runner cp -rv local deb/opt/apps/deepin-wine-runner + cp -rv WindowModule.py deb/opt/apps/deepin-wine-runner mkdir -pv deb/opt/apps/deepin-wine-runner/entries/ cp -rv deb/usr/share/applications deb/opt/apps/deepin-wine-runner/entries/applications python3 UpdateTime.py diff --git a/WindowModule.py b/WindowModule.py new file mode 100644 index 0000000..21bbf9f --- /dev/null +++ b/WindowModule.py @@ -0,0 +1,58 @@ +# 用于实现窗口模块化的组件和调用封装 +import os +import sys +import PyQt5.QtWidgets as QtWidgets + +moduleNameList = { + "mainwindow": { + "Name": "运行器", + "RepeatShow": False + }, + "deepin-wine-easy-packager": { + "Name": "简易打包器", + "RepeatShow": False + }, + "deepin-wine-packager": { + "Name": "专业打包器", + "RepeatShow": False + }, + "VM.mainwindow": { + "Name": "虚拟机管理工具", + "RepeatShow": True + }, + "VM.show-vm": { + "Name": "虚拟机连接工具(VNC)", + "RepeatShow": True + }, + "wine.installwine": { + "Name": "Wine 安装工具", + "RepeatShow": True + }, +} + +class RunnerWindow: + programPath = os.path.split(os.path.realpath(__file__))[0] # 获取当前程序目录 + import globalenv + recycleTime = 0 + def __init__(self, app: QtWidgets.QApplication, moduleName: str) -> None: + self.globalenv._init() # globalenv 的 init 是必须的,这样才能正确的 import Wine 运行器的窗口 + self.globalenv.set_value("app", app) # 用于将该部分的 app 给子模块的 Qt 控件调用以解决 UI 异常以及其它问题 + # 因为 Python 有不允许重复 import 的特性从而导致多次返回的控件实际指向同一对象,所以要通过特殊的方式绕过这一限制 + # 将使用指向程序所在文件夹的超链接以改变库名称从而实现每次引入时命名控件不同 + # 通过嵌套多个 local.local.local 以解决问题 + # 同理可以利用该特性使用 globalenv 传值 + if (not os.path.exists(f"{self.programPath}/local")): + # 没有存在该超链接,不启用该机制 + self.globalenv.set_value("app", app) + self.mainwindow = __import__(moduleName, fromlist=["mainwindow"]) + return + while True: + self.recycleTime += 1 + testModuleName = "local." * self.recycleTime + moduleName + if (not testModuleName in sys.modules): + self.mainwindow = __import__(testModuleName, fromlist=["mainwindow"]) # 设置 fromlist 就不会返回最上层节点,及 local + break + + def Win(self) -> QtWidgets.QMainWindow: + # 输出窗口 + return self.mainwindow.window \ No newline at end of file diff --git a/main.py b/main.py index 911b8cd..845821d 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ class RunnerWindow: programPath = os.path.split(os.path.realpath(__file__))[0] # 获取当前程序目录 import globalenv recycleTime = 0 - def __init__(self, app: QtWidgets.QApplication, moduleName: str): + def __init__(self, app: QtWidgets.QApplication, moduleName: str) -> None: self.globalenv._init() # globalenv 的 init 是必须的,这样才能正确的 import Wine 运行器的窗口 self.globalenv.set_value("app", app) # 用于将该部分的 app 给子模块的 Qt 控件调用以解决 UI 异常以及其它问题 # 因为 Python 有不允许重复 import 的特性从而导致多次返回的控件实际指向同一对象,所以要通过特殊的方式绕过这一限制 diff --git a/mainwindow.py b/mainwindow.py index 3a2bd07..b8c9c12 100755 --- a/mainwindow.py +++ b/mainwindow.py @@ -317,32 +317,6 @@ class Runexebutton_threading(QtCore.QThread): option += "WINEDEBUG=FIXME,ERR,WARN,TRACE,Message " wineUsingOption = "" exePath = e2.currentText() - # 禁用没什么用还一堆坑的参数识别问题 - if False: - fileName = [".exe"] - changePath = False - for i in fileName: - if i in exePath: - print(i) - print(exePath) - l = exePath.index(i) - exePath = f"{exePath[:l+4]}' {exePath[l+4:]} '" - print(l) - print(exePath) - changePath = True - break - #if not changePath and not os.path.exists(changePath): - if not changePath and not os.path.exists(exePath): - # 删除前后无用空格以防止出现问题 - print(exePath) - exePath = exePath.strip() - # 有空格再说 - if " " in exePath: - l = exePath.index(" ") - exePath = f"{exePath[:l]}' {exePath[l:]} '" - print(l) - #print(i) - print(exePath) if o1.currentText() == "基于 UOS exagear 的 deepin-wine6-stable" or o1.currentText() == "基于 UOS box86 的 deepin-wine6-stable": wineUsingOption = "" if o1.currentText() == "基于 UOS box86 的 deepin-wine6-stable" or o1.currentText() == "基于 UOS exagear 的 deepin-wine6-stable": @@ -422,12 +396,8 @@ StartupNotify=true''') class Temp: webWindow = None - - - #QtCore.QUrl().url() - # 显示“关于这个程序”窗口 -def about_this_program()->"显示“关于这个程序”窗口": +def about_this_program(): global about global title global iconPath