summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addAccount.go4
-rw-r--r--area.go35
-rw-r--r--gui.go17
-rw-r--r--mainCloudBox.go30
-rw-r--r--splash.go3
-rw-r--r--structs.go18
-rw-r--r--vmBox.go52
7 files changed, 67 insertions, 92 deletions
diff --git a/addAccount.go b/addAccount.go
index 18089e8..353951a 100644
--- a/addAccount.go
+++ b/addAccount.go
@@ -20,7 +20,7 @@ func AddEntry(box *GuiBox, name string) *GuiEntry {
})
box.UiBox.Append(ue, false)
- ge.E = ue
+ ge.UiEntry = ue
box.EntryMap[name] = ge
return ge
@@ -69,7 +69,7 @@ func generateSubdomain(b *GuiButton) {
}
// subdomain.SetText("cust00013.wit.dev")
- txt := SetText(b.Box, "SUBDOMAIN", "cust001.testing.com.customers.wpord.wit.com")
+ txt := SetText(b.Box, "SUBDOMAIN", "cust001.testing.com.customers.wprod.wit.com")
log.Println("generateSubdomain subdomain = ", txt)
log.Println("generateSubdomain END")
}
diff --git a/area.go b/area.go
index 88723d0..1a0b9c9 100644
--- a/area.go
+++ b/area.go
@@ -1,44 +1,28 @@
package gui
import "log"
-// import "time"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
import "github.com/davecgh/go-spew/spew"
-func findFB(button *GuiButton) *GuiButton {
- var a *GuiButton
- for key, foo := range Data.AllButtons {
- log.Println("findFB() Data.AllButtons key, foo=", key, foo)
- if foo == button {
- log.Println("findFB() FOUND BUTTON key, foo=", key, foo)
- a = foo
- }
- }
- return a
-}
+// THIS IS CLEAN
func makeSplashArea(gb *GuiBox, newText *ui.AttributedString) {
// make this button just to get the default font (but don't display the button)
// There should be another way to do this (?)
var newB *GuiButton
- newB = CreateFontButton(gb, "AREA")
+ newB = CreateFontButton(gb, "AREA")
+ newB.Box = gb
+ newB.GW = gb.W
// initialize the GuiArea{}
- gb.Area = new(GuiArea)
- gb.Area.Window = gb.W
- gb.Area.UiAttrstr = newText
-
- // ah.UiAttrstr = makeAttributedString()
- gb.Area.UiArea = ui.NewArea(gb.Area)
- newB.A = gb.Area.UiArea
- newB.GW = gb.W
- newB.Box = gb
- // Data.AllButtons[1].A = ah.UiArea
- // ah.Button = &Data.AllButtons[1]
- gb.Area.Button = newB
+ gb.Area = new(GuiArea)
+ gb.Area.Button = newB
+ gb.Area.Box = gb
+ gb.Area.UiAttrstr = newText
+ gb.Area.UiArea = ui.NewArea(gb.Area)
if (Data.Debug) {
spew.Dump(gb.Area.UiArea)
@@ -103,6 +87,7 @@ func (ah GuiArea) DragBroken(a *ui.Area) {
log.Println("GOT DragBroken()")
}
+// TODO: fix KeyEvents
func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
log.Println("GOT KeyEvent()")
if (ke.Key == 10) {
diff --git a/gui.go b/gui.go
index 22f4d3b..84618a0 100644
--- a/gui.go
+++ b/gui.go
@@ -145,6 +145,7 @@ func mouseClick(b *GuiButton) {
createAddVmBox(b.GW, b)
return
}
+ /*
if (b.Action == "WINDOW CLOSE") {
b.W.Hide()
// TODO: fix this (seems to crash? maybe because we are in the button here?)
@@ -154,10 +155,12 @@ func mouseClick(b *GuiButton) {
if (b.Action == "ADD") {
log.Println("\tgui.mouseClick() SHOULD ADD VM HERE?")
}
+ */
}
if (Data.MouseClick == nil) {
log.Println("\tgui.mouseClick() Data.MouseClick() IS nil. NOT DOING ANYTHING")
+ log.Println("\tgui.mouseClick() Your application did not set a MouseClick() callback function")
} else {
log.Println("\tgui.mouseClick() Data.MouseClick() START")
Data.MouseClick(b)
@@ -210,8 +213,7 @@ func AddButton(b *GuiButton, name string) *ui.Button {
return newB
}
-func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM,
- name string, action string, custom func(*GuiButton)) *GuiButton {
+func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, name string, action string, custom func(*GuiButton)) *GuiButton {
newUiB := ui.NewButton(name)
newUiB.OnClicked(defaultButtonClick)
@@ -223,7 +225,6 @@ func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM,
panic("crap")
}
newB.GW = box.W
- newB.T = box.W.UiTab
newB.Account = a
newB.VM = vm
newB.Box = box
@@ -266,9 +267,9 @@ func GetText(box *GuiBox, name string) string {
return ""
}
e := box.EntryMap[name]
- log.Println("gui.GetText() box.EntryMap[", name, "] = ", e.E.Text())
+ log.Println("gui.GetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
log.Println("gui.GetText() END")
- return e.E.Text()
+ return e.UiEntry.Text()
}
func SetText(box *GuiBox, name string, value string) error {
@@ -283,9 +284,9 @@ func SetText(box *GuiBox, name string, value string) error {
return fmt.Errorf("gui.SetText() ERROR box.EntryMap[", name, "] == nil ")
}
e := box.EntryMap[name]
- log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.E.Text())
- e.E.SetText(value)
- log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.E.Text())
+ log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
+ e.UiEntry.SetText(value)
+ log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
log.Println("gui.SetText() END")
return nil
}
diff --git a/mainCloudBox.go b/mainCloudBox.go
index 869905a..6f5d971 100644
--- a/mainCloudBox.go
+++ b/mainCloudBox.go
@@ -170,12 +170,13 @@ func GuiInit() {
})
}
-func StartNewWindow(c *pb.Config, bg bool, action string) {
+func StartNewWindow(c *pb.Config, bg bool, action string, text func() *ui.AttributedString) {
log.Println("InitNewWindow() Create a new window")
var newGuiWindow GuiWindow
- newGuiWindow.Width = int(c.Width)
- newGuiWindow.Height = int(c.Height)
- newGuiWindow.Action = action
+ newGuiWindow.Width = int(c.Width)
+ newGuiWindow.Height = int(c.Height)
+ newGuiWindow.Action = action
+ newGuiWindow.GetText = text
Data.Windows = append(Data.Windows, &newGuiWindow)
// make(newGuiWindow.BoxMap)
@@ -210,7 +211,7 @@ func InitWindow(gw *GuiWindow) {
// create a 'fake' button entry for the mouse clicks
var newBM GuiButton
newBM.Action = "QUIT"
- newBM.W = gw.UiWindow
+// newBM.W = gw.UiWindow
newBM.GW = gw
Data.AllButtons = append(Data.AllButtons, &newBM)
@@ -231,7 +232,12 @@ func InitWindow(gw *GuiWindow) {
if (gw.Action == "SPLASH") {
log.Println("InitWindow() TRYING SPLASH")
damnit := "click" + string(Data.Config.Hostname)
- tmp := getSplashText(damnit)
+ var tmp *ui.AttributedString
+ if (gw.GetText == nil) {
+ tmp = getSplashText(damnit)
+ } else {
+ tmp = gw.GetText()
+ }
log.Println("InitWindow() TRYING SPLASH tmp =", tmp)
abox := ShowSplashBox(gw, tmp)
@@ -252,7 +258,7 @@ func makeEntryVbox(hbox *ui.Box, a string, startValue string, edit bool, action
e := defaultMakeEntry(startValue, edit, action)
- vboxN.Append(e.E, false)
+ vboxN.Append(e.UiEntry, false)
hbox.Append(vboxN, false)
// End 'Nickname' vertical box
@@ -298,7 +304,7 @@ func defaultEntryChange(e *ui.Entry) {
if (Data.Debug) {
log.Println("\tdefaultEntryChange() Data.AllEntries =", key, em)
}
- if Data.AllEntries[key].E == e {
+ if Data.AllEntries[key].UiEntry == e {
log.Println("defaultEntryChange() FOUND",
"action =", Data.AllEntries[key].Action,
"Last =", Data.AllEntries[key].Last,
@@ -324,9 +330,9 @@ func defaultMakeEntry(startValue string, edit bool, action string) *GuiEntry {
// add the entry field to the global map
var newEntry GuiEntry
- newEntry.E = e
- newEntry.Edit = edit
- newEntry.Action = action
+ newEntry.UiEntry = e
+ newEntry.Edit = edit
+ newEntry.Action = action
if (action == "Memory") {
newEntry.Normalize = normalizeInt
}
@@ -342,7 +348,7 @@ func makeEntryHbox(hbox *ui.Box, a string, startValue string, edit bool, action
hboxN.Append(ui.NewLabel(a), false)
e := defaultMakeEntry(startValue, edit, action)
- hboxN.Append(e.E, false)
+ hboxN.Append(e.UiEntry, false)
hbox.Append(hboxN, false)
// End 'Nickname' vertical box
diff --git a/splash.go b/splash.go
index 95d83e0..da03f3d 100644
--- a/splash.go
+++ b/splash.go
@@ -74,9 +74,6 @@ func ShowSplashBox(gw *GuiWindow, newText *ui.AttributedString) *GuiBox {
okButton := CreateButton(gb, nil, nil, "OK", "AREA", nil)
newbox.Append(okButton.B, false)
- okButton = CreateButton(gb, nil, nil, "NEWTEXT", "NEWTEXT", nil)
- newbox.Append(okButton.B, false)
-
// os.Exit(0)
return gb
}
diff --git a/structs.go b/structs.go
index 1013033..89057b9 100644
--- a/structs.go
+++ b/structs.go
@@ -71,13 +71,14 @@ type GuiData struct {
//
type GuiWindow struct {
Action string
-// Area *GuiArea // should be moved to GuiBox
BoxMap map[string]*GuiBox
Width int
Height int
+ // andlabs/ui abstraction mapping
UiWindow *ui.Window
UiTab *ui.Tab // if this != nil, the window is 'tabbed'
+ GetText func() *ui.AttributedString
}
@@ -100,9 +101,6 @@ type GuiButton struct {
// andlabs/ui abstraction mapping
B *ui.Button
FB *ui.FontButton
- A *ui.Area // should be deprecated
- W *ui.Window // should be deprecated
- T *ui.Tab // should be deprecated
}
type GuiBox struct {
@@ -110,6 +108,7 @@ type GuiBox struct {
EntryMap map[string]*GuiEntry
Area *GuiArea
+ // andlabs/ui abstraction mapping
UiBox *ui.Box
}
@@ -120,13 +119,12 @@ type GuiEntry struct {
Normalize func (string) string // function to 'normalize' the data
B *GuiButton
+ Box *GuiBox
Account *pb.Account
VM *pb.Event_VM
- E *ui.Entry
- W *ui.Window // should be moved to *GuiWindow or GuiBox
- T *ui.Tab // should be moved to *GuiWindow or GuiBox
-
+ // andlabs/ui abstraction mapping
+ UiEntry *ui.Entry
}
//
@@ -135,8 +133,8 @@ type GuiEntry struct {
// AREA STRUCTURES START
//
type GuiArea struct{
- Window *GuiWindow // what window this area is in (should be GuiBox?)
Button *GuiButton // what button handles mouse events
+ Box *GuiBox
UiAttrstr *ui.AttributedString
UiArea *ui.Area
@@ -178,7 +176,6 @@ type TableData struct {
lastRow int
lastColumn int
-// parentTab *ui.Tab
}
//
@@ -231,6 +228,7 @@ type RowData struct {
Status string // status of the row?
/*
// TODO: These may or may not be implementable
+ // depending on if it's possible to detect the bgcolor or what row is selected
click func() // what function to call if the user clicks on it
doubleclick func() // what function to call if the user double clicks on it
*/
diff --git a/vmBox.go b/vmBox.go
index a8bb8ce..ae04554 100644
--- a/vmBox.go
+++ b/vmBox.go
@@ -10,35 +10,24 @@ import pb "git.wit.com/wit/witProtobuf"
import "github.com/davecgh/go-spew/spew"
-/*
-func AddVmConfigureTab(wm *GuiWindow, name string, pbVM *pb.Event_VM) {
- CreateVmBox(wm, pbVM)
-}
-*/
-
func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) {
log.Println("CreateVmBox() START")
log.Println("CreateVmBox() vm.Name =", vm.Name)
log.Println("CreateVmBox() gw =", gw)
- var gb *GuiBox
- gb = new(GuiBox)
+ var box *GuiBox
+ box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
log.Println("CreateVmBox() vbox =", vbox)
- log.Println("CreateVmBox() gb.UiBox =", gb.UiBox)
- gb.UiBox = vbox
- log.Println("CreateVmBox() gb.W =", gb.W)
- gb.W = gw
+ log.Println("CreateVmBox() box.UiBox =", box.UiBox)
+ box.UiBox = vbox
+ log.Println("CreateVmBox() box.W =", box.W)
+ box.W = gw
log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap)
- gw.BoxMap[vm.Name] = gb
-
-// gw.UiTab.Append(vm.Name, vbox)
-
-
+ gw.BoxMap[vm.Name] = box
- spew.Dump(vm)
if (Data.Debug) {
spew.Dump(vm)
}
@@ -61,19 +50,19 @@ func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) {
hboxButtons.SetPadded(true)
vbox.Append(hboxButtons, false)
- a := CreateButton(gb, nil, vm, "Power On", "POWERON", nil)
+ a := CreateButton(box, nil, vm, "Power On", "POWERON", nil)
hboxButtons.Append(a.B, false)
- a = CreateButton(gb, nil, vm, "Power Off", "POWEROFF", nil)
+ a = CreateButton(box, nil, vm, "Power Off", "POWEROFF", nil)
hboxButtons.Append(a.B, false)
- a = CreateButton(gb, nil, vm, "Destroy", "DESTROY", nil)
+ a = CreateButton(box, nil, vm, "Destroy", "DESTROY", nil)
hboxButtons.Append(a.B, false)
- a = CreateButton(gb, nil, vm, "ping", "PING", runPingClick)
+ a = CreateButton(box, nil, vm, "ping", "PING", runPingClick)
hboxButtons.Append(a.B, false)
- a = CreateButton(gb, nil, vm, "Console", "XTERM", runTestExecClick)
+ a = CreateButton(box, nil, vm, "Console", "XTERM", runTestExecClick)
hboxButtons.Append(a.B, false)
- a = CreateButton(gb, nil, vm, "Save", "SAVE", nil)
+ a = CreateButton(box, nil, vm, "Save", "SAVE", nil)
hboxButtons.Append(a.B, false)
- a = CreateButton(gb, nil, vm, "Done", "DONE", nil)
+ a = CreateButton(box, nil, vm, "Done", "DONE", nil)
hboxButtons.Append(a.B, false)
AddBoxToTab(vm.Name, gw.UiTab, vbox)
@@ -83,14 +72,14 @@ func createAddVmBox(gw *GuiWindow, b *GuiButton) {
log.Println("createAddVmBox() START")
name := "(" + b.Account.Nick + ")"
- var gb *GuiBox
- gb = new(GuiBox)
+ var box *GuiBox
+ box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
- gb.UiBox = vbox
- gb.W = gw
- gw.BoxMap["ADD VM" + name] = gb
+ box.UiBox = vbox
+ box.W = gw
+ gw.BoxMap["ADD VM" + name] = box
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
@@ -113,13 +102,12 @@ func createAddVmBox(gw *GuiWindow, b *GuiButton) {
newb.Action = "CREATE"
newb.VM = b.VM
newb.Account = b.Account
- newb.T = gw.UiTab
hostname.B = &newb
memory.B = &newb
disk.B = &newb
hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false)
- a := CreateButton(gb, nil, nil, "Cancel", "CLOSE", nil)
+ a := CreateButton(box, nil, nil, "Cancel", "CLOSE", nil)
hboxButtons.Append(a.B, false)
AddBoxToTab(name, gw.UiTab, vbox)