Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
|
5437b68670 | |
|
1068eb5aad | |
|
1418d4652e | |
|
1127b96570 | |
|
308543c02c | |
|
d141b4d308 |
2
Makefile
2
Makefile
|
@ -19,4 +19,4 @@ toolkitConfig.pb.go: toolkitConfig.proto
|
|||
|
||||
clean:
|
||||
rm -f go.* *.pb.go
|
||||
go-mod-clean --purge
|
||||
go-mod-clean purge
|
||||
|
|
31
action.go
31
action.go
|
@ -5,6 +5,8 @@
|
|||
package tree
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"go.wit.com/lib/protobuf/guipb"
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/widget"
|
||||
|
@ -27,6 +29,35 @@ func (me *TreeInfo) doAction(a widget.Action) {
|
|||
me.ToolkitInit()
|
||||
return
|
||||
}
|
||||
if a.WidgetPB != nil {
|
||||
log.Log(TREEWARN, "tree: got a WidgetPB")
|
||||
widgetpb := new(guipb.Widgets)
|
||||
err := widgetpb.Unmarshal(a.WidgetPB)
|
||||
if err != nil {
|
||||
log.Log(TREEWARN, "WidgetPB unmarshal err", err)
|
||||
return
|
||||
}
|
||||
log.Log(TREEWARN, "tree: unmarshal worked!")
|
||||
var wind *Node
|
||||
newa := new(widget.Action)
|
||||
newa.WidgetType = widget.Window
|
||||
newa.WidgetId = -234
|
||||
newa.ParentId = -1234
|
||||
newa.State.Enable = true
|
||||
wind = addNode(newa)
|
||||
if wind == nil {
|
||||
log.Log(TREEWARN, "tree: addNode() failed to add win")
|
||||
return
|
||||
}
|
||||
wind.State.ProgName = "WinPB"
|
||||
wind.State.Label = "WinPB"
|
||||
me.Add(wind)
|
||||
me.doWidgetsPB(widgetpb.Tree)
|
||||
me.ToolkitClose()
|
||||
os.Exit(0)
|
||||
// me.doTable(a)
|
||||
return
|
||||
}
|
||||
if a.TablePB != nil {
|
||||
log.Log(TREE, "tree: got a TablePB")
|
||||
me.doTable(a)
|
||||
|
|
|
@ -38,9 +38,9 @@ func addNode(a *widget.Action) *Node {
|
|||
}
|
||||
|
||||
if treeRoot.FindWidgetId(a.WidgetId) != nil {
|
||||
log.Log(TREEWARN, "AddNode() WidgetId already exists", a.WidgetId)
|
||||
log.Log(TREEWARN, "probably this is a Show() / Hide() issue")
|
||||
log.Log(TREEWARN, "TODO: figure out what to do here")
|
||||
// ignore these errors for now
|
||||
log.Log(TREE, "AddNode() WidgetId already exists", a.WidgetId)
|
||||
log.Log(TREE, "TODO: figure out what to do here probably this is a Show() / Hide() issue")
|
||||
return treeRoot.FindWidgetId(a.WidgetId)
|
||||
}
|
||||
|
||||
|
|
4
find.go
4
find.go
|
@ -10,6 +10,10 @@ func FindWidgetId(id int) *Node {
|
|||
return treeRoot.FindWidgetId(id)
|
||||
}
|
||||
|
||||
func FindWidgetById(id int) *Node {
|
||||
return treeRoot.FindWidgetId(id)
|
||||
}
|
||||
|
||||
// searches the binary tree for a WidgetId
|
||||
func (n *Node) FindWidgetId(id int) *Node {
|
||||
if n == nil {
|
||||
|
|
25
init.go
25
init.go
|
@ -68,7 +68,30 @@ func (t *TreeInfo) ConfigFind(n string) (string, error) {
|
|||
if n == r.Name {
|
||||
return r.Value, nil
|
||||
}
|
||||
log.Info("toolkit config", r.Plugin, r.Name, r.Value, n)
|
||||
// log.Info("toolkit config no-match on", r.Plugin, r.Name, r.Value, n)
|
||||
}
|
||||
return "", fmt.Errorf("toolkit config %s not found", n)
|
||||
}
|
||||
|
||||
func (t *TreeInfo) ConfigSave(o *ToolkitConfig) {
|
||||
t.configInsert(o)
|
||||
t.config.configSave()
|
||||
}
|
||||
|
||||
// update the config option value (or append if new record)
|
||||
func (t *TreeInfo) configInsert(newr *ToolkitConfig) {
|
||||
all := t.config.All() // get the list of repos
|
||||
for all.Scan() {
|
||||
r := all.Next()
|
||||
if t.PluginName != r.Plugin {
|
||||
// option isn't for this plugin
|
||||
continue
|
||||
}
|
||||
if newr.Name == r.Name {
|
||||
// found the record!
|
||||
r.Value = newr.Value
|
||||
return
|
||||
}
|
||||
}
|
||||
t.config.Append(newr)
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ type TreeInfo struct {
|
|||
Disable func(*Node) // disable a widget
|
||||
ShowTable func(*guipb.Table) // attempt at sending a whole table
|
||||
currentTables []*guipb.Table // track the list of tables?
|
||||
Root *guipb.Tree // this is the future of this system
|
||||
// Root *guipb.Tree // this is the future of this system
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
|
|
42
table.go
42
table.go
|
@ -15,8 +15,17 @@ import (
|
|||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
func (me *TreeInfo) doWidgetsPB(w *guipb.Widget) {
|
||||
log.Log(TREEWARN, "tree:", w.Id, w.Name)
|
||||
|
||||
for _, child := range w.Children {
|
||||
me.doWidgetsPB(child)
|
||||
}
|
||||
}
|
||||
|
||||
func (me *TreeInfo) doTable(a widget.Action) {
|
||||
if a.TablePB == nil {
|
||||
log.Log(TREE, "tree: action didn't have a Table PB")
|
||||
|
@ -200,6 +209,7 @@ func (me *TreeInfo) makeTable(t *guipb.Table) {
|
|||
return
|
||||
}
|
||||
me.Add(grid)
|
||||
grid.State.ProgName = "TableGridPB"
|
||||
// log.Info("tree: makeTable() finished add win & grid")
|
||||
var h int = 0
|
||||
var w int = 0
|
||||
|
@ -263,7 +273,11 @@ func (me *TreeInfo) addTableRow(t *guipb.Table, grid *Node, name string, w int)
|
|||
me.Add(head)
|
||||
h += 1
|
||||
for _, v := range r.Widgets {
|
||||
v.Name = fmt.Sprintf("%d", v.Size)
|
||||
vi, err := extractInt64(v.Val)
|
||||
if err != nil {
|
||||
log.Log(TREEWARN, "int error", err)
|
||||
}
|
||||
v.Name = fmt.Sprintf("%d", vi)
|
||||
// log.Info("tree: Add()ing to grid here", v.Id, v.Name, w, h)
|
||||
lab := grid.makeGridLabel(v, w, h)
|
||||
me.Add(lab)
|
||||
|
@ -307,6 +321,30 @@ func (me *TreeInfo) addTableRow(t *guipb.Table, grid *Node, name string, w int)
|
|||
return false
|
||||
}
|
||||
|
||||
func extractInt64(anyVal *anypb.Any) (int64, error) {
|
||||
val := &wrapperspb.Int64Value{}
|
||||
if err := anyVal.UnmarshalTo(val); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return val.Value, nil
|
||||
}
|
||||
|
||||
// returns true if widget is in a table
|
||||
func (n *Node) InTable() bool {
|
||||
// log.Info("InTable() parent id =", n.ParentId)
|
||||
grid := FindWidgetById(int(n.ParentId))
|
||||
if grid != nil {
|
||||
if grid.WidgetType == widget.Grid {
|
||||
if grid.State.ProgName == "TableGridPB" {
|
||||
// this is a protobuf table
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func dumpTable(t *guipb.Table) {
|
||||
for i, o := range t.Order {
|
||||
log.Info("got order:", t.Title, i, o)
|
||||
|
@ -320,7 +358,7 @@ func dumpTable(t *guipb.Table) {
|
|||
for i, r := range t.IntRows {
|
||||
log.Info("got int row:", t.Title, i, r.Header.Name, r.Vals)
|
||||
for _, v := range r.Widgets {
|
||||
log.Info("tree: got int widget:", v.Id, v.Size)
|
||||
log.Info("tree: got int widget:", v.Id, v.Val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ package forgepb;
|
|||
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||
|
||||
message ToolkitConfig { //
|
||||
string plugin = 1; // 'gocui', 'andlabs', etc
|
||||
string name = 2; // variable name 'fullscreen'
|
||||
string plugin = 1; // 'gocui', 'andlabs', etc `autogenpb:unique`
|
||||
string name = 2; // variable name 'fullscreen' `autogenpb:unique`
|
||||
string value = 3; // value "true"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue