From 5005edc9e37cb207f6c6035ea6fe3c3d98d94caa Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 20 Jan 2025 05:06:08 -0600 Subject: add a 'app' defined default plugin variable --- Makefile | 13 ++++++++----- init.go | 12 ++++++++++++ plugin.go | 40 ++++++++++++++++++++-------------------- structs.go | 5 ++--- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 3adf833..83bbf8d 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,17 @@ -all: goimports vet +all: @echo - @echo This is the core gui package 'go.wit.com/gui/gui' + @echo This is the core GUI package 'go.wit.com/gui' @echo - @echo It creates a binary tree of widgets - @echo The widgets are things like Windows, Buttons, Labels, etc + @echo "It creates a binary tree of widgets (Windows, Buttons, etc)" + @echo "This is the interface to the GUI GO plugin (ncurses, GTK, etc)" @echo + @echo "todo: rewrite this using protobufs" + @echo + @make goimports vet vet: @GO111MODULE=off go vet - @echo go vet: this go library package builds okay + @echo go vet: this go library should build okay goimports: goimports -w *.go diff --git a/init.go b/init.go index 4dfbf07..3883fa1 100644 --- a/init.go +++ b/init.go @@ -280,6 +280,12 @@ func (n *Node) Default() *Node { log.Log(WARN, "LoadToolkit() failed for =", argGui.GuiPlugin) return nil } + if me.appPlugin != "" { + if n, err = n.LoadToolkit(me.appPlugin); err == nil { + return n + } + } + // if DISPLAY isn't set, return since gtk can't load // TODO: figure out how to check what to do in macos and mswindows if os.Getenv("DISPLAY") == "" { @@ -393,3 +399,9 @@ func trapStdout() { // defer guioutf.Close() } + +// sets the applications requested plugin +// the command line arguements override this +func (n *Node) SetAppDefaultPlugin(plugname string) { + me.appPlugin = plugname +} diff --git a/plugin.go b/plugin.go index 72b3112..7e8ad3c 100644 --- a/plugin.go +++ b/plugin.go @@ -56,6 +56,26 @@ type aplug struct { var allPlugins []*aplug +func (n *Node) LoadToolkit(name string) (*Node, error) { + log.Log(PLUG, "LoadToolkit() START for name =", name) + plug := initPlugin(name) + if plug == nil { + return n, errors.New("initPlugin(" + name + ") failed") + } + plug.dead = false + + log.Log(PLUG, "LoadToolkit() sending Toolkit Init action to the plugin channel") + var a widget.Action + a.ActionType = widget.ToolkitInit + plug.pluginChan <- a + // sleep(.5) // temp hack until chan communication is setup + + // TODO: find a new way to do this that is locking, safe and accurate + me.rootNode.redraw(plug) + log.Log(PLUG, "LoadToolkit() END for name =", name) + return n, nil +} + // loads and initializes a toolkit (andlabs/ui, gocui, etc) // attempts to locate the .so file func initPlugin(name string) *aplug { @@ -281,26 +301,6 @@ func (n *Node) ListToolkits() { } } -func (n *Node) LoadToolkit(name string) (*Node, error) { - log.Log(PLUG, "LoadToolkit() START for name =", name) - plug := initPlugin(name) - if plug == nil { - return n, errors.New("initPlugin(" + name + ") failed") - } - plug.dead = false - - log.Log(PLUG, "LoadToolkit() sending Toolkit Init action to the plugin channel") - var a widget.Action - a.ActionType = widget.ToolkitInit - plug.pluginChan <- a - // sleep(.5) // temp hack until chan communication is setup - - // TODO: find a new way to do this that is locking, safe and accurate - me.rootNode.redraw(plug) - log.Log(PLUG, "LoadToolkit() END for name =", name) - return n, nil -} - func (n *Node) CloseToolkit(name string) bool { log.Log(PLUG, "CloseToolkit() for name =", name) for i, plug := range allPlugins { diff --git a/structs.go b/structs.go index 9c5789e..09fbf1f 100644 --- a/structs.go +++ b/structs.go @@ -56,9 +56,8 @@ type guiConfig struct { // option to pass in compiled plugins as embedded files resFS embed.FS - // used to beautify logging to Stdout - // depth int - // prefix string + // what the application would like the default GUI plugin to be + appPlugin string } /* -- cgit v1.2.3