Compare commits

..

No commits in common. "guimaster" and "v0.20.0" have entirely different histories.

19 changed files with 274 additions and 283 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
*.swp *.swp
*.so
go.mod go.mod
go.sum go.sum
andlabs

View File

@ -1 +0,0 @@
// plugin

View File

@ -1,19 +1,10 @@
VERSION = $(shell git describe --tags) all: plugin
BUILDTIME = $(shell date +%Y.%m.%d)
all: clean goimports vet andlabs.so plugin:
GO111MODULE="off" go build -v -x -buildmode=plugin -o ../andlabs.so
andlabs.so: pluginreal:
GO111MODULE=off go build -v -x -buildmode=plugin -o andlabs.so \ go build -v -x -buildmode=plugin -o ~/go/lib/andlabs.so
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
install: clean
go build -v -buildmode=plugin -o ~/go/lib/andlabs-${VERSION}.so \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
cd ~/go/lib && ln -f -s andlabs-${VERSION}.so andlabs.so
clean:
rm -f andlabs andlabs.*so
goget: goget:
GO111MODULE="off" go get -v -t -u GO111MODULE="off" go get -v -t -u
@ -21,11 +12,6 @@ goget:
goimports: goimports:
goimports -w *.go goimports -w *.go
vet:
@GO111MODULE=off go vet
@echo this go plugin builds okay
redomod: redomod:
rm -f go.* rm -f go.*
goimports -w *.go goimports -w *.go

View File

@ -1,3 +0,0 @@
// TODO: make a fake 'plugin' channel of communication to andlabs for mswindows
// Windows doesn't support plugins. How can I keep andlabs and only compile it on windows?
// https://forum.heroiclabs.com/t/setting-up-goland-to-compile-plugins-on-windows/594/5

177
action.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"go.wit.com/dev/andlabs/ui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
@ -80,6 +81,7 @@ func ready(n *tree.Node) bool {
func hide(n *tree.Node) { func hide(n *tree.Node) {
show(n, false) show(n, false)
n.State.Hidden = true
} }
func show(n *tree.Node, b bool) { func show(n *tree.Node, b bool) {
@ -103,7 +105,7 @@ func show(n *tree.Node, b bool) {
} }
} }
func realEnable(n *tree.Node, b bool) { func enable(n *tree.Node, b bool) {
if !ready(n) { if !ready(n) {
return return
} }
@ -148,15 +150,6 @@ func pad(n *tree.Node, b bool) {
} }
} }
func showWidget(n *tree.Node) {
log.Info("not implemented in andlabs yet")
// widgetDelete(n)
}
func hideWidget(n *tree.Node) {
widgetDelete(n)
}
func widgetDelete(n *tree.Node) { func widgetDelete(n *tree.Node) {
log.Log(ANDLABS, "widgetDelete()", n.WidgetId, n.WidgetType) log.Log(ANDLABS, "widgetDelete()", n.WidgetId, n.WidgetType)
var tk *guiWidget var tk *guiWidget
@ -169,12 +162,124 @@ func widgetDelete(n *tree.Node) {
tk.uiWindow.Destroy() tk.uiWindow.Destroy()
tk.uiWindow = nil tk.uiWindow = nil
} }
// n.DeleteNode() n.DeleteNode()
} else { } else {
log.Log(ANDLABS, "DESTROY can't destroy TODO:", n.WidgetId, n.WidgetType) log.Log(ANDLABS, "DESTROY can't destroy TODO:", n.WidgetId, n.WidgetType)
} }
} }
/*
func processAction(a *widget.Action) {
log.Log(ANDLABS, "processAction() START a.ActionType =", a.ActionType, "a.Value", a.Value)
if a.ActionType == widget.ToolkitInit {
Init()
return
}
switch a.WidgetType {
case widget.Root:
if me.treeRoot == nil {
log.Log(INFO, "processAction() found the treeRoot")
me.treeRoot = me.myTree.AddNode(a)
} else {
log.Log(ERROR, "processAction() Something terrible has happened")
log.Log(ERROR, "processAction() treeNode was sent an action", a.ActionType, a)
}
return
}
log.Log(ANDLABS, "andlabs processAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId, a.ActionType)
switch a.WidgetType {
case widget.Flag:
log.Log(ERROR, "processAction() RE-IMPLEMENT LOG FLAGS")
return
}
if me.treeRoot == nil {
panic("me.treeRoot == nil")
}
if a.ActionType == widget.Add {
n := add(a)
// show(n, !a.State.Hidden)
if a.State.Hidden {
hide(n)
} else {
if a.State.Enable {
// nothing to do
} else {
enable(n, false)
}
}
// pad(n, n.State.Pad)
// expand(n, a.State.Expand)
return
}
n := me.treeRoot.FindWidgetId(a.WidgetId)
if n == nil {
if a.ActionType == widget.Delete {
// this is normal. the widget is aleady deleted
return
}
if a.WidgetType == widget.Window {
// this could happen maybe someday
log.Log(ANDLABS, "processAction() trying on nonexistant window", a.WidgetId, a.ActionType)
return
}
str := a.ActionType.String() + " id " + widget.GetString(a.WidgetId) + " " + a.WidgetType.String()
err := errors.New("andlabs processAction() findWidgetId got nil " + str)
log.Error(err, a.ActionType, a.WidgetType)
log.Log(WARN, "processAction() ERROR findWidgetId found nil for id =", a.WidgetId)
log.Log(WARN, "processAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
log.Log(WARN, "processAction() ERROR findWidgetId found nil for id =", a.WidgetId)
if WARN.Bool() {
me.treeRoot.ListWidgets()
}
return
panic("findWidgetId found nil for id = " + string(a.WidgetId))
}
if a.ActionType == widget.Dump {
log.Log(NOW, "processAction() Dump =", a.ActionType, a.WidgetType, n.State.ProgName)
return
}
switch a.ActionType {
case widget.Delete:
widgetDelete(n)
case widget.Show:
show(n, true)
case widget.Hide:
hide(n)
case widget.Enable:
enable(n, true)
case widget.Disable:
log.Log(ANDLABS, "andlabs got disable for", n.WidgetId, n.State.ProgName)
enable(n, false)
case widget.Checked:
setChecked(n, a.State.Checked)
case widget.Get:
setText(n, a)
case widget.GetText:
switch a.WidgetType {
case widget.Textbox:
a.Value = n.State.Value
}
case widget.Set:
setText(n, a)
case widget.SetText:
log.Log(ANDLABS, "andlabs SetText wid =", n.WidgetId, n.State.Value, a.State.Value)
setText(n, a)
case widget.AddText:
addText(n, a)
default:
log.Log(ERROR, "processAction() Unknown =", a.ActionType, a.WidgetType)
}
log.Log(INFO, "processAction() END =", a.ActionType, a.WidgetType)
}
*/
func SetTitle(n *tree.Node, s string) { func SetTitle(n *tree.Node, s string) {
SetText(n, s) SetText(n, s)
} }
@ -185,28 +290,66 @@ func SetLabel(n *tree.Node, s string) {
func SetText(n *tree.Node, s string) { func SetText(n *tree.Node, s string) {
if n == nil { if n == nil {
log.Log(WARN, "Tree Error: Add() sent n == nil") log.Warn("Tree Error: Add() sent n == nil")
return return
} }
if n.TK == nil { if n.TK == nil {
log.Log(WARN, "SetText() Tree sent an action on a widget we didn't seem to have.", n.WidgetId) log.Warn("Tree sent an action on a widget we didn't seem to have.")
return return
} }
setText(n, s) setText(n, s)
log.Log(ANDLABS, "SetText() (new)", n.WidgetType, n.String(), s) log.Info("SetText() (new)", n.WidgetType, n.String(), s)
} }
func AddText(n *tree.Node, s string) { func AddText(n *tree.Node, s string) {
if n == nil { if n == nil {
log.Log(WARN, "Tree Error: Add() sent n == nil") log.Warn("Tree Error: Add() sent n == nil")
return return
} }
if n.TK == nil { if n.TK == nil {
log.Log(WARN, "AddText() Tree sent an action on a widget we didn't seem to have.", n.WidgetId) log.Warn("Tree sent an action on a widget we didn't seem to have.")
return return
} }
log.Log(ANDLABS, "AddText()", n.WidgetType, n.String()) log.Info("AddText()", n.WidgetType, n.String())
// w := n.TK.(*guiWidget) // w := n.TK.(*guiWidget)
// w.AddText(s) // w.AddText(s)
addText(n, s) addText(n, s)
} }
func newAction(n *tree.Node, atype widget.ActionType) {
log.Log(INFO, "newaction() START", atype)
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
}
if n.TK == nil {
log.Warn("Tree sent an action on a widget we didn't seem to have.")
// do this init here again? Probably something
// went wrong and we should reset the our while gocui.View tree
n.TK = initWidget(n)
}
// w := n.TK.(*guiWidget)
switch atype {
case widget.Show:
log.Log(NOW, "Show() HERE. a.Hidden() was =", n.Hidden())
show(n, true)
case widget.Hide:
log.Log(NOW, "Hide() HERE. a.State.Hidden was =", n.Hidden())
hide(n)
case widget.Move:
log.Log(NOW, "attempt to move() =", atype, n.WidgetType, n.ProgName())
case widget.ToolkitClose:
log.Log(NOW, "attempting to Quit andlabs.ui")
// standardClose()
ui.Quit()
case widget.Enable:
enable(n, true)
case widget.Disable:
enable(n, false)
case widget.Delete:
widgetDelete(n)
default:
log.Log(ERROR, "newaction() UNHANDLED Action Type =", atype, "WidgetType =", n.WidgetType, "Name =", n.ProgName())
}
log.Log(INFO, "newaction() END", atype, n.String())
}

23
add.go
View File

@ -30,13 +30,13 @@ func add(n *tree.Node) {
newSlider(p, n) newSlider(p, n)
case widget.Dropdown: case widget.Dropdown:
newDropdown(p, n) newDropdown(p, n)
// setText(n, n.State.DefaultS) setText(n, n.State.DefaultS)
case widget.Combobox: case widget.Combobox:
newCombobox(p, n) newCombobox(p, n)
// setText(n, n.State.DefaultS) setText(n, n.State.DefaultS)
case widget.Textbox: case widget.Textbox:
newTextbox(p, n) newTextbox(p, n)
// setText(n, n.State.DefaultS) setText(n, n.State.DefaultS)
/* /*
case widget.Image: case widget.Image:
newImage(p, n) newImage(p, n)
@ -48,25 +48,18 @@ func add(n *tree.Node) {
func newAdd(n *tree.Node) { func newAdd(n *tree.Node) {
if n == nil { if n == nil {
log.Log(WARN, "Tree Error: Add() sent n == nil") log.Warn("Tree Error: Add() sent n == nil")
return return
} }
if n.WidgetType == widget.Root { if n.WidgetType == widget.Root {
me.treeRoot = n me.treeRoot = n
return return
} }
if me.treeRoot == nil {
panic("test")
}
add(n) add(n)
if n.TK == nil { if n.TK == nil {
if n.WidgetId == 1 || n.WidgetId == 2 { log.Warn("Tree sent an action on a widget we didn't seem to have.")
// this is normal at plugin init() time // do this init here again? Probably something
} else { // went wrong and we should reset the our while gocui.View tree
// this probably shouldn't be happening
log.Log(WARN, "newAdd() Tree sent an action on a widget we didn't seem to have.", n.WidgetId, n.WidgetType, n.ProgName())
}
// Probably something went wrong and we should reset / redraw everything?
n.TK = initWidget(n) n.TK = initWidget(n)
} }
// show(n, !a.State.Hidden) // show(n, !a.State.Hidden)
@ -76,7 +69,7 @@ func newAdd(n *tree.Node) {
if n.State.Enable { if n.State.Enable {
// nothing to do // nothing to do
} else { } else {
realEnable(n, false) enable(n, false)
} }
} }
} }

View File

@ -6,7 +6,10 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
func realAddText(n *tree.Node, s string) { func compareStrings(n *tree.Node, ss []string) {
}
func addText(n *tree.Node, s string) {
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
log.Log(ANDLABS, "addText() START with s =", s) log.Log(ANDLABS, "addText() START with s =", s)
@ -18,7 +21,19 @@ func realAddText(n *tree.Node, s string) {
switch n.WidgetType { switch n.WidgetType {
case widget.Dropdown: case widget.Dropdown:
for i, s := range n.State.Strings {
log.Log(ANDLABS, "n.State.Strings =", i, s)
_, ok := n.Strings[s]
// If the key exists
if ok {
log.Log(ANDLABS, "string is already in the dropdown", i, s)
} else {
log.Log(ANDLABS, "adding new string to dropdown", i, s)
addDropdownName(n, s) addDropdownName(n, s)
// TODO: make numbers
n.Strings[s] = 21
}
}
case widget.Combobox: case widget.Combobox:
addComboboxName(n, s) addComboboxName(n, s)
default: default:

View File

@ -34,7 +34,7 @@ func (t *guiWidget) checked() bool {
return t.uiCheckbox.Checked() return t.uiCheckbox.Checked()
} }
func realSetChecked(n *tree.Node, b bool) { func setChecked(n *tree.Node, b bool) {
if n.WidgetType != widget.Checkbox { if n.WidgetType != widget.Checkbox {
} }
var tk *guiWidget var tk *guiWidget

View File

@ -34,11 +34,11 @@ func newCombobox(p, n *tree.Node) {
log.Log(ANDLABS, "add combobox entries on create:", n.State.Strings) log.Log(ANDLABS, "add combobox entries on create:", n.State.Strings)
// add the initial combobox entries // add the initial combobox entries
for i, s := range n.State.Strings { for i, s := range n.State.Strings {
log.Log(ANDLABS, "add combobox entries on create progname:", n.GetProgName(), "State.Strings =", i, s) log.Log(ANDLABS, "add combobox entries on create", n.GetProgName(), i, s)
addComboboxName(n, s) addComboboxName(n, s)
} }
cur := n.CurrentS() cur := n.String()
log.Log(ANDLABS, "add combobox: set default value on create to", cur) log.Log(ANDLABS, "add combobox: set default value on create to", n.GetProgName(), cur)
setComboboxName(n, cur) setComboboxName(n, cur)
} }
@ -48,7 +48,7 @@ func addComboboxName(n *tree.Node, s string) {
} }
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
log.Log(ANDLABS, "addComboboxName()", n.WidgetId, "add:", s) log.Log(INFO, "addComboboxName()", n.WidgetId, "add:", s)
tk.uiEditableCombobox.Append(s) tk.uiEditableCombobox.Append(s)
if tk.val == nil { if tk.val == nil {
@ -59,7 +59,7 @@ func addComboboxName(n *tree.Node, s string) {
// If this is the first menu added, set the dropdown to it // If this is the first menu added, set the dropdown to it
if tk.c == 0 { if tk.c == 0 {
log.Log(ANDLABS, "addComboboxName() first string:", s) log.Log(INFO, "THIS IS THE FIRST combobox", s)
tk.uiEditableCombobox.SetText(s) tk.uiEditableCombobox.SetText(s)
} }
tk.c = tk.c + 1 tk.c = tk.c + 1
@ -71,7 +71,7 @@ func setComboboxName(n *tree.Node, s string) bool {
} }
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
log.Log(ANDLABS, "SetComboboxName()", n.WidgetId, ",", s) log.Log(INFO, "SetComboboxName()", n.WidgetId, ",", s)
tk.uiEditableCombobox.SetText(s) tk.uiEditableCombobox.SetText(s)
return false return false
} }

View File

@ -99,6 +99,6 @@ func setDropdownName(n *tree.Node, s string) bool {
return true return true
} }
} }
log.Log(WARN, "SetDropdownName() failed", s, n.WidgetId, n.GetProgName()) log.Warn("SetDropdownName() failed", s, n.WidgetId, n.GetProgName())
return false return false
} }

View File

@ -11,9 +11,11 @@ import (
var NOW *log.LogFlag var NOW *log.LogFlag
var INFO *log.LogFlag var INFO *log.LogFlag
var SPEW *log.LogFlag
var WARN *log.LogFlag var WARN *log.LogFlag
var ERROR *log.LogFlag var ERROR *log.LogFlag
var CHANGE *log.LogFlag
var ANDLABS *log.LogFlag var ANDLABS *log.LogFlag
func init() { func init() {
@ -23,7 +25,10 @@ func init() {
NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff") NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff")
INFO = log.NewFlag("INFO", false, full, short, "normal debugging stuff") INFO = log.NewFlag("INFO", false, full, short, "normal debugging stuff")
WARN = log.NewFlag("WARN", true, full, short, "bad things") WARN = log.NewFlag("WARN", false, full, short, "bad things")
SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff")
CHANGE = log.NewFlag("CHANGE", false, full, short, "show when the user does things")
full = "go.wit.com/gui" full = "go.wit.com/gui"
short = "andlabs" short = "andlabs"

View File

@ -1,36 +1,27 @@
// plugin
package main package main
import ( import (
"runtime/debug" "runtime/debug"
"sync" "sync"
"time"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget"
"go.wit.com/dev/andlabs/ui" "go.wit.com/dev/andlabs/ui"
// the _ means we only need this for the init() // the _ means we only need this for the init()
_ "go.wit.com/dev/andlabs/ui/winmanifest" _ "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 uiMainUndef bool = true
var uiMain sync.Once var uiMain sync.Once
var muAction sync.Mutex var muAction sync.Mutex
/* func queueAction(n *tree.Node, atype widget.ActionType) {
func newaction(n *tree.Node, atype widget.ActionType) {
ui.QueueMain(func() { ui.QueueMain(func() {
newAction(n, atype) newAction(n, atype)
}) })
} }
*/
func queueAdd(n *tree.Node) { func queueAdd(n *tree.Node) {
ui.QueueMain(func() { ui.QueueMain(func() {
@ -38,51 +29,27 @@ func queueAdd(n *tree.Node) {
}) })
} }
func enableWidget(n *tree.Node) { func queueSetTitle(n *tree.Node, s string) {
ui.QueueMain(func() {
realEnable(n, true)
})
}
func disableWidget(n *tree.Node) {
ui.QueueMain(func() {
realEnable(n, false)
})
}
func setTitle(n *tree.Node, s string) {
ui.QueueMain(func() { ui.QueueMain(func() {
SetText(n, s) SetText(n, s)
}) })
} }
func setLabel(n *tree.Node, s string) { func queueSetLabel(n *tree.Node, s string) {
ui.QueueMain(func() { ui.QueueMain(func() {
realSetText(n, s) SetText(n, s)
}) })
} }
func setText(n *tree.Node, s string) { func queueSetText(n *tree.Node, s string) {
ui.QueueMain(func() { ui.QueueMain(func() {
realSetText(n, s) SetText(n, s)
}) })
} }
func addText(n *tree.Node, s string) { func queueAddText(n *tree.Node, s string) {
ui.QueueMain(func() { ui.QueueMain(func() {
realAddText(n, s) AddText(n, s)
})
}
func setChecked(n *tree.Node, b bool) {
ui.QueueMain(func() {
realSetChecked(n, b)
})
}
func toolkitClose() {
ui.QueueMain(func() {
ui.Quit()
}) })
} }
@ -91,7 +58,7 @@ func queueMain(currentA widget.Action) {
// this never happends // this never happends
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Log("YAHOOOO Recovered in queueMain() application:", r) log.Warn("YAHOOOO Recovered in queueMain() application:", r)
log.Println("Recovered from panic:", r) log.Println("Recovered from panic:", r)
log.Println("Stack trace:") log.Println("Stack trace:")
debug.PrintStack() debug.PrintStack()
@ -114,37 +81,20 @@ func queueMain(currentA widget.Action) {
func guiMain() { func guiMain() {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Log(WARN, "YAHOO andlabs GUI recovered in guiMain()") log.Warn("YAHOOOO Recovered in guiMain application:", r)
log.Log(WARN, "Stack trace:") log.Warn("Recovered from panic:", r)
log.Warn("Stack trace:")
debug.PrintStack() debug.PrintStack()
log.Log(WARN, "Recovered from panic:", r)
log.Log(WARN, "andlabs GUI recovered in guiMain()")
log.Log(WARN, "YAHOO andlabs GUI recovered in guiMain()")
me.myTree.SendToolkitPanic() me.myTree.SendToolkitPanic()
return return
} }
}() }()
// TODO: THIS IS THE PROBLEM
ui.Main(func() { ui.Main(func() {
// this is a bad hack for now. // this is a bad hack for now.
// a better way would be to spawn ui.Main on the first actual window // a better way would be to spawn ui.Main on the first actual window
// that is supposed to be displayed // that is supposed to be displayed
if r := recover(); r != nil {
log.Log(WARN, "YAHOO andlabs GUI recovered in guiMain()")
log.Log(WARN, "Stack trace:")
debug.PrintStack()
log.Log(WARN, "Recovered from panic:", r)
log.Log(WARN, "andlabs GUI recovered in guiMain()")
log.Log(WARN, "YAHOO andlabs GUI recovered in guiMain()")
me.myTree.SendToolkitPanic()
return
}
time.Sleep(time.Second)
placeholderUI() placeholderUI()
me.myTree.InitOK()
// if nothing is working, run this instead to make // if nothing is working, run this instead to make
// sure you have something // sure you have something
// demoUI() // demoUI()
@ -152,21 +102,17 @@ func guiMain() {
} }
func Init() { func Init() {
log.Log(WARN, "Init() TODO: move init() to here") 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 // This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func initPlugin() { func init() {
log.Log(INFO, "Init() START") log.Log(INFO, "Init() START")
log.Log(INFO, "Init()") log.Log(INFO, "Init()")
// Can you pass values to a plugin init() ? Otherwise, there is no way to safely print // Can you pass values to a plugin init() ? Otherwise, there is no way to safely print
// log.Log(INFO, "init() Setting defaultBehavior = true") // log.Log(INFO, "init() Setting defaultBehavior = true")
// setDefaultBehavior(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 = tree.New()
me.myTree.PluginName = "andlabs" me.myTree.PluginName = "andlabs"
// me.myTree.ActionFromChannel = queueMain // me.myTree.ActionFromChannel = queueMain
@ -177,9 +123,6 @@ func initPlugin() {
me.myTree.SetLabel = queueSetLabel me.myTree.SetLabel = queueSetLabel
me.myTree.SetText = queueSetText me.myTree.SetText = queueSetText
me.myTree.AddText = queueAddText 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? // 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 // fake out the OS toolkit by making a fake window. This is probably needed for macos & windows

View File

@ -2,9 +2,6 @@ package main
import ( import (
// "os" // "os"
"os"
"go.wit.com/dev/andlabs/ui" "go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest" _ "go.wit.com/dev/andlabs/ui/winmanifest"
@ -41,16 +38,6 @@ import (
func place(p *tree.Node, n *tree.Node) bool { func place(p *tree.Node, n *tree.Node) bool {
log.Log(INFO, "place() 1 START", n.WidgetType, n.GetProgName(), n.GetLabel()) log.Log(INFO, "place() 1 START", n.WidgetType, n.GetProgName(), n.GetLabel())
if p == nil {
log.Log(WARN, "place() parent == nil")
os.Exit(-1)
return false
}
if n == nil {
log.Log(WARN, "place() node == nil")
os.Exit(-1)
return false
}
if !ready(n) { if !ready(n) {
if n.WidgetType == widget.Window { if n.WidgetType == widget.Window {
// TODO: figure out window in window placement // TODO: figure out window in window placement
@ -70,15 +57,13 @@ func place(p *tree.Node, n *tree.Node) bool {
log.Sleep(1) log.Sleep(1)
panic("ptk == nil") panic("ptk == nil")
} }
// p.DumpWidget("parent: ")
// n.DumpWidget("child: ")
// log.Log(WARN, "place() switch", p.WidgetType, n.WidgetId, n.GetProgName()) log.Log(INFO, "place() switch", p.WidgetType, n.WidgetId, n.GetProgName())
switch p.WidgetType { switch p.WidgetType {
case widget.Grid: case widget.Grid:
tk.gridX = n.State.GridOffset.X - 1 tk.gridX = n.State.GridOffset.X - 1
tk.gridY = n.State.GridOffset.Y - 1 tk.gridY = n.State.GridOffset.Y - 1
// log.Log(WARN, "place() on Grid at gridX,gridY", tk.gridX, tk.gridY) log.Log(INFO, "place() on Grid at gridX,gridY", tk.gridX, tk.gridY)
ptk.uiGrid.Append(tk.uiControl, ptk.uiGrid.Append(tk.uiControl,
tk.gridX, tk.gridY, 1, 1, tk.gridX, tk.gridY, 1, 1,
false, ui.AlignFill, false, ui.AlignFill) false, ui.AlignFill, false, ui.AlignFill)
@ -121,10 +106,6 @@ func place(p *tree.Node, n *tree.Node) bool {
return true return true
case widget.Window: case widget.Window:
log.Log(INFO, "Adding Something to Window", n.WidgetId, n.GetProgName()) log.Log(INFO, "Adding Something to Window", n.WidgetId, n.GetProgName())
if n.WidgetType == widget.Window {
log.Log(INFO, "TODO: make window in a window a tab", n.WidgetId, n.GetProgName())
return true
}
ptk.uiWindow.SetChild(tk.uiControl) ptk.uiWindow.SetChild(tk.uiControl)
return true return true
default: default:

View File

@ -6,20 +6,22 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
func realSetText(n *tree.Node, name string) { func setText(n *tree.Node, name string) {
// name := widget.GetString(a.Value) // name := widget.GetString(a.Value)
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
log.Log(ANDLABS, "setText() START with text =", name, n.WidgetType) log.Info("setText() START with text =", name, n.WidgetType)
log.Log(CHANGE, "setText() START with text =", name)
if tk == nil { if tk == nil {
log.Log(ERROR, "setText error. tk == nil", n.GetProgName(), n.WidgetId) log.Log(ERROR, "setText error. tk == nil", n.GetProgName(), n.WidgetId)
return return
} }
log.Log(CHANGE, "setText() Attempt on", n.WidgetType, "with", name)
switch n.WidgetType { switch n.WidgetType {
case widget.Window: case widget.Window:
log.Log(ANDLABS, "setText() Attempt to set the title to", name) log.Log(CHANGE, "setText() Attempt to set the title to", name)
tk.uiWindow.SetTitle(name) tk.uiWindow.SetTitle(name)
case widget.Tab: case widget.Tab:
case widget.Group: case widget.Group:
@ -27,7 +29,7 @@ func realSetText(n *tree.Node, name string) {
case widget.Checkbox: case widget.Checkbox:
tk.uiCheckbox.SetText(name) tk.uiCheckbox.SetText(name)
case widget.Textbox: case widget.Textbox:
log.Log(ANDLABS, "setText() on Textbox START with text =", name) log.Info("setText() on Textbox START with text =", name)
if tk.uiEntry != nil { if tk.uiEntry != nil {
tk.uiEntry.SetText(name) tk.uiEntry.SetText(name)
} }
@ -47,13 +49,13 @@ func realSetText(n *tree.Node, name string) {
var i int = -1 var i int = -1
var s string var s string
orig = tk.uiCombobox.Selected() orig = tk.uiCombobox.Selected()
log.Log(ANDLABS, "try to set the Dropdown to", name, "from", orig) log.Log(CHANGE, "try to set the Dropdown to", name, "from", orig)
// try to find the string // try to find the string
for i, s = range tk.val { for i, s = range tk.val {
log.Log(ANDLABS, "i, s", i, s) log.Log(CHANGE, "i, s", i, s)
if name == s { if name == s {
tk.uiCombobox.SetSelected(i) tk.uiCombobox.SetSelected(i)
log.Log(ANDLABS, "setText() Dropdown worked.", name) log.Log(CHANGE, "setText() Dropdown worked.", name)
return return
} }
} }
@ -71,5 +73,5 @@ func realSetText(n *tree.Node, name string) {
default: default:
log.Log(ERROR, "plugin Send() Don't know how to setText on", n.WidgetType, "yet") log.Log(ERROR, "plugin Send() Don't know how to setText on", n.WidgetType, "yet")
} }
log.Log(ANDLABS, "setText() END with name =") log.Log(CHANGE, "setText() END with name =")
} }

View File

@ -1,16 +1,12 @@
package main package main
import ( import (
"sync"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/dev/andlabs/ui" "go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest" _ "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' // It's probably a terrible idea to call this 'me'
var me config var me config

View File

@ -1,13 +0,0 @@
// 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/lib/protobuf/guipb"
"go.wit.com/log"
)
func showTable(t *guipb.Table) {
log.Info("should show table here")
}

31
tree.go Normal file
View File

@ -0,0 +1,31 @@
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()
}

View File

@ -1,79 +0,0 @@
// 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 FrozenChannel() chan widget.Action {
return me.myTree.FrozenChannel()
}
func initTree() *tree.TreeInfo {
t := tree.New()
t.PluginName = PLUGIN
t.Add = newAdd
t.SetTitle = setTitle
t.SetLabel = setLabel
t.SetText = setText
t.AddText = addText
t.Enable = enableWidget
t.Disable = disableWidget
t.Show = showWidget
t.Hide = hideWidget
t.SetChecked = setChecked
t.ToolkitClose = toolkitClose
t.ShowTable = showTable
return t
}

View File

@ -3,8 +3,6 @@ package main
import ( import (
"go.wit.com/dev/andlabs/ui" "go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest" _ "go.wit.com/dev/andlabs/ui/winmanifest"
"go.wit.com/log"
"go.wit.com/widget"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
) )
@ -26,20 +24,16 @@ func newWindow(p, n *tree.Node) {
win.SetBorderless(n.State.Borderless) win.SetBorderless(n.State.Borderless)
win.SetMargined(n.State.Pad) win.SetMargined(n.State.Pad)
win.OnClosing(func(*ui.Window) bool { win.OnClosing(func(*ui.Window) bool {
newt.uiWindow = nil // delete the local reference to the window // show(n, false)
me.myTree.SendWindowCloseEvent(n) me.myTree.SendWindowCloseEvent(n)
// n.DeleteNode() n.DeleteNode()
return true return true
}) })
newt.uiWindow = win newt.uiWindow = win
newt.uiControl = win newt.uiControl = win
n.TK = newt n.TK = newt
if p.WidgetType == widget.Window {
log.Log(WARN, "newWindow() TODO: make this window a tab")
} else {
place(p, n) place(p, n)
}
win.Show() win.Show()
return return
} }