diff options
| author | Jeff Carr <[email protected]> | 2022-11-13 08:53:03 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2022-11-13 08:53:03 -0600 |
| commit | 207cf7ea16f1da8fa9f893504d77a2856298cc22 (patch) | |
| tree | 54d513b83ce797be75268f7d8867e0b01ab8f23e /main.go | |
| parent | ed382bec55be25039e4dcf020d1512139855c9bb (diff) | |
Massive refactor to use go plugins. This is neat.
update README.md
set xterm title. make os.Exit() default on window close
add a toolkit.Widget to the node structure
remove 'Greeter' symbol mapping scheme
removed the testing greeter code
plugins:
attempt to load plugins in a sensible order
andlabs/ui:
working andlabs/ui plugin (andlabs2)
buttons work in andlabs plugin
TODO: re-implement non-plugin version for Windows
mswindows doesn't support go plugins yet
gocui:
put the gocui console so file in the binary
does a full init of gocui plugin
Button() and Group() working very well with gogui
cleanly exit gocui
technically you can load two toolkits at the same time
kinda both working at the same time. esoteric
two working plugins at the same time
give up working on two gui's at the same time
this is fun, but _not interesting
wow. this actually works. NewButton() from both toolkits
examples:
all the examples run again
remove early helloplugin example
buttonplugin example cmd code
buttonplugin runs and ldd is minimum
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 109 |
1 files changed, 94 insertions, 15 deletions
@@ -3,22 +3,29 @@ package gui import ( "log" "os" + "embed" ) -import toolkit "git.wit.org/wit/gui/toolkit/andlabs" +// Windows doesn't support plugins. How can I keep andlabs and only compile it on windows? +// https://forum.heroiclabs.com/t/setting-up-goland-to-compile-plugins-on-windows/594/5 +// import toolkit "git.wit.org/wit/gui/toolkit/andlabs" const Xaxis = 0 // stack things horizontally const Yaxis = 1 // stack things vertically +// may this plugin work when all other plugins fail +//go:embed toolkit/gocui.so +var res embed.FS + func init() { log.Println("gui.init() has been run") Config.counter = 0 Config.prefix = "wit" - // Config.Options.Debug = true - // Config.Options.DebugNode = true - // Config.Options.DebugTabs = true + // Config.Debug.Debug = true + // Config.Debug.Node = true + // Config.Debug.Tabs = true title := "guiBinaryTree" w := 640 @@ -26,45 +33,117 @@ func init() { // Populates the top of the binary tree Config.master = addNode(title, w, h) - if (Config.Options.Debug) { + if (Config.Debug.Debug) { Config.master.Dump() } +} + +func Init() { + var initBAD bool = true + + 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 + } + + // 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("andlabs2")) { + initBAD = false + } + } + + // andlabs2 gui failed. fall back to the terminal gui (should be compiled into the binary) + if (initBAD) { + if (LoadToolkit("gocui")) { + initBAD = false + } + } - // load the gocui plugin - PlugGocli = LoadPlugin("../../toolkit/gocui.so") - PlugGocliOk = false + // 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() + } + // StandardExit(nil) } +// This should not pass a function func Main(f func()) { - if (Config.Options.Debug) { + if (Config.Debug.Debug) { log.Println("Starting gui.Main() (using gtk via andlabs/ui)") } - toolkit.Main(f) + for _, aplug := range allPlugins { + log.Println("gui.Node.NewButton() toolkit plugin =", aplug.name) + if (aplug.MainOk) { + log.Println("gui.Node.Main() Already Ran Main()", aplug.name) + continue + } + if (aplug.Main == nil) { + log.Println("gui.Node.Main() Main == nil", aplug.name) + continue + } + aplug.MainOk = true + aplug.Main(f) + // f() + } + // toolkit.Main(f) } +// This should never be exposed(?) + // Other goroutines must use this to access the GUI // // You can not acess / process the GUI thread directly from // other goroutines. This is due to the nature of how // Linux, MacOS and Windows work (they all work differently. suprise. surprise.) // For example: gui.Queue(NewWindow()) -func Queue(f func()) { +func queue(f func()) { log.Println("Sending function to gui.Main() (using gtk via andlabs/ui)") - toolkit.Queue(f) + // toolkit.Queue(f) + for _, aplug := range allPlugins { + log.Println("gui.Node.NewButton() toolkit plugin =", aplug.name) + if (aplug.Queue == nil) { + continue + } + aplug.Queue(f) + } } // The window is destroyed but the application does not quit func StandardClose(n *Node) { - if (Config.Options.Debug) { + if (Config.Debug.Debug) { log.Println("wit/gui Standard Window Close. name =", n.Name) } } - // The window is destroyed but the application does not quit func StandardExit(n *Node) { - if (Config.Options.Debug) { + 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") + for i, aplug := range allPlugins { + log.Println("gui.Node.NewButton()", i, aplug) + if (aplug.Quit != nil) { + aplug.Quit() + } + } + os.Exit(0) } |
