diff --git a/.gitignore b/.gitignore index 74bffcc..c051da5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,14 @@ *.swp cloud-control-panel + example-gui/example-gui example-systray/example-systray example-UI-table/example-UI-table -example-dnssecsocket/example-dnssecsocket example-table/example-table example-aminal/example-aminal example-multiple-windows/example-multiple-windows +example-lookupAAAA/example-lookupAAAA test1/test1 test2/test2 diff --git a/example-UI-table/Makefile b/example-UI-table/Makefile deleted file mode 100644 index 84a5618..0000000 --- a/example-UI-table/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -run: - go run *.go - -build: - go build diff --git a/example-UI-table/main.go b/example-UI-table/main.go deleted file mode 100644 index 0f14127..0000000 --- a/example-UI-table/main.go +++ /dev/null @@ -1,67 +0,0 @@ -package main - -import "log" -import "fmt" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -import "git.wit.com/wit/gui" - -var cloudwin *ui.Window -var cloudtab *ui.Tab -var tabcount int - -func main() { - // 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) -} - -// can not pass any args to this (?) -func setupCloudUI() { - cloudwin = ui.NewWindow("Cloud Control Panel", 640, 480, false) - cloudwin.OnClosing(func(*ui.Window) bool { - ui.Quit() - return true - }) - ui.OnShouldQuit(func() bool { - cloudwin.Destroy() - return true - }) - - cloudtab = ui.NewTab() - cloudwin.SetChild(cloudtab) - cloudwin.SetMargined(true) - - tabcount = 0 - addTableTab() -// cloudtab.Append("Cloud Info", makeCloudInfoBox()) -// cloudtab.SetMargined(tabcount, true) - - cloudwin.Show() -} - -func addTableTab() { - var parts []gui.TableColumnData - - for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} { - log.Println(key, foo) - - var b gui.TableColumnData - b.CellType = foo - b.Heading = fmt.Sprintf("heading%d", key) - parts = append(parts, b) - } - mh := gui.AddTableTab(cloudtab, 0, "test seven", 7, parts) - - // set some test values as an example - mh.Rows[1].HumanData[1].Text = "jwctest1" - mh.Rows[2].HumanData[2].Text = "jwctest2" - mh.Rows[3].HumanData[3].Text = "jwctest3" - mh.Rows[3].HumanData[4].Text = "jwctest4" - mh.Rows[2].HumanData[5].Text = "jwctest5" - mh.Rows[3].HumanData[6].Text = "jwctest6" - mh.Rows[4].HumanData[7].Text = "jwctest7" - mh.Rows[5].HumanData[8].Text = "jwctest8" -} diff --git a/example-aminal/Makefile b/example-aminal/Makefile index 21397e9..40646b7 100644 --- a/example-aminal/Makefile +++ b/example-aminal/Makefile @@ -1,6 +1,6 @@ build: go build - example-aminal + ./example-aminal build-windows: diff --git a/example-dnssecsocket/Makefile b/example-dnssecsocket/Makefile deleted file mode 100644 index 5f03483..0000000 --- a/example-dnssecsocket/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - go build diff --git a/example-dnssecsocket/config.go b/example-dnssecsocket/config.go deleted file mode 100644 index 39b6207..0000000 --- a/example-dnssecsocket/config.go +++ /dev/null @@ -1,109 +0,0 @@ -package main - -/* - This simply parses the command line arguments using the default golang - package called 'flag'. This can be used as a simple template to parse - command line arguments in other programs. - - It puts everything in the 'config' package which I think is a good - wrapper around the 'flags' package and doesn't need a whole mess of - global variables -*/ - -import "log" -import "os" -import "flag" -import "fmt" -import "github.com/gookit/config" -import "github.com/gookit/config/yaml" -import "github.com/gookit/config/json" - -// import "github.com/davecgh/go-spew/spew" - -var customUsage = func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0]) - flag.PrintDefaults() - - fmt.Println("") - fmt.Println("EXAMPLES:") - fmt.Println("") - fmt.Println(os.Args[0] + "--hostname test.hostname.wit.com") - fmt.Println("") -} - -func parseFlags() { - var version string - var nogui bool - var hostname string - var width int - var height int - - flag.StringVar (&version, "version", "v0.1", "Set compiled in version string") - - flag.StringVar (&hostname, "hostname", "localhost", "Your full hostname") - flag.IntVar (&width, "width", 400, "Width of the Window") - flag.IntVar (&height, "height", 600, "Height of the Window") - - flag.BoolVar (&nogui, "nogui", nogui, "Do not display the GUI") - - // Set the output if something fails to stdout rather than stderr - flag.CommandLine.SetOutput(os.Stdout) - - flag.Usage = customUsage - flag.Parse() - - if flag.Parsed() { - log.Println("flag.Parse() worked") - } else { - log.Println("flag.Parse() failed") - } - - config.Set("width", width) - config.Set("height", height) - config.Set("hostname", hostname) - config.Set("nogui", nogui) -} - -func parseConfig() { - config.WithOptions(config.ParseEnv) - parseFlags() - - config.LoadOSEnv([]string{"MAIL"}) - config.LoadOSEnv([]string{"USER"}) - config.LoadOSEnv([]string{"BUILDDEBUG"}) - -/* - urls := flag.Args() - log.Println("flag.Aargs() = ", urls) - - for _, addr := range flag.Args() { - log.Println("GET %s", addr) - } -*/ - - // add driver for support of yaml and json - config.AddDriver(yaml.Driver) - config.AddDriver(json.Driver) - - config.LoadFiles("config.json") - - for _, addr := range config.Strings("arr1") { - log.Println("addr =", addr) - } - - map1 := config.StringMap("map1") - fmt.Printf("%#v\n",map1) - - log.Println(config.String("map1.key1.jwc1")) - - 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) - } - - if (config.String("nogui") == "true") { - log.Println("DO NOT DISPLAY THE GUI") - } -} diff --git a/example-dnssecsocket/eventChannel.go b/example-dnssecsocket/eventChannel.go deleted file mode 100644 index cdabebc..0000000 --- a/example-dnssecsocket/eventChannel.go +++ /dev/null @@ -1,151 +0,0 @@ -package main - -import "fmt" -import "log" -import "net" -import "os" -import "io" -import "bytes" -import "strconv" - -import "github.com/golang/protobuf/proto" -import pb "git.wit.com/wit/witProtobuf" - -import "git.wit.com/wit/gui" - -var mychannel chan *pb.Event - -func initChannel() { - mychannel = make(chan *pb.Event) -} - -// func processEvents(mychannel chan *pb.Event) { -func processEvents() { - for { - message := <-mychannel - log.Println("processEvents() on channel recieved a message = ", message) - mh := addVmsTab(30) - ReadReceivedData(message, mh) - if (message.Type == pb.Event_DEMO) { - log.Println("processEvents() do Event DEMO") - } - } -} - -func ReadReceivedData(data *pb.Event, mh *gui.TableData) { - msgItems := data.GetResults() - log.Println("ReadReceivedData() Event msgItems=", msgItems) - for _, item := range msgItems { - log.Println(item) - } - - nets := data.GetNetworks() - log.Println("ReadReceivedData() Event networks=", nets) - for _, item := range nets { - log.Println(item) - } - - vms := data.GetVms() - log.Println("ReadReceivedData() Event vms=", vms) - row := 0 - for _, item := range vms { - mh.Rows[row].HumanData[3].Text = item.Name - log.Println(item) - row += 1 - } - - log.Println("ReadReceivedData() mh rows") - for row := 0; row < mh.RowCount; row++ { - log.Println("\trow=", row) - } -} - -func handleProtoClient(conn net.Conn) { - fmt.Println("Connected!") - defer conn.Close() - var buf bytes.Buffer - _, err := io.Copy(&buf, conn) - if err != nil { - fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error()) - return - } - pdata := pb.CreateSampleEvent() - err = proto.Unmarshal(buf.Bytes(), pdata) - if err != nil { - fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error()) - return - } - mychannel <- pdata -} - -// Marshal & Unmarshal just to see if it ever fails -func addEvent(msg *pb.Event) { - data, err := proto.Marshal(msg) - if (err != nil) { - log.Printf("addEvent() something fucked up happened in Marshal") - } - - pdata := new(pb.Event) - err = proto.Unmarshal(data, pdata) - if (err != nil) { - log.Printf("addEvent() something fucked up happened in Unmarshal") - } - - mychannel <- pdata -} - -func addSampleEvent() { - msg := pb.CreateSampleEvent() - msg.Name = "generated in addSampleEvent()" - - data, err := proto.Marshal(msg) - if (err != nil) { - log.Printf("addSampleEvent() something fucked up happened in Marshal") - } - - pdata := new(pb.Event) - err = proto.Unmarshal(data, pdata) - if (err != nil) { - log.Printf("addSampleEvent() something fucked up happened in Unmarshal") - } - - mychannel <- pdata -} - -func sendEventToWIT() { - msg := pb.CreateSampleEvent() - - var mybuf []byte - mybuf, err := proto.Marshal(msg) - if (err != nil) { - log.Printf("something fucked up happened") - } - writeBytesToSocket(mybuf) -} - -func sendDataToDest() { - msg := pb.CreateSampleEvent() - msg.Name = "from dnssecsockettest()" - - data, err := proto.Marshal(msg) - if (err != nil) { - log.Printf("something fucked up happened") - } - - conn, err := net.Dial("tcp", "localhost:8080") - if err != nil { - log.Println("Fatal error: %s", err.Error()) - return - } - n, err := conn.Write(data) - if err != nil { - // fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error()) - log.Println("Fatal error: %s", err.Error()) - return - } - - pb.DumpEventData(msg) - log.Println("Sent " + strconv.Itoa(n) + " bytes") - // time.Sleep(3 * 1000 * 1000 * 1000) - conn.Close() -} diff --git a/example-dnssecsocket/gorilla.go b/example-dnssecsocket/gorilla.go deleted file mode 100644 index 1c4d85f..0000000 --- a/example-dnssecsocket/gorilla.go +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2015 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -// import "flag" -import "log" -import "net/url" -import "os" -import "os/signal" -import "time" - -import "github.com/gorilla/websocket" - -import "github.com/golang/protobuf/proto" -import pb "git.wit.com/wit/witProtobuf" - -var gorillaConn *websocket.Conn - -func readGorillaConn(conn *websocket.Conn) { - for { - mytype, message, err := conn.ReadMessage() - if err != nil { - log.Println("read:", err) - return - } - if (mytype == websocket.BinaryMessage) { - protobufMsg := new(pb.Event) - err = proto.Unmarshal(message, protobufMsg) - if (err != nil) { - log.Printf("readConn() something fucked up happened in Unmarshal") - } - log.Printf("readGorillaConn() successfully read protobuf from gorilla websocket") - addEvent(protobufMsg) - } else { - log.Printf("recv: %s", message) - // log.Printf("type, err = ", mytype, err) - } - time.Sleep(time.Second) - log.Println("gorilla readGorillaConn()", time.Now()) - } -} - -func gorillaSendProtobuf() { - if (gorillaConn == nil) { - log.Println("gorillaSendProtobuf() gorillaConn == nil") - log.Println("Need to re-open connection here") - return - } - msg := pb.CreateSampleEvent() - msg.Name = "test echo over gorilla websocket" - data, _ := proto.Marshal(msg) - err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, data) - if err2 != nil { - log.Println("write:", err2) - gorillaConn = nil - return - } -} - -func closeGorillaConn() { - if gorillaConn == nil { - log.Println("gorillaConn already was nil") - return - } - - // Cleanly close the connection by sending a close message and then - // waiting (with timeout) for the server to close the connection. - err := gorillaConn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) - if err != nil { - log.Println("write close:", err) - return - } - - // this must be called or set to be called with defer - gorillaConn.Close() - gorillaConn = nil -} - -func gorillaDial(hostname string) { - // var addr = flag.String("addr", "v000185.testing.com.customers.wprod.wit.com:9000", "http service address") - - for { - // u := url.URL{Scheme: "ws", Host: *addr, Path: "/event"} - u := url.URL{Scheme: "ws", Host: hostname, Path: "/event"} - log.Printf("connecting to %s", u.String()) - - conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil) - if err != nil { - log.Println("gorilla Dial failed", err) - } else { - gorillaConn = conn - - // handle inbound messages on the channel - readGorillaConn(conn) - closeGorillaConn() - } - - time.Sleep(time.Second * 5) // try every 5 seconds - } -} - -// -// this is a facinating code snippet that I wanted to leave here because it is -// so interesting. Complements to the gorilla websocket example developers -// -func beautifulAndFacinatingChannel() { - done := make(chan struct{}) - - interrupt := make(chan os.Signal, 1) - signal.Notify(interrupt, os.Interrupt) - - ticker := time.NewTicker(time.Second * 1) - - defer ticker.Stop() - defer close(done) - - for { - select { - case <-done: - return - case t := <-ticker.C: - log.Println("gorilla NewTicker()", t.String()) - case <-interrupt: - log.Println("interrupt") - - gorillaSendProtobuf() - - // not sure what this does. nothing right? - select { - case <-done: - case <-time.After(time.Second): - } - return - } - } -} diff --git a/example-dnssecsocket/infoTabUI.go b/example-dnssecsocket/infoTabUI.go deleted file mode 100644 index 12840e8..0000000 --- a/example-dnssecsocket/infoTabUI.go +++ /dev/null @@ -1,243 +0,0 @@ -package main - -import "log" -import "time" -import "fmt" -import "runtime/debug" -import "runtime" - -import "github.com/gookit/config" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -import "git.wit.com/wit/gui" - -// import "github.com/davecgh/go-spew/spew" - -var cloudwin *ui.Window -var cloudtab *ui.Tab -var tabcount int - -func makeCloudInfoBox() ui.Control { - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - hbox.Append(vbox, false) - - vbox.Append(ui.NewColorButton(), false) - - mybutton := ui.NewButton("cpuinfo") - mybutton.OnClicked(func(*ui.Button) { - log.Println("send over socket") - writelnToSocket("cpuinfo") - }) - vbox.Append(mybutton, false) - - // VM list test button - listVMbutton := ui.NewButton("list") - listVMbutton.OnClicked(func(*ui.Button) { - log.Println("send over socket") - writelnToSocket("list") - }) - vbox.Append(listVMbutton, false) - - vbox.Append(ui.NewLabel("Debugging:"), false) - - // ATTEMPT TO ADD THE TABLE HERE - add2button := ui.NewButton("Add a Test Table") - add2button.OnClicked(func(*ui.Button) { - log.Println("send over socket") - addTableTab() - }) - vbox.Append(add2button, false) - // ATTEMPT TO ADD THE TABLE HERE END - - hbox.Append(ui.NewVerticalSeparator(), false) - - // Send a test protobuf Event to localhost - add3button := ui.NewButton("Add buf to chann") - add3button.OnClicked(func(*ui.Button) { - log.Println("add protobuf event to the channel") - addSampleEvent() - }) - vbox.Append(add3button, false) - - // Send a protobuf Event over the WIT socket - add4button := ui.NewButton("Send protobuf to Event Channel") - add4button.OnClicked(func(*ui.Button) { - log.Println("sent a protobuf over the TCP socket") - sendEventToWIT() - }) - vbox.Append(add4button, false) - - // Send a protobuf Event over the WIT socket - add5button := ui.NewButton("Send protobuf to localhost") - add5button.OnClicked(func(*ui.Button) { - log.Println("sent a Marshal'd protobuf to a localhost socket") - sendDataToDest() - }) - vbox.Append(add5button, false) - - // Send a protobuf over a gorilla websocket - add6button := ui.NewButton("gorillaSendProtobuf()") - add6button.OnClicked(func(*ui.Button) { - log.Println("gorillaSendProtobuf()") - gorillaSendProtobuf() - }) - vbox.Append(add6button, false) - - // debug all the golang goroutines - add7button := ui.NewButton("debug.PrintStack()") - add7button.OnClicked(func(*ui.Button) { - log.Println("debug.PrintStack() (SHOULD BE JUST THIS goroutine)") - debug.PrintStack() - - log.Println("ATTEMPT FULL STACK DUMP") - log.Println("ATTEMPT FULL STACK DUMP") - log.Println("ATTEMPT FULL STACK DUMP") - buf := make([]byte, 1<<16) - runtime.Stack(buf, true) - fmt.Printf("%s", buf) - }) - vbox.Append(add7button, false) - - hbox.Append(ui.NewVerticalSeparator(), false) - - vbox = ui.NewVerticalBox() - vbox.SetPadded(true) - hbox.Append(vbox, true) - - grid := ui.NewGrid() - grid.SetPadded(true) - vbox.Append(grid, false) - - msggrid := ui.NewGrid() - msggrid.SetPadded(true) - - 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 -} - -func setupCloudUI() { - cloudwin = ui.NewWindow("Cloud Control Panel", config.Int("width"), config.Int("height"), false) - cloudwin.OnClosing(func(*ui.Window) bool { - ui.Quit() - return true - }) - ui.OnShouldQuit(func() bool { - cloudwin.Destroy() - return true - }) - - cloudtab = ui.NewTab() - cloudwin.SetChild(cloudtab) - cloudwin.SetMargined(true) - - tabcount = 0 - cloudtab.Append("Cloud Info", makeCloudInfoBox()) - cloudtab.SetMargined(tabcount, true) - - cloudwin.Show() -} - -func addTableTab() { - var parts []gui.TableColumnData - - for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} { - log.Println(key, foo) - - var b gui.TableColumnData - b.CellType = foo - b.Heading = fmt.Sprintf("heading%d", key) - parts = append(parts, b) - } - - log.Println("Sleep for 2 seconds, then try to add new tabs") - time.Sleep(1 * 1000 * 1000 * 1000) - gui.AddTableTab(cloudtab, 1, "test seven", 7, parts) -} - -func addProtobufTab() { - var parts []gui.TableColumnData - - for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} { - log.Println(key, foo) - - var b gui.TableColumnData - b.CellType = foo - b.Heading = fmt.Sprintf("heading%d", key) - parts = append(parts, b) - } - - log.Println("Sleep for 2 seconds, then try to add new tabs") - time.Sleep(1 * 1000 * 1000 * 1000) - gui.AddTableTab(cloudtab, 1, "test seven", 7, parts) -} - -type aheader struct { - headtype string - name string -} - -func addVmsTab(count int) *gui.TableData { - var parts []gui.TableColumnData - - human := 0 - - tmp := gui.TableColumnData{} - tmp.CellType = "BG" - tmp.Heading = "background" - tmp.Index = human - parts = append(parts, tmp) - human += 1 - - tmp = gui.TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "name" - tmp.Index = human - parts = append(parts, tmp) - - tmp = gui.TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "hostname" - tmp.Index = human - parts = append(parts, tmp) - - tmp = gui.TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "IPv6" - tmp.Index = human - parts = append(parts, tmp) - - tmp = gui.TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "cpus" - parts = append(parts, tmp) - - tmp = gui.TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "memory" - parts = append(parts, tmp) - - tmp = gui.TableColumnData{} - tmp.CellType = "BUTTON" - tmp.Heading = "Details" - parts = append(parts, tmp) - - mh := gui.AddTableTab(cloudtab, 1, "Virtual Machines", count, parts) - return mh -} diff --git a/example-dnssecsocket/main.go b/example-dnssecsocket/main.go deleted file mode 100644 index 673939d..0000000 --- a/example-dnssecsocket/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -// import "github.com/gookit/config" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -func main() { - parseConfig() - - initChannel() - go processEvents() - - // setups up a dnssecsocket() - 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) -} diff --git a/example-dnssecsocket/socketWIT.go b/example-dnssecsocket/socketWIT.go deleted file mode 100644 index 7a521b0..0000000 --- a/example-dnssecsocket/socketWIT.go +++ /dev/null @@ -1,101 +0,0 @@ -package main - -import "log" -import "os" -import "time" -import "net" -import "fmt" -import "bufio" - -import "git.wit.com/wit/shell" -import "git.wit.com/jcarr/dnssecsocket" - -var socketAlive bool = false -var connCurrent *net.TCPConn - -const ( - CONN_HOST = "v000185.testing.com.customers.wprod.wit.com" - CONN_PORT = "3333" - CONN_PROTO = "tcp" -) - -func writelnToSocket(aline string) { - if connCurrent == nil { - log.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 { - log.Println("SOCKET WRITE FAILED with err=", err, a) - connCurrent = nil - return - } -} - -func writeBytesToSocket(data []byte) { - if (connCurrent == nil) { - log.Println("WIT Socket is currently down (connCurrent == nil)") - return - } - a, err := connCurrent.Write(data) - log.Println("WIT Socket Write() returned:", a, err) -} - -func socketToWIT(myhostname string) { - remoteAddr := CONN_HOST + ":" + CONN_PORT - log.Println("remoteAddr:", remoteAddr) - - localTCPAddr := dnssecsocket.ResolveIPv6hostname(myhostname) - remoteTCPAddr, err := net.ResolveTCPAddr("tcp", remoteAddr) - - // connect to this socket - conn, err := net.DialTCP(CONN_PROTO, localTCPAddr, remoteTCPAddr) - - if err != nil { - log.Println(CONN_HOST, CONN_PORT, CONN_PROTO) - log.Println(err) - log.Println("socket connect failed. Not sure what to do here. os.Exit() ?") - connCurrent = nil - return - } - defer conn.Close() - - log.Println("socket connected to", CONN_PROTO, CONN_HOST, CONN_PORT) - - tmp, err := conn.Write([]byte(string(myhostname + "\n"))) - log.Println("conn.Write:", tmp, err) - - 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) - - shell.NonBlockingReader(newreader, os.Stdout) -} - -func retrySocket() { - for { - log.Println("Sleep for 3 seconds, then try to establish connection to WIT") - time.Sleep(3 * 1000 * 1000 * 1000) - - // for now, loop until I figure out what to actually do - socketToWIT("librem15.lab.wit.com") - } -} diff --git a/example-lookupAAAA/Makefile b/example-lookupAAAA/Makefile new file mode 100644 index 0000000..aff2a07 --- /dev/null +++ b/example-lookupAAAA/Makefile @@ -0,0 +1,3 @@ +run: + go build + ./example-lookupAAAA diff --git a/example-multiple-windows/main.go b/example-multiple-windows/main.go index f02deca..d5e5117 100644 --- a/example-multiple-windows/main.go +++ b/example-multiple-windows/main.go @@ -15,13 +15,18 @@ import _ "github.com/andlabs/ui/winmanifest" var first *gui.GuiWindow +// This sometimes crashes on the most recent window +// under linux. but it doesn't always crash + func main() { var c *pb.Config c = pb.MakeDefaultConfig() + gui.Data.Config = c i := 1 c.Width = int32(400 + 50 * i) + c.Height = int32(400 + 50 * i) c.Hostname = fmt.Sprintf("splash %d", i) first = StartNewWindow(c, true, "SPLASH") @@ -53,7 +58,7 @@ func StartNewWindow(c *pb.Config, bg bool, action string) *gui.GuiWindow { var newGuiWindow *gui.GuiWindow newGuiWindow = new(gui.GuiWindow) - newGuiWindow.C = c + // newGuiWindow.Config = c /* @@ -80,40 +85,39 @@ func StartNewWindow(c *pb.Config, bg bool, action string) *gui.GuiWindow { return newGuiWindow } -func InitWindow(wm *gui.GuiWindow) { - log.Println("InitWindow() NEW WINDOW wm =", wm) +func InitWindow(gw *gui.GuiWindow) { + log.Println("InitWindow() NEW WINDOW gw =", gw) - c := wm.C - wm.W = ui.NewWindow("", int(c.Width), int(c.Height), true) - // wm.W.SetBorderless(false) + c := gui.Data.Config + gw.UiWindow = ui.NewWindow("", int(c.Width), int(c.Height), true) + // gw.UiWindow.SetBorderless(false) - blah := wm - wm.W.OnClosing(func(*ui.Window) bool { + blah := gw + gw.UiWindow.OnClosing(func(*ui.Window) bool { log.Println("InitWindow() OnClosing() blah") log.Println("InitWindow() OnClosing() blah") log.Println("InitWindow() OnClosing() blah") log.Println("InitWindow() OnClosing() blah") spew.Dump(blah) - spew.Dump(wm) - wm.C = nil - log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING wm=", wm) - spew.Dump(wm) - spew.Dump(wm.W) + spew.Dump(gw) + log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw) + spew.Dump(gw) + spew.Dump(gw.UiWindow) // mouseClick(&newBM) - if (wm.W != nil) { - wm.W.Hide() + if (gw.UiWindow != nil) { + gw.UiWindow.Hide() } time.Sleep(1000 * time.Millisecond) - spew.Dump(wm) - // wm.W.Destroy() + spew.Dump(gw) + // gw.UiWindow.Destroy() ui.Quit() time.Sleep(1000 * time.Millisecond) return true }) - // wm.W.SetChild(wm.T) - // wm.W.SetMargined(true) + // gw.UiWindow.SetChild(gw.T) + // gw.UiWindow.SetMargined(true) - log.Println("InitWindow() Show() wm.Action =", wm.Action) - wm.W.Show() + log.Println("InitWindow() Show() gw.Action =", gw.Action) + gw.UiWindow.Show() } diff --git a/test4/Makefile b/test4/Makefile deleted file mode 100644 index 52515aa..0000000 --- a/test4/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -run: - go build - ./test4 diff --git a/test4/main.go b/test4/main.go deleted file mode 100644 index 75ecdcd..0000000 --- a/test4/main.go +++ /dev/null @@ -1,88 +0,0 @@ -package main - -import "os" -import "log" -import "fmt" - -import "github.com/davecgh/go-spew/spew" - -import "git.wit.com/wit/gui" -import pb "git.wit.com/wit/witProtobuf" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -func main() { - var c *pb.Config - c = pb.MakeDefaultConfig() - - gui.Data.MouseClick = mainMouseClick - - i := 1 - - c.Width += int32(100 * i) - c.Hostname = fmt.Sprintf("splash %d", i) - gui.StartNewWindow(c, true, "SPLASH") - - i += 1 - c.Width += int32(100 * i) - c.Hostname = fmt.Sprintf("splash %d", i) - gui.StartNewWindow(c, true, "BLAH") - - for { - i += 1 - c.Width += int32(100 * i) - c.Hostname = fmt.Sprintf("splash %d", i) - gui.StartNewWindow(c, false, "SPLASH") - - i += 1 - c.Width += int32(100 * i) - c.Hostname = fmt.Sprintf("splash %d", i) - gui.StartNewWindow(c, false, "BLAH") - } -} - -// This is the handler for all mosue clicks (buttons, areas, etc)) -// -// This is massive for a reason. EVERY MOUSE CLICK COMES HERE -// the 'gui' code is kinda just a holder. It will pass everything -// here and we have to sort out what to do with the click -// at least, that is the current design because I thought it -// might be a good approach. Time will tell... -// -func mainMouseClick(b *gui.GuiButton) { - if (b == nil) { - log.Println("mainMouseClick() BACK IN MAIN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?") - log.Println("mainMouseClick() BACK IN MAIN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?") - os.Exit(-1) - } - log.Println("mainMouseClick() b.Action =", b.Action) - log.Println("mainMouseClick() b.Action =", b.Account) - spew.Dump(b.Account) - - var wm *gui.GuiWindow - - wm = b.WM - if (wm == nil) { - log.Println("mainMouseClick() BACK IN MAIN CONTROL PANEL CODE (wm is nil) WHY DID THIS HAPPEN?") - log.Println("mainMouseClick() BACK IN MAIN CONTROL PANEL CODE (wm is nil) WHY DID THIS HAPPEN?") - os.Exit(-1) - } - log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE wm =", wm) - log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE window wm.W =", wm.W) - if (wm.W == nil) { - log.Println("mainMouseClick() BACK IN MAIN CONTROL PANEL CODE (wm.W is nil) WHY DID THIS HAPPEN?") - log.Println("mainMouseClick() BACK IN MAIN CONTROL PANEL CODE (wm.W is nil) WHY DID THIS HAPPEN?") - os.Exit(-1) - } - - if (b.Action == "NEWTEXT") { - log.Println("mainMouseClick() NEWTEXT wm.W =", wm.W) - } else if (b.Action == "SPLASH") { - log.Println("mainMouseClick() SPLASH wm.W =", wm.W) - } else if (b.Action == "AREA") { - log.Println("mainMouseClick() AREA wm.W =", wm.W) - wm.W.Destroy() - ui.Quit() - } -}