Compare commits

..

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

28 changed files with 322 additions and 479 deletions

5
.gitignore vendored
View File

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

View File

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

27
LICENSE
View File

@ -1,27 +0,0 @@
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,19 +1,7 @@
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:
GO111MODULE=off go build -v -x -buildmode=plugin -o 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 +9,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

169
action.go
View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"errors"
"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"
@ -12,26 +14,20 @@ import (
// and that there already a widget created // and that there already a widget created
func notNew(n *tree.Node) bool { func notNew(n *tree.Node) bool {
if n == nil { if n == nil {
log.Log(ERROR, "notNew() n = nil") log.Warn("ready() n = nil")
return true return true
} }
if n.TK != nil { if n.TK != nil {
log.Log(ERROR, "notNew() n.TK = nil", n.WidgetId, n.GetProgName()) log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName())
return true return true
} }
if n.Parent == nil { if n.Parent == nil {
log.Log(ERROR, "notNew() n.Parent = nil", n.WidgetId, n.GetProgName()) log.Warn("ready() n.Parent = nil", n.WidgetId, n.GetProgName())
return true return true
} }
if n.Parent.TK == nil { if n.Parent.TK == nil {
if n.Parent.WidgetId == 0 { log.Warn("ready() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
// this is normal if the widget type is a window log.Warn("ready() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
if n.WidgetType == widget.Window {
return true
}
}
log.Log(ERROR, "notNew() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "notNew() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
return true return true
} }
// this means you can add a new widgets // this means you can add a new widgets
@ -40,11 +36,11 @@ func notNew(n *tree.Node) bool {
func tkbad(n *tree.Node) bool { func tkbad(n *tree.Node) bool {
if n == nil { if n == nil {
log.Log(ERROR, "tkbad() n = nil") log.Warn("ready() n = nil")
return true return true
} }
if n.TK == nil { if n.TK == nil {
log.Log(ERROR, "tkbad() n.TK = nil", n.WidgetId, n.GetProgName()) log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName())
return true return true
} }
return false return false
@ -53,35 +49,25 @@ func tkbad(n *tree.Node) bool {
// this makes sure widget and it's parent exists // this makes sure widget and it's parent exists
func ready(n *tree.Node) bool { func ready(n *tree.Node) bool {
if n == nil { if n == nil {
log.Log(ERROR, "ready() n = nil") log.Warn("ready() n = nil")
return false return false
} }
if n.TK == nil { if n.TK == nil {
log.Log(ERROR, "ready() n.TK = nil", n.WidgetId, n.GetProgName()) log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName())
return false return false
} }
if n.Parent == nil { if n.Parent == nil {
log.Log(ERROR, "ready() n.Parent = nil", n.WidgetId, n.GetProgName()) log.Warn("ready() n.Parent = nil", n.WidgetId, n.GetProgName())
return false return false
} }
if n.Parent.TK == nil { if n.Parent.TK == nil {
if n.Parent.WidgetId == 0 { log.Warn("ready() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
// this is normal if the widget type is a window log.Warn("ready() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
if n.WidgetType == widget.Window {
return false
}
}
log.Log(ERROR, "ready() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
log.Log(ERROR, "ready() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
return false return false
} }
return true return true
} }
func hide(n *tree.Node) {
show(n, false)
}
func show(n *tree.Node, b bool) { func show(n *tree.Node, b bool) {
if tkbad(n) { if tkbad(n) {
return return
@ -103,12 +89,15 @@ func show(n *tree.Node, b bool) {
} }
} }
func realEnable(n *tree.Node, b bool) { func enable(n *tree.Node, b bool) {
if !ready(n) {
return
}
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
if n == nil {
panic("WHAT? enable was passed nil. How does this even happen?")
}
if tk == nil {
return
}
if tk.uiControl == nil { if tk.uiControl == nil {
return return
} }
@ -123,7 +112,7 @@ func pad(n *tree.Node, b bool) {
if tkbad(n) { if tkbad(n) {
return return
} }
log.Log(ANDLABS, "pad() on WidgetId =", n.WidgetId) log.Warn("pad() on WidgetId =", n.WidgetId)
t := n.TK.(*guiWidget) t := n.TK.(*guiWidget)
if t == nil { if t == nil {
@ -148,65 +137,105 @@ 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(NOW, "widgetDelete()", n.WidgetId)
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
if n.WidgetType == widget.Window { if n.WidgetType == widget.Window {
log.Log(ANDLABS, "DESTROY uiWindow here") log.Warn("DESTROY uiWindow here")
log.Log(ANDLABS, "DESTROY NEED TO REMOVE n from parent.Children") log.Warn("NEED TO REMOVE n from parent.Children")
if tk.uiWindow != nil { if tk.uiWindow != nil {
tk.uiWindow.Destroy() tk.uiWindow.Destroy()
tk.uiWindow = nil tk.uiWindow = nil
} }
// n.DeleteNode() n.DeleteNode()
}
}
func processAction(a *widget.Action) {
log.Warn("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 { } else {
log.Log(ANDLABS, "DESTROY can't destroy TODO:", n.WidgetId, n.WidgetType) log.Warn("processAction() Something terrible has happened")
log.Warn("processAction() treeNode was sent an action", a.ActionType, a)
} }
return
} }
func SetTitle(n *tree.Node, s string) { log.Warn("andlabs processAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId, a.ActionType)
SetText(n, s) switch a.WidgetType {
case widget.Flag:
log.Log(ERROR, "processAction() RE-IMPLEMENT LOG FLAGS")
return
} }
func SetLabel(n *tree.Node, s string) { if me.treeRoot == nil {
SetText(n, s) panic("me.treeRoot == nil")
} }
func SetText(n *tree.Node, s string) { if a.ActionType == widget.Add {
n := add(a)
show(n, n.State.Visable)
// pad(n, n.State.Pad)
// expand(n, a.State.Expand)
return
}
n := me.treeRoot.FindWidgetId(a.WidgetId)
if n == nil { if n == nil {
log.Log(WARN, "Tree Error: Add() sent n == nil") log.Error(errors.New("andlabs processAction() ERROR findWidgetId found nil"), a.ActionType, a.WidgetType)
log.Log(NOW, "processAction() ERROR findWidgetId found nil for id =", a.WidgetId)
log.Log(NOW, "processAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
log.Log(NOW, "processAction() ERROR findWidgetId found nil for id =", a.WidgetId)
me.treeRoot.ListWidgets()
return return
} panic("findWidgetId found nil for id = " + string(a.WidgetId))
if n.TK == nil {
log.Log(WARN, "SetText() Tree sent an action on a widget we didn't seem to have.", n.WidgetId)
return
}
setText(n, s)
log.Log(ANDLABS, "SetText() (new)", n.WidgetType, n.String(), s)
} }
func AddText(n *tree.Node, s string) { if a.ActionType == widget.Dump {
if n == nil { log.Log(NOW, "processAction() Dump =", a.ActionType, a.WidgetType, n.State.ProgName)
log.Log(WARN, "Tree Error: Add() sent n == nil")
return return
} }
if n.TK == nil {
log.Log(WARN, "AddText() Tree sent an action on a widget we didn't seem to have.", n.WidgetId) switch a.ActionType {
return case widget.Delete:
widgetDelete(n)
case widget.Show:
show(n, true)
case widget.Hide:
show(n, false)
case widget.Enable:
enable(n, true)
case widget.Disable:
log.Warn("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
} }
log.Log(ANDLABS, "AddText()", n.WidgetType, n.String()) case widget.Set:
// w := n.TK.(*guiWidget) setText(n, a)
// w.AddText(s) case widget.SetText:
addText(n, s) 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)
} }

55
add.go
View File

@ -6,12 +6,23 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
func add(n *tree.Node) { func add(a *widget.Action) *tree.Node {
log.Warn("andlabs add()", a.WidgetId, a.State.ProgName)
if a.WidgetType == widget.Root {
if me.treeRoot == nil {
me.treeRoot = me.myTree.AddNode(a)
}
return me.treeRoot
}
n := me.myTree.AddNode(a)
p := n.Parent p := n.Parent
switch n.WidgetType { switch n.WidgetType {
case widget.Window: case widget.Window:
log.Warn("SPEEDY Add window", n.WidgetId, n.GetProgName())
newWindow(p, n) newWindow(p, n)
case widget.Group: case widget.Group:
log.Warn("SPEEDY Add Group", n.WidgetId, n.GetProgName())
newGroup(p, n) newGroup(p, n)
case widget.Grid: case widget.Grid:
newGrid(n) newGrid(n)
@ -23,60 +34,22 @@ func add(n *tree.Node) {
newButton(p, n) newButton(p, n)
case widget.Checkbox: case widget.Checkbox:
newCheckbox(p, n) newCheckbox(p, n)
setChecked(n, n.State.Checked)
case widget.Spinner: case widget.Spinner:
newSpinner(p, n) newSpinner(p, n)
case widget.Slider: case widget.Slider:
newSlider(p, n) newSlider(p, n)
case widget.Dropdown: case widget.Dropdown:
newDropdown(p, n) newDropdown(p, n)
// setText(n, n.State.DefaultS)
case widget.Combobox: case widget.Combobox:
newCombobox(p, n) newCombobox(p, n)
// setText(n, n.State.DefaultS)
case widget.Textbox: case widget.Textbox:
newTextbox(p, n) newTextbox(p, n)
// setText(n, n.State.DefaultS)
/* /*
case widget.Image: case widget.Image:
newImage(p, n) newImage(p, n)
*/ */
default: default:
log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.ProgName()) log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.State.ProgName)
}
}
func newAdd(n *tree.Node) {
if n == nil {
log.Log(WARN, "Tree Error: Add() sent n == nil")
return
}
if n.WidgetType == widget.Root {
me.treeRoot = n
return
}
if me.treeRoot == nil {
panic("test")
}
add(n)
if n.TK == nil {
if n.WidgetId == 1 || n.WidgetId == 2 {
// this is normal at plugin init() time
} else {
// 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)
}
// show(n, !a.State.Hidden)
if n.Hidden() {
hide(n)
} else {
if n.State.Enable {
// nothing to do
} else {
realEnable(n, false)
}
} }
return n
} }

View File

@ -6,23 +6,39 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
func realAddText(n *tree.Node, s string) { func compareStrings(n *tree.Node, ss []string) {
}
// func (n *node) addText(a *widget.Action) {
func addText(n *tree.Node, a *widget.Action) {
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
log.Log(ANDLABS, "addText() START with s =", s) log.Warn("andlabs addText() START with a.Value =", a.Value)
if tk == nil { if tk == nil {
log.Log(ERROR, "addText error. tk == nil", n.State.ProgName, n.WidgetId) log.Log(ERROR, "addText error. tk == nil", n.State.ProgName, n.WidgetId)
return return
} }
log.Log(ANDLABS, "addText() Attempt on", n.WidgetType, "with", s) log.Warn("andlabs addText() Attempt on", n.WidgetType, "with", a.Value)
switch n.WidgetType { switch n.WidgetType {
case widget.Dropdown: case widget.Dropdown:
for i, s := range a.State.Strings {
log.Warn("andlabs a.State.Strings =", i, s)
_, ok := n.Strings[s]
// If the key exists
if ok {
log.Warn("andlabs a.State.Strings is here", i, s)
} else {
log.Warn("andlabs is not here", 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, widget.GetString(a.Value))
default: default:
log.Log(ERROR, "addText() doesn't work on", n.WidgetType) log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType)
} }
log.Log(ANDLABS, "addText() END with =", s) log.Log(CHANGE, "addText() END with a.Value =", a.Value)
} }

1
box.go
View File

@ -50,6 +50,7 @@ from all the nodes in the binary tree
TODO: handle user killing/closing a window using the OS TODO: handle user killing/closing a window using the OS
*/ */
// func (n *node) rawBox() *ui.Box {
func rawBox(n *tree.Node) *ui.Box { func rawBox(n *tree.Node) *ui.Box {
var box *ui.Box var box *ui.Box

View File

@ -7,6 +7,7 @@ import (
_ "go.wit.com/dev/andlabs/ui/winmanifest" _ "go.wit.com/dev/andlabs/ui/winmanifest"
) )
// func (p *node) newButton(n *node) {
func newButton(p *tree.Node, n *tree.Node) { func newButton(p *tree.Node, n *tree.Node) {
if notNew(n) { if notNew(n) {
return return

View File

@ -21,8 +21,8 @@ func newCheckbox(p *tree.Node, n *tree.Node) {
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) { newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
var b bool var b bool
b = newt.checked() b = newt.checked()
n.State.Checked = b n.SetValue(b)
log.Log(ANDLABS, "Checkbox is now =", b) log.Warn("Checkbox is now =", b)
me.myTree.SendUserEvent(n) me.myTree.SendUserEvent(n)
}) })
@ -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

@ -23,22 +23,24 @@ func newCombobox(p, n *tree.Node) {
newt.val = make(map[int]string) newt.val = make(map[int]string)
cb.OnChanged(func(spin *ui.EditableCombobox) { cb.OnChanged(func(spin *ui.EditableCombobox) {
n.State.CurrentS = spin.Text() n.SetValue(spin.Text())
log.Log(ANDLABS, "combobox changed ="+spin.Text()+".") log.Warn("combobox changed =" + spin.Text() + ".")
me.myTree.SendUserEvent(n) me.myTree.SendUserEvent(n)
}) })
n.TK = newt n.TK = newt
place(p, n) place(p, n)
log.Log(ANDLABS, "add combobox entries on create:", n.State.Strings) log.Warn("add combobox entries on create:", n.State.Strings)
log.Warn("add combobox entries on create:", n.State.Strings)
log.Warn("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.Warn("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.Warn("add combobox: TODO: set default value on create", n.GetProgName(), cur)
setComboboxName(n, cur) setComboboxName(n, cur)
} }
@ -48,7 +50,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 +61,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 +73,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

@ -27,9 +27,9 @@ func newDropdown(p, n *tree.Node) {
i := spin.Selected() i := spin.Selected()
if newt.val == nil { if newt.val == nil {
log.Log(ERROR, "make map didn't work") log.Log(ERROR, "make map didn't work")
n.State.CurrentS = "map did not work. ui.Combobox error" n.SetValue("map did not work. ui.Combobox error")
} else { } else {
n.State.CurrentS = newt.val[i] n.SetValue(newt.val[i])
} }
me.myTree.SendUserEvent(n) me.myTree.SendUserEvent(n)
}) })
@ -37,17 +37,19 @@ func newDropdown(p, n *tree.Node) {
n.TK = newt n.TK = newt
place(p, n) place(p, n)
log.Log(ANDLABS, "add dropdown entries on create:", n.State.Strings) log.Warn("add dropdown entries on create:", n.State.Strings)
log.Warn("add dropdown entries on create:", n.State.Strings)
log.Warn("add dropdown entries on create:", n.State.Strings)
if n.State.Strings == nil { if n.State.Strings == nil {
return return
} }
// add the initial dropdown entries // add the initial dropdown entries
for i, s := range n.State.Strings { for i, s := range n.State.Strings {
log.Log(ANDLABS, "add dropdown: add entries on create", n.GetProgName(), i, s) log.Warn("add dropdown: add entries on create", n.GetProgName(), i, s)
addDropdownName(n, s) addDropdownName(n, s)
} }
cur := n.String() cur := n.String()
log.Log(ANDLABS, "add dropdown: set default value on create", n.GetProgName(), cur) log.Warn("add dropdown: set default value on create", n.GetProgName(), cur)
setDropdownName(n, cur) setDropdownName(n, cur)
} }
@ -93,12 +95,12 @@ func setDropdownName(n *tree.Node, s string) bool {
for i, tmp := range tk.val { for i, tmp := range tk.val {
if s == tmp { if s == tmp {
n.State.CurrentS = s n.SetValue(s)
setDropdownInt(n, i) setDropdownInt(n, i)
log.Log(ANDLABS, "SetDropdownInt() worked", tmp, i) log.Warn("SetDropdownInt() worked", tmp, i)
return true return true
} }
} }
log.Log(WARN, "SetDropdownName() failed", s, n.WidgetId, n.GetProgName()) log.Warn("SetDropdownName() failed", s)
return false return false
} }

12
go.mod Normal file
View File

@ -0,0 +1,12 @@
module go.wit.com/toolkits/andlabs
go 1.21.4
require (
go.wit.com/dev/andlabs/ui v0.0.1
go.wit.com/log v0.5.5
go.wit.com/toolkits/tree v0.0.5
go.wit.com/widget v1.1.6
)
require go.wit.com/dev/davecgh/spew v1.1.4 // indirect

10
go.sum Normal file
View File

@ -0,0 +1,10 @@
go.wit.com/dev/andlabs/ui v0.0.1 h1:SowOybLBu/qUOqp905EZikz5/iPa3GpmnCAPzNOYajM=
go.wit.com/dev/andlabs/ui v0.0.1/go.mod h1:mlKEEe05ZJURzjh1LtjzdGMHVbJm9a7BUaVpA9cHxsM=
go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek=
go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
go.wit.com/log v0.5.5 h1:bK3b94uVKgev4jB5wg06FnvCFBEapQICTSH2YW+CWr4=
go.wit.com/log v0.5.5/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=
go.wit.com/toolkits/tree v0.0.5 h1:weWlg58OSPtEOOD40G1P5CJ5nNJIYfJ6vMuJb8sGzUE=
go.wit.com/toolkits/tree v0.0.5/go.mod h1:n4F2seonm1aYMml+YGOpCqWo0bkFwT/RH834J6f5/iE=
go.wit.com/widget v1.1.6 h1:av2miF5vlohMfARA/QGPTPfgW/ADup1c+oeAOKgroPY=
go.wit.com/widget v1.1.6/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ=

View File

@ -11,10 +11,12 @@ 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 ANDLABS *log.LogFlag var CHANGE *log.LogFlag
var TOOLKIT *log.LogFlag
func init() { func init() {
full := "go.wit.com/toolkits/andlabs" full := "go.wit.com/toolkits/andlabs"
@ -24,9 +26,9 @@ func init() {
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", true, full, short, "bad things")
SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff")
full = "go.wit.com/gui" ERROR = log.NewFlag("ERROR", false, full, short, "toolkit errors")
short = "andlabs" CHANGE = log.NewFlag("ERROR", false, full, short, "show when the user does things")
ERROR = log.NewFlag("ERROR", false, full, short, "andlab toolkit errors") TOOLKIT = log.NewFlag("ERROR", false, full, short, "andlabs specific stuff")
ANDLABS = log.NewFlag("ANDLABS", false, full, short, "andlabs specific stuff")
} }

View File

@ -1,4 +1,3 @@
// plugin
package main package main
import ( import (
@ -7,115 +6,48 @@ import (
"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 newaction(n *tree.Node, atype widget.ActionType) {
ui.QueueMain(func() {
newAction(n, atype)
})
}
*/
func queueAdd(n *tree.Node) {
ui.QueueMain(func() {
newAdd(n)
})
}
func enableWidget(n *tree.Node) {
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() {
SetText(n, s)
})
}
func setLabel(n *tree.Node, s string) {
ui.QueueMain(func() {
realSetText(n, s)
})
}
func setText(n *tree.Node, s string) {
ui.QueueMain(func() {
realSetText(n, s)
})
}
func addText(n *tree.Node, s string) {
ui.QueueMain(func() {
realAddText(n, s)
})
}
func setChecked(n *tree.Node, b bool) {
ui.QueueMain(func() {
realSetChecked(n, b)
})
}
func toolkitClose() {
ui.QueueMain(func() {
ui.Quit()
})
}
/*
func queueMain(currentA widget.Action) { 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()
me.myTree.SendToolkitPanic() me.myTree.SendToolkitPanic()
} }
}() }()
*/
// andlabs puts this inside the gofunction over there // andlabs puts this inside the gofunction over there
// probably this should be changed around here // probably this should be changed around here
// and only andlabs stuff should be sent there? // and only andlabs stuff should be sent there?
// it's easier to code it this way however // it's easier to code it this way however
// also, if it dies here, it get's caught // also, if it dies here, it get's caught
// usually, this is where it dies // usually, this is where it dies
log.Log(ANDLABS, "about to send action into the andlabs ui.QueueMain()") log.Warn("about to send action into the andlabs ui.QueueMain()")
ui.QueueMain(func() { ui.QueueMain(func() {
processAction(&currentA) processAction(&currentA)
}) })
} }
*/
func guiMain() { func guiMain() {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Log(WARN, "YAHOOOO Recovered in guiMain application:", r) log.Warn("YAHOOOO Recovered in guiMain application:", r)
log.Log(WARN, "Recovered from panic:", r) log.Println("Recovered from panic:", r)
log.Log(WARN, "Stack trace:") log.Println("Stack trace:")
debug.PrintStack() debug.PrintStack()
me.myTree.SendToolkitPanic() me.myTree.SendToolkitPanic()
return return
@ -127,8 +59,6 @@ func guiMain() {
// that is supposed to be displayed // that is supposed to be displayed
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()
@ -136,34 +66,20 @@ 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
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? // 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"
@ -40,53 +37,41 @@ import (
// ----------------------------- // -----------------------------
func place(p *tree.Node, n *tree.Node) bool { func place(p *tree.Node, n *tree.Node) bool {
log.Warn("SPEEDY newplace() 1 START", n.WidgetId, n.GetProgName(), n.GetLabel(), n.String())
log.Warn("SPEEDY newplace() n.State.Strings =", n.State.Strings)
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 { log.Warn("place() 1 START not ready()")
// TODO: figure out window in window placement
return true
}
log.Log(ERROR, "place() 1 START not ready()", n.WidgetType, n.GetProgName(), n.GetLabel())
return false return false
} }
log.Log(INFO, "place() 1 START ready()")
var tk, ptk *guiWidget var tk, ptk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
ptk = p.TK.(*guiWidget) ptk = p.TK.(*guiWidget)
log.Warn("SPEEDY newplace() 2 START", n.WidgetId, n.GetProgName(), n.GetLabel())
if ptk == nil { if ptk == nil {
log.Log(ERROR, "ptk == nil", p.GetProgName(), p.ParentId, p.WidgetType, ptk) log.Log(ERROR, "ptk == nil", p.GetProgName(), p.ParentId, p.WidgetType, ptk)
log.Log(ERROR, "n = ", n.GetProgName(), n.ParentId, n.WidgetType, tk) log.Log(ERROR, "n = ", n.GetProgName(), n.ParentId, n.WidgetType, tk)
log.Log(ERROR, "SPEEDY ptk == nil", n.WidgetId, n.GetProgName()) log.Warn("SPEEDY ptk == nil", n.WidgetId, n.GetProgName())
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)
log.Warn("SPEEDY newplace() before switch", 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.Warn("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)
return true return true
case widget.Group: case widget.Group:
if ptk.uiBox == nil { if ptk.uiBox == nil {
log.Log(ANDLABS, "place() andlabs hack group to use add a box", n.GetProgName(), n.WidgetType) log.Log(WARN, "place() andlabs hack group to use add a box", n.GetProgName(), n.WidgetType)
n.State.Direction = widget.Vertical
ptk.uiBox = rawBox(n) ptk.uiBox = rawBox(n)
ptk.uiGroup.SetChild(ptk.uiBox) ptk.uiGroup.SetChild(ptk.uiBox)
} }
@ -106,10 +91,14 @@ func place(p *tree.Node, n *tree.Node) bool {
panic("tk.uiControl == nil") panic("tk.uiControl == nil")
} }
log.Log(ERROR, "CHECK LOGIC ON THIS. APPENDING directly into a window without a tab") log.Log(ERROR, "CHECK LOGIC ON THIS. APPENDING directly into a window without a tab")
ptk.uiTab.Append(n.State.Label, tk.uiControl) // log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() node=", n.WidgetId, n.GetProgName(), n.Text, n.WidgetType)
// log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() on parent=", p.WidgetId, p.GetProgName(), p.Text, p.WidgetType)
// panic("tk.uiControl == nil")
ptk.uiTab.Append(widget.GetString(n.State.Value), tk.uiControl)
ptk.boxC += 1 ptk.boxC += 1
return true return true
case widget.Box: case widget.Box:
log.Warn("SPEEDY Add Something to Box", n.WidgetId, n.GetProgName())
log.Log(INFO, "place() uiBox =", ptk.uiBox) log.Log(INFO, "place() uiBox =", ptk.uiBox)
log.Log(INFO, "place() uiControl =", tk.uiControl) log.Log(INFO, "place() uiControl =", tk.uiControl)
if n.WidgetType == widget.Textbox { if n.WidgetType == widget.Textbox {
@ -120,16 +109,12 @@ func place(p *tree.Node, n *tree.Node) bool {
ptk.boxC += 1 ptk.boxC += 1
return true return true
case widget.Window: case widget.Window:
log.Log(INFO, "Adding Something to Window", n.WidgetId, n.GetProgName()) log.Warn("SPEEDY Add 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:
log.Log(ERROR, "place() how? Parent =", p.WidgetId, p.WidgetType) log.Log(ERROR, "place() how? Parent =", p.WidgetId, p.WidgetType)
} }
log.Log(ERROR, "newplace() returned without doing anything", n.WidgetId, n.GetProgName()) log.Warn("SPEEDY newplace() return", n.WidgetId, n.GetProgName())
return false return false
} }

View File

@ -6,20 +6,22 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
func realSetText(n *tree.Node, name string) { // func (n *node) setText(a *widget.Action) {
// name := widget.GetString(a.Value) func setText(n *tree.Node, a *widget.Action) {
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.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.Warn("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,6 @@ 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)
if tk.uiEntry != nil { if tk.uiEntry != nil {
tk.uiEntry.SetText(name) tk.uiEntry.SetText(name)
} }
@ -39,21 +40,21 @@ func realSetText(n *tree.Node, name string) {
case widget.Button: case widget.Button:
tk.uiButton.SetText(name) tk.uiButton.SetText(name)
case widget.Slider: case widget.Slider:
log.Log(ERROR, "setText() on slider unknown", n.GetProgName()) log.Log(ERROR, "setText() on slider unknown", a.ActionType, "on checkbox", n.GetProgName())
case widget.Spinner: case widget.Spinner:
log.Log(ERROR, "setText() on spinner unknown", n.GetProgName()) log.Log(ERROR, "setText() on spinner unknown", a.ActionType, "on checkbox", n.GetProgName())
case widget.Dropdown: case widget.Dropdown:
var orig int var orig int
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
} }
} }
@ -69,7 +70,7 @@ func realSetText(n *tree.Node, name string) {
case widget.Combobox: case widget.Combobox:
tk.uiEditableCombobox.SetText(name) tk.uiEditableCombobox.SetText(name)
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", a.ActionType)
} }
log.Log(ANDLABS, "setText() END with name =") log.Log(CHANGE, "setText() END with name =")
} }

View File

@ -22,7 +22,7 @@ func newSlider(p, n *tree.Node) {
newt.uiControl = s newt.uiControl = s
s.OnChanged(func(spin *ui.Slider) { s.OnChanged(func(spin *ui.Slider) {
n.State.CurrentI = newt.uiSlider.Value() n.SetValue(newt.uiSlider.Value())
me.myTree.SendUserEvent(n) me.myTree.SendUserEvent(n)
}) })

View File

@ -18,7 +18,7 @@ func newSpinner(p, n *tree.Node) {
newt.uiControl = s newt.uiControl = s
s.OnChanged(func(s *ui.Spinbox) { s.OnChanged(func(s *ui.Spinbox) {
n.State.CurrentI = newt.uiSpinbox.Value() n.SetValue(newt.uiSpinbox.Value())
me.myTree.SendUserEvent(n) me.myTree.SendUserEvent(n)
}) })

View File

@ -1,15 +1,15 @@
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 // var andlabs map[int]*andlabsT
// var callback func(int) bool
// var callback chan toolkit.Action
// 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

20
tab.go
View File

@ -32,16 +32,16 @@ func (p *node) newTab(n *node) {
} }
t := p.tk t := p.tk
log.Log(ANDLABS, "newTab() START", n.WidgetId, n.ParentId) log.Log(TOOLKIT, "newTab() START", n.WidgetId, n.ParentId)
if t.uiTab == nil { if t.uiTab == nil {
// this means you have to make a new tab // this means you have to make a new tab
log.Log(ANDLABS, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId) log.Log(TOOLKIT, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId)
newt = rawTab(t.uiWindow, widget.GetString(n.value)) newt = rawTab(t.uiWindow, widget.GetString(n.value))
t.uiTab = newt.uiTab t.uiTab = newt.uiTab
} else { } else {
// this means you have to append a tab // this means you have to append a tab
log.Log(ANDLABS, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId) log.Log(TOOLKIT, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId)
if n.WidgetType == widget.Tab { if n.WidgetType == widget.Tab {
// andlabs doesn't have multiple tab widgets so make a fake one? // andlabs doesn't have multiple tab widgets so make a fake one?
// this makes a guiWidget internal structure with the parent values // this makes a guiWidget internal structure with the parent values
@ -63,16 +63,18 @@ func (p *node) newTab(n *node) {
func tabSetMargined(tab *ui.Tab, b bool) { func tabSetMargined(tab *ui.Tab, b bool) {
c := tab.NumPages() c := tab.NumPages()
for i := 0; i < c; i++ { for i := 0; i < c; i++ {
log.Log(ANDLABS, "SetMargined", i, b) log.Log(TOOLKIT, "SetMargined", i, b)
tab.SetMargined(i, b) tab.SetMargined(i, b)
} }
} }
func rawTab(w *ui.Window, name string) *guiWidget { func rawTab(w *ui.Window, name string) *guiWidget {
var newt guiWidget var newt guiWidget
log.Log(ANDLABS, "rawTab() START", name) log.Log(TOOLKIT, "rawTab() START", name)
if w == nil { if w == nil {
log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window") log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
// sleep(1) // sleep(1)
return nil return nil
@ -82,20 +84,20 @@ func rawTab(w *ui.Window, name string) *guiWidget {
w.SetChild(tab) w.SetChild(tab)
newt.uiTab = tab newt.uiTab = tab
newt.uiControl = tab newt.uiControl = tab
log.Log(ANDLABS, "rawTab() END", name) log.Log(TOOLKIT, "rawTab() END", name)
return &newt return &newt
} }
/* /*
func (t *guiWidget) appendTab(name string) *guiWidget { func (t *guiWidget) appendTab(name string) *guiWidget {
var newT guiWidget var newT guiWidget
log.Log(ANDLABS, "appendTab() ADD", name) log.Log(TOOLKIT, "appendTab() ADD", name)
if t.uiTab == nil { if t.uiTab == nil {
log.Log(ANDLABS, "UiWindow == nil. I can't add a widget without a place to put it") log.Log(TOOLKIT, "UiWindow == nil. I can't add a widget without a place to put it")
panic("should never have happened. wit/gui/toolkit has ui.Tab == nil") panic("should never have happened. wit/gui/toolkit has ui.Tab == nil")
} }
log.Log(ANDLABS, "appendTab() START name =", name) log.Log(TOOLKIT, "appendTab() START name =", name)
var hbox *ui.Box var hbox *ui.Box
if defaultBehavior { if defaultBehavior {

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")
}

View File

@ -17,20 +17,18 @@ func newTextbox(p, n *tree.Node) {
e := ui.NewEntry() e := ui.NewEntry()
newt.uiEntry = e newt.uiEntry = e
newt.uiControl = e newt.uiControl = e
newt.uiEntry.SetText(n.State.DefaultS)
e.OnChanged(func(spin *ui.Entry) { e.OnChanged(func(spin *ui.Entry) {
n.State.CurrentS = spin.Text() n.SetValue(spin.Text())
me.myTree.SendUserEvent(n) me.myTree.SendUserEvent(n)
}) })
} else { } else {
e := ui.NewNonWrappingMultilineEntry() e := ui.NewNonWrappingMultilineEntry()
newt.uiMultilineEntry = e newt.uiMultilineEntry = e
newt.uiControl = e newt.uiControl = e
newt.uiMultilineEntry.SetText(n.State.DefaultS)
e.OnChanged(func(spin *ui.MultilineEntry) { e.OnChanged(func(spin *ui.MultilineEntry) {
n.State.CurrentS = spin.Text() n.SetValue(spin.Text())
me.myTree.SendUserEvent(n) me.myTree.SendUserEvent(n)
}) })
} }

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"
) )
@ -22,24 +20,33 @@ func newWindow(p, n *tree.Node) {
newt = new(guiWidget) newt = new(guiWidget)
// bool == false is if the OS defined border on the window should be used // bool == false is if the OS defined border on the window should be used
win := ui.NewWindow(n.GetProgName(), 40, 40, n.State.Borderless) win := ui.NewWindow(n.GetProgName(), 640, 480, n.State.Borderless)
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
} }
/*
func (n *node) SetWindowTitle(title string) {
log.Log(CHANGE, "toolkit NewWindow", widget.GetString(n.value), "title", title)
win := n.tk.uiWindow
if win == nil {
log.Log(ERROR, "Error: no window", n.WidgetId)
} else {
win.SetTitle(title)
log.Log(CHANGE, "Setting the window title", title)
}
}
*/