summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-04 01:57:59 -0600
committerJeff Carr <[email protected]>2025-03-04 01:57:59 -0600
commitf65d80862e9ef92ab8b36829342a6738cbc4b5d5 (patch)
treef8733a57b92c35d7d634e91a60aee98a549d6fa1
parentdcd32c255c4c4a7b31ebc2395a541704a753a092 (diff)
fyne changes to see if it can workv0.0.29v0.0.28
-rw-r--r--Makefile4
-rw-r--r--README.md15
-rw-r--r--action.go50
-rw-r--r--args.go4
-rw-r--r--fynetest.go3
-rw-r--r--main.go54
-rw-r--r--node.go63
-rw-r--r--plugin.go46
-rw-r--r--stdin.go2
-rw-r--r--structs.go8
-rw-r--r--treeInit.go18
11 files changed, 238 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index 5721c75..8b4220c 100644
--- a/Makefile
+++ b/Makefile
@@ -26,6 +26,10 @@ non-plugin:
go build -v -x
./fyne
+GO111-non-plugin:
+ GO111MODULE=off go build -v -x
+ ./fyne
+
check-git-clean:
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)
diff --git a/README.md b/README.md
index 018b9ce..e5fc023 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,18 @@
-# nogui
+# fyne
Package gui implements a abstraction layer for Go visual elements.
This is a sample plugin. It's a skeleton intended to be used when making a new toolkit plugin.
+
+fyne appears to require:
+ runtime.LockOSThread() // Ensure main stays on one OS thread
+ a := app.New()
+ w := a.NewWindow("Fyne Plugin Fix")
+ w.ShowAndRun()
+
+error:
+gui doing TestDraw() Forge: (this kinda works sometimes)
+panic: Run() or ShowAndRun() must be called from main goroutine
+
+so for fyne to work, there must be a protocol buffer GO GUI plugin first that
+can spawn and talk to fyne
diff --git a/action.go b/action.go
index 0bf52c7..8dd6a33 100644
--- a/action.go
+++ b/action.go
@@ -7,6 +7,8 @@ package main
*/
import (
+ "slices"
+
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
@@ -105,22 +107,54 @@ func addText(n *tree.Node, s string) {
// w.AddText(s)
}
-func enableWidget(n *tree.Node) {
+func setChecked(n *tree.Node, b bool) {
log.Info("do enable() here")
}
-func disableWidget(n *tree.Node) {
+func toolkitClose() {
log.Info("do enable() here")
}
-func setChecked(n *tree.Node, b bool) {
- log.Info("do enable() here")
+func showTable(t *guipb.Table) {
+ log.Info("gocui: should show table here")
+ if t == nil {
+ return
+ }
+ log.Info("gocui: table.Title", t.Title)
}
-func showTable(n *guipb.Table) {
- log.Info("do enable() here")
+func enableWidget(n *tree.Node) {
+ tk := n.TK.(*guiWidget)
+ tk.Enable()
}
-func toolkitClose() {
- log.Info("do enable() here")
+func disableWidget(n *tree.Node) {
+ tk := n.TK.(*guiWidget)
+ tk.Disable()
+}
+
+func showWidget(n *tree.Node) {
+ tk := n.TK.(*guiWidget)
+ tk.Show()
+}
+
+func hideWidget(n *tree.Node) {
+ tk := n.TK.(*guiWidget)
+ if n.WidgetType == widget.Window {
+ // tk.windowFrame.Hide()
+ // tk.hideWidgets()
+ }
+ tk.Hide()
+ tk.deleteWidget()
+}
+
+func (tk *guiWidget) deleteWidget() {
+ log.Info("gocui deleteWidget() looking for child to delete:", tk.cuiName)
+ p := tk.parent
+ for i, child := range p.children {
+ if tk == child {
+ log.Info("deleteWidget() found parent with child to delete:", i, child.cuiName)
+ p.children = slices.Delete(p.children, i, i+1)
+ }
+ }
}
diff --git a/args.go b/args.go
index 88fcf53..b25c85f 100644
--- a/args.go
+++ b/args.go
@@ -17,8 +17,8 @@ var WARN *log.LogFlag
var ERROR *log.LogFlag
func init() {
- full := "toolkit/nocui"
- short := "nocui"
+ full := "toolkit/fyne"
+ short := "fyne"
NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff")
INFO = log.NewFlag("INFO", true, full, short, "normal debugging stuff")
diff --git a/fynetest.go b/fynetest.go
index 8948948..371aaeb 100644
--- a/fynetest.go
+++ b/fynetest.go
@@ -9,6 +9,7 @@ import (
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
+ "go.wit.com/log"
)
var a fyne.App
@@ -16,6 +17,7 @@ var w fyne.Window
var w2 fyne.Window
func fynetest() {
+ log.Info("FYNE TEST START")
a = app.New()
w = a.NewWindow("Hello")
@@ -28,6 +30,7 @@ func fynetest() {
}),
))
+ log.Info("FYNE TEST SHOW")
w.Show()
// bobWindow()
diff --git a/main.go b/main.go
index 8328ad6..a22e99d 100644
--- a/main.go
+++ b/main.go
@@ -8,34 +8,36 @@ package main
*/
import (
+ "runtime"
+
+ "fyne.io/fyne/v2/app"
"go.wit.com/log"
)
var PLUGIN string = "fyne"
+func blah() {
+ fynetest()
+ a.Run()
+}
+
func initPlugin() {
log.Log(INFO, "Init()")
-
me.myTree = initTree()
- /*
- me.myTree.PluginName = "nocui"
- // me.myTree.ActionFromChannel = doAction
-
- me.myTree.NodeAction = newaction
- me.myTree.Add = Add
- me.myTree.SetTitle = SetTitle
- me.myTree.SetLabel = SetLabel
- me.myTree.SetText = SetText
- me.myTree.AddText = AddText
- */
me.exit = false
-
- log.Log(INFO, "Init() END")
-
showOptions()
go simpleStdin()
+ log.Log(INFO, "Init() FYNE END")
+ // blah()
+
+ me.myTree.InitOK()
+}
+
+func init() {
+ // fynetest()
+ // a.Run()
}
// this must be defined for plugin's, but is never run
@@ -44,3 +46,25 @@ func main() {
fynetest()
a.Run()
}
+
+// this is called at the very initial connection
+// between the app and this gocui plugin
+// this is a good place to initialize gocui's default behavior
+func toolkitInit() {
+ log.Log(INFO, "TOOLKIT Init()")
+
+ me.exit = false
+ showOptions()
+ log.Log(INFO, "TOOLKIT Init() END")
+
+ fynetest()
+ go a.Run()
+}
+
+func testmain() {
+ runtime.LockOSThread() // Ensure main stays on one OS thread
+ a := app.New()
+ w := a.NewWindow("Fyne Plugin Fix")
+ w.ShowAndRun()
+ // use w.QueueUpdate() to talk to fyne (?)
+}
diff --git a/node.go b/node.go
new file mode 100644
index 0000000..26e2efe
--- /dev/null
+++ b/node.go
@@ -0,0 +1,63 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "go.wit.com/widget"
+)
+
+func (tk *guiWidget) WidgetType() widget.WidgetType {
+ if tk.node == nil {
+ return widget.Label
+ }
+ return tk.node.WidgetType
+}
+
+func (tk *guiWidget) WidgetId() int {
+ return tk.node.WidgetId
+}
+
+func (tk *guiWidget) GetLabel() string {
+ return tk.node.GetLabel()
+}
+
+func (tk *guiWidget) IsEnabled() bool {
+ return tk.node.IsEnabled()
+}
+
+func (tk *guiWidget) Checked() bool {
+ return tk.node.State.Checked
+}
+
+func (tk *guiWidget) Hidden() bool {
+ if tk.node == nil {
+ return false
+ }
+ if tk.parent == nil {
+ return tk.node.Hidden()
+ }
+ if tk.parent.WidgetId() == 0 {
+ return tk.node.Hidden()
+ }
+ if tk.parent.Hidden() {
+ return true
+ }
+ return tk.node.Hidden()
+}
+
+func (tk *guiWidget) Direction() widget.Orientation {
+ return tk.node.State.Direction
+}
+
+func (tk *guiWidget) GridW() int {
+ return tk.node.State.AtW
+}
+
+func (tk *guiWidget) GridH() int {
+ return tk.node.State.AtH
+}
+
+func (tk *guiWidget) SetChecked(b bool) {
+ tk.node.State.Checked = b
+}
diff --git a/plugin.go b/plugin.go
new file mode 100644
index 0000000..7923d60
--- /dev/null
+++ b/plugin.go
@@ -0,0 +1,46 @@
+package main
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/widget"
+)
+
+func (tk *guiWidget) Show() {
+}
+
+func (tk *guiWidget) Hide() {
+}
+
+func (tk *guiWidget) Disable() {
+ if tk == nil {
+ log.Info("widget is nil")
+ return
+ }
+
+ switch tk.WidgetType() {
+ case widget.Box:
+ return
+ case widget.Button:
+ return
+ default:
+ log.Log(NOW, "fixme")
+ }
+}
+
+func (tk *guiWidget) Enable() {
+ if tk == nil {
+ log.Info("widget is nil")
+ return
+ }
+
+ switch tk.WidgetType() {
+ case widget.Box:
+ // hideDisable()
+ return
+ case widget.Button:
+ // tk.restoreEnableColor()
+ return
+ default:
+ log.Log(NOW, "fixme")
+ }
+}
diff --git a/stdin.go b/stdin.go
index df27e0a..9c92e73 100644
--- a/stdin.go
+++ b/stdin.go
@@ -33,7 +33,7 @@ func showOptions() {
func simpleStdin() {
defer func() {
if r := recover(); r != nil {
- log.Warn("nocui YAHOOOO Recovered in simpleStdin()", r)
+ log.Warn("fyne YAHOOOO Recovered in simpleStdin()", r)
log.Println("Recovered from panic:", r)
log.Println("Stack trace:")
debug.PrintStack()
diff --git a/structs.go b/structs.go
index d64389a..5704dd4 100644
--- a/structs.go
+++ b/structs.go
@@ -8,8 +8,12 @@ import (
// stores the raw toolkit internals
type guiWidget struct {
- Width int
- Height int
+ parent *guiWidget
+ children []*guiWidget
+ node *tree.Node // the pointer back to the tree
+ cuiName string
+ Width int
+ Height int
c int
val map[string]int
diff --git a/treeInit.go b/treeInit.go
index 78ff4fb..aa709a8 100644
--- a/treeInit.go
+++ b/treeInit.go
@@ -32,6 +32,9 @@ package main
*/
import (
+ "time"
+
+ log "go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
@@ -49,9 +52,20 @@ func Callback(guiCallback chan widget.Action) {
func PluginChannel() chan widget.Action {
initOnce.Do(initPlugin)
+ for {
+ if me.myTree != nil {
+ break
+ }
+ log.Info("me.myTree == nil")
+ time.Sleep(300 * time.Millisecond)
+ }
return me.myTree.PluginChannel()
}
+func FrozenChannel() chan widget.Action {
+ return me.myTree.FrozenChannel()
+}
+
func initTree() *tree.TreeInfo {
t := tree.New()
t.PluginName = PLUGIN
@@ -64,7 +78,11 @@ func initTree() *tree.TreeInfo {
t.Enable = enableWidget
t.Disable = disableWidget
+ t.Show = showWidget
+ t.Hide = hideWidget
+
t.SetChecked = setChecked
+ t.ToolkitInit = toolkitInit
t.ToolkitClose = toolkitClose
t.ShowTable = showTable