From 514b39e3825d39adf540bf67dc4ea8115007e3d7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 13 Feb 2025 14:27:32 -0600 Subject: better filename --- init.go | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 168 ---------------------------------------------------------------- 2 files changed, 168 insertions(+), 168 deletions(-) create mode 100644 init.go delete mode 100644 main.go diff --git a/init.go b/init.go new file mode 100644 index 0000000..dd9a08c --- /dev/null +++ b/init.go @@ -0,0 +1,168 @@ +// plugin +package main + +import ( + "runtime/debug" + "sync" + + "go.wit.com/log" + "go.wit.com/toolkits/tree" + "go.wit.com/widget" + + "go.wit.com/dev/andlabs/ui" + // the _ means we only need this for the init() + _ "go.wit.com/dev/andlabs/ui/winmanifest" +) + +// sent via -ldflags +var VERSION string +var BUILDTIME string + +var PLUGIN string = "andlabs" + +var uiMainUndef bool = true +var uiMain sync.Once +var muAction sync.Mutex + +func newaction(n *tree.Node, atype widget.ActionType) { + ui.QueueMain(func() { + newAction(n, atype) + }) +} + +func queueAdd(n *tree.Node) { + ui.QueueMain(func() { + newAdd(n) + }) +} + +func setTitle(n *tree.Node, s string) { + ui.QueueMain(func() { + SetText(n, s) + }) +} + +func setLabel(n *tree.Node, s string) { + ui.QueueMain(func() { + SetText(n, s) + }) +} + +func showTable(n *tree.Node) { + ui.QueueMain(func() { + log.Info("show table here") + }) +} + +func realSetText(n *tree.Node, s string) { + ui.QueueMain(func() { + SetText(n, s) + }) +} + +func realAddText(n *tree.Node, s string) { + ui.QueueMain(func() { + AddText(n, s) + }) +} + +func realSetChecked(n *tree.Node, b bool) { + ui.QueueMain(func() { + setChecked(n, b) + }) +} + +func toolkitClose() { + ui.QueueMain(func() { + ui.Quit() + }) +} + +/* +func queueMain(currentA widget.Action) { + // this never happends + defer func() { + if r := recover(); r != nil { + log.Log("YAHOOOO Recovered in queueMain() application:", r) + log.Println("Recovered from panic:", r) + log.Println("Stack trace:") + debug.PrintStack() + 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? + // it's easier to code it this way however + // also, if it dies here, it get's caught + // usually, this is where it dies + log.Log(ANDLABS, "about to send action into the andlabs ui.QueueMain()") + ui.QueueMain(func() { + processAction(¤tA) + }) +} +*/ + +func guiMain() { + defer func() { + if r := recover(); r != nil { + log.Log(WARN, "YAHOOOO Recovered in guiMain application:", r) + log.Log(WARN, "Recovered from panic:", r) + log.Log(WARN, "Stack trace:") + debug.PrintStack() + me.myTree.SendToolkitPanic() + return + } + }() + ui.Main(func() { + // this is a bad hack for now. + // a better way would be to spawn ui.Main on the first actual window + // that is supposed to be displayed + placeholderUI() + + me.myTree.InitOK() + + // if nothing is working, run this instead to make + // sure you have something + // demoUI() + }) +} + +func Init() { + log.Log(WARN, "Init() TODO: move init() to here") +} + +// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc +func initPlugin() { + log.Log(INFO, "Init() START") + log.Log(INFO, "Init()") + // Can you pass values to a plugin init() ? Otherwise, there is no way to safely print + // log.Log(INFO, "init() Setting defaultBehavior = true") + // setDefaultBehavior(true) + + me.myTree = initTree() + + // me.ok = true // this tells init() it's okay to work with gocui + /* + me.myTree = tree.New() + me.myTree.PluginName = "andlabs" + // 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 + me.myTree.SetChecked = queueSetChecked + me.myTree.ToolkitClose = queueToolkitClose + */ + + // 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 + // actually, this probably breaks the macos build + go guiMain() +} + +func main() { +} diff --git a/main.go b/main.go deleted file mode 100644 index dd9a08c..0000000 --- a/main.go +++ /dev/null @@ -1,168 +0,0 @@ -// plugin -package main - -import ( - "runtime/debug" - "sync" - - "go.wit.com/log" - "go.wit.com/toolkits/tree" - "go.wit.com/widget" - - "go.wit.com/dev/andlabs/ui" - // the _ means we only need this for the init() - _ "go.wit.com/dev/andlabs/ui/winmanifest" -) - -// sent via -ldflags -var VERSION string -var BUILDTIME string - -var PLUGIN string = "andlabs" - -var uiMainUndef bool = true -var uiMain sync.Once -var muAction sync.Mutex - -func newaction(n *tree.Node, atype widget.ActionType) { - ui.QueueMain(func() { - newAction(n, atype) - }) -} - -func queueAdd(n *tree.Node) { - ui.QueueMain(func() { - newAdd(n) - }) -} - -func setTitle(n *tree.Node, s string) { - ui.QueueMain(func() { - SetText(n, s) - }) -} - -func setLabel(n *tree.Node, s string) { - ui.QueueMain(func() { - SetText(n, s) - }) -} - -func showTable(n *tree.Node) { - ui.QueueMain(func() { - log.Info("show table here") - }) -} - -func realSetText(n *tree.Node, s string) { - ui.QueueMain(func() { - SetText(n, s) - }) -} - -func realAddText(n *tree.Node, s string) { - ui.QueueMain(func() { - AddText(n, s) - }) -} - -func realSetChecked(n *tree.Node, b bool) { - ui.QueueMain(func() { - setChecked(n, b) - }) -} - -func toolkitClose() { - ui.QueueMain(func() { - ui.Quit() - }) -} - -/* -func queueMain(currentA widget.Action) { - // this never happends - defer func() { - if r := recover(); r != nil { - log.Log("YAHOOOO Recovered in queueMain() application:", r) - log.Println("Recovered from panic:", r) - log.Println("Stack trace:") - debug.PrintStack() - 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? - // it's easier to code it this way however - // also, if it dies here, it get's caught - // usually, this is where it dies - log.Log(ANDLABS, "about to send action into the andlabs ui.QueueMain()") - ui.QueueMain(func() { - processAction(¤tA) - }) -} -*/ - -func guiMain() { - defer func() { - if r := recover(); r != nil { - log.Log(WARN, "YAHOOOO Recovered in guiMain application:", r) - log.Log(WARN, "Recovered from panic:", r) - log.Log(WARN, "Stack trace:") - debug.PrintStack() - me.myTree.SendToolkitPanic() - return - } - }() - ui.Main(func() { - // this is a bad hack for now. - // a better way would be to spawn ui.Main on the first actual window - // that is supposed to be displayed - placeholderUI() - - me.myTree.InitOK() - - // if nothing is working, run this instead to make - // sure you have something - // demoUI() - }) -} - -func Init() { - log.Log(WARN, "Init() TODO: move init() to here") -} - -// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc -func initPlugin() { - log.Log(INFO, "Init() START") - log.Log(INFO, "Init()") - // Can you pass values to a plugin init() ? Otherwise, there is no way to safely print - // log.Log(INFO, "init() Setting defaultBehavior = true") - // setDefaultBehavior(true) - - me.myTree = initTree() - - // me.ok = true // this tells init() it's okay to work with gocui - /* - me.myTree = tree.New() - me.myTree.PluginName = "andlabs" - // 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 - me.myTree.SetChecked = queueSetChecked - me.myTree.ToolkitClose = queueToolkitClose - */ - - // 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 - // actually, this probably breaks the macos build - go guiMain() -} - -func main() { -} -- cgit v1.2.3