meccatronis commited on
Commit
f542a21
·
verified ·
1 Parent(s): 7373657

Upload ui.py with huggingface_hub

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