File size: 5,468 Bytes
f542a21 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | #!/usr/bin/env python3
"""
Floating Window UI for GPU Monitor
PyQt6-based always-on-top floating window
"""
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QHBoxLayout, QPushButton
from PyQt6.QtCore import Qt, QPoint, QTimer
from PyQt6.QtGui import QMouseEvent
class FloatingWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.oldPos = self.pos()
def initUI(self):
# Set window flags for floating behavior
self.setWindowFlags(
Qt.WindowType.WindowStaysOnTopHint |
Qt.WindowType.FramelessWindowHint |
Qt.WindowType.Tool
)
# Set window properties
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
self.setFixedSize(220, 200)
# Create layout
self.layout = QVBoxLayout()
self.layout.setContentsMargins(10, 10, 10, 10)
self.layout.setSpacing(2)
# Set stylesheet
self.setStyleSheet("""
QWidget {
background-color: rgba(0, 0, 0, 180);
border-radius: 10px;
border: 1px solid #3498db;
}
QLabel {
color: #ecf0f1;
font-family: 'Segoe UI', Arial;
font-size: 12px;
font-weight: bold;
border: none;
}
#title {
color: #3498db;
font-size: 14px;
margin-bottom: 5px;
}
""")
# Create title bar
self.title_layout = QHBoxLayout()
self.title_layout.setContentsMargins(0, 0, 0, 5)
self.lbl_title = QLabel("AMD GPU MONITOR")
self.lbl_title.setObjectName("title")
self.btn_close = QPushButton("×")
self.btn_close.setFixedSize(20, 20)
self.btn_close.setStyleSheet("""
QPushButton {
background-color: transparent;
color: #e74c3c;
font-size: 18px;
font-weight: bold;
border: none;
margin: 0;
padding: 0;
}
QPushButton:hover {
color: #ff0000;
}
""")
self.btn_close.clicked.connect(self.close)
self.title_layout.addWidget(self.lbl_title)
self.title_layout.addStretch()
self.title_layout.addWidget(self.btn_close)
# Create data labels
self.lbl_load = QLabel("GPU Load: --%")
self.lbl_clocks = QLabel("Clocks: -- / -- MHz")
self.lbl_vram = QLabel("VRAM: -- / -- MB")
self.lbl_temp = QLabel("Temp: --°C")
self.lbl_power = QLabel("Power: --W")
self.lbl_fan = QLabel("Fan: -- RPM (--%)")
# Add widgets to layout
self.layout.addLayout(self.title_layout)
self.layout.addWidget(self.lbl_load)
self.layout.addWidget(self.lbl_clocks)
self.layout.addWidget(self.lbl_vram)
self.layout.addWidget(self.lbl_temp)
self.layout.addWidget(self.lbl_power)
self.layout.addWidget(self.lbl_fan)
self.setLayout(self.layout)
def update_data(self, data):
"""Update the UI with new GPU data"""
# Update GPU load
if data['gpu_usage'] is not None:
self.lbl_load.setText(f"GPU Load: {data['gpu_usage']:.1f}%")
else:
self.lbl_load.setText("GPU Load: --%")
# Update clocks
core_clk = data['core_clock'] if data['core_clock'] is not None else "--"
mem_clk = data['mem_clock'] if data['mem_clock'] is not None else "--"
self.lbl_clocks.setText(f"Clocks: {core_clk} / {mem_clk} MHz")
# Update VRAM
if data['vram_used'] is not None and data['vram_total'] is not None:
self.lbl_vram.setText(f"VRAM: {data['vram_used']} / {data['vram_total']} MB")
else:
self.lbl_vram.setText("VRAM: -- / -- MB")
# Update temperature
if data['temperature'] is not None:
self.lbl_temp.setText(f"Temp: {data['temperature']:.1f}°C")
else:
self.lbl_temp.setText("Temp: --°C")
# Update power
if data['power_draw'] is not None:
self.lbl_power.setText(f"Power: {data['power_draw']:.1f}W")
else:
self.lbl_power.setText("Power: --W")
# Update fan
rpm = data['fan_rpm'] if data['fan_rpm'] is not None else "--"
pwm = data['fan_pwm'] if data['fan_pwm'] is not None else "--"
self.lbl_fan.setText(f"Fan: {rpm} RPM ({pwm}%)")
def mousePressEvent(self, event: QMouseEvent):
"""Handle mouse press for window dragging"""
if event.button() == Qt.MouseButton.LeftButton:
self.oldPos = event.globalPosition().toPoint()
def mouseMoveEvent(self, event: QMouseEvent):
"""Handle mouse move for window dragging"""
if event.buttons() & Qt.MouseButton.LeftButton:
delta = event.globalPosition().toPoint() - self.oldPos
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldPos = event.globalPosition().toPoint()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = FloatingWindow()
window.show()
sys.exit(app.exec()) |