初步Qt迁移

This commit is contained in:
gfdgd_xi 2022-07-23 12:44:33 +08:00
parent 7f18273cca
commit eb44817201
2 changed files with 65 additions and 97 deletions

View File

@ -1,15 +1,14 @@
#!/usr/bin/env python3
import os
import sys
import json
import base64
import requests
import ttkthemes
import traceback
import webbrowser
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.messagebox as messagebox
import urllib.parse as parse
import PyQt5.QtGui as QtGui
import PyQt5.QtWidgets as QtWidgets
# 读取文本文档
def readtxt(path: "路径")->"读取文本文档":
@ -28,17 +27,18 @@ def Update(name, stars, contact, things, version):
"Version": version
}
try:
messagebox.showinfo(message=requests.post(parse.unquote(base64.b64decode("aHR0cCUzQS8vMTIwLjI1LjE1My4xNDQvdWVuZ2luZS1ydW5uZXIvYnVnL3VwbG9hZC5waHA=").decode("utf-8")), data=data).text)
QtWidgets.QMessageBox.information(widget, "提示", requests.post(parse.unquote(base64.b64decode("aHR0cCUzQS8vMTIwLjI1LjE1My4xNDQvdWVuZ2luZS1ydW5uZXIvYnVnL3VwbG9hZC5waHA=").decode("utf-8")), data=data).text)
print(data)
except:
traceback.print_exc()
messagebox.showerror(title="错误", message="服务器疑似出现错误,可以进行以下尝试:①多尝试几次;②使用其他反馈途径\n错误信息{}".format(traceback.format_exc()))
QtWidgets.QMessageBox.critical(widget, "错误", f"服务器疑似出现错误,可以进行以下尝试:①多尝试几次;②使用其他反馈途径\n错误信息{traceback.format_exc()}")
def UpdateButtonClick():
#判断是否为空
if nameThings.get() == "" or starValue.get() == "" or contactThings.get() == "" or updateThings.get(1.0, "end").replace(" ", "").replace("\n", "") == "":
messagebox.showerror(title="错误", message="反馈信息未填写完整!")
if nameThings.text() == "" or starMenu.currentText() == "" or contactThings.text() == "" or updateThings.toPlainText().replace(" ", "").replace("\n", "") == "":
QtWidgets.QMessageBox.critical(widget, "错误", "反馈信息未填写完整!")
return
Update(name=nameThings.get(), stars=starValue.get(), contact=contactThings.get(), things=updateThings.get(1.0, "end"), version=version)
Update(name=nameThings.text(), stars=starMenu.currentText(), contact=contactThings.text(), things=updateThings.toPlainText(), version=version)
def OpenGiteeIssues():
webbrowser.open_new_tab("https://gitee.com/gfdgd-xi/uengine-runner/issues")
@ -46,6 +46,9 @@ def OpenGiteeIssues():
def OpenGithubIssues():
webbrowser.open_new_tab("https://github.com/gfdgd-xi/uengine-runner/issues")
def OpenGitlinkIssues():
webbrowser.open_new_tab("https://www.gitlink.org.cn/gfdgd_xi/uengine-runner/issues")
# 获取用户主目录
def get_home()->"获取用户主目录":
return os.path.expanduser('~')
@ -53,7 +56,7 @@ def get_home()->"获取用户主目录":
###########################
# 程序信息
###########################
iconPath = "{}/runner.png".format(os.path.split(os.path.realpath(__file__))[0])
iconPath = "{}/runner.svg".format(os.path.split(os.path.realpath(__file__))[0])
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
information = json.loads(readtxt(programPath + "/information.json"))
version = information["Version"]
@ -61,68 +64,42 @@ version = information["Version"]
###########################
# 窗口创建
###########################
# 读取主题
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:
window = tk.Tk()
themes = ttkthemes.ThemedStyle(window)
themes.set_theme("breeze")
else:
import ttkbootstrap
style = ttkbootstrap.Style(theme="darkly")
window = style.master # 创建窗口
win = ttk.Frame()
starValue = tk.StringVar()
starValue.set("5分")
name = ttk.Label(win, text="你的昵称:")
nameThings = ttk.Entry(win, width=25)
contact = ttk.Label(win, text="联系方式(电子邮箱):")
contactThings = ttk.Entry(win, width=25)
star = ttk.Label(win, text="评分:")
starMenu = ttk.OptionMenu(win, starValue, "5分", "5分", "4分", "3分", "2分", "1分")
updateThingsTips = ttk.Label(win, text="反馈内容(支持 Markdown 格式):")
updateThings = tk.Text(win, width=100)
otherUpload = ttk.Frame(win)
# 所属内容
tips = ttk.Label(otherUpload, text="如果无法正常反馈,可以用其他方式反馈:")
giteeButton = ttk.Button(otherUpload, text="Gitee Issues", command=OpenGiteeIssues)
githubButton = ttk.Button(otherUpload, text="Github Issues", command=OpenGithubIssues)
updateButton = ttk.Button(win, text="提交", command=UpdateButtonClick)
# 设置窗口
window.title("UEngine 运行器 {} 问题/建议反馈".format(version))
window.resizable(0, 0)
window.iconphoto(False, tk.PhotoImage(file=iconPath))
tips.grid(row=0, column=0)
giteeButton.grid(row=0, column=1)
githubButton.grid(row=0, column=2)
name.grid(row=0, column=0)
nameThings.grid(row=0, column=1)
contact.grid(row=0, column=2)
contactThings.grid(row=0, column=3)
star.grid(row=0, column=4)
starMenu.grid(row=0, column=5)
updateThingsTips.grid(row=1, column=0, columnspan=2)
updateThings.grid(row=2, column=0, columnspan=6)
otherUpload.grid(row=3, column=0, columnspan=4, sticky=tk.W)
updateButton.grid(row=3, column=5)
win.pack(expand="yes", fill="both")
window.mainloop()
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
widget = QtWidgets.QWidget()
widgetLayout = QtWidgets.QGridLayout()
nameThings = QtWidgets.QLineEdit()
contactThings = QtWidgets.QLineEdit()
starMenu = QtWidgets.QComboBox()
updateThings = QtWidgets.QTextEdit()
updateButton = QtWidgets.QPushButton("提交")
otherUpload = QtWidgets.QHBoxLayout()
giteeButton = QtWidgets.QPushButton("Gitee Issues")
githubButton = QtWidgets.QPushButton("Github Issues")
gitlinkButton = QtWidgets.QPushButton("Gitlink Issues")
otherUpload.addWidget(QtWidgets.QLabel("如果无法正常反馈,可以用其他方式反馈:"))
otherUpload.addWidget(giteeButton)
otherUpload.addWidget(githubButton)
otherUpload.addWidget(gitlinkButton)
otherUpload.addSpacerItem(QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum))
starMenu.addItems(["5分", "4分", "3分", "2分", "1分"])
widgetLayout.addWidget(QtWidgets.QLabel("你的昵称:"), 0, 0, 1, 1)
widgetLayout.addWidget(QtWidgets.QLabel("联系方式(电子邮箱):"), 0, 2, 1, 1)
widgetLayout.addWidget(QtWidgets.QLabel("评分:"), 0, 4, 1, 1)
widgetLayout.addWidget(QtWidgets.QLabel("反馈内容(支持 Markdown 格式):"), 1, 0, 1, 2)
widgetLayout.addWidget(nameThings, 0, 1, 1, 1)
widgetLayout.addWidget(contactThings, 0, 3, 1, 1)
widgetLayout.addWidget(starMenu, 0, 5, 1, 1)
widgetLayout.addWidget(updateThings, 2, 0, 1, 6)
widgetLayout.addLayout(otherUpload, 3, 0, 1, 5)
widgetLayout.addWidget(updateButton, 3, 5, 1, 1)
giteeButton.clicked.connect(OpenGiteeIssues)
githubButton.clicked.connect(OpenGithubIssues)
gitlinkButton.clicked.connect(OpenGitlinkIssues)
updateButton.clicked.connect(UpdateButtonClick)
widget.setLayout(widgetLayout)
window.setCentralWidget(widget)
window.setWindowTitle(f"UEngine 运行器 {version} 问题/建议反馈")
window.setWindowIcon(QtGui.QIcon(iconPath))
window.show()
sys.exit(app.exec_())

View File

@ -1,15 +1,12 @@
#!/usr/bin/env python3
#########################################
# 版本1.6.2
# 更新时间2022年06月19
# 版本1.8.0
# 更新时间2022年07月23
#########################################
import os
import sys
import traceback
import ttkthemes
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.messagebox as messagebox
import PyQt5.QtWidgets as QtWidgets
########################
#
########################
@ -29,40 +26,34 @@ def readtxt(path: "路径")->"读取文本文档":
###################
# 判断是不是 root
###################
app = QtWidgets.QApplication(sys.argv)
if os.geteuid() != 0:
print("不是以 root 权限运行本程序!")
root = tk.Tk()
root.overrideredirect(1)
root.withdraw()
messagebox.showerror(title="错误", message="不是以 root 权限运行本程序!")
QtWidgets.QMessageBox.critical(None, "错误", "不是以 root 权限运行本程序!")
sys.exit(1)
###################
#
###################
window = tk.Tk()
style = ttkthemes.ThemedStyle(window)
style.set_theme("breeze")
window.withdraw()
try:
if sys.argv[1] == "1" and messagebox.askokcancel(title="提示", message="你确定要删除吗?"):
if sys.argv[1] == "1" and QtWidgets.QMessageBox.question(None, "提示", "你确定要删除吗?", QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Cancel) == QtWidgets.QMessageBox.Ok:
os.remove("/data/uengine/data/data/misc/adb/adb_keys")
messagebox.showinfo(title="提示", message="完成")
QtWidgets.QMessageBox.information(None, "提示", "完成")
except:
traceback.print_exc()
messagebox.showerror(title="错误", message=traceback.format_exc())
QtWidgets.QMessageBox.critical(None, "错误", traceback.format_exc())
sys.exit(2)
if sys.argv[1] == "1":
sys.exit(0)
if not messagebox.askyesno(title="提示", message='''请阅读以下提示然后确定是否继续:
if QtWidgets.QMessageBox.question(None, "提示", '''请阅读以下提示然后确定是否继续:
1、安装后即可使用 adb 连接 UEngine;
2、重置 UEngine 或 adb 就需要重新设置该支持补丁;
3、需要 root 权限;'''):
3、需要 root 权限;''') == QtWidgets.QMessageBox.No:
sys.exit(0)
# 写入(需要 root
if not os.path.exists("/data/uengine/data/data/misc/adb"):
messagebox.showerror(title="错误", message="无法读取 UEngine 数据!")
QtWidgets.QMessageBox.critical(None, "错误", "无法读取 UEngine 数据!")
sys.exit(1)
try:
things = readtxt(sys.argv[2])
@ -74,8 +65,8 @@ try:
if os.path.exists("/data/uengine/data/data/misc/adb/adb_keys"):
old = readtxt("/data/uengine/data/data/misc/adb/adb_keys") + "\n"
write_txt("/data/uengine/data/data/misc/adb/adb_keys", old + "\n".join(adbKey))
messagebox.showinfo(title="提示", message="完成")
QtWidgets.QMessageBox.information(None, "提示", "完成")
except:
traceback.print_exc()
messagebox.showerror(title="错误", message=traceback.format_exc())
QtWidgets.QMessageBox.information(None, "错误", traceback.format_exc())
sys.exit(2)