2021-05-29 22:54:59 +08:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# 使用系统默认的 python3 运行
|
|
|
|
|
###########################################################################################
|
2021-08-08 22:02:43 +08:00
|
|
|
|
# 作者:gfdgd xi<3025613752@qq.com>
|
2021-08-15 21:46:48 +08:00
|
|
|
|
# 版本:1.3.2
|
|
|
|
|
# 更新时间:2021年8月15日
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 感谢:anbox、deepin 和 UOS
|
2021-05-29 22:54:59 +08:00
|
|
|
|
# 基于 Python3 的 tkinter 构建
|
2021-08-08 22:02:43 +08:00
|
|
|
|
# 更新:actionchen<917981399@qq.com>
|
2021-05-29 22:54:59 +08:00
|
|
|
|
###########################################################################################
|
|
|
|
|
#################
|
|
|
|
|
# 引入所需的库
|
|
|
|
|
#################
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import time
|
|
|
|
|
import json
|
|
|
|
|
import shutil
|
2021-06-06 11:54:38 +08:00
|
|
|
|
import zipfile
|
2021-05-29 22:54:59 +08:00
|
|
|
|
import traceback
|
|
|
|
|
import threading
|
2021-08-08 22:02:43 +08:00
|
|
|
|
import ttkthemes
|
2021-05-29 22:54:59 +08:00
|
|
|
|
import webbrowser
|
|
|
|
|
import subprocess
|
|
|
|
|
import tkinter as tk
|
|
|
|
|
import tkinter.ttk as ttk
|
|
|
|
|
import tkinter.messagebox as messagebox
|
|
|
|
|
import tkinter.filedialog as filedialog
|
2021-08-08 17:14:48 +08:00
|
|
|
|
from getxmlimg import getsavexml
|
2021-08-08 22:02:43 +08:00
|
|
|
|
from tkinter.constants import TOP
|
2021-05-29 22:54:59 +08:00
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 卸载程序
|
|
|
|
|
def UninstallProgram(package: "apk 包名")->"卸载程序":
|
|
|
|
|
try:
|
|
|
|
|
global fineUninstallApkHistory
|
|
|
|
|
Return = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg='{}'".format(package))
|
|
|
|
|
if os.path.exists("{}/.local/share/applications/{}.desktop".format(get_home(), package)):
|
|
|
|
|
os.remove("{}/.local/share/applications/{}.desktop".format(get_home(), package))
|
|
|
|
|
if os.path.exists("{}/{}.desktop".format(get_desktop_path(), package)):
|
|
|
|
|
os.remove("{}/{}.desktop".format(get_desktop_path(), package))
|
2021-08-08 17:14:48 +08:00
|
|
|
|
fineUninstallApkHistory.append(ComboUninstallPath.get())
|
|
|
|
|
ComboUninstallPath['value'] = fineUninstallApkHistory
|
2021-07-11 14:45:11 +08:00
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", str(json.dumps(ListToDictionary(fineUninstallApkHistory)))) # 将历史记录的数组转换为字典并写入
|
|
|
|
|
return Return
|
|
|
|
|
except:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
messagebox.showerror(title="错误", message=traceback.format_exc())
|
2021-05-29 22:54:59 +08:00
|
|
|
|
|
2021-08-08 17:14:48 +08:00
|
|
|
|
def BtnFindUninstallApkClk():
|
2021-07-02 20:05:01 +08:00
|
|
|
|
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApk.json"))["path"])
|
|
|
|
|
if path != "" and path != "()":
|
|
|
|
|
try:
|
2021-08-08 17:14:48 +08:00
|
|
|
|
ComboUninstallPath.set(path)
|
2021-07-02 20:05:01 +08:00
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2021-05-29 22:54:59 +08:00
|
|
|
|
|
2021-07-02 20:05:01 +08:00
|
|
|
|
def ButtonClick8():
|
2021-08-08 17:14:48 +08:00
|
|
|
|
if ComboUninstallPath.get() is "":
|
2021-07-02 20:38:34 +08:00
|
|
|
|
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续卸载 APK")
|
|
|
|
|
return
|
2021-07-02 20:05:01 +08:00
|
|
|
|
DisabledAndEnbled(True)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
if os.path.exists(ComboUninstallPath.get()):
|
|
|
|
|
path = GetApkPackageName(ComboUninstallPath.get())
|
2021-07-02 20:05:01 +08:00
|
|
|
|
else:
|
2021-08-08 17:14:48 +08:00
|
|
|
|
path = ComboUninstallPath.get()
|
2021-07-02 20:05:01 +08:00
|
|
|
|
UninstallProgram(path)
|
|
|
|
|
messagebox.showinfo(message="操作执行完毕!", title="提示")
|
2021-05-29 22:54:59 +08:00
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 浏览窗口
|
2021-08-08 17:14:48 +08:00
|
|
|
|
# temp strs
|
|
|
|
|
temppath=""
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def FindApk()->"浏览窗口":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApk.json"))["path"])
|
2021-08-08 17:14:48 +08:00
|
|
|
|
global temppath
|
|
|
|
|
temppath = path
|
|
|
|
|
print("apk path is find:" + path)
|
2021-05-29 22:54:59 +08:00
|
|
|
|
if path != "" and path != "()":
|
|
|
|
|
try:
|
2021-08-08 17:14:48 +08:00
|
|
|
|
ComboInstallPath.set(path)
|
2021-05-29 22:54:59 +08:00
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def Button3Install():
|
2021-08-08 17:14:48 +08:00
|
|
|
|
if ComboInstallPath.get() is "":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续安装 APK")
|
|
|
|
|
return
|
|
|
|
|
DisabledAndEnbled(True)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
threading.Thread(target=InstallApk, args=(ComboInstallPath.get(),)).start()
|
2021-05-29 22:54:59 +08:00
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 安装应用
|
|
|
|
|
def InstallApk(path: "apk 路径", quit: "是否静默安装" = False):
|
|
|
|
|
try:
|
2021-08-15 21:46:48 +08:00
|
|
|
|
if not os.path.exists("{}/.local/share/applications/uengine/".format(get_home())):
|
|
|
|
|
print("Mkdir")
|
|
|
|
|
os.mkdir("{}/.local/share/applications/uengine/".format(get_home()))
|
2021-08-08 17:14:48 +08:00
|
|
|
|
print("start install apk")
|
2021-07-11 14:45:11 +08:00
|
|
|
|
global findApkHistory
|
|
|
|
|
commandReturn = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(path))
|
2021-08-15 21:46:48 +08:00
|
|
|
|
print(commandReturn)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
print("start install apk12")
|
|
|
|
|
iconSavePath = "{}/.local/share/icons/hicolor/256x256/apps/{}.png".format(get_home(), GetApkPackageName(path))
|
|
|
|
|
tempstr1 = iconSavePath
|
|
|
|
|
print("start install apk1")
|
|
|
|
|
iconSaveDir = os.path.dirname(iconSavePath)
|
|
|
|
|
if not os.path.exists(iconSaveDir):
|
|
|
|
|
os.makedirs(iconSaveDir,exist_ok=True)
|
2021-07-11 14:45:11 +08:00
|
|
|
|
SaveApkIcon(path, iconSavePath)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
print("start install apk2")
|
2021-07-11 14:45:11 +08:00
|
|
|
|
BuildUengineDesktop(GetApkPackageName(path), GetApkActivityName(path), GetApkChineseLabel(path), iconSavePath,
|
|
|
|
|
"{}/{}.desktop".format(get_desktop_path(), GetApkPackageName(path)))
|
2021-08-08 17:14:48 +08:00
|
|
|
|
print("start install apk3")
|
2021-07-11 14:45:11 +08:00
|
|
|
|
BuildUengineDesktop(GetApkPackageName(path), GetApkActivityName(path), GetApkChineseLabel(path), iconSavePath,
|
2021-08-15 21:46:48 +08:00
|
|
|
|
"{}/.local/share/applications/uengine/{}.desktop".format(get_home(), GetApkPackageName(path)))
|
2021-08-08 17:14:48 +08:00
|
|
|
|
print("\nprint install complete")
|
2021-07-11 14:45:11 +08:00
|
|
|
|
if quit:
|
|
|
|
|
print(commandReturn)
|
|
|
|
|
return
|
|
|
|
|
messagebox.showinfo(title="提示", message="操作完成!")
|
2021-08-08 17:14:48 +08:00
|
|
|
|
findApkHistory.append(ComboInstallPath.get())
|
|
|
|
|
ComboInstallPath['value'] = findApkHistory
|
2021-07-11 14:45:11 +08:00
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
|
|
|
|
except:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
messagebox.showerror(title="错误", message=traceback.format_exc())
|
2021-05-29 22:54:59 +08:00
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 禁用或启动所有控件
|
|
|
|
|
def DisabledAndEnbled(choose: "启动或者禁用")->"禁用或启动所有控件":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
userChoose = {True: tk.DISABLED, False: tk.NORMAL}
|
|
|
|
|
a = userChoose[choose]
|
2021-08-08 17:14:48 +08:00
|
|
|
|
ComboInstallPath.configure(state=a)
|
|
|
|
|
ComboUninstallPath.configure(state=a)
|
|
|
|
|
BtnFindApk.configure(state=a)
|
|
|
|
|
BtnInstall.configure(state=a)
|
|
|
|
|
BtnShowUengineApp.configure(state=a)
|
|
|
|
|
BtnUninstallApkBrowser.configure(state=a)
|
|
|
|
|
BtnUninstall.configure(state=a)
|
2021-08-08 22:02:43 +08:00
|
|
|
|
Btngeticon.configure(state=a)
|
2021-05-29 22:54:59 +08:00
|
|
|
|
|
|
|
|
|
# 需引入 subprocess
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 运行系统命令并获取返回值
|
|
|
|
|
def GetCommandReturn(cmd: "命令")->"运行系统命令并获取返回值":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
# cmd 是要获取输出的命令
|
|
|
|
|
return subprocess.getoutput(cmd)
|
|
|
|
|
|
|
|
|
|
def Button5Click():
|
|
|
|
|
threading.Thread(target=OpenUengineProgramList).start()
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 打开“uengine 所有程序列表”
|
|
|
|
|
def OpenUengineProgramList()->"打开“uengine 所有程序列表”":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
os.system("/usr/bin/uengine-launch.sh --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity")
|
|
|
|
|
|
|
|
|
|
# 显示“关于这个程序”窗口
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def about_this_program()->"显示“关于这个程序”窗口":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
global about
|
|
|
|
|
global title
|
|
|
|
|
global iconPath
|
2021-05-30 13:04:46 +08:00
|
|
|
|
mess = tk.Toplevel()
|
|
|
|
|
message = ttk.Frame(mess)
|
|
|
|
|
mess.resizable(0, 0)
|
|
|
|
|
mess.title("关于 {}".format(title))
|
2021-08-08 17:14:48 +08:00
|
|
|
|
#mess.iconphoto(False, tk.PhotoImage(file=iconPath))
|
2021-05-29 22:54:59 +08:00
|
|
|
|
img = ImageTk.PhotoImage(Image.open(iconPath))
|
2021-08-08 17:14:48 +08:00
|
|
|
|
LabApkPath = ttk.Label(message, image=img)
|
2021-05-29 22:54:59 +08:00
|
|
|
|
label2 = ttk.Label(message, text=about)
|
2021-05-30 13:04:46 +08:00
|
|
|
|
button1 = ttk.Button(message, text="确定", command=mess.withdraw)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
LabApkPath.pack()
|
2021-05-29 22:54:59 +08:00
|
|
|
|
label2.pack()
|
|
|
|
|
button1.pack(side="bottom")
|
2021-05-30 13:04:46 +08:00
|
|
|
|
message.pack()
|
|
|
|
|
mess.mainloop()
|
2021-05-29 22:54:59 +08:00
|
|
|
|
|
|
|
|
|
# 显示“提示”窗口
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def helps()->"显示“提示”窗口":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
global tips
|
|
|
|
|
messagebox.showinfo(title="提示", message=tips)
|
|
|
|
|
|
|
|
|
|
# 显示更新内容窗口
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def UpdateThings()->"显示更新内容窗口":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
messagebox.showinfo(title="更新内容", message=updateThings)
|
|
|
|
|
|
|
|
|
|
# 打开程序官网
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def OpenProgramURL()->"打开程序官网":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
webbrowser.open_new_tab(programUrl)
|
|
|
|
|
|
|
|
|
|
# 重启本应用程序
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def ReStartProgram()->"重启本应用程序":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
python = sys.executable
|
|
|
|
|
os.execl(python, python, * sys.argv)
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 清理历史记录
|
|
|
|
|
def CleanProgramHistory()->"清理历史记录":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
try:
|
|
|
|
|
if messagebox.askokcancel(title="警告", message="删除后将无法恢复,你确定吗?\n删除后软件将会自动重启。"):
|
|
|
|
|
shutil.rmtree(get_home() + "/.config/uengine-runner")
|
|
|
|
|
ReStartProgram()
|
|
|
|
|
except:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
messagebox.showerror(title="错误", message=traceback.format_exc())
|
|
|
|
|
|
|
|
|
|
# 获取用户主目录
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def get_home()->"获取用户主目录":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
return os.path.expanduser('~')
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 发送“启动 uengine 所有程序”的 .desktop 文件到桌面
|
|
|
|
|
def SendUengineAndroidListForDesktop()->"发送“启动 uengine 所有程序”的 .desktop 文件到桌面":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
global desktop
|
|
|
|
|
global desktopName
|
|
|
|
|
DisabledAndEnbled(True)
|
|
|
|
|
try:
|
|
|
|
|
if os.path.exists("{}/{}".format(get_desktop_path(), desktopName)):
|
|
|
|
|
if not messagebox.askokcancel(title="提示", message="桌面已经存在快捷方式,你确定要覆盖吗?"):
|
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
return
|
|
|
|
|
shutil.copy(desktop, get_desktop_path())
|
|
|
|
|
messagebox.showinfo(title="提示", message="发送成功!")
|
|
|
|
|
except:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
messagebox.showerror(title="错误", message=traceback.format_exc())
|
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
|
|
|
|
|
# 获取用户桌面目录
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def get_desktop_path()->"获取用户桌面目录":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
for line in open(get_home() + "/.config/user-dirs.dirs"): # 以行来读取配置文件
|
|
|
|
|
desktop_index = line.find("XDG_DESKTOP_DIR=\"") # 寻找是否有对应项,有返回 0,没有返回 -1
|
|
|
|
|
if desktop_index != -1: # 如果有对应项
|
|
|
|
|
break # 结束循环
|
|
|
|
|
if desktop_index == -1: # 如果是提前结束,值一定≠-1,如果是没有提前结束,值一定=-1
|
|
|
|
|
return -1
|
|
|
|
|
else:
|
|
|
|
|
get = line[17:-2] # 截取桌面目录路径
|
|
|
|
|
get_index = get.find("$HOME") # 寻找是否有对应的项,需要替换内容
|
|
|
|
|
if get != -1: # 如果有
|
|
|
|
|
get = get.replace("$HOME", get_home()) # 则把其替换为用户目录(~)
|
|
|
|
|
return get # 返回目录
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 发送“启动 uengine 所有程序”的 .desktop 文件到启动器
|
|
|
|
|
def SendUengineAndroidListForLauncher()->"发送“启动 uengine 所有程序”的 .desktop 文件到启动器":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
DisabledAndEnbled(True)
|
|
|
|
|
try:
|
|
|
|
|
if os.path.exists("{}/.local/share/applications/{}".format(get_home(), desktopName)):
|
|
|
|
|
if not messagebox.askokcancel(title="提示", message="启动器已经存在快捷方式,你确定要覆盖吗?"):
|
|
|
|
|
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="发送成功!")
|
|
|
|
|
except:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
messagebox.showerror(title="错误", message=traceback.format_exc())
|
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
|
|
|
|
|
# 数组转字典
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def ListToDictionary(list: "需要转换的数组")->"数组转字典":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
dictionary = {}
|
|
|
|
|
for i in range(len(list)):
|
|
|
|
|
dictionary[i] = list[i]
|
|
|
|
|
return dictionary
|
|
|
|
|
|
|
|
|
|
# 读取文本文档
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def readtxt(path: "路径")->"读取文本文档":
|
2021-05-29 22:54:59 +08:00
|
|
|
|
f = open(path, "r") # 设置文件对象
|
|
|
|
|
str = f.read() # 获取内容
|
|
|
|
|
f.close() # 关闭文本对象
|
|
|
|
|
return str # 返回结果
|
|
|
|
|
|
|
|
|
|
# 写入文本文档
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def write_txt(path: "路径", things: "内容")->"写入文本文档":
|
2021-08-08 17:14:48 +08:00
|
|
|
|
TxtDir = os.path.dirname(path)
|
|
|
|
|
print(TxtDir)
|
|
|
|
|
if not os.path.exists(TxtDir):
|
|
|
|
|
os.makedirs(TxtDir,exist_ok=True)
|
2021-05-29 22:54:59 +08:00
|
|
|
|
file = open(path, 'w', encoding='UTF-8') # 设置文件对象
|
|
|
|
|
file.write(things) # 写入文本
|
|
|
|
|
file.close() # 关闭文本对象
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 获取 aapt 的所有信息
|
|
|
|
|
def GetApkInformation(apkFilePath: "apk 所在路径")->"获取 aapt 的所有信息":
|
2021-06-06 11:54:38 +08:00
|
|
|
|
return GetCommandReturn("aapt dump badging '{}'".format(apkFilePath))
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 获取 apk Activity
|
|
|
|
|
def GetApkActivityName(apkFilePath: "apk 所在路径")->"获取 apk Activity":
|
2021-06-06 11:54:38 +08:00
|
|
|
|
info = GetApkInformation(apkFilePath)
|
|
|
|
|
for line in info.split('\n'):
|
|
|
|
|
if "launchable-activity" in line:
|
|
|
|
|
line = line[0: line.index("label='")]
|
|
|
|
|
line = line.replace("launchable-activity: ", "")
|
|
|
|
|
line = line.replace("'", "")
|
|
|
|
|
line = line.replace(" ", "")
|
|
|
|
|
line = line.replace("name=", "")
|
|
|
|
|
line = line.replace("label=", "")
|
|
|
|
|
line = line.replace("icon=", "")
|
|
|
|
|
return line
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 获取 apk 包名
|
|
|
|
|
def GetApkPackageName(apkFilePath: "apk 所在路径")->"获取 apk 包名":
|
2021-06-06 11:54:38 +08:00
|
|
|
|
info = GetApkInformation(apkFilePath)
|
|
|
|
|
for line in info.split('\n'):
|
|
|
|
|
if "package:" in line:
|
|
|
|
|
line = line[0: line.index("versionCode='")]
|
|
|
|
|
line = line.replace("package:", "")
|
|
|
|
|
line = line.replace("name=", "")
|
|
|
|
|
line = line.replace("'", "")
|
|
|
|
|
line = line.replace(" ", "")
|
|
|
|
|
return line
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 生成 uengine 启动文件到桌面
|
|
|
|
|
def BuildUengineDesktop(packageName: "软件包名", activityName: "activity", showName: "显示名称", iconPath: "程序图标所在目录", savePath:".desktop 文件保存路径")->"生成 uengine 启动文件到桌面":
|
|
|
|
|
things = '''[Desktop Entry]
|
2021-06-06 11:54:38 +08:00
|
|
|
|
Categories=app;
|
|
|
|
|
Encoding=UTF-8
|
|
|
|
|
Exec=/usr/bin/uengine-launch.sh --action=android.intent.action.MAIN --package={} --component={}
|
|
|
|
|
GenericName={}
|
|
|
|
|
Icon={}
|
|
|
|
|
MimeType=
|
|
|
|
|
Name={}
|
|
|
|
|
StartupWMClass={}
|
|
|
|
|
Terminal=false
|
|
|
|
|
Type=Application
|
|
|
|
|
'''.format(packageName, activityName, showName, iconPath, showName, showName)
|
|
|
|
|
write_txt(savePath, things)
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 获取软件的中文名称
|
|
|
|
|
def GetApkChineseLabel(apkFilePath)->"获取软件的中文名称":
|
2021-06-06 11:54:38 +08:00
|
|
|
|
info = GetApkInformation(apkFilePath)
|
|
|
|
|
for line in info.split('\n'):
|
|
|
|
|
if "application-label:" in line:
|
|
|
|
|
line = line.replace("application-label:", "")
|
|
|
|
|
line = line.replace("'", "")
|
|
|
|
|
return line
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 获取图标在包内的路径
|
2021-08-08 17:14:48 +08:00
|
|
|
|
#def GetApkIconInApk(apkFilePath)->"获取图标在包内的路径":
|
|
|
|
|
|
|
|
|
|
#合并两个函数到一起
|
2021-08-08 22:02:43 +08:00
|
|
|
|
def SaveApkIcon(apkFilePath, iconSavePath)->"获取 apk 文件的图标":
|
2021-08-12 15:12:13 +08:00
|
|
|
|
try:
|
|
|
|
|
info = GetApkInformation(apkFilePath)
|
|
|
|
|
for line in info.split('\n'):
|
|
|
|
|
if "application:" in line:
|
|
|
|
|
xmlpath = line.split(":")[-1].split()[-1].split("=")[-1].replace("'","")
|
|
|
|
|
if xmlpath.endswith('.xml'):
|
|
|
|
|
xmlsave = getsavexml()
|
|
|
|
|
print(xmlpath)
|
|
|
|
|
xmlsave.savexml(apkFilePath,xmlpath,iconSavePath)
|
|
|
|
|
else:
|
|
|
|
|
zip = zipfile.ZipFile(apkFilePath)
|
|
|
|
|
iconData = zip.read(xmlpath)
|
|
|
|
|
with open(iconSavePath, 'w+b') as saveIconFile:
|
|
|
|
|
saveIconFile.write(iconData)
|
|
|
|
|
except:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
print("Error, show defult icon")
|
|
|
|
|
shutil.copy(programPath + "/defult.png", iconSavePath)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
|
|
|
|
def saveicon():
|
|
|
|
|
global temppath
|
|
|
|
|
global tempstr1
|
|
|
|
|
iconSavePath = "{}/.local/share/icons/hicolor/256x256/apps/{}.png".format(get_home(), GetApkPackageName(temppath))
|
|
|
|
|
print(iconSavePath+"iconpaths")
|
|
|
|
|
SaveApkIcon(temppath, iconSavePath)
|
|
|
|
|
|
2021-08-08 22:02:43 +08:00
|
|
|
|
def SaveIconToOtherPath():
|
|
|
|
|
apkPath = ComboInstallPath.get()
|
|
|
|
|
if apkPath == "":
|
|
|
|
|
messagebox.showerror(title="错误", message="你没有选择 apk 文件")
|
|
|
|
|
return
|
|
|
|
|
path = filedialog.asksaveasfilename(title="保存图标", filetypes=[("PNG 图片", "*.png"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/SaveApkIcon.json"))["path"])
|
|
|
|
|
if not path == "":
|
|
|
|
|
try:
|
|
|
|
|
SaveApkIcon(apkPath, path)
|
|
|
|
|
except:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
messagebox.showerror(title="错误", message="本程序不支持保存该 apk 的图标")
|
|
|
|
|
return
|
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/SaveApkIcon.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
|
|
|
|
findApkHistory.append(ComboInstallPath.get())
|
|
|
|
|
ComboInstallPath['value'] = findApkHistory
|
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
|
|
|
|
messagebox.showinfo(title="提示", message="保存成功!")
|
|
|
|
|
|
2021-08-08 17:14:48 +08:00
|
|
|
|
## 获取 apk 文件的图标(部分程序不支持)
|
|
|
|
|
# def SaveApkIcon(apkFilePath, iconSavePath)->"获取 apk 文件的图标(部分程序不支持)":
|
|
|
|
|
# zip = zipfile.ZipFile(apkFilePath)
|
|
|
|
|
# iconData = zip.read(GetApkIconInApk(apkFilePath))
|
|
|
|
|
# with open(iconSavePath, 'w+b') as saveIconFile:
|
|
|
|
|
# saveIconFile.write(iconData)
|
2021-06-06 11:54:38 +08:00
|
|
|
|
|
2021-08-15 21:46:48 +08:00
|
|
|
|
def BackUengineClean()->"清空 uengine 数据":
|
|
|
|
|
print("Choose")
|
|
|
|
|
if messagebox.askokcancel(title="警告", message="清空后数据将会完全丢失,确定要继续吗?"):
|
|
|
|
|
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")
|
|
|
|
|
return
|
|
|
|
|
print("Choose False")
|
|
|
|
|
|
|
|
|
|
def UengineBridgeStart():
|
|
|
|
|
DisabledAndEnbled(True)
|
|
|
|
|
os.system("pkexec uengine-bridge.sh start")
|
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
|
|
|
|
|
def UengineBridgeStop():
|
|
|
|
|
DisabledAndEnbled(True)
|
|
|
|
|
os.system("pkexec uengine-bridge.sh stop")
|
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
|
|
|
|
|
def UengineBridgeRestart():
|
|
|
|
|
DisabledAndEnbled(True)
|
|
|
|
|
os.system("pkexec uengine-bridge.sh restart")
|
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
|
|
|
|
|
def UengineBridgeReload():
|
|
|
|
|
DisabledAndEnbled(True)
|
|
|
|
|
os.system("pkexec uengine-bridge.sh reload")
|
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
|
|
|
|
|
def UengineBridgeForceReload():
|
|
|
|
|
DisabledAndEnbled(True)
|
|
|
|
|
os.system("pkexec uengine-bridge.sh force-reload")
|
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
|
|
|
|
|
class InstallWindow():
|
|
|
|
|
def ShowWindows(command):
|
|
|
|
|
global message
|
|
|
|
|
global text
|
|
|
|
|
global installTipsText
|
|
|
|
|
global progressbar
|
|
|
|
|
message = tk.Toplevel()
|
|
|
|
|
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()
|
|
|
|
|
result = subprocess.getoutput(command)
|
|
|
|
|
InstallWindow.AddText(result)
|
|
|
|
|
messagebox.showinfo(title="提示", message="操作完毕!")
|
|
|
|
|
installTipsText.set("操作完毕!")
|
|
|
|
|
message.title("操作完毕!")
|
|
|
|
|
progressbar.stop()
|
|
|
|
|
progressbar["value"] = 100
|
|
|
|
|
# 特意添加!
|
|
|
|
|
DisabledAndEnbled(False)
|
|
|
|
|
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)
|
|
|
|
|
|
2021-06-06 11:54:38 +08:00
|
|
|
|
|
|
|
|
|
# 获取用户桌面目录
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def get_desktop_path()->"获取用户桌面目录":
|
2021-06-06 11:54:38 +08:00
|
|
|
|
for line in open(get_home() + "/.config/user-dirs.dirs"): # 以行来读取配置文件
|
|
|
|
|
desktop_index = line.find("XDG_DESKTOP_DIR=\"") # 寻找是否有对应项,有返回 0,没有返回 -1
|
|
|
|
|
if desktop_index != -1: # 如果有对应项
|
|
|
|
|
break # 结束循环
|
|
|
|
|
if desktop_index == -1: # 如果是提前结束,值一定≠-1,如果是没有提前结束,值一定=-1
|
|
|
|
|
return -1
|
|
|
|
|
else:
|
|
|
|
|
get = line[17:-2] # 截取桌面目录路径
|
|
|
|
|
get_index = get.find("$HOME") # 寻找是否有对应的项,需要替换内容
|
|
|
|
|
if get != -1: # 如果有
|
|
|
|
|
get = get.replace("$HOME", get_home()) # 则把其替换为用户目录(~)
|
|
|
|
|
return get # 返回目录
|
|
|
|
|
|
|
|
|
|
# 获取用户主目录
|
2021-07-11 14:45:11 +08:00
|
|
|
|
def get_home()->"获取用户主目录":
|
2021-06-06 11:54:38 +08:00
|
|
|
|
return os.path.expanduser('~')
|
2021-07-11 14:45:11 +08:00
|
|
|
|
|
2021-08-16 07:22:18 +08:00
|
|
|
|
def StartUengine():
|
|
|
|
|
os.system("systemctl enable uengine-container uengine-session && systemctl start uengine-container uengine-session")
|
|
|
|
|
|
|
|
|
|
def StopUengine():
|
|
|
|
|
os.system("systemctl disable uengine-container uengine-session")
|
|
|
|
|
|
2021-05-29 22:54:59 +08:00
|
|
|
|
###########################
|
|
|
|
|
# 程序信息
|
|
|
|
|
###########################
|
|
|
|
|
programUrl = "https://gitee.com/gfdgd-xi/uengine-runner"
|
2021-08-15 21:46:48 +08:00
|
|
|
|
version = "1.3.2"
|
2021-07-11 14:45:11 +08:00
|
|
|
|
goodRunSystem = "Linux(deepin/UOS)"
|
|
|
|
|
aaptVersion = GetCommandReturn("aapt version")
|
2021-08-08 17:14:48 +08:00
|
|
|
|
about = ''' 一个基于 Python3 的 tkinter 制作的 uengine APK 安装器
|
|
|
|
|
|
|
|
|
|
版本 :{}
|
|
|
|
|
|
|
|
|
|
适用平台 :{}
|
|
|
|
|
|
|
|
|
|
tkinter版本:{}
|
|
|
|
|
|
|
|
|
|
aapt 版本 :{}
|
|
|
|
|
|
|
|
|
|
程序官网 :{}
|
|
|
|
|
|
2021-08-08 22:02:43 +08:00
|
|
|
|
©2021-{}'''.format(version, goodRunSystem, tk.TkVersion, aaptVersion,programUrl, time.strftime("%Y"))
|
2021-08-08 17:14:48 +08:00
|
|
|
|
tips = ''' 新版本Deepin/UOS发布后,可以在应用商店安装部分官方已适配的安卓应用,对爱好者来说,不能自己安装APK软件包始终差点意思,本程序可以为Deepin/UOS上的Uengine安卓运行环境安装自定义APK软件包,并能发送安装的APK包启动菜单到桌面或系统菜单。
|
|
|
|
|
|
|
|
|
|
安装APK:
|
|
|
|
|
点浏览按钮,选中需要安装的APK,然后点安装按钮
|
|
|
|
|
|
|
|
|
|
卸载APK:
|
|
|
|
|
在卸载APK下面的输入框内输入需要卸载的APK包名,点卸载按钮,如果无法获取包名,可以通过浏览APK文件程序自动获取包名进行卸载。
|
|
|
|
|
|
2021-08-08 22:02:43 +08:00
|
|
|
|
保存APK图标:
|
|
|
|
|
在安装APK下面的输入框浏览或输入APK的路径,然后点击“保存图标”按钮,选择保存位置即可
|
|
|
|
|
|
2021-08-15 21:46:48 +08:00
|
|
|
|
重置(删除)uengine 数据:
|
|
|
|
|
点击菜单栏的“uengine”的“清空uengine数据”,输入密码重启即可
|
|
|
|
|
注意:如果任何安卓一遍打不开,多打开几遍应该就可以重新加载uengine配置了
|
|
|
|
|
|
2021-08-08 17:14:48 +08:00
|
|
|
|
打开Uengine应用列表:
|
|
|
|
|
打开系统已安装的应用列表(安卓界面)
|
|
|
|
|
|
|
|
|
|
提示:
|
2021-07-02 20:05:01 +08:00
|
|
|
|
1、需要你有使用 root 权限的能力;
|
2021-07-11 14:45:11 +08:00
|
|
|
|
2、需要安装 uengine 才能使用;
|
2021-08-08 22:02:43 +08:00
|
|
|
|
3、提取 apk 图标的 apk 路径以“安装 apk”那栏为准;
|
2021-08-15 21:46:48 +08:00
|
|
|
|
4、如果想要连接其他手机,请使用 1.2.0 以前的版本,可以使用 adb 连接。
|
2021-08-08 17:14:48 +08:00
|
|
|
|
'''
|
2021-08-15 21:46:48 +08:00
|
|
|
|
updateThingsString = '''V.1.3.2:
|
|
|
|
|
※1、支持uengine数据重置;
|
|
|
|
|
※2、支持修改uengine网络桥接的启动状态;
|
|
|
|
|
※3、支持右键安装/卸载;
|
2021-08-16 07:22:18 +08:00
|
|
|
|
※4、支持启用或禁用uengine;
|
2021-08-15 21:46:48 +08:00
|
|
|
|
|
|
|
|
|
V1.3.1:
|
2021-08-12 15:12:13 +08:00
|
|
|
|
※1、修复打包问题,防止部分用户安装出错的问题;
|
|
|
|
|
※2、修复了程序无法提取图标时可以提取默认图标使用;
|
|
|
|
|
|
|
|
|
|
V1.3.0:
|
2021-08-08 22:02:43 +08:00
|
|
|
|
※1、修改了界面布局;
|
|
|
|
|
※2、修复大多数新安装普通用户的路图标及启动菜单文件路径不存在导致安装APK报错的bugs;
|
|
|
|
|
3、删除少量冗余代码,调整代码顺序;
|
2021-08-15 21:46:48 +08:00
|
|
|
|
4、支持提取apk图标。
|
2021-08-08 22:02:43 +08:00
|
|
|
|
|
|
|
|
|
V1.2.3
|
2021-08-08 17:14:48 +08:00
|
|
|
|
1、调整部分控件名称;
|
|
|
|
|
2、调整界面布局及界面风格;
|
|
|
|
|
|
|
|
|
|
V1.2.2
|
|
|
|
|
1、对程序错误的显示更加人性化;
|
2021-08-15 21:46:48 +08:00
|
|
|
|
2、对icon的获取方式进行了升级;
|
2021-08-08 22:02:43 +08:00
|
|
|
|
3、增加了注释、删除部分冗余代码。
|
2021-08-16 07:22:18 +08:00
|
|
|
|
'''
|
2021-08-08 17:14:48 +08:00
|
|
|
|
title = "uengine 安装器 {}".format(version)
|
2021-08-15 21:46:48 +08:00
|
|
|
|
updateTime = "2021年08月15日"
|
2021-05-29 22:54:59 +08:00
|
|
|
|
updateThings = "{} 更新内容:\n{}\n更新时间:{}".format(version, updateThingsString, updateTime, time.strftime("%Y"))
|
2021-08-12 15:12:13 +08:00
|
|
|
|
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
|
2021-06-06 11:54:38 +08:00
|
|
|
|
iconPath = "{}/icon.png".format(os.path.split(os.path.realpath(__file__))[0])
|
2021-05-29 22:54:59 +08:00
|
|
|
|
desktop = "/opt/apps/uengine-runner/UengineAndroidProgramList.desktop"
|
|
|
|
|
desktopName = "UengineAndroidProgramList.desktop"
|
2021-08-08 22:02:43 +08:00
|
|
|
|
contribute = '''gfdgd xi<3025613752@qq.com>
|
|
|
|
|
actionchen<917981399@qq.com>'''
|
2021-08-08 17:14:48 +08:00
|
|
|
|
useProgram = '''1、uengine相关软件包(基于anbox开发)
|
2021-05-30 13:04:46 +08:00
|
|
|
|
2、Python3
|
|
|
|
|
3、tkinter(tkinter.tk、ttkthemes 和 tkinter.ttk)
|
2021-07-02 20:05:01 +08:00
|
|
|
|
4、aapt
|
2021-05-30 13:04:46 +08:00
|
|
|
|
……'''
|
2021-05-29 22:54:59 +08:00
|
|
|
|
|
|
|
|
|
###########################
|
|
|
|
|
# 加载配置
|
|
|
|
|
###########################
|
2021-08-15 21:46:48 +08:00
|
|
|
|
if not os.path.exists("{}/.local/share/applications/uengine/".format(get_home())):
|
|
|
|
|
os.mkdir("{}/.local/share/applications/uengine/".format(get_home()))
|
2021-05-29 22:54:59 +08:00
|
|
|
|
if not os.path.exists(get_home() + "/.config/uengine-runner"): # 如果没有配置文件夹
|
|
|
|
|
os.mkdir(get_home() + "/.config/uengine-runner") # 创建配置文件夹
|
|
|
|
|
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApkHistory.json"): # 如果没有配置文件
|
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", json.dumps({})) # 创建配置文件
|
2021-06-06 11:54:38 +08:00
|
|
|
|
if not os.path.exists(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json"): # 如果没有配置文件
|
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", json.dumps({})) # 创建配置文件
|
2021-05-29 22:54:59 +08:00
|
|
|
|
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApk.json"): # 如果没有配置文件
|
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
2021-06-06 11:54:38 +08:00
|
|
|
|
if not os.path.exists(get_home() + "/.config/uengine-runner/FindUninstallApk.json"): # 如果没有配置文件
|
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
2021-08-08 22:02:43 +08:00
|
|
|
|
if not os.path.exists(get_home() + "/.config/uengine-runner/SaveApkIcon.json"): # 如果没有配置文件
|
|
|
|
|
write_txt(get_home() + "/.config/uengine-runner/SaveApkIcon.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
2021-05-29 22:54:59 +08:00
|
|
|
|
|
|
|
|
|
###########################
|
|
|
|
|
# 设置变量
|
|
|
|
|
###########################
|
|
|
|
|
findApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApkHistory.json")).values())
|
2021-06-06 11:54:38 +08:00
|
|
|
|
fineUninstallApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json")).values())
|
|
|
|
|
|
2021-08-08 17:14:48 +08:00
|
|
|
|
# add sub window
|
|
|
|
|
#添加窗口开启关闭开关,防止重复开启
|
|
|
|
|
windowflag = "close"
|
|
|
|
|
|
|
|
|
|
def showhelp():
|
|
|
|
|
|
2021-08-08 22:02:43 +08:00
|
|
|
|
#define window and frame and button label
|
|
|
|
|
#
|
2021-08-08 17:14:48 +08:00
|
|
|
|
global windowflag
|
|
|
|
|
if windowflag == "close":
|
|
|
|
|
helpwindow=tk.Toplevel()
|
|
|
|
|
helpwindow.resizable(0, 0)
|
|
|
|
|
helpwindow.title("帮助")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# get screen width and height
|
|
|
|
|
screen_width = helpwindow.winfo_screenwidth()
|
|
|
|
|
screen_height = helpwindow.winfo_screenheight()
|
|
|
|
|
# calculate position x and y coordinates 假设主窗口大小固定 570x236像素 ,设置窗口位置为屏幕中心。
|
2021-08-15 21:46:48 +08:00
|
|
|
|
winwith=550
|
|
|
|
|
winhigh=700
|
2021-08-08 17:14:48 +08:00
|
|
|
|
x = (screen_width/2) - (winwith/2)
|
|
|
|
|
y = (screen_height/2) - (winhigh/2)
|
|
|
|
|
|
2021-08-15 21:46:48 +08:00
|
|
|
|
helpwindow.geometry("550x700"+"+{:.0f}+{:.0f}".format(x, y))
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
|
|
|
|
style = ttkthemes.ThemedStyle(helpwindow)
|
|
|
|
|
style.set_theme("breeze")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
2021-08-15 21:46:48 +08:00
|
|
|
|
LabText = ttk.Label(LabFrmText, textvariable=HelpStr,width=55)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
LabText.config(wraplength=350)
|
|
|
|
|
|
|
|
|
|
def on_closing():
|
|
|
|
|
global windowflag
|
|
|
|
|
windowflag = "close"
|
|
|
|
|
print(windowflag)
|
|
|
|
|
helpwindow.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-08-08 22:02:43 +08:00
|
|
|
|
# define button func
|
2021-08-08 17:14:48 +08:00
|
|
|
|
def ChgLog():
|
|
|
|
|
HelpStr.set(updateThingsString)
|
|
|
|
|
def ChgAbout():
|
|
|
|
|
HelpStr.set(about)
|
|
|
|
|
def ChgDep():
|
|
|
|
|
HelpStr.set(useProgram)
|
2021-08-08 22:02:43 +08:00
|
|
|
|
def ChgCon():
|
|
|
|
|
HelpStr.set(contribute)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
def ChgTips():
|
|
|
|
|
HelpStr.set(tips)
|
|
|
|
|
LabText.config(wraplength=350)
|
|
|
|
|
|
|
|
|
|
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)
|
2021-08-08 22:02:43 +08:00
|
|
|
|
BtnGongxian = ttk.Button(FrmMenu, text="有贡献的开发者",width=14,command=ChgCon)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
BtnAbout = ttk.Button(FrmMenu, text="关于",width=14,command=ChgAbout)
|
|
|
|
|
|
|
|
|
|
|
2021-08-08 22:02:43 +08:00
|
|
|
|
#layout
|
2021-08-08 17:14:48 +08:00
|
|
|
|
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)
|
2021-08-08 22:02:43 +08:00
|
|
|
|
BtnGongxian.grid(row=3,column=0,sticky=tk.NW,padx=3)
|
|
|
|
|
BtnAbout.grid(row=4,column=0,sticky=tk.NW,padx=3)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
2021-05-29 22:54:59 +08:00
|
|
|
|
###########################
|
|
|
|
|
# 窗口创建
|
|
|
|
|
###########################
|
2021-07-11 14:45:11 +08:00
|
|
|
|
win = tk.Tk() # 创建窗口
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 设置窗口
|
2021-05-30 13:04:46 +08:00
|
|
|
|
style = ttkthemes.ThemedStyle(win)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
style.set_theme("breeze")
|
2021-05-30 13:04:46 +08:00
|
|
|
|
window = ttk.Frame(win)
|
|
|
|
|
win.attributes('-alpha', 0.5)
|
|
|
|
|
win.title(title)
|
|
|
|
|
win.resizable(0, 0)
|
|
|
|
|
win.iconphoto(False, tk.PhotoImage(file=iconPath))
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
|
|
|
|
# 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))
|
|
|
|
|
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 创建控件
|
2021-08-08 17:14:48 +08:00
|
|
|
|
FrmInstall = ttk.Frame(window)
|
|
|
|
|
FrmUninstall = ttk.Frame(window)
|
|
|
|
|
LabApkPath = ttk.Label(window, text="安装APK:")
|
|
|
|
|
LabUninstallPath = ttk.Label(window, text="卸载APK:")
|
|
|
|
|
ComboInstallPath = ttk.Combobox(window, width=50)
|
|
|
|
|
ComboUninstallPath = ttk.Combobox(window, width=50)
|
|
|
|
|
BtnFindApk = ttk.Button(FrmInstall, text="浏览", command=FindApk)
|
|
|
|
|
BtnInstall = ttk.Button(FrmInstall, text="安装", command=Button3Install)
|
|
|
|
|
BtnShowUengineApp = ttk.Button(window, text="打开 uengine 应用列表", command=Button5Click)
|
|
|
|
|
BtnUninstallApkBrowser = ttk.Button(FrmUninstall, text="浏览", command=BtnFindUninstallApkClk)
|
|
|
|
|
BtnUninstall = ttk.Button(FrmUninstall, text="卸载", command=ButtonClick8)
|
2021-08-08 22:02:43 +08:00
|
|
|
|
Btngeticon = ttk.Button(window, text="保存图标", command=SaveIconToOtherPath)
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 设置菜单栏
|
|
|
|
|
menu = tk.Menu(window, background="white")
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
2021-05-30 13:04:46 +08:00
|
|
|
|
programmenu = tk.Menu(menu, tearoff=0, background="white") # 设置“程序”菜单栏
|
|
|
|
|
uengine = tk.Menu(menu, tearoff=0, background="white")
|
|
|
|
|
help = tk.Menu(menu, tearoff=0, background="white") # 设置“帮助”菜单栏
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
2021-05-29 22:54:59 +08:00
|
|
|
|
menu.add_cascade(label="程序", menu=programmenu)
|
2021-05-30 13:04:46 +08:00
|
|
|
|
menu.add_cascade(label="uengine", menu=uengine)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
menu.add_cascade(label="关于", menu=help)
|
|
|
|
|
|
2021-05-29 22:54:59 +08:00
|
|
|
|
programmenu.add_command(label="清空软件历史记录", command=CleanProgramHistory)
|
|
|
|
|
programmenu.add_separator() # 设置分界线
|
2021-08-08 17:14:48 +08:00
|
|
|
|
programmenu.add_command(label="退出程序", command=window.quit) # 设置“退出程序”
|
|
|
|
|
|
2021-05-29 22:54:59 +08:00
|
|
|
|
uengine.add_command(label="发送 uengine 应用列表到桌面", command=SendUengineAndroidListForDesktop)
|
|
|
|
|
uengine.add_command(label="发送 uengine 应用列表到启动器", command=SendUengineAndroidListForLauncher)
|
2021-08-15 21:46:48 +08:00
|
|
|
|
uengine.add_separator()
|
2021-08-16 07:22:18 +08:00
|
|
|
|
uengine.add_command(label="启用 uengine", command=StartUengine)
|
|
|
|
|
uengine.add_command(label="禁用 uengine", command=StopUengine)
|
|
|
|
|
uengine.add_separator()
|
2021-08-15 21:46:48 +08:00
|
|
|
|
uengine.add_command(label="启用 uengine 网络桥接", command=UengineBridgeStart)
|
|
|
|
|
uengine.add_command(label="关闭 uengine 网络桥接", command=UengineBridgeStop)
|
|
|
|
|
uengine.add_command(label="重启 uengine 网络桥接", command=UengineBridgeRestart)
|
|
|
|
|
uengine.add_command(label="加载 uengine 网络桥接", command=UengineBridgeReload)
|
|
|
|
|
uengine.add_command(label="强制加载 uengine 网络桥接", command=UengineBridgeForceReload)
|
|
|
|
|
|
|
|
|
|
uengine.add_separator()
|
|
|
|
|
uengine.add_command(label="清空 uengine 数据", command=BackUengineClean)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
2021-05-29 22:54:59 +08:00
|
|
|
|
help.add_command(label="程序官网", command=OpenProgramURL) # 设置“程序官网”项
|
2021-08-08 17:14:48 +08:00
|
|
|
|
help.add_command(label="帮助", command=showhelp) # 设置“关于这个程序”项
|
|
|
|
|
|
|
|
|
|
menu.configure(activebackground="dodgerblue")
|
|
|
|
|
help.configure(activebackground="dodgerblue")
|
|
|
|
|
uengine.configure(activebackground="dodgerblue")
|
|
|
|
|
programmenu.configure(activebackground="dodgerblue")
|
|
|
|
|
|
2021-05-29 22:54:59 +08:00
|
|
|
|
# 设置控件
|
2021-08-08 17:14:48 +08:00
|
|
|
|
ComboUninstallPath['value'] = fineUninstallApkHistory
|
|
|
|
|
ComboInstallPath['value'] = findApkHistory
|
2021-08-15 21:46:48 +08:00
|
|
|
|
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])
|
|
|
|
|
print("Unstall Path: " + sys.argv[2])
|
|
|
|
|
else:
|
|
|
|
|
print("Command Format Error")
|
|
|
|
|
except:
|
|
|
|
|
print("Not Command Or Command Format Error")
|
2021-07-11 14:45:11 +08:00
|
|
|
|
# 显示控件
|
2021-05-30 13:04:46 +08:00
|
|
|
|
win.config(menu=menu) # 显示菜单栏
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LabApkPath.grid(row=1, column=0,sticky= tk.W,padx=3)
|
|
|
|
|
ComboInstallPath.grid(row=2, column=0,padx=3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FrmInstall.grid(row=2, column=1,padx=3)
|
|
|
|
|
BtnFindApk.grid(row=0, column=0)
|
|
|
|
|
BtnInstall.grid(row=0, column=1)
|
|
|
|
|
|
|
|
|
|
LabUninstallPath.grid(row=3, column=0,sticky= tk.W,padx=3)
|
|
|
|
|
ComboUninstallPath.grid(row=4, column=0,padx=3)
|
|
|
|
|
|
|
|
|
|
FrmUninstall.grid(row=4, column=1,padx=3)
|
|
|
|
|
BtnUninstallApkBrowser.grid(row=0, column=0)
|
|
|
|
|
BtnUninstall.grid(row=0, column=1)
|
|
|
|
|
|
|
|
|
|
BtnShowUengineApp.grid(row=5, column=0,sticky= tk.W,padx=3,pady=2)
|
|
|
|
|
|
2021-08-08 22:02:43 +08:00
|
|
|
|
Btngeticon.grid(row=3, column=1,sticky= tk.W,padx=3,pady=2)
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
2021-05-30 13:04:46 +08:00
|
|
|
|
window.pack()
|
2021-08-08 17:14:48 +08:00
|
|
|
|
|
|
|
|
|
win.mainloop()
|