cool HW monitor!
All checks were successful
Build MuCaPy Executable / build-and-package (push) Successful in 1m38s
All checks were successful
Build MuCaPy Executable / build-and-package (push) Successful in 1m38s
This commit is contained in:
121
mucapy/main.py
121
mucapy/main.py
@@ -4,13 +4,15 @@ import cv2
|
|||||||
import json
|
import json
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import psutil # Add psutil import
|
||||||
from PyQt5.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout,
|
from PyQt5.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout,
|
||||||
QWidget, QLabel, QPushButton, QComboBox, QSpinBox,
|
QWidget, QLabel, QPushButton, QComboBox, QSpinBox,
|
||||||
QFileDialog, QMessageBox, QMenu, QAction, QMenuBar,
|
QFileDialog, QMessageBox, QMenu, QAction, QMenuBar,
|
||||||
QActionGroup, QSizePolicy, QGridLayout, QGroupBox,
|
QActionGroup, QSizePolicy, QGridLayout, QGroupBox,
|
||||||
QDockWidget, QScrollArea, QToolButton, QDialog,
|
QDockWidget, QScrollArea, QToolButton, QDialog,
|
||||||
QShortcut, QListWidget, QFormLayout, QLineEdit,
|
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.QtCore import Qt, QTimer, QDir, QSize, QSettings, QDateTime, QRect, QThread, pyqtSignal, QMutex
|
||||||
from PyQt5.QtGui import (QImage, QPixmap, QIcon, QColor, QKeySequence, QPainter,
|
from PyQt5.QtGui import (QImage, QPixmap, QIcon, QColor, QKeySequence, QPainter,
|
||||||
QPen, QBrush)
|
QPen, QBrush)
|
||||||
@@ -1322,6 +1324,11 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
# Load saved settings first
|
# Load saved settings first
|
||||||
self.load_saved_settings()
|
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
|
# Set dark theme style
|
||||||
self.setStyleSheet("""
|
self.setStyleSheet("""
|
||||||
@@ -1897,6 +1904,63 @@ class MainWindow(QMainWindow):
|
|||||||
self.display_area.setLayout(self.display_layout)
|
self.display_area.setLayout(self.display_layout)
|
||||||
main_layout.addWidget(self.display_area)
|
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)
|
main_widget.setLayout(main_layout)
|
||||||
self.setCentralWidget(main_widget)
|
self.setCentralWidget(main_widget)
|
||||||
|
|
||||||
@@ -2102,6 +2166,61 @@ class MainWindow(QMainWindow):
|
|||||||
else:
|
else:
|
||||||
self.sidebar.collapse()
|
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__":
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
opencv-python==4.11.0.86
|
opencv-python==4.11.0.86
|
||||||
numpy==2.2.6
|
numpy==2.2.6
|
||||||
PyQt5==5.15.11
|
PyQt5==5.15.11
|
||||||
requests==2.32.3
|
requests==2.32.3
|
||||||
|
psutil==5.9.8
|
||||||
Reference in New Issue
Block a user