This commit is contained in:
2022-07-04 22:44:04 +08:00
parent d4f5053c78
commit 302db1b690
19 changed files with 1307 additions and 144 deletions

206
main.py
View File

@@ -1,8 +1,8 @@
#!/usr/bin/env python3
# 使用系统默认的 python3 运行
###########################################################################################
# 作者gfdgd xi
# 版本1.5.0
# 作者gfdgd xi、为什么您不喜欢熊出没和阿布呢
# 版本1.5.1
# 更新时间2022年07月03日
# 感谢:感谢 wine 以及 deepin-wine 团队,提供了 wine 和 deepin-wine 给大家使用,让我能做这个程序
# 基于 Python3 的 tkinter 构建
@@ -92,21 +92,27 @@ def DisableButton(things):
button1.configure(state=a[things])
button2.configure(state=a[things])
button3.configure(state=a[things])
wineConfig.configure(state=a[things])
e1.configure(state=a[things])
e2.configure(state=a[things])
o1.configure(state=a[things])
winetricksOpen.configure(state=a[things])
getProgramIcon.configure(state=a[things])
uninstallProgram.configure(state=a[things])
# 运行可执行文件的线程
def runexebutton_threading():
DisableButton(True)
if e1.get() == "" or e2.get() == "": # 判断文本框是否有内容
tkinter.messagebox.showinfo(title="提示", message="没有填写需要使用的 wine 容器或需要运行的 exe 应用")
if e2.get() == "": # 判断文本框是否有内容
tkinter.messagebox.showinfo(title="提示", message="没有填写需要使用的 exe 应用")
DisableButton(False)
return
else: # 如果都有
#text = subprocess.getoutput("WINEPREFIX='" + e1.get() + "' " + wine[o1_text.get()] + " '" + e2.get() + "'") # 运行
res = subprocess.Popen(["WINEPREFIX='" + e1.get() + "' " + wine[o1_text.get()] + " '" + e2.get() + "'"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if e1.get() == "":
wineBottonPath = get_home() + "/.wine"
else:
wineBottonPath = e1.get()
res = subprocess.Popen(["WINEPREFIX='" + wineBottonPath + "' " + wine[o1_text.get()] + " '" + e2.get() + "'"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# 清空文本框内容
returnText.config(state=tk.NORMAL)
returnText.delete(1.0, "end")
@@ -114,11 +120,14 @@ def runexebutton_threading():
# 实时读取程序返回
while res.poll() is None:
returnText.config(state=tk.NORMAL)
text = res.stdout.readline().decode("utf8")
try:
text = res.stdout.readline().decode("utf8")
except:
text = ""
returnText.insert("end", text)
print(text)
returnText.config(state=tk.DISABLED)
findExeHistory.append(e1.get()) # 将记录写进数组
findExeHistory.append(wineBottonPath) # 将记录写进数组
wineBottonHistory.append(e2.get()) # 将记录写进数组
write_txt(get_home() + "/.config/deepin-wine-runner/FindExeHistory.json", str(json.dumps(ListToDictionary(findExeHistory)))) # 将历史记录的数组转换为字典并写入
write_txt(get_home() + "/.config/deepin-wine-runner/WineBottonHistory.json", str(json.dumps(ListToDictionary(wineBottonHistory)))) # 将历史记录的数组转换为字典并写入
@@ -157,8 +166,8 @@ def UpdateThings():
# 生成 desktop 文件在启动器
def make_desktop_on_launcher():
if combobox1.get() == "" or e2.get() == "" or e1.get() == "": # 判断文本框是否有内容
tkinter.messagebox.showinfo(title="提示", message="没有填写需要使用的 wine 容器或需要运行的 exe 应用或保存的文件名")
if combobox1.get() == "" or e2.get() == "": # 判断文本框是否有内容
tkinter.messagebox.showinfo(title="提示", message="没有填写需要使用 exe 应用或保存的文件名")
else: # 如果都有
if os.path.exists(get_home() + "/.local/share/applications/" + combobox1.get() + ".desktop"): # 判断目录是否有该文件,如果有
choose = tkinter.messagebox.askokcancel(title="提示", message="文件已经存在,是否覆盖?") # 询问用户是否覆盖
@@ -166,10 +175,13 @@ def make_desktop_on_launcher():
os.remove(get_home() + "/.local/share/applications/" + combobox1.get() + ".desktop") # 删除该文件
else: # 如不覆盖
return # 结束
#os.mknod(get_home() + "/.local/share/applications/" + combobox1.get() + ".desktop")
if e1.get() == "":
wineBottonPath = get_home() + "/.wine"
else:
wineBottonPath = e1.get()
write_txt(get_home() + "/.local/share/applications/" + combobox1.get() + ".desktop", f'''[Desktop Entry]
Name={combobox1.get()}
Exec=env WINEPREFIX='{e1.get()}' {wine[o1_text.get()]} '{e2.get()}'
Exec=env WINEPREFIX='{wineBottonPath}' {wine[o1_text.get()]} '{e2.get()}'
Icon={iconPath}
Type=Application
StartupNotify=true''') # 写入文本文档
@@ -181,8 +193,8 @@ StartupNotify=true''') # 写入文本文档
# 生成 desktop 文件在桌面
# (第四个按钮的事件)
def make_desktop_on_desktop():
if combobox1.get() == "" or e2.get() == "" or e1.get() == "": # 判断文本框是否有内容
tkinter.messagebox.showinfo(title="提示", message="没有填写需要使用的 wine 容器或需要运行的 exe 应用或保存的文件名")
if combobox1.get() == "" or e2.get() == "": # 判断文本框是否有内容
tkinter.messagebox.showinfo(title="提示", message="没有填写需要使用的 exe 应用或保存的文件名")
else: # 如果都有
if os.path.exists(get_desktop_path() + "/" + combobox1.get() + ".desktop"): # 判断目录是否有该文件,如果有
choose = tkinter.messagebox.askokcancel(title="提示", message="文件已经存在,是否覆盖?") # 询问用户是否覆盖
@@ -190,10 +202,14 @@ def make_desktop_on_desktop():
os.remove(get_desktop_path() + "/" + combobox1.get() + ".desktop") # 删除该文件
else: # 如不覆盖
return # 结束
if e1.get() == "":
wineBottonPath = get_home() + "/.wine"
else:
wineBottonPath = e1.get()
os.mknod(get_desktop_path() + "/" + combobox1.get() + ".desktop")
write_txt(get_desktop_path() + "/" + combobox1.get() + ".desktop", f'''[Desktop Entry]
Name={combobox1.get()}
Exec=env WINEPREFIX='{e1.get()}' {wine[o1_text.get()]} '{e2.get()}'
Exec=env WINEPREFIX='{wineBottonPath}' {wine[o1_text.get()]} '{e2.get()}'
Icon={iconPath}
Type=Application
StartupNotify=true''') # 写入文本文档
@@ -228,41 +244,99 @@ def InstallWine():
def OpenWineBotton():
if e1.get() == "":
tkinter.messagebox.showinfo(title="提示", message="您未选择需要打开的 Wine 容器")
return
os.system("xdg-open \"" + e1.get().replace("\"", "\\\"") + "\"")
wineBottonPath = get_home() + "/.wine"
else:
wineBottonPath = e1.get()
os.system("xdg-open \"" + wineBottonPath.replace("\'", "\\\'") + "\"")
def OpenWineFontPath():
if e1.get() == "":
tkinter.messagebox.showinfo(title="提示", message="您未选择需要打开的 Wine 容器")
return
wineBottonPath = get_home() + "/.wine"
else:
wineBottonPath = e1.get()
tkinter.messagebox.showinfo(title="提示", message="如果安装字体?只需要把字体文件复制到此字体目录\n按下“OK”按钮可以打开字体目录")
os.system("xdg-open \"" + e1.get().replace("\"", "\\\"") + "/drive_c/windows/Fonts\"")
os.system("xdg-open \"" + wineBottonPath.replace("\'", "\\\'") + "/drive_c/windows/Fonts\"")
def UninstallProgram():
threading.Thread(target=UninstallProgram_threading).start()
def UninstallProgram_threading():
threading.Thread(target=RunWineProgram, args=[programPath + "/geek.exe"]).start()
def ConfigWineBotton():
threading.Thread(target=RunWineProgram, args=["winecfg"]).start()
def RunWineProgram(wineProgram, history = False):
DisableButton(True)
if e1.get() == "": # 判断文本框是否有内容
tkinter.messagebox.showinfo(title="提示", message="没有填写需要使用的 wine 容器")
DisableButton(False)
else: # 如果都有
#text = subprocess.getoutput("WINEPREFIX='" + e1.get() + "' " + wine[o1_text.get()] + " '" + e2.get() + "'") # 运行
res = subprocess.Popen(["WINEPREFIX='" + e1.get() + "' " + wine[o1_text.get()] + " '" + programPath + "/geek.exe'"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# 清空文本框内容
if e1.get() == "":
wineBottonPath = get_home() + "/.wine"
else:
wineBottonPath = e1.get()
print("WINEPREFIX='" + wineBottonPath + "' " + wine[o1_text.get()] + " '" + wineProgram + "'")
res = subprocess.Popen(["WINEPREFIX='" + wineBottonPath + "' " + wine[o1_text.get()] + " '" + wineProgram + "'"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# 清空文本框内容
returnText.config(state=tk.NORMAL)
returnText.delete(1.0, "end")
returnText.config(state=tk.DISABLED)
# 实时读取程序返回
while res.poll() is None:
returnText.config(state=tk.NORMAL)
returnText.delete(1.0, "end")
returnText.config(state=tk.DISABLED)
# 实时读取程序返回
while res.poll() is None:
returnText.config(state=tk.NORMAL)
try:
text = res.stdout.readline().decode("utf8")
returnText.insert("end", text)
print(text)
returnText.config(state=tk.DISABLED)
except:
text = ""
returnText.insert("end", text)
print(text)
returnText.config(state=tk.DISABLED)
if history:
findExeHistory.append(wineBottonPath) # 将记录写进数组
wineBottonHistory.append(e2.get()) # 将记录写进数组
write_txt(get_home() + "/.config/deepin-wine-runner/FindExeHistory.json", str(json.dumps(ListToDictionary(findExeHistory)))) # 将历史记录的数组转换为字典并写入
write_txt(get_home() + "/.config/deepin-wine-runner/WineBottonHistory.json", str(json.dumps(ListToDictionary(wineBottonHistory)))) # 将历史记录的数组转换为字典并写入
e1['value'] = findExeHistory
e2['value'] = wineBottonHistory
DisableButton(False)
def RunWinetricks():
DisableButton(True)
wineBottonPath = get_home() + "/.wine"
if not e1.get() == "":
wineBottonPath = e1.get()
print("WINEPREFIX='" + wineBottonPath + "' winetricks")
res = subprocess.Popen(["WINEPREFIX='" + wineBottonPath + "' winetricks"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# 清空文本框内容
returnText.config(state=tk.NORMAL)
returnText.delete(1.0, "end")
returnText.config(state=tk.DISABLED)
# 实时读取程序返回
while res.poll() is None:
returnText.config(state=tk.NORMAL)
try:
text = res.stdout.readline().decode("utf8")
except:
text = ""
returnText.insert("end", text)
print(text)
returnText.config(state=tk.DISABLED)
DisableButton(False)
def InstallMonoGecko(program):
DisableButton(True)
if e1.get() == "":
wineBottonPath = get_home() + "/.wine"
else:
wineBottonPath = e1.get()
os.system(f"deepin-terminal -C \"'{programPath}/InstallMono.py' '{wineBottonPath}' {wine[o1_text.get()]} {program}\" --keep-open")
DisableButton(False)
def InstallNetFramework():
DisableButton(True)
if e1.get() == "":
wineBottonPath = get_home() + "/.wine"
else:
wineBottonPath = e1.get()
os.system(f"deepin-terminal -C \"'{programPath}/InstallNetFramework.py' '{wineBottonPath}' {wine[o1_text.get()]}\" --keep-open")
DisableButton(False)
###########################
# 加载配置
@@ -284,7 +358,7 @@ if not os.path.exists(get_home() + "/.config/deepin-wine-runner/WineBotton.json"
# 设置变量
###########################
# 如果要添加其他 wine请在字典添加其名称和执行路径
wine = {"deepin-wine": "deepin-wine", "deepin-wine5": "deepin-wine5", "wine": "wine", "wine64": "wine64", "deepin-wine5 stable": "deepin-wine5-stable", "deepin-wine6 stable": "deepin-wine6-stable", "spark-wine7-devel": "spark-wine7-devel"}
wine = {"deepin-wine": "deepin-wine", "deepin-wine5": "deepin-wine5", "wine": "wine", "wine64": "wine64", "deepin-wine5 stable": "deepin-wine5-stable", "deepin-wine6 stable": "deepin-wine6-stable", "spark-wine7-devel": "spark-wine7-devel", "ukylin-wine": "ukylin-wine"}
shellHistory = list(json.loads(readtxt(get_home() + "/.config/deepin-wine-runner/ShellHistory.json")).values())
findExeHistory = list(json.loads(readtxt(get_home() + "/.config/deepin-wine-runner/FindExeHistory.json")).values())
wineBottonHistory = list(json.loads(readtxt(get_home() + "/.config/deepin-wine-runner/WineBottonHistory.json")).values())
@@ -294,8 +368,8 @@ wineBottonHistory = list(json.loads(readtxt(get_home() + "/.config/deepin-wine-r
# 程序信息
###########################
iconPath = "{}/icon.png".format(os.path.split(os.path.realpath(__file__))[0])
programUrl = "https://gitee.com/gfdgd-xi/deep-wine-runner"
version = "1.5.0"
programUrl = "https://gitee.com/gfdgd-xi/deep-wine-runner\nhttps://github.com/gfdgd-xi/deep-wine-runner\nhttps://www.gitlink.org.cn/gfdgd_xi/deep-wine-runner"
version = "1.5.1"
goodRunSystem = "Linux"
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
about = '''一个基于 Python3 的 tkinter 制作的 wine 运行器
@@ -303,21 +377,27 @@ about = '''一个基于 Python3 的 tkinter 制作的 wine 运行器
适用平台:{}
tkinter 版本:{}
程序官网:{}
©2020-{} gfdgd xi'''.format(version, goodRunSystem, tk.TkVersion, programUrl, time.strftime("%Y"))
©2020-{} gfdgd xi、为什么您不喜欢熊出没和阿布呢'''.format(version, goodRunSystem, tk.TkVersion, programUrl, time.strftime("%Y"))
tips = '''提示:
1、使用终端运行该程序可以看到 wine 以及程序本身的提示和报错;
2、wine 32 位和 64 位的容器互不兼容;
3、部分 wine 系统没有预装,本程序没有设置任何 wine 的依赖项,如果需要使用请自行安装'''
updateThingsString = '''*1、支持显示 wine 程序运行时的返回内容
*2、优化打包方式减少从 pip 安装的库,并将 pip 源设为阿里源提升下载速度
*3、新增 spark-wine7-devel
*4、支持从程序启动用于安装 wine 的程序(在菜单栏的“程序”)
5、优化 wine 安装脚本,在安装星火应用商店的 wine 时支持检测是否有 ss-apt-fast如果有就调用替代 apt 提升安装速度
6、支持关闭指定 wine 的进程,以及访问对应 wine 容器的目录和字体目录
7、从生成shell脚本改为升级到desktop文件
3、所有的 wine 和 winetricks 均需要自行安装(可以从 菜单栏=>程序 里面进行安装)
4、本程序支持带参数运行 wine 程序(之前版本也可以),只需要按以下格式即可:
exe路径\' 参数 \'
即可(单引号需要输入)
5、wine 容器如果没有指定,则会默认为 ~/.wine'''
updateThingsString = '''※1、支持打开 spark-wine7-devel 的专门缩放设置(如未安装则此按钮禁用)
※2、支持提取选择的 exe 文件的图标
※3、支持向指定的 wine 容器安装 mono、gecko、.net framework此功能在菜单栏“Wine”中卸载只需要使用程序的卸载按钮打开 Geek Uninstaller 即可)
※4、支持指定特定的 wine 容器调用 winetricks
※5、在没有指定 wine 容器的情况下,将自动设置为 ~/.wine
6、新增 ukylin-wine
7、将默认选择的 wine 改为 deepin-wine6 stable
8、支持打开指定容器的 winecfg、winver、regedit、taskmgr
9、双击使用 wine 运行器打开 exe不知道能不能生效
'''
title = "wine 运行器 {}".format(version)
updateTime = "2022年07月03"
updateTime = "2022年07月04"
updateThings = "{} 更新内容:\n{}\n更新时间:{}".format(version, updateThingsString, updateTime, time.strftime("%Y"))
@@ -330,7 +410,7 @@ window = ttk.Frame()
# 设置变量以修改和获取值项
o1_text = tk.StringVar()
combobox1 = tk.StringVar()
o1_text.set("deepin-wine")
o1_text.set("deepin-wine6 stable")
# 创建控件
controlFrame = ttk.Frame(window)
sendFrame = ttk.Frame(window)
@@ -338,9 +418,13 @@ button1 = ttk.Button(window, text="浏览", command=liulanbutton) # 创建按
button2 = ttk.Button(window, text="浏览", command=liulanexebutton) # 创建按钮控件
button3 = ttk.Button(controlFrame, text="启动", command=runexebutton) # 创建按钮控件
killProgram = ttk.Button(controlFrame, text="停止", command=KillProgram)
openWineBotton = ttk.Button(controlFrame, text="打开 Wine 容器所在目录", command=OpenWineBotton)
openWineBotton = ttk.Button(controlFrame, text="打开Wine容器目录", command=OpenWineBotton)
installWineFont = ttk.Button(controlFrame, text="安装字体", command=OpenWineFontPath)
uninstallProgram = ttk.Button(controlFrame, text="卸载程序", command=UninstallProgram)
wineConfig = ttk.Button(controlFrame, text="配置wine容器", command=ConfigWineBotton)
sparkWineSetting = ttk.Button(controlFrame, text="星火wine设置", command=lambda: threading.Thread(target=os.system, args=["/opt/durapps/spark-dwine-helper/spark-dwine-helper-settings/settings.sh"]).start())
getProgramIcon = ttk.Button(controlFrame, text="获取选择的程序图标", command=lambda: threading.Thread(target=RunWineProgram, args=[f"{programPath}/Run.bat' '{programPath}/BeCyIconGrabber.exe' '{e2.get()}"]).start())
winetricksOpen = ttk.Button(controlFrame, text="使用winetricks打开指定容器(只能使用wine和wine64)", command=lambda: threading.Thread(target=RunWinetricks).start())
button5 = ttk.Button(sendFrame, text="创建用于运行的 desktop 文件到桌面", command=make_desktop_on_desktop) # 创建按钮控件
saveDesktopFileOnLauncher = ttk.Button(sendFrame, text="创建用于运行的 desktop 文件到启动器", command=make_desktop_on_launcher) # 创建按钮控件
label1 = ttk.Label(window, text="选择你想要使用的 wine 容器:") # 创建标签控件
@@ -350,7 +434,7 @@ label4 = ttk.Label(window, text="设置标题,以便把上方填写的信息
e1 = ttk.Combobox(window, width=100) # 创建文本框控件
e2 = ttk.Combobox(window, width=100) # 创建文本框控件
combobox1 = ttk.Combobox(window, width=100)
o1 = ttk.OptionMenu(window, o1_text, "deepin-wine", *list(wine)) # 创建选择框控件
o1 = ttk.OptionMenu(window, o1_text, "deepin-wine6 stable", *list(wine)) # 创建选择框控件
returnText = tk.Text(window)
menu = tk.Menu(window, background="white") # 设置菜单栏
programmenu = tk.Menu(menu, tearoff=0, background="white") # 设置“程序”菜单栏
@@ -360,6 +444,14 @@ programmenu.add_separator() # 设置分界线
programmenu.add_command(label="清空软件历史记录", command=CleanProgramHistory)
programmenu.add_separator() # 设置分界线
programmenu.add_command(label="退出程序", command=window.quit) # 设置“退出程序”项
wineOption = tk.Menu(menu, tearoff=0, background="white") # 设置“Wine”菜单栏
menu.add_cascade(label="Wine", menu=wineOption)
wineOption.add_command(label="在指定wine、指定容器安装 .net framework", command=lambda: threading.Thread(target=InstallNetFramework).start())
wineOption.add_command(label="在指定wine、指定容器安装 gecko", command=lambda: threading.Thread(target=InstallMonoGecko, args=["gecko"]).start())
wineOption.add_command(label="在指定wine、指定容器安装 mono", command=lambda: threading.Thread(target=InstallMonoGecko, args=["mono"]).start())
wineOption.add_command(label="打开指定wine、指定容器的注册表", command=lambda: threading.Thread(target=RunWineProgram, args=["regedit"]).start())
wineOption.add_command(label="打开指定wine、指定容器的任务管理器", command=lambda: threading.Thread(target=RunWineProgram, args=["taskmgr"]).start())
wineOption.add_command(label="打开指定wine、指定容器的关于 wine", command=lambda: threading.Thread(target=RunWineProgram, args=["winver"]).start())
help = tk.Menu(menu, tearoff=0, background="white") # 设置“帮助”菜单栏
menu.add_cascade(label="帮助", menu=help)
help.add_command(label="程序官网", command=OpenProgramURL) # 设置“程序官网”项
@@ -373,14 +465,20 @@ themes = ttkthemes.ThemedStyle(win)
themes.set_theme("adapta")
win.config(bg="white")
# 设置控件
if len(sys.argv) > 1 and sys.argv[1]:
e1.set(f"{get_home()}/.wine")
e2.set(sys.argv[1])
menu.configure(activebackground="white")
programmenu.configure(activebackground="white")
wineOption.configure(activebackground="white")
help.configure(activebackground="white")
e1['value'] = findExeHistory
e2['value'] = wineBottonHistory
combobox1['value'] = shellHistory
returnText.insert("end", "此可以查看到 Wine 应用安装时的程序返回值")
returnText.config(state=tk.DISABLED)
if not os.path.exists("/opt/durapps/spark-dwine-helper/spark-dwine-helper-settings/settings.sh"):
sparkWineSetting.config(state=tk.DISABLED)
# 添加控件
win.config(menu=menu) # 显示菜单栏
label1.grid(row=0, column=0)
@@ -399,6 +497,10 @@ killProgram.grid(row=0, column=1)
openWineBotton.grid(row=0, column=2)
installWineFont.grid(row=0, column=3)
uninstallProgram.grid(row=0, column=4)
wineConfig.grid(row=0, column=5)
sparkWineSetting.grid(row=0, column=6)
getProgramIcon.grid(row=0, column=7)
winetricksOpen.grid(row=0, column=8)
sendFrame.grid(row=5, column=0, columnspan=3)
button5.grid(row=0, column=0)
saveDesktopFileOnLauncher.grid(row=0, column=1)