2019-05-24 02:53:34 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
import "time"
|
|
|
|
import "fmt"
|
2019-05-24 11:02:35 -05:00
|
|
|
import "strings"
|
|
|
|
import "os/exec"
|
2019-05-24 13:32:47 -05:00
|
|
|
import "runtime"
|
2019-06-01 23:15:55 -05:00
|
|
|
import "reflect"
|
2019-05-24 02:53:34 -05:00
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-24 17:35:41 -05:00
|
|
|
import "github.com/davecgh/go-spew/spew"
|
2019-05-24 02:53:34 -05:00
|
|
|
|
2019-05-24 17:35:41 -05:00
|
|
|
// import pb "git.wit.com/wit/witProtobuf"
|
2019-05-24 02:53:34 -05:00
|
|
|
|
2019-06-01 04:41:03 -05:00
|
|
|
// THIS IS NOT CLEAN (but probably doesn't need to be. it's debugging)
|
2019-06-01 03:32:55 -05:00
|
|
|
|
2019-05-24 02:53:34 -05:00
|
|
|
// can not pass any args to this (?)
|
2019-05-29 21:57:15 -05:00
|
|
|
/*
|
2019-05-24 02:53:34 -05:00
|
|
|
func setupCloudUI() {
|
2019-05-29 14:21:10 -05:00
|
|
|
Data.Window1.W = ui.NewWindow("Cloud Control Panel", Data.Width, Data.Height, false)
|
|
|
|
Data.Window1.W.OnClosing(func(*ui.Window) bool {
|
2019-05-24 02:53:34 -05:00
|
|
|
ui.Quit()
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
ui.OnShouldQuit(func() bool {
|
2019-05-29 14:21:10 -05:00
|
|
|
Data.Window1.W.Destroy()
|
2019-05-24 02:53:34 -05:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2019-05-29 14:21:10 -05:00
|
|
|
Data.Window1.T = ui.NewTab()
|
|
|
|
Data.Window1.W.SetChild(Data.Window1.T)
|
|
|
|
Data.Window1.W.SetMargined(true)
|
2019-05-24 02:53:34 -05:00
|
|
|
|
2019-05-29 15:11:08 -05:00
|
|
|
// Data.tabcount = 0
|
2019-05-29 14:21:10 -05:00
|
|
|
Data.Window1.T.Append("Cloud Info", makeCloudInfoBox())
|
2019-05-29 15:11:08 -05:00
|
|
|
// Data.Window1.T.SetMargined(Data.tabcount, true)
|
2019-05-24 02:53:34 -05:00
|
|
|
|
2019-05-29 14:21:10 -05:00
|
|
|
Data.Window1.W.Show()
|
2019-05-24 02:53:34 -05:00
|
|
|
}
|
2019-05-29 21:57:15 -05:00
|
|
|
*/
|
2019-05-24 02:53:34 -05:00
|
|
|
|
|
|
|
func addTableTab() {
|
|
|
|
var parts []TableColumnData
|
|
|
|
|
|
|
|
for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} {
|
|
|
|
log.Println(key, foo)
|
|
|
|
|
|
|
|
var b TableColumnData
|
|
|
|
b.CellType = foo
|
|
|
|
b.Heading = fmt.Sprintf("heading%d", key)
|
|
|
|
parts = append(parts, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Sleep for 2 seconds, then try to add new tabs")
|
|
|
|
time.Sleep(1 * 1000 * 1000 * 1000)
|
2019-05-29 21:57:15 -05:00
|
|
|
// AddTableTab(Data.Window1.T, 1, "test seven", 7, parts, nil)
|
2019-05-24 02:53:34 -05:00
|
|
|
}
|
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
func addDebuggingButtons(box *GuiBox) {
|
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
|
|
|
box.UiBox.Append(vbox, false)
|
|
|
|
|
2019-05-24 02:53:34 -05:00
|
|
|
vbox.Append(ui.NewLabel("Debugging:"), false)
|
|
|
|
|
|
|
|
vbox.Append(ui.NewColorButton(), false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a := CreateButton(box, nil, nil, "Add Account", "ADD", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
vbox.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(box, nil, nil, "Quit", "QUIT", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
vbox.Append(a.B, false)
|
2019-05-24 02:53:34 -05:00
|
|
|
|
|
|
|
// ATTEMPT TO ADD THE TABLE HERE
|
|
|
|
add2button := ui.NewButton("Add a Test Table")
|
|
|
|
add2button.OnClicked(func(*ui.Button) {
|
|
|
|
log.Println("send over socket")
|
|
|
|
addTableTab()
|
|
|
|
})
|
|
|
|
vbox.Append(add2button, false)
|
|
|
|
// ATTEMPT TO ADD THE TABLE HERE END
|
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(box, nil, nil, "Hide & Show Box1&2", "HIDE", runTestHide)
|
2019-05-30 13:41:23 -05:00
|
|
|
vbox.Append(a.B, false)
|
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(box, nil, nil, "Close GUI", "QUIT", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
vbox.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(box, nil, nil, "DEBUG goroutines", "DEBUG", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
vbox.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(box, nil, nil, "xterm", "XTERM", runTestExecClick)
|
2019-05-30 13:41:23 -05:00
|
|
|
vbox.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(box, nil, nil, "Load test.json config file", "CONFIG", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
vbox.Append(a.B, false)
|
2019-05-24 11:02:35 -05:00
|
|
|
}
|
|
|
|
|
2019-05-30 10:55:54 -05:00
|
|
|
func runTestHide(b *GuiButton) {
|
2019-05-29 21:57:15 -05:00
|
|
|
/*
|
2019-05-29 15:11:08 -05:00
|
|
|
log.Println("runTestHide START")
|
|
|
|
Data.Window1.Box1.Hide()
|
|
|
|
Data.Window1.Box2.Hide()
|
2019-05-29 17:46:21 -05:00
|
|
|
// time.Sleep(2000 * time.Millisecond)
|
2019-05-29 15:11:08 -05:00
|
|
|
Data.State = "HIDE"
|
|
|
|
log.Println("runTestHide END")
|
2019-05-29 21:57:15 -05:00
|
|
|
*/
|
2019-05-29 15:11:08 -05:00
|
|
|
}
|
|
|
|
|
2019-05-30 10:55:54 -05:00
|
|
|
func runPingClick(b *GuiButton) {
|
2019-05-24 17:35:41 -05:00
|
|
|
log.Println("runPingClick START")
|
2019-05-25 18:00:33 -05:00
|
|
|
log.Println("runTestExecClick b.VM", b.VM)
|
|
|
|
hostname := "localhost"
|
|
|
|
if (b.VM != nil) {
|
|
|
|
hostname = b.VM.Hostname
|
|
|
|
}
|
2019-05-24 17:35:41 -05:00
|
|
|
spew.Dump(b)
|
|
|
|
var tmp []string
|
2019-05-29 04:44:18 -05:00
|
|
|
tmp = append(tmp, "xterm", "-geometry", "120x30", "-e", "ping " + hostname + ";sleep 3")
|
|
|
|
go runCommand(tmp)
|
2019-05-24 17:35:41 -05:00
|
|
|
log.Println("runPingClick END")
|
|
|
|
}
|
|
|
|
|
2019-05-30 10:55:54 -05:00
|
|
|
func runTestExecClick(b *GuiButton) {
|
2019-05-24 11:02:35 -05:00
|
|
|
log.Println("runTestExecClick START")
|
2019-05-24 13:32:47 -05:00
|
|
|
if runtime.GOOS == "linux" {
|
2019-05-24 17:35:41 -05:00
|
|
|
go runSimpleCommand("xterm -report-fonts")
|
|
|
|
} else if runtime.GOOS == "windows" {
|
2019-05-25 18:00:33 -05:00
|
|
|
go runSimpleCommand("mintty.exe")
|
2019-05-24 13:32:47 -05:00
|
|
|
} else {
|
2019-05-24 17:35:41 -05:00
|
|
|
go runSimpleCommand("xterm")
|
2019-05-24 13:32:47 -05:00
|
|
|
}
|
2019-05-24 11:02:35 -05:00
|
|
|
log.Println("runTestExecClick END")
|
|
|
|
}
|
|
|
|
|
2019-05-24 17:35:41 -05:00
|
|
|
func runSimpleCommand(s string) {
|
|
|
|
cmd := strings.TrimSpace(s) // this is like 'chomp' in perl
|
|
|
|
cmdArgs := strings.Fields(cmd)
|
|
|
|
runCommand(cmdArgs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runCommand(cmdArgs []string) {
|
2019-05-29 04:44:18 -05:00
|
|
|
log.Println("runCommand() START", cmdArgs)
|
2019-05-24 11:02:35 -05:00
|
|
|
process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
|
2019-05-24 17:35:41 -05:00
|
|
|
// process := exec.Command("xterm", "-e", "ping localhost")
|
2019-05-29 04:44:18 -05:00
|
|
|
log.Println("runCommand() process.Start()")
|
2019-05-24 11:02:35 -05:00
|
|
|
process.Start()
|
2019-05-29 04:44:18 -05:00
|
|
|
log.Println("runCommand() process.Wait()")
|
2019-05-24 11:02:35 -05:00
|
|
|
process.Wait()
|
2019-05-29 04:44:18 -05:00
|
|
|
log.Println("runCommand() NEED TO CHECK THE TIME HERE TO SEE IF THIS WORKED")
|
|
|
|
log.Println("runCommand() OTHERWISE INFORM THE USER")
|
|
|
|
log.Println("runCommand() END")
|
2019-05-24 02:53:34 -05:00
|
|
|
}
|
2019-06-01 23:15:55 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// this watches the GUI primarily to process protobuf's
|
|
|
|
// this is pointless or wrong but I use it for debugging
|
|
|
|
//
|
|
|
|
func WatchGUI() {
|
|
|
|
count := 0
|
|
|
|
|
|
|
|
for {
|
|
|
|
if (count > 20) {
|
|
|
|
log.Println("Sleep() in watchGUI() Data.State =", Data.State)
|
|
|
|
for i, window := range Data.Windows {
|
|
|
|
log.Println("watchGUI() Data.Windows i =", i, "Action =", window.Action)
|
|
|
|
for name, abox := range window.BoxMap {
|
|
|
|
log.Println("\twatchGUI() BOX name =", name)
|
|
|
|
if (name == "SplashArea3") {
|
|
|
|
log.Println("\t\twatchGUI() BOX abox =", reflect.TypeOf(abox))
|
|
|
|
win := abox.Window
|
|
|
|
log.Println("\t\twatchGUI() BOX win =", reflect.TypeOf(win))
|
|
|
|
area := win.Area
|
|
|
|
log.Println("\t\twatchGUI() BOX area =", reflect.TypeOf(area), area.UiArea)
|
|
|
|
// spew.Dump(area.UiArea)
|
|
|
|
// area.UiArea.Show()
|
|
|
|
// time.Sleep(2000 * time.Millisecond)
|
|
|
|
// os.Exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count = 0
|
|
|
|
}
|
|
|
|
count += 1
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|