From 199d81891fdd7088e95f646b139d3c64458074cf Mon Sep 17 00:00:00 2001 From: rattatwinko Date: Wed, 28 May 2025 20:13:54 +0200 Subject: [PATCH] cool HW monitor! --- mucapy/main.py | 121 ++++++++++++++++++++++++++++++++++++++++++++++- requirements.txt | 3 +- 2 files changed, 122 insertions(+), 2 deletions(-) diff --git a/mucapy/main.py b/mucapy/main.py index 4b05616..7663c43 100644 --- a/mucapy/main.py +++ b/mucapy/main.py @@ -4,13 +4,15 @@ import cv2 import json import urllib.parse import numpy as np +import psutil # Add psutil import from PyQt5.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout, QWidget, QLabel, QPushButton, QComboBox, QSpinBox, QFileDialog, QMessageBox, QMenu, QAction, QMenuBar, QActionGroup, QSizePolicy, QGridLayout, QGroupBox, QDockWidget, QScrollArea, QToolButton, QDialog, QShortcut, QListWidget, QFormLayout, QLineEdit, - QCheckBox, QTabWidget, QListWidgetItem, QSplitter) + QCheckBox, QTabWidget, QListWidgetItem, QSplitter, + QProgressBar) # Add QProgressBar from PyQt5.QtCore import Qt, QTimer, QDir, QSize, QSettings, QDateTime, QRect, QThread, pyqtSignal, QMutex from PyQt5.QtGui import (QImage, QPixmap, QIcon, QColor, QKeySequence, QPainter, QPen, QBrush) @@ -1322,6 +1324,11 @@ class MainWindow(QMainWindow): # Load saved settings first self.load_saved_settings() + + # Initialize hardware monitor timer + self.hw_timer = QTimer() + self.hw_timer.timeout.connect(self.update_hardware_stats) + self.hw_timer.start(1000) # Update every second # Set dark theme style self.setStyleSheet(""" @@ -1897,6 +1904,63 @@ class MainWindow(QMainWindow): self.display_area.setLayout(self.display_layout) main_layout.addWidget(self.display_area) + # Hardware Monitor section + hw_monitor_group = QGroupBox("Hardware Monitor") + hw_monitor_layout = QVBoxLayout() + + # CPU Usage + cpu_layout = QHBoxLayout() + cpu_layout.addWidget(QLabel("CPU Usage:")) + self.cpu_progress = QProgressBar() + self.cpu_progress.setRange(0, 100) + self.cpu_progress.setTextVisible(True) + self.cpu_progress.setFormat("%p%") + self.cpu_progress.setStyleSheet(""" + QProgressBar { + border: 1px solid #555; + border-radius: 2px; + text-align: center; + background-color: #2A2A2A; + } + QProgressBar::chunk { + background-color: #3A6EA5; + width: 1px; + } + """) + cpu_layout.addWidget(self.cpu_progress) + hw_monitor_layout.addLayout(cpu_layout) + + # Per-core CPU Usage + cores_layout = QGridLayout() + self.core_bars = [] + num_cores = psutil.cpu_count() + for i in range(num_cores): + core_label = QLabel(f"Core {i}:") + core_bar = QProgressBar() + core_bar.setRange(0, 100) + core_bar.setTextVisible(True) + core_bar.setFormat("%p%") + core_bar.setStyleSheet(""" + QProgressBar { + border: 1px solid #555; + border-radius: 2px; + text-align: center; + background-color: #2A2A2A; + max-height: 12px; + } + QProgressBar::chunk { + background-color: #3A6EA5; + width: 1px; + } + """) + cores_layout.addWidget(core_label, i, 0) + cores_layout.addWidget(core_bar, i, 1) + self.core_bars.append(core_bar) + hw_monitor_layout.addLayout(cores_layout) + + hw_monitor_group.setLayout(hw_monitor_layout) + sidebar_layout.addWidget(hw_monitor_group) + main_widget.setLayout(main_layout) self.setCentralWidget(main_widget) @@ -2102,6 +2166,61 @@ class MainWindow(QMainWindow): else: self.sidebar.collapse() + def update_hardware_stats(self): + """Update hardware statistics""" + # Update overall CPU usage + cpu_percent = psutil.cpu_percent() + self.cpu_progress.setValue(int(cpu_percent)) + + # Update per-core CPU usage + per_core = psutil.cpu_percent(percpu=True) + for i, usage in enumerate(per_core): + if i < len(self.core_bars): + self.core_bars[i].setValue(int(usage)) + + # Set color based on usage + for bar in [self.cpu_progress] + self.core_bars: + value = bar.value() + if value < 60: + bar.setStyleSheet(""" + QProgressBar { + border: 1px solid #555; + border-radius: 2px; + text-align: center; + background-color: #2A2A2A; + } + QProgressBar::chunk { + background-color: #3A6EA5; + width: 1px; + } + """) + elif value < 85: + bar.setStyleSheet(""" + QProgressBar { + border: 1px solid #555; + border-radius: 2px; + text-align: center; + background-color: #2A2A2A; + } + QProgressBar::chunk { + background-color: #E5A823; + width: 1px; + } + """) + else: + bar.setStyleSheet(""" + QProgressBar { + border: 1px solid #555; + border-radius: 2px; + text-align: center; + background-color: #2A2A2A; + } + QProgressBar::chunk { + background-color: #A23535; + width: 1px; + } + """) + if __name__ == "__main__": app = QApplication(sys.argv) diff --git a/requirements.txt b/requirements.txt index aac312f..612d51d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ opencv-python==4.11.0.86 numpy==2.2.6 PyQt5==5.15.11 -requests==2.32.3 \ No newline at end of file +requests==2.32.3 +psutil==5.9.8 \ No newline at end of file