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}

+

©2021-{time.strftime("%Y")}

''' +updateThingsString = "" +tips = "" +contribute = "" title = "{} {}".format(langFile[lang]["Main"]["MainWindow"]["Title"], version) updateTime = information["Time"] updateThings = "{} 更新内容:\n{}\n更新时间:{}".format(version, updateThingsString, updateTime, time.strftime("%Y")) -iconPath = "{}/runner.png".format(os.path.split(os.path.realpath(__file__))[0]) desktop = programPath + "/UengineAndroidProgramList.desktop" desktopName = "UengineAndroidProgramList.desktop" -contribute = "\n".join(information["Contribute"]) useProgram = "" threading.Thread(target=UseProgram).start() @@ -1278,9 +1288,10 @@ if not os.path.exists(get_home() + "/.config/uengine-runner/SaveApkIcon.json"): write_txt(get_home() + "/.config/uengine-runner/SaveApkIcon.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件 if not os.path.exists(get_home() + "/.config/uengine-runner/SaveApk.json"): # 如果没有配置文件 write_txt(get_home() + "/.config/uengine-runner/SaveApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件 +app = QtWidgets.QApplication(sys.argv) if not os.path.exists(get_home() + "/.config/uengine-runner/setting.json"): - choose = None - choose = easygui.indexbox(msg="""在使用本程序前,请选择安装Apk包的设置以便更好的运行,下列选项的详细介绍: + choosemsg = QtWidgets.QMessageBox() + choosemsg.setText("""在使用本程序前,请选择安装Apk包的设置以便更好的运行,下列选项的详细介绍: 不备份Apk包直接安装:适用于Deepin(旧版UEngine),安装较快,不受/tmp大小所限,但Deepin23和UOS(新版UEngine)不推荐此选项,因为安装后会自动删除Apk安装包; 备份Apk包然后在安装后自动拷贝原先目录:适用于Deepin23和UOS(新版UEngine),安装较慢,受/tmp大小所限,安装后不会丢失Apk,Deepin(旧版UEngine)不推荐使用该选项; @@ -1288,11 +1299,15 @@ if not os.path.exists(get_home() + "/.config/uengine-runner/setting.json"): 后期可以在程序主界面的菜单栏的“程序”=>“设置”里进行修改, 如果不知道正在使用的系统是什么版本可以打开系统设置查看。 -""", title="设置", choices=["不备份Apk包直接安装", "备份Apk包然后在安装后自动拷贝原先目录"]) +""") + choosemsg.setWindowTitle("设置") + choose = None + choosemsg.addButton("不备份Apk包直接安装", QtWidgets.QMessageBox.ActionRole).clicked.connect(lambda: BackAPK(0)) + choosemsg.addButton("备份Apk包然后在安装后自动拷贝原先目录", QtWidgets.QMessageBox.ActionRole).clicked.connect(lambda: BackAPK(1)) + #choose = easygui.indexbox(title="设置", choices=["不备份Apk包直接安装", "备份Apk包然后在安装后自动拷贝原先目录"]) + choosemsg.exec_() if choose == None: - root = tk.Tk() - root.withdraw() - messagebox.showinfo(title="提示", message="必须选择一个选项!否则无法进入程序!") + QtWidgets.QMessageBox.information(None, "提示", "必须选择一个选项!否则无法进入程序!") sys.exit() write_txt(get_home() + "/.config/uengine-runner/setting.json", json.dumps({"SaveApk": int(choose)})) @@ -1308,149 +1323,95 @@ findApkActivityHistory = list(json.loads(readtxt(get_home() + "/.config/uengine- # add sub window #添加窗口开启关闭开关,防止重复开启 windowflag = "close" - -def showhelp(): - - #define window and frame and button label - # - global windowflag - if windowflag == "close": - helpwindow=tk.Toplevel() - helpwindow.resizable(0, 0) - helpwindow.title("帮助") - helpwindow.iconphoto(False, tk.PhotoImage(file=iconPath)) - - # get screen width and height - screen_width = helpwindow.winfo_screenwidth() - screen_height = helpwindow.winfo_screenheight() - # calculate position x and y coordinates 假设主窗口大小固定 570x236像素 ,设置窗口位置为屏幕中心。 - - - winwith=550 - winhigh=700 - x = (screen_width/2) - (winwith/2) - y = (screen_height/2) - (winhigh/2) - if not helpwindow.winfo_screenheight() > 1080: - helpwindow.geometry(f"{winwith}x{winhigh}"+"+{:.0f}+{:.0f}".format(x, y)) - - - Frmroot=ttk.Frame(helpwindow) - FrmMenu = ttk.Frame(Frmroot) - FrmText = ttk.Frame(Frmroot) - - LabFrmText=ttk.LabelFrame(FrmText,text="帮助",height=800,borderwidth=3) - HelpStr = tk.StringVar() - HelpStr.set(tips) - LabText = ttk.Label(LabFrmText, textvariable=HelpStr,width=55) - LabText.config(wraplength=350) - - def on_closing(): - global windowflag - windowflag = "close" - print(windowflag) - helpwindow.destroy() - - - - # define button func - def ChgLog(): - HelpStr.set(updateThingsString) - def ChgAbout(): - HelpStr.set(about) - def ChgDep(): - if useProgram == "": - BtnZujian.configure(state=tk.DISABLED) - return - HelpStr.set(useProgram) - def ChgCon(): - HelpStr.set(contribute) - def ChgTips(): - HelpStr.set(tips) - LabText.config(wraplength=350) - def Egg(event): - try: - lists = json.loads(requests.get("http://120.25.153.144/uengine-runner/VersionList.json").text) - data = [] - for i in lists: - data.append(int(requests.get("http://120.25.153.144/uengine-runner/{}/data.txt".format(i)).text)) - except: - messagebox.showerror(title="错误", message="服务器出错!数据获取失败!") - return - fig = matplotlib.pylab.figure() - fig.canvas.set_window_title("“UEngine 运行器”安装数(数据只供参考)") - matplotlib.pylab.plot(lists, data) - index = numpy.arange(len(lists)) - fonts = matplotlib.font_manager.FontProperties(fname='/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc') # 用于支持中文显示,需要依赖fonts-noto-cjk - matplotlib.pylab.xlabel("版本号", fontproperties=fonts) - matplotlib.pylab.ylabel("安装数", fontproperties=fonts) +def Egg(): + try: + lists = json.loads(requests.get("http://120.25.153.144/uengine-runner/VersionList.json").text) + data = [] + for i in lists: + data.append(int(requests.get("http://120.25.153.144/uengine-runner/{}/data.txt".format(i)).text)) + except: + QtWidgets.QMessageBox.critical(widget, "错误", "服务器出错!数据获取失败!") + return + fig = matplotlib.pylab.figure() + fig.canvas.set_window_title("“UEngine 运行器”安装数(数据只供参考)") + matplotlib.pylab.plot(lists, data) + index = numpy.arange(len(lists)) + fonts = matplotlib.font_manager.FontProperties(fname='/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc') # 用于支持中文显示,需要依赖fonts-noto-cjk + matplotlib.pylab.xlabel("版本号", fontproperties=fonts) + matplotlib.pylab.ylabel("安装数", fontproperties=fonts) - matplotlib.pylab.title("“UEngine 运行器”安装数(数据只供参考)", fontproperties=fonts) - matplotlib.pylab.show() + matplotlib.pylab.title("“UEngine 运行器”安装数(数据只供参考)", fontproperties=fonts) + matplotlib.pylab.show() +helpWindow = None +def showhelp(): + global helpWindow + helpWindow = QtWidgets.QMainWindow() + helpWidget = QtWidgets.QWidget() + helpLayout = QtWidgets.QGridLayout() - BtnReadme = ttk.Button(FrmMenu, text="使用说明",width=14,command=ChgTips) - BtnLog = ttk.Button(FrmMenu, text="更新内容",width=14,command=ChgLog) - BtnZujian = ttk.Button(FrmMenu, text="程序依赖的组件",width=14,command=ChgDep) - BtnGongxian = ttk.Button(FrmMenu, text="有贡献的开发者",width=14,command=ChgCon) - BtnAbout = ttk.Button(FrmMenu, text="关于",width=14,command=ChgAbout) - BtnAbout.bind("", Egg) + def ChgLog(): + HelpStr.setHtml(updateThingsString) + def ChgAbout(event): + HelpStr.setHtml(about) + def ChgDep(): + if useProgram == "": + BtnZujian.setDisabled(True) + return + HelpStr.setHtml(useProgram) + def ChgCon(): + HelpStr.setHtml(contribute) + def ChgTips(): + HelpStr.setHtml(tips) + + + BtnReadme = QtWidgets.QPushButton("使用说明") + BtnLog = QtWidgets.QPushButton("更新内容") + BtnZujian = QtWidgets.QPushButton("程序依赖的组件") + BtnGongxian = QtWidgets.QPushButton("有贡献的开发者") + BtnAbout = QtWidgets.QPushButton("关于") + HelpStr = QtWidgets.QTextBrowser() + BtnReadme.clicked.connect(ChgTips) + BtnLog.clicked.connect(ChgLog) + BtnZujian.clicked.connect(ChgDep) + BtnGongxian.clicked.connect(ChgCon) + BtnAbout.clicked.connect(ChgAbout) - #layout - FrmMenu.grid(row=0,column=0,sticky=tk.NW) - BtnReadme.grid(row=0,column=0,sticky=tk.NW,padx=3) - BtnLog.grid(row=1,column=0,sticky=tk.NW,padx=3) - BtnZujian.grid(row=2,column=0,sticky=tk.NW,padx=3) - BtnGongxian.grid(row=3,column=0,sticky=tk.NW,padx=3) - BtnAbout.grid(row=4,column=0,sticky=tk.NW,padx=3) + ChgTips() + + helpLayout.addWidget(BtnReadme, 0, 0, 1, 1) + helpLayout.addWidget(BtnLog, 1, 0, 1, 1) + helpLayout.addWidget(BtnZujian, 2, 0, 1, 1) + helpLayout.addWidget(BtnGongxian, 3, 0, 1, 1) + helpLayout.addWidget(BtnAbout, 4, 0, 1, 1) + helpLayout.addWidget(HelpStr, 0, 1, 6, 1) + + helpWidget.setLayout(helpLayout) + helpWindow.setCentralWidget(helpWidget) + helpWindow.setFixedSize(helpWindow.frameSize().width() * 0.9, helpWindow.frameSize().height() * 1.5) + helpWindow.setWindowTitle("帮助") + helpWindow.setWindowIcon(QtGui.QIcon(iconPath)) + helpWindow.show() + return - FrmText.grid(row=0,column=1,sticky=tk.NW) - LabFrmText.grid(row=0,column=0,sticky=tk.NW,padx=3,pady=3) - LabText.grid(row=0,column=0,sticky=tk.NW) - - Frmroot.pack() - windowflag = "open" - print(windowflag) - #helpwindow.mainloop() - helpwindow.protocol("WM_DELETE_WINDOW", on_closing) -# 读取主题 -try: - theme = not ("dark" in readtxt(get_home() + "/.gtkrc-2.0") and "gtk-theme-name=" in readtxt(get_home() + "/.gtkrc-2.0")) -except: - print("主题读取错误,默认使用浅色主题") - theme = True -if theme: - win = tk.Tk() - themes = ttkthemes.ThemedStyle(win) - themes.set_theme("breeze") -else: - import ttkbootstrap - style = ttkbootstrap.Style(theme="darkly") - win = style.master # 创建窗口 ########################### # 检查 UEngine 是否安装 ########################### if not os.path.exists("/usr/bin/uengine"): - # 不渲染窗口 - style = ttkthemes.ThemedStyle(win) - style.set_theme("breeze") - win.withdraw() # Deepin/UOS 用户 if "deepin" in SystemVersion.lower() or "uos" in SystemVersion.lower(): - if messagebox.askyesno(title="提示", message="您的电脑没有安装 UEngine,是否安装 UEngine 以便更好的使用\n安装完后重新启动该程序即可"): + if QtWidgets.QMessageBox.question(None, "提示", "您的电脑没有安装 UEngine,是否安装 UEngine 以便更好的使用\n安装完后重新启动该程序即可") == QtWidgets.QMessageBox.Yes: os.system(f"'{programPath}/launch.sh' deepin-terminal -C \"pkexec apt install uengine -y\"") sys.exit(0) # 非 Deepin/UOS 用户 else: - if messagebox.askyesno(title="提示", message="您的电脑没有安装 UEngine,是否安装 UEngine 以便更好的使用\n这里将会使用 shenmo 提供的脚本进行安装\n安装完后重新启动该程序即可\n提示:无法保证此安装脚本安装的 UEngine 可以使用"): + if QtWidgets.QMessageBox.question(None, "提示", "您的电脑没有安装 UEngine,是否安装 UEngine 以便更好的使用\n这里将会使用 shenmo 提供的脚本进行安装\n安装完后重新启动该程序即可\n提示:无法保证此安装脚本安装的 UEngine 可以使用") == QtWidgets.QMessageBox.Yes: os.system(f"'{programPath}/launch.sh' deepin-terminal -C \"bash '{programPath}/uengine-installer'\"") sys.exit(0) - # 重新显示窗口 - win.wm_deiconify() ########################### # 窗口创建 ########################### -app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() widget = QtWidgets.QWidget() widgetLayout = QtWidgets.QGridLayout() @@ -1477,7 +1438,19 @@ FrmInstallWidget.setSizePolicy(size) BtnShowUengineApp.setSizePolicy(size) ComboInstallPath.setEditable(True) ComboInstallPath.addItems(findApkHistory) +ComboInstallPath.setEditText("") ComboInstallPath.setFixedSize(ComboInstallPath.frameSize().width() * 5, ComboInstallPath.frameSize().height()) +try: + if sys.argv[1] == "-i": + ComboInstallPath.setCurrentText(sys.argv[2]) + print("Install Path: " + sys.argv[2]) + elif sys.argv[1] == "-u": + ComboInstallPath.setCurrentText(sys.argv[2]) + print("Unstall Path: " + sys.argv[2]) + else: + print("Command Format Error") +except: + print("Not Command Or Command Format Error") # 绑定信号 BtnFindApk.clicked.connect(FindApk) BtnInstall.clicked.connect(Button3Install) @@ -1512,8 +1485,8 @@ programmenu.addAction(settingWindow) programmenu.addSeparator() programmenu.addAction(exitProgram) # 绑定事件 -exitProgram.triggered.connect(CleanProgramHistory) -exitProgram.triggered.connect(SettingWindow.ShowWindow) +cleanProgramHistory.triggered.connect(CleanProgramHistory) +settingWindow.triggered.connect(SettingWindow.ShowWindow) exitProgram.triggered.connect(window.close) adbUengineConnect = QtWidgets.QAction(langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][0]) @@ -1600,7 +1573,6 @@ uengineCheckCpu.triggered.connect(UengineCheckCpu) uengineUbuntuInstall.triggered.connect(UengineUbuntuInstall) uengineDeleteUengineCheck.triggered.connect(DelUengineCheck) uengineReinstall.triggered.connect(ReinstallUengine) -uengineUbuntuInstall.triggered.connect(UbuntuInstallUengine) uengineStart = QtWidgets.QAction(langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][2]["Menu"][0]) uengineStop = QtWidgets.QAction(langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][2]["Menu"][1]) @@ -1694,184 +1666,6 @@ widget.setLayout(widgetLayout) window.setCentralWidget(widget) window.setWindowTitle(title) window.show() +window.setWindowIcon(QtGui.QIcon(iconPath)) window.setFixedSize(window.frameSize().width(), window.frameSize().height()) -sys.exit(app.exec_()) - -# 设置窗口 -#style = ttkthemes.ThemedStyle(win) -#style.set_theme("breeze") -window = ttk.Frame(win) -win.title(title) -win.resizable(0, 0) -win.iconphoto(False, tk.PhotoImage(file=iconPath)) - -# get screen width and height -screen_width = win.winfo_screenwidth() -screen_height = win.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) - -win.geometry(""+"+{:.0f}+{:.0f}".format(x, y)) - -# 创建控件 -FrmInstall = ttk.Frame(window) -#FrmUninstall = ttk.Frame(window) -LabApkPath = ttk.Label(window, text=langFile[lang]["Main"]["MainWindow"]["LabApkPath"]) -ComboInstallPath = ttk.Combobox(window, width=50) -BtnFindApk = ttk.Button(FrmInstall, text=langFile[lang]["Main"]["MainWindow"]["BtnFindApk"], command=FindApk) -BtnInstall = ttk.Button(FrmInstall, text=langFile[lang]["Main"]["MainWindow"]["BtnInstall"], command=Button3Install) -BtnShowUengineApp = ttk.Button(window, text=langFile[lang]["Main"]["MainWindow"]["BtnShowUengineApp"], command=Button5Click) -BtnUninstall = ttk.Button(FrmInstall, text=langFile[lang]["Main"]["MainWindow"]["BtnUninstall"], command=ButtonClick8) -Btngeticon = ttk.Button(FrmInstall, text=langFile[lang]["Main"]["MainWindow"]["Btngeticon"], command=SaveIconToOtherPath) -BtnSaveApk = ttk.Button(FrmInstall, text=langFile[lang]["Main"]["MainWindow"]["BtnSaveApk"], command=SaveInstallUengineApp) -BtnApkInformation = ttk.Button(FrmInstall, text=langFile[lang]["Main"]["MainWindow"]["BtnApkInformation"], command=ApkInformation.ShowWindows) -# 设置菜单栏 -menu = tk.Menu(window, background="white") - -programmenu = tk.Menu(menu, tearoff=0, background="white") # 设置“程序”菜单栏 -adb = tk.Menu(menu, tearoff=0, background="white") -uengine = tk.Menu(menu, tearoff=0, background="white") -help = tk.Menu(menu, tearoff=0, background="white") # 设置“帮助”菜单栏 - -adbServer = tk.Menu(adb, tearoff=0, background="white") - -uengineService = tk.Menu(uengine, tearoff=0, background="white") -uengineInternet = tk.Menu(uengine, tearoff=0, background="white") -uengineIcon = tk.Menu(uengine, tearoff=0, background="white") -uengineUseAdb = tk.Menu(uengine, tearoff=0, background="white") -uengineData = tk.Menu(uengine, tearoff=0, background="white") -uengineRoot = tk.Menu(uengine, tearoff=0, background="white") - -menu.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][0]["Name"], menu=programmenu) -menu.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Name"], menu=adb) -menu.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Name"], menu=uengine) -menu.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][3]["Name"], menu=help) - -programmenu.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][0]["Menu"][0], command=CleanProgramHistory) -programmenu.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][0]["Menu"][2], command=SettingWindow.ShowWindow) -programmenu.add_separator() # 设置分界线 -programmenu.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][0]["Menu"][1], command=window.quit) # 设置“退出程序” - -adb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][0], command=UengineConnectAdb) -adb.add_separator() -adb.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][1]["Name"], menu=adbServer) -adb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][2], command=AdbConnectDeviceShow) -adb.add_separator() -adb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][3], command=AdbChangeUengineDisplaySize.ShowWindows) -adb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][4], command=AdbAndroidInstallAppList) -adb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][5], command=AdbCPUAndRAWShowInTer) -adb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][6], command=AdbShellShowInTer) -adb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][7], command=ScrcpyConnectUengine) -adb.add_separator() -adb.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][8]["Name"], menu=uengineUseAdb) - -adbServer.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][1]["Menu"][0], command=AdbStartServer) -adbServer.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][1]["Menu"][1], command=AdbStopServer) -adbServer.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][1]["Menu"][2], command=AdbKillAdbProgress) - -uengine.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][13], command=AllowOrDisallowUpdateAndroidApp) -uengine.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][15], command=SetHttpProxy) -uengine.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][1], command=OpenUengineDebBuilder) -uengine.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][7], command=KeyboardToMouse) -uengine.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][8], command=UengineCheckCpu) -uengine.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][12], command=UengineUbuntuInstall) -uengine.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][2]["Name"], menu=uengineService) -uengine.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][3]["Name"], menu=uengineInternet) -uengine.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][4]["Name"], menu=uengineIcon) -uengine.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][5]["Name"], menu=uengineUseAdb) -uengine.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][6]["Name"], menu=uengineData) -uengine.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][9], command=DelUengineCheck) -uengine.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][10], command=ReinstallUengine) -uengine.add_cascade(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][11]["Name"], menu=uengineRoot) -uengine.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][14], command=UbuntuInstallUengine) - -help.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][3]["Menu"][0], command=OpenProgramURL) # 设置“程序官网”项 -help.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][3]["Menu"][2], command=UengineRunnerBugUpload) # 设置“传bug”项 -help.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][3]["Menu"][4], command=ShowHelp) # 设置“更多帮助”项 -help.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][3]["Menu"][3], command=UpdateWindow.ShowWindow) -help.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][3]["Menu"][1], command=showhelp) # 设置“关于这个程序”项 - -uengineService.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][2]["Menu"][0], command=StartUengine) -uengineService.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][2]["Menu"][1], command=StopUengine) -uengineService.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][2]["Menu"][2], command=UengineRestart) - -uengineInternet.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][3]["Menu"][0], command=UengineBridgeStart) -uengineInternet.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][3]["Menu"][1], command=UengineBridgeStop) -uengineInternet.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][3]["Menu"][2], command=UengineBridgeRestart) -uengineInternet.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][3]["Menu"][3], command=UengineBridgeReload) -uengineInternet.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][3]["Menu"][4], command=UengineBridgeForceReload) - -uengineIcon.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][4]["Menu"][0], command=SendUengineAndroidListForDesktop) -uengineIcon.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][4]["Menu"][1], command=SendUengineAndroidListForLauncher) -uengineIcon.add_separator() -uengineIcon.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][4]["Menu"][2], command=AddNewUengineDesktopLink.ShowWindow) -uengineIcon.add_separator() -uengineIcon.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][4]["Menu"][3], command=CleanAllUengineDesktopLink) - -uengineUseAdb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][8]["Menu"][0], command=UengineConnectAdb) -uengineUseAdb.add_separator() -uengineUseAdb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][8]["Menu"][1], command=UengineUseAdb) -uengineUseAdb.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][1]["Menu"][8]["Menu"][2], command=UengineDoNotUseAdb) - -uengineData.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][6]["Menu"][0], command=OpenUengineRootData) -uengineData.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][6]["Menu"][1], command=OpenUengineUserData) -uengineData.add_separator() -uengineData.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][6]["Menu"][2], command=BackUengineClean) - -uengineRoot.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][11]["Menu"][0], command=InstallRootUengineImage) -uengineRoot.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][11]["Menu"][1], command=BuildRootUengineImage) -uengineRoot.add_separator() -uengineRoot.add_command(label=langFile[lang]["Main"]["MainWindow"]["Menu"][2]["Menu"][11]["Menu"][2], command=ReinstallUengineImage) - -menu.configure(activebackground="dodgerblue") -help.configure(activebackground="dodgerblue") -adb.configure(activebackground="dodgerblue") -uengine.configure(activebackground="dodgerblue") -programmenu.configure(activebackground="dodgerblue") -uengineService.configure(activebackground="dodgerblue") -uengineInternet.configure(activebackground="dodgerblue") -uengineIcon.configure(activebackground="dodgerblue") -uengineUseAdb.configure(activebackground="dodgerblue") -uengineData.configure(activebackground="dodgerblue") - -# 设置控件 -ComboInstallPath['value'] = findApkHistory -try: - if sys.argv[1] == "-i": - ComboInstallPath.set(sys.argv[2]) - print("Install Path: " + sys.argv[2]) - elif sys.argv[1] == "-u": - #ComboUninstallPath.set(sys.argv[2]) - ComboInstallPath.set(sys.argv[2]) - print("Unstall Path: " + sys.argv[2]) - else: - print("Command Format Error") -except: - print("Not Command Or Command Format Error") -# 显示控件 -win.config(menu=menu) # 显示菜单栏 - - - -LabApkPath.grid(row=0, column=0,sticky= tk.W,padx=3) -ComboInstallPath.grid(row=1, column=0,padx=3) - - -FrmInstall.grid(row=0, column=1,padx=3, rowspan=3) -BtnFindApk.grid(row=0, column=0) -BtnInstall.grid(row=0, column=1) - -BtnUninstall.grid(row=1, column=0) - -BtnShowUengineApp.grid(row=2, column=0,sticky= tk.W,padx=3,pady=2) - -BtnApkInformation.grid(row=2, column=1,sticky= tk.W,padx=3,pady=2) -Btngeticon.grid(row=1, column=1,sticky= tk.W,padx=3,pady=2) -BtnSaveApk.grid(row=2, column=0,sticky= tk.W,padx=3,pady=2) - -window.pack() - -win.mainloop() +sys.exit(app.exec_()) \ No newline at end of file diff --git a/uengine-keyboard b/uengine-keyboard index c696647..d6d9d3f 100755 --- a/uengine-keyboard +++ b/uengine-keyboard @@ -1,9 +1,9 @@ #!/usr/bin/env python3 -######################################### -# 版本:1.6.1 -# 更新时间:2022年10月06日 +############################################################### +# 版本:1.8.0 +# 更新时间:2022年07月26日 # Need: unix, python3-tk, python3-pip, pymouse, keyboard -######################################### +############################################################### import os import sys import time @@ -30,7 +30,6 @@ def Inputt(key): Setting(key) else: Mouse(key) - #Mouse(key) def Open(): path = filedialog.askopenfilename(title="打开", filetypes=[["json 文件", "*.json"], ["全部文件", ["*.*"]]]) @@ -56,13 +55,12 @@ def Mouse(key): if keybo.__contains__(key.name): print(keybo[key.name]["MousePlace"]) pyautogui.FAILSAFE = False - #os.system(programPath + "/mouse.py {} {}".format(keybo[key.name]["MousePlace"][0], keybo[key.name]["MousePlace"][1])) try: + print((keybo[key.name]["MousePlace"][0], keybo[key.name]["MousePlace"][1])) pyautogui.click(keybo[key.name]["MousePlace"][0], keybo[key.name]["MousePlace"][1]) + except: traceback.print_exc() - #pyautogui.click(1500, 800) - #m.click(keybo[key.name]["MousePlace"][0],keybo[key.name]["MousePlace"][1]) def Setting(key): if key.event_type == 'up': @@ -105,11 +103,8 @@ def ShowTips(): def Closing(): global close close = True - window.destroy() - #key.close() - #stop_thread(keys) - keyboard.unhook(Inputt) - sys.exit(0) + # 偷懒了,直接强制关闭进程 + os.system(f"kill {os.getpid()}") def Key(): @@ -145,6 +140,20 @@ def Clean(): def About(): threading.Thread(target=os.system, args=["{}/uengine-runner-about".format(programPath)]).start() +lock = False +def ThreadCheck(): + global lock + lock = True + pyautogui.position() + lock = False + +def RestartProgramTimer(): + threading.Thread(target=ThreadCheck).start() + time.sleep(0.1) + if lock: + ReStartProgram() + RestartProgramTimer() + ################### # ################### @@ -226,16 +235,9 @@ settingMouseToKeyboard.grid(row=0, column=0) settingButton.grid(row=0, column=1) win.pack(fill="both", expand="yes") -#threaded.lock.allocate_lock() keys = threading.Thread(target=Key) keys.start() threading.Thread(target=ShowTips).start() pyautogui.FAILSAFE = False -'''def B(key): - if key.event_type == "up": - print(pyautogui.position()) - print(key.name) - pyautogui.click(1500, 800) -keyboard.hook(B) -keyboard.wait()''' +threading.Thread(target=RestartProgramTimer).start() window.mainloop() \ No newline at end of file