andlabs is broken
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
11d3f20c4a
commit
56f8246bca
6
main.go
6
main.go
|
@ -196,9 +196,9 @@ func New() *Node {
|
||||||
if (os.Getenv("DISPLAY") == "") {
|
if (os.Getenv("DISPLAY") == "") {
|
||||||
return Config.rootNode
|
return Config.rootNode
|
||||||
}
|
}
|
||||||
if (LoadPlugin("andlabs")) {
|
// if (LoadPlugin("andlabs")) {
|
||||||
log(logError, "New() failed to load andlabs")
|
// log(logError, "New() failed to load andlabs")
|
||||||
}
|
// }
|
||||||
return Config.rootNode
|
return Config.rootNode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,47 +15,47 @@ 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
|
var uiMainUndef bool = true
|
||||||
|
|
||||||
func catchActionChannel() {
|
func catchActionChannel() {
|
||||||
log(logNow, "makeCallback() START")
|
log(logNow, "catchActionChannel() START")
|
||||||
for {
|
for {
|
||||||
log(logNow, "makeCallback() for loop")
|
log(logNow, "catchActionChannel() for loop")
|
||||||
select {
|
select {
|
||||||
case a := <-pluginChan:
|
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)
|
// go Action(a)
|
||||||
if (a.WidgetType == toolkit.Window) {
|
if (uiMainUndef) {
|
||||||
log(logNow, "makeCallback() WINDOW START")
|
log(logError,"catchActionChannel() main() was not run yet")
|
||||||
// this is a hack for now
|
log(logError,"catchActionChannel() main() was not run yet")
|
||||||
// if uiMain == true, ui.Main() has already started
|
log(logError,"catchActionChannel() main() was not run yet")
|
||||||
if (uiMain) {
|
log(logError,"catchActionChannel() ui.Main() START")
|
||||||
log(logNow, "WINDOW START newWindow(&a)")
|
log(logError,"catchActionChannel() ui.Main() START")
|
||||||
newWindow(a)
|
log(logError,"catchActionChannel() ui.Main() START")
|
||||||
} else {
|
log(logError,"catchActionChannel() ui.Main() START")
|
||||||
go ui.Main( func() {
|
sleep(1)
|
||||||
log(logNow, "ui.Main() WINDOW START DOING NOTHING")
|
// ui.Main(demoUI)
|
||||||
newWindow(a)
|
ui.Main( func() {
|
||||||
log(logNow, "ui.Main() WINDOW END")
|
rawAction(a)
|
||||||
})
|
})
|
||||||
uiMain = true
|
// probably not needed, but in here for now under development
|
||||||
}
|
uiMainUndef = false
|
||||||
sleep(.5)
|
sleep(1)
|
||||||
log(logNow, "makeCallback() WINDOW END")
|
|
||||||
} else {
|
} else {
|
||||||
log(logNow, "makeCallback() STUFF")
|
log(logNow, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
|
||||||
rawAction(a)
|
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)")
|
log(debugNow, "Main() START (using gtk via andlabs/ui)")
|
||||||
f() // support the old way. deprecate this
|
f() // support the old way. deprecate this
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// this sets the channel to send user events back from the plugin
|
// this sets the channel to send user events back from the plugin
|
||||||
func Callback(guiCallback chan toolkit.Action) {
|
func Callback(guiCallback chan toolkit.Action) {
|
||||||
|
@ -75,7 +75,7 @@ func PluginChannel() chan toolkit.Action {
|
||||||
//
|
//
|
||||||
// For example: Queue(NewWindow())
|
// For example: Queue(NewWindow())
|
||||||
//
|
//
|
||||||
func Queue(f func()) {
|
func queue(f func()) {
|
||||||
log(logNow, "Sending function to ui.QueueMain()")
|
log(logNow, "Sending function to ui.QueueMain()")
|
||||||
log(logNow, "using gui.Queue() in this plugin DOES BREAK. TODO: solve this with channels")
|
log(logNow, "using gui.Queue() in this plugin DOES BREAK. TODO: solve this with channels")
|
||||||
ui.QueueMain(f)
|
ui.QueueMain(f)
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
*/
|
|
@ -33,6 +33,10 @@ func Init() {
|
||||||
|
|
||||||
log(logNow, "Init() start pluginChan")
|
log(logNow, "Init() start pluginChan")
|
||||||
go catchActionChannel()
|
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
|
// 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")
|
log(logInfo, "catchActionChannel() infinite for() loop restarted select on channel")
|
||||||
select {
|
select {
|
||||||
case a := <-me.pluginChan:
|
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) {
|
if (me.baseGui == nil) {
|
||||||
log(logError,"main() was not run yet")
|
// something went wrong initializing the gocui
|
||||||
go main()
|
log(logError,"ERROR: console did not initialize")
|
||||||
// probably not needed, but in here for now under development
|
continue
|
||||||
sleep(1)
|
|
||||||
}
|
}
|
||||||
log(logNow, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
|
log(logNow, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
|
||||||
action(&a)
|
action(&a)
|
||||||
|
|
Loading…
Reference in New Issue