summaryrefslogtreecommitdiff
path: root/toolkit/andlabs/main.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-07 18:16:16 -0500
committerJeff Carr <[email protected]>2023-04-07 18:16:16 -0500
commit0a520c8ebc38640098e8d2c21711162b1697d38d (patch)
tree75ce11e40429502d36cadda6afcb11c213a7f7ba /toolkit/andlabs/main.go
parent820067cbff754cf9a5f96c425d8f31b5949d353c (diff)
andlabs kinda works with a channel
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/andlabs/main.go')
-rw-r--r--toolkit/andlabs/main.go66
1 files changed, 57 insertions, 9 deletions
diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go
index 9ca71ca..137af04 100644
--- a/toolkit/andlabs/main.go
+++ b/toolkit/andlabs/main.go
@@ -11,15 +11,43 @@ import (
//go:embed resources
var res embed.FS
+var pluginChan chan toolkit.Action
+
+func catchActionChannel() {
+ log(logNow, "makeCallback() START")
+ for {
+ log(logNow, "makeCallback() for loop")
+ select {
+ case a := <-pluginChan:
+ log(logNow, "makeCallback() SELECT widget id =", a.WidgetId, a.Name)
+ // go Action(a)
+ if (a.WidgetType == toolkit.Window) {
+ log(logNow, "makeCallback() WINDOW START")
+ go ui.Main( func() {
+ log(logNow, "ui.Main() WINDOW START")
+ rawAction(&a)
+ log(logNow, "ui.Main() WINDOW END")
+ })
+ sleep(.5)
+ log(logNow, "makeCallback() WINDOW END")
+ } else {
+ log(logNow, "makeCallback() STUFF")
+ rawAction(&a)
+ /*
+ Queue( func() {
+ rawAction(&a)
+ })
+ */
+ log(logNow, "makeCallback() STUFF END")
+ }
+ sleep(.1)
+ }
+ }
+}
func Main(f func()) {
- log(debugToolkit, "Starting gui.Main() (using gtk via andlabs/ui)")
- ui.Main( func() {
- log(debugToolkit, "Starting gui.Main() (using gtk via andlabs/ui)")
- // time.Sleep(1 * time.Second)
- // NewWindow2("helloworld2", 200, 100)
- f()
- })
+ log(debugNow, "gui.Main() START (using gtk via andlabs/ui)")
+ f() // support the old way. deprecate this
}
// this sets the channel to send user events back from the plugin
@@ -36,13 +64,14 @@ func Callback(guiCallback chan toolkit.Action) {
// For example: Queue(NewWindow())
//
func Queue(f func()) {
- log(debugToolkit, "Sending function to ui.QueueMain()")
- log(debugPlugin, "using gui.Queue() in this plugin DOES BREAK. TODO: solve this with channels")
+ log(logNow, "Sending function to ui.QueueMain()")
+ log(logNow, "using gui.Queue() in this plugin DOES BREAK. TODO: solve this with channels")
ui.QueueMain(f)
}
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func Init() {
+ log(logNow, "Init() START")
log(debugToolkit, "Init()")
// Can you pass values to a plugin init() ? Otherwise, there is no way to safely print
// log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
@@ -52,6 +81,25 @@ func Init() {
// mapToolkits = make(map[*toolkit.Widget]*andlabsT)
andlabs = make(map[int]*andlabsT)
+ pluginChan = make(chan toolkit.Action)
+
+ log(logNow, "Init() ui.Main() start")
+ go catchActionChannel()
+ /*
+ ui.Main( func() {
+ log(logNow, "gui.Main() IN (using gtk via andlabs/ui)")
+ var a toolkit.Action
+ a.Name = "jcarr"
+ a.Width = 640
+ a.Height = 480
+ a.WidgetId = 0
+ newWindow(&a)
+ // time.Sleep(1 * time.Second)
+ // NewWindow2("helloworld2", 200, 100)
+ log(logNow, "gui.Main() EXIT (using gtk via andlabs/ui)")
+ })
+ */
+ log(logNow, "Init() END")
}
// TODO: properly exit the plugin since Quit() doesn't do it