andlabs is broken

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-11 15:25:03 -05:00
parent 11d3f20c4a
commit 56f8246bca
4 changed files with 132 additions and 36 deletions

View File

@ -196,9 +196,9 @@ func New() *Node {
if (os.Getenv("DISPLAY") == "") {
return Config.rootNode
}
if (LoadPlugin("andlabs")) {
log(logError, "New() failed to load andlabs")
}
// if (LoadPlugin("andlabs")) {
// log(logError, "New() failed to load andlabs")
// }
return Config.rootNode
}

View File

@ -15,47 +15,47 @@ var res embed.FS
// this is the channel we get requests to make widgets
var pluginChan chan toolkit.Action
var uiMain bool = false
var uiMainUndef bool = true
func catchActionChannel() {
log(logNow, "makeCallback() START")
log(logNow, "catchActionChannel() START")
for {
log(logNow, "makeCallback() for loop")
log(logNow, "catchActionChannel() for loop")
select {
case a := <-pluginChan:
log(logNow, "makeCallback() SELECT widget id =", a.WidgetId, a.Name)
log(logNow, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
// go Action(a)
if (a.WidgetType == toolkit.Window) {
log(logNow, "makeCallback() WINDOW START")
// this is a hack for now
// if uiMain == true, ui.Main() has already started
if (uiMain) {
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)
log(logNow, "makeCallback() WINDOW END")
if (uiMainUndef) {
log(logError,"catchActionChannel() main() was not run yet")
log(logError,"catchActionChannel() main() was not run yet")
log(logError,"catchActionChannel() main() was not run yet")
log(logError,"catchActionChannel() ui.Main() START")
log(logError,"catchActionChannel() ui.Main() START")
log(logError,"catchActionChannel() ui.Main() START")
log(logError,"catchActionChannel() ui.Main() START")
sleep(1)
// ui.Main(demoUI)
ui.Main( func() {
rawAction(a)
})
// probably not needed, but in here for now under development
uiMainUndef = false
sleep(1)
} else {
log(logNow, "makeCallback() STUFF")
log(logNow, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
rawAction(a)
log(logNow, "makeCallback() STUFF END")
log(logNow, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
}
// sleep(.1)
}
}
}
func Main(f func()) {
/*
func main(f func()) {
log(debugNow, "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
func Callback(guiCallback chan toolkit.Action) {
@ -75,7 +75,7 @@ func PluginChannel() chan toolkit.Action {
//
// For example: Queue(NewWindow())
//
func Queue(f func()) {
func queue(f func()) {
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)

View File

@ -0,0 +1,96 @@
package main
import (
"github.com/andlabs/ui"
)
// Example showing how to update the UI using the QueueMain function
// especially if the update is coming from another goroutine
//
// see QueueMain in 'main.go' for detailed description
var count int
func demoUI() {
mainWindow := ui.NewWindow("libui Updating UI", 640, 480, true)
mainWindow.OnClosing(func(*ui.Window) bool {
ui.Quit()
return true
})
ui.OnShouldQuit(func() bool {
mainWindow.Destroy()
return true
})
vbContainer := ui.NewVerticalBox()
vbContainer.SetPadded(true)
inputGroup := ui.NewGroup("Input")
inputGroup.SetMargined(true)
vbInput := ui.NewVerticalBox()
vbInput.SetPadded(true)
inputForm := ui.NewForm()
inputForm.SetPadded(true)
message := ui.NewEntry()
message.SetText("Hello World")
inputForm.Append("What message do you want to show?", message, false)
showMessageButton := ui.NewButton("Show message")
clearMessageButton := ui.NewButton("Clear message")
vbInput.Append(inputForm, false)
vbInput.Append(showMessageButton, false)
vbInput.Append(clearMessageButton, false)
inputGroup.SetChild(vbInput)
messageGroup := ui.NewGroup("Message")
messageGroup.SetMargined(true)
vbMessage := ui.NewVerticalBox()
vbMessage.SetPadded(true)
messageLabel := ui.NewLabel("")
vbMessage.Append(messageLabel, false)
messageGroup.SetChild(vbMessage)
countGroup := ui.NewGroup("Counter")
countGroup.SetMargined(true)
vbCounter := ui.NewVerticalBox()
vbCounter.SetPadded(true)
countLabel := ui.NewLabel("blah")
vbCounter.Append(countLabel, false)
countGroup.SetChild(vbCounter)
vbContainer.Append(inputGroup, false)
vbContainer.Append(messageGroup, false)
vbContainer.Append(countGroup, false)
mainWindow.SetChild(vbContainer)
showMessageButton.OnClicked(func(*ui.Button) {
// Update the UI directly as it is called from the main thread
messageLabel.SetText(message.Text())
})
clearMessageButton.OnClicked(func(*ui.Button) {
// Update the UI directly as it is called from the main thread
messageLabel.SetText("")
})
mainWindow.Show()
}
/*
func main() {
ui.Main(setupUI)
}
*/

View File

@ -33,6 +33,10 @@ func Init() {
log(logNow, "Init() start pluginChan")
go catchActionChannel()
sleep(.1)
go main()
// probably not needed, but in here for now under development
sleep(.1)
}
// this sets the channel to send user events back from the plugin
@ -50,14 +54,10 @@ func catchActionChannel() {
log(logInfo, "catchActionChannel() infinite for() loop restarted select on channel")
select {
case a := <-me.pluginChan:
// this plugin can be loaded, but it doesn't actually do anything until
// the calling program sends an action to it. Then, it actually will initialize
// the tty and take over your console
if (me.baseGui == nil) {
log(logError,"main() was not run yet")
go main()
// probably not needed, but in here for now under development
sleep(1)
// something went wrong initializing the gocui
log(logError,"ERROR: console did not initialize")
continue
}
log(logNow, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
action(&a)