Really rough bart implementation

This commit is contained in:
2022-10-16 00:21:28 -07:00
parent ac9f37487e
commit e85241c998
3 changed files with 140 additions and 9 deletions

View File

@@ -1,9 +1,12 @@
import gintro/[gtk4, gobject, gio, adw]
import std/[with]
import std/[with, httpclient]
import actransit
import metar
import bart
const airports = @["khwd", "koak", "klvk", "khaf"]
const airports = @["khwd", "koak", "klvk", "khaf", "kmry", "ksac"]
let client = newHttpClient()
proc clearMetars(metar_list: gtk4.ListBox) =
for i in 1..airports.len:
@@ -24,12 +27,16 @@ proc addMetars(metar_list: gtk4.ListBox) =
proc button_refresh_signal(b: Button,
widgets: tuple[vs: adw.ViewStack, home: Label, office: Label, metar_list: gtk4.ListBox]) =
if widgets.vs.get_visible_child_name() == "act_view":
widgets.home.text = home_predictions().cstring
widgets.office.text = office_predictions().cstring
widgets.home.text = client.home_predictions().cstring
widgets.office.text = client.office_predictions().cstring
elif widgets.vs.get_visible_child_name() == "metar_view":
clearMetars(widgets.metar_list)
addMetars(widgets.metar_list)
proc bart_departures_signal(b: Button, widgets: tuple[dropdown: DropDown, label: Label]) =
let prediction = client.prediction_for_station_idx(widgets.dropdown.getSelected())
widgets.label.text = prediction.cstring
proc activate(app: adw.Application) =
let
window = adw.newApplicationWindow(app)
@@ -37,6 +44,9 @@ proc activate(app: adw.Application) =
switcher_bar = adw.newViewSwitcherBar()
bart_box = newBox(Orientation.vertical, 0)
bart_station_dropdown = newDropDownFromStrings(bart_station_names())
bart_get_departures_button = newButton()
bart_label = newLabel()
metar_box = newBox(Orientation.vertical, 0)
metar_list = newListBox()
@@ -77,6 +87,19 @@ proc activate(app: adw.Application) =
append home_label
append office_label
with bart_box:
marginTop = 10
marginEnd = 10
marginStart = 10
append bart_station_dropdown
append bart_get_departures_button
append bart_label
with bart_get_departures_button:
marginTop = 10
label = "Get departures".cstring
connect("clicked", bart_departures_signal, (bart_station_dropdown, bart_label))
with metar_box:
append metar_list
@@ -92,7 +115,7 @@ proc activate(app: adw.Application) =
iconName = "view-refresh"
with home_label:
text = home_predictions().cstring
text = client.home_predictions().cstring
marginTop = 10
marginBottom = 10
marginStart = 10
@@ -100,7 +123,7 @@ proc activate(app: adw.Application) =
halign = Align.start
with office_label:
text = office_predictions().cstring
text = client.office_predictions().cstring
marginTop = 10
marginBottom = 10
marginStart = 10