s/Config/me/ to remove direct access to anything

since most everything needs to be passed to the toolkits
everything should be accessed via func()'s

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-28 10:35:57 -05:00
parent a132b48ada
commit 14f69c4a40
12 changed files with 39 additions and 43 deletions

View File

@ -107,12 +107,6 @@ external things which might be useful
* [GO Style Guide]
```
## Variables
```golang
var Config guiConfig
```
## Functions
### func [DebugWidgetWindow](/debugWidget.go#L52)
@ -152,12 +146,13 @@ Creates a window helpful for debugging this package
The window is destroyed and the application exits
TODO: properly exit the plugin since Quit() doesn't do it
### func [Watchdog](/watchdog.go#L15)
### func [Watchdog](/watchdog.go#L16)
`func Watchdog()`
This program sits here.
If you exit here, the whole thing will os.Exit()
TODO: use Ticker
This goroutine can be used like a watchdog timer

View File

@ -17,7 +17,7 @@ func (n *Node) NewButton(name string, custom func()) *Node {
// deprecate this once andlabs is refactored
func callback(i int) bool {
log(debugError, "callback() for widget id =", i)
n := Config.rootNode.FindId(i)
n := me.rootNode.FindId(i)
log(debugError, "callback() found node =", n)
// running custom here means the button get's clicked twice
if (n.Custom == nil) {

View File

@ -9,7 +9,7 @@ func (n *Node) DebugFlags(makeWindow bool) {
// make a new window
// make a new tab in the existing window
if (makeWindow) {
w = Config.rootNode.NewWindow("Debug Flags")
w = me.rootNode.NewWindow("Debug Flags")
w.Custom = w.StandardClose
} else {
w = n.NewTab("Flags")

View File

@ -18,7 +18,7 @@ func (n *Node) DebugGoChannels(makeWindow bool) {
// make a new window
// make a new tab in the existing window
if (makeWindow) {
w = Config.rootNode.NewWindow("Debug GO Channels")
w = me.rootNode.NewWindow("Debug GO Channels")
w.Custom = w.StandardClose
} else {
w = n.NewTab("Chan")

View File

@ -16,7 +16,7 @@ func (n *Node) DebugGolangWindow(makeWindow bool) {
// make a new window
// make a new tab in the existing window
if (makeWindow) {
w = Config.rootNode.NewWindow("GO")
w = me.rootNode.NewWindow("GO")
w.Custom = w.StandardClose
} else {
w = n.NewTab("GOLANG")

View File

@ -60,7 +60,7 @@ func DebugWidgetWindow(w *Node) {
// make a new window
// make a new tab in the existing window
if (makeTabs) {
bugWidget = Config.rootNode.NewWindow("Widgets")
bugWidget = me.rootNode.NewWindow("Widgets")
bugWidget.Custom = bugWidget.StandardClose
} else {
bugWidget = bugWin.NewTab("Widgets")
@ -162,7 +162,7 @@ func DebugWidgetWindow(w *Node) {
activeJunk.NewLabel("test junk")
if (activeWidget == nil) {
setActiveWidget(Config.rootNode)
setActiveWidget(me.rootNode)
}
}

View File

@ -19,7 +19,7 @@ var myButton *Node
Creates a window helpful for debugging this package
*/
func DebugWindow() {
bugWin = Config.rootNode.NewWindow("go.wit.com/gui debug window").DebugTab("Debug Tab")
bugWin = me.rootNode.NewWindow("go.wit.com/gui debug window").DebugTab("Debug Tab")
bugWin.Custom = bugWin.StandardClose
// bugWin.DebugTab("Debug Tab")
}
@ -66,7 +66,7 @@ func (n *Node) DebugTab(title string) *Node {
g1.NewButton("List toolkits", func () {
dropdownWindow(g1)
Config.rootNode.ListToolkits()
me.rootNode.ListToolkits()
})
g1.NewButton("List Windows", func () {
dropdownWindow(g1)
@ -79,7 +79,7 @@ func (n *Node) DebugTab(title string) *Node {
g2.NewButton("Node.ListChildren(true)", func () {
if (activeWidget == nil) {
activeWidget = Config.rootNode
activeWidget = me.rootNode
}
activeWidget.ListChildren(true)
})
@ -95,7 +95,7 @@ func (n *Node) DebugTab(title string) *Node {
})
g2.NewButton("load toolkit 'gocui'", func () {
Config.rootNode.LoadToolkit("gocui")
me.rootNode.LoadToolkit("gocui")
})
return newN
@ -120,7 +120,7 @@ func dropdownWindow(p *Node) {
}
// var last = ""
for _, child := range Config.rootNode.children {
for _, child := range me.rootNode.children {
log(logInfo, "\t\t", child.id, child.Name)
dd.AddDropdownName(child.Name)
// last = child.Name
@ -160,5 +160,5 @@ func dropdownWindowWidgets(p *Node) {
}
// list everything in the binary tree
addDropdowns(Config.rootNode)
addDropdowns(me.rootNode)
}

30
main.go
View File

@ -17,21 +17,21 @@ const Yaxis = 1 // stack things vertically
func init() {
log("init() has been run")
Config.counter = 0
Config.prefix = "wit"
me.counter = 0
me.prefix = "wit"
// Populates the top of the binary tree
Config.rootNode = addNode("guiBinaryTree")
Config.rootNode.WidgetType = toolkit.Root
me.rootNode = addNode("guiBinaryTree")
me.rootNode.WidgetType = toolkit.Root
// used to pass debugging flags to the toolkit plugins
Config.flag = Config.rootNode.newNode("flag", 0, nil)
Config.flag.WidgetType = toolkit.Flag
me.flag = me.rootNode.newNode("flag", 0, nil)
me.flag.WidgetType = toolkit.Flag
Config.flag = Config.rootNode.newNode("stdout", 0, nil)
Config.flag.WidgetType = toolkit.Stdout
me.flag = me.rootNode.newNode("stdout", 0, nil)
me.flag.WidgetType = toolkit.Stdout
Config.guiChan = make(chan toolkit.Action, 1)
me.guiChan = make(chan toolkit.Action, 1)
go watchCallback()
}
@ -40,10 +40,10 @@ func watchCallback() {
for {
log(logNow, "watchCallback() restarted select for toolkit user events")
select {
case a := <-Config.guiChan:
case a := <-me.guiChan:
if (a.ActionType == toolkit.UserQuit) {
log(logNow, "doUserEvent() User sent Quit()")
Config.rootNode.doCustom()
me.rootNode.doCustom()
exit("wit/gui toolkit.UserQuit")
break
}
@ -53,7 +53,7 @@ func watchCallback() {
break
}
n := Config.rootNode.FindId(a.WidgetId)
n := me.rootNode.FindId(a.WidgetId)
if (n == nil) {
log(logError, "watchCallback() UNKNOWN widget id =", a.WidgetId, a.Name)
} else {
@ -115,7 +115,7 @@ func (n *Node) doUserEvent(a toolkit.Action) {
}
func (n *Node) InitEmbed(resFS embed.FS) *Node {
Config.resFS = resFS
me.resFS = resFS
return n
}
@ -162,7 +162,7 @@ func (n *Node) LoadToolkit(name string) *Node {
sleep(.5) // temp hack until chan communication is setup
// TODO: find a new way to do this that is locking, safe and accurate
Config.rootNode.redraw(plug)
me.rootNode.redraw(plug)
log(logInfo, "LoadToolkit() END for name =", name)
return n
}
@ -188,7 +188,7 @@ func (n *Node) CloseToolkit(name string) bool {
// some toolkit's on some operating systems don't support more than one
// Keep things simple. Do the default expected thing whenever possible
func New() *Node {
return Config.rootNode
return me.rootNode
}
// try to load andlabs, if that doesn't work, fall back to the console

View File

@ -24,10 +24,10 @@ func addNode(title string) *Node {
n := new(Node)
n.Name = title
n.Text = title
n.id = Config.counter
n.id = me.counter
log(debugNode, "addNode = widget setid =", n.id)
Config.counter += 1
me.counter += 1
return n
}

View File

@ -120,7 +120,7 @@ func searchPaths(name string) *aplug {
// first try to load the embedded plugin file
filename = "plugins/" + name + ".so"
pfile, err = Config.resFS.ReadFile(filename)
pfile, err = me.resFS.ReadFile(filename)
if (err == nil) {
log(logError, "write out file here", name, filename, len(pfile))
exit()
@ -195,7 +195,7 @@ func initToolkit(name string, filename string) *aplug {
log(debugError, "initToolkit() ERROR PluginChannel() returned nil for plugin:", newPlug.name, filename)
return nil
}
newPlug.Callback(Config.guiChan)
newPlug.Callback(me.guiChan)
newPlug.InitOk = true
log(debugPlugin, "initToolkit() END", newPlug.name, filename)

View File

@ -21,7 +21,7 @@ import (
// For example, a "Mouse Control Panel" not the GIMP or blender.
//
var Config guiConfig
var me guiConfig
// This struct can be used with the go-arg package
type GuiArgs struct {

View File

@ -9,18 +9,19 @@ var watchtime time.Duration = 100 // in tenths of seconds
/*
This program sits here.
If you exit here, the whole thing will os.Exit()
TODO: use Ticker
This goroutine can be used like a watchdog timer
*/
func Watchdog() {
var i = 1
for {
log(logInfo, "watchdog timer is alive. give me something to do.", i)
if (Config.rootNode == nil) {
log(logInfo, "Config.rootNode == nil", i)
log(logInfo, "gui.Watchdog() is alive. give me something to do.", i)
if (me.rootNode == nil) {
log(logInfo, "me.rootNode == nil", i)
} else {
if (logVerbose) {
Config.rootNode.ListChildren(true)
me.rootNode.ListChildren(true)
}
}
i += 1