fix the splash area logic

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-02 19:56:14 -07:00
parent ab7deeafa8
commit 1b48bec90b
7 changed files with 131 additions and 8 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ test1/test1
test2/test2
test3/test3
test4/test4
test5/test5

View File

@ -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)

View File

@ -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)
}

View File

@ -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

12
main.go
View File

@ -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)

3
test5/Makefile Normal file
View File

@ -0,0 +1,3 @@
run:
go build
./test5

86
test5/main.go Normal file
View File

@ -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)
}