both andlabs & gocui plugins have working channels
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
de249412fb
commit
b9b5f1afd6
|
@ -162,7 +162,7 @@ This should not pass a function
|
|||
|
||||
`func ShowDebugValues()`
|
||||
|
||||
### func [StandardExit](/main.go#L273)
|
||||
### func [StandardExit](/main.go#L250)
|
||||
|
||||
`func StandardExit()`
|
||||
|
||||
|
|
27
main.go
27
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)
|
||||
|
|
15
plugin.go
15
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue