From 495de03e39c798afacaec25e56e553d23281e73a Mon Sep 17 00:00:00 2001 From: Dunestorm Date: Sun, 7 Jul 2024 16:41:50 +0100 Subject: [PATCH 1/4] LiquidGUI [1.1.0.0] Dev - Initial Linux support. --- LiquidCTL_Helper.py | 37 +++++++++++++++++-------------- MessageHandler.py | 2 +- main.pyw | 49 ++++++++++++++++++++++------------------- resources.py | 2 +- styles/SubLabel.py | 4 ++-- styles/SubLabelValue.py | 6 ++--- 6 files changed, 53 insertions(+), 47 deletions(-) diff --git a/LiquidCTL_Helper.py b/LiquidCTL_Helper.py index 1e6cbe1..784d0fa 100644 --- a/LiquidCTL_Helper.py +++ b/LiquidCTL_Helper.py @@ -1,11 +1,12 @@ from liquidctl import find_liquidctl_devices, cli class LiquidCTL_Helper(): - device_name = None - device_temp = 0 - device_fanSpeed = 0 - device_pumpSpeed = 0 - device_fwVers = None + device_name = None + device_temp = 0 + device_fanSpeed = 0 + device_pumpSpeed = 0 + device_fwVers = None + device_connect_error = False devices = find_liquidctl_devices() try: @@ -14,8 +15,9 @@ class LiquidCTL_Helper(): #print(f'{dev.description}') device_name = dev.description device_fwVers = ''.join(map(str, dev.firmware_version)) - except: - pass + except OSError: + print("ERROR: Connecting to LiquidCTL device!") + device_connect_error = True def ForceInit(self): init_status = self.dev.initialize() @@ -31,16 +33,17 @@ class LiquidCTL_Helper(): return True def Update(self): - with self.dev.connect(): - status = self.dev.get_status() - for key, value, unit in status: - #print(f'- {key}: {value} {unit}') - if key == "Liquid temperature": - self.device_temp = value - elif key == "Fan speed": - self.device_fanSpeed = value - elif key == "Pump speed": - self.device_pumpSpeed = value + if self.device_connect_error == False: + with self.dev.connect(): + status = self.dev.get_status() + for key, value, unit in status: + #print(f'- {key}: {value} {unit}') + if key == "Liquid temperature": + self.device_temp = value + elif key == "Fan speed": + self.device_fanSpeed = value + elif key == "Pump speed": + self.device_pumpSpeed = value def SetFanSpeed(self, speed): with self.dev.connect(): diff --git a/MessageHandler.py b/MessageHandler.py index f52223b..dbedfd2 100644 --- a/MessageHandler.py +++ b/MessageHandler.py @@ -1,4 +1,4 @@ -from PySide6.QtWidgets import QMessageBox +from PyQt6.QtWidgets import QMessageBox @staticmethod class MessageHandler(): diff --git a/main.pyw b/main.pyw index 737cc99..50bafe8 100644 --- a/main.pyw +++ b/main.pyw @@ -1,24 +1,22 @@ import sys -import win32mica -from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel, QProgressBar -from PySide6.QtCore import Qt, QTimer, QThreadPool -from PySide6.QtGui import QFont, QIcon +from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel, QProgressBar +from PyQt6.QtCore import Qt, QTimer, QThreadPool +from PyQt6.QtGui import QFont, QIcon from LiquidCTL_Helper import LiquidCTL_Helper from MessageHandler import MessageHandler -import resources, pkg_resources.extern +import resources from styles.SubLabel import SubLabel from styles.SubLabelValue import SubLabelValue - class MainWindow(QMainWindow): """ Main application window. """ - def __init__(self, lctl): + def __init__(self): super(MainWindow, self).__init__() - self.setWindowTitle("LiquidGUI (v.1.0.3.2)") + self.setWindowTitle("LiquidGUI (v.1.1.0.0)") self.setFixedSize(450, 385) - self.lctl = lctl + self.lctl = LiquidCTL_Helper() # Widgets ########################################## self.lbl_device_name = QLabel(font=QFont("Calibre", @@ -62,7 +60,6 @@ class MainWindow(QMainWindow): layout.addWidget(self.lbl_fwvers) layout.setSpacing(10) - self.setLayout(layout) self.setCentralWidget(widget) self.setContentsMargins(20, 20, 20, 20) @@ -77,15 +74,16 @@ class MainWindow(QMainWindow): def update_widgets(self): """ Update widgets using LiquidCTL library.""" - self.lbl_device_name.setText("- " + self.lctl.device_name + " -") - self.prg_temp.setValue(self.lctl.device_temp) - self.lbl_value_prg_temp.setText(str(self.lctl.device_temp) + "°C") - self.prg_fanspeed.setValue(self.lctl.device_fanSpeed) - self.lbl_value_prg_fanspeed.setText(str(self.lctl.device_fanSpeed) + " rpm") - self.prg_pumpspeed.setValue(self.lctl.device_pumpSpeed) - self.lbl_value_prg_pumpspeed.setText(str(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_name != None: + self.lbl_device_name.setText("- " + self.lctl.device_name + " -") + self.prg_temp.setValue(int(self.lctl.device_temp)) + self.lbl_value_prg_temp.setText(str(self.lctl.device_temp) + "°C") + self.prg_fanspeed.setValue(self.lctl.device_fanSpeed) + self.lbl_value_prg_fanspeed.setText(str(self.lctl.device_fanSpeed) + " rpm") + self.prg_pumpspeed.setValue(self.lctl.device_pumpSpeed) + self.lbl_value_prg_pumpspeed.setText(str(self.lctl.device_pumpSpeed) + " rpm") + if self.lctl.device_fwVers is not None: + self.lbl_fwvers.setText(f"Firmware: v{self.lctl.device_fwVers}") def main(): @@ -94,18 +92,23 @@ def main(): icon = QIcon(":/icons/LiquidGUI.ico") app.setWindowIcon(icon) - window = MainWindow(LiquidCTL_Helper()) + window = MainWindow() window.setWindowIcon(icon) - window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) - + # Show error and quit app if no devices are found if window.lctl.TestConnectionState(): MessageHandler().ShowNoDevicesFoundError() sys.exit(1) else: - win32mica.ApplyMica(window.winId(), win32mica.MICAMODE.DARK) + try: + import win32mica + win32mica.ApplyMica(window.winId(), win32mica.MICAMODE.DARK) + window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + except ImportError as e: + print(f"ERROR: Unable to import {e.name}") window.show() + app.setStyle("Breeze") app.exec() diff --git a/resources.py b/resources.py index 19cdb4d..f204151 100644 --- a/resources.py +++ b/resources.py @@ -3,7 +3,7 @@ # Created by: The Resource Compiler for Qt version 6.7.2 # WARNING! All changes made in this file will be lost! -from PySide6 import QtCore +from PyQt6 import QtCore qt_resource_data = b"\ \x00\x00\xa2\x14\ diff --git a/styles/SubLabel.py b/styles/SubLabel.py index f2ce70d..d2f00f8 100644 --- a/styles/SubLabel.py +++ b/styles/SubLabel.py @@ -1,5 +1,5 @@ -from PySide6.QtWidgets import QLabel -from PySide6.QtGui import QFont +from PyQt6.QtWidgets import QLabel +from PyQt6.QtGui import QFont class SubLabel(QLabel): """ Formatting for sub-labels. """ diff --git a/styles/SubLabelValue.py b/styles/SubLabelValue.py index 1a4a236..9e73d19 100644 --- a/styles/SubLabelValue.py +++ b/styles/SubLabelValue.py @@ -1,6 +1,6 @@ -from PySide6.QtWidgets import QLabel -from PySide6.QtGui import QFont -from PySide6.QtCore import Qt +from PyQt6.QtWidgets import QLabel +from PyQt6.QtGui import QFont +from PyQt6.QtCore import Qt class SubLabelValue(QLabel): """ Formatting for values. """ From aed37b7fae4940d7e8e9c8e14c3b3043fe505e2b Mon Sep 17 00:00:00 2001 From: Dunestorm Date: Mon, 8 Jul 2024 23:25:29 +0100 Subject: [PATCH 2/4] LiquidGUI [1.1.0.0] Dev - Added build script for Linux. --- .vscode/launch.json | 5 +++-- .vscode/tasks.json | 13 ++++++++----- build.sh | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100755 build.sh diff --git a/.vscode/launch.json b/.vscode/launch.json index 306f58e..540f0b6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,11 +6,12 @@ "configurations": [ { "name": "Python: Current File", - "type": "python", + "type": "debugpy", "request": "launch", "program": "${file}", "console": "integratedTerminal", - "justMyCode": true + "justMyCode": true, + "sudo": true } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1c59d37..e88e9ab 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,13 +4,16 @@ "version": "2.0.0", "tasks": [ { - "label": "Build", + "label": "Windows Build", "type": "shell", "command": "cmd.exe /c build.bat", - "group": { - "kind": "build", - "isDefault": true - } + "group": "build" + }, + { + "label": "Linux Build", + "type": "shell", + "command": "${workspaceFolder}/build.sh", + "group": "build" } ] } \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..ffc6c6b --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +pyinstaller main.pyw --onefile --paths .venv\Lib\site-packages --name LiquidGUI \ No newline at end of file From 65456aa5c61cf90b9fa362476c04dc766ec19d9a Mon Sep 17 00:00:00 2001 From: Dunestorm Date: Tue, 9 Jul 2024 22:00:56 +0100 Subject: [PATCH 3/4] LiquidGUI [1.1.0.0] Dev - Code cleanup & refactoring. - Platform specific code. --- globals.py | 3 +++ main.pyw | 37 ++++++++++++++++++++----------------- styles/Labels.py | 26 ++++++++++++++++++++++++++ styles/SubLabel.py | 9 --------- styles/SubLabelValue.py | 10 ---------- styles/__init__.py | 15 +++++++++++++++ 6 files changed, 64 insertions(+), 36 deletions(-) create mode 100644 globals.py create mode 100644 styles/Labels.py delete mode 100644 styles/SubLabel.py delete mode 100644 styles/SubLabelValue.py create mode 100644 styles/__init__.py diff --git a/globals.py b/globals.py new file mode 100644 index 0000000..9ebcf69 --- /dev/null +++ b/globals.py @@ -0,0 +1,3 @@ +import platform + +os_type = platform.system() \ No newline at end of file diff --git a/main.pyw b/main.pyw index 50bafe8..9bab045 100644 --- a/main.pyw +++ b/main.pyw @@ -1,29 +1,27 @@ +# Hard Dependencies. import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel, QProgressBar from PyQt6.QtCore import Qt, QTimer, QThreadPool from PyQt6.QtGui import QFont, QIcon from LiquidCTL_Helper import LiquidCTL_Helper +# Project Imports from MessageHandler import MessageHandler -import resources -from styles.SubLabel import SubLabel -from styles.SubLabelValue import SubLabelValue +from styles.Labels import * +import globals class MainWindow(QMainWindow): """ Main application window. """ def __init__(self): super(MainWindow, self).__init__() - self.setWindowTitle("LiquidGUI (v.1.1.0.0)") + self.setWindowTitle("LiquidGUI (v.1.1.0.0) DEV") self.setFixedSize(450, 385) self.lctl = LiquidCTL_Helper() - # Widgets ########################################## - self.lbl_device_name = QLabel(font=QFont("Calibre", - 14, - weight=QFont.Weight.Bold), - alignment=Qt.AlignmentFlag.AlignCenter) - + # Widgets ########################################## + self.lbl_device_name = MainLabel(None) + self.lbl_temp = SubLabel(value="💧 Liquid Temperature:") self.prg_temp = QProgressBar(textVisible=False, minimum=0, @@ -88,28 +86,33 @@ class MainWindow(QMainWindow): def main(): """ Initialize application and setup window parameters. """ + # Setup app and window. app = QApplication(sys.argv) icon = QIcon(":/icons/LiquidGUI.ico") app.setWindowIcon(icon) window = MainWindow() window.setWindowIcon(icon) - - # Show error and quit app if no devices are found + + # Show error and quit app if no devices are found. if window.lctl.TestConnectionState(): MessageHandler().ShowNoDevicesFoundError() sys.exit(1) - else: + + # Handle OS specific tweaks. + if globals.os_type == "Windows": + window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + try: + import resources import win32mica win32mica.ApplyMica(window.winId(), win32mica.MICAMODE.DARK) - window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) except ImportError as e: print(f"ERROR: Unable to import {e.name}") - window.show() - app.setStyle("Breeze") - app.exec() + # Finally run the application. + window.show() + app.exec() if __name__ == "__main__": diff --git a/styles/Labels.py b/styles/Labels.py new file mode 100644 index 0000000..be2993d --- /dev/null +++ b/styles/Labels.py @@ -0,0 +1,26 @@ +from PyQt6.QtWidgets import QLabel +from PyQt6.QtGui import QFont +from PyQt6.QtCore import Qt +import styles + +class MainLabel(QLabel): + """ Formatting for the main label. """ + def __init__(self, value): + super().__init__() + self.setAlignment(Qt.AlignmentFlag.AlignCenter) + self.setFont(QFont(styles.sublabel_font, 16, weight=QFont.Weight.Bold)) + self.setText(value) + +class SubLabel(QLabel): + """ Formatting for sub-labels. """ + def __init__(self, value): + super().__init__() + self.setFont(QFont(styles.mainlabel_font, 10, weight=QFont.Weight.Bold)) + self.setText(value) + +class SubLabelValue(QLabel): + """ Formatting for values. """ + def __init__(self): + super().__init__() + self.setAlignment(Qt.AlignmentFlag.AlignRight) + self.setFont(QFont(styles.sublabelvalue_font, 8)) \ No newline at end of file diff --git a/styles/SubLabel.py b/styles/SubLabel.py deleted file mode 100644 index d2f00f8..0000000 --- a/styles/SubLabel.py +++ /dev/null @@ -1,9 +0,0 @@ -from PyQt6.QtWidgets import QLabel -from PyQt6.QtGui import QFont - -class SubLabel(QLabel): - """ Formatting for sub-labels. """ - def __init__(self, value): - super().__init__() - self.setFont(QFont("Calibre", 10, weight=QFont.Weight.Bold)) - self.setText(value) \ No newline at end of file diff --git a/styles/SubLabelValue.py b/styles/SubLabelValue.py deleted file mode 100644 index 9e73d19..0000000 --- a/styles/SubLabelValue.py +++ /dev/null @@ -1,10 +0,0 @@ -from PyQt6.QtWidgets import QLabel -from PyQt6.QtGui import QFont -from PyQt6.QtCore import Qt - -class SubLabelValue(QLabel): - """ Formatting for values. """ - def __init__(self): - super().__init__() - self.setAlignment(Qt.AlignmentFlag.AlignRight) - self.setFont(QFont("Cascadia Code", 8)) \ No newline at end of file diff --git a/styles/__init__.py b/styles/__init__.py new file mode 100644 index 0000000..be123fe --- /dev/null +++ b/styles/__init__.py @@ -0,0 +1,15 @@ +from PyQt6.QtGui import QFont +import globals + +mainlabel_font = None +sublabel_font = None +sublabelvalue_font = None + +if globals.os_type == "Windows": + sublabelvalue_font = "Cascadia Code" + sublabel_font = "Calibre" + mainlabel_font = "Calibre" +elif globals.os_type == "Linux": + sublabelvalue_font = "Liberation Mono" + sublabel_font = "Cantarell" + mainlabel_font = "Cantarell" \ No newline at end of file From 852186587cc9e827841e3bf963676ffc840d2846 Mon Sep 17 00:00:00 2001 From: Dunestorm Date: Tue, 9 Jul 2024 22:01:26 +0100 Subject: [PATCH 4/4] Removed DEV label from app. --- main.pyw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.pyw b/main.pyw index 9bab045..fcfd58e 100644 --- a/main.pyw +++ b/main.pyw @@ -14,7 +14,7 @@ class MainWindow(QMainWindow): """ Main application window. """ def __init__(self): super(MainWindow, self).__init__() - self.setWindowTitle("LiquidGUI (v.1.1.0.0) DEV") + self.setWindowTitle("LiquidGUI (v.1.1.0.0)") self.setFixedSize(450, 385) self.lctl = LiquidCTL_Helper()