diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 107 |
1 files changed, 47 insertions, 60 deletions
@@ -1,8 +1,6 @@ package gui import ( - "log" - "os" "embed" ) @@ -18,83 +16,76 @@ const Yaxis = 1 // stack things vertically var res embed.FS func init() { - log.Println("gui.init() has been run") + debugGui = true + log(debugGui, "gui.init() has been run") Config.counter = 0 Config.prefix = "wit" - // Config.Debug.Debug = true - // Config.Debug.Node = true - // Config.Debug.Tabs = true - title := "guiBinaryTree" w := 640 h := 480 // Populates the top of the binary tree Config.master = addNode(title, w, h) - if (Config.Debug.Debug) { - Config.master.Dump() - } + // Config.master.Dump() + debugGui = false } -func Init() { - var initBAD bool = true +func InitPlugins(names []string) { + log(debugGui, "Starting gui.Init()") - if (Config.Debug.Debug) { - log.Println("Starting gui.Init()") - } for _, aplug := range allPlugins { - log.Println("gui.LoadToolkit() already loaded toolkit plugin =", aplug.name) - initBAD = false + log(debugGui, "gui.LoadToolkit() already loaded toolkit plugin =", aplug.name) + for _, name := range names { + if (name == aplug.name) { + return + } + } } - // the program didn't specify a plugin. Try to load one - // TODO: detect the OS & user preferences to load the best one - if (initBAD) { - if (LoadToolkit("andlabs")) { - initBAD = false + // try to load each plugin in the order passed to this function + for _, name := range names { + if (LoadToolkit(name)) { + // aplug.InitOk = true + // aplug.Init() + return } } - // andlabs gui plugin failed. fall back to the terminal gui (should be compiled into the binary) - if (initBAD) { - if (LoadToolkit("gocui")) { - initBAD = false - } + // the program didn't specify a plugin. Try to load one + // TODO: detect the OS & user preferences to load the best one + // TODO: commented out Init() on 02/26/2023 because I'm not sure how to run it correctly + if (LoadToolkit("andlabs")) { + // aplug.InitOk = true + // aplug.Init() + return } - // locate the shared library file - // panic("WTF Init()") - for _, aplug := range allPlugins { - log.Println("gui.Node.Init() toolkit plugin =", aplug.name) - if (aplug.InitOk) { - log.Println("gui.Node.Init() Already Ran Init()", aplug.name) - continue - } - if (aplug.Init == nil) { - log.Println("gui.Node.Main() Init == nil", aplug.name) - continue - } - aplug.InitOk = true - aplug.Init() + if (LoadToolkit("gocui")) { + // aplug.InitOk = true + // aplug.Init() + return } - // StandardExit(nil) + + // Should die here? TODO: need a Node to call StandardExit + // StandardExit("golang wit/gui could not load a plugin TODO: do something to STDOUT (?)") } // This should not pass a function func Main(f func()) { - if (Config.Debug.Debug) { - log.Println("Starting gui.Main() (using gtk via andlabs/ui)") - } + log(debugGui, "Starting gui.Main() (using gtk via andlabs/ui)") + + InitPlugins([]string{"andlabs", "gocui"}) + for _, aplug := range allPlugins { - log.Println("gui.Node.NewButton() toolkit plugin =", aplug.name) + log(debugGui, "gui.Node.NewButton() toolkit plugin =", aplug.name) if (aplug.MainOk) { - log.Println("gui.Node.Main() Already Ran Main()", aplug.name) + log(debugGui, "gui.Node.Main() Already Ran Main()", aplug.name) continue } if (aplug.Main == nil) { - log.Println("gui.Node.Main() Main == nil", aplug.name) + log(debugGui, "gui.Node.Main() Main == nil", aplug.name) continue } aplug.MainOk = true @@ -113,10 +104,10 @@ func Main(f func()) { // Linux, MacOS and Windows work (they all work differently. suprise. surprise.) // For example: gui.Queue(NewWindow()) func Queue(f func()) { - log.Println("Sending function to gui.Main() (using gtk via andlabs/ui)") + log(debugGui, "Sending function to gui.Main() (using gtk via andlabs/ui)") // toolkit.Queue(f) for _, aplug := range allPlugins { - log.Println("gui.Node.NewButton() toolkit plugin =", aplug.name) + log(debugGui, "gui.Node.NewButton() toolkit plugin =", aplug.name) if (aplug.Queue == nil) { continue } @@ -126,24 +117,20 @@ func Queue(f func()) { // The window is destroyed but the application does not quit func StandardClose(n *Node) { - if (Config.Debug.Debug) { - log.Println("wit/gui Standard Window Close. name =", n.Name) - } + log(debugGui, "wit/gui Standard Window Close. name =", n.Name) + log(debugGui, "wit/gui Standard Window Close. n.custom exit =", n.custom) } // The window is destroyed but the application does not quit func StandardExit(n *Node) { - if (Config.Debug.Debug) { - log.Println("wit/gui Standard Window Exit. running os.Exit()") - } - - log.Println("gui.Node.StandardExit() attempt to exit each toolkit plugin") + log(debugGui, "wit/gui Standard Window Exit. running os.Exit()") + log(debugGui, "gui.Node.StandardExit() attempt to exit each toolkit plugin") for i, aplug := range allPlugins { - log.Println("gui.Node.NewButton()", i, aplug) + log(debugGui, "gui.Node.NewButton()", i, aplug) if (aplug.Quit != nil) { aplug.Quit() } } - os.Exit(0) + exit("StandardExit") } |
