From 6bf4202cc2dc2656111b3b3b6eedb8346c935cf8 Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Tue, 26 Jul 2022 14:57:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90Tkinter=E8=BD=ACPyQt5=E4=BB=A5=E5=8F=8A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=94=AE=E7=9B=98=E6=98=A0=E5=B0=84=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=9A=84=E6=97=A0=E6=B3=95=E9=80=80=E5=87=BA=E5=92=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=B8=80=E6=AE=B5=E6=97=B6=E9=97=B4=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E6=98=A0=E5=B0=84=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py => mainwindow.py | 1032 +++++++++++++++----------------------- uengine-keyboard | 44 +- 2 files changed, 436 insertions(+), 640 deletions(-) rename main.py => mainwindow.py (62%) diff --git a/main.py b/mainwindow.py similarity index 62% rename from main.py rename to mainwindow.py index aa2e639..990054b 100755 --- a/main.py +++ b/mainwindow.py @@ -3,7 +3,7 @@ ########################################################################################### # 作者:gfdgd xi<3025613752@qq.com> # 版本:1.8.0 -# 更新时间:2022年07月23日 +# 更新时间:2022年07月25日 # 感谢:anbox、deepin 和 UOS # 基于 Python3 的 tkinter 构建 # 更新:gfdgd xi<3025613752@qq.com>、actionchen<917981399@qq.com>、为什么您不喜欢熊出没和阿布呢 @@ -20,8 +20,6 @@ import shutil import zipfile import traceback import threading -import easygui -import ttkthemes import webbrowser import subprocess import matplotlib @@ -30,16 +28,9 @@ import numpy import matplotlib.figure import matplotlib.pylab import matplotlib.font_manager -import PIL.Image as Image -import PIL.ImageTk as ImageTk import PyQt5.QtGui as QtGui import PyQt5.QtCore as QtCore import PyQt5.QtWidgets as QtWidgets -import tkinter as tk -import tkinter.ttk as ttk -import tkinter.messagebox as messagebox -import tkinter.filedialog as filedialog -import tkinter.simpledialog as simpledialog from getxmlimg import getsavexml class UninstallProgram(QtCore.QThread): @@ -263,12 +254,12 @@ def ReStartProgram()->"重启本应用程序": # 清理历史记录 def CleanProgramHistory()->"清理历史记录": try: - if messagebox.askokcancel(title="警告", message="删除后将无法恢复,你确定吗?\n删除后软件将会自动重启。"): + if QtWidgets.QMessageBox.warning(widget, "警告", "删除后将无法恢复,你确定吗?\n删除后软件将会自动重启。", QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel, QtWidgets.QMessageBox.Cancel) == QtWidgets.QMessageBox.Ok: shutil.rmtree(get_home() + "/.config/uengine-runner") ReStartProgram() except: traceback.print_exc() - messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.critical(widget, "错误", traceback.format_exc()) # 获取用户主目录 def get_home()->"获取用户主目录": @@ -285,14 +276,14 @@ def SendUengineAndroidListForDesktop()->"发送“启动 uengine 所有程序” DisabledAndEnbled(True) try: if os.path.exists("{}/{}".format(get_desktop_path(), desktopName)): - if not messagebox.askokcancel(title="提示", message="桌面已经存在快捷方式,你确定要覆盖吗?"): + if QtWidgets.QMessageBox.question(widget, "提示", "桌面已经存在快捷方式,你确定要覆盖吗?") == QtWidgets.QMessageBox.No: DisabledAndEnbled(False) return shutil.copy(desktop, get_desktop_path()) - messagebox.showinfo(title="提示", message="发送成功!") + QtWidgets.QMessageBox.critical(widget, "提示", "发送成功!") except: traceback.print_exc() - messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.critical(widget, "错误", traceback.format_exc()) DisabledAndEnbled(False) # 获取用户桌面目录 @@ -315,17 +306,17 @@ def SendUengineAndroidListForLauncher()->"发送“启动 uengine 所有程序 DisabledAndEnbled(True) try: if os.path.exists("{}/.local/share/applications/{}".format(get_home(), desktopName)): - if not messagebox.askokcancel(title="提示", message="启动器已经存在快捷方式,你确定要覆盖吗?"): + if QtWidgets.QMessageBox.question(widget, "提示", "启动器已经存在快捷方式,你确定要覆盖吗?") == QtWidgets.QMessageBox.No: DisabledAndEnbled(False) return if not os.path.exists("{}/.local/share/applications/".format(get_home())): os.makedirs("{}/.local/share/applications/".format(get_home())) shutil.copy(desktop, "{}/.local/share/applications/{}".format(get_home(), desktopName)) os.system("chmod 755 {}/.local/share/applications/{}".format(get_home(), desktopName)) - messagebox.showinfo(title="提示", message="发送成功!") + QtWidgets.QMessageBox.critical(widget, "提示", "发送成功!") except: traceback.print_exc() - messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.critical(widget, "错误", traceback.format_exc()) DisabledAndEnbled(False) # 数组转字典 @@ -395,7 +386,7 @@ def UbuntuInstallUengine(): threading.Thread(target=os.system, args=[f"'{programPath}/launch.sh' deepin-terminal -C \"bash '{programPath + '/uengine-installer'}'\""]).start() def BuildRootUengineImage(): - threading.Thread(target=os.system, args=[f"'{programPath}/launch.sh' deepin-terminal -C \"bash '{programPath + '/root-uengine.sh'}'\""]).start() + threading.Thread(target=os.system, args=[f"'{programPath}/launch.sh' deepin-terminal -C \"bash '{programPath}/root-uengine.sh'\""]).start() def ReinstallUengineImage(): threading.Thread(target=os.system, args=[f"'{programPath}/launch.sh' deepin-terminal -e ''pkexec apt reinstall uengine-android-image -y"]).start() @@ -464,7 +455,7 @@ def saveicon(): def KeyboardToMouse(): threading.Thread(target=os.system, args=["pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY {}/uengine-keyboard".format(programPath)]).start() -# 用户自行保存APK +# 用户自行保存 def SaveIconToOtherPath(): apkPath = ComboInstallPath.currentText() if apkPath == "": @@ -487,15 +478,15 @@ def SaveIconToOtherPath(): # 清空 uengine 数据 def BackUengineClean()->"清空 uengine 数据": print("Choose") - if messagebox.askokcancel(title="警告", message="清空后数据将会完全丢失,确定要继续吗?"): + if QtWidgets.QMessageBox.warning(widget, "警告", "清空后数据将会完全丢失,确定要继续吗?", QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel, QtWidgets.QMessageBox.Cancel) == QtWidgets.QMessageBox.Ok: DisabledAndEnbled(True) try: if os.path.exists("{}/.local/share/applications/uengine/".format(get_home())): shutil.rmtree("{}/.local/share/applications/uengine/".format(get_home())) except: traceback.print_exc() - messagebox.showerror(title="错误", message=traceback.format_exc()) - InstallWindow.ShowWindows("pkexec rm -rfv /data/uengine") + QtWidgets.QMessageBox.critical(widget, "错误", traceback.format_exc()) + os.system(f"'{programPath}/launch.sh' deepin-terminal -C \"pkexec rm -rfv /data/uengine\"") return print("Choose False") @@ -551,14 +542,14 @@ def ScrcpyConnectUengine(): if os.path.exists("/snap/bin/scrcpy"): threading.Thread(target=os.system, args=["/snap/bin/scrcpy -s '192.168.250.2:5555'"]).start() return - if messagebox.askyesno(title="提示", message="你没有安装Scrcpy(指使用Snap安装),\n如果你使用了其他方法安装了Scrcpy,可以输入命令“scrcpy -s '192.168.250.2:5555'”,\n是否现在要使用Snap安装Scrcpy?"): + if QtWidgets.QMessageBox.question(title="提示", message="你没有安装Scrcpy(指使用Snap安装),\n如果你使用了其他方法安装了Scrcpy,可以输入命令“scrcpy -s '192.168.250.2:5555'”,\n是否现在要使用Snap安装Scrcpy?") == QtWidgets.QMessageBox.Yes: if not os.path.exists("/tmp/uengine-runner"): os.makedirs("/tmp/uengine-runner") write_txt("/tmp/uengine-runner/InstallScrcpy.sh", '''#!/bin/bash sudo apt install snapd -y sudo snap refresh sudo snap install scrcpy''') - threading.Thread(target=InstallWindow.ShowWindows, args=["chmod 777 /tmp/uengine-runner/InstallScrcpy.sh -Rv && pkexec /tmp/uengine-runner/InstallScrcpy.sh"]).start() + threading.Thread(target=os.system, args=[f"'{programPath}/launch.sh' deepin-terminal -C \"chmod 777 /tmp/uengine-runner/InstallScrcpy.sh -Rv && pkexec /tmp/uengine-runner/InstallScrcpy.sh\""]).start() return # 获取用户桌面目录 @@ -579,26 +570,28 @@ def get_desktop_path()->"获取用户桌面目录": # 提取已安装程序的apk def SaveInstallUengineApp(): while True: - result = simpledialog.askstring(title="输入apk包名", prompt="请输入要获取的apk包名以便进行下一步操作") - if result == "" or result == None: + result = QtWidgets.QInputDialog.getText(widget, "输入 APK 包名", "请输入要获取的apk包名以便进行下一步操作") + #result = simpledialog.askstring(title="输入apk包名", prompt="请输入要获取的apk包名以便进行下一步操作") + if result[1] == False: return + result = result[0] if os.path.exists("/data/uengine/data/data/app/{}-1".format(result)): break - messagebox.showerror(title="错误", message=langFile[lang]["Main"]["MainWindow"]["Error"]["PathError"]) - path = filedialog.asksaveasfilename(title="保存apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/SaveApk.json"))["path"]) + QtWidgets.QMessageBox.critical(widget, "错误", langFile[lang]["Main"]["MainWindow"]["Error"]["PathError"]) + path = QtWidgets.QFileDialog.getSaveFileName(widget, "保存apk", "~", "APK 文件(*.apk);;所有文件(*.*)", json.loads(readtxt(get_home() + "/.config/uengine-runner/SaveApk.json"))["path"])[0] if path == "" or path == (): return try: shutil.copy("/data/uengine/data/data/app/{}-1/base.apk".format(result), path) write_txt(get_home() + "/.config/uengine-runner/SaveApk.json", json.dumps({"path": os.path.dirname(path)})) - messagebox.showinfo(title="提示", message="提取完成!") + QtWidgets.QMessageBox.information(widget, "提示", "提取完成!") except: traceback.print_exc() - messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.critical(widget, "错误", traceback.format_exc()) def UengineCheckCpu(): english = GetCommandReturn("uengine check-features") - messagebox.showinfo(title="提示", message="{}".format(english)) + QtWidgets.QMessageBox.information(widget, "提示", english) # 获取用户主目录 def get_home()->"获取用户主目录": @@ -606,14 +599,14 @@ def get_home()->"获取用户主目录": # 删除所有的 uengine 应用快捷方式 def CleanAllUengineDesktopLink(): - if messagebox.askokcancel(title="提示", message="你确定要删除所有的 UEngine 应用快捷方式吗?"): + if QtWidgets.QMessageBox.question(widget, "提示", "你是否要删除所有的 UEngine 应用快捷方式?") == QtWidgets.QMessageBox.No: try: shutil.rmtree("{}/.local/share/applications/uengine".format(get_home())) os.makedirs("{}/.local/share/applications/uengine".format(get_home())) - messagebox.showinfo(title="提示", message="删除完毕!") + QtWidgets.QMessageBox.information(widget, "提示", "删除完毕!") except: traceback.print_exc() - messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.critical(widget, "错误", traceback.format_exc()) # 打开 uengine 应用打包器 def OpenUengineDebBuilder(): @@ -643,44 +636,44 @@ def UengineSettingShow(): # 杀死 adb 进程 def AdbKillAdbProgress(): os.system("killall adb") - messagebox.showinfo(title="提示", message="完成!") + QtWidgets.QMessageBox.information(widget, "提示", "完成!") # 关闭 adb 服务 def AdbStopServer(): os.system("adb kill-server") - messagebox.showinfo(title="提示", message="完成!") + QtWidgets.QMessageBox.information(widget, "提示", "完成!") # 开启 adb 服务 def AdbStartServer(): os.system("adb start-server") - messagebox.showinfo(title="提示", message="完成!") + QtWidgets.QMessageBox.information(widget, "提示", "完成!") def ReinstallUengine(): threading.Thread(target=os.system, args=[f"'{programPath}/launch.sh' deepin-terminal -C 'pkexec apt reinstall uengine uengine-android-image uengine-modules-dkms -y && notify-send -i uengine \"安装完毕!\"'"]).start() def DelUengineCheck(): if not os.path.exists("/usr/share/uengine/uengine-check-runnable.sh"): - messagebox.showinfo(title="提示", message="本功能已经被删除,无法重复删除!") + QtWidgets.QMessageBox.information(widget, "提示", "本功能已经被删除,无法重复删除!") return - if messagebox.askokcancel(title="警告", message="删除后将无法使用本软件恢复\n如果需要恢复本功能,请重新安装 UEngine!"): - threading.Thread(target=InstallWindow.ShowWindows, args=["pkexec rm -v /usr/share/uengine/uengine-check-runnable.sh"]).start() + if QtWidgets.QMessageBox.warning(widget, "警告", "删除后将无法使用本软件恢复\n如果需要恢复本功能,请重新安装 UEngine!", QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel, QtWidgets.QMessageBox.Ok) == QtWidgets.QMessageBox.Ok: + threading.Thread(target=os.system, args=["'{programPath}/launch.sh' deepin-terminal -C 'pkexec rm -v /usr/share/uengine/uengine-check-runnable.sh'"]).start() # 使用 adb 连接 uengine def UengineConnectAdb(): - messagebox.showinfo(title="提示", message=subprocess.getoutput("adb connect 192.168.250.2:5555")) + QtWidgets.QMessageBox.information(widget, "提示", subprocess.getoutput("adb connect 192.168.250.2:5555")) # 允许用户使用 adb def UengineUseAdb(): # 因为需要 root,所以需要开二号程序 os.system("adb start-server") # 保证有生成文件 os.system("pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY {}/uengine-useadb 0 '{}'".format(programPath, "{}/.android/adbkey.pub".format(get_home()))) # 写入配置 - if messagebox.askyesno(title="提示", message="是否要连接到 UEngine?"): + if QtWidgets.QMessageBox.question(title="提示", message="是否要连接到 UEngine?") == QtWidgets.QMessageBox.Yes: UengineConnectAdb() def UengineDoNotUseAdb(): # 因为需要 root,所以需要开二号程序 if not os.path.exists("/data/uengine/data/data/misc/adb/adb_keys"): - messagebox.showinfo(title="提示", message="你的 uengine 在设置前已经禁用 adb 连接,无需重复设置") + QtWidgets.QMessageBox.critical(widget, "提示", "你的 uengine 在设置前已经禁用 adb 连接,无需重复设置") return threading.Thread(target=os.system, args=["pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY {}/uengine-useadb 1".format(programPath)]).start() @@ -722,180 +715,205 @@ def ShowHelp(): def AllowOrDisallowUpdateAndroidApp(): if not os.path.exists("/data/uengine/data/data/misc/adb/adb_keys"): - if not messagebox.askyesno(title=langFile[lang]["Main"]["MainWindow"]["Answer"]["Title"], message=langFile[lang]["Main"]["MainWindow"]["Answer"]["UseAdbPackageAnswer"]): + if QtWidgets.QMessageBox.question(widget, langFile[lang]["Main"]["MainWindow"]["Answer"]["Title"], langFile[lang]["Main"]["MainWindow"]["Answer"]["UseAdbPackageAnswer"]) == QtWidgets.QMessageBox.No: return os.system("pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY {}/uengine-useadb 0 '{}'".format(programPath,"{}/.android/adbkey.pub".format(get_home()))) # 写入配 adb = api.Adb("192.168.250.2:5555") adb.Service.Close() adb.connect() - if messagebox.askyesno(title=langFile[lang]["Main"]["MainWindow"]["Answer"]["Title"], message=langFile[lang]["Main"]["MainWindow"]["Answer"]["AllowOrDisallowUpdateAndroidAppAnswer"][int(adb.boolAndroidInstallOtherAppSetting())]): + if QtWidgets.QMessageBox.question(widget, langFile[lang]["Main"]["MainWindow"]["Answer"]["Title"], message=langFile[lang]["Main"]["MainWindow"]["Answer"]["AllowOrDisallowUpdateAndroidAppAnswer"][int(adb.boolAndroidInstallOtherAppSetting())]) == QtWidgets.QMessageBox.Yes: adb.setAndroidInstallOtherAppSetting(not adb.boolAndroidInstallOtherAppSetting()) - messagebox.showinfo(title=langFile[lang]["Main"]["MainWindow"]["Information"]["Title"], message=langFile[lang]["Main"]["MainWindow"]["Answer"]["CompleteInformation"]) + QtWidgets.QMessageBox.information(widget, langFile[lang]["Main"]["MainWindow"]["Information"]["Title"], langFile[lang]["Main"]["MainWindow"]["Answer"]["CompleteInformation"]) def SetHttpProxy(): adb = api.Adb("192.168.250.2:5555") adb.Service.Close() adb.connect() - if not messagebox.askokcancel(title="提示", message="此功能需要安装 adb 补丁,请保证已经安装然后按下“OK”"): + if QtWidgets.QMessageBox.question(title="提示", message="此功能需要安装 adb 补丁,请保证已经安装然后按下“Yes”") == QtWidgets.QMessageBox.No: return - proxy = easygui.enterbox(title="输入代理", msg="请输入要设置的代理(为空代表不设置代理)") - if proxy == None: + proxy = QtWidgets.QInputDialog(title="输入代理", msg="请输入要设置的代理(为空代表不设置代理)") + if proxy[1] == False: return - if proxy == "": + if proxy[0] == "": os.system("adb -s 192.168.250.2:5555 shell settings delete global http_proxy") os.system("adb -s 192.168.250.2:5555 shell settings delete global global_http_proxy_host") os.system("adb -s 192.168.250.2:5555 shell settings delete global global_http_proxy_port") - messagebox.showinfo(title="提示", message="设置成功!") + QtWidgets.QMessageBox.information(widget, "提示", "设置成功!") else: - os.system(f"adb -s 192.168.250.2:5555 shell settings put global http_proxy \"{proxy}\"") - messagebox.showinfo(title="提示", message="设置成功!") + os.system(f"adb -s 192.168.250.2:5555 shell settings put global http_proxy \"{proxy[0]}\"") + QtWidgets.QMessageBox.information(widget, "提示", "设置成功!") class SettingWindow(): saveApkOption = None + settingWindow = None def ShowWindow(): - setting = tk.Toplevel() - setting.resizable(0, 0) - setting.iconphoto(False, tk.PhotoImage(file=iconPath)) - setting.title("设置 UEngine 运行器" + version) - saveApkFrame = ttk.LabelFrame(setting, text="Apk 安装设置") + SettingWindow.settingWindow = QtWidgets.QMainWindow() + setting = QtWidgets.QWidget() + settingLayout = QtWidgets.QGridLayout() + + SettingWindow.saveApkOption = QtWidgets.QComboBox() + controlFrame = QtWidgets.QHBoxLayout() + cancalButton = QtWidgets.QPushButton("取消") + okButton = QtWidgets.QPushButton("保存") + + settingLayout.addWidget(QtWidgets.QLabel("APK 安装模式:"), 0, 0, 1, 1) + settingLayout.addWidget(SettingWindow.saveApkOption, 0, 1, 1, 1) + settingLayout.addLayout(controlFrame, 1, 1, 1, 1) + controlFrame.addItem(QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)) + controlFrame.addWidget(cancalButton) + controlFrame.addWidget(okButton) + + SettingWindow.saveApkOption.addItems(["不备份Apk包直接安装", "备份Apk包然后在安装后自动拷贝原先目录"]) try: data = json.loads(readtxt(get_home() + "/.config/uengine-runner/setting.json")) except: - messagebox.showerror(title="错误", message=langFile[lang]["Main"]["MainWindow"]["Error"]["SettingReadError"]) - setting.destroy() - SettingWindow.saveApkOption = tk.IntVar() - SettingWindow.saveApkOption.set(int(data["SaveApk"])) - ttk.Radiobutton(saveApkFrame, text="不备份Apk包直接安装", value=0, variable=SettingWindow.saveApkOption).pack(anchor=tk.W) - ttk.Radiobutton(saveApkFrame, text="备份Apk包然后在安装后自动拷贝原先目录", value=1, variable=SettingWindow.saveApkOption).pack(anchor=tk.W) - controlFrame = ttk.Frame(setting) - ttk.Button(controlFrame, text="取消", command=setting.destroy).grid(row=0, column=0) - ttk.Button(controlFrame, text="保存", command=SettingWindow.SaveSetting).grid(row=0, column=1) - saveApkFrame.pack() - controlFrame.pack(anchor=tk.E) + QtWidgets.QMessageBox.critical(widget, "错误", langFile[lang]["Main"]["MainWindow"]["Error"]["SettingReadError"]) + SettingWindow.settingWindow.close() + return + SettingWindow.saveApkOption.setCurrentIndex(int(data["SaveApk"])) + cancalButton.clicked.connect(SettingWindow.settingWindow.close) + okButton.clicked.connect(SettingWindow.SaveSetting) + + setting.setLayout(settingLayout) + SettingWindow.settingWindow.setWindowTitle(f"设置 UEngine 运行器 {version}") + SettingWindow.settingWindow.setWindowIcon(QtGui.QIcon(iconPath)) + SettingWindow.settingWindow.setCentralWidget(setting) + SettingWindow.settingWindow.show() + SettingWindow.settingWindow.setFixedSize(SettingWindow.settingWindow.frameSize().width(), SettingWindow.settingWindow.frameSize().height()) + return + def SaveSetting(): try: - write_txt(get_home() + "/.config/uengine-runner/setting.json", json.dumps({"SaveApk": bool(SettingWindow.saveApkOption.get())})) + write_txt(get_home() + "/.config/uengine-runner/setting.json", json.dumps({"SaveApk": bool(SettingWindow.saveApkOption.currentIndex())})) except: traceback.print_exc() - messagebox.showerror(title="错误", message=langFile[lang]["Main"]["MainWindow"]["Error"]["SettingSaveError"]) + QtWidgets.QMessageBox.critical(widget, "错误", langFile[lang]["Main"]["MainWindow"]["Error"]["SettingSaveError"]) return - messagebox.showinfo(title="提示", message="设置保存完毕!") + QtWidgets.QMessageBox.information(widget, "提示", "设置保存完毕!") class UpdateWindow(): data = {} + update = None def ShowWindow(): - 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.destroy) + UpdateWindow.update = QtWidgets.QMainWindow() + updateWidget = QtWidgets.QWidget() + updateWidgetLayout = QtWidgets.QGridLayout() + versionLabel = QtWidgets.QLabel(f"当前版本:{version}\n最新版本:未知\n更新内容:") + updateText = QtWidgets.QTextBrowser() + ok = QtWidgets.QPushButton("更新(更新过程中会关闭所有Python应用,包括这个应用)") + ok.clicked.connect(UpdateWindow.Update) + cancel = QtWidgets.QPushButton("取消") + cancel.clicked.connect(UpdateWindow.update.close) try: UpdateWindow.data = json.loads(requests.get("http://120.25.153.144/uengine-runner/update.json").text) - versionLabel = ttk.Label(update, text="当前版本:{}\n最新版本:{}\n更新内容:".format(version, UpdateWindow.data["Version"])) + versionLabel = QtWidgets.QLabel(f"当前版本:{version}\n最新版本:{UpdateWindow.data['Version']}\n更新内容:") if UpdateWindow.data["Version"] == version: - updateText.insert("0.0", "此为最新版本,无需更新") - ok.configure(state=tk.DISABLED) + updateText.setText("此为最新版本,无需更新") + ok.setDisabled(True) else: - updateText.insert("0.0", UpdateWindow.data["New"].replace("\\n", "\n")) + updateText.setText(UpdateWindow.data["New"].replace("\\n", "\n")) except: traceback.print_exc() - messagebox.showerror(title="错误", message=langFile[lang]["Main"]["MainWindow"]["Error"]["ConnectServerError"]) - 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() + QtWidgets.QMessageBox.critical(updateWidget, "错误", "无法连接服务器!") + updateWidgetLayout.addWidget(versionLabel, 0, 0, 1, 1) + updateWidgetLayout.addWidget(updateText, 1, 0, 1, 3) + updateWidgetLayout.addWidget(ok, 2, 2, 1, 1) + updateWidgetLayout.addWidget(cancel, 2, 1, 1, 1) + updateWidget.setLayout(updateWidgetLayout) + UpdateWindow.update.setCentralWidget(updateWidget) + UpdateWindow.update.setWindowTitle("检查更新") + UpdateWindow.setWindowIcon(QtGui.QIcon(iconPath)) + UpdateWindow.update.resize(updateWidget.frameGeometry().width(), int(updateWidget.frameGeometry().height() * 1.5)) + UpdateWindow.update.show() + def Update(): - if not os.path.exists("/tmp/uengine-runner/update"): - os.makedirs("/tmp/uengine-runner/update") + if os.path.exists("/tmp/uengine-runner/update"): + shutil.rmtree("/tmp/uengine-runner/update") + os.makedirs("/tmp/uengine-runner/update") try: - write_txt("/tmp/uengine-runner/update.sh", """#!/bin/bash + print(UpdateWindow.data["Url"]) + write_txt("/tmp/uengine-runner/update.sh", f"""#!/bin/bash echo 删除多余的安装包 rm -rfv /tmp/uengine-runner/update/* echo 关闭“UEngine 运行器”以及其它“Python 应用” killall python3 echo 下载安装包 -wget -P /tmp/uengine-runner/update {} +wget -P /tmp/uengine-runner/update {UpdateWindow.data["Url"][0]} echo 安装安装包 -dpkg -i /tmp/uengine-runner/update/*.deb +dpkg -i /tmp/uengine-runner/update/* echo 修复依赖关系 apt install -f -y -notify-send -i uengine "更新完毕!" +notify-send -i "{iconPath}" "更新完毕!" zenity --info --text=\"更新完毕!\" --ellipsize -""".format(UpdateWindow.data["Url"][int(information["Package"] == "com.gitee.uengine.runner.spark")], iconPath)) +""") except: traceback.print_exc() - easygui.textbox(title="错误", msg="更新出现错误,无法继续更新!", text=traceback.format_exc()) + QtWidgets.QMessageBox.critical(widget, "错误,无法继续更新", traceback.format_exc()) os.system(f"'{programPath}/launch.sh' deepin-terminal -e pkexec bash /tmp/uengine-runner/update.sh") image = None class ApkInformation(): + message = None def ShowWindows(): global fullInformation global path global tab1 - path = ComboInstallPath.get() + path = ComboInstallPath.currentText() package = GetApkPackageName(path) if package == None or package == "": - messagebox.showerror(title="错误", message=langFile[lang]["Main"]["MainWindow"]["Error"]["ApkFileError"]) + QtWidgets.QMessageBox.critical(widget, "错误", langFile[lang]["Main"]["MainWindow"]["Error"]["ApkFileError"]) return - message = tk.Toplevel() - message.title("“{}“的Apk信息".format(GetApkChineseLabel(path))) - message.iconphoto(False, tk.PhotoImage(file=iconPath)) - - tab = ttk.Notebook(message) + ApkInformation.message = QtWidgets.QMainWindow() + messageWidget = QtWidgets.QWidget() + messageLayout = QtWidgets.QVBoxLayout() + ApkInformation.message.setWindowTitle("“{}“的Apk信息".format(GetApkChineseLabel(path))) + #message.iconphoto(False, tk.PhotoImage(file=iconPath)) + tab = QtWidgets.QTabWidget() + #tab = ttk.Notebook(message) - tab1 = ttk.Frame(message) - tab2 = ttk.Frame(message) + tab1 = QtWidgets.QWidget() + tab2 = QtWidgets.QWidget() - fullInformation = tk.Text(tab2) - - tab.add(tab1, text="简化版") - tab.add(tab2, text="完整版") - - fullInformation.pack(expand="yes", fill="both") - - tab.pack(expand="yes", fill="both") - - threading.Thread(target=ApkInformation.GetInformation).start() - - message.mainloop() - - def GetInformation(): - # 获取详细信息 - fullInformation.configure(state=tk.NORMAL) - fullInformation.insert("1.0", GetApkInformation(path)) - fullInformation.configure(state=tk.DISABLED) - # 获取图标 + tab.addTab(tab1, "简化版") + tab1Layout = QtWidgets.QGridLayout() SaveApkIcon(path, "/tmp/uengine-runner-android-app-icon.png") - # 读取图标 - global image - image = Image.open("/tmp/uengine-runner-android-app-icon.png") - if image.size[0] + image.size[1] <= 512: - ttk.Label(tab1, image=ImageTk.PhotoImage(Image.open("/tmp/uengine-runner-android-app-icon.png"))).pack() - else: - ttk.Label(tab1, image=ImageTk.PhotoImage(Image.open("/tmp/uengine-runner-android-app-icon.png").resize((256, 256), Image.ANTIALIAS))).pack() - image.close() - info = '''包名:{} -中文名:{} -Activity:{} -版本:{}'''.format(GetApkPackageName(path), GetApkChineseLabel(path), GetApkActivityName(path), GetApkVersion(path)) - ttk.Label(tab1, text=info).pack() - ttk.Button(tab1, text="查看程序评分情况", command=ApkInformation.ShowMap).pack() - ttk.Button(tab1, text="上传程序评分情况", command=ApkInformation.UpdateMark).pack() + simpleInformation = QtWidgets.QLabel(f""" +
+包名:{GetApkPackageName(path)}
+中文名:{GetApkChineseLabel(path)}
+Activity:{GetApkActivityName(path)}
+版本:{GetApkVersion(path)}
""") + + seeFen = QtWidgets.QPushButton("查看程序评分情况") + updFen = QtWidgets.QPushButton("上传程序评分情况") + seeFen.clicked.connect(ApkInformation.ShowMap) + updFen.clicked.connect(ApkInformation.UpdateMark) + tab1Layout.addWidget(simpleInformation, 0, 0, 1, 3) + tab1Layout.addWidget(seeFen, 1, 1, 1, 1) + tab1Layout.addWidget(updFen, 2, 1, 1, 1) + tab1.setLayout(tab1Layout) + + tab.addTab(tab2, "完整版") + tab2Layout = QtWidgets.QVBoxLayout() + fullInformation = QtWidgets.QTextBrowser() + fullInformation.setText(GetApkInformation(path)) + tab2Layout.addWidget(fullInformation) + tab2.setLayout(tab2Layout) + + messageLayout.addWidget(tab) + messageWidget.setLayout(messageLayout) + ApkInformation.message.setCentralWidget(messageWidget) + ApkInformation.message.setWindowIcon(QtGui.QIcon(iconPath)) + ApkInformation.message.setWindowTitle("APK 信息") + ApkInformation.message.show() + return def UpdateMark(): - #message = tk.Toplevel() - #message.iconphoto(False, tk.PhotoImage(file=iconPath)) - choose = easygui.indexbox(title="选择评分", choices=["含有不良信息", "0分", "1分", "2分", "3分", "4分", "5分", "取消"], msg="""选择应用“{}”的使用评分。建议参考如下规范进行评分: + chooseWindow = QtWidgets.QMessageBox() + chooseWindow.setWindowTitle("选择评分") + chooseWindow.setText(f"""选择应用“{GetApkChineseLabel(path)}”的使用评分。建议参考如下规范进行评分: 含有不良信息(-1分):含有违法违规信息(如果有就不要选择其它选项了) 0星:完全无法使用,连安装都有问题 1星:完全无法使用,但是能正常安装 @@ -903,26 +921,48 @@ Activity:{} 3星:勉强能使用,运行也不大流畅 4星:大部分功能正常,运行流畅(可能会有点小卡) 5星:完全正常且非常流畅,没有任何功能和性能问题,就和直接在手机上用一样 -""".format(GetApkChineseLabel(path))) +""") + choices=["含有不良信息", "0分", "1分", "2分", "3分", "4分", "5分", "取消"] + button0 = chooseWindow.addButton(choices[0], QtWidgets.QMessageBox.ActionRole) + button1 = chooseWindow.addButton(choices[1], QtWidgets.QMessageBox.ActionRole) + button2 = chooseWindow.addButton(choices[2], QtWidgets.QMessageBox.ActionRole) + button3 = chooseWindow.addButton(choices[3], QtWidgets.QMessageBox.ActionRole) + button4 = chooseWindow.addButton(choices[4], QtWidgets.QMessageBox.ActionRole) + button5 = chooseWindow.addButton(choices[5], QtWidgets.QMessageBox.ActionRole) + button6 = chooseWindow.addButton(choices[6], QtWidgets.QMessageBox.ActionRole) + button7 = chooseWindow.addButton(choices[7], QtWidgets.QMessageBox.ActionRole) + button0.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(0))) + button1.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(1))) + button2.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(2))) + button3.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(3))) + button4.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(4))) + button5.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(5))) + button6.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(6))) + button7.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(7))) + chooseWindow.exec_() + return + + def UpdateMarkInternet(choose): print(choose) if choose == None or choose == 7: return try: - messagebox.showinfo(title="提示", message=requests.post("http://120.25.153.144/uengine-runner/app/check/add.php", {"Package": GetApkPackageName(path), "Type": choose}).text) + QtWidgets.QMessageBox.critical(widget, "提示", requests.post("http://120.25.153.144/uengine-runner/app/check/add.php", {"Package": GetApkPackageName(path), "Type": choose}).text) except: - messagebox.showerror(title="错误", message=langFile[lang]["Main"]["MainWindow"]["Error"]["ConnectServerStarError"]) + traceback.print_exc() + QtWidgets.QMessageBox.critical(widget, "错误", langFile[lang]["Main"]["MainWindow"]["Error"]["ConnectServerStarError"]) def ShowMap(): package = GetApkPackageName(path) if package == None or package == "": - messagebox.showerror(title="错误", message=langFile[lang]["Main"]["MainWindow"]["Error"]["ApkFileError"]) + QtWidgets.QMessageBox.critical(widget, "错误", langFile[lang]["Main"]["MainWindow"]["Error"]["ApkFileError"]) return try: data = json.loads(requests.get("http://120.25.153.144/uengine-runner/app/check/" + package +"/data.json").text) print(data) except: - messagebox.showinfo(title="错误", message="此程序暂时没有评分,欢迎您贡献第一个评分!") + QtWidgets.QMessageBox.information(widget, "提示", "此程序暂时没有评分,欢迎您贡献第一个评分!") return index = numpy.arange(len(data)) print(index) @@ -935,14 +975,37 @@ Activity:{} matplotlib.pylab.xlabel("用户评分数", fontproperties=fonts) matplotlib.pylab.ylabel("等级", fontproperties=fonts) matplotlib.pylab.title("“" + chinese + "”的用户评分(数据只供参考)", fontproperties=fonts) - matplotlib.pylab.show() + matplotlib.pylab.show(block=True) class AdbChangeUengineDisplaySize(): + messageWindow = None def ShowWindows(): global displayX global displayY global displaySize - message = tk.Toplevel() + AdbChangeUengineDisplaySize.messageWindow = QtWidgets.QMainWindow() + message = QtWidgets.QWidget() + messageLayout = QtWidgets.QGridLayout() + + displaySize = QtWidgets.QLabel("当前 UEngine 屏幕分辨率:\n" + subprocess.getoutput("adb -s '192.168.250.2:5555' shell wm size")) + displayX = QtWidgets.QLineEdit() + displayY = QtWidgets.QLineEdit() + setButton = QtWidgets.QPushButton("设置分辨率") + setButton.setSizePolicy(size) + setButton.clicked.connect(AdbChangeUengineDisplaySize.SettingDisplaySize) + messageLayout.addWidget(displaySize, 0, 0, 1, 3) + messageLayout.addWidget(displayX, 1, 0, 1, 1) + messageLayout.addWidget(QtWidgets.QLabel("×")) + messageLayout.addWidget(displayY, 1, 2, 1, 1) + messageLayout.addWidget(setButton, 2, 0, 1, 3, QtCore.Qt.AlignCenter) + + + message.setLayout(messageLayout) + AdbChangeUengineDisplaySize.messageWindow.setCentralWidget(message) + AdbChangeUengineDisplaySize.messageWindow.setWindowTitle("修改 UEngine 分辨率") + AdbChangeUengineDisplaySize.messageWindow.setWindowIcon(QtGui.QIcon(iconPath)) + AdbChangeUengineDisplaySize.messageWindow.show() + return message.iconphoto(False, tk.PhotoImage(file=iconPath)) messageFrame = ttk.Frame(message) @@ -983,156 +1046,97 @@ class AdbChangeUengineDisplaySize(): def GetUengineDisplaySize(): global displaySize - displaySize.set("当前 UEngine 屏幕分辨率:\n" + subprocess.getoutput("adb -s '192.168.250.2:5555' shell wm size")) + displaySize.setText("当前 UEngine 屏幕分辨率:\n" + subprocess.getoutput("adb -s '192.168.250.2:5555' shell wm size")) #displaySize.set(subprocess.getoutput("adb -s '192.168.250.2:5555' shell wm size")) def SettingDisplaySize(): global displayX global displayY try: - int(displayX.get()) - int(displayY.get()) + int(displayX.text()) + int(displayY.text()) except: - messagebox.showerror(title="错误", message=langFile[lang]["Main"]["MainWindow"]["Error"]["InputDataError"]) + QtWidgets.QMessageBox.critical(widget, "错误", langFile[lang]["Main"]["MainWindow"]["Error"]["InputDataError"]) return - os.system("adb -s '192.168.250.2:5555' shell wm size {}x{}".format(displayX.get(), displayY.get())) + os.system("adb -s '192.168.250.2:5555' shell wm size {}x{}".format(displayX.text(), displayY.text())) AdbChangeUengineDisplaySize.GetUengineDisplaySize() - messagebox.showinfo(title="提示", message="执行完毕!") - -# 运行命令的窗口 -class InstallWindow(): - # 显示窗口 - def ShowWindows(command): - global message - global text - global installTipsText - global progressbar - global runCommand - message = tk.Toplevel() - message.title("执行命令") - message.iconphoto(False, tk.PhotoImage(file=iconPath)) - messageFrame = ttk.Frame(message) - installTipsText = tk.StringVar() - message.title("正在操作……") - installTipsText.set("正在操作……") - installTips = ttk.Label(messageFrame, textvariable=installTipsText) - progressbar = ttk.Progressbar(messageFrame, length=500, mode='indeterminate') - text = tk.Text(messageFrame) - text.config(background="black", foreground="white") - installTips.pack() - progressbar.pack(fill="x") - text.pack(expand='yes', fill='both') - messageFrame.pack(expand='yes', fill='both') - print("Run!") - threading.Thread(target=InstallWindow.RunCommand, args=[command]).start() - message.mainloop() - - # 运行命令并显示 - def RunCommand(command): - global message - global text - global progressbar - global installTipsText - InstallWindow.AddText("$>" + command + "\n") - progressbar.start() - res = subprocess.Popen([command], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - # 实时读取程序返回 - while res.poll() is None: - try: - texts = res.stdout.readline().decode("utf8") - except: - texts = "" - print(texts, end="") - InstallWindow.AddText(texts) - messagebox.showinfo(title="提示", message="操作完毕!") - installTipsText.set("操作完毕!") - message.title("操作完毕!") - progressbar.stop() - progressbar["value"] = 100 - # 特意添加! - DisabledAndEnbled(False) - if command == "pkexec rm -rfv /data/uengine": - print("Clean!") - if messagebox.askyesno(title="提示", message="清空完毕,将会在重启后生效,是否要重启?"): - print("reboot") - os.system("reboot") - - # 添加文本 - def AddText(things): - global text - text.configure(state=tk.NORMAL) - text.insert("end", things) - text.configure(state=tk.DISABLED) + QtWidgets.QMessageBox.information(widget, "提示", "执行完毕!") class ShowTextTipsWindow(): + messageWindow = None def ShowWindow(things): - message = tk.Toplevel() + ShowTextTipsWindow.messageWindow = QtWidgets.QMainWindow() + message = QtWidgets.QWidget() + messageLayout = QtWidgets.QVBoxLayout() - message.title("提示") - message.iconphoto(False, tk.PhotoImage(file=iconPath)) + text = QtWidgets.QTextBrowser() + text.setText(things) + ok = QtWidgets.QPushButton("确定") + ok.clicked.connect(ShowTextTipsWindow.messageWindow.close) + #ok.setSizePolicy(size) - text = tk.Text(message) - quitButton = ttk.Button(message, text="确定", command=message.destroy) + messageLayout.addWidget(text) + messageLayout.addWidget(ok) - text.insert("end", things) - text.configure(state=tk.DISABLED) - - text.pack(fill="both", expand="yes") - quitButton.pack() - - message.mainloop() + message.setLayout(messageLayout) + ShowTextTipsWindow.messageWindow.setCentralWidget(message) + ShowTextTipsWindow.messageWindow.setWindowTitle("提示") + ShowTextTipsWindow.messageWindow.setWindowIcon(QtGui.QIcon(iconPath)) + ShowTextTipsWindow.messageWindow.show() + ShowTextTipsWindow.messageWindow.resize(ShowTextTipsWindow.messageWindow.frameSize().width() * 2, ShowTextTipsWindow.messageWindow.frameSize().height() * 1.5) + return # 添加/删除 uengine 应用快捷方式 class AddNewUengineDesktopLink(): addTips = '''可以输入app的包名和Activity或通过浏览apk文件来获取包名和Activity 注意:如果是要删除只要输入包名即可''' + messageWindow = None def ShowWindow(): global activityName global packageName - message = tk.Toplevel() - message.iconphoto(False, tk.PhotoImage(file=iconPath)) + AddNewUengineDesktopLink.messageWindow = QtWidgets.QMainWindow() + message = QtWidgets.QWidget() + messageLayout = QtWidgets.QGridLayout() - tipsLabel = ttk.Label(message, text=AddNewUengineDesktopLink.addTips) - packageName = ttk.Combobox(message, width=30) - activityName = ttk.Combobox(message, width=30) - findApk = ttk.Button(message, text="浏览", command=AddNewUengineDesktopLink.FindApk) - controlFrame = ttk.Frame(message) - testOpen = ttk.Button(controlFrame, text="打开", command=AddNewUengineDesktopLink.TestOpen) - saveButton = ttk.Button(controlFrame, text="写入", command=AddNewUengineDesktopLink.SaveDesktopLink) - delButton = ttk.Button(controlFrame, text="删除", command=AddNewUengineDesktopLink.DelDesktopLink) + activityName = QtWidgets.QLineEdit() + packageName = QtWidgets.QLineEdit() + browser = QtWidgets.QPushButton("浏览……") + controlFrame = QtWidgets.QHBoxLayout() + open = QtWidgets.QPushButton("打开") + save = QtWidgets.QPushButton("保存") + delete = QtWidgets.QPushButton("删除") - message.title("添加/删除 UEngine 图标") - message.resizable(0, 0) - message.iconphoto(False, tk.PhotoImage(file=iconPath)) - # get screen width and height - screen_width = message.winfo_screenwidth() - screen_height = message.winfo_screenheight() - # calculate position x and y coordinates 假设主窗口大小固定 570x236像素 ,设置窗口位置为屏幕中心。 - winwith=570 - winhigh=236 - x = (screen_width/2) - (winwith/2) - y = (screen_height/2) - (winhigh/2) - message.geometry("+{}+{}".format(int(x), int(y))) - - packageName["value"] = findApkNameHistory - activityName["value"] = findApkActivityHistory + packageName.setPlaceholderText("APK 包名") + activityName.setPlaceholderText("APK 的 Activity") - tipsLabel.grid(row=0, column=0, columnspan=3) - packageName.grid(row=1, column=0) - activityName.grid(row=1, column=1) - findApk.grid(row=1, column=2) - controlFrame.grid(row=2, column=0, columnspan=3) - testOpen.grid(row=0, column=0) - saveButton.grid(row=0, column=1) - delButton.grid(row=0, column=2) + browser.clicked.connect(AddNewUengineDesktopLink.FindApk) + open.clicked.connect(AddNewUengineDesktopLink.TestOpen) + save.clicked.connect(AddNewUengineDesktopLink.SaveDesktopLink) + delete.clicked.connect(AddNewUengineDesktopLink.DelDesktopLink) - message.mainloop() + messageLayout.addWidget(QtWidgets.QLabel(AddNewUengineDesktopLink.addTips), 0, 0, 1, 3) + messageLayout.addWidget(packageName, 1, 0, 1, 1) + messageLayout.addWidget(activityName, 1, 1, 1, 1) + messageLayout.addWidget(browser, 1, 2, 1, 1) + messageLayout.addLayout(controlFrame, 2, 0, 1, 3) + controlFrame.addItem(QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)) + controlFrame.addWidget(open) + controlFrame.addWidget(save) + controlFrame.addWidget(delete) + controlFrame.addItem(QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)) + + message.setLayout(messageLayout) + AddNewUengineDesktopLink.messageWindow.setCentralWidget(message) + AddNewUengineDesktopLink.messageWindow.setWindowTitle("添加/删除 UEngine 图标") + AddNewUengineDesktopLink.messageWindow.setWindowIcon(QtGui.QIcon(iconPath)) + AddNewUengineDesktopLink.messageWindow.show() + return # 添加快捷方式 def SaveDesktopLink(): try: if os.path.exists("{}/.local/share/applications/uengine/{}.desktop".format(get_home(), packageName.get())): - if not messagebox.askokcancel(title="提示", message="文件已存在,确定要覆盖吗?"): + if QtWidgets.QMessageBox.question(widget, "提示", "文件已存在,是否要覆盖?") == QtWidgets.QMessageBox.No: return if not os.path.exists("{}/.local/share/icons/hicolor/256x256/apps/".format(get_home())): os.makedirs("{}/.local/share/icons/hicolor/256x256/apps/".format(get_home())) @@ -1144,10 +1148,10 @@ class AddNewUengineDesktopLink(): BuildUengineDesktop(packageName.get(), activityName, packageName.get(), iconSavePath, "{}/{}.desktop".format(get_desktop_path(), packageName.get())) AddNewUengineDesktopLink.SaveHistory() - messagebox.showinfo(title="提示", message="创建完毕!") + QtWidgets.QMessageBox.information(widget, "提示", "创建完毕!") except: traceback.print_exc() - messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.information(widget, "错误", traceback.format_exc()) # 删除快捷方式 @@ -1155,49 +1159,49 @@ class AddNewUengineDesktopLink(): try: global packageName if not os.path.exists("{}/.local/share/applications/uengine/{}.desktop".format(get_home(), packageName.get())): - messagebox.showerror(title="错误", message="此包名对应的 UEngine 桌面快捷方式不存在!") + QtWidgets.QMessageBox.critical(widget, "错误", "此包名对应的 UEngine 桌面快捷方式不存在!") return - if not messagebox.askyesno(title="提示", message="你确定要删除吗?删除后将无法恢复!"): + if QtWidgets.QMessageBox.warning(widget, "警告", "你确定要删除吗?删除后将无法恢复!", QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel, QtWidgets.QMessageBox.Cancel) == QtWidgets.QMessageBox.Cancel: return try: os.remove("{}/.local/share/applications/uengine/{}.desktop".format(get_home(), packageName.get())) AddNewUengineDesktopLink.SaveHistory() - messagebox.showinfo(title="提示", message="已删除") + QtWidgets.QMessageBox.information(widget, "提示", "已删除") except: traceback.print_exc() - messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.critical(widget, "错误", traceback.format_exc()) except: traceback.print_exc() - messagebox.showerror(title="错误", message=traceback.format_exc()) + QtWidgets.QMessageBox.critical(widget, "错误", traceback.format_exc()) # 保存历史记录 def SaveHistory(): - findApkNameHistory.append(packageName.get()) - findApkActivityHistory.append(activityName.get()) - packageName['value'] = findApkNameHistory - activityName['value'] = findApkActivityHistory + findApkNameHistory.append(packageName.text()) + findApkActivityHistory.append(activityName.text()) + #packageName['value'] = findApkNameHistory + #activityName['value'] = findApkActivityHistory write_txt(get_home() + "/.config/uengine-runner/FindApkNameHistory.json", str(json.dumps(ListToDictionary(findApkNameHistory)))) # 将历史记录的数组转换为字典并写入 write_txt(get_home() + "/.config/uengine-runner/FindApkActivityHistory.json", str(json.dumps(ListToDictionary(findApkActivityHistory)))) # 将历史记录的数组转换为字典并写入 # 打开测试 def TestOpen(): - threading.Thread(target=os.system, args=["/usr/bin/uengine launch --package={} --component={}".format(packageName.get(), activityName.get())]).start() + threading.Thread(target=os.system, args=["/usr/bin/uengine launch --package={} --component={}".format(packageName.text(), activityName.text())]).start() AddNewUengineDesktopLink.SaveHistory() # 浏览文件 def FindApk(): - path = filedialog.askopenfilename(title="选择apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApkName.json"))["path"]) - if path == "" or path == (): + path = QtWidgets.QFileDialog.getOpenFileName(widget, "选择apk", "~", "APK 文件(*.apk);;所有文件(*.*)", json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApkName.json"))["path"])[0] + if path == "" or path == () or path == None: return - packageName.set(GetApkPackageName(path)) - activityName.set(str(GetApkActivityName(path))) + packageName.setText(GetApkPackageName(path)) + activityName.setText(str(GetApkActivityName(path))) write_txt(get_home() + "/.config/uengine-runner/FindApkName.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件 def UseProgram(): global useProgram useProgram = '''1、UEngine:{} 2、python3:{} -3、tkinter:{} +3、PyQt:{} 4、aapt:{} 5、dpkg:{} 6、mkdir:{} @@ -1206,7 +1210,7 @@ def UseProgram(): 9、adb:{} 10、deepin 终端:{}'''.format(subprocess.getoutput("uengine version"), subprocess.getoutput("python3 --version"), - tk.TkVersion, + QtCore.qVersion, subprocess.getoutput("aapt version"), subprocess.getoutput("dpkg --version"), subprocess.getoutput("mkdir --version"), @@ -1214,6 +1218,10 @@ def UseProgram(): subprocess.getoutput("adb version"), subprocess.getoutput("deepin-terminal -v")) +def BackAPK(choice): + global choose + choose = choice + ########################### # 程序信息 ########################### @@ -1228,28 +1236,30 @@ version = information["Version"] goodRunSystem = information["System"] aaptVersion = GetCommandReturn("aapt version") SystemVersion = GetSystemVersion() -about = '''介绍 :一个基于 Python3 的 tkinter 制作的 UEngine 运行器,在新版本Deepin/UOS发布后,可以在应用商店安装部分官方已适配的安卓应用,对爱好者来说,不能自己安装APK软件包始终差点意思,本程序可以为Deepin/UOS上的UEngine安卓运行环境安装自定义APK软件包,并能发送安装的APK包启动菜单到桌面或系统菜单。 - -版本 :{} - -适用平台 :{} - -Tk 版本 :{} - -程序官网 :{} - -系统版本 : {} - -©2021-{}'''.format(version, goodRunSystem, tk.TkVersion, programUrl, SystemVersion, time.strftime("%Y")) -tips = "\n".join(information["Tips"]) -updateThingsString = "\n".join(information["Update"]) +iconPath = "{}/runner.svg".format(os.path.split(os.path.realpath(__file__))[0]) +about = f''' +介绍 :一个基于 Python3 的 PyQt5 制作的 UEngine 运行器,在新版本Deepin/UOS发布后,可以在应用商店安装部分官方已适配的安卓应用,对爱好者来说,不能自己安装APK软件包始终差点意思,本程序可以为Deepin/UOS上的UEngine安卓运行环境安装自定义APK软件包,并能发送安装的APK包启动菜单到桌面或系统菜单。
+版本 :{version}
+适用平台 :{goodRunSystem}
+Qt 版本 :{QtCore.qVersion()}
+程序官网 :{programUrl}
+系统版本 : {SystemVersion}
+{i}
" +for i in information["Update"]: + updateThingsString += f"{i}
" +for i in information["Contribute"]: + contribute += f"