From 1b48bec90b46acef363240e4b3f20e53334e52dd Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 2 Jun 2019 19:56:14 -0700 Subject: [PATCH] fix the splash area logic Signed-off-by: Jeff Carr --- .gitignore | 1 + eventChannel.go | 4 +-- gui-buttonClicks.go | 11 ++++++ gui-splashPage.go | 22 +++++++++--- main.go | 12 ++++++- test5/Makefile | 3 ++ test5/main.go | 86 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 test5/Makefile create mode 100644 test5/main.go diff --git a/.gitignore b/.gitignore index c051da5..acc8c0b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ test1/test1 test2/test2 test3/test3 test4/test4 +test5/test5 diff --git a/eventChannel.go b/eventChannel.go index 0e50f73..d7b5d78 100644 --- a/eventChannel.go +++ b/eventChannel.go @@ -84,9 +84,9 @@ func ReadReceivedData(data *pb.Event, mh *gui.TableData, box *gui.GuiBox) { newGuiButton.Box = mh.Box gui.Data.AllButtons = append(gui.Data.AllButtons, &newGuiButton) mh.Rows[row].HumanData[6].Button = &newGuiButton - mh.Rows[row].HumanData[6].VM = vm +// mh.Rows[row].HumanData[6].VM = vm - mh.Rows[row].VM = vm +// mh.Rows[row].VM = vm log.Println("\tvm=", vm) log.Println("\tvm.Name=", vm.Name) diff --git a/gui-buttonClicks.go b/gui-buttonClicks.go index 71fd775..fb68f47 100644 --- a/gui-buttonClicks.go +++ b/gui-buttonClicks.go @@ -129,3 +129,14 @@ func mainMouseClick(b *gui.GuiButton) { log.Println("mainMouseClick() FAILED TO FIND b.Action =", b.Action) log.Println("mainMouseClick() END") } + +func makeButton(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM, + name string, action string, custom func(*gui.GuiButton)) *gui.GuiButton { + val := &myButtonInfo{} + val.Account = a + val.Accounts = config.Accounts + val.VM = vm + val.Custom = custom + val.Name = "jcarr" + return gui.NewCreateButton(box, custom, name, val) +} diff --git a/gui-splashPage.go b/gui-splashPage.go index b7e13e3..b17392f 100644 --- a/gui-splashPage.go +++ b/gui-splashPage.go @@ -31,7 +31,7 @@ func showSplashBox(gw *gui.GuiWindow) *gui.GuiBox { gui.NewLabel(box, "build date: " + BUILDTIME) } - gui.CreateButton(box, nil, nil, "OK", "AREA", splashClick) + makeButton(box, nil, nil, "OK", "AREA", splashClick) log.Println("ShowSplashBox() END box =", box) return box } @@ -60,6 +60,7 @@ func getNEWTEXT() *ui.AttributedString { } func splashClick(b *gui.GuiButton) { + log.Println("splashClick() START") gw := b.Box.Window // if there is already an account, skip straight to the main screen for key, _ := range config.Accounts { @@ -71,17 +72,19 @@ func splashClick(b *gui.GuiButton) { gw = gui.InitGuiWindow("splashClick() Box22", gw) gw.UiTab.Delete(0) - log.Println("addSubdomainQuestionBox() START") + log.Println("splashClick() AddGenericBox() START") box := gui.AddGenericBox(gw, "addSubdomainQuestion") + log.Println("splashClick() AddGenericBox() END box =", box) gui.NewLabel(box, "Enter your Subdomain or") - gui.CreateButton(box, nil, nil, "Generate", "SUBDOMAIN", generateSubdomain) + makeButton(box, nil, nil, "Generate", "SUBDOMAIN", generateSubdomain) + gui.AddEntry(box, "SUBDOMAIN") gui.HorizontalBreak(box) - gui.CreateButton(box, nil, nil, "Create Subdomain Account", "ADD", addSubdomainButton) + makeButton(box, nil, nil, "Create Subdomain Account", "ADD", addSubdomainButton) - log.Println("addSubdomainQuestionBox() END box =", box) + log.Println("splashClick() END box =", box) } func addSubdomainButton(b *gui.GuiButton) { @@ -109,6 +112,15 @@ func addSubdomainButton(b *gui.GuiButton) { func generateSubdomain(b *gui.GuiButton) { log.Println("generateSubdomain START") + if values, ok := b.Values.(*myButtonInfo); ! ok { + log.Println("\tvalues.Accounts error") + } else { + log.Println("\tvalues.Accounts =", values.Accounts) + log.Println("\tvalues.Name =", values.Name) + } + // use this way? + // values, _ := b.Values.(*myButtonInfo) + if (b == nil) { log.Println("generateSubdomain ERROR b == nil") return diff --git a/main.go b/main.go index 1532adf..8b529b9 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import "time" import "github.com/miekg/dns" import "git.wit.com/wit/gui" -// import pb "git.wit.com/wit/witProtobuf" +import pb "git.wit.com/wit/witProtobuf" import "git.wit.com/jcarr/dnssecsocket" import "github.com/gobuffalo/packr" @@ -20,6 +20,16 @@ var GOVERSION string // this is passed in as an ldflag var BUILDTIME string // this is passed in as an ldflag var VERSION string // this is passed in as an ldflag +type myButtonInfo struct { + Account *pb.Account // associated with what account? + Accounts []*pb.Account // associated with what account? + VM *pb.Event_VM // associated with which VM? + Custom func (*gui.GuiButton) + ADD func (*gui.GuiButton) + Name string +} + + // use mergo to merge structs // import "github.com/imdario/mergo" // mergo.Merge(&dest, src) diff --git a/test5/Makefile b/test5/Makefile new file mode 100644 index 0000000..c92bf1c --- /dev/null +++ b/test5/Makefile @@ -0,0 +1,3 @@ +run: + go build + ./test5 diff --git a/test5/main.go b/test5/main.go new file mode 100644 index 0000000..8e06397 --- /dev/null +++ b/test5/main.go @@ -0,0 +1,86 @@ +package main + +import "fmt" +import "io" +import "log" +import "reflect" +import "strings" +import "encoding/json" + +type S struct{ + blah int + foo string +} + +func (s *S) addr() { fmt.Printf("%p\n", s) } + +type Codec interface { + Encode(w io.Writer, v interface{}) error + Decode(r io.Reader, v interface{}) error +} + +func (jsonCodec) Encode(w io.Writer, v interface{}) error { + return json.NewEncoder(w).Encode(v) +} + +func (jsonCodec) Decode(r io.Reader, v interface{}) error { + return json.NewDecoder(r).Decode(v) +} + +var JSON Codec = jsonCodec{} + +type jsonCodec struct{} + +type buttons interface { + Encode(w io.Writer, v interface{}) error + Decode(r io.Reader, v interface{}) error +} + +type foo struct{} + +type goo struct{ + test int +} + +func bar(baz interface{}) { + log.Println("baz =", baz) + log.Println("reflect.TypeOf(baz) =", reflect.TypeOf(baz)) + switch f := baz.(type) { + case int: + log.Println("baz.(type) is an int =", f * 3) + case *foo: // f is of type *foo + log.Println("baz.(type) is known as *foo") + default: // f is some other type + log.Println("baz.(type) =", f) + } + +} + + +func main() { + var a, b S + a.addr() // 0x1beeb0 + b.addr() // 0x1beeb0 + + f := &foo{} + bar(f) // every type implements interface{}. Nothing special required + + g := &goo{} + g.test = 4 + bar(g) // every type implements interface{}. Nothing special required + + bar("hello") // every type implements interface{}. Nothing special required + + // what is this? +// s := &Service{ +// Codec: JSON, +// } + + r := strings.NewReader("Hello, Reader!") + err := JSON.Decode(r, "afjd") + log.Println("JSON.Decoder err =", err) + + // err := JSON.Encode(w, obj) + // log.Println("err =", err) + +}