both andlabs & gocui plugins have working channels

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-08 00:28:33 -05:00
parent de249412fb
commit b9b5f1afd6
6 changed files with 41 additions and 32 deletions

View File

@ -162,7 +162,7 @@ This should not pass a function
`func ShowDebugValues()` `func ShowDebugValues()`
### func [StandardExit](/main.go#L273) ### func [StandardExit](/main.go#L250)
`func StandardExit()` `func StandardExit()`

27
main.go
View File

@ -203,7 +203,8 @@ func Main(f func()) {
if (os.Getenv("DISPLAY") == "") { if (os.Getenv("DISPLAY") == "") {
InitPlugins([]string{"gocui"}) InitPlugins([]string{"gocui"})
} else { } else {
InitPlugins([]string{"gocui", "andlabs"}) InitPlugins([]string{"andlabs", "gocui"})
// InitPlugins([]string{"gocui", "andlabs"})
} }
for _, aplug := range allPlugins { 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 // The window is destroyed but the application does not quit
func (n *Node) StandardClose() { func (n *Node) StandardClose() {
log(debugGui, "wit/gui Standard Window Close. name =", n.Name) log(debugGui, "wit/gui Standard Window Close. name =", n.Name)

View File

@ -336,14 +336,17 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
continue continue
} }
if (aplug.pluginChan == nil) { if (aplug.pluginChan == nil) {
log(debugNow, "Action() SEND old way") log(debugNow, "Action() SEND old way", aplug.name)
log(debugNow, "Action() SEND old way") log(debugNow, "Action() SEND old way", aplug.name)
log(debugNow, "Action() SEND old way") log(debugNow, "Action() SEND old way", aplug.name)
aplug.Action(a) 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 { } else {
log(debugNow, "Action() SEND pluginChan") log(debugNow, "Action() SEND pluginChan", aplug.name)
log(debugNow, "Action() SEND pluginChan") log(debugNow, "Action() SEND pluginChan", aplug.name)
log(debugNow, "Action() SEND pluginChan") log(debugNow, "Action() SEND pluginChan", aplug.name)
aplug.pluginChan <- *a aplug.pluginChan <- *a
} }
} }

View File

@ -11,6 +11,8 @@ import (
//go:embed resources //go:embed resources
var res embed.FS var res embed.FS
// this is the channel we get requests to make widgets
var pluginChan chan toolkit.Action var pluginChan chan toolkit.Action
func catchActionChannel() { func catchActionChannel() {

View File

@ -33,6 +33,23 @@ func Callback(guiCallback chan toolkit.Action) {
me.callback = guiCallback 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() { func Exit() {
// TODO: send exit to the plugin // TODO: send exit to the plugin
me.baseGui.Close() me.baseGui.Close()
@ -50,6 +67,10 @@ func Main(f func()) {
setOutput(outf) setOutput(outf)
log("This is a test log entry") log("This is a test log entry")
if (me.pluginChan == nil) {
me.pluginChan = make(chan toolkit.Action)
}
go catchActionChannel()
MouseMain() MouseMain()
me.baseGui.Close() me.baseGui.Close()
} }

View File

@ -23,7 +23,13 @@ type config struct {
rootNode *cuiWidget // the base of the binary tree. it should have id == 0 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 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 callback chan toolkit.Action
// this is the channel we get requests to make widgets
pluginChan chan toolkit.Action
helpLabel *gocui.View helpLabel *gocui.View
defaultBehavior bool defaultBehavior bool