2019-05-08 15:09:17 -05:00
|
|
|
package gui
|
2019-05-08 15:04:18 -05:00
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
import "github.com/gookit/config"
|
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-05-22 21:05:25 -05:00
|
|
|
//
|
|
|
|
// 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
|
2019-05-22 20:35:00 -05:00
|
|
|
|
2019-05-22 21:05:25 -05:00
|
|
|
type GuiDataStructure struct {
|
2019-05-22 20:35:00 -05:00
|
|
|
State string
|
|
|
|
MainWindow *ui.Window
|
2019-05-22 21:05:25 -05:00
|
|
|
Width int
|
2019-05-22 21:11:43 -05:00
|
|
|
Height int
|
2019-05-22 20:35:00 -05:00
|
|
|
ButtonClick func(int, string)
|
2019-05-22 23:34:46 -05:00
|
|
|
ButtonClickNew func(*ButtonMap)
|
2019-05-22 21:18:55 -05:00
|
|
|
CurrentVM string
|
2019-05-22 22:30:48 -05:00
|
|
|
MyArea *ui.Area
|
2019-05-22 21:11:43 -05:00
|
|
|
|
2019-05-22 22:30:48 -05:00
|
|
|
// stuff for the splash screen / setup tabs
|
2019-05-22 21:05:25 -05:00
|
|
|
cloudWindow *ui.Window
|
2019-05-22 22:30:48 -05:00
|
|
|
cloudTab *ui.Tab
|
|
|
|
cloudBox *ui.Box
|
|
|
|
smallBox *ui.Box
|
|
|
|
|
2019-05-22 21:11:43 -05:00
|
|
|
mainwin *ui.Window
|
|
|
|
maintab *ui.Tab
|
|
|
|
tabcount int
|
|
|
|
allButtons []ButtonMap
|
|
|
|
|
2019-05-22 22:30:48 -05:00
|
|
|
|
|
|
|
|
2019-05-22 21:11:43 -05:00
|
|
|
// stuff for the 'area'
|
|
|
|
fontButton *ui.FontButton
|
|
|
|
attrstr *ui.AttributedString
|
|
|
|
splashArea *ui.Area
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
type TableColumnData struct {
|
2019-05-12 20:05:17 -05:00
|
|
|
Index int
|
|
|
|
CellType string
|
|
|
|
Heading string
|
|
|
|
Color string
|
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
type ButtonMap struct {
|
|
|
|
B *ui.Button
|
2019-05-22 12:39:56 -05:00
|
|
|
FB *ui.FontButton
|
|
|
|
onClick func (int, string)
|
|
|
|
onChanged func (int, string)
|
|
|
|
custom func (int, string)
|
2019-05-22 23:34:46 -05:00
|
|
|
Name string // the text on the button
|
|
|
|
Note string // what type of button
|
2019-05-21 16:39:46 -05:00
|
|
|
}
|
|
|
|
|
2019-05-08 15:04:18 -05:00
|
|
|
func setupUI() {
|
2019-05-22 21:11:43 -05:00
|
|
|
Data.mainwin = ui.NewWindow("Cloud Control Panel", Data.Width, Data.Height, false)
|
|
|
|
Data.mainwin.OnClosing(func(*ui.Window) bool {
|
2019-05-08 15:04:18 -05:00
|
|
|
ui.Quit()
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
ui.OnShouldQuit(func() bool {
|
2019-05-22 21:11:43 -05:00
|
|
|
Data.mainwin.Destroy()
|
2019-05-08 15:04:18 -05:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2019-05-22 21:11:43 -05:00
|
|
|
Data.maintab = ui.NewTab()
|
|
|
|
Data.mainwin.SetChild(Data.maintab)
|
|
|
|
Data.mainwin.SetMargined(true)
|
2019-05-08 15:04:18 -05:00
|
|
|
|
2019-05-22 21:11:43 -05:00
|
|
|
Data.tabcount = 0
|
|
|
|
Data.mainwin.Show()
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|
|
|
|
|
2019-05-10 03:26:55 -05:00
|
|
|
func AddNewTab(mytab *ui.Tab, newbox ui.Control, tabOffset int) {
|
|
|
|
mytab.Append("Cloud Info", newbox)
|
|
|
|
mytab.SetMargined(tabOffset, true)
|
2019-05-10 01:25:55 -05:00
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
func InitColumns(mh *TableData, parts []TableColumnData) {
|
2019-05-12 14:54:11 -05:00
|
|
|
tmpBTindex := 0
|
2019-05-13 02:30:38 -05:00
|
|
|
humanID := 0
|
2019-05-12 14:54:11 -05:00
|
|
|
for key, foo := range parts {
|
2019-05-13 02:30:38 -05:00
|
|
|
log.Println("key, foo =", key, foo)
|
|
|
|
// log.Println("mh.Cells =", mh.Cells)
|
|
|
|
// log.Println("mh.Human =", mh.Human)
|
2019-05-13 02:08:59 -05:00
|
|
|
|
|
|
|
parts[key].Index = humanID
|
|
|
|
humanID += 1
|
|
|
|
|
|
|
|
if (foo.CellType == "BG") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowBTcolor (mh, tmpBTindex, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "BUTTON") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowButtonColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "TEXTCOLOR") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowTextColorColumn(mh, tmpBTindex, tmpBTindex + 1, parts[key].Heading, ui.TableColor{0.0, 0, 0.9, 1}, parts[key])
|
|
|
|
tmpBTindex += 2
|
|
|
|
} else if (foo.CellType == "TEXT") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowTextColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else {
|
|
|
|
panic("I don't know what this is in initColumnNames")
|
|
|
|
}
|
2019-05-12 14:54:11 -05:00
|
|
|
}
|
2019-05-13 02:46:11 -05:00
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []TableColumnData) *TableData {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh := new(TableData)
|
|
|
|
|
|
|
|
mh.RowCount = rowcount
|
|
|
|
mh.Rows = make([]RowData, mh.RowCount)
|
|
|
|
|
|
|
|
InitColumns(mh, parts)
|
2019-05-12 14:54:11 -05:00
|
|
|
|
|
|
|
model := ui.NewTableModel(mh)
|
|
|
|
table := ui.NewTable(
|
|
|
|
&ui.TableParams{
|
|
|
|
Model: model,
|
2019-05-13 02:46:11 -05:00
|
|
|
RowBackgroundColorModelColumn: 0, // Row Background color is always index zero
|
2019-05-12 14:54:11 -05:00
|
|
|
})
|
|
|
|
|
2019-05-13 02:46:11 -05:00
|
|
|
tmpBTindex := 0
|
2019-05-12 14:54:11 -05:00
|
|
|
for key, foo := range parts {
|
|
|
|
log.Println(key, foo)
|
|
|
|
if (foo.CellType == "BG") {
|
|
|
|
} else if (foo.CellType == "BUTTON") {
|
|
|
|
tmpBTindex += 1
|
|
|
|
table.AppendButtonColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable)
|
|
|
|
} else if (foo.CellType == "TEXTCOLOR") {
|
|
|
|
tmpBTindex += 1
|
2019-05-13 01:37:27 -05:00
|
|
|
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable,
|
|
|
|
&ui.TableTextColumnOptionalParams{
|
|
|
|
ColorModelColumn: tmpBTindex + 1,
|
|
|
|
});
|
2019-05-12 14:54:11 -05:00
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "TEXT") {
|
|
|
|
tmpBTindex += 1
|
2019-05-13 01:37:27 -05:00
|
|
|
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable, nil)
|
2019-05-12 14:54:11 -05:00
|
|
|
} else {
|
|
|
|
panic("I don't know what this is in initColumnNames")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
|
|
|
|
|
|
|
vbox.Append(table, true)
|
|
|
|
mytab.Append(name, vbox)
|
2019-05-12 14:54:11 -05:00
|
|
|
mytab.SetMargined(mytabcount, true)
|
2019-05-12 17:11:32 -05:00
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
vbox.Append(ui.NewVerticalSeparator(), false)
|
|
|
|
|
|
|
|
hbox := ui.NewHorizontalBox()
|
|
|
|
hbox.SetPadded(true)
|
|
|
|
|
|
|
|
myAddVM := addVmButton("Add Virtual Machine")
|
|
|
|
hbox.Append(myAddVM, false)
|
|
|
|
|
|
|
|
myClose := closeButton("Close", mytab)
|
|
|
|
hbox.Append(myClose, false)
|
|
|
|
|
|
|
|
vbox.Append(hbox, false)
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
return mh
|
2019-05-12 14:54:11 -05:00
|
|
|
}
|
|
|
|
|
2019-05-08 15:09:17 -05:00
|
|
|
func DoGUI() {
|
2019-05-13 01:02:39 -05:00
|
|
|
for {
|
|
|
|
ui.Main(setupUI)
|
|
|
|
log.Println("GUI exited. Not sure what to do here. os.Exit() ?")
|
|
|
|
}
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|
2019-05-21 16:39:46 -05:00
|
|
|
|
2019-05-22 12:39:56 -05:00
|
|
|
func defaultButtonClick(button *ui.Button) {
|
|
|
|
log.Println("defaultButtonClick() button =", button)
|
2019-05-22 21:11:43 -05:00
|
|
|
for key, foo := range Data.allButtons {
|
|
|
|
log.Println("Data.allButtons =", key, foo)
|
|
|
|
if Data.allButtons[key].B == button {
|
2019-05-22 12:39:56 -05:00
|
|
|
log.Println("\tBUTTON MATCHED")
|
2019-05-22 23:34:46 -05:00
|
|
|
log.Println("\tData.allButtons[key].Name", Data.allButtons[key].Name)
|
|
|
|
log.Println("\tData.allButtons[key].Note", Data.allButtons[key].Note)
|
|
|
|
if (Data.ButtonClickNew != nil) {
|
|
|
|
Data.ButtonClickNew( &Data.allButtons[key])
|
|
|
|
} else if Data.allButtons[key].custom != nil {
|
|
|
|
Data.allButtons[key].custom(42, "BUTTON DOES NOTHING")
|
2019-05-22 12:39:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultFontButtonClick(button *ui.FontButton) {
|
|
|
|
log.Println("defaultButtonClick() button =", button)
|
2019-05-22 21:11:43 -05:00
|
|
|
for key, foo := range Data.allButtons {
|
|
|
|
log.Println("Data.allButtons =", key, foo)
|
2019-05-22 12:39:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateButton(name string, note string, custom func(int, string)) *ui.Button {
|
2019-05-22 13:27:58 -05:00
|
|
|
newB := ui.NewButton(name)
|
2019-05-22 12:39:56 -05:00
|
|
|
|
|
|
|
newB.OnClicked(defaultButtonClick)
|
|
|
|
|
|
|
|
var newmap ButtonMap
|
|
|
|
newmap.B = newB
|
2019-05-22 23:34:46 -05:00
|
|
|
newmap.Note = note
|
|
|
|
newmap.Name = name
|
2019-05-22 12:39:56 -05:00
|
|
|
newmap.custom = custom
|
2019-05-22 21:11:43 -05:00
|
|
|
Data.allButtons = append(Data.allButtons, newmap)
|
2019-05-22 12:39:56 -05:00
|
|
|
|
|
|
|
return newB
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateFontButton(name string, note string, custom func(int, string)) *ui.FontButton {
|
|
|
|
newB := ui.NewFontButton()
|
|
|
|
|
|
|
|
newB.OnChanged(defaultFontButtonClick)
|
|
|
|
|
|
|
|
var newmap ButtonMap
|
|
|
|
newmap.FB = newB
|
2019-05-22 23:34:46 -05:00
|
|
|
newmap.Note = note
|
|
|
|
newmap.Name = name
|
2019-05-22 12:39:56 -05:00
|
|
|
newmap.custom = custom
|
2019-05-22 21:11:43 -05:00
|
|
|
Data.allButtons = append(Data.allButtons, newmap)
|
2019-05-22 12:39:56 -05:00
|
|
|
|
|
|
|
return newB
|
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
func closeButtonClick(button *ui.Button) {
|
|
|
|
log.Println("closeButtonClick() hostname =", config.String("hostname"), button)
|
|
|
|
spew.Dump(button)
|
|
|
|
}
|
|
|
|
|
|
|
|
func closeButton(name string, mytab *ui.Tab) ui.Control {
|
|
|
|
tmpButton := ui.NewButton(name)
|
2019-05-22 20:35:00 -05:00
|
|
|
tmpButton.OnClicked(defaultButtonClick)
|
2019-05-21 16:39:46 -05:00
|
|
|
|
|
|
|
return tmpButton
|
|
|
|
}
|
|
|
|
|
|
|
|
func addVmButtonClick(button *ui.Button) {
|
|
|
|
log.Println("addVMButtonClick()")
|
|
|
|
spew.Dump(button)
|
|
|
|
}
|
|
|
|
|
|
|
|
func addVmButton(name string) ui.Control {
|
|
|
|
tmpButton := ui.NewButton(name)
|
|
|
|
tmpButton.OnClicked(addVmButtonClick)
|
|
|
|
|
|
|
|
return tmpButton
|
|
|
|
}
|