summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-02-13 14:27:13 -0600
committerJeff Carr <[email protected]>2025-02-13 14:27:13 -0600
commit0c0c42ecbb97496628f51c9df08794d53a28db73 (patch)
tree78c4bace4f4ce854492908df6e0f5b605f7f653c
parent9babe64e41d22761027bebef4feade948857d3a7 (diff)
works again
-rw-r--r--Makefile2
-rw-r--r--main.go53
-rw-r--r--structs.go4
-rw-r--r--tree.go31
-rw-r--r--treeInit.go69
5 files changed, 108 insertions, 51 deletions
diff --git a/Makefile b/Makefile
index c8c2187..b6b7b32 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)
-all: goimports vet andlabs.so
+all: clean goimports vet andlabs.so
andlabs.so:
GO111MODULE=off go build -v -buildmode=plugin -o andlabs.so \
diff --git a/main.go b/main.go
index add53a2..dd9a08c 100644
--- a/main.go
+++ b/main.go
@@ -18,11 +18,13 @@ import (
var VERSION string
var BUILDTIME string
+var PLUGIN string = "andlabs"
+
var uiMainUndef bool = true
var uiMain sync.Once
var muAction sync.Mutex
-func queueAction(n *tree.Node, atype widget.ActionType) {
+func newaction(n *tree.Node, atype widget.ActionType) {
ui.QueueMain(func() {
newAction(n, atype)
})
@@ -34,37 +36,43 @@ func queueAdd(n *tree.Node) {
})
}
-func queueSetTitle(n *tree.Node, s string) {
+func setTitle(n *tree.Node, s string) {
ui.QueueMain(func() {
SetText(n, s)
})
}
-func queueSetLabel(n *tree.Node, s string) {
+func setLabel(n *tree.Node, s string) {
ui.QueueMain(func() {
SetText(n, s)
})
}
-func queueSetText(n *tree.Node, s string) {
+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 queueAddText(n *tree.Node, s string) {
+func realAddText(n *tree.Node, s string) {
ui.QueueMain(func() {
AddText(n, s)
})
}
-func queueSetChecked(n *tree.Node, b bool) {
+func realSetChecked(n *tree.Node, b bool) {
ui.QueueMain(func() {
setChecked(n, b)
})
}
-func queueToolkitClose() {
+func toolkitClose() {
ui.QueueMain(func() {
ui.Quit()
})
@@ -112,6 +120,8 @@ func guiMain() {
// that is supposed to be displayed
placeholderUI()
+ me.myTree.InitOK()
+
// if nothing is working, run this instead to make
// sure you have something
// demoUI()
@@ -123,25 +133,30 @@ func Init() {
}
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
-func init() {
+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 = tree.New()
- me.myTree.PluginName = "andlabs"
- // me.myTree.ActionFromChannel = queueMain
+ 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
+ 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
diff --git a/structs.go b/structs.go
index 1e2017f..89bbf29 100644
--- a/structs.go
+++ b/structs.go
@@ -1,12 +1,16 @@
package main
import (
+ "sync"
+
"go.wit.com/toolkits/tree"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
+var initOnce sync.Once // run initPlugin() only once
+
// It's probably a terrible idea to call this 'me'
var me config
diff --git a/tree.go b/tree.go
deleted file mode 100644
index 113bd51..0000000
--- a/tree.go
+++ /dev/null
@@ -1,31 +0,0 @@
-package main
-
-/*
- This code should be common to all gui plugins
-
- There are some helper functions that are probably going to be
- the same everywhere. Mostly due to handling the binary tree structure
- and the channel communication
-
- For now, it's just a symlink to the 'master' version in
- ./toolkit/nocui/common.go
-*/
-
-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()
-}
diff --git a/treeInit.go b/treeInit.go
new file mode 100644
index 0000000..57db353
--- /dev/null
+++ b/treeInit.go
@@ -0,0 +1,69 @@
+// 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.NodeAction = newaction
+ t.Add = newAdd
+ t.SetTitle = setTitle
+ t.SetLabel = setLabel
+ t.SetText = setText
+ t.AddText = addText
+ t.SetChecked = setChecked
+ t.ToolkitClose = toolkitClose
+ t.ShowTable = showTable
+
+ return t
+}