单独封装用于实现窗口模块化的组件和调用

This commit is contained in:
gfdgd xi 2024-08-02 20:59:56 +08:00
parent 3f1fefa8a5
commit df95e7d0b0
4 changed files with 61 additions and 32 deletions

View File

@ -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

58
WindowModule.py Normal file
View File

@ -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

View File

@ -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 的特性从而导致多次返回的控件实际指向同一对象,所以要通过特殊的方式绕过这一限制

View File

@ -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