andlabs kinda works with a channel
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
8f6e971948
commit
60a4a1bfd6
|
@ -37,7 +37,7 @@ func (n *Node) Redraw(p *aplug) {
|
|||
}
|
||||
|
||||
func (n *Node) redo(p *aplug) {
|
||||
log(logNow, "redo()", n.id, n.WidgetType, n.Name)
|
||||
log(logNow, "redo()", p.name, n.id, n.WidgetType, n.Name)
|
||||
|
||||
var a *toolkit.Action
|
||||
a = new(toolkit.Action)
|
||||
|
|
|
@ -11,12 +11,12 @@ var stretchy bool // expand things like buttons to the maximum size
|
|||
var padded bool // add space between things like buttons
|
||||
var margin bool // add space around the frames of windows
|
||||
|
||||
var debugToolkit bool
|
||||
var debugChange bool
|
||||
var debugPlugin bool
|
||||
var debugAction bool
|
||||
var debugFlags bool
|
||||
var debugGrid bool
|
||||
var debugToolkit bool = true
|
||||
var debugChange bool = true
|
||||
var debugPlugin bool = true
|
||||
var debugAction bool = true
|
||||
var debugFlags bool = true
|
||||
var debugGrid bool = true
|
||||
var debugNow bool = true
|
||||
var debugError bool = true
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ import (
|
|||
// various debugging flags
|
||||
var logNow bool = true // useful for active development
|
||||
var logError bool = true
|
||||
var logWarn bool = false
|
||||
var logInfo bool = false
|
||||
var logVerbose bool = false
|
||||
var logWarn bool = true
|
||||
var logInfo bool = true
|
||||
var logVerbose bool = true
|
||||
|
||||
func log(a ...any) {
|
||||
witlog.Where = "wit/gui/andlabs"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,24 +23,28 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) {
|
|||
}
|
||||
|
||||
func Action(a *toolkit.Action) {
|
||||
log(logNow, "Action() START")
|
||||
if (a == nil) {
|
||||
log(debugPlugin, "Action = nil")
|
||||
return
|
||||
}
|
||||
pluginChan <- *a
|
||||
/*
|
||||
f := func() {
|
||||
rawAction(a)
|
||||
}
|
||||
|
||||
// f()
|
||||
Queue(f)
|
||||
*/
|
||||
log(logNow, "Action() END")
|
||||
}
|
||||
|
||||
func rawAction(a *toolkit.Action) {
|
||||
log(debugAction, "rawAction() START a.ActionType =", a.ActionType)
|
||||
log(debugAction, "rawAction() START a.S =", a.S)
|
||||
|
||||
log(debugAction, "Action() START a.ActionType =", a.ActionType)
|
||||
log(debugAction, "Action() START a.S =", a.S)
|
||||
|
||||
log(logInfo, "Action() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
|
||||
log(logNow, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
|
||||
switch a.WidgetType {
|
||||
case toolkit.Flag:
|
||||
flag(a)
|
||||
|
@ -87,12 +91,12 @@ func rawAction(a *toolkit.Action) {
|
|||
case toolkit.Delete:
|
||||
uiDelete(a)
|
||||
case toolkit.Move:
|
||||
log(debugNow, "attempt to move() =", a.ActionType, a.WidgetType)
|
||||
log(debugNow, "rawAction() attempt to move() =", a.ActionType, a.WidgetType)
|
||||
move(a)
|
||||
default:
|
||||
log(debugError, "Action() Unknown =", a.ActionType, a.WidgetType)
|
||||
log(debugError, "rawAction() Unknown =", a.ActionType, a.WidgetType)
|
||||
}
|
||||
log(debugAction, "Action() END =", a.ActionType, a.WidgetType)
|
||||
log(debugAction, "rawAction() END =", a.ActionType, a.WidgetType)
|
||||
}
|
||||
|
||||
func flag(a *toolkit.Action) {
|
||||
|
|
|
@ -54,6 +54,10 @@ func (w *cuiWidget) drawView() {
|
|||
}
|
||||
}
|
||||
|
||||
if (me.baseGui == nil) {
|
||||
log(logError, "drawView() ERROR: me.baseGui == nil", w)
|
||||
return
|
||||
}
|
||||
v, _ := me.baseGui.View(w.cuiName)
|
||||
if (v != nil) {
|
||||
log(logError, "drawView() already defined for name", w.cuiName)
|
||||
|
|
28
watchdog.go
28
watchdog.go
|
@ -27,3 +27,31 @@ func Watchdog() {
|
|||
time.Sleep(watchtime * time.Second / 10)
|
||||
}
|
||||
}
|
||||
// https://www.reddit.com/r/golang/comments/12em87q/how_to_run_periodic_tasks/
|
||||
/*
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
done <- true
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
fmt.Println("Done!")
|
||||
return
|
||||
case t := <-ticker.C:
|
||||
fmt.Println("Current time: ", t)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue