diff --git a/README-goreadme.md b/README-goreadme.md index c6e0d00..7ea9fc6 100644 --- a/README-goreadme.md +++ b/README-goreadme.md @@ -162,7 +162,7 @@ This should not pass a function `func ShowDebugValues()` -### func [StandardExit](/main.go#L273) +### func [StandardExit](/main.go#L250) `func StandardExit()` diff --git a/main.go b/main.go index db9664d..135486e 100644 --- a/main.go +++ b/main.go @@ -203,7 +203,8 @@ func Main(f func()) { if (os.Getenv("DISPLAY") == "") { InitPlugins([]string{"gocui"}) } else { - InitPlugins([]string{"gocui", "andlabs"}) + InitPlugins([]string{"andlabs", "gocui"}) + // InitPlugins([]string{"gocui", "andlabs"}) } for _, aplug := range allPlugins { @@ -238,30 +239,6 @@ func Main(f func()) { } -/* -This is deprecated and will be implemented more correctly with waitgroups - -// 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()) { - log(debugGui, "Sending function to gui.Main() (using gtk via andlabs/ui)") - // toolkit.Queue(f) - for _, aplug := range allPlugins { - log(debugGui, "NewButton() toolkit plugin =", aplug.name) - if (aplug.Queue == nil) { - continue - } - aplug.Queue(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/plugin.go b/plugin.go index caabd9e..467fce7 100644 --- a/plugin.go +++ b/plugin.go @@ -336,14 +336,17 @@ func newaction(a *toolkit.Action, n *Node, where *Node) { continue } if (aplug.pluginChan == nil) { - log(debugNow, "Action() SEND old way") - log(debugNow, "Action() SEND old way") - log(debugNow, "Action() SEND old way") + log(debugNow, "Action() SEND old way", aplug.name) + log(debugNow, "Action() SEND old way", aplug.name) + log(debugNow, "Action() SEND old way", aplug.name) aplug.Action(a) + log(debugNow, "Action() SEND trying aplug.PluginChannel()", aplug.name) + aplug.pluginChan = aplug.PluginChannel() + log(debugNow, "Action() SEND trying aplug.PluginChannel()", aplug.pluginChan) } else { - log(debugNow, "Action() SEND pluginChan") - log(debugNow, "Action() SEND pluginChan") - log(debugNow, "Action() SEND pluginChan") + log(debugNow, "Action() SEND pluginChan", aplug.name) + log(debugNow, "Action() SEND pluginChan", aplug.name) + log(debugNow, "Action() SEND pluginChan", aplug.name) aplug.pluginChan <- *a } } diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go index 19a8aaa..a8c8b39 100644 --- a/toolkit/andlabs/main.go +++ b/toolkit/andlabs/main.go @@ -11,6 +11,8 @@ import ( //go:embed resources var res embed.FS + +// this is the channel we get requests to make widgets var pluginChan chan toolkit.Action func catchActionChannel() { diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go index b115786..2365f6f 100644 --- a/toolkit/gocui/main.go +++ b/toolkit/gocui/main.go @@ -33,6 +33,23 @@ func Callback(guiCallback chan toolkit.Action) { me.callback = guiCallback } +func PluginChannel() chan toolkit.Action { + return me.pluginChan +} + +func catchActionChannel() { + log(logNow, "makeCallback() START") + for { + log(logNow, "makeCallback() for loop") + select { + case a := <-me.pluginChan: + log(logNow, "makeCallback() SELECT widget id =", a.WidgetId, a.Name) + Action(&a) + sleep(.1) + } + } +} + func Exit() { // TODO: send exit to the plugin me.baseGui.Close() @@ -50,6 +67,10 @@ func Main(f func()) { setOutput(outf) log("This is a test log entry") + if (me.pluginChan == nil) { + me.pluginChan = make(chan toolkit.Action) + } + go catchActionChannel() MouseMain() me.baseGui.Close() } diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go index 8170416..e8e8172 100644 --- a/toolkit/gocui/structs.go +++ b/toolkit/gocui/structs.go @@ -23,7 +23,13 @@ type config struct { rootNode *cuiWidget // the base of the binary tree. it should have id == 0 ctrlDown *cuiWidget // shown if you click the mouse when the ctrl key is pressed + // this is the channel we send user events like + // mouse clicks or keyboard events back to the program callback chan toolkit.Action + + // this is the channel we get requests to make widgets + pluginChan chan toolkit.Action + helpLabel *gocui.View defaultBehavior bool