-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.go
123 lines (113 loc) · 3.05 KB
/
gui.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"github.com/pkg/browser"
"github.com/sqweek/dialog"
)
var mainWindow *walk.MainWindow
var statusLink *walk.LinkLabel
func runWindowsUI() {
var timetableLabel *walk.Label
var userEdit, passwordEdit, addressEdit *walk.LineEdit
var connectButton, chooseButton *walk.PushButton
MainWindow{
AssignTo: &mainWindow,
Title: "SimSig Departure Board",
Size: Size{200, 270},
MinSize: Size{200, 270},
MaxSize: Size{600, 270},
Layout: VBox{},
Children: []Widget{
Label{
Text: "SimSig Departure Board",
Font: Font{PointSize: 18, Bold: true},
},
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
PushButton{
AssignTo: &chooseButton,
Text: "Choose Timetable",
OnClicked: func() {
var filename string
var err error
filename, err = dialog.File().Title("Select Active SimSig WTT").SetStartDir("C:\\Users\\Public\\Documents\\SimSig\\Timetables").Filter("SimSig WTT(*.WTT)", "wtt").Load()
if err != nil {
walk.MsgBox(mainWindow, "Timetable Load Error", err.Error(), walk.MsgBoxOK|walk.MsgBoxIconError)
return
}
result := loadTimetable(filename)
if result != "" {
walk.MsgBox(mainWindow, "Timetable Load Error", result, walk.MsgBoxOK|walk.MsgBoxIconError)
} else {
timetableLabel.SetText(filename)
connectButton.SetEnabled(true)
chooseButton.SetEnabled(false)
}
},
},
Label{
AssignTo: &timetableLabel,
Text: "No timetable selected",
EllipsisMode: EllipsisPath,
},
Label{
Text: "User:",
TextAlignment: AlignFar,
},
LineEdit{AssignTo: &userEdit},
Label{
Text: "Password:",
TextAlignment: AlignFar,
},
LineEdit{
AssignTo: &passwordEdit,
PasswordMode: true,
},
Label{
Text: "Interface Gateway:",
TextAlignment: AlignFar,
},
LineEdit{
AssignTo: &addressEdit,
Text: "localhost:51515",
},
},
},
PushButton{
AssignTo: &connectButton,
Text: "Connect",
Enabled: false,
OnClicked: func() {
statusLink.SetText("Connecting to " + addressEdit.Text())
connectButton.SetEnabled(false)
go gatewayConnection(userEdit.Text(), passwordEdit.Text(), addressEdit.Text())
},
},
LinkLabel{
AssignTo: &statusLink,
//MaxSize: Size{500, 0},
Text: `Not Connected to SimSig`,
OnLinkActivated: func(link *walk.LinkLabelLink) {
browser.OpenURL("http://localhost:8090/")
},
},
},
}.Run()
}
func updateStatus(status string) {
mainWindow.Synchronize(func() {
statusLink.SetText(status)
})
}
func webInterfaceReady() {
mainWindow.Synchronize(func() {
statusLink.SetText("<a href=\"http://localhost:8090\">Open Departure Board</a>")
})
}
func showError(message string) {
mainWindow.Synchronize(func() {
walk.MsgBox(mainWindow, "Error", message, walk.MsgBoxOK|walk.MsgBoxIconError)
})
}