2019-06-01 05:38:49 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
import "time"
|
|
|
|
import "regexp"
|
2019-06-02 13:40:44 -05:00
|
|
|
// import "os"
|
2019-06-01 05:38:49 -05:00
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-06-02 13:40:44 -05:00
|
|
|
const Xaxis = 0
|
|
|
|
const Yaxis = 1
|
|
|
|
|
2019-06-01 05:38:49 -05:00
|
|
|
func GuiInit() {
|
|
|
|
ui.OnShouldQuit(func() bool {
|
|
|
|
// mouseClick(&newBM)
|
|
|
|
ui.Quit()
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-02 14:38:29 -05:00
|
|
|
// func InitGuiWindow(c *pb.Config, action string, maketab func(*GuiWindow) *GuiBox, uiW *ui.Window, uiT *ui.Tab) *GuiWindow {
|
2019-06-02 17:49:52 -05:00
|
|
|
func InitGuiWindow(action string, gw *GuiWindow) *GuiWindow {
|
2019-06-01 16:10:12 -05:00
|
|
|
log.Println("InitGuiWindow() START")
|
2019-06-01 05:38:49 -05:00
|
|
|
var newGuiWindow GuiWindow
|
2019-06-02 17:49:52 -05:00
|
|
|
newGuiWindow.Width = Config.Width
|
|
|
|
newGuiWindow.Height = Config.Height
|
2019-06-01 16:10:12 -05:00
|
|
|
newGuiWindow.Action = action
|
2019-06-02 14:38:29 -05:00
|
|
|
newGuiWindow.MakeWindow = gw.MakeWindow
|
|
|
|
newGuiWindow.UiWindow = gw.UiWindow
|
|
|
|
newGuiWindow.UiTab = gw.UiTab
|
2019-06-01 16:10:12 -05:00
|
|
|
newGuiWindow.BoxMap = make(map[string]*GuiBox)
|
|
|
|
newGuiWindow.EntryMap = make(map[string]*GuiEntry)
|
|
|
|
newGuiWindow.EntryMap["test"] = nil
|
2019-06-01 05:38:49 -05:00
|
|
|
Data.Windows = append(Data.Windows, &newGuiWindow)
|
|
|
|
|
2019-06-01 16:10:12 -05:00
|
|
|
log.Println("InitGuiWindow() END *GuiWindow =", &newGuiWindow)
|
|
|
|
return &newGuiWindow
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-02 17:49:52 -05:00
|
|
|
func StartNewWindow(bg bool, action string, callback func(*GuiWindow) *GuiBox) {
|
2019-06-02 14:38:29 -05:00
|
|
|
log.Println("StartNewWindow() Create a new window")
|
|
|
|
var junk GuiWindow
|
|
|
|
junk.MakeWindow = callback
|
2019-06-02 17:49:52 -05:00
|
|
|
window := InitGuiWindow(action, &junk)
|
2019-06-01 05:38:49 -05:00
|
|
|
if (bg) {
|
2019-06-02 14:38:29 -05:00
|
|
|
log.Println("StartNewWindow() START NEW GOROUTINE for ui.Main()")
|
2019-06-01 05:38:49 -05:00
|
|
|
go ui.Main(func() {
|
2019-06-02 14:38:29 -05:00
|
|
|
log.Println("gui.StartNewWindow() inside ui.Main()")
|
2019-06-01 16:10:12 -05:00
|
|
|
InitTabWindow(window)
|
2019-06-01 05:38:49 -05:00
|
|
|
})
|
2019-06-02 14:38:29 -05:00
|
|
|
time.Sleep(2000 * time.Millisecond) // this might make it more stable on windows?
|
2019-06-01 05:38:49 -05:00
|
|
|
} else {
|
2019-06-02 14:38:29 -05:00
|
|
|
log.Println("StartNewWindow() WAITING for ui.Main()")
|
2019-06-01 05:38:49 -05:00
|
|
|
ui.Main(func() {
|
2019-06-02 14:38:29 -05:00
|
|
|
log.Println("gui.StartNewWindow() inside ui.Main()")
|
2019-06-01 16:10:12 -05:00
|
|
|
InitTabWindow(window)
|
2019-06-01 05:38:49 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitTabWindow(gw *GuiWindow) {
|
|
|
|
log.Println("InitTabWindow() THIS WINDOW IS NOT YET SHOWN")
|
|
|
|
|
|
|
|
gw.UiWindow = ui.NewWindow("", int(gw.Width), int(gw.Height), true)
|
|
|
|
gw.UiWindow.SetBorderless(false)
|
|
|
|
|
|
|
|
// create a 'fake' button entry for the mouse clicks
|
2019-06-02 17:19:53 -05:00
|
|
|
/*
|
2019-06-01 05:38:49 -05:00
|
|
|
var newBM GuiButton
|
|
|
|
newBM.Action = "QUIT"
|
|
|
|
newBM.GW = gw
|
|
|
|
Data.AllButtons = append(Data.AllButtons, &newBM)
|
2019-06-02 17:19:53 -05:00
|
|
|
*/
|
2019-06-01 05:38:49 -05:00
|
|
|
|
|
|
|
gw.UiWindow.OnClosing(func(*ui.Window) bool {
|
|
|
|
log.Println("InitTabWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw)
|
|
|
|
ui.Quit()
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
gw.UiTab = ui.NewTab()
|
|
|
|
gw.UiWindow.SetChild(gw.UiTab)
|
|
|
|
gw.UiWindow.SetMargined(true)
|
|
|
|
|
|
|
|
log.Println("InitTabWindow() gw =", gw)
|
|
|
|
|
2019-06-01 23:15:55 -05:00
|
|
|
gw.MakeWindow(gw)
|
2019-06-01 05:38:49 -05:00
|
|
|
gw.UiWindow.Show()
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
// string handling examples that might be helpful for normalizeInt()
|
|
|
|
isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString
|
|
|
|
|
|
|
|
for _, username := range []string{"userone", "user2", "user-three"} {
|
|
|
|
if !isAlpha(username) {
|
|
|
|
fmt.Printf("%q is not valid\n", username)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const alpha = "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
|
|
|
|
func alphaOnly(s string) bool {
|
|
|
|
for _, char := range s {
|
|
|
|
if !strings.Contains(alpha, strings.ToLower(string(char))) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
func normalizeInt(s string) string {
|
|
|
|
// reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
|
|
|
reg, err := regexp.Compile("[^0-9]+")
|
|
|
|
if err != nil {
|
|
|
|
log.Println("normalizeInt() regexp.Compile() ERROR =", err)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
clean := reg.ReplaceAllString(s, "")
|
|
|
|
log.Println("normalizeInt() s =", clean)
|
|
|
|
return clean
|
|
|
|
}
|
|
|
|
|
2019-06-02 15:40:44 -05:00
|
|
|
func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) {
|
|
|
|
ui.MsgBox(gw.UiWindow, msg1, msg2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) {
|
|
|
|
ui.MsgBoxError(gw.UiWindow, msg1, msg2)
|
|
|
|
}
|