Files
LiquidGUI/main.pyw
Dunestorm 2226ebbe69 LiquidGUI [1.3.0.0]
- Initial psutil support for system vitals.
2025-01-27 00:17:44 +00:00

179 lines
7.0 KiB
Python

# External Dependencies v####################################
import sys
from PySide6.QtWidgets import (QApplication,
QMainWindow,
QWidget,
QVBoxLayout,
QProgressBar,
QPushButton)
from PySide6.QtCore import (Qt,
QTimer,
QThreadPool)
from PySide6.QtGui import QIcon
## Internal Imports #########################################
import resources
import common
from MessageHandler import MessageHandler
## Platform Imports #########################################
import globals
from sys_vitals_helper import SysVitals_Helper
if globals.os == "Windows":
from LiquidCTL_Helper_Windows import LiquidCTL_Helper
from styles import Labels_Windows as Labels
import win32mica # type: ignore
import darkdetect # type: ignore
elif globals.os == "Linux":
from LiquidCTL_Helper_Linux import LiquidCTL_Helper
from styles import Labels_Linux as Labels
from pathlib import Path
from sys_vitals_helper import SysVitals_Helper, Component
class MainWindow(QMainWindow):
""" Main application window. """
def __init__(self, lctl):
super(MainWindow, self).__init__()
self.setWindowTitle("LiquidGUI (v.1.3.0.0) DEV")
self.setFixedSize(450, 700)
self.lctl = lctl
self.svh = SysVitals_Helper()
# Widgets ##########################################
self.lbl_device_name = Labels.MainLabel()
self.lbl_temp = Labels.SubLabel(value="💧 Liquid Temperature:")
self.min_max_cur_temp = common.MinMaxCurrent()
self.prg_temp = QProgressBar(textVisible=False,
minimum=0,
maximum=50)
self.lbl_value_prg_temp = Labels.SubLabelValue()
self.lbl_fanspeed = Labels.SubLabel(value="🍃 Fan Speed:")
self.min_max_cur_fanspeed = common.MinMaxCurrent()
self.prg_fanspeed = QProgressBar(textVisible=False,
minimum=520,
maximum=1700)
self.lbl_value_prg_fanspeed = Labels.SubLabelValue()
self.lbl_pumpspeed = Labels.SubLabel(value="⛽ Pump Speed:")
self.min_max_cur_pumpspeed = common.MinMaxCurrent()
self.prg_pumpspeed = QProgressBar(textVisible=False,
minimum=1900,
maximum=2700)
self.lbl_value_prg_pumpspeed = Labels.SubLabelValue()
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,
maximum=105)
self.lbl_value_prg_cpu_temp = Labels.SubLabelValue()
self.btn_reset_min_max = QPushButton("Reset Min/Max")
self.btn_reset_min_max.clicked.connect(self.on_reset_min_max)
self.lbl_fwvers = Labels.SubLabelValue()
# Layout ##########################################
widget = QWidget(self)
layout = QVBoxLayout(widget)
layout.addWidget(self.lbl_device_name)
layout.addWidget(self.lbl_temp)
layout.addWidget(self.prg_temp)
layout.addWidget(self.lbl_value_prg_temp)
layout.addWidget(self.lbl_fanspeed)
layout.addWidget(self.prg_fanspeed)
layout.addWidget(self.lbl_value_prg_fanspeed)
layout.addWidget(self.lbl_pumpspeed)
layout.addWidget(self.prg_pumpspeed)
layout.addWidget(self.lbl_value_prg_pumpspeed)
layout.addWidget(self.lbl_cpu_temp)
layout.addWidget(self.prg_cpu_temp)
layout.addWidget(self.lbl_value_prg_cpu_temp)
layout.addWidget(self.lbl_fwvers)
layout.addWidget(self.btn_reset_min_max)
layout.setSpacing(10)
self.setLayout(layout)
self.setCentralWidget(widget)
self.setContentsMargins(20, 20, 20, 20)
# 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(self.update_widgets)
self.timer.start()
def on_reset_min_max(self):
""" Pauses the timer and creates new instances of MinMaxCurrent """
self.timer.stop()
self.min_max_cur_temp = common.MinMaxCurrent()
self.min_max_cur_fanspeed = common.MinMaxCurrent()
self.min_max_cur_pumpspeed = common.MinMaxCurrent()
self.min_max_cur_cpu_temp = common.MinMaxCurrent()
self.timer.start()
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(
self.min_max_cur_temp.builder(
self.lctl.device_temp, "°C"))
self.prg_fanspeed.setValue(self.lctl.device_fanSpeed)
self.lbl_value_prg_fanspeed.setText(
self.min_max_cur_fanspeed.builder(
self.lctl.device_fanSpeed, " rpm"))
self.prg_pumpspeed.setValue(self.lctl.device_pumpSpeed)
self.lbl_value_prg_pumpspeed.setText(
self.min_max_cur_pumpspeed.builder(
self.lctl.device_pumpSpeed, " rpm"))
if self.lctl.device_fwVers is not None:
self.lbl_fwvers.setText(f"Firmware: v{self.lctl.device_fwVers}")
self.prg_cpu_temp.setValue(self.svh.GetTemps(Component.CPU_AMD))
self.lbl_value_prg_cpu_temp.setText(
self.min_max_cur_cpu_temp.builder(
self.svh.GetTemps(Component.CPU_AMD), "°C"))
# print(f"CPU: {self.svh.GetTemps(Component.CPU_AMD)}°C")
# print(f"GPU: {self.svh.GetTemps(Component.GPU_AMD)}°C")
# print(f"MOBO: {self.svh.GetTemps(Component.MOBO_ASUS)}°C")
def main():
""" Initialize application and setup window parameters. """
app = QApplication(sys.argv)
window = MainWindow(LiquidCTL_Helper())
if globals.os == "Windows":
window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
icon = QIcon(":/icons/LiquidGUI.ico")
if darkdetect.isDark():
win32mica.ApplyMica(window.winId(), win32mica.MICAMODE.DARK)
elif darkdetect.isLight():
win32mica.ApplyMica(window.winId(), win32mica.MICAMODE.LIGHT)
elif globals.os == "Linux":
app.setDesktopFileName("LiquidGUI")
icon = QIcon(":/icons/LiquidGUI.png")
app.setWindowIcon(icon)
# Show error and quit app if no devices are found
if window.lctl.TestConnectionState():
MessageHandler().ShowNoDevicesFoundError()
sys.exit(1)
else:
window.show()
app.exec()
if __name__ == "__main__":
main()