Skip to content

Commit 845992d

Browse files
committed
Unlimited fps for gauges, 15fps for labels
1 parent fd2db11 commit 845992d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/gauge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ def gdk_color_to_tuple(color):
8484
ctx.arc(width / 2, ARC_CENTER, ARC_SIZE / 2, ARC_START, ARC_START + ARC_LENGTH * self.fill)
8585
ctx.stroke()
8686

87-
Gauge.set_css_name("gauge")
87+
Gauge.set_css_name("gauge")

src/test_worker.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def __init__(self, app, server):
2323
self.stop_event = threading.Event()
2424
self.app = app
2525
self.server = server
26+
27+
self.start_time = 0
28+
self.last_label_update = 0
2629

2730
def run(self):
2831
event_loop = asyncio.new_event_loop()
@@ -61,26 +64,26 @@ def on_event(type):
6164
view.ping = f"{self.results.ping:.1f}ms"
6265
view.jitter = f"{self.results.jitter:.1f}ms"
6366
elif type == "download_start":
64-
timeout = GLib.timeout_add(1000 / 30, lambda: self.update(view.download, self.results.total_dl, False))
67+
timeout = view.download.get_frame_clock().connect("before-paint", lambda *_: self.update(view.download, self.results.total_dl, False))
6568

6669
view.progress.remove_css_class("up")
6770
view.progress.add_css_class("dl")
6871
view.download.add_css_class("active")
6972

7073
self.start_time = time.time()
7174
elif type == "download_end":
72-
GLib.source_remove(timeout)
75+
view.download.get_frame_clock().disconnect(timeout)
7376
view.download.remove_css_class("active")
7477
elif type == "upload_start":
75-
timeout = GLib.timeout_add(1000 / 30, lambda: self.update(view.upload, self.results.total_up, True))
78+
timeout = view.upload.get_frame_clock().connect("before-paint", lambda *_: self.update(view.upload, self.results.total_up, True))
7679

7780
view.progress.remove_css_class("dl")
7881
view.progress.add_css_class("up")
7982
view.upload.add_css_class("active")
8083

8184
self.start_time = time.time()
8285
elif type == "upload_end":
83-
GLib.source_remove(timeout)
86+
view.upload.get_frame_clock().disconnect(timeout)
8487
view.upload.remove_css_class("active")
8588

8689
GLib.idle_add(self.app.win.test_view.progress.set_visible, True)
@@ -99,7 +102,9 @@ def update(self, gauge, total, part_two):
99102

100103
if current_duration > 1:
101104
speedMb = round(value / 125_000, 1)
102-
gauge.value = str(speedMb) + "Mbps"
105+
if time.time() - self.last_label_update >= 0.075:
106+
gauge.value = str(speedMb) + "Mbps"
107+
self.last_label_update = time.time()
103108
gauge.fill = min(speedMb / self.app.settings.get_int("gauge-scale"), 1.0)
104109

105110
view.progress.set_fraction(current_duration / DURATION * 0.5 + (0.5 if part_two else 0.0))

0 commit comments

Comments
 (0)