Skip to content

Commit

Permalink
Add the server name to the test view, among other things
Browse files Browse the repository at this point in the history
  • Loading branch information
Ketok4321 committed Aug 17, 2023
1 parent 435939c commit 3c97f1d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Gauge(Adw.Bin):
label = GObject.Property(type=str)
value = GObject.Property(type=str, default="...")

color1 = GObject.Property(type=str)
color2 = GObject.Property(type=str)

@GObject.Property(type=float, minimum = 0.0, maximum = 1.0)
def fill(self):
return self._fill
Expand All @@ -31,7 +34,7 @@ def __init__(self, **kwargs):
def draw(self, da, ctx, width, height): # TODO: Try blue-green color scheme, like in adwaita demo
IS_LIGHT = not Adw.StyleManager.get_default().get_dark()

ARC_SIZE = min(width, height) * 0.9
ARC_SIZE = min(width, height) * 0.85

ARC_START = 0.75 * math.pi
ARC_LENGTH = 1.5 * math.pi
Expand All @@ -44,18 +47,18 @@ def hex_to_rgb(hexa):
return tuple(int(hexa[i:i+2], 16) / 255 for i in (0, 2, 4))

UNFILLED_COLOR = 0, 0, 0, 0.1 if IS_LIGHT else 0.3
FILLED_COLOR_1 = hex_to_rgb("C061CB")
FILLED_COLOR_2 = hex_to_rgb("1C71D8")
FILLED_COLOR_1 = hex_to_rgb(self.color1)
FILLED_COLOR_2 = hex_to_rgb(self.color2)

ctx.set_line_width(ARC_THICKNESS)

ctx.set_source_rgba(*UNFILLED_COLOR)
ctx.arc(width / 2, ARC_CENTER, ARC_SIZE / 2, ARC_START, ARC_START + ARC_LENGTH)
ctx.stroke()

filled = cairo.LinearGradient(0.0, 0.0, 0.0, height)
filled = cairo.LinearGradient(0.0, 0.0, width, 0.0)
filled.add_color_stop_rgb(0, *FILLED_COLOR_1)
filled.add_color_stop_rgb(height, *FILLED_COLOR_2)
filled.add_color_stop_rgb(width, *FILLED_COLOR_2)

ctx.set_source(filled)
ctx.arc(width / 2, ARC_CENTER, ARC_SIZE / 2, ARC_START, ARC_START + ARC_LENGTH * self.fill)
Expand Down
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def on_start_action(self, widget, _):
server = self.servers[self.win.start_view.server_selector.get_selected()]

self.win.test_view.reset()
self.win.test_view.server = server.name

self.worker = SpeedtestWorker(self.win.test_view, server)
self.worker.start()
Expand Down
12 changes: 10 additions & 2 deletions src/ui/views/test.blp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ using Gtk 4.0;
using Adw 1;

//TODO: Jitter?
//TODO: Show name of the server
//TODO: Change the scale of the gauge?

template $TestView : Box {
orientation: vertical;

ProgressBar progress {
styles [ "osd" ]
}

Label title {
label: bind template.server;
margin-top: 8;
styles [ "title-2" ]
}

Box {
orientation: horizontal;

$Gauge download {
label: "Download:";
color1: "33d17a";
color2: "62a0ea";

vexpand: true;
hexpand: true;
Expand All @@ -41,6 +47,8 @@ template $TestView : Box {

$Gauge upload {
label: "Upload:";
color1: "c061cb";
color2: "1c71d8";

vexpand: true;
hexpand: true;
Expand Down
1 change: 1 addition & 0 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TestView(Gtk.Box):
download = Gtk.Template.Child()
upload = Gtk.Template.Child()
ping = GObject.Property(type=str, default="...")
server = GObject.Property(type=str)

progress = Gtk.Template.Child()

Expand Down

0 comments on commit 3c97f1d

Please sign in to comment.