Skip to content

Commit b62e8fc

Browse files
committed
feat(monitor): add smoother usage bar changes
1 parent adc8f4b commit b62e8fc

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/GPUMonitor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
AMD_GPU_NOT_SUPPORTED,
2525
)
2626

27+
from ui_update import animate_bar
28+
2729

2830
class SimpleGraph(QGraphicsView):
2931
def __init__(self, title, parent=None):
@@ -143,7 +145,7 @@ def update_gpu_info(self):
143145
gpu_usage = utilization.gpu
144146
vram_usage = (memory.used / memory.total) * 100
145147

146-
self.gpu_bar.setValue(int(vram_usage))
148+
animate_bar(self, self.gpu_bar, int(vram_usage))
147149
self.gpu_label.setText(
148150
GPU_USAGE_FORMAT.format(
149151
gpu_usage,

src/ui_update.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from PySide6.QtCore import QTimer
2+
13
from Localizations import *
24
import psutil
35
from error_handling import show_error
@@ -11,14 +13,42 @@ def update_model_info(logger, self, model_info):
1113
def update_system_info(self):
1214
ram = psutil.virtual_memory()
1315
cpu = psutil.cpu_percent()
14-
self.ram_bar.setValue(int(ram.percent))
16+
17+
# Smooth transition for RAM bar
18+
animate_bar(self, self.ram_bar, ram.percent)
19+
20+
# Smooth transition for CPU bar
21+
animate_bar(self, self.cpu_bar, cpu)
22+
1523
self.ram_bar.setFormat(
1624
RAM_USAGE_FORMAT.format(
1725
ram.percent, ram.used // 1024 // 1024, ram.total // 1024 // 1024
1826
)
1927
)
2028
self.cpu_label.setText(CPU_USAGE_FORMAT.format(cpu))
21-
self.cpu_bar.setValue(int(cpu))
29+
30+
def animate_bar(self, bar, target_value):
31+
current_value = bar.value()
32+
difference = target_value - current_value
33+
34+
if abs(difference) <= 1: # Avoid animation for small changes
35+
bar.setValue(target_value)
36+
return
37+
38+
step = 1 if difference > 0 else -1 # Increment or decrement based on difference
39+
timer = QTimer(self)
40+
timer.timeout.connect(lambda: _animate_step(bar, target_value, step, timer))
41+
timer.start(10) # Adjust the interval for animation speed
42+
43+
def _animate_step(bar, target_value, step, timer):
44+
current_value = bar.value()
45+
new_value = current_value + step
46+
47+
if (step > 0 and new_value > target_value) or (step < 0 and new_value < target_value):
48+
bar.setValue(target_value)
49+
timer.stop()
50+
else:
51+
bar.setValue(new_value)
2252

2353

2454
def update_download_progress(self, progress):

0 commit comments

Comments
 (0)