use the new tree functions
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
fea47363e0
commit
1e98d2607b
79
action.go
79
action.go
|
@ -1,8 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"go.wit.com/dev/andlabs/ui"
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/toolkits/tree"
|
||||
"go.wit.com/widget"
|
||||
|
@ -169,6 +168,7 @@ func widgetDelete(n *tree.Node) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func processAction(a *widget.Action) {
|
||||
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)
|
||||
}
|
||||
*/
|
||||
|
||||
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())
|
||||
}
|
||||
|
|
51
add.go
51
add.go
|
@ -6,16 +6,7 @@ import (
|
|||
"go.wit.com/widget"
|
||||
)
|
||||
|
||||
func add(a *widget.Action) *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)
|
||||
|
||||
func add(n *tree.Node) {
|
||||
p := n.Parent
|
||||
switch n.WidgetType {
|
||||
case widget.Window:
|
||||
|
@ -32,27 +23,53 @@ func add(a *widget.Action) *tree.Node {
|
|||
newButton(p, n)
|
||||
case widget.Checkbox:
|
||||
newCheckbox(p, n)
|
||||
setChecked(n, a.State.Checked)
|
||||
setChecked(n, n.State.Checked)
|
||||
case widget.Spinner:
|
||||
newSpinner(p, n)
|
||||
case widget.Slider:
|
||||
newSlider(p, n)
|
||||
case widget.Dropdown:
|
||||
newDropdown(p, n)
|
||||
setText(n, a)
|
||||
setText(n, widget.GetString(n.State.Value))
|
||||
case widget.Combobox:
|
||||
newCombobox(p, n)
|
||||
setText(n, a)
|
||||
setText(n, widget.GetString(n.State.Value))
|
||||
case widget.Textbox:
|
||||
newTextbox(p, n)
|
||||
setText(n, a)
|
||||
setText(n, widget.GetString(n.State.Value))
|
||||
/*
|
||||
case widget.Image:
|
||||
newImage(p, n)
|
||||
*/
|
||||
default:
|
||||
log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.State.ProgName)
|
||||
log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.ProgName())
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
|
16
addText.go
16
addText.go
|
@ -9,20 +9,20 @@ import (
|
|||
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
|
||||
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 {
|
||||
log.Log(ERROR, "addText error. tk == nil", n.State.ProgName, n.WidgetId)
|
||||
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 {
|
||||
case widget.Dropdown:
|
||||
for i, s := range a.State.Strings {
|
||||
log.Log(ANDLABS, "a.State.Strings =", i, s)
|
||||
for i, s := range n.State.Strings {
|
||||
log.Log(ANDLABS, "n.State.Strings =", i, s)
|
||||
_, ok := n.Strings[s]
|
||||
// If the key exists
|
||||
if ok {
|
||||
|
@ -35,9 +35,9 @@ func addText(n *tree.Node, a *widget.Action) {
|
|||
}
|
||||
}
|
||||
case widget.Combobox:
|
||||
addComboboxName(n, widget.GetString(a.Value))
|
||||
addComboboxName(n, s)
|
||||
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)
|
||||
}
|
||||
|
|
32
box.go
32
box.go
|
@ -31,24 +31,24 @@ func newBox(n *tree.Node) {
|
|||
}
|
||||
|
||||
/*
|
||||
rawBox -- hack to arbitrarily add a box in andlabs to work
|
||||
around the problem that a "group" can not have one entry in it
|
||||
TODO: fix this so that a box is "added on demand" that is,
|
||||
if "go.wit.com/gui" sends you a 2nd thing to add to a group,
|
||||
automatically add a box then. The problem with this, is the macos, windows and linux gtk
|
||||
will panic on a move when an chind object is disasociated from the group
|
||||
I haven't had time to try to debug this, so, instead, it's just probably better to always
|
||||
add a box here. There doesn't seem to be any real issue with forcing a box to be inserted
|
||||
into the toolkits that is "outside" the binary tree of widgets. This only means, that on
|
||||
a destroy of the tree, this box must be checked
|
||||
rawBox -- hack to arbitrarily add a box in andlabs to work
|
||||
around the problem that a "group" can not have one entry in it
|
||||
TODO: fix this so that a box is "added on demand" that is,
|
||||
if "go.wit.com/gui" sends you a 2nd thing to add to a group,
|
||||
automatically add a box then. The problem with this, is the macos, windows and linux gtk
|
||||
will panic on a move when an chind object is disasociated from the group
|
||||
I haven't had time to try to debug this, so, instead, it's just probably better to always
|
||||
add a box here. There doesn't seem to be any real issue with forcing a box to be inserted
|
||||
into the toolkits that is "outside" the binary tree of widgets. This only means, that on
|
||||
a destroy of the tree, this box must be checked
|
||||
|
||||
even that is a probably not senario however since clicking on the close box in the toolkit
|
||||
has the operating system destroy everything in the window. it may or may not be possible
|
||||
to control that behavior. at this time, it's "undetermined" and the best course of action
|
||||
is to detect the window is destroyed and then remove all the toolkit information
|
||||
from all the nodes in the binary tree
|
||||
even that is a probably not senario however since clicking on the close box in the toolkit
|
||||
has the operating system destroy everything in the window. it may or may not be possible
|
||||
to control that behavior. at this time, it's "undetermined" and the best course of action
|
||||
is to detect the window is destroyed and then remove all the toolkit information
|
||||
from all the nodes in the binary tree
|
||||
|
||||
TODO: handle user killing/closing a window using the OS
|
||||
TODO: handle user killing/closing a window using the OS
|
||||
*/
|
||||
func rawBox(n *tree.Node) *ui.Box {
|
||||
var box *ui.Box
|
||||
|
|
49
main.go
49
main.go
|
@ -17,8 +17,44 @@ var uiMainUndef bool = true
|
|||
var uiMain sync.Once
|
||||
var muAction sync.Mutex
|
||||
|
||||
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
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -29,7 +65,6 @@ func queueMain(currentA widget.Action) {
|
|||
me.myTree.SendToolkitPanic()
|
||||
}
|
||||
}()
|
||||
*/
|
||||
// andlabs puts this inside the gofunction over there
|
||||
// probably this should be changed around here
|
||||
// and only andlabs stuff should be sent there?
|
||||
|
@ -41,6 +76,7 @@ func queueMain(currentA widget.Action) {
|
|||
processAction(¤tA)
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
func guiMain() {
|
||||
defer func() {
|
||||
|
@ -79,7 +115,14 @@ func init() {
|
|||
|
||||
me.myTree = tree.New()
|
||||
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?
|
||||
// fake out the OS toolkit by making a fake window. This is probably needed for macos & windows
|
||||
|
|
20
setText.go
20
setText.go
|
@ -6,8 +6,8 @@ import (
|
|||
"go.wit.com/widget"
|
||||
)
|
||||
|
||||
func setText(n *tree.Node, a *widget.Action) {
|
||||
name := widget.GetString(a.Value)
|
||||
func setText(n *tree.Node, name string) {
|
||||
// name := widget.GetString(a.Value)
|
||||
var tk *guiWidget
|
||||
tk = n.TK.(*guiWidget)
|
||||
|
||||
|
@ -21,12 +21,12 @@ func setText(n *tree.Node, a *widget.Action) {
|
|||
switch n.WidgetType {
|
||||
case widget.Window:
|
||||
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.Group:
|
||||
tk.uiGroup.SetTitle(a.State.Label)
|
||||
tk.uiGroup.SetTitle(name)
|
||||
case widget.Checkbox:
|
||||
tk.uiCheckbox.SetText(a.State.Label)
|
||||
tk.uiCheckbox.SetText(name)
|
||||
case widget.Textbox:
|
||||
if tk.uiEntry != nil {
|
||||
tk.uiEntry.SetText(name)
|
||||
|
@ -35,13 +35,13 @@ func setText(n *tree.Node, a *widget.Action) {
|
|||
tk.uiMultilineEntry.SetText(name)
|
||||
}
|
||||
case widget.Label:
|
||||
tk.uiLabel.SetText(a.State.Label)
|
||||
tk.uiLabel.SetText(name)
|
||||
case widget.Button:
|
||||
tk.uiButton.SetText(a.State.Label)
|
||||
tk.uiButton.SetText(name)
|
||||
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:
|
||||
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:
|
||||
var orig int
|
||||
var i int = -1
|
||||
|
@ -69,7 +69,7 @@ func setText(n *tree.Node, a *widget.Action) {
|
|||
case widget.Combobox:
|
||||
tk.uiEditableCombobox.SetText(name)
|
||||
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 =")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue