From dffeb995a00e3e4af5ef8ae058684a8636e1936e Mon Sep 17 00:00:00 2001 From: rattatwinko Date: Sun, 8 Jun 2025 14:12:42 +0200 Subject: [PATCH] seperate files for the CPU style ; and more error resistant --- mucapy/main.py | 79 +++++++++++++++++++++++----- mucapy/styling/bar/seperate/a85.qss | 27 ++++++++++ mucapy/styling/bar/seperate/else.qss | 27 ++++++++++ mucapy/styling/bar/seperate/u60.qss | 27 ++++++++++ 4 files changed, 146 insertions(+), 14 deletions(-) create mode 100644 mucapy/styling/bar/seperate/a85.qss create mode 100644 mucapy/styling/bar/seperate/else.qss create mode 100644 mucapy/styling/bar/seperate/u60.qss diff --git a/mucapy/main.py b/mucapy/main.py index 0ffaf03..5afbcd2 100644 --- a/mucapy/main.py +++ b/mucapy/main.py @@ -233,6 +233,7 @@ class CameraThread(QThread): except Exception as e: print(f"Connection attempt {attempt + 1} failed: {str(e)}") + if self.cap: self.cap.release() self.cap = None @@ -567,7 +568,6 @@ class CameraDisplay(QLabel): self.get_camera_display_style = getpath.resource_path("styling/camera_display.qss") with open(self.get_camera_display_style,"r") as cdst: self.setStyleSheet(cdst.read()) - # I really dont know what the fuck is going on here. The StyleSheet never actually gets called self.setMinimumSize(320, 240) self.fullscreen_window = None @@ -1469,7 +1469,10 @@ class MainWindow(QMainWindow): # Apply saved settings to UI self.apply_saved_settings() - + + # For the CPU Styling we have another one so we set this here! + self.sepstyleing = False + def load_saved_settings(self): """Load saved settings from configuration""" # Load model directory @@ -2200,20 +2203,62 @@ class MainWindow(QMainWindow): for bar in [self.cpu_progress] + self.core_bars: value = bar.value() if value < 60: - u60 = getpath.resource_path("styling/bar/u60.qss") - with open(u60,"r") as u60_style: - bar.setStyleSheet(u60_style.read()) - + # Here we load the Style File if the CPU Load is under 60% + if self.sepstyleing == False: + u60 = getpath.resource_path("styling/bar/u60.qss") + try: + with open(u60,"r") as u60_style: + bar.setStyleSheet(u60_style.read()) + except FileNotFoundError: + print("Styling for CPU U60 not found!") + exit(1) + else: + u60seperate = getpath.resource_path("styling/bar/seperate/u60.qss") + try: + with open(u60seperate,"r") as u60_seperate_styling: + bar.setStyleSheet(u60_seperate_styling.read()) + except FileNotFoundError: + print("No Seperate Styling! Generate one!") + pass + elif value < 85: - u85 = getpath.resource_path("styling/bar/a85.qss") - with open(u85,"r") as a85_styling: - bar.setStyleSheet(a85_styling.read()) + # Here we load the Style File if the CPU Load is over 85% + if self.sepstyleing == False: + u85 = getpath.resource_path("styling/bar/a85.qss") + try: + with open(u85,"r") as a85_styling: + bar.setStyleSheet(a85_styling.read()) + except FileNotFoundError: + print("Styling for CPU u85 not found") + exit(1) + else: + u85sep = getpath.resource_path("styling/bar/seperate/a85.qss") + try: + with open(u85sep,"r") as u85style_sep: + bar.setStyleSheet(u85style_sep.read()) + except FileNotFoundError: + print("No Seperate File Found for U85") + pass else: - else_file = getpath.resource_path("styling/bar/else.qss") - with open(else_file, "r") as else_style: - bar.setStyleSheet(else_style.read()) - + # Here we load the Style File if the CPU Load is over 85 or 100 or smth idk + if self.sepstyleing == False: + else_file = getpath.resource_path("styling/bar/else.qss") + try: + with open(else_file, "r") as else_style: + bar.setStyleSheet(else_style.read()) + except FileNotFoundError: + print("No ElseStyling found!") + exit(1) + else: + else_file_seperate = getpath.resource_path("styling/bar/seperate/else.qss") + try: + with open(else_file_seperate,"r") as efs: + bar.setStyleSheet(efs.read()) + except FileNotFoundError: + print("No Sepearte Styling found") + pass + def toggle_detection(self): """Toggle detection enabled/disabled""" @@ -2285,7 +2330,13 @@ if __name__ == "__main__": pass app = QApplication(sys.argv) - + + # Here we try to set the AppIcon ; If it isnt find then just pass + try: + app.setWindowIcon(QIcon(getpath.resource_path("styling/icon.png"))) + except FileNotFoundError: + pass + # Set application style to Fusion for better dark mode support app.setStyle("Fusion") diff --git a/mucapy/styling/bar/seperate/a85.qss b/mucapy/styling/bar/seperate/a85.qss new file mode 100644 index 0000000..e13d7af --- /dev/null +++ b/mucapy/styling/bar/seperate/a85.qss @@ -0,0 +1,27 @@ +QProgressBar { + border: 2px solid #550000; + border-radius: 50px; + background-color: qradialgradient( + cx:0.5, cy:0.5, + fx:0.5, fy:0.5, + radius:1.0, + stop:0 #0d0d0d, + stop:1 #1a1a1a + ); + text-align: center; + color: #cccccc; + font-family: "Fira Code", "OCR A Std", monospace; + font-style: italic; + font-size: 14px; + padding: 5px; +} + +QProgressBar::chunk { + background: qlineargradient( + x1:0, y1:0, x2:1, y2:1, + stop:0 #ff0033, + stop:1 #ff6666 + ); + border-radius: 50px; + margin: 1px; +} diff --git a/mucapy/styling/bar/seperate/else.qss b/mucapy/styling/bar/seperate/else.qss new file mode 100644 index 0000000..e13d7af --- /dev/null +++ b/mucapy/styling/bar/seperate/else.qss @@ -0,0 +1,27 @@ +QProgressBar { + border: 2px solid #550000; + border-radius: 50px; + background-color: qradialgradient( + cx:0.5, cy:0.5, + fx:0.5, fy:0.5, + radius:1.0, + stop:0 #0d0d0d, + stop:1 #1a1a1a + ); + text-align: center; + color: #cccccc; + font-family: "Fira Code", "OCR A Std", monospace; + font-style: italic; + font-size: 14px; + padding: 5px; +} + +QProgressBar::chunk { + background: qlineargradient( + x1:0, y1:0, x2:1, y2:1, + stop:0 #ff0033, + stop:1 #ff6666 + ); + border-radius: 50px; + margin: 1px; +} diff --git a/mucapy/styling/bar/seperate/u60.qss b/mucapy/styling/bar/seperate/u60.qss new file mode 100644 index 0000000..e13d7af --- /dev/null +++ b/mucapy/styling/bar/seperate/u60.qss @@ -0,0 +1,27 @@ +QProgressBar { + border: 2px solid #550000; + border-radius: 50px; + background-color: qradialgradient( + cx:0.5, cy:0.5, + fx:0.5, fy:0.5, + radius:1.0, + stop:0 #0d0d0d, + stop:1 #1a1a1a + ); + text-align: center; + color: #cccccc; + font-family: "Fira Code", "OCR A Std", monospace; + font-style: italic; + font-size: 14px; + padding: 5px; +} + +QProgressBar::chunk { + background: qlineargradient( + x1:0, y1:0, x2:1, y2:1, + stop:0 #ff0033, + stop:1 #ff6666 + ); + border-radius: 50px; + margin: 1px; +}