dynamically add tabs. work around the JSON config file problem

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-07 14:54:08 -07:00
parent e4233a1251
commit dc3f440e47
5 changed files with 60 additions and 13 deletions

View File

@ -95,6 +95,10 @@ func parseConfig() {
log.Println(config.String("map1.key1.jwc1")) log.Println(config.String("map1.key1.jwc1"))
cloud := config.StringMap("cloud") for account, _ := range config.StringMap("cloud") {
fmt.Printf("%#v\n",cloud) port := config.String("cloud." + account + ".port")
proto := config.String("cloud." + account + ".proto")
hostname := config.String("cloud." + account + ".hostname")
fmt.Println(hostname, port, proto)
}
} }

View File

@ -9,7 +9,13 @@
], ],
"baseKey": "value2", "baseKey": "value2",
"cloud": { "cloud": {
"v000185.testing.com.customers.wprod.wit.com": { "jcarr": {
"hostname": "fire.lab.wit.com",
"port": 3333,
"proto": "tcp"
},
"v000185": {
"hostname": "v000185.testing.com.customers.wprod.wit.com",
"port": 3333, "port": 3333,
"proto": "tcp" "proto": "tcp"
} }

View File

@ -8,6 +8,12 @@ cloud:
v000185.testing.com.customers.wprod.wit.com: v000185.testing.com.customers.wprod.wit.com:
port: 3333 port: 3333
proto: tcp proto: tcp
jcarr:
port: 3333
proto: tcp
foo.bar:
port: 3333
proto: tcp
map1: map1:
key1: key1:

35
gui.go
View File

@ -13,6 +13,8 @@ import _ "github.com/andlabs/ui/winmanifest"
// import "github.com/davecgh/go-spew/spew" // import "github.com/davecgh/go-spew/spew"
var mainwin *ui.Window var mainwin *ui.Window
var maintab *ui.Tab
var tabcount int
func hostnameButton(hostname string) ui.Control { func hostnameButton(hostname string) ui.Control {
tmpbox := ui.NewHorizontalBox() tmpbox := ui.NewHorizontalBox()
@ -242,25 +244,38 @@ func setupUI() {
return true return true
}) })
tab := ui.NewTab() maintab = ui.NewTab()
mainwin.SetChild(tab) mainwin.SetChild(maintab)
mainwin.SetMargined(true) mainwin.SetMargined(true)
name := "v000185.testing.com.customers.wprod.wit.com" name := "v000185.testing.com.customers.wprod.wit.com"
tab.Append(name, makeDemotable(name)) maintab.Append(name, makeDemotable(name))
tab.SetMargined(0, true) tabcount = 0
maintab.SetMargined(tabcount, true)
name = "jcarrTable" name = "jcarrTable"
table, mh, model := makeJcarrtable(name) table, mh, model := makeJcarrtable(name)
log.Println(table, mh, model) log.Println(table, mh, model)
tab.Append(name, table) maintab.Append(name, table)
tab.SetMargined(1, true) tabcount += 1
maintab.SetMargined(tabcount, true)
tab.Append("List examples", makeNumbersPage()) maintab.Append("List examples", makeNumbersPage())
tab.SetMargined(2, true) tabcount += 1
maintab.SetMargined(tabcount, true)
tab.Append("Choosers examples", makeDataChoosersPage()) maintab.Append("Choosers examples", makeDataChoosersPage())
tab.SetMargined(3, true) tabcount += 1
maintab.SetMargined(tabcount, true)
mainwin.Show() mainwin.Show()
} }
func addTableTab(name string) {
table, mh, model := makeJcarrtable(name)
log.Println(table, mh, model)
tabcount += 1
maintab.Append(name, table)
maintab.SetMargined(tabcount, true)
}

16
main.go
View File

@ -72,6 +72,22 @@ func main() {
go doGUI() go doGUI()
log.Println("Sleep for 2 seconds, then try to add new tabs")
time.Sleep(2 * 1000 * 1000 * 1000)
log.Println("Sleep for 2 seconds, then try to add new tabs")
time.Sleep(2 * 1000 * 1000 * 1000)
log.Println("Sleep for 2 seconds, then try to add new tabs")
time.Sleep(2 * 1000 * 1000 * 1000)
for account, _ := range config.StringMap("cloud") {
port := config.String("cloud." + account + ".port")
proto := config.String("cloud." + account + ".proto")
hostname := config.String("cloud." + account + ".hostname")
fmt.Println(hostname, port, proto)
addTableTab(account)
}
for { for {
log.Println("Sleep for 10 seconds, then try to establish connection to WIT") log.Println("Sleep for 10 seconds, then try to establish connection to WIT")