Initial commit

This commit is contained in:
2022-08-07 00:42:07 -07:00
commit f93e429a64
3 changed files with 101 additions and 0 deletions

83
toolbox.nim Normal file
View File

@@ -0,0 +1,83 @@
import gintro/[gtk4, gobject, gio, adw]
import std/[httpclient, with]
import strformat
import actransit
proc home_predictions: string =
let client = newHttpClient()
const home_nl = "51067"
const home_12 = "58995"
const home_29 = "56557"
let nl_predictions = client.get_predictions(home_nl, "NL").format_predictions
let twelve_predictions = client.get_predictions(home_12, "12").format_predictions
let twenty_nine_predictions = client.get_predictions(home_29, "29").format_predictions
&"Home\nNL: {nl_predictions}\n12: {twelve_predictions}\n29: {twenty_nine_predictions}"
proc office_predictions: string =
let client = newHttpClient()
const office_nl = "56565"
const office_12 = "57111"
let nl_predictions = client.get_predictions(office_nl, "NL").format_predictions
let twelve_predictions = client.get_predictions(office_12, "12").format_predictions
&"Oakland Office\nNL: {nl_predictions}\n12: {twelve_predictions}"
proc activate(app: adw.Application) =
let
window = adw.newApplicationWindow(app)
home_label = newLabel()
office_label = newLabel()
refresh_button = newButtonFromIconName("view-refresh")
header = adw.newHeaderBar()
mainBox = newBox(Orientation.vertical, 0)
with mainBox:
append header
append home_label
append office_label
with header:
pack_end refresh_button
with refresh_button:
iconName = "view-refresh"
with home_label:
text = home_predictions().cstring
marginTop = 10
marginBottom = 10
marginStart = 10
marginEnd = 10
with office_label:
text = office_predictions().cstring
marginTop = 10
marginBottom = 10
marginStart = 10
marginEnd = 10
proc button_refresh_signal(b: Button, labels: tuple[home: Label, office: Label]) =
labels.home.text = home_predictions().cstring
labels.office.text = office_predictions().cstring
refresh_button.connect("clicked", button_refresh_signal, (home_label, office_label))
with window:
title = "Toolbox"
defaultSize = (300, 500)
content = mainBox
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()