use the new tree functions

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-05 12:06:17 -06:00
parent fea47363e0
commit 1e98d2607b
6 changed files with 191 additions and 56 deletions

View File

@ -1,8 +1,7 @@
package main package main
import ( import (
"errors" "go.wit.com/dev/andlabs/ui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
@ -169,6 +168,7 @@ func widgetDelete(n *tree.Node) {
} }
} }
/*
func processAction(a *widget.Action) { func processAction(a *widget.Action) {
log.Log(ANDLABS, "processAction() START a.ActionType =", a.ActionType, "a.Value", a.Value) log.Log(ANDLABS, "processAction() START a.ActionType =", a.ActionType, "a.Value", a.Value)
@ -278,3 +278,78 @@ func processAction(a *widget.Action) {
} }
log.Log(INFO, "processAction() END =", a.ActionType, a.WidgetType) log.Log(INFO, "processAction() END =", a.ActionType, a.WidgetType)
} }
*/
func SetTitle(n *tree.Node, s string) {
SetText(n, s)
}
func SetLabel(n *tree.Node, s string) {
SetText(n, s)
}
func SetText(n *tree.Node, s string) {
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
}
if n.TK == nil {
log.Warn("Tree sent an action on a widget we didn't seem to have.")
return
}
setText(n, s)
log.Info("SetText() (new)", n.WidgetType, n.String(), s)
}
func AddText(n *tree.Node, s string) {
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
}
if n.TK == nil {
log.Warn("Tree sent an action on a widget we didn't seem to have.")
return
}
log.Info("AddText()", n.WidgetType, n.String())
// w := n.TK.(*guiWidget)
// w.AddText(s)
addText(n, s)
}
func newAction(n *tree.Node, atype widget.ActionType) {
log.Log(INFO, "newaction() START", atype)
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
}
if n.TK == nil {
log.Warn("Tree sent an action on a widget we didn't seem to have.")
// do this init here again? Probably something
// went wrong and we should reset the our while gocui.View tree
n.TK = initWidget(n)
}
// w := n.TK.(*guiWidget)
switch atype {
case widget.Show:
log.Log(NOW, "Show() HERE. a.Hidden() was =", n.Hidden())
show(n, true)
case widget.Hide:
log.Log(NOW, "Hide() HERE. a.State.Hidden was =", n.Hidden())
hide(n)
case widget.Move:
log.Log(NOW, "attempt to move() =", atype, n.WidgetType, n.ProgName())
case widget.ToolkitClose:
log.Log(NOW, "attempting to Quit andlabs.ui")
// standardClose()
ui.Quit()
case widget.Enable:
enable(n, true)
case widget.Disable:
enable(n, false)
case widget.Delete:
widgetDelete(n)
default:
log.Log(ERROR, "newaction() UNHANDLED Action Type =", atype, "WidgetType =", n.WidgetType, "Name =", n.ProgName())
}
log.Log(INFO, "newaction() END", atype, n.String())
}

49
add.go
View File

@ -6,16 +6,7 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
func add(a *widget.Action) *tree.Node { func add(n *tree.Node) {
log.Log(ANDLABS, "add()", a.WidgetId, a.WidgetType, a.State.ProgName)
if a.WidgetType == widget.Root {
if me.treeRoot == nil {
me.treeRoot = me.myTree.AddNode(a)
}
return me.treeRoot
}
n := me.myTree.AddNode(a)
p := n.Parent p := n.Parent
switch n.WidgetType { switch n.WidgetType {
case widget.Window: case widget.Window:
@ -32,27 +23,53 @@ func add(a *widget.Action) *tree.Node {
newButton(p, n) newButton(p, n)
case widget.Checkbox: case widget.Checkbox:
newCheckbox(p, n) newCheckbox(p, n)
setChecked(n, a.State.Checked) setChecked(n, n.State.Checked)
case widget.Spinner: case widget.Spinner:
newSpinner(p, n) newSpinner(p, n)
case widget.Slider: case widget.Slider:
newSlider(p, n) newSlider(p, n)
case widget.Dropdown: case widget.Dropdown:
newDropdown(p, n) newDropdown(p, n)
setText(n, a) setText(n, widget.GetString(n.State.Value))
case widget.Combobox: case widget.Combobox:
newCombobox(p, n) newCombobox(p, n)
setText(n, a) setText(n, widget.GetString(n.State.Value))
case widget.Textbox: case widget.Textbox:
newTextbox(p, n) newTextbox(p, n)
setText(n, a) setText(n, widget.GetString(n.State.Value))
/* /*
case widget.Image: case widget.Image:
newImage(p, n) newImage(p, n)
*/ */
default: default:
log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.State.ProgName) log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.ProgName())
}
} }
return n func newAdd(n *tree.Node) {
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
}
if n.WidgetType == widget.Root {
me.treeRoot = n
return
}
add(n)
if n.TK == nil {
log.Warn("Tree sent an action on a widget we didn't seem to have.")
// do this init here again? Probably something
// went wrong and we should reset the our while gocui.View tree
n.TK = initWidget(n)
}
// show(n, !a.State.Hidden)
if n.Hidden() {
hide(n)
} else {
if n.State.Enable {
// nothing to do
} else {
enable(n, false)
}
}
} }

View File

@ -9,20 +9,20 @@ import (
func compareStrings(n *tree.Node, ss []string) { func compareStrings(n *tree.Node, ss []string) {
} }
func addText(n *tree.Node, a *widget.Action) { func addText(n *tree.Node, s string) {
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
log.Log(ANDLABS, "addText() START with a.Value =", a.Value) log.Log(ANDLABS, "addText() START with s =", s)
if tk == nil { if tk == nil {
log.Log(ERROR, "addText error. tk == nil", n.State.ProgName, n.WidgetId) log.Log(ERROR, "addText error. tk == nil", n.State.ProgName, n.WidgetId)
return return
} }
log.Log(ANDLABS, "addText() Attempt on", n.WidgetType, "with", a.Value) log.Log(ANDLABS, "addText() Attempt on", n.WidgetType, "with", s)
switch n.WidgetType { switch n.WidgetType {
case widget.Dropdown: case widget.Dropdown:
for i, s := range a.State.Strings { for i, s := range n.State.Strings {
log.Log(ANDLABS, "a.State.Strings =", i, s) log.Log(ANDLABS, "n.State.Strings =", i, s)
_, ok := n.Strings[s] _, ok := n.Strings[s]
// If the key exists // If the key exists
if ok { if ok {
@ -35,9 +35,9 @@ func addText(n *tree.Node, a *widget.Action) {
} }
} }
case widget.Combobox: case widget.Combobox:
addComboboxName(n, widget.GetString(a.Value)) addComboboxName(n, s)
default: default:
log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType) log.Log(ERROR, "addText() doesn't work on", n.WidgetType)
} }
log.Log(ANDLABS, "addText() END with a.Value =", a.Value) log.Log(ANDLABS, "addText() END with =", s)
} }

49
main.go
View File

@ -17,8 +17,44 @@ var uiMainUndef bool = true
var uiMain sync.Once var uiMain sync.Once
var muAction sync.Mutex var muAction sync.Mutex
func queueMain(currentA widget.Action) { func queueAction(n *tree.Node, atype widget.ActionType) {
ui.QueueMain(func() {
newAction(n, atype)
})
}
func queueAdd(n *tree.Node) {
ui.QueueMain(func() {
newAdd(n)
})
}
func queueSetTitle(n *tree.Node, s string) {
ui.QueueMain(func() {
SetText(n, s)
})
}
func queueSetLabel(n *tree.Node, s string) {
ui.QueueMain(func() {
SetText(n, s)
})
}
func queueSetText(n *tree.Node, s string) {
ui.QueueMain(func() {
SetText(n, s)
})
}
func queueAddText(n *tree.Node, s string) {
ui.QueueMain(func() {
AddText(n, s)
})
}
/* /*
func queueMain(currentA widget.Action) {
// this never happends // this never happends
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
@ -29,7 +65,6 @@ func queueMain(currentA widget.Action) {
me.myTree.SendToolkitPanic() me.myTree.SendToolkitPanic()
} }
}() }()
*/
// andlabs puts this inside the gofunction over there // andlabs puts this inside the gofunction over there
// probably this should be changed around here // probably this should be changed around here
// and only andlabs stuff should be sent there? // and only andlabs stuff should be sent there?
@ -41,6 +76,7 @@ func queueMain(currentA widget.Action) {
processAction(&currentA) processAction(&currentA)
}) })
} }
*/
func guiMain() { func guiMain() {
defer func() { defer func() {
@ -79,7 +115,14 @@ func init() {
me.myTree = tree.New() me.myTree = tree.New()
me.myTree.PluginName = "andlabs" me.myTree.PluginName = "andlabs"
me.myTree.ActionFromChannel = queueMain // me.myTree.ActionFromChannel = queueMain
me.myTree.NodeAction = queueAction
me.myTree.Add = queueAdd
me.myTree.SetTitle = queueSetTitle
me.myTree.SetLabel = queueSetLabel
me.myTree.SetText = queueSetText
me.myTree.AddText = queueAddText
// TODO: this is messed up. run ui.Main() from the first add? Initialize it with an empty thing first? // TODO: this is messed up. run ui.Main() from the first add? Initialize it with an empty thing first?
// fake out the OS toolkit by making a fake window. This is probably needed for macos & windows // fake out the OS toolkit by making a fake window. This is probably needed for macos & windows

View File

@ -6,8 +6,8 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
func setText(n *tree.Node, a *widget.Action) { func setText(n *tree.Node, name string) {
name := widget.GetString(a.Value) // name := widget.GetString(a.Value)
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
@ -21,12 +21,12 @@ func setText(n *tree.Node, a *widget.Action) {
switch n.WidgetType { switch n.WidgetType {
case widget.Window: case widget.Window:
log.Log(CHANGE, "setText() Attempt to set the title to", name) log.Log(CHANGE, "setText() Attempt to set the title to", name)
tk.uiWindow.SetTitle(a.State.Label) tk.uiWindow.SetTitle(name)
case widget.Tab: case widget.Tab:
case widget.Group: case widget.Group:
tk.uiGroup.SetTitle(a.State.Label) tk.uiGroup.SetTitle(name)
case widget.Checkbox: case widget.Checkbox:
tk.uiCheckbox.SetText(a.State.Label) tk.uiCheckbox.SetText(name)
case widget.Textbox: case widget.Textbox:
if tk.uiEntry != nil { if tk.uiEntry != nil {
tk.uiEntry.SetText(name) tk.uiEntry.SetText(name)
@ -35,13 +35,13 @@ func setText(n *tree.Node, a *widget.Action) {
tk.uiMultilineEntry.SetText(name) tk.uiMultilineEntry.SetText(name)
} }
case widget.Label: case widget.Label:
tk.uiLabel.SetText(a.State.Label) tk.uiLabel.SetText(name)
case widget.Button: case widget.Button:
tk.uiButton.SetText(a.State.Label) tk.uiButton.SetText(name)
case widget.Slider: case widget.Slider:
log.Log(ERROR, "setText() on slider unknown", a.ActionType, "on checkbox", n.GetProgName()) log.Log(ERROR, "setText() on slider unknown", n.GetProgName())
case widget.Spinner: case widget.Spinner:
log.Log(ERROR, "setText() on spinner unknown", a.ActionType, "on checkbox", n.GetProgName()) log.Log(ERROR, "setText() on spinner unknown", n.GetProgName())
case widget.Dropdown: case widget.Dropdown:
var orig int var orig int
var i int = -1 var i int = -1
@ -69,7 +69,7 @@ func setText(n *tree.Node, a *widget.Action) {
case widget.Combobox: case widget.Combobox:
tk.uiEditableCombobox.SetText(name) tk.uiEditableCombobox.SetText(name)
default: default:
log.Log(ERROR, "plugin Send() Don't know how to setText on", n.WidgetType, "yet", a.ActionType) log.Log(ERROR, "plugin Send() Don't know how to setText on", n.WidgetType, "yet")
} }
log.Log(CHANGE, "setText() END with name =") log.Log(CHANGE, "setText() END with name =")
} }