-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.go
85 lines (68 loc) · 1.56 KB
/
display.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"flag"
"log"
"runtime"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
)
func tm() string {
return time.Now().Format("3:04:05")
}
func main() {
stop := flag.Int("stop", 74640, "bus stop code")
flag.Parse()
myApp := app.New()
myWindow := myApp.NewWindow("List Data")
bottomRight := text(tm())
bottomRight.TextSize = 40
bottomRight.Alignment = fyne.TextAlignTrailing
bottomLeft := text("weather")
bottomLeft.TextSize = 32
weatherUpdate(bottomLeft)
bottom := container.New(
layout.NewGridLayout(2), bottomLeft, bottomRight,
)
go weatherLoop(bottomLeft)
go clockUpdate(bottomRight)
centre := newTimeTable(*stop)
centre.start()
border := container.New(layout.NewBorderLayout(
layout.NewSpacer(), bottom,
layout.NewSpacer(), layout.NewSpacer()), centre.c, bottom)
myWindow.SetContent(border)
go centre.displayLoop()
if runtime.GOOS == "linux" {
myWindow.SetFullScreen(true)
}
myWindow.ShowAndRun()
}
func clockUpdate(bottom *canvas.Text) {
tick := time.NewTicker(time.Second)
for range tick.C {
bottom.Text = tm()
bottom.Refresh()
}
}
func weatherLoop(w *canvas.Text) {
tick := time.NewTicker(time.Hour)
for range tick.C {
weatherUpdate(w)
}
}
func weatherUpdate(w *canvas.Text) {
weather, err := GetWeather()
if err != nil {
log.Println("could not get weather", err)
w.Text = "Weather Error"
} else if len(weather) > 0 {
w.Text = weather[0].String()
log.Println("setting bottom left to ", w.Text)
}
w.Show()
w.Refresh()
}