|
2 | 2 | This application automatically puts the system into hibernation after a specified countdown.''' |
3 | 3 | # pylint: disable = W0718 |
4 | 4 | # pylint: disable = C0103 |
| 5 | +import sys |
5 | 6 | import logging |
6 | 7 | import time |
7 | 8 | import tkinter as tk |
8 | 9 | from tkinter import ttk, messagebox |
9 | 10 | import subprocess |
10 | 11 | import base64 |
11 | | -import logging |
12 | 12 | import os |
13 | 13 | import json |
14 | 14 | from hPyT import maximize_minimize_button # https://pypi.org/project/hPyT/ |
15 | 15 | from modules.b64assets import APP_ICON |
16 | 16 |
|
17 | | -VERSION = "1.10.0" |
18 | | -RELEASE_DATE = "04.07.2025" |
| 17 | +VERSION = "1.11.0" |
| 18 | +RELEASE_DATE = "11.09.2025" |
19 | 19 |
|
20 | 20 | # Global cache |
21 | | -DEBUG_MODE = False |
22 | | -DISABLE_HIBERNATION_CALL = False # No more accidental hibernations durring development lol |
| 21 | +DEV_MODE = True # No more accidental hibernations durring development lol |
| 22 | +LOGGING_LEVEL = "INFO" # INFO, DEBUG, WARNING, ERROR, CRITICAL |
23 | 23 |
|
24 | 24 | FPS_Count_Sum = 0 |
25 | 25 | Keybinds_enabled = True # Set to False to disable keybinds |
26 | | -App_Start_time_DEBUG = time.time() # Start measuring time |
27 | 26 | countdown_terminated = False |
28 | 27 |
|
29 | 28 | # Logger configuration |
30 | 29 | logging.basicConfig( |
31 | | - level=logging.INFO, # INFO, DEBUG, WARNING, ERROR, CRITICAL |
| 30 | + level=getattr(logging, LOGGING_LEVEL), |
32 | 31 | format="%(asctime)s - [%(levelname)s] - %(message)s", |
33 | 32 | handlers=[ |
34 | 33 | #logging.FileHandler("AutoHibernate.log", encoding="utf-8"), |
35 | 34 | logging.StreamHandler() |
36 | 35 | ] |
37 | 36 | ) |
38 | 37 |
|
39 | | -if logging.getLogger().isEnabledFor(logging.DEBUG): |
40 | | - logging.debug("Debug mode is enabled. Debug messages will be logged.") |
41 | | - DEBUG_MODE = True |
| 38 | +if DEV_MODE: |
| 39 | + logging.warning("Development mode is enabled and so Hibernation call is disabled. Please disable it before pushing into production!\n") |
42 | 40 |
|
43 | 41 | # Application settings |
44 | 42 | HIBERNATION_TIME = 10 # Countdown time to hibernation (in seconds) |
45 | | -TARGET_FPS = 20 # Target: 20 FPS (for smoothness) |
| 43 | +TARGET_FPS = 20 # Target: 20 FPS |
46 | 44 | DEFAULT_FONT = ("Arial", 13) # Font used in the application |
47 | 45 | FOOTER_FONT = ("Arial", 8, "italic") # Footer font |
48 | | -BUTTON_FONT = ("Helvetica", 10) |
49 | | -BUTTON_STYLE = "raised" |
50 | | -FRAME_STYLE = "groove" |
| 46 | +BUTTON_FONT = ("Helvetica", 10) # Button font |
| 47 | +BUTTON_STYLE = "raised" # Button style |
| 48 | +FRAME_STYLE = "groove" # Frame style |
| 49 | + |
| 50 | +def parse_arguments(): |
| 51 | + """Check command line arguments for custom hibernation time.""" |
| 52 | + global HIBERNATION_TIME |
| 53 | + args = sys.argv |
| 54 | + if len(args) >= 3 and args[1] in ("/t", "-t", "--time"): |
| 55 | + try: |
| 56 | + custom_time = int(args[2]) |
| 57 | + if custom_time > 0: |
| 58 | + HIBERNATION_TIME = custom_time |
| 59 | + logging.info("Using hibernation time from arguments: %d", HIBERNATION_TIME) |
| 60 | + elif custom_time == 0: |
| 61 | + HIBERNATION_TIME = 0.1 |
| 62 | + logging.warning("Custom time [arg] is 0. Setting hibernation time to minimum of 0.1 second.") |
| 63 | + else: |
| 64 | + logging.warning("Custom time [arg] is less than 0. Using default settings") |
| 65 | + except ValueError: |
| 66 | + logging.error("Invalid argument for time: %s", args[2]) |
51 | 67 |
|
52 | 68 | # Load config: overrides defaults if present, creates config file if missing or invalid |
53 | 69 | def load_config_from_file(): |
@@ -157,9 +173,9 @@ def hibernate_system_call(): |
157 | 173 | '''Function to call system hibernation and handle errors''' |
158 | 174 | time_label.config(text="Hibernating...\n") |
159 | 175 | logging.info("Calling system hibernation") |
160 | | - if DISABLE_HIBERNATION_CALL: |
| 176 | + if DEV_MODE: |
161 | 177 | terminate_countdown() |
162 | | - logging.info("| Hibernation call is disabled (DISABLE_HIBERNATION_CALL=True). Skipping system call. |") |
| 178 | + logging.info("| Hibernation call is disabled (DEV_MODE=True). Skipping system call. |") |
163 | 179 | messagebox.showinfo("Info", "Hibernation is disabled (test mode). The system will not hibernate.") |
164 | 180 | root.destroy() |
165 | 181 | return |
@@ -269,6 +285,7 @@ def load_base64_image(base64_data: str): |
269 | 285 | if current_os() == "Windows": |
270 | 286 | maximize_minimize_button.hide(root) |
271 | 287 | HIBERNATION_TIME, TARGET_FPS, SHOW_DECIMAL_SECONDS = load_config_from_file() |
| 288 | + parse_arguments() |
272 | 289 | root.protocol("WM_DELETE_WINDOW", on_closing) |
273 | 290 |
|
274 | 291 | root.after(100, root.focus_force) # Force focus after a short delay |
@@ -341,7 +358,7 @@ def on_escape(event): # pylint: disable=unused-argument |
341 | 358 |
|
342 | 359 | # Footer with version info |
343 | 360 | version_label = tk.Label( |
344 | | - root, text=f"By @Nieznany237 | Version {VERSION} Released {RELEASE_DATE}", |
| 361 | + root, text=f"Release {VERSION} ({RELEASE_DATE}) | by @Nieznany237", |
345 | 362 | font=FOOTER_FONT, fg="#7E7E7E", anchor="se", justify="right" |
346 | 363 | ) |
347 | 364 | version_label.place(relx=1.0, rely=1.0, anchor="se", x=-8, y=0) |
@@ -369,15 +386,3 @@ def on_escape(event): # pylint: disable=unused-argument |
369 | 386 | countdown(time_label, progress_bar) |
370 | 387 |
|
371 | 388 | root.mainloop() |
372 | | - |
373 | | -# DEBUG |
374 | | -if DEBUG_MODE is True: |
375 | | - App_End_time_DEBUG = time.time() |
376 | | - try: |
377 | | - debug_elapsed_time = App_End_time_DEBUG - App_Start_time_DEBUG # pylint: disable=E0606 |
378 | | - except NameError: |
379 | | - debug_elapsed_time = 0.0 |
380 | | - actual_fps = FPS_Count_Sum / HIBERNATION_TIME |
381 | | - logging.debug("Application runtime: %.4f seconds", debug_elapsed_time) |
382 | | - logging.debug("Average FPS: %.1f", actual_fps) |
383 | | - logging.debug("Total FPS count: %d", FPS_Count_Sum) |
|
0 commit comments