Skip to content

Commit 1fc58c9

Browse files
committed
Read version and display on config. window
Try to run python code with local interpreter: useful when working with venvs
1 parent a2be03c commit 1fc58c9

File tree

4 files changed

+56
-33
lines changed

4 files changed

+56
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,5 @@ dmypy.json
140140
screencap.png
141141
tmp
142142

143+
version.txt
143144
external/LibreHardwareMonitor/LibreHardwareMonitorLib.sys

configure.py

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@
163163

164164
MAIN_DIRECTORY = Path(__file__).resolve().parent
165165
THEMES_DIR = MAIN_DIRECTORY / "res/themes"
166+
VERSION_FILE = MAIN_DIRECTORY / "version.txt"
166167

167168
circular_mask = Image.open(MAIN_DIRECTORY / "res/backgrounds/circular-mask.png")
169+
DISABLED_COLOR = "#C0C0C0"
168170

169171

170172
def get_theme_data(name: str):
@@ -323,6 +325,17 @@ def __init__(self):
323325
"Fans missing from the list? Install lm-sensors package\n"
324326
"and run 'sudo sensors-detect' command, then reboot.")
325327

328+
try:
329+
version = open(VERSION_FILE).readline()
330+
except:
331+
try:
332+
version = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8')
333+
except:
334+
version = "0.0.0"
335+
336+
version_label = ttk.Label(self.window, text=version, foreground=DISABLED_COLOR)
337+
version_label.place(x=5, y=550)
338+
326339
self.weather_ping_btn = ttk.Button(self.window, text="Weather & ping",
327340
command=lambda: self.on_weatherping_click())
328341
self.weather_ping_btn.place(x=80, y=520, height=50, width=130)
@@ -510,13 +523,6 @@ def on_weatherping_click(self):
510523
self.more_config_window.show()
511524

512525
def on_open_theme_folder_click(self):
513-
# path = f'"{MAIN_DIRECTORY}res/themes"'
514-
# if platform.system() == "Windows":
515-
# os.startfile(path)
516-
# elif platform.system() == "Darwin":
517-
# subprocess.Popen(["open", path])
518-
# else:
519-
# subprocess.Popen(["xdg-open", path])
520526
path = MAIN_DIRECTORY / "res/themes"
521527

522528
if platform.system() == "Windows":
@@ -527,24 +533,35 @@ def on_open_theme_folder_click(self):
527533
subprocess.Popen(["xdg-open", str(path)])
528534

529535
def on_theme_editor_click(self):
530-
theme_editor = next(MAIN_DIRECTORY.glob("theme-editor.*"))
531-
532-
if platform.system() == "Windows":
533-
subprocess.Popen([str(theme_editor), self.theme_cb.get()], shell=True)
534-
else:
535-
subprocess.Popen([str(theme_editor), self.theme_cb.get()])
536+
try:
537+
# Load Python file with local python interpreter (useful for venvs)
538+
theme_editor = next(MAIN_DIRECTORY.glob("theme-editor.py"))
539+
subprocess.Popen([sys.executable, str(theme_editor), self.theme_cb.get()])
540+
except:
541+
# Load binary (for releases) or Python file with system interpreter
542+
theme_editor = next(MAIN_DIRECTORY.glob("theme-editor*"))
543+
if platform.system() == "Windows":
544+
subprocess.Popen([str(theme_editor), self.theme_cb.get()], shell=True)
545+
else:
546+
subprocess.Popen([str(theme_editor), self.theme_cb.get()])
536547

537548
def on_save_click(self):
538549
self.save_config_values()
539550

540551
def on_saverun_click(self):
541552
self.save_config_values()
542-
main_file = next(MAIN_DIRECTORY.glob("main.*"))
543553

544-
if platform.system() == "Windows":
545-
subprocess.Popen([str(main_file)], shell=True)
546-
else:
547-
subprocess.Popen([str(main_file)])
554+
try:
555+
# Load Python file with local python interpreter (useful for venvs)
556+
main_file = next(MAIN_DIRECTORY.glob("main.py"))
557+
subprocess.Popen([sys.executable, str(main_file)])
558+
except:
559+
# Load binary (for releases) or Python file with system interpreter
560+
main_file = next(MAIN_DIRECTORY.glob("main*"))
561+
if platform.system() == "Windows":
562+
subprocess.Popen([str(main_file)], shell=True)
563+
else:
564+
subprocess.Popen([str(main_file)])
548565

549566
self.window.destroy()
550567

@@ -556,10 +573,10 @@ def on_model_change(self, e=None):
556573
self.show_hide_brightness_warning()
557574
model = self.model_cb.get()
558575
if model == SIMULATED_MODEL:
559-
self.com_cb.configure(state="disabled", foreground="#C0C0C0")
560-
self.orient_cb.configure(state="disabled", foreground="#C0C0C0")
576+
self.com_cb.configure(state="disabled", foreground=DISABLED_COLOR)
577+
self.orient_cb.configure(state="disabled", foreground=DISABLED_COLOR)
561578
self.brightness_slider.configure(state="disabled")
562-
self.brightness_val_label.configure(foreground="#C0C0C0")
579+
self.brightness_val_label.configure(foreground=DISABLED_COLOR)
563580
else:
564581
self.com_cb.configure(state="readonly", foreground="#000")
565582
self.orient_cb.configure(state="readonly", foreground="#000")
@@ -591,8 +608,8 @@ def on_size_change(self, e=None):
591608
def on_hwlib_change(self, e=None):
592609
hwlib = [k for k, v in hw_lib_map.items() if v == self.hwlib_cb.get()][0]
593610
if hwlib == "STUB" or hwlib == "STATIC":
594-
self.eth_cb.configure(state="disabled", foreground="#C0C0C0")
595-
self.wl_cb.configure(state="disabled", foreground="#C0C0C0")
611+
self.eth_cb.configure(state="disabled", foreground=DISABLED_COLOR)
612+
self.wl_cb.configure(state="disabled", foreground=DISABLED_COLOR)
596613
else:
597614
self.eth_cb.configure(state="readonly", foreground="#000")
598615
self.wl_cb.configure(state="readonly", foreground="#000")

library/pythoncheck.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@
2424

2525
# Oldest / newest version supported
2626
MIN_PYTHON = (3, 9)
27-
MAX_PYTHON = (3, 14)
2827
# For Windows: max Python 3.13 until PythonNet support for 3.14
2928
MAX_PYTHON_WINDOWS = (3, 13)
29+
MAX_PYTHON_OTHERS = (3, 14)
30+
MAX_PYTHON = MAX_PYTHON_WINDOWS if sys.platform == "win32" else MAX_PYTHON_OTHERS
3031

3132

3233
def check_python_version():
3334
current_version = sys.version_info[:2]
34-
platform = sys.platform
3535

36-
if current_version < MIN_PYTHON or (platform == "win32" and current_version > MAX_PYTHON_WINDOWS) or (
37-
platform != "win32" and current_version > MAX_PYTHON):
36+
if current_version < MIN_PYTHON or current_version > MAX_PYTHON:
3837
print(f"[ERROR] Python {current_version[0]}.{current_version[1]} is not supported by this program. "
39-
f"Python {MIN_PYTHON[0]}.{MIN_PYTHON[1]}-{MAX_PYTHON[0]}.{MAX_PYTHON[1]} required on platform {platform}.")
38+
f"Python {MIN_PYTHON[0]}.{MIN_PYTHON[1]}-{MAX_PYTHON[0]}.{MAX_PYTHON[1]} required on platform {sys.platform}.")
4039
try:
4140
sys.exit(0)
4241
except:

main.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,18 @@ def on_signal_caught(signum, frame=None):
116116
def on_configure_tray(tray_icon, item):
117117
logger.info("Configure from tray icon")
118118

119-
configure_file = next(MAIN_DIRECTORY.glob("configure.*"))
119+
try:
120+
# Load Python file with local python interpreter (useful for venvs)
121+
configure_file = next(MAIN_DIRECTORY.glob("configure.py"))
122+
subprocess.Popen([sys.executable, str(configure_file)])
123+
except:
124+
# Load binary (for releases) or Python file with system interpreter
125+
configure_file = next(MAIN_DIRECTORY.glob("configure*"))
126+
if platform.system() == "Windows":
127+
subprocess.Popen([str(configure_file)], shell=True)
128+
else:
129+
subprocess.Popen([str(configure_file)])
120130

121-
if platform.system() == "Windows":
122-
subprocess.Popen([str(configure_file)], shell=True)
123-
else:
124-
subprocess.Popen([str(configure_file)])
125131
clean_stop(tray_icon)
126132

127133
def on_exit_tray(tray_icon, item):

0 commit comments

Comments
 (0)