Skip to content

Commit 999cba0

Browse files
authored
Merge pull request #5 from Nieznany237/DEV
1.11.0 Release
2 parents 759e376 + 3012123 commit 999cba0

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

Main.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,68 @@
22
This application automatically puts the system into hibernation after a specified countdown.'''
33
# pylint: disable = W0718
44
# pylint: disable = C0103
5+
import sys
56
import logging
67
import time
78
import tkinter as tk
89
from tkinter import ttk, messagebox
910
import subprocess
1011
import base64
11-
import logging
1212
import os
1313
import json
1414
from hPyT import maximize_minimize_button # https://pypi.org/project/hPyT/
1515
from modules.b64assets import APP_ICON
1616

17-
VERSION = "1.10.0"
18-
RELEASE_DATE = "04.07.2025"
17+
VERSION = "1.11.0"
18+
RELEASE_DATE = "11.09.2025"
1919

2020
# 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
2323

2424
FPS_Count_Sum = 0
2525
Keybinds_enabled = True # Set to False to disable keybinds
26-
App_Start_time_DEBUG = time.time() # Start measuring time
2726
countdown_terminated = False
2827

2928
# Logger configuration
3029
logging.basicConfig(
31-
level=logging.INFO, # INFO, DEBUG, WARNING, ERROR, CRITICAL
30+
level=getattr(logging, LOGGING_LEVEL),
3231
format="%(asctime)s - [%(levelname)s] - %(message)s",
3332
handlers=[
3433
#logging.FileHandler("AutoHibernate.log", encoding="utf-8"),
3534
logging.StreamHandler()
3635
]
3736
)
3837

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")
4240

4341
# Application settings
4442
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
4644
DEFAULT_FONT = ("Arial", 13) # Font used in the application
4745
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])
5167

5268
# Load config: overrides defaults if present, creates config file if missing or invalid
5369
def load_config_from_file():
@@ -157,9 +173,9 @@ def hibernate_system_call():
157173
'''Function to call system hibernation and handle errors'''
158174
time_label.config(text="Hibernating...\n")
159175
logging.info("Calling system hibernation")
160-
if DISABLE_HIBERNATION_CALL:
176+
if DEV_MODE:
161177
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. |")
163179
messagebox.showinfo("Info", "Hibernation is disabled (test mode). The system will not hibernate.")
164180
root.destroy()
165181
return
@@ -269,6 +285,7 @@ def load_base64_image(base64_data: str):
269285
if current_os() == "Windows":
270286
maximize_minimize_button.hide(root)
271287
HIBERNATION_TIME, TARGET_FPS, SHOW_DECIMAL_SECONDS = load_config_from_file()
288+
parse_arguments()
272289
root.protocol("WM_DELETE_WINDOW", on_closing)
273290

274291
root.after(100, root.focus_force) # Force focus after a short delay
@@ -341,7 +358,7 @@ def on_escape(event): # pylint: disable=unused-argument
341358

342359
# Footer with version info
343360
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",
345362
font=FOOTER_FONT, fg="#7E7E7E", anchor="se", justify="right"
346363
)
347364
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
369386
countdown(time_label, progress_bar)
370387

371388
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

Comments
 (0)