works again

This commit is contained in:
Jeff Carr 2025-02-13 14:27:13 -06:00
parent 9babe64e41
commit 0c0c42ecbb
5 changed files with 108 additions and 51 deletions

View File

@ -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 \

53
main.go
View File

@ -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.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.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

View File

@ -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

31
tree.go
View File

@ -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()
}

69
treeInit.go Normal file
View File

@ -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
}