diff options
| author | Jeff Carr <[email protected]> | 2023-04-28 10:35:57 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-04-28 10:35:57 -0500 |
| commit | 923f7721cca66d84dea77ffd9640d793803142ee (patch) | |
| tree | 824c9a2b83f574c37279c8526a1566035e78c2bb | |
| parent | 03942de00e133daf59da8ed3b6c3e71ce8afe316 (diff) | |
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 <[email protected]>
| -rw-r--r-- | README-goreadme.md | 9 | ||||
| -rw-r--r-- | button.go | 2 | ||||
| -rw-r--r-- | debugFlags.go | 2 | ||||
| -rw-r--r-- | debugGochan.go | 2 | ||||
| -rw-r--r-- | debugGolang.go | 2 | ||||
| -rw-r--r-- | debugWidget.go | 4 | ||||
| -rw-r--r-- | debugWindow.go | 12 | ||||
| -rw-r--r-- | main.go | 30 | ||||
| -rw-r--r-- | node.go | 4 | ||||
| -rw-r--r-- | plugin.go | 4 | ||||
| -rw-r--r-- | structs.go | 2 | ||||
| -rw-r--r-- | watchdog.go | 9 |
12 files changed, 39 insertions, 43 deletions
diff --git a/README-goreadme.md b/README-goreadme.md index 3e458b5..abf7acd 100644 --- a/README-goreadme.md +++ b/README-goreadme.md @@ -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 @@ -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) { diff --git a/debugFlags.go b/debugFlags.go index a62b6b9..6072008 100644 --- a/debugFlags.go +++ b/debugFlags.go @@ -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") diff --git a/debugGochan.go b/debugGochan.go index ad70fbd..5ac07a8 100644 --- a/debugGochan.go +++ b/debugGochan.go @@ -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") diff --git a/debugGolang.go b/debugGolang.go index 707b3d6..ac0b929 100644 --- a/debugGolang.go +++ b/debugGolang.go @@ -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") diff --git a/debugWidget.go b/debugWidget.go index 6345625..de34376 100644 --- a/debugWidget.go +++ b/debugWidget.go @@ -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) } } diff --git a/debugWindow.go b/debugWindow.go index febe961..338461e 100644 --- a/debugWindow.go +++ b/debugWindow.go @@ -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) } @@ -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 @@ -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 } @@ -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) @@ -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 { diff --git a/watchdog.go b/watchdog.go index 690ca44..e80861f 100644 --- a/watchdog.go +++ b/watchdog.go @@ -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 |
