From 590701a8737ee69c3182f661f8e1e16a38a2fc16 Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Mon, 18 Jul 2022 15:22:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E7=AA=97=E5=8F=A3QT=E6=94=B9=E9=80=A0?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main-newguipyqt.py | 558 +++++++++------------------------------------ 参考图.png | Bin 0 -> 211242 bytes 2 files changed, 113 insertions(+), 445 deletions(-) create mode 100644 参考图.png diff --git a/main-newguipyqt.py b/main-newguipyqt.py index 5dc7aec..cea9c1a 100755 --- a/main-newguipyqt.py +++ b/main-newguipyqt.py @@ -15,7 +15,6 @@ import sys import time import json import shutil -import easygui import requests import threading import traceback @@ -24,7 +23,7 @@ import webbrowser import subprocess import ttkbootstrap import tkinter as tk -import tkinter.ttk as ttk +#import tkinter.ttk as ttk import tkinter.filedialog import tkinter.messagebox import PyQt5.QtGui as QtGui @@ -583,34 +582,7 @@ class UpdateWindow(): UpdateWindow.update.setWindowTitle("检查更新") UpdateWindow.update.resize(updateWidget.frameGeometry().width(), updateWidget.frameGeometry().height() * 1.5) UpdateWindow.update.show() - return - update = tk.Toplevel() - update.title("检查更新") - update.resizable(0, 0) - update.iconphoto(False, tk.PhotoImage(file=iconPath)) - versionLabel = ttk.Label(update, text="当前版本:{}\n最新版本:未知\n更新内容:".format(version)) - updateText = tk.Text(update) - controlFrame = ttk.Frame(update) - ok = ttk.Button(controlFrame, text="更新(更新过程中会关闭所有Python应用,包括这个应用)", command=UpdateWindow.Update) - cancel = ttk.Button(controlFrame, text="取消", command=update.quit) - try: - UpdateWindow.data = json.loads(requests.get("http://120.25.153.144/spark-deepin-wine-runner/update.json").text) - versionLabel = ttk.Label(update, text="当前版本:{}\n最新版本:{}\n更新内容:".format(version, UpdateWindow.data["Version"])) - if UpdateWindow.data["Version"] == version: - updateText.insert("0.0", "此为最新版本,无需更新") - ok.configure(state=tk.DISABLED) - else: - updateText.insert("0.0", UpdateWindow.data["New"].replace("\\n", "\n")) - except: - traceback.print_exc() - tkinter.messagebox.showerror(title="错误", message="无法连接服务器!") - updateText.configure(state=tk.DISABLED) - versionLabel.pack(anchor=tk.W) - updateText.pack() - controlFrame.pack(anchor=tk.E) - cancel.grid(row=0, column=0) - ok.grid(row=0, column=1) - update.mainloop() + def Update(): if os.path.exists("/tmp/spark-deepin-wine-runner/update"): shutil.rmtree("/tmp/spark-deepin-wine-runner/update") @@ -638,7 +610,7 @@ zenity --info --text=\"更新完毕!\" --ellipsize class GetDllFromWindowsISO: wineBottonPath = get_home() + "/.wine" - isoPath = None#ttk.Entry() + isoPath = None dllList = None message = None dllFound = None @@ -649,94 +621,116 @@ class GetDllFromWindowsISO: browser = None mount = False mountButton = None + dllListModel = None def ShowWindow(): DisableButton(True) - GetDllFromWindowsISO.message = tk.Toplevel() + GetDllFromWindowsISO.message = QtWidgets.QMainWindow() + widget = QtWidgets.QWidget() + widgetLayout = QtWidgets.QGridLayout() if not e1.currentText() == "": GetDllFromWindowsISO.wineBottonPath = e1.currentText() - ttk.Label(GetDllFromWindowsISO.message, text=f"""提示: + widgetLayout.addWidget(QtWidgets.QLabel(f"""提示: 目前本提取功能只支持 Windows XP 以及 Windows Server 2003 等老系统的官方安装镜像,只支持读取 i386 安装方法的安装镜像,不支持读取 wim、ghost 安装方式 以及不要拷贝/替换太多的 dll,否则可能会导致 wine 容器异常 最后,拷贝/替换 dll 后,建议点击下面“设置 wine 容器”按钮==》函数库 进行设置 -当前选择的 Wine 容器:{GetDllFromWindowsISO.wineBottonPath}""").grid(row=0, column=0, columnspan=3, sticky=tk.W) - ttk.Label(GetDllFromWindowsISO.message, text="ISO镜像:").grid(row=1, column=0, sticky=tk.W) - GetDllFromWindowsISO.isoPath = ttk.Combobox(GetDllFromWindowsISO.message, width=100) - GetDllFromWindowsISO.browser = ttk.Button(GetDllFromWindowsISO.message, text="浏览……", command=GetDllFromWindowsISO.Browser) - isoControl = ttk.Frame(GetDllFromWindowsISO.message) - GetDllFromWindowsISO.mountButton = ttk.Button(isoControl, text="读取/挂载ISO镜像", command=GetDllFromWindowsISO.MountDisk) - ttk.Button(isoControl, text="关闭/卸载ISO镜像", command=GetDllFromWindowsISO.UmountDisk).grid(row=0, column=1) - ttk.Label(GetDllFromWindowsISO.message, text="查找DLL\n(为空则代表不查找,\n将显示全部内容):").grid(row=3, column=0) - GetDllFromWindowsISO.dllFound = ttk.Combobox(GetDllFromWindowsISO.message, width=100) - GetDllFromWindowsISO.foundButton = ttk.Button(GetDllFromWindowsISO.message, text="查找", command=GetDllFromWindowsISO.Found) - GetDllFromWindowsISO.dllList = tk.Listbox(GetDllFromWindowsISO.message, width=100) - GetDllFromWindowsISO.dllControl = ttk.Frame(GetDllFromWindowsISO.message) - GetDllFromWindowsISO.saveDll = ttk.Button(GetDllFromWindowsISO.dllControl, text="保存到 wine 容器中", command=GetDllFromWindowsISO.CopyDll) - GetDllFromWindowsISO.setWineBotton = ttk.Button(GetDllFromWindowsISO.dllControl, text="设置 wine 容器", command=lambda: threading.Thread(target=RunWineProgram, args=["winecfg", False, False]).start()) - # 设置控件 +当前选择的 Wine 容器:{GetDllFromWindowsISO.wineBottonPath}"""), 0, 0, 1, 5) + isoLabel = QtWidgets.QLabel("ISO镜像:") + GetDllFromWindowsISO.isoPath = QtWidgets.QComboBox() + GetDllFromWindowsISO.browser = QtWidgets.QPushButton("浏览") + isoControl = QtWidgets.QWidget() + isoControlLayout = QtWidgets.QHBoxLayout() + isoControl.setLayout(isoControlLayout) + dllControl = QtWidgets.QWidget() + dllControlLayout = QtWidgets.QHBoxLayout() + dllControl.setLayout(dllControlLayout) + GetDllFromWindowsISO.mountButton = QtWidgets.QPushButton("读取/挂载ISO镜像") + umountButton = QtWidgets.QPushButton("关闭/卸载ISO镜像") + GetDllFromWindowsISO.dllFound = QtWidgets.QComboBox() + GetDllFromWindowsISO.foundButton = QtWidgets.QPushButton("查找") + GetDllFromWindowsISO.dllList = QtWidgets.QListView() + GetDllFromWindowsISO.saveDll = QtWidgets.QPushButton("保存到 wine 容器中") + GetDllFromWindowsISO.setWineBotton = QtWidgets.QPushButton("设置 wine 容器") + isoLabel.setSizePolicy(size) + GetDllFromWindowsISO.isoPath.setEditable(True) + GetDllFromWindowsISO.isoPath.addItems(isoPath) + GetDllFromWindowsISO.isoPath.setEditText("") + GetDllFromWindowsISO.browser.setSizePolicy(size) + GetDllFromWindowsISO.mountButton.setSizePolicy(size) + isoControlLayout.addWidget(GetDllFromWindowsISO.mountButton) + umountButton.setSizePolicy(size) + isoControlLayout.addWidget(umountButton) + GetDllFromWindowsISO.dllFound.setEditable(True) + GetDllFromWindowsISO.dllFound.addItems(isoPathFound) + GetDllFromWindowsISO.dllFound.setEditText("") + GetDllFromWindowsISO.saveDll.setSizePolicy(size) + dllControlLayout.addWidget(GetDllFromWindowsISO.saveDll) + GetDllFromWindowsISO.setWineBotton.setSizePolicy(size) GetDllFromWindowsISO.DisbledDown(True) - GetDllFromWindowsISO.isoPath['value'] = isoPath - GetDllFromWindowsISO.dllFound['value'] = isoPathFound - # 显示控件 - GetDllFromWindowsISO.isoPath.grid(row=1, column=1) - GetDllFromWindowsISO.browser.grid(row=1, column=2) - GetDllFromWindowsISO.mountButton.grid(row=0, column=0) - isoControl.grid(row=2, column=0, columnspan=3) - GetDllFromWindowsISO.dllFound.grid(row=3, column=1) - GetDllFromWindowsISO.foundButton.grid(row=3, column=2) - GetDllFromWindowsISO.dllList.grid(row=4, column=0, columnspan=3) - GetDllFromWindowsISO.dllControl.grid(row=5, column=0, columnspan=3) - GetDllFromWindowsISO.saveDll.grid(row=0, column=0) - GetDllFromWindowsISO.setWineBotton.grid(row=0, column=1) - # 设置 - GetDllFromWindowsISO.message.protocol('WM_DELETE_WINDOW', GetDllFromWindowsISO.ExitWindow) - GetDllFromWindowsISO.message.title(f"Wine 运行器 {version}——从 ISO 提取 DLL") - # 显示 - GetDllFromWindowsISO.message.mainloop() + dllControlLayout.addWidget(GetDllFromWindowsISO.setWineBotton) + widgetLayout.addWidget(isoLabel, 1, 0, 1, 1) + widgetLayout.addWidget(GetDllFromWindowsISO.isoPath, 1, 1, 1, 1) + widgetLayout.addWidget(GetDllFromWindowsISO.browser, 1, 2, 1, 1) + widgetLayout.addWidget(isoControl, 2, 1, 1, 1) + widgetLayout.addWidget(QtWidgets.QLabel("查找DLL\n(为空则代表不查找,\n将显示全部内容):"), 3, 0, 1, 1) + widgetLayout.addWidget(GetDllFromWindowsISO.dllFound, 3, 1, 1, 1) + widgetLayout.addWidget(GetDllFromWindowsISO.foundButton, 3, 2, 1, 1) + widgetLayout.addWidget(GetDllFromWindowsISO.dllList, 4, 1, 1, 1) + widgetLayout.addWidget(dllControl, 5, 1, 1, 1) + #widgetLayout.addWidget(GetDllFromWindowsISO.setWineBotton, 5, 2, 1, 1) + widget.setLayout(widgetLayout) + GetDllFromWindowsISO.browser.clicked.connect(GetDllFromWindowsISO.Browser) + GetDllFromWindowsISO.mountButton.clicked.connect(GetDllFromWindowsISO.MountDisk) + umountButton.clicked.connect(GetDllFromWindowsISO.UmountDisk) + GetDllFromWindowsISO.foundButton.clicked.connect(GetDllFromWindowsISO.Found) + GetDllFromWindowsISO.saveDll.clicked.connect(GetDllFromWindowsISO.CopyDll) + GetDllFromWindowsISO.setWineBotton.clicked.connect(lambda: RunWineProgram("winecfg", Disbled=False)) + GetDllFromWindowsISO.message.setCentralWidget(widget) + GetDllFromWindowsISO.dllListModel = QtCore.QStringListModel() + GetDllFromWindowsISO.dllListModel.setStringList([]) + GetDllFromWindowsISO.dllList.setModel(GetDllFromWindowsISO.dllListModel) + GetDllFromWindowsISO.isoPath.currentText() + GetDllFromWindowsISO.message.show() def DisbledUp(state): - nd = [tk.NORMAL, tk.DISABLED] - GetDllFromWindowsISO.isoPath.configure(state=nd[int(state)]) - GetDllFromWindowsISO.browser.configure(state=nd[int(state)]) - GetDllFromWindowsISO.mountButton.configure(state=nd[int(state)]) + GetDllFromWindowsISO.isoPath.setDisabled(state) + GetDllFromWindowsISO.browser.setDisabled(state) + GetDllFromWindowsISO.mountButton.setDisabled(state) def DisbledDown(state): - nd = [tk.NORMAL, tk.DISABLED] - GetDllFromWindowsISO.dllList.configure(state=nd[int(state)]) - GetDllFromWindowsISO.dllFound.configure(state=nd[int(state)]) - #GetDllFromWindowsISO.dllControl.configure(state=nd[int(state)]) - GetDllFromWindowsISO.saveDll.configure(state=nd[int(state)]) - GetDllFromWindowsISO.setWineBotton.configure(state=nd[int(state)]) - GetDllFromWindowsISO.foundButton.configure(state=nd[int(state)]) + GetDllFromWindowsISO.dllList.setDisabled(state) + GetDllFromWindowsISO.dllFound.setDisabled(state) + GetDllFromWindowsISO.saveDll.setDisabled(state) + GetDllFromWindowsISO.setWineBotton.setDisabled(state) + GetDllFromWindowsISO.foundButton.setDisabled(state) def Browser(): - path = tkinter.filedialog.askopenfilename(title="选择 ISO 镜像文件", - filetypes=[("ISO 镜像文件", "*.iso"), ("ISO 镜像文件", "*.ISO"), ("所有文件", "*.*")], - initialdir=json.loads(readtxt(get_home() + "/.config/deepin-wine-runner/FindISO.json"))["path"]) + path = QtWidgets.QFileDialog.getOpenFileName(GetDllFromWindowsISO.message, "选择 ISO 镜像文件", json.loads(readtxt(get_home() + "/.config/deepin-wine-runner/FindISO.json"))["path"], "iso 镜像文件(*.iso);;ISO 镜像文件(*.ISO);;所有文件(*.*)")[0] if path == None or path == "": return - GetDllFromWindowsISO.isoPath.set(path) + GetDllFromWindowsISO.isoPath.setEditText(path) write_txt(get_home() + "/.config/deepin-wine-runner/FindISO.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件 def Found(): - found = GetDllFromWindowsISO.dllFound.get() - GetDllFromWindowsISO.dllList.configure(state=tk.NORMAL) - GetDllFromWindowsISO.dllList.delete(0, tk.END) + found = GetDllFromWindowsISO.dllFound.currentText() + findList = [] try: if found == "": for i in os.listdir("/tmp/wine-runner-getdll/i386"): if i[-3:] == "dl_": - GetDllFromWindowsISO.dllList.insert("end", i[:-1] + "l") + findList.append(i[:-1] + "l") return for i in os.listdir("/tmp/wine-runner-getdll/i386"): if found in i[:-1] + "l": - GetDllFromWindowsISO.dllList.insert("end", i[:-1] + "l") + findList.append(i[:-1] + "l") isoPathFound.append(found) # 将记录写进数组 write_txt(get_home() + "/.config/deepin-wine-runner/ISOPathFound.json", str(json.dumps(ListToDictionary(isoPathFound)))) # 将历史记录的数组转换为字典并写入 - GetDllFromWindowsISO.dllFound['value'] = isoPathFound + GetDllFromWindowsISO.dllFound.clear() + GetDllFromWindowsISO.dllFound.addItems(isoPathFound) + GetDllFromWindowsISO.dllListModel.setStringList(findList) except: traceback.print_exc() - tkinter.messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.critical(GetDllFromWindowsISO.message, "错误", traceback.format_exc()) def ExitWindow(): @@ -747,8 +741,8 @@ class GetDllFromWindowsISO: GetDllFromWindowsISO.message.quit() def MountDisk(): - if not os.path.exists(GetDllFromWindowsISO.isoPath.get()): - tkinter.messagebox.showerror(title="错误", message="您选择的 ISO 镜像文件不存在") + if not os.path.exists(GetDllFromWindowsISO.isoPath.currentText()): + QtWidgets.QMessageBox.critical(GetDllFromWindowsISO.message, "错误", "您选择的 ISO 镜像文件不存在") return if os.path.exists("/tmp/wine-runner-getdll"): try: @@ -760,53 +754,53 @@ class GetDllFromWindowsISO: os.rmdir("/tmp/wine-runner-getdll") except: traceback.print_exc() - tkinter.messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.critical(GetDllFromWindowsISO.message, "错误", traceback.format_exc()) return os.makedirs("/tmp/wine-runner-getdll") - GetDllFromWindowsISO.dllList.configure(state=tk.NORMAL) - os.system(f"pkexec mount '{GetDllFromWindowsISO.isoPath.get()}' /tmp/wine-runner-getdll") - GetDllFromWindowsISO.dllList.delete(0, tk.END) + os.system(f"pkexec mount '{GetDllFromWindowsISO.isoPath.currentText()}' /tmp/wine-runner-getdll") + findList = [] try: for i in os.listdir("/tmp/wine-runner-getdll/i386"): if i[-3:] == "dl_": - GetDllFromWindowsISO.dllList.insert("end", i[:-1] + "l") + findList.append(i[:-1] + "l") except: traceback.print_exc() - tkinter.messagebox.showerror(title="错误", message=f"镜像内容读取/挂载失败,报错如下:\n{traceback.format_exc()}") + QtWidgets.QMessageBox.critical(GetDllFromWindowsISO.message, "错误", f"镜像内容读取/挂载失败,报错如下:\n{traceback.format_exc()}") return + GetDllFromWindowsISO.dllListModel.setStringList(findList) GetDllFromWindowsISO.DisbledDown(False) GetDllFromWindowsISO.DisbledUp(True) GetDllFromWindowsISO.mount = True - isoPath.append(GetDllFromWindowsISO.isoPath.get()) # 将记录写进数组 + isoPath.append(GetDllFromWindowsISO.isoPath.currentText()) # 将记录写进数组 write_txt(get_home() + "/.config/deepin-wine-runner/ISOPath.json", str(json.dumps(ListToDictionary(isoPath)))) # 将历史记录的数组转换为字典并写入 - GetDllFromWindowsISO.isoPath['value'] = isoPath + GetDllFromWindowsISO.isoPath.clear() + GetDllFromWindowsISO.isoPath.addItems(isoPath) + #GetDllFromWindowsISO.isoPath['value'] = isoPath def UmountDisk(): os.system("pkexec umount /tmp/wine-runner-getdll") - GetDllFromWindowsISO.dllList.configure(state=tk.NORMAL) try: shutil.rmtree("/tmp/wine-runner-getdll") except: traceback.print_exc() - tkinter.messagebox.showerror(title="错误", message=f"关闭/卸载镜像失败,报错如下:\n{traceback.format_exc()}") + QtWidgets.QMessageBox.critical(GetDllFromWindowsISO.message, "错误", f"关闭/卸载镜像失败,报错如下:\n{traceback.format_exc()}") return GetDllFromWindowsISO.DisbledDown(True) GetDllFromWindowsISO.DisbledUp(False) GetDllFromWindowsISO.mount = False + QtWidgets.QMessageBox.information(GetDllFromWindowsISO.message, "提示", "关闭/卸载成功!") def CopyDll(): - for i in GetDllFromWindowsISO.dllList.curselection(): - choose = GetDllFromWindowsISO.dllList.get(i) - if os.path.exists(f"{GetDllFromWindowsISO.wineBottonPath}/drive_c/windows/system32/{choose}"): - if not tkinter.messagebox.askyesno(title="提示", message=f"DLL {choose} 已经存在,是否覆盖?"): - continue - print(i) - try: - shutil.copy(f"/tmp/wine-runner-getdll/i386/{choose[:-1]}_", f"{GetDllFromWindowsISO.wineBottonPath}/drive_c/windows/system32/{choose}") - tkinter.messagebox.showinfo(title="提示", message="提取成功!") - except: - traceback.print_exc() - tkinter.messagebox.showerror(title="错误", message=traceback.format_exc()) + choose = GetDllFromWindowsISO.dllList.selectionModel().selectedIndexes()[0].data() + if os.path.exists(f"{GetDllFromWindowsISO.wineBottonPath}/drive_c/windows/system32/{choose}"): + if QtWidgets.QMessageBox.question(title="提示", message=f"DLL {choose} 已经存在,是否覆盖?") == QtWidgets.QMessageBox.No: + return + try: + shutil.copy(f"/tmp/wine-runner-getdll/i386/{choose[:-1]}_", f"{GetDllFromWindowsISO.wineBottonPath}/drive_c/windows/system32/{choose}") + QtWidgets.QMessageBox.information(GetDllFromWindowsISO.message, "提示", "提取成功!") + except: + traceback.print_exc() + QtWidgets.QMessageBox.critical(GetDllFromWindowsISO.message, "错误", traceback.format_exc()) class ProgramSetting(): wineBottonA = None @@ -937,9 +931,9 @@ try: if change: write_txt(get_home() + "/.config/deepin-wine-runner/WineSetting.json", json.dumps(setting)) except: - root = tk.Tk() - root.withdraw() - tkinter.messagebox.showerror(title="错误", message="无法读取配置,无法继续") + traceback.print_exc() + app = QtWidgets.QApplication(sys.argv) + QtWidgets.QMessageBox.critical(None, "错误", f"无法读取配置,无法继续\n{traceback.format_exc()}") sys.exit(1) ########################### @@ -987,6 +981,10 @@ Qt 版本:{QtCore.qVersion()}
{updateThingsString} 更新时间:{updateTime}
{tips} ++
k!L**MOF23^yP?+HRtr>E
zPNGibPVf@kjwV3AgCsBTr}bve!>%y-=_ji#c)YpCE4ox9jl;fK4{2=FLi^#g0NsxW
z3DrO+q92HR%uiE!v+L`_t6S8P@jX57`o^CP2FUFySE`jIoRL;UgoEo7w-y>TA6CQm
zoQ}t|+Ys@%FCL$fltR;NnkdFXTX_M2R;&3M4^{AdY=wC&W1L7Lf;w%Wzv!R0wmXU6
zz&^;Gp<7p$+L-I~?)$kl@yJ07Dis#-mu6q*5@A3N;dv6JLuBS=BWys&cEWai^LL~L
zrj*b|wj_L$KacrmTmmu0B_zeAr>cyMRi;=-dYU9ol7)mma1kl+lCuau#5S75j6LZq
zfwG_^0@qjJzuLo}2J*gt;+LvjdvE!%3pW>?{J3w5s62O8TpAxGeWJB2>R#P!ii`{c
zBj~A>U!bwO(I!1h4~TW@6!V98e O-#6Y{mlx7eJL+jhh$#WaDb3PBbF{9HT4DNb2ZX@t$#uJ?=OS$s3VP7x9L4ex*D`61VxsKuVBjr
zUcFJ4AW8b1mUd@5h6>7f_?+<>e&+E1wD=wwfYyh}gnZV>H||!itqc0G~p83-+h&Tqv-rq>Gm|!`G}(A
z!%EHwkN){a;6!;oPt`DYSnKMi1)3~@e
zJR-Z=S;BB&?*J=hb6bj;2&-eU=XRcx{z!g)SQUT?pTmv(jLRf6k`|R_{B8?KH6eMk
z@+wDERW*wW)Z>(W`#4t1zn-(5LgHTL&mzgpM#r40rD|I!y=M9TIC$UJxRnGZAXqzE
zP-t`$r%}qc7j={F6;5wTsglMcrCY#MT?1M$4RE|bL%q8C6o8}s|1YK&g6QAM%AYcy
zHDsUqnzQ|w4-uXP$9))Zz;21~*9b3Sah;)U;$k~N;#Nr42zun8N#M4W&yqV{jPrWeUh}x$E$xwg>9X!WQ5JH-|PC<92Rkt5AR26!gAgg1Vk@3
zG~Ml18d#v}>2Fa|*1N^vQ@9