From a235371d1a98a10a7d7e585bd145e8f357fcd842 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 11 Apr 2023 21:37:36 -0500 Subject: [PATCH] both gocui and andlabs worked with buttondemo Signed-off-by: Jeff Carr --- README-goreadme.md | 6 +-- main.go | 112 ++-------------------------------------- toolkit/andlabs/main.go | 8 +-- watchdog.go | 6 +++ 4 files changed, 16 insertions(+), 116 deletions(-) diff --git a/README-goreadme.md b/README-goreadme.md index a734836..fe9ce18 100644 --- a/README-goreadme.md +++ b/README-goreadme.md @@ -127,7 +127,7 @@ Creates a window helpful for debugging this package `func Indent(b bool, a ...interface{})` -### func [LoadPlugin](/main.go#L172) +### func [LoadPlugin](/main.go#L114) `func LoadPlugin(name string) bool` @@ -149,7 +149,7 @@ loads and initializes a toolkit (andlabs/ui, gocui, etc) `func ShowDebugValues()` -### func [StandardExit](/main.go#L261) +### func [StandardExit](/main.go#L155) `func StandardExit()` @@ -190,7 +190,7 @@ var Config GuiConfig The Node is a binary tree. This is how all GUI elements are stored simply the name and the size of whatever GUI element exists -#### func [New](/main.go#L190) +#### func [New](/main.go#L132) `func New() *Node` diff --git a/main.go b/main.go index 3e4117b..9776401 100644 --- a/main.go +++ b/main.go @@ -44,64 +44,6 @@ func init() { go watchCallback() } -/* -func doGuiChan() { - for { - select { - case <-Config.ActionCh1: - log(true, "CHANNEL ACTION 1 !!!!!") - return - case <-Config.ActionCh2: - log(true, "CHANNEL ACTION 2 !!!!!") - return - default: - log(true, "doGuiChan() nothing") - } - log(true, "doGuiChan() for()") - } -} -*/ - -/* -// TODO: add logic to just load the 1st 'most common' gui toolkit -// and allow the 'go-arg' command line args to override the defaults -func InitPlugins(names []string) []string { - log(debugGui, "Starting gui.Init()") - - for _, aplug := range allPlugins { - log(debugGui, "LoadToolkit() already loaded toolkit plugin =", aplug.name) - for _, name := range names { - if (name == aplug.name) { - return []string{name} - } - } - } - - // try to load each plugin in the order passed to this function - for _, name := range names { - aPlug := LoadToolkit(name) - if (aPlug != nil) { - // exit because it worked! - return []string{name} - } - } - - // 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 - andlabsPlug := LoadToolkit("andlabs") - if (andlabsPlug != nil) { - return []string{} - } - - gocuiPlug := LoadToolkit("andlabs") - if (gocuiPlug != nil) { - return []string{} - } - return []string{} -} -*/ - func watchCallback() { log(logInfo, "watchCallback() START") for { @@ -196,60 +138,12 @@ func New() *Node { if (os.Getenv("DISPLAY") == "") { return Config.rootNode } -// if (LoadPlugin("andlabs")) { -// log(logError, "New() failed to load andlabs") -// } + if (LoadPlugin("andlabs")) { + log(logError, "New() failed to load andlabs") + } return Config.rootNode } -/* -// This should not pass a function -func Main(f func()) { - log(debugGui, "Starting gui.Main() (using gtk via andlabs/ui)") - - // TODO: this is linux only - // TODO: detect if this was run from the command line (parent == bash?) - // if DISPLAY is not set, don't even bother with loading andlabs - if (os.Getenv("DISPLAY") == "") { - InitPlugins([]string{"gocui"}) - } else { - // InitPlugins([]string{"andlabs", "gocui"}) - InitPlugins([]string{"gocui", "andlabs"}) - } - - for _, aplug := range allPlugins { - log(debugGui, "NewButton() toolkit plugin =", aplug.name) - if (aplug.MainOk) { - log(debugGui, "Main() Already Ran Main()", aplug.name) - continue - } - if (aplug.Main == nil) { - log(debugGui, "Main() Main == nil", aplug.name) - continue - } - aplug.MainOk = true - if (aplug.Callback == nil) { - // TODO: don't load the module if this failed ? - // if Callback() isn't set in the plugin, no information can be sent to it! - log(debugError, "SERIOUS ERROR: plugin Callback() == nil. nothing will work for toolkit", aplug.name) - } else { - aplug.Callback(Config.guiChan) - } - - if (aplug.PluginChannel == nil) { - // TODO: don't load the module if this failed ? - // if Callback() isn't set in the plugin, no information can be sent to it! - log(debugError, "ERROR: plugin does not implement a send channel. toolkit =", aplug.name) - } else { - aplug.pluginChan = aplug.PluginChannel() - } - - aplug.Main(f) - } - -} -*/ - // The window is destroyed but the application does not quit func (n *Node) StandardClose() { log(debugGui, "wit/gui Standard Window Close. name =", n.Name) diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go index 37df0be..e6befd2 100644 --- a/toolkit/andlabs/main.go +++ b/toolkit/andlabs/main.go @@ -34,10 +34,10 @@ func catchActionChannel() { log(logError,"catchActionChannel() ui.Main() START") log(logError,"catchActionChannel() ui.Main() START") sleep(1) - // ui.Main(demoUI) - ui.Main( func() { - rawAction(a) - }) + go ui.Main(demoUI) + // go ui.Main( func() { + // rawAction(a) + // }) // probably not needed, but in here for now under development uiMainUndef = false sleep(1) diff --git a/watchdog.go b/watchdog.go index 61c0247..af59439 100644 --- a/watchdog.go +++ b/watchdog.go @@ -23,6 +23,12 @@ func Watchdog() { Config.rootNode.ListChildren(true) } } + if (i == 2) { + LoadPlugin("gocui") + } +// if (i == 3) { +// LoadPlugin("andlabs") +// } i += 1 time.Sleep(watchtime * time.Second / 10) }