120 lines
4.4 KiB
Python
120 lines
4.4 KiB
Python
# 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
|
|
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) DEV")
|
|
self.setFixedSize(450, 385)
|
|
|
|
self.lctl = LiquidCTL_Helper()
|
|
|
|
# Widgets ##########################################
|
|
self.lbl_device_name = MainLabel(None)
|
|
|
|
self.lbl_temp = SubLabel(value="💧 Liquid Temperature:")
|
|
self.prg_temp = QProgressBar(textVisible=False,
|
|
minimum=0,
|
|
maximum=50)
|
|
self.lbl_value_prg_temp = SubLabelValue()
|
|
|
|
self.lbl_fanspeed = SubLabel(value="🍃 Fan Speed:")
|
|
self.prg_fanspeed = QProgressBar(textVisible=False,
|
|
minimum=520,
|
|
maximum=1700)
|
|
self.lbl_value_prg_fanspeed = SubLabelValue()
|
|
|
|
self.lbl_pumpspeed = SubLabel(value="⛽ Pump Speed:")
|
|
self.prg_pumpspeed = QProgressBar(textVisible=False,
|
|
minimum=1900,
|
|
maximum=2700)
|
|
self.lbl_value_prg_pumpspeed = SubLabelValue()
|
|
|
|
self.lbl_fwvers = 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_fwvers)
|
|
layout.setSpacing(10)
|
|
|
|
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 update_widgets(self):
|
|
""" Update widgets using LiquidCTL library."""
|
|
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():
|
|
""" 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.
|
|
if window.lctl.TestConnectionState():
|
|
MessageHandler().ShowNoDevicesFoundError()
|
|
sys.exit(1)
|
|
|
|
# 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)
|
|
except ImportError as e:
|
|
print(f"ERROR: Unable to import {e.name}")
|
|
|
|
# Finally run the application.
|
|
window.show()
|
|
app.exec()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|