move all structs into a common file
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
171390c100
commit
8730dbc4dd
12
debug.go
12
debug.go
|
@ -5,6 +5,7 @@ import "time"
|
|||
import "fmt"
|
||||
import "strings"
|
||||
import "os/exec"
|
||||
import "runtime"
|
||||
|
||||
import "github.com/gookit/config"
|
||||
|
||||
|
@ -17,7 +18,7 @@ import _ "github.com/andlabs/ui/winmanifest"
|
|||
|
||||
// can not pass any args to this (?)
|
||||
func setupCloudUI() {
|
||||
Data.cloudWindow = ui.NewWindow("Cloud Control Panel", config.Int("width"), config.Int("height"), false)
|
||||
Data.cloudWindow = ui.NewWindow("Cloud Control Panel", Data.Width, config.Int("height"), false)
|
||||
Data.cloudWindow.OnClosing(func(*ui.Window) bool {
|
||||
ui.Quit()
|
||||
return true
|
||||
|
@ -112,11 +113,18 @@ func addDebuggingButtons(vbox *ui.Box, custom func(*ButtonMap, string)) {
|
|||
|
||||
vbox.Append(CreateButton("DEBUG goroutines", "DEBUG", custom), false)
|
||||
vbox.Append(CreateButton("xterm", "XTERM", runTestExecClick), false)
|
||||
vbox.Append(CreateButton("Load test.json config file", "CONFIG", custom), false)
|
||||
}
|
||||
|
||||
func runTestExecClick(b *ButtonMap, msg string) {
|
||||
log.Println("runTestExecClick START")
|
||||
go runCommand("xterm -report-fonts")
|
||||
if runtime.GOOS == "linux" {
|
||||
go runCommand("xterm -report-fonts")
|
||||
} else if runtime.GOOS == "windows" {
|
||||
go runCommand("cmd.exe")
|
||||
} else {
|
||||
go runCommand("xterm")
|
||||
}
|
||||
log.Println("runTestExecClick END")
|
||||
}
|
||||
|
||||
|
|
106
gui.go
106
gui.go
|
@ -8,112 +8,6 @@ import _ "github.com/andlabs/ui/winmanifest"
|
|||
import "github.com/gookit/config"
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
//
|
||||
// All GUI Data Structures and functions that are external
|
||||
// If you need cross platform support, these might only
|
||||
// be the safe way to interact with the GUI
|
||||
//
|
||||
var Data GuiDataStructure
|
||||
|
||||
type GuiTabStructure struct {
|
||||
me *ui.Tab
|
||||
parentWindow *ui.Window
|
||||
firstBox *ui.Box
|
||||
tabOffset int
|
||||
|
||||
// this means only one table per tab
|
||||
mh *TableData
|
||||
|
||||
// stuff for the 'area'
|
||||
// this means only one area per tab
|
||||
fontButton *ui.FontButton
|
||||
attrstr *ui.AttributedString
|
||||
splashArea *ui.Area
|
||||
}
|
||||
|
||||
type GuiDataStructure struct {
|
||||
State string
|
||||
Width int
|
||||
Height int
|
||||
|
||||
// a fallback default function to handle mouse events
|
||||
// if nothing else is defined to handle them
|
||||
MouseClick func(*ButtonMap)
|
||||
|
||||
// general information
|
||||
Version string
|
||||
GitCommit string
|
||||
GoVersion string
|
||||
Buildtime string
|
||||
HomeDir string
|
||||
Debug bool
|
||||
DebugTable bool
|
||||
|
||||
// official hostname and IPv6 address for this box
|
||||
Hostname string
|
||||
IPv6 string
|
||||
|
||||
// account entry textboxes
|
||||
AccNick string
|
||||
AccUser string
|
||||
AccPass string
|
||||
|
||||
// A map of all buttons everywhere on all
|
||||
// windows, all tabs, across all goroutines
|
||||
// This is "GLOBAL"
|
||||
AllButtons []ButtonMap
|
||||
|
||||
// a tab (maybe the one the user is playing with?)
|
||||
CurrentTab *GuiTabStructure
|
||||
// a VM (maybe the one the user is playing with?)
|
||||
CurrentVM string
|
||||
|
||||
// All the tabs
|
||||
Tabs []GuiTabStructure
|
||||
|
||||
// stuff for the splash screen / setup tabs
|
||||
// MainWindow *ui.Window
|
||||
cloudWindow *ui.Window
|
||||
cloudTab *ui.Tab
|
||||
cloudBox *ui.Box
|
||||
smallBox *ui.Box
|
||||
|
||||
mainwin *ui.Window
|
||||
maintab *ui.Tab
|
||||
tabcount int
|
||||
|
||||
// stuff for the 'area'
|
||||
MyArea *ui.Area
|
||||
fontButton *ui.FontButton
|
||||
attrstr *ui.AttributedString
|
||||
splashArea *ui.Area
|
||||
}
|
||||
|
||||
type TableColumnData struct {
|
||||
Index int
|
||||
CellType string
|
||||
Heading string
|
||||
Color string
|
||||
}
|
||||
|
||||
type ButtonMap struct {
|
||||
B *ui.Button
|
||||
FB *ui.FontButton
|
||||
onClick func (int, string)
|
||||
onChanged func (int, string)
|
||||
custom func (*ButtonMap, string)
|
||||
Name string // the text on the button
|
||||
Note string // what type of button
|
||||
AccNick string // what account this button is for
|
||||
}
|
||||
|
||||
/*
|
||||
func AddNewTab(mytab *ui.Tab, newbox ui.Control, tabOffset int) {
|
||||
mytab.Append("Cloud Info", newbox)
|
||||
mytab.SetMargined(tabOffset, true)
|
||||
}
|
||||
*/
|
||||
|
||||
func InitColumns(mh *TableData, parts []TableColumnData) {
|
||||
tmpBTindex := 0
|
||||
humanID := 0
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
package gui
|
||||
|
||||
import "image/color"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
//
|
||||
// All GUI Data Structures and functions that are external
|
||||
// If you need cross platform support, these might only
|
||||
// be the safe way to interact with the GUI
|
||||
//
|
||||
var Data GuiDataStructure
|
||||
|
||||
type GuiTabStructure struct {
|
||||
me *ui.Tab
|
||||
parentWindow *ui.Window
|
||||
firstBox *ui.Box
|
||||
tabOffset int
|
||||
|
||||
// this means only one table per tab
|
||||
mh *TableData
|
||||
|
||||
// stuff for the 'area'
|
||||
// this means only one area per tab
|
||||
fontButton *ui.FontButton
|
||||
attrstr *ui.AttributedString
|
||||
splashArea *ui.Area
|
||||
}
|
||||
|
||||
type GuiDataStructure struct {
|
||||
State string
|
||||
Width int
|
||||
Height int
|
||||
|
||||
// a fallback default function to handle mouse events
|
||||
// if nothing else is defined to handle them
|
||||
MouseClick func(*ButtonMap)
|
||||
|
||||
// general information
|
||||
Version string
|
||||
GitCommit string
|
||||
GoVersion string
|
||||
Buildtime string
|
||||
HomeDir string
|
||||
Debug bool
|
||||
DebugTable bool
|
||||
|
||||
// official hostname and IPv6 address for this box
|
||||
Hostname string
|
||||
IPv6 string
|
||||
|
||||
// account entry textboxes
|
||||
AccNick string
|
||||
AccUser string
|
||||
AccPass string
|
||||
|
||||
// A map of all buttons everywhere on all
|
||||
// windows, all tabs, across all goroutines
|
||||
// This is "GLOBAL"
|
||||
AllButtons []ButtonMap
|
||||
|
||||
// a tab (maybe the one the user is playing with?)
|
||||
CurrentTab *GuiTabStructure
|
||||
// a VM (maybe the one the user is playing with?)
|
||||
CurrentVM string
|
||||
CurrentPbVM *pb.Event_VM
|
||||
|
||||
// All the tabs
|
||||
Tabs []GuiTabStructure
|
||||
|
||||
// stuff for the splash screen / setup tabs
|
||||
// MainWindow *ui.Window
|
||||
cloudWindow *ui.Window
|
||||
cloudTab *ui.Tab
|
||||
cloudBox *ui.Box
|
||||
smallBox *ui.Box
|
||||
|
||||
mainwin *ui.Window
|
||||
maintab *ui.Tab
|
||||
tabcount int
|
||||
|
||||
// stuff for the 'area'
|
||||
MyArea *ui.Area
|
||||
fontButton *ui.FontButton
|
||||
attrstr *ui.AttributedString
|
||||
splashArea *ui.Area
|
||||
}
|
||||
|
||||
type TableColumnData struct {
|
||||
Index int
|
||||
CellType string
|
||||
Heading string
|
||||
Color string
|
||||
}
|
||||
|
||||
type ButtonMap struct {
|
||||
B *ui.Button
|
||||
FB *ui.FontButton
|
||||
onClick func (int, string)
|
||||
onChanged func (int, string)
|
||||
custom func (*ButtonMap, string)
|
||||
Name string // the text on the button
|
||||
Note string // what type of button
|
||||
AccNick string // what account this button is for
|
||||
}
|
||||
|
||||
//
|
||||
// TABLE DATA STRUCTURES START
|
||||
//
|
||||
|
||||
type CellData struct {
|
||||
Index int
|
||||
HumanID int
|
||||
Name string // what type of cell is this?
|
||||
}
|
||||
|
||||
// hmm. will this stand the test of time?
|
||||
type RowData struct {
|
||||
Name string // what kind of row is this?
|
||||
Status string // status of the row?
|
||||
/*
|
||||
// These may or may not be implementable
|
||||
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
|
||||
*/
|
||||
HumanData [20]HumanCellData
|
||||
|
||||
// The VM from the protobuf
|
||||
PbVM *pb.Event_VM
|
||||
}
|
||||
|
||||
//
|
||||
// This maps the andlabs/ui & libui components into a "human"
|
||||
// readable cell reference list. The reason is that there
|
||||
// are potentially 3 values for each cell. The Text, the Color
|
||||
// and an image. These are not always needed so the number
|
||||
// of fields varies between 1 and 3. Internally, the toolkit
|
||||
// GUI abstraction needs to list all of them, but it's then
|
||||
// hard to figure out which column goes with the columns that
|
||||
// you see when you visually are looking at it like a spreadsheet
|
||||
//
|
||||
// This makes a map so that we can say "give me the value at
|
||||
// row 4 and column 2" and find the fields that are needed
|
||||
//
|
||||
// TODO: add back image support and the progress bar
|
||||
//
|
||||
type HumanCellData struct {
|
||||
Name string // what kind of row is this?
|
||||
Text string
|
||||
TextID int
|
||||
Color color.RGBA
|
||||
ColorID int
|
||||
}
|
||||
|
||||
type HumanMap struct {
|
||||
Name string // what kind of row is this?
|
||||
TextID int
|
||||
ColorID int
|
||||
}
|
||||
|
||||
//
|
||||
// This is the structure that andlabs/ui uses to pass information
|
||||
// to the GUI. This is the "authoritative" data.
|
||||
//
|
||||
type TableData struct {
|
||||
RowCount int // This is the number of 'rows' which really means data elements not what the human sees
|
||||
RowWidth int // This is how wide each row is
|
||||
Rows []RowData // This is all the table data by row
|
||||
generatedColumnTypes []ui.TableValue // generate this dynamically
|
||||
|
||||
Cells [20]CellData
|
||||
Human [20]HumanMap
|
||||
|
||||
lastRow int
|
||||
lastColumn int
|
||||
}
|
||||
|
||||
//
|
||||
// TABLE DATA STRUCTURES END
|
||||
//
|
65
table.go
65
table.go
|
@ -3,77 +3,12 @@
|
|||
package gui
|
||||
|
||||
import "log"
|
||||
import "image/color"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
type CellData struct {
|
||||
Index int
|
||||
HumanID int
|
||||
Name string // what type of cell is this?
|
||||
}
|
||||
|
||||
// hmm. will this stand the test of time?
|
||||
type RowData struct {
|
||||
Name string // what kind of row is this?
|
||||
Status string // status of the row?
|
||||
/*
|
||||
// These may or may not be implementable
|
||||
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
|
||||
*/
|
||||
HumanData [20]HumanCellData
|
||||
}
|
||||
|
||||
//
|
||||
// This maps the andlabs/ui & libui components into a "human"
|
||||
// readable cell reference list. The reason is that there
|
||||
// are potentially 3 values for each cell. The Text, the Color
|
||||
// and an image. These are not always needed so the number
|
||||
// of fields varies between 1 and 3. Internally, the toolkit
|
||||
// GUI abstraction needs to list all of them, but it's then
|
||||
// hard to figure out which column goes with the columns that
|
||||
// you see when you visually are looking at it like a spreadsheet
|
||||
//
|
||||
// This makes a map so that we can say "give me the value at
|
||||
// row 4 and column 2" and find the fields that are needed
|
||||
//
|
||||
// TODO: add back image support and the progress bar
|
||||
//
|
||||
type HumanCellData struct {
|
||||
Name string // what kind of row is this?
|
||||
Text string
|
||||
TextID int
|
||||
Color color.RGBA
|
||||
ColorID int
|
||||
}
|
||||
|
||||
type HumanMap struct {
|
||||
Name string // what kind of row is this?
|
||||
TextID int
|
||||
ColorID int
|
||||
}
|
||||
|
||||
//
|
||||
// This is the structure that andlabs/ui uses to pass information
|
||||
// to the GUI. This is the "authoritative" data.
|
||||
//
|
||||
type TableData struct {
|
||||
RowCount int // This is the number of 'rows' which really means data elements not what the human sees
|
||||
RowWidth int // This is how wide each row is
|
||||
Rows []RowData // This is all the table data by row
|
||||
generatedColumnTypes []ui.TableValue // generate this dynamically
|
||||
|
||||
Cells [20]CellData
|
||||
Human [20]HumanMap
|
||||
|
||||
lastRow int
|
||||
lastColumn int
|
||||
}
|
||||
|
||||
func initRowBTcolor(mh *TableData, intBG int, cell TableColumnData) {
|
||||
humanInt := cell.Index
|
||||
|
||||
|
|
|
@ -100,12 +100,13 @@ func defaultSetCellValue(mh *TableData, row int, column int) {
|
|||
vmname := mh.Rows[row].HumanData[humanID].Text
|
||||
log.Println("vmname =", vmname)
|
||||
log.Println("defaultSetCellValue() FOUND THE BUTTON!!!!!!! Button was pressed START", row, column)
|
||||
Data.CurrentVM = fmt.Sprintf("%s",vmname)
|
||||
Data.CurrentVM = fmt.Sprintf("%s",vmname)
|
||||
Data.CurrentPbVM = mh.Rows[row].PbVM
|
||||
log.Println("User last clicked on Data.CurrentVM =", Data.CurrentVM)
|
||||
if (Data.Debug) {
|
||||
go ui.Main(ShowVM)
|
||||
} else {
|
||||
AddVmConfigureTab(vmname)
|
||||
AddVmConfigureTab(vmname, mh.Rows[row].PbVM)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
136
vmWindow.go
136
vmWindow.go
|
@ -5,6 +5,10 @@ import "log"
|
|||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
func ShowVM() {
|
||||
name := Data.CurrentVM
|
||||
log.Println("ShowVM() START Data.CurrentVM=", Data.CurrentVM)
|
||||
|
@ -22,7 +26,7 @@ func ShowVM() {
|
|||
VMwin.SetChild(VMtab)
|
||||
VMwin.SetMargined(true)
|
||||
|
||||
createVmBox(VMtab, buttonVmClick)
|
||||
createVmBox(VMtab, buttonVmClick, Data.CurrentPbVM)
|
||||
// vmBox := createVmBox(buttonVmClick)
|
||||
// VMtab.Append(Data.CurrentVM, vmBox)
|
||||
// VMtab.SetMargined(0, true)
|
||||
|
@ -30,14 +34,41 @@ func ShowVM() {
|
|||
VMwin.Show()
|
||||
}
|
||||
|
||||
func AddVmConfigureTab(name string) {
|
||||
createVmBox(Data.cloudTab, buttonVmClick)
|
||||
func AddVmConfigureTab(name string, pbVM *pb.Event_VM) {
|
||||
createVmBox(Data.cloudTab, buttonVmClick, Data.CurrentPbVM)
|
||||
// vmBox := createVmBox(Data.cloudTab, buttonVmClick)
|
||||
// Data.cloudTab.Append(name, vmBox)
|
||||
// Data.cloudTab.SetMargined(0, true)
|
||||
}
|
||||
|
||||
func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string)) {
|
||||
// makeEntryBox(box, "hostname:", "blah.foo.org") {
|
||||
func makeEntryBox(hbox *ui.Box, a string, b string) {
|
||||
// Start 'Nickname' vertical box
|
||||
vboxN := ui.NewVerticalBox()
|
||||
vboxN.SetPadded(true)
|
||||
vboxN.Append(ui.NewLabel(a), false)
|
||||
|
||||
entryNick := ui.NewEntry()
|
||||
entryNick.SetText(b)
|
||||
entryNick.SetReadOnly(false)
|
||||
|
||||
vboxN.Append(entryNick, false)
|
||||
|
||||
entryNick.OnChanged(func(*ui.Entry) {
|
||||
log.Println("OK. TEXT WAS CHANGED TO =", entryNick.Text())
|
||||
// Data.AccNick = entryNick.Text()
|
||||
})
|
||||
hbox.Append(vboxN, false)
|
||||
// End 'Nickname' vertical box
|
||||
}
|
||||
|
||||
func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string), pbVM *pb.Event_VM) {
|
||||
log.Println("createVmBox() START")
|
||||
log.Println("createVmBox() pbVM.Name", pbVM.Name)
|
||||
spew.Dump(pbVM)
|
||||
if (Data.Debug) {
|
||||
spew.Dump(pbVM)
|
||||
}
|
||||
vbox := ui.NewVerticalBox()
|
||||
vbox.SetPadded(true)
|
||||
|
||||
|
@ -45,90 +76,11 @@ func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string)) {
|
|||
hboxAccount.SetPadded(true)
|
||||
vbox.Append(hboxAccount, false)
|
||||
|
||||
// Start 'Provider' vertical box
|
||||
vboxC := ui.NewVerticalBox()
|
||||
vboxC.SetPadded(true)
|
||||
vboxC.Append(ui.NewLabel("Cloud Provider:"), false)
|
||||
|
||||
cbox := ui.NewCombobox()
|
||||
cbox.Append("WIT")
|
||||
cbox.Append("Evocative")
|
||||
vboxC.Append(cbox, false)
|
||||
cbox.SetSelected(0)
|
||||
|
||||
cbox.OnSelected(func(*ui.Combobox) {
|
||||
log.Println("OK. Selected Cloud Provider =", cbox.Selected())
|
||||
})
|
||||
hboxAccount.Append(vboxC, false)
|
||||
// End 'Cloud Provider' vertical box
|
||||
|
||||
// Start 'Region' vertical box
|
||||
vboxR := ui.NewVerticalBox()
|
||||
vboxR.SetPadded(true)
|
||||
vboxR.Append(ui.NewLabel("Region:"), false)
|
||||
|
||||
regbox := ui.NewCombobox()
|
||||
regbox.Append("Any")
|
||||
regbox.Append("SF")
|
||||
vboxR.Append(regbox, false)
|
||||
regbox.SetSelected(0)
|
||||
|
||||
regbox.OnSelected(func(*ui.Combobox) {
|
||||
log.Println("OK. Selected something =", regbox.Selected())
|
||||
})
|
||||
hboxAccount.Append(vboxR, false)
|
||||
// End 'Region' vertical box
|
||||
|
||||
// Start 'Nickname' vertical box
|
||||
vboxN := ui.NewVerticalBox()
|
||||
vboxN.SetPadded(true)
|
||||
vboxN.Append(ui.NewLabel("Account Nickname:"), false)
|
||||
|
||||
entryNick := ui.NewEntry()
|
||||
entryNick.SetReadOnly(false)
|
||||
|
||||
vboxN.Append(entryNick, false)
|
||||
|
||||
entryNick.OnChanged(func(*ui.Entry) {
|
||||
log.Println("OK. nickname =", entryNick.Text())
|
||||
Data.AccNick = entryNick.Text()
|
||||
})
|
||||
hboxAccount.Append(vboxN, false)
|
||||
// End 'Nickname' vertical box
|
||||
|
||||
// Start 'Username' vertical box
|
||||
vboxU := ui.NewVerticalBox()
|
||||
vboxU.SetPadded(true)
|
||||
vboxU.Append(ui.NewLabel("Account Username:"), false)
|
||||
|
||||
entryUser := ui.NewEntry()
|
||||
entryUser.SetReadOnly(false)
|
||||
|
||||
vboxU.Append(entryUser, false)
|
||||
|
||||
entryUser.OnChanged(func(*ui.Entry) {
|
||||
log.Println("OK. username =", entryUser.Text())
|
||||
Data.AccUser = entryUser.Text()
|
||||
})
|
||||
hboxAccount.Append(vboxU, false)
|
||||
// End 'Username' vertical box
|
||||
|
||||
// Start 'Password' vertical box
|
||||
vboxP := ui.NewVerticalBox()
|
||||
vboxP.SetPadded(true)
|
||||
vboxP.Append(ui.NewLabel("Account Password:"), false)
|
||||
|
||||
entryPass := ui.NewEntry()
|
||||
entryPass.SetReadOnly(false)
|
||||
|
||||
vboxP.Append(entryPass, false)
|
||||
|
||||
entryPass.OnChanged(func(*ui.Entry) {
|
||||
log.Println("OK. password =", entryPass.Text())
|
||||
Data.AccPass = entryPass.Text()
|
||||
})
|
||||
hboxAccount.Append(vboxP, false)
|
||||
// End 'Password' vertical box
|
||||
// Add hostname entry box
|
||||
makeEntryBox(hboxAccount, "hostname:", pbVM.Hostname)
|
||||
makeEntryBox(hboxAccount, "IPv6:", pbVM.IPv6)
|
||||
makeEntryBox(hboxAccount, "RAM:", string(pbVM.Memory))
|
||||
makeEntryBox(hboxAccount, "CPU:", string(pbVM.Cpus))
|
||||
|
||||
vbox.Append(ui.NewHorizontalSeparator(), false)
|
||||
|
||||
|
@ -136,15 +88,11 @@ func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string)) {
|
|||
hboxButtons.SetPadded(true)
|
||||
vbox.Append(hboxButtons, false)
|
||||
|
||||
okButton := CreateButton("Add Account", "ADD", custom)
|
||||
hboxButtons.Append(okButton, false)
|
||||
|
||||
backButton := CreateButton("Back", "BACK", custom)
|
||||
hboxButtons.Append(backButton, false)
|
||||
|
||||
hboxButtons.Append(CreateButton("Power On", "POWERON", custom), false)
|
||||
hboxButtons.Append(CreateButton("Power Off", "POWEROFF", custom), false)
|
||||
hboxButtons.Append(CreateButton("Destroy", "DESTROY", custom), false)
|
||||
hboxButtons.Append(CreateButton("Console", "XTERM", runTestExecClick), false)
|
||||
hboxButtons.Append(CreateButton("Done", "DONE", custom), false)
|
||||
|
||||
tab.Append(Data.CurrentVM, vbox)
|
||||
tab.SetMargined(0, true)
|
||||
|
|
Loading…
Reference in New Issue