andlabs: my logic for new window is still wrong

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-08 11:43:58 -05:00
parent 85c2fb8d70
commit e34ec5efbf
6 changed files with 32 additions and 57 deletions

View File

@ -203,8 +203,8 @@ func Main(f func()) {
if (os.Getenv("DISPLAY") == "") { if (os.Getenv("DISPLAY") == "") {
InitPlugins([]string{"gocui"}) InitPlugins([]string{"gocui"})
} else { } else {
//InitPlugins([]string{"andlabs", "gocui"}) InitPlugins([]string{"andlabs", "gocui"})
InitPlugins([]string{"gocui", "andlabs"}) // InitPlugins([]string{"gocui", "andlabs"})
} }
for _, aplug := range allPlugins { for _, aplug := range allPlugins {

View File

@ -59,7 +59,7 @@ type aplug struct {
// simplifies passing to the plugin // simplifies passing to the plugin
// Send func(*toolkit.Widget, *toolkit.Widget) // Send func(*toolkit.Widget, *toolkit.Widget)
// should replace Send() // should replace Send()
Action func(*toolkit.Action) // Action func(*toolkit.Action)
} }
var allPlugins []*aplug var allPlugins []*aplug
@ -104,7 +104,7 @@ func LoadToolkit(name string) *aplug {
// Sends instructions like "Add", "Delete", "Disable", etc // Sends instructions like "Add", "Delete", "Disable", etc
// Sends a widget (button, checkbox, etc) and it's parent widget // Sends a widget (button, checkbox, etc) and it's parent widget
newPlug.Action = loadFuncA(newPlug, "Action") // newPlug.Action = loadFuncA(newPlug, "Action")
// this tells the toolkit plugin how to send user events back to us // this tells the toolkit plugin how to send user events back to us
// for things like: the user clicked on the 'Check IPv6' // for things like: the user clicked on the 'Check IPv6'
@ -332,24 +332,15 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
for _, aplug := range allPlugins { for _, aplug := range allPlugins {
log(debugPlugin, "Action() aplug =", aplug.name, "Action type=", a.ActionType) log(debugPlugin, "Action() aplug =", aplug.name, "Action type=", a.ActionType)
if (aplug.pluginChan == nil) { if (aplug.pluginChan == nil) {
log(debugNow, "Action() SEND old way", aplug.name) log(debugNow, "Action() retrieving the aplug.PluginChannel()", aplug.name)
log(debugNow, "Action() SEND old way", aplug.name)
log(debugNow, "Action() SEND old way", aplug.name)
if (aplug.Action == nil) {
log(debugPlugin, "Failed Action() == nil for", aplug.name)
continue
}
aplug.Action(a)
log(debugNow, "Action() SEND trying aplug.PluginChannel()", aplug.name)
aplug.pluginChan = aplug.PluginChannel() aplug.pluginChan = aplug.PluginChannel()
log(debugNow, "Action() SEND trying aplug.PluginChannel()", aplug.pluginChan) log(debugNow, "Action() retrieved", aplug.pluginChan)
} else {
log(debugNow, "Action() SEND pluginChan", aplug.name)
log(debugNow, "Action() SEND pluginChan", aplug.name)
log(debugNow, "Action() SEND pluginChan", aplug.name)
aplug.pluginChan <- *a
} }
sleep(.5) log(debugNow, "Action() SEND pluginChan", aplug.name)
log(debugNow, "Action() SEND pluginChan", aplug.name)
log(debugNow, "Action() SEND pluginChan", aplug.name)
aplug.pluginChan <- *a
sleep(.2)
} }
// increment where to put the next widget in a grid or table // increment where to put the next widget in a grid or table
if (where != nil) { if (where != nil) {

View File

@ -76,12 +76,7 @@ func (n *Node) redo(plug *aplug) {
// plug.Action(a) // plug.Action(a)
if (plug.pluginChan == nil) { if (plug.pluginChan == nil) {
log(debugNow, "Action() SEND old way", plug.name) log(debugNow, "Action() ERRRRRRROR pluginChan == nil", plug.name)
log(debugNow, "Action() SEND old way", plug.name)
log(debugNow, "Action() SEND old way", plug.name)
plug.Action(a)
log(debugNow, "Action() SEND trying plug.PluginChannel()", plug.name)
log(debugNow, "Action() SEND trying plug.PluginChannel()", plug.pluginChan)
} else { } else {
log(debugNow, "Action() SEND pluginChan", plug.name) log(debugNow, "Action() SEND pluginChan", plug.name)
log(debugNow, "Action() SEND pluginChan", plug.name) log(debugNow, "Action() SEND pluginChan", plug.name)

View File

@ -29,7 +29,7 @@ func add(a *toolkit.Action) {
// for now, window gets handled without checking where == nil) // for now, window gets handled without checking where == nil)
if (a.WidgetType == toolkit.Window) { if (a.WidgetType == toolkit.Window) {
doWindow(a) newWindow(*a)
return return
} }
@ -44,7 +44,7 @@ func add(a *toolkit.Action) {
switch a.WidgetType { switch a.WidgetType {
case toolkit.Window: case toolkit.Window:
doWindow(a) newWindow(*a)
return return
case toolkit.Tab: case toolkit.Tab:
log(debugError, "add() CAME AT THIS FROM add() =", a.Name) log(debugError, "add() CAME AT THIS FROM add() =", a.Name)

View File

@ -15,6 +15,8 @@ var res embed.FS
// this is the channel we get requests to make widgets // this is the channel we get requests to make widgets
var pluginChan chan toolkit.Action var pluginChan chan toolkit.Action
var uiMain bool = false
func catchActionChannel() { func catchActionChannel() {
log(logNow, "makeCallback() START") log(logNow, "makeCallback() START")
for { for {
@ -25,11 +27,19 @@ func catchActionChannel() {
// go Action(a) // go Action(a)
if (a.WidgetType == toolkit.Window) { if (a.WidgetType == toolkit.Window) {
log(logNow, "makeCallback() WINDOW START") log(logNow, "makeCallback() WINDOW START")
go ui.Main( func() { // this is a hack for now
log(logNow, "ui.Main() WINDOW START DOING NOTHING") // if uiMain == true, ui.Main() has already started
newWindow(&a) if (uiMain) {
log(logNow, "ui.Main() WINDOW END") log(logNow, "WINDOW START newWindow(&a)")
}) newWindow(a)
} else {
go ui.Main( func() {
log(logNow, "ui.Main() WINDOW START DOING NOTHING")
newWindow(a)
log(logNow, "ui.Main() WINDOW END")
})
uiMain = true
}
sleep(.5) sleep(.5)
log(logNow, "makeCallback() WINDOW END") log(logNow, "makeCallback() WINDOW END")
} else { } else {
@ -43,7 +53,7 @@ func catchActionChannel() {
} }
func Main(f func()) { func Main(f func()) {
log(debugNow, "gui.Main() START (using gtk via andlabs/ui)") log(debugNow, "Main() START (using gtk via andlabs/ui)")
f() // support the old way. deprecate this f() // support the old way. deprecate this
} }
@ -79,28 +89,11 @@ func Init() {
// log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true") // log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
setDefaultBehavior(true) setDefaultBehavior(true)
// mapWidgets = make(map[*andlabsT]*toolkit.Widget)
// mapToolkits = make(map[*toolkit.Widget]*andlabsT)
andlabs = make(map[int]*andlabsT) andlabs = make(map[int]*andlabsT)
pluginChan = make(chan toolkit.Action) pluginChan = make(chan toolkit.Action)
log(logNow, "Init() ui.Main() start") log(logNow, "Init() start channel reciever")
go catchActionChannel() 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") log(logNow, "Init() END")
} }

View File

@ -15,7 +15,7 @@ func (t *andlabsT) ErrorWindow(msg1 string, msg2 string) {
ui.MsgBoxError(t.uiWindow, msg1, msg2) ui.MsgBoxError(t.uiWindow, msg1, msg2)
} }
func newWindow(a *toolkit.Action) { func newWindow(a toolkit.Action) {
var newt *andlabsT var newt *andlabsT
newt = new(andlabsT) newt = new(andlabsT)
@ -49,7 +49,3 @@ func (t *andlabsT) SetWindowTitle(title string) {
log(debugToolkit, "Setting the window title", title) log(debugToolkit, "Setting the window title", title)
} }
} }
func doWindow(a *toolkit.Action) {
newWindow(a)
}