From 89129fc6e5899b24da4d39be81ae849eddc724a9 Mon Sep 17 00:00:00 2001 From: Dunestorm Date: Mon, 10 Feb 2025 20:13:22 +0000 Subject: [PATCH] LiquidGUI [1.3.0.0] - Continued refactoring. --- .vscode/launch.json | 10 +++- .../liquidctl_helper_interface.py | 0 interfaces/vitals_helper_interface.py | 8 +++ liquidctl_helper_linux.py | 6 +- liquidctl_helper_windows.py | 6 +- main.pyw | 55 ++++++++++--------- vitals_helper.py | 33 +++++------ 7 files changed, 67 insertions(+), 51 deletions(-) rename liquidctl_helper_interface.py => interfaces/liquidctl_helper_interface.py (100%) create mode 100644 interfaces/vitals_helper_interface.py diff --git a/.vscode/launch.json b/.vscode/launch.json index 306f58e..b6b9d5f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,9 +4,17 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "Python: LiquidCTL", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/main.pyw", + "console": "integratedTerminal", + "justMyCode": true + }, { "name": "Python: Current File", - "type": "python", + "type": "debugpy", "request": "launch", "program": "${file}", "console": "integratedTerminal", diff --git a/liquidctl_helper_interface.py b/interfaces/liquidctl_helper_interface.py similarity index 100% rename from liquidctl_helper_interface.py rename to interfaces/liquidctl_helper_interface.py diff --git a/interfaces/vitals_helper_interface.py b/interfaces/vitals_helper_interface.py new file mode 100644 index 0000000..32cf18e --- /dev/null +++ b/interfaces/vitals_helper_interface.py @@ -0,0 +1,8 @@ +from abc import ABC, abstractmethod + + +class VitalsHelperInterface(ABC): + @abstractmethod + def get_temps(self, HWSensor): + """ Return Temperatures """ + pass \ No newline at end of file diff --git a/liquidctl_helper_linux.py b/liquidctl_helper_linux.py index da538c6..ea52625 100644 --- a/liquidctl_helper_linux.py +++ b/liquidctl_helper_linux.py @@ -1,13 +1,13 @@ +from interfaces.liquidctl_helper_interface import LiquidCTL_Helper_Interface import subprocess import re -from liquidctl_helper_interface import LiquidCTL_Helper_Interface class LiquidCTL_Helper(LiquidCTL_Helper_Interface): - device_name: str = "" + device_name = str() device_temp = 0 device_fanSpeed = 0 device_pumpSpeed = 0 - device_fwVers = None + device_fwVers = str() devices = None diff --git a/liquidctl_helper_windows.py b/liquidctl_helper_windows.py index 5f0b5c5..010f832 100644 --- a/liquidctl_helper_windows.py +++ b/liquidctl_helper_windows.py @@ -1,12 +1,12 @@ +from interfaces.liquidctl_helper_interface import LiquidCTL_Helper_Interface from liquidctl import find_liquidctl_devices, cli # type: ignore -from liquidctl_helper_interface import LiquidCTL_Helper_Interface class LiquidCTL_Helper(LiquidCTL_Helper_Interface): - device_name = None + device_name = str() device_temp = 0 device_fanSpeed = 0 device_pumpSpeed = 0 - device_fwVers = None + device_fwVers = str() devices = find_liquidctl_devices() try: diff --git a/main.pyw b/main.pyw index 017cfb6..cbd4f9b 100644 --- a/main.pyw +++ b/main.pyw @@ -16,17 +16,15 @@ import common from MessageHandler import MessageHandler ## Platform Imports ######################################### import globals -from vitals_helper import Component from styles import Labels if globals.os == "Windows": from liquidctl_helper_windows import LiquidCTL_Helper - from vitals_helper import VitalsHelperWindows as svh + from vitals_helper import VitalsHelperWindows as VitalsHelper import win32mica # type: ignore import darkdetect # type: ignore elif globals.os == "Linux": from liquidctl_helper_linux import LiquidCTL_Helper - from vitals_helper import VitalsHelperLinux as svh - + from vitals_helper import VitalsHelperLinux as VitalsHelper class MainWindow(QMainWindow): @@ -37,13 +35,13 @@ class MainWindow(QMainWindow): self.setWindowTitle("LiquidGUI (v.1.3.0.0) DEV") self.setFixedSize(450, 700) - self.lctl = lctl - self.svh = svh() + self._lctl = lctl + self.__vitals_helper = VitalsHelper() # Widgets ########################################## self.lbl_device_name = Labels.MainLabel() - self.lbl_cpu_temp = Labels.SubLabel(value="🔳 CPU Temp:") + self.lbl_cpu_temp = Labels.SubLabel(value="💻 CPU Temp:") self.min_max_cur_cpu_temp = common.MinMaxCurrent() self.prg_cpu_temp = QProgressBar(textVisible=False, minimum=0, @@ -101,12 +99,12 @@ class MainWindow(QMainWindow): self.setCentralWidget(widget) self.setContentsMargins(20, 20, 20, 20) - # Threading ####################################### + # Threading ####################################################################### self.thread_manager = QThreadPool() self.timer = QTimer() self.timer.setInterval(1000) - self.timer.timeout.connect(lambda: self.thread_manager.start(self.lctl.Update)) + self.timer.timeout.connect(lambda: self.thread_manager.start(self._lctl.Update)) self.timer.timeout.connect(self.update_widgets) self.timer.start() @@ -122,39 +120,46 @@ class MainWindow(QMainWindow): def update_widgets(self): """ Update widgets using LiquidCTL library.""" - self.lbl_value_prg_cpu_temp.setText( - self.min_max_cur_cpu_temp.builder( - self.svh.get_temps(Component.lin_cpu_amd), "°C")) - - self.prg_cpu_temp.setValue( - self.svh.get_temps(Component.lin_cpu_amd)) + # Platform Specific Widgets ####################################################### + if globals.platform == "Windows": + self.__vitals_helper() + elif globals.platform == "Linux": + self.lbl_value_prg_cpu_temp.setText( + self.min_max_cur_cpu_temp.builder( + self.__vitals_helper.get_temps( + self.__vitals_helper.Component.lin_cpu_amd), "°C")) + self.prg_cpu_temp.setValue( + self.__vitals_helper.get_temps( + self.__vitals_helper.Component.lin_cpu_amd)) + + # Cross Platform Widgets ########################################################## self.lbl_device_name.setText( - self.lctl.device_name) + self._lctl.device_name) self.prg_temp.setValue( - self.lctl.device_temp) + self._lctl.device_temp) self.lbl_value_prg_temp.setText( self.min_max_cur_temp.builder( - self.lctl.device_temp, "°C")) + self._lctl.device_temp, "°C")) self.prg_fanspeed.setValue( - self.lctl.device_fanSpeed) + self._lctl.device_fanSpeed) self.lbl_value_prg_fanspeed.setText( self.min_max_cur_fanspeed.builder( - self.lctl.device_fanSpeed, " rpm")) + self._lctl.device_fanSpeed, " rpm")) self.prg_pumpspeed.setValue( - self.lctl.device_pumpSpeed) + self._lctl.device_pumpSpeed) self.lbl_value_prg_pumpspeed.setText( self.min_max_cur_pumpspeed.builder( - self.lctl.device_pumpSpeed, " rpm")) + self._lctl.device_pumpSpeed, " rpm")) - if self.lctl.device_fwVers is not None: - self.lbl_fwvers.setText(f"Firmware: v{self.lctl.device_fwVers}") + if self._lctl.device_fwVers is not None: + self.lbl_fwvers.setText(f"Firmware: v{self._lctl.device_fwVers}") def main(): @@ -178,7 +183,7 @@ def main(): app.setWindowIcon(icon) # Show error and quit app if no devices are found - if window.lctl.TestConnectionState(): + if window._lctl.TestConnectionState(): MessageHandler().ShowNoDevicesFoundError() sys.exit(1) else: diff --git a/vitals_helper.py b/vitals_helper.py index 03867b4..215473f 100644 --- a/vitals_helper.py +++ b/vitals_helper.py @@ -1,33 +1,28 @@ +from interfaces.vitals_helper_interface import VitalsHelperInterface from enum import Enum -from abc import ABC, abstractmethod import psutil -import pythonnet -import os -class Component(Enum): - lin_cpu_amd = ("k10temp", "Tctl") - lin_gpu_amd = ("amdgpu", "edge") - lin_mobo_asus = ("asus_wmi_sensors", "Motherboard Temperature") - - -class VitalsHelperInterface(ABC): - @abstractmethod - def get_temps(self, component: Component): - """ Return Temperatures """ - pass class VitalsHelperLinux(VitalsHelperInterface): - def get_temps(self, component: Component): + class HWSensor(Enum): + lin_cpu_amd = ("k10temp", "Tctl") + lin_gpu_amd = ("amdgpu", "edge") + lin_mobo_asus = ("asus_wmi_sensors", "Motherboard Temperature") + + def get_temps(self, _hw_sensor: HWSensor): temps = psutil.sensors_temperatures() - if component.value[0] in temps: - for entry in temps[component.value[0]]: - if entry.label == component.value[1]: + if _hw_sensor.value[0] in temps: + for entry in temps[_hw_sensor.value[0]]: + if entry.label == _hw_sensor.value[1]: return round(entry.current, 2) class VitalsHelperWindows(VitalsHelperInterface): def __init__(self): print(f"{self.__class__.__name__} is not Implemented") + + class HWSensor(Enum): + pass - def get_temps(self, component: Component): + def get_temps(self, _hw_sensor: HWSensor): return 0 \ No newline at end of file