try to stabilize the GUI
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
745ef852ef
commit
baecdd3d58
51
infoTabUI.go
51
infoTabUI.go
|
@ -4,20 +4,17 @@ import "log"
|
||||||
// import "time"
|
// import "time"
|
||||||
// import "fmt"
|
// import "fmt"
|
||||||
|
|
||||||
// import "github.com/gookit/config"
|
import "github.com/gookit/config"
|
||||||
|
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
import _ "github.com/andlabs/ui/winmanifest"
|
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 jwcmainwin *ui.Window
|
||||||
// var maintab *ui.Tab
|
var jwcmaintab *ui.Tab
|
||||||
|
var tabcount int
|
||||||
|
|
||||||
// var tabcount int
|
|
||||||
|
|
||||||
// var jcarrButton *ui.Button
|
|
||||||
// var jcarrEntry *ui.MultilineEntry
|
|
||||||
|
|
||||||
func makeCloudInfoBox() ui.Control {
|
func makeCloudInfoBox() ui.Control {
|
||||||
hbox := ui.NewHorizontalBox()
|
hbox := ui.NewHorizontalBox()
|
||||||
|
@ -38,6 +35,7 @@ func makeCloudInfoBox() ui.Control {
|
||||||
log.Println("send over socket")
|
log.Println("send over socket")
|
||||||
})
|
})
|
||||||
vbox.Append(mybutton, false)
|
vbox.Append(mybutton, false)
|
||||||
|
vbox.Append(ui.NewLabel("Hostname:"), false)
|
||||||
|
|
||||||
hbox.Append(ui.NewVerticalSeparator(), false)
|
hbox.Append(ui.NewVerticalSeparator(), false)
|
||||||
|
|
||||||
|
@ -119,5 +117,44 @@ func makeCloudInfoBox() ui.Control {
|
||||||
1, 0, 1, 1,
|
1, 0, 1, 1,
|
||||||
false, ui.AlignFill, false, ui.AlignFill)
|
false, ui.AlignFill, false, ui.AlignFill)
|
||||||
|
|
||||||
|
vbox.Append(ui.NewLabel("Hostname:"), false)
|
||||||
|
vbox.Append(ui.NewLabel("librem15.lab.wit.com"), false)
|
||||||
|
|
||||||
|
|
||||||
|
entryForm := ui.NewForm()
|
||||||
|
entryForm.SetPadded(true)
|
||||||
|
vbox.Append(entryForm, false)
|
||||||
|
|
||||||
|
hostnameEntry := ui.NewEntry()
|
||||||
|
entryForm.Append("hostname:", hostnameEntry, false)
|
||||||
|
hostnameEntry.SetText("librem15.lab.wit.com")
|
||||||
|
|
||||||
|
IPv6entry := ui.NewEntry()
|
||||||
|
entryForm.Append("IPv6:", IPv6entry, false)
|
||||||
|
IPv6entry.SetText("2604:bbc0:3:3:0:10:0:1003")
|
||||||
|
|
||||||
return hbox
|
return hbox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupCloudUI() {
|
||||||
|
jwcmainwin = ui.NewWindow("Cloud Control Panel", config.Int("width"), config.Int("height"), false)
|
||||||
|
jwcmainwin.OnClosing(func(*ui.Window) bool {
|
||||||
|
ui.Quit()
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
ui.OnShouldQuit(func() bool {
|
||||||
|
jwcmainwin.Destroy()
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
jwcmaintab = ui.NewTab()
|
||||||
|
jwcmainwin.SetChild(jwcmaintab)
|
||||||
|
jwcmainwin.SetMargined(true)
|
||||||
|
|
||||||
|
tabcount = 0
|
||||||
|
jwcmaintab.Append("Cloud Info", makeCloudInfoBox())
|
||||||
|
jwcmaintab.SetMargined(tabcount, true)
|
||||||
|
|
||||||
|
|
||||||
|
jwcmainwin.Show()
|
||||||
|
}
|
||||||
|
|
66
main.go
66
main.go
|
@ -7,6 +7,9 @@ import "fmt"
|
||||||
|
|
||||||
import "github.com/gookit/config"
|
import "github.com/gookit/config"
|
||||||
|
|
||||||
|
import "github.com/andlabs/ui"
|
||||||
|
import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
import "git.wit.com/wit/gui"
|
import "git.wit.com/wit/gui"
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
@ -24,32 +27,7 @@ import "git.wit.com/wit/gui"
|
||||||
// always sorted slice (new project)
|
// always sorted slice (new project)
|
||||||
// https://github.com/yaa110/sslice
|
// https://github.com/yaa110/sslice
|
||||||
|
|
||||||
func main() {
|
func add2() {
|
||||||
parseConfig()
|
|
||||||
|
|
||||||
// only test the socket code if no GUI
|
|
||||||
if (config.String("nogui") == "true") {
|
|
||||||
retrySocket()
|
|
||||||
onExit()
|
|
||||||
}
|
|
||||||
|
|
||||||
go gui.DoGUI()
|
|
||||||
go retrySocket()
|
|
||||||
|
|
||||||
//
|
|
||||||
// NOTE: This needs to be something long like 2 seconds.
|
|
||||||
// Not sure way. Otherwise it will hang GTK
|
|
||||||
//
|
|
||||||
/*
|
|
||||||
log.Println("Sleep for 2 seconds, then try to add new tabs")
|
|
||||||
time.Sleep(1 * 1000 * 1000 * 1000)
|
|
||||||
gui.AddChoosersDemo()
|
|
||||||
*/
|
|
||||||
|
|
||||||
log.Println("Sleep for 2 seconds, then try to add new tabs")
|
|
||||||
time.Sleep(1 * 1000 * 1000 * 1000)
|
|
||||||
gui.AddNewTab(makeCloudInfoBox())
|
|
||||||
|
|
||||||
var parts []gui.InputData
|
var parts []gui.InputData
|
||||||
|
|
||||||
for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} {
|
for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} {
|
||||||
|
@ -64,22 +42,24 @@ func main() {
|
||||||
log.Println("Sleep for 2 seconds, then try to add new tabs")
|
log.Println("Sleep for 2 seconds, then try to add new tabs")
|
||||||
time.Sleep(1 * 1000 * 1000 * 1000)
|
time.Sleep(1 * 1000 * 1000 * 1000)
|
||||||
gui.AddTableTab("test seven", 7, parts)
|
gui.AddTableTab("test seven", 7, parts)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
parseConfig()
|
||||||
|
|
||||||
|
// only test the socket code if no GUI
|
||||||
|
if (config.String("nogui") == "true") {
|
||||||
|
retrySocket()
|
||||||
|
onExit()
|
||||||
|
}
|
||||||
|
|
||||||
|
go retrySocket()
|
||||||
|
|
||||||
|
// make this the main loop in an attempt to figure out the crashes
|
||||||
|
// do not change this until the GUI is stable
|
||||||
|
ui.Main(setupCloudUI)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
log.Println("Sleep for 1000 seconds, then try to add new tabs")
|
|
||||||
time.Sleep(1000 * 1000 * 1000 * 1000)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
// THIS CRASHES FOR SOME REASON
|
|
||||||
log.Println("Sleep for 10 seconds, then try to add new tabs")
|
|
||||||
time.Sleep(10 * 1000 * 1000 * 1000)
|
|
||||||
gui.AddEntriesDemo()
|
|
||||||
*/
|
|
||||||
|
|
||||||
log.Println("Sleep for 2 seconds, then try to add new tabs")
|
|
||||||
time.Sleep(2 * 1000 * 1000 * 1000)
|
|
||||||
|
|
||||||
for account, _ := range config.StringMap("cloud") {
|
for account, _ := range config.StringMap("cloud") {
|
||||||
port := config.String("cloud." + account + ".port")
|
port := config.String("cloud." + account + ".port")
|
||||||
proto := config.String("cloud." + account + ".proto")
|
proto := config.String("cloud." + account + ".proto")
|
||||||
|
@ -92,11 +72,7 @@ func main() {
|
||||||
log.Println("Sleep for 10 seconds, then add next table")
|
log.Println("Sleep for 10 seconds, then add next table")
|
||||||
time.Sleep(10 * 1000 * 1000 * 1000)
|
time.Sleep(10 * 1000 * 1000 * 1000)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
for {
|
|
||||||
// TODO: figure out how to exit
|
|
||||||
time.Sleep(10 * 1000 * 1000 * 1000)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit and write out the config
|
// Exit and write out the config
|
||||||
|
|
59
socketWIT.go
59
socketWIT.go
|
@ -6,13 +6,14 @@ import "time"
|
||||||
import "net"
|
import "net"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "bufio"
|
import "bufio"
|
||||||
|
import "strings"
|
||||||
|
|
||||||
import "git.wit.com/wit/shell"
|
import "git.wit.com/wit/shell"
|
||||||
import "git.wit.com/jcarr/dnssecsocket"
|
import "git.wit.com/jcarr/dnssecsocket"
|
||||||
|
import "git.wit.com/wit/gui"
|
||||||
|
|
||||||
//import "github.com/svent/go-nbreader"
|
//import "github.com/svent/go-nbreader"
|
||||||
// import "github.com/gookit/config"
|
// import "github.com/gookit/config"
|
||||||
// import "git.wit.com/wit/gui"
|
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
|
@ -29,12 +30,31 @@ import "git.wit.com/jcarr/dnssecsocket"
|
||||||
// always sorted slice (new project)
|
// always sorted slice (new project)
|
||||||
// https://github.com/yaa110/sslice
|
// https://github.com/yaa110/sslice
|
||||||
|
|
||||||
|
var socketAlive bool = false
|
||||||
|
|
||||||
|
var connCurrent *net.TCPConn
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CONN_HOST = "v000185.testing.com.customers.wprod.wit.com"
|
CONN_HOST = "v000185.testing.com.customers.wprod.wit.com"
|
||||||
CONN_PORT = "3333"
|
CONN_PORT = "3333"
|
||||||
CONN_PROTO = "tcp"
|
CONN_PROTO = "tcp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func writelnToSocket(aline string) {
|
||||||
|
if connCurrent == nil {
|
||||||
|
fmt.Println("SOCKET IS NOT CONNECTED")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// a, err := connCurrent.Write([]byte(string(text + "\n")))
|
||||||
|
a, err := connCurrent.Write([]byte(string(aline + "\n")))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("SOCKET WRITE FAILED with err=", err, a)
|
||||||
|
connCurrent = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func socketToWIT(myhostname string) {
|
func socketToWIT(myhostname string) {
|
||||||
remoteAddr := CONN_HOST + ":" + CONN_PORT
|
remoteAddr := CONN_HOST + ":" + CONN_PORT
|
||||||
log.Println("remoteAddr:", remoteAddr)
|
log.Println("remoteAddr:", remoteAddr)
|
||||||
|
@ -49,6 +69,7 @@ func socketToWIT(myhostname string) {
|
||||||
log.Println(CONN_HOST, CONN_PORT, CONN_PROTO)
|
log.Println(CONN_HOST, CONN_PORT, CONN_PROTO)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println("socket connect failed. Not sure what to do here. os.Exit() ?")
|
log.Println("socket connect failed. Not sure what to do here. os.Exit() ?")
|
||||||
|
connCurrent = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
@ -58,7 +79,23 @@ func socketToWIT(myhostname string) {
|
||||||
tmp, err := conn.Write([]byte(string(myhostname + "\n")))
|
tmp, err := conn.Write([]byte(string(myhostname + "\n")))
|
||||||
log.Println("conn.Write:", tmp, err)
|
log.Println("conn.Write:", tmp, err)
|
||||||
|
|
||||||
connStdin, _ := conn.File()
|
if (err != nil) {
|
||||||
|
fmt.Println("SOCKET DIED with err=", err)
|
||||||
|
connCurrent = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
connStdin, err := conn.File()
|
||||||
|
|
||||||
|
if (err != nil) {
|
||||||
|
fmt.Println("SOCKET File() failed with err=", err)
|
||||||
|
connCurrent = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the socketAlive flag to true since the socket appears to be alive
|
||||||
|
socketAlive = true
|
||||||
|
connCurrent = conn
|
||||||
|
|
||||||
newreader := bufio.NewReader(connStdin)
|
newreader := bufio.NewReader(connStdin)
|
||||||
go shell.NonBlockingReader(newreader, os.Stdout)
|
go shell.NonBlockingReader(newreader, os.Stdout)
|
||||||
|
@ -70,11 +107,27 @@ func socketToWIT(myhostname string) {
|
||||||
fmt.Print("Text to send: ")
|
fmt.Print("Text to send: ")
|
||||||
text, _ := reader.ReadString('\n')
|
text, _ := reader.ReadString('\n')
|
||||||
|
|
||||||
|
text = strings.TrimSpace(text) // this is like perl chomp
|
||||||
|
log.Println("LINE WAS:", text)
|
||||||
|
log.Println("LINE WAS:", text)
|
||||||
|
log.Println("LINE WAS:", text)
|
||||||
|
|
||||||
|
if (text == "ADD") {
|
||||||
|
tmp := makeCloudInfoBox()
|
||||||
|
time.Sleep(1 * 1000 * 1000 * 1000)
|
||||||
|
gui.AddNewTab(jwcmaintab, tmp, 0)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text == "ADD2") {
|
||||||
|
add2()
|
||||||
|
continue
|
||||||
|
}
|
||||||
// send the command over the socket socket
|
// send the command over the socket socket
|
||||||
a, err := conn.Write([]byte(string(text + "\n")))
|
a, err := conn.Write([]byte(string(text + "\n")))
|
||||||
|
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
fmt.Println("SOCKET DIED with err=", err, a)
|
fmt.Println("SOCKET WRITE FAILED with err=", err, a)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue