152 lines
4.0 KiB
Nim
152 lines
4.0 KiB
Nim
import gintro/[gtk4, gobject, gio, adw]
|
|
import std/[with, httpclient]
|
|
import actransit
|
|
import metar
|
|
import bart
|
|
|
|
const airports = @["khwd", "koak", "klvk", "khaf", "kmry", "ksac"]
|
|
|
|
let client = newHttpClient()
|
|
|
|
proc clearMetars(metar_list: gtk4.ListBox) =
|
|
for i in 1..airports.len:
|
|
let metar_row = metar_list.get_row_at_index(0)
|
|
metar_list.remove(metar_row)
|
|
|
|
proc addMetars(metar_list: gtk4.ListBox) =
|
|
let metars = getMetars(airports)
|
|
|
|
for metar in metars:
|
|
let metar_label = newLabel()
|
|
with metar_label:
|
|
text = metar.rawText.cstring
|
|
halign = Align.start
|
|
wrap = true
|
|
metar_list.append(metar_label)
|
|
|
|
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 = 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)
|
|
view_stack = adw.newViewStack()
|
|
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()
|
|
|
|
act_box = newBox(Orientation.vertical, 0)
|
|
home_label = newLabel()
|
|
office_label = newLabel()
|
|
|
|
refresh_button = newButtonFromIconName("view-refresh")
|
|
header = adw.newHeaderBar()
|
|
main_box = newBox(Orientation.vertical, 0)
|
|
|
|
|
|
with main_box:
|
|
append header
|
|
append view_stack
|
|
append switcher_bar
|
|
|
|
let
|
|
act_view_page = view_stack.add_titled(act_box, "act_view", "AC Transit")
|
|
bart_view_page = view_stack.add_titled(bart_box, "bart_view", "BART")
|
|
metar_view_page = view_stack.add_titled(metar_box, "metar_view", "Metar")
|
|
|
|
act_view_page.set_icon_name("go-home")
|
|
bart_view_page.set_icon_name("view-grid")
|
|
metar_view_page.set_icon_name("weather-clear")
|
|
|
|
with view_stack:
|
|
set_visible_child_name "act_view"
|
|
vexpand = true
|
|
|
|
with switcher_bar:
|
|
reveal = true
|
|
stack = view_stack
|
|
valign = Align.end
|
|
|
|
with act_box:
|
|
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
|
|
|
|
with header:
|
|
pack_end refresh_button
|
|
|
|
with metar_list:
|
|
selectionMode = SelectionMode.none
|
|
showSeparators = true
|
|
addMetars(metar_list)
|
|
|
|
with refresh_button:
|
|
iconName = "view-refresh"
|
|
|
|
with home_label:
|
|
text = client.home_predictions().cstring
|
|
marginTop = 10
|
|
marginBottom = 10
|
|
marginStart = 10
|
|
marginEnd = 10
|
|
halign = Align.start
|
|
|
|
with office_label:
|
|
text = client.office_predictions().cstring
|
|
marginTop = 10
|
|
marginBottom = 10
|
|
marginStart = 10
|
|
marginEnd = 10
|
|
hexpand = true
|
|
halign = Align.start
|
|
|
|
refresh_button.connect("clicked", button_refresh_signal, (view_stack, home_label, office_label, metar_list))
|
|
|
|
with window:
|
|
title = "Toolbox"
|
|
defaultSize = (300, 500)
|
|
content = main_box
|
|
show()
|
|
|
|
proc initAdw(app: adw.Application) =
|
|
adw.init()
|
|
|
|
proc main =
|
|
let app = adw.newApplication("space.quietfeathers.toolbox", {})
|
|
app.connect("startup", initAdw)
|
|
app.connect("activate", activate)
|
|
discard run(app)
|
|
|
|
main()
|