switch to treeInit

This commit is contained in:
Jeff Carr 2025-02-14 18:11:19 -06:00
parent c4e48c6403
commit a83ca26ac3
Notes: Jeff Carr 2025-02-14 19:32:31 -06:00
// `autogen:go.mod`

module go.wit.com/toolkits/nocui

go 1.22

toolchain go1.23.6

require (
	go.wit.com/lib/protobuf/guipb v0.0.2
	go.wit.com/log v0.22.16
	go.wit.com/toolkits/tree v0.22.10
	go.wit.com/widget v1.1.29
)

require google.golang.org/protobuf v1.36.5 // indirect

// `autogen:go.sum`

github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
go.wit.com/lib/protobuf/guipb v0.0.2 h1:ZR4cLy+XheRQEFLlissBmASJDqiLfHaAluF6wYbVuOo=
go.wit.com/lib/protobuf/guipb v0.0.2/go.mod h1:mZsirb7zRgsE2IGHuvHkG7j85hkrGZl3NAALOEkjowA=
go.wit.com/log v0.22.16 h1:E0Vd0Z2ILtfjhs7J/CQ4g13DK1jtQiYl6l5KOBGsZoA=
go.wit.com/log v0.22.16/go.mod h1:/c5Uj30sWRQ4B5ei2ElB6Q8Si/cK6v+KbxnH208KD84=
go.wit.com/toolkits/tree v0.22.10 h1:h1sHPBenR0Ohj0LG4nL3nW6/deCsbb+qeBmw8Idl6w8=
go.wit.com/toolkits/tree v0.22.10/go.mod h1:BhgxAFb8LxpM/L9e8nM+fQdM9MYi6lInMagRIX5+VTA=
go.wit.com/widget v1.1.29 h1:rURM/N1hbrl0btGlBIUx0SCre9jj+hshvkBLMMa008I=
go.wit.com/widget v1.1.29/go.mod h1:wj7TpAr2gk7Poa+v8XQkH1aidnTdgAa/a8GxrMtcztw=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=

// `autogen:`
7 changed files with 120 additions and 95 deletions

View File

@ -1,10 +1,10 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)
all:nocui.so
all: goimports nocui
@#ldd nocui.so
nocui.so:
nocui:
GO111MODULE=off go build -v -buildmode=plugin -o nocui.so \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"

View File

@ -7,12 +7,13 @@ package main
*/
import (
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
func Add(n *tree.Node) {
func newAdd(n *tree.Node) {
log.Log(INFO, "Add() END =", n.WidgetType, n.String())
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
@ -68,15 +69,15 @@ func newaction(n *tree.Node, atype widget.ActionType) {
log.Log(INFO, "newaction() END", atype, n.String())
}
func SetTitle(n *tree.Node, s string) {
SetText(n, s)
func setTitle(n *tree.Node, s string) {
setText(n, s)
}
func SetLabel(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) {
func setText(n *tree.Node, s string) {
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
@ -90,7 +91,7 @@ func SetText(n *tree.Node, s string) {
log.Info("SetText()", n.WidgetType, n.String())
}
func AddText(n *tree.Node, s string) {
func addText(n *tree.Node, s string) {
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
@ -103,3 +104,23 @@ func AddText(n *tree.Node, s string) {
// w := n.TK.(*guiWidget)
// w.AddText(s)
}
func enableWidget(n *tree.Node) {
log.Info("do enable() here")
}
func disableWidget(n *tree.Node) {
log.Info("do enable() here")
}
func setChecked(n *tree.Node, b bool) {
log.Info("do enable() here")
}
func showTable(n *guipb.Table) {
log.Info("do enable() here")
}
func toolkitClose() {
log.Info("do enable() here")
}

View File

@ -1,51 +0,0 @@
package main
/*
import (
"go.wit.com/log"
"go.wit.com/widget"
"go.wit.com/toolkits/tree"
)
func doWidgetClick(n *tree.Node) {
switch n.WidgetType {
case widget.Root:
// THIS IS THE BEGINING OF THE LAYOUT
// rootNode.nextW = 0
// rootNode.nextH = 0
// rootNode.redoTabs(true)
case widget.Flag:
// me.rootNode.redoColor(true)
// rootNode.dumpTree(true)
case widget.Window:
// setCurrentWindow(w)
// n.doUserEvent()
case widget.Tab:
// setCurrentTab(w)
case widget.Group:
// n.placeWidgets()
// n.toggleTree()
case widget.Checkbox:
if n.Bool() {
// n.setCheckbox(false)
} else {
// n.setCheckbox(true)
}
// n.doUserEvent()
case widget.Grid:
// rootNode.hideWidgets()
// n.placeGrid()
// n.showWidgets()
case widget.Box:
// n.showWidgetPlacement(logNow, "drawTree()")
if n.Bool() {
log.Log(NOW, "BOX IS HORIZONTAL", n.GetProgName())
} else {
log.Log(NOW, "BOX IS VERTICAL", n.GetProgName())
}
case widget.Button:
// n.doUserEvent()
default:
}
}
*/

25
main.go
View File

@ -9,22 +9,25 @@ package main
import (
"go.wit.com/log"
"go.wit.com/toolkits/tree"
)
func init() {
var PLUGIN string = "nocui"
func initPlugin() {
log.Log(INFO, "Init()")
me.myTree = tree.New()
me.myTree.PluginName = "nocui"
// me.myTree.ActionFromChannel = doAction
me.myTree = initTree()
/*
me.myTree.PluginName = "nocui"
// me.myTree.ActionFromChannel = doAction
me.myTree.NodeAction = newaction
me.myTree.Add = Add
me.myTree.SetTitle = SetTitle
me.myTree.SetLabel = SetLabel
me.myTree.SetText = SetText
me.myTree.AddText = AddText
// me.myTree.NodeAction = newaction
me.myTree.Add = Add
me.myTree.SetTitle = SetTitle
me.myTree.SetLabel = SetLabel
me.myTree.SetText = SetText
me.myTree.AddText = AddText
*/
me.exit = false

View File

@ -1,6 +1,8 @@
package main
import (
"sync"
"go.wit.com/toolkits/tree"
)
@ -13,6 +15,8 @@ type guiWidget struct {
val map[string]int
}
var initOnce sync.Once // run initPlugin() only once
// It's probably a terrible idea to call this 'me'
var me config

24
tree.go
View File

@ -1,24 +0,0 @@
package main
/*
This is reference code for toolkit developers
*/
import (
"go.wit.com/widget"
)
// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from
// other goroutines. This is due to the nature of how
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
//
// this sets the channel to send user events back from the plugin
func Callback(guiCallback chan widget.Action) {
me.myTree.Callback(guiCallback)
}
func PluginChannel() chan widget.Action {
return me.myTree.PluginChannel()
}

72
treeInit.go Normal file
View File

@ -0,0 +1,72 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
/*
DO NOT EDIT THIS FILE
this file is the same for every GUI toolkit plugin
when you are making a new GUI toolkit plugin for
a specific toolkit, you just need to define these
functions.
for example, in the "gocui" toolkit, the functions
below are what triggers the "gocui" GO package
to draw labels, buttons, windows, etc
If you are starting out trying to make a new GUI toolkit,
all you have to do is copy this file over. Then
work on making these functions. addWidget(), setText(), etc.
That's it!
*/
package main
/*
This is reference code for toolkit developers
This is how information is passed in GO back to the application
via the GO 'plugin' concept
TODO: switch this to protocol buffers
*/
import (
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from
// other goroutines. This is due to the nature of how
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
//
// this sets the channel to send user events back from the plugin
func Callback(guiCallback chan widget.Action) {
me.myTree.Callback(guiCallback)
}
func PluginChannel() chan widget.Action {
initOnce.Do(initPlugin)
return me.myTree.PluginChannel()
}
func initTree() *tree.TreeInfo {
t := tree.New()
t.PluginName = PLUGIN
t.Add = newAdd
t.SetTitle = setTitle
t.SetLabel = setLabel
t.SetText = setText
t.AddText = addText
t.Enable = enableWidget
t.Disable = disableWidget
t.SetChecked = setChecked
t.ToolkitClose = toolkitClose
t.ShowTable = showTable
return t
}