-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched to PyInstaller, UAC request without tricks, changed logging …
…settings, improved error handling, easy refactoring and new icon
- Loading branch information
1 parent
005f0c3
commit 7092ea4
Showing
20 changed files
with
221 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,14 @@ | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
import pyvan | ||
from genexe.generate_exe import generate_exe | ||
from pyvan import HEADER_NO_CONSOLE | ||
|
||
OPTIONS = { | ||
"main_file_name": "../process-governor.py", | ||
"show_console": False, | ||
"use_existing_requirements": True, | ||
"extra_pip_install_args": [], | ||
"python_version": None, | ||
"use_pipreqs": False, | ||
"install_only_these_modules": [], | ||
"exclude_modules": [], | ||
"include_modules": [], | ||
"path_to_get_pip_and_python_embedded_zip": "downloads_for_van", | ||
"build_dir": "dist", | ||
"pydist_sub_dir": "pydist", | ||
"source_sub_dir": "src", | ||
"icon_file": "src/resource/favicon.ico", | ||
"input_dir": "src" | ||
} | ||
|
||
original = pyvan.make_startup_exe | ||
|
||
|
||
def make_startup_exe(main_file_name, show_console, build_dir, relative_pydist_dir, relative_source_dir, icon_file=None): | ||
""" Make the startup exe file needed to run the script """ | ||
print("Making startup exe file") | ||
|
||
exe_fname = os.path.join(build_dir, os.path.splitext(os.path.basename(main_file_name))[0] + ".exe") | ||
python_entrypoint = "python.exe" | ||
command_str = f"{{EXE_DIR}}\\{relative_pydist_dir}\\{python_entrypoint} {{EXE_DIR}}\\{relative_source_dir}\\{main_file_name}" | ||
|
||
generate_exe( | ||
target=Path(exe_fname), | ||
command=command_str, | ||
icon_file=None if icon_file is None else Path(icon_file), | ||
show_console=show_console | ||
) | ||
|
||
main_file_name = os.path.join(build_dir, main_file_name) | ||
|
||
if not show_console: | ||
with open(main_file_name, "r", encoding="utf8", errors="surrogateescape") as f: | ||
main_content = f.read() | ||
if HEADER_NO_CONSOLE not in main_content: | ||
with open(main_file_name, "w", encoding="utf8", errors="surrogateescape") as f: | ||
f.write(str(HEADER_NO_CONSOLE + main_content)) | ||
|
||
shutil.copy(main_file_name, build_dir) | ||
|
||
print("Done!") | ||
|
||
|
||
pyvan.make_startup_exe = make_startup_exe | ||
|
||
pyvan.build(**OPTIONS) | ||
import PyInstaller.__main__ | ||
|
||
PyInstaller.__main__.run([ | ||
'process-governor.py', | ||
'--noconfirm', | ||
'--onedir', | ||
'--uac-admin', | ||
'--hide-console', 'hide-early', | ||
'--add-data', './resources/*;./resources', | ||
'--contents-directory', 'scripts', | ||
'--icon', 'resources/app.ico', | ||
'--name', 'Process Governor', | ||
'--debug', 'noarchive', | ||
]) |
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
import sys, os | ||
if sys.executable.endswith('pythonw.exe'): | ||
sys.stdout = open(os.devnull, 'w') | ||
sys.stderr = open(os.path.join(os.getenv('TEMP'), 'stderr-{}'.format(os.path.basename(sys.argv[0]))), "w") | ||
|
||
import platform | ||
import sys | ||
|
||
import pyuac | ||
from util import pyuac_fix | ||
from util.lock_instance import create_lock_file, remove_lock_file | ||
|
||
from main_loop import start_app | ||
from util.lock_instance import create_lock_file, remove_lock_file | ||
from util.messages import message_box, MBIcon | ||
|
||
if __name__ == "__main__": | ||
if not platform.system() == "Windows": | ||
print("Process Governor is intended to run on Windows only.") | ||
sys.exit(1) | ||
|
||
if not pyuac.isUserAdmin(): | ||
pyuac_fix.runAsAdmin(wait=False, showCmd=False) | ||
else: | ||
create_lock_file() | ||
try: | ||
start_app() | ||
finally: | ||
remove_lock_file() | ||
message_box( | ||
"Process Governor", | ||
"This program requires administrator privileges to run.\n" | ||
"Please run the program as an administrator to ensure proper functionality.", | ||
MBIcon.INFORMATION | ||
) | ||
sys.exit(1) | ||
|
||
create_lock_file() | ||
try: | ||
start_app() | ||
finally: | ||
remove_lock_file() |
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
import os | ||
import sys | ||
|
||
|
||
def get_root(): | ||
if getattr(sys, 'frozen', False): | ||
application_path = sys._MEIPASS | ||
else: | ||
application_path = os.getcwd() | ||
|
||
return application_path | ||
|
||
|
||
def get_tray_icon() -> str: | ||
""" | ||
Get the path to the tray icon file. | ||
This function checks if the icon file "favicon.ico" exists in the "resource" directory. If it exists, the | ||
full path to the icon file is returned. If not found, it returns the path relative to the "src" directory. | ||
Returns: | ||
str: The path to the tray icon file. | ||
""" | ||
icon_name = "resource/favicon.ico" | ||
|
||
if os.path.isfile(icon_name): | ||
return icon_name | ||
|
||
return f"src/{icon_name}" | ||
return f"{get_root()}/resources/app.ico" |
Oops, something went wrong.