diff --git a/src/check_edgechromium.py b/src/check_edgechromium.py new file mode 100644 index 0000000..f25eacd --- /dev/null +++ b/src/check_edgechromium.py @@ -0,0 +1,12 @@ +import tkinter.messagebox +from os import system + +import webview.platforms.winforms + +if webview.platforms.winforms.renderer != "edgechromium": + tkinter.messagebox.showerror("错误", "请使用EdgeChromium渲染器\n关闭此对话框后将启动安装程序") + system(".\\ecwv_installer.exe") + if webview.platforms.winforms._is_chromium(): + webview.platforms.winforms.renderer = "edgechromium" + else: + tkinter.messagebox.showwarning("警告", "EdgeChromium渲染器安装失败或取消\n请手动安装\n接下来将继续运行程序, 能不能跑起来全看天意吧...") \ No newline at end of file diff --git a/WebView2_Runtime_Setup.exe b/src/ecwv_installer.exe similarity index 100% rename from WebView2_Runtime_Setup.exe rename to src/ecwv_installer.exe diff --git a/src/fix_workpath.py b/src/fix_workpath.py new file mode 100644 index 0000000..f48dcc5 --- /dev/null +++ b/src/fix_workpath.py @@ -0,0 +1,7 @@ +import sys +from os import chdir +from os.path import abspath, dirname + +selfdir = dirname(sys.argv[0]) +if selfdir == "": selfdir = abspath(".") +chdir(selfdir) \ No newline at end of file diff --git a/src/gui_launcher.py b/src/gui_launcher.py index 78005d1..6eb1e24 100644 --- a/src/gui_launcher.py +++ b/src/gui_launcher.py @@ -1,10 +1,12 @@ +import fix_workpath as _ + import ctypes from tkinter import Tk, Label, BooleanVar, StringVar from tkinter.ttk import Entry, Button, Checkbutton, LabelFrame from tkinter.filedialog import askopenfilename from tkinter.messagebox import showerror -from os import chdir,popen -from os.path import exists,isfile,dirname +from os import popen +from os.path import exists, isfile from sys import argv import gui_const @@ -12,10 +14,6 @@ console_window.Hide() -selfdir = dirname(argv[0]) -if selfdir == "": selfdir = "." -chdir(selfdir) - if exists("./main.py"): target_path = "./main.py" elif exists("./main.exe"): diff --git a/src/main.py b/src/main.py index 052dd2c..1741e81 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,7 @@ import err_processer as _ import init_logging as _ +import fix_workpath as _ +import check_edgechromium as _ import json import sys @@ -7,8 +9,8 @@ import logging from threading import Thread from ctypes import windll -from os import chdir, listdir, popen, environ; environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "" -from os.path import exists, abspath, dirname, isfile, isdir +from os import listdir, popen, environ; environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "" +from os.path import exists, isfile, isdir from shutil import rmtree from tempfile import gettempdir from ntpath import basename @@ -31,10 +33,6 @@ import ppr_help from phicore import * -selfdir = dirname(sys.argv[0]) -if selfdir == "": selfdir = abspath(".") -chdir(selfdir) - if not exists("./7z.exe") or not exists("./7z.dll"): logging.fatal("7z.exe or 7z.dll Not Found") windll.kernel32.ExitProcess(1) diff --git a/src/phigros.py b/src/phigros.py index 033b4ff..802f1bc 100644 --- a/src/phigros.py +++ b/src/phigros.py @@ -1,5 +1,7 @@ import err_processer as _ import init_logging as _ +import fix_workpath as _ +import check_edgechromium as _ import webbrowser import typing @@ -11,8 +13,8 @@ import logging from threading import Thread from ctypes import windll -from os import chdir, environ, mkdir, system, popen, listdir; environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "" -from os.path import exists, abspath, dirname +from os import environ, mkdir, system, listdir; environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "" +from os.path import exists from shutil import rmtree from tempfile import gettempdir @@ -31,10 +33,6 @@ import chartfuncs_rpe import playsound -selfdir = dirname(sys.argv[0]) -if selfdir == "": selfdir = abspath(".") -chdir(selfdir) - if not exists("./7z.exe") or not exists("./7z.dll"): logging.fatal("7z.exe or 7z.dll Not Found") windll.kernel32.ExitProcess(1) diff --git a/src/tool-compile.py b/src/tool-compile.py index 69e456c..3c60b83 100644 --- a/src/tool-compile.py +++ b/src/tool-compile.py @@ -20,8 +20,8 @@ def compile(file:str, hideconsole:bool): debug = "--debug" in argv compile_files = [ ("main.py", False), - ("GUI_Launcher.py", False), - ("Phigros.py", False) + ("gui_launcher.py", False), + ("phigros.py", False) ] extend = open("_compile_pyiextend.py", "r", encoding="utf-8").read() @@ -33,7 +33,7 @@ def compile(file:str, hideconsole:bool): system(f"{py} -m pip install pyinstaller") pyinstaller = ".\\compile_venv\\Scripts\\pyinstaller.exe" pyi_makespec = ".\\compile_venv\\Scripts\\pyi-makespec.exe" -ts:list[Thread] = [] +ts: list[Thread] = [] for file, hideconsole in compile_files: ts.append(Thread(target=compile, args=(file, hideconsole))) diff --git a/src/tool-createAutoplayOneFingerVideo.py b/src/tool-createAutoplayOneFingerVideo.py index d0df2f7..dd1e70f 100644 --- a/src/tool-createAutoplayOneFingerVideo.py +++ b/src/tool-createAutoplayOneFingerVideo.py @@ -1,6 +1,6 @@ +import fix_workpath as _ + import json -from os import chdir -from os.path import dirname, abspath from sys import argv from random import uniform @@ -120,9 +120,6 @@ def gfingerp(sec: float) -> tuple[float, float]: fps = videoCap.get(cv2.CAP_PROP_FPS) optWriter = cv2.VideoWriter(outputVideoFilePath, cv2.VideoWriter.fourcc(*'mp4v'), fps, (w, h), True) -selfdir = dirname(argv[0]) -if selfdir == "": selfdir = abspath(".") -chdir(selfdir) finger = Image.open("./resources/finger.png") finger = finger.resize((int(w * 0.4), int(w * 0.4 / finger.width * finger.height))) diff --git a/src/webcv.py b/src/webcv.py index c8cfb69..70d439b 100644 --- a/src/webcv.py +++ b/src/webcv.py @@ -1,23 +1,19 @@ from __future__ import annotations +import fix_workpath as _ + import threading import typing import http.server import io import time from ctypes import windll -from os import chdir -from os.path import abspath, dirname -from sys import argv +from os.path import abspath from random import randint import webview from PIL import Image -selfdir = dirname(argv[0]) -if selfdir == "": selfdir = abspath(".") -chdir(selfdir) - current_thread = threading.current_thread screen_width = windll.user32.GetSystemMetrics(0) screen_height = windll.user32.GetSystemMetrics(1)