starting to try safe chan and goroutines
fix tab title's right before attempting to add chan goroutines removed "where" widget pointer box added to tab experiement with log as it's own repo Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
fa356841bf
commit
4ae2022600
|
@ -107,42 +107,6 @@ external things which might be useful
|
||||||
* [GO Style Guide]
|
* [GO Style Guide]
|
||||||
```
|
```
|
||||||
|
|
||||||
version v1.3
|
|
||||||
|
|
||||||
I like things to be easy.
|
|
||||||
|
|
||||||
this means all the log settings are in one place. it should allow
|
|
||||||
things to be over-ridden externally to the library
|
|
||||||
but still allow command line --args to pass debugging settings
|
|
||||||
|
|
||||||
## I also have a generic sleep() and exit() in here because it's simple
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
|
|
||||||
log("something", foo, bar)
|
|
||||||
var DEBUG bool = true
|
|
||||||
log(DEBUG, "something else", someOtherVariable) # if DEBUG == false, return doing nothing
|
|
||||||
log(SPEW, "something else", someOtherVariable) # this get's sent to spew.Dump(). Very useful for debugging!
|
|
||||||
|
|
||||||
## Variables
|
|
||||||
|
|
||||||
```golang
|
|
||||||
var INFO bool
|
|
||||||
```
|
|
||||||
|
|
||||||
```golang
|
|
||||||
var LOGOFF bool = false // turn this off, all logging stops
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
```golang
|
|
||||||
var SPEW spewt
|
|
||||||
```
|
|
||||||
|
|
||||||
```golang
|
|
||||||
var WARN bool
|
|
||||||
```
|
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
### func [DebugWidgetWindow](/debugWidget.go#L52)
|
### func [DebugWidgetWindow](/debugWidget.go#L52)
|
||||||
|
@ -293,6 +257,8 @@ You get a window
|
||||||
|
|
||||||
## Sub Packages
|
## Sub Packages
|
||||||
|
|
||||||
|
* [log](./log)
|
||||||
|
|
||||||
* [toolkit](./toolkit)
|
* [toolkit](./toolkit)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
@ -6,11 +6,14 @@ func (n *Node) NewButton(name string, custom func()) *Node {
|
||||||
newNode := n.New(name, toolkit.Button, custom)
|
newNode := n.New(name, toolkit.Button, custom)
|
||||||
|
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
|
a.Title = name
|
||||||
a.Type = toolkit.Add
|
a.Type = toolkit.Add
|
||||||
// a.Widget = &newNode.widget
|
a.Callback = callback
|
||||||
// a.Where = &n.widget
|
|
||||||
// action(&a)
|
|
||||||
newaction(&a, newNode, n)
|
newaction(&a, newNode, n)
|
||||||
|
|
||||||
return newNode
|
return newNode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func callback(i int) {
|
||||||
|
log(debugError, "button callback() i =", i)
|
||||||
|
}
|
||||||
|
|
1
chan.go
1
chan.go
|
@ -22,6 +22,7 @@ func makeConc() {
|
||||||
func startTheThing(wg *conc.WaitGroup) {
|
func startTheThing(wg *conc.WaitGroup) {
|
||||||
wg.Go(func() {
|
wg.Go(func() {
|
||||||
log(debugNow, "startTheThing()")
|
log(debugNow, "startTheThing()")
|
||||||
|
panic("test conc.WaitGroup")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,10 @@ func addDemoTab(window *gui.Node, title string) {
|
||||||
dd.AddDropdownName("more 2")
|
dd.AddDropdownName("more 2")
|
||||||
dd.AddDropdownName("more 3")
|
dd.AddDropdownName("more 3")
|
||||||
|
|
||||||
g.SetNext(3,1)
|
// g.SetNext(3,1)
|
||||||
g1.NewLabel("label (3,1)")
|
// g1.NewLabel("label (3,1)")
|
||||||
g.SetNext(3,2)
|
// g.SetNext(3,2)
|
||||||
g1.NewLabel("label (3,2)")
|
// g1.NewLabel("label (3,2)")
|
||||||
|
|
||||||
g2 := newNode.NewGroup("group 2")
|
g2 := newNode.NewGroup("group 2")
|
||||||
tb := g2.NewTextbox("tb")
|
tb := g2.NewTextbox("tb")
|
||||||
|
|
|
@ -188,8 +188,7 @@ func (n *Node) debugAddWidgetButtons() {
|
||||||
n.NewButton("Dropdown", func () {
|
n.NewButton("Dropdown", func () {
|
||||||
a := activeWidget.NewDropdown("tmp dropdown")
|
a := activeWidget.NewDropdown("tmp dropdown")
|
||||||
a.AddText("this is better than tcl/tk")
|
a.AddText("this is better than tcl/tk")
|
||||||
a.AddText("make something for tim")
|
a.AddText("make something for tim for qflow")
|
||||||
a.AddText("for qflow")
|
|
||||||
a.AddText("and for riscv")
|
a.AddText("and for riscv")
|
||||||
a.Custom = func () {
|
a.Custom = func () {
|
||||||
log("custom dropdown() a =", a.widget.Name, a.widget.S, "id=", a.id)
|
log("custom dropdown() a =", a.widget.Name, a.widget.S, "id=", a.id)
|
||||||
|
@ -198,7 +197,7 @@ func (n *Node) debugAddWidgetButtons() {
|
||||||
n.NewButton("Combobox", func () {
|
n.NewButton("Combobox", func () {
|
||||||
a := activeWidget.NewCombobox("tmp combobox")
|
a := activeWidget.NewCombobox("tmp combobox")
|
||||||
a.AddText("mirrors.wit.com")
|
a.AddText("mirrors.wit.com")
|
||||||
a.AddText("go.wit.org")
|
a.AddText("go.wit.com")
|
||||||
a.Custom = func () {
|
a.Custom = func () {
|
||||||
log("custom combobox() a =", a.widget.Name, a.widget.S, "id=", a.id)
|
log("custom combobox() a =", a.widget.Name, a.widget.S, "id=", a.id)
|
||||||
}
|
}
|
||||||
|
@ -213,12 +212,14 @@ func (n *Node) debugAddWidgetButtons() {
|
||||||
// SetDebug(true)
|
// SetDebug(true)
|
||||||
debugGrid = activeWidget.NewGrid("tmp grid", 2, 3)
|
debugGrid = activeWidget.NewGrid("tmp grid", 2, 3)
|
||||||
debugGridLabel = debugGrid.NewLabel("mirrors.wit.com")
|
debugGridLabel = debugGrid.NewLabel("mirrors.wit.com")
|
||||||
|
/*
|
||||||
debugGrid.SetNext(0,1)
|
debugGrid.SetNext(0,1)
|
||||||
debugGrid.NewLabel("foo (0,1)")
|
debugGrid.NewLabel("foo (0,1)")
|
||||||
debugGrid.SetNext(1,1)
|
debugGrid.SetNext(1,1)
|
||||||
debugGrid.NewLabel("foo (1,1)")
|
debugGrid.NewLabel("foo (1,1)")
|
||||||
debugGrid.SetNext(2,1)
|
debugGrid.SetNext(2,1)
|
||||||
debugGrid.NewLabel("foo (2,1)")
|
debugGrid.NewLabel("foo (2,1)")
|
||||||
|
*/
|
||||||
// SetDebug(false)
|
// SetDebug(false)
|
||||||
DebugWidgetWindow(debugGrid)
|
DebugWidgetWindow(debugGrid)
|
||||||
})
|
})
|
||||||
|
|
|
@ -83,6 +83,10 @@ func (n *Node) DebugTab(title string) *Node {
|
||||||
activeWidget.ListChildren(true)
|
activeWidget.ListChildren(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
g2.NewButton("test conc", func () {
|
||||||
|
makeConc()
|
||||||
|
})
|
||||||
|
|
||||||
return newN
|
return newN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
grid.go
1
grid.go
|
@ -39,6 +39,7 @@ func (n *Node) NewBox(name string, b bool) *Node {
|
||||||
|
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
a.Type = toolkit.Add
|
a.Type = toolkit.Add
|
||||||
|
a.Title = name
|
||||||
a.B = b
|
a.B = b
|
||||||
newaction(&a, newNode, n)
|
newaction(&a, newNode, n)
|
||||||
|
|
||||||
|
|
126
log.go
126
log.go
|
@ -1,125 +1,29 @@
|
||||||
//
|
|
||||||
// version v1.3
|
|
||||||
//
|
|
||||||
// I like things to be easy.
|
|
||||||
//
|
|
||||||
// this means all the log settings are in one place. it should allow
|
|
||||||
// things to be over-ridden externally to the library
|
|
||||||
// but still allow command line --args to pass debugging settings
|
|
||||||
//
|
|
||||||
// I also have a generic sleep() and exit() in here because it's simple
|
|
||||||
//
|
|
||||||
// Usage:
|
|
||||||
//
|
|
||||||
// log("something", foo, bar)
|
|
||||||
// var DEBUG bool = true
|
|
||||||
// log(DEBUG, "something else", someOtherVariable) # if DEBUG == false, return doing nothing
|
|
||||||
// log(SPEW, "something else", someOtherVariable) # this get's sent to spew.Dump(). Very useful for debugging!
|
|
||||||
//
|
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
witlog "git.wit.org/wit/gui/log"
|
||||||
"runtime"
|
|
||||||
"runtime/pprof"
|
|
||||||
golog "log"
|
|
||||||
"time"
|
|
||||||
"reflect"
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
// "net"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var LOGOFF bool = false // turn this off, all logging stops
|
// various debugging flags
|
||||||
var WARN bool
|
var logNow bool = true // useful for active development
|
||||||
var INFO bool
|
var logError bool = true
|
||||||
|
var logWarn bool = false
|
||||||
|
var logInfo bool = false
|
||||||
|
var logVerbose bool = false
|
||||||
|
|
||||||
type spewt struct {
|
// var log interface{}
|
||||||
a bool
|
|
||||||
}
|
|
||||||
|
|
||||||
var SPEW spewt
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
sleep() # you know what this does? sleeps for 1 second. yep. dump. easy.
|
|
||||||
sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second
|
|
||||||
*/
|
|
||||||
func sleep(a ...any) {
|
|
||||||
if (a == nil) {
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log("sleep", a[0])
|
|
||||||
|
|
||||||
switch a[0].(type) {
|
|
||||||
case int:
|
|
||||||
time.Sleep(time.Duration(a[0].(int)) * time.Second)
|
|
||||||
case float64:
|
|
||||||
time.Sleep(time.Duration(a[0].(float64) * 1000) * time.Millisecond)
|
|
||||||
default:
|
|
||||||
log("sleep a[0], type = ", a[0], reflect.TypeOf(a[0]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
exit() # yep. exits. I guess everything must be fine
|
|
||||||
exit(3) # I guess 3 it is then
|
|
||||||
exit("dont like apples") # ok. I'll make a note of that
|
|
||||||
*/
|
|
||||||
func exit(a ...any) {
|
|
||||||
log("exit", a)
|
|
||||||
//if (a) {
|
|
||||||
// os.Exit(a)
|
|
||||||
//}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
I've spent, am spending, too much time thinking about 'logging'. 'log', 'logrus', 'zap', whatever.
|
|
||||||
I'm not twitter. i don't give a fuck about how many nanoseconds it takes to log. Anyway, this
|
|
||||||
implementation is probably faster than all of those because you just set one bool to FALSE
|
|
||||||
and it all stops.
|
|
||||||
Sometimes I need to capture to stdout, sometimes stdout can't
|
|
||||||
work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread
|
|
||||||
over 8 million references in every .go file. I'm tapping out and putting
|
|
||||||
it in one place. here it is. Also, this makes having debug levels really fucking easy.
|
|
||||||
You can define whatever level of logging you want from anywhere (command line) etc.
|
|
||||||
|
|
||||||
log() # doesn't do anything
|
|
||||||
log(stuff) # sends it to whatever log you define in a single place. here is the place
|
|
||||||
*/
|
|
||||||
|
|
||||||
func log(a ...any) {
|
func log(a ...any) {
|
||||||
if (LOGOFF) {
|
witlog.Where = "wit/gui"
|
||||||
return
|
witlog.Log(a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a == nil) {
|
func sleep(a ...any) {
|
||||||
return
|
witlog.Sleep(a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
var tbool bool
|
func exit(a ...any) {
|
||||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(tbool)) {
|
witlog.Exit(a...)
|
||||||
// golog.Println("\t a[0] = bool")
|
|
||||||
if (a[0] == false) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
a[0] = "WIT/GUI"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) {
|
|
||||||
a = a[1:]
|
|
||||||
spew.Dump(a)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
golog.Println(a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func loggo() {
|
|
||||||
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
|
||||||
golog.Println("runtime.NumGoroutine() = ", runtime.NumGoroutine())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// b bool, print if true
|
// b bool, print if true
|
||||||
|
@ -135,5 +39,5 @@ func logindent(b bool, depth int, format string, a ...any) {
|
||||||
// array prepend(). Why isn't this a standard function. It should be:
|
// array prepend(). Why isn't this a standard function. It should be:
|
||||||
// a.prepend(debugGui, newFormat)
|
// a.prepend(debugGui, newFormat)
|
||||||
a = append([]any{b, newFormat}, a...)
|
a = append([]any{b, newFormat}, a...)
|
||||||
log(a...)
|
witlog.Log(a...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,142 @@
|
||||||
|
package witlog
|
||||||
|
//
|
||||||
|
// version v1.2
|
||||||
|
//
|
||||||
|
// I like things to be easy.
|
||||||
|
//
|
||||||
|
// this means all the log settings are in one place. it should allow
|
||||||
|
// things to be over-ridden externally to the library
|
||||||
|
// but still allow command line --args to pass debugging settings
|
||||||
|
//
|
||||||
|
// I also have a generic sleep() and exit() in here because it's simple
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
//
|
||||||
|
// log("something", foo, bar)
|
||||||
|
// var DEBUG bool = true
|
||||||
|
// log(DEBUG, "something else", someOtherVariable) # if DEBUG == false, return doing nothing
|
||||||
|
// log(SPEW, "something else", someOtherVariable) # this get's sent to spew.Dump(). Very useful for debugging!
|
||||||
|
//
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
|
golog "log"
|
||||||
|
"time"
|
||||||
|
"reflect"
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
// "net"
|
||||||
|
)
|
||||||
|
|
||||||
|
var LOGOFF bool = false // turn this off, all logging stops
|
||||||
|
var debugToolkit bool = false // does spew stuff?
|
||||||
|
|
||||||
|
var Where string = "gui/log"
|
||||||
|
|
||||||
|
type spewt struct {
|
||||||
|
a bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var SPEW spewt
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
sleep() # you know what this does? sleeps for 1 second. yep. dump. easy.
|
||||||
|
sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second
|
||||||
|
*/
|
||||||
|
func Sleep(a ...any) {
|
||||||
|
if (a == nil) {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Log(true, "sleep", a[0])
|
||||||
|
|
||||||
|
switch a[0].(type) {
|
||||||
|
case int:
|
||||||
|
time.Sleep(time.Duration(a[0].(int)) * time.Second)
|
||||||
|
case float64:
|
||||||
|
time.Sleep(time.Duration(a[0].(float64) * 1000) * time.Millisecond)
|
||||||
|
default:
|
||||||
|
Log("sleep a[0], type = ", a[0], reflect.TypeOf(a[0]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
exit() # yep. exits. I guess everything must be fine
|
||||||
|
exit(3) # I guess 3 it is then
|
||||||
|
exit("dont like apples") # ok. I'll make a note of that
|
||||||
|
*/
|
||||||
|
func Exit(a ...any) {
|
||||||
|
Log(true, "exit", a)
|
||||||
|
//if (a) {
|
||||||
|
// os.Exit(a)
|
||||||
|
//}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
I've spent, am spending, too much time thinking about 'logging'. 'log', 'logrus', 'zap', whatever.
|
||||||
|
I'm not twitter. i don't give a fuck about how many nanoseconds it takes to log. Anyway, this
|
||||||
|
implementation is probably faster than all of those because you just set one bool to FALSE
|
||||||
|
and it all stops.
|
||||||
|
Sometimes I need to capture to stdout, sometimes stdout can't
|
||||||
|
work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread
|
||||||
|
over 8 million references in every .go file. I'm tapping out and putting
|
||||||
|
it in one place. here it is. Also, this makes having debug levels really fucking easy.
|
||||||
|
You can define whatever level of logging you want from anywhere (command line) etc.
|
||||||
|
|
||||||
|
log() # doesn't do anything
|
||||||
|
log(stuff) # sends it to whatever log you define in a single place. here is the place
|
||||||
|
*/
|
||||||
|
|
||||||
|
func Log(a ...any) {
|
||||||
|
if (LOGOFF) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a == nil) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var tbool bool
|
||||||
|
if (reflect.TypeOf(a[0]) == reflect.TypeOf(tbool)) {
|
||||||
|
if (a[0] == false) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a[0] = Where
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) {
|
||||||
|
// a = a[1:]
|
||||||
|
a[0] = Where
|
||||||
|
if (debugToolkit) {
|
||||||
|
scs := spew.ConfigState{MaxDepth: 1}
|
||||||
|
scs.Dump(a)
|
||||||
|
// spew.Dump(a)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
golog.Println(a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loggo() {
|
||||||
|
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||||
|
golog.Println("runtime.NumGoroutine() = ", runtime.NumGoroutine())
|
||||||
|
}
|
||||||
|
|
||||||
|
func logindent(depth int, format string, a ...interface{}) {
|
||||||
|
var tabs string
|
||||||
|
for i := 0; i < depth; i++ {
|
||||||
|
tabs = tabs + format
|
||||||
|
}
|
||||||
|
|
||||||
|
// newFormat := tabs + strconv.Itoa(depth) + " " + format
|
||||||
|
newFormat := tabs + format
|
||||||
|
Log(debugToolkit, newFormat, a)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetOutput(f *os.File) {
|
||||||
|
golog.SetOutput(f)
|
||||||
|
}
|
52
plugin.go
52
plugin.go
|
@ -79,11 +79,6 @@ func LoadToolkit(name string) bool {
|
||||||
// unload the plugin and restore state
|
// unload the plugin and restore state
|
||||||
newPlug.Quit = loadFuncE(&newPlug, "Quit")
|
newPlug.Quit = loadFuncE(&newPlug, "Quit")
|
||||||
|
|
||||||
// Sends a widget (button, checkbox, etc) and it's parent widget
|
|
||||||
// This includes instructions like "Add", "Delete", "Disable", etc
|
|
||||||
// newPlug.Send = loadFunc2(&newPlug, "Send")
|
|
||||||
|
|
||||||
// This should replace Send()
|
|
||||||
// Sends instructions like "Add", "Delete", "Disable", etc
|
// Sends instructions like "Add", "Delete", "Disable", etc
|
||||||
// Sends a widget (button, checkbox, etc) and it's parent widget
|
// Sends a widget (button, checkbox, etc) and it's parent widget
|
||||||
newPlug.Action = loadFuncA(&newPlug, "Action")
|
newPlug.Action = loadFuncA(&newPlug, "Action")
|
||||||
|
@ -230,36 +225,6 @@ func loadfile(filename string) *plugin.Plugin {
|
||||||
return plug
|
return plug
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// Sends a widget and what to do with it to the plugin
|
|
||||||
// parent = n, child = c
|
|
||||||
func send(p *Node, c *Node) {
|
|
||||||
for _, aplug := range allPlugins {
|
|
||||||
log(debugPlugin, "Send() aplug =", aplug.name, "type=", c.widget.Type, "action=", c.widget.Action, "name=", c.widget.Name)
|
|
||||||
if (aplug.Send == nil) {
|
|
||||||
log(debugPlugin, "Failed. Send() == nil for", aplug.name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
aplug.Send(&c.parent.widget, &c.widget)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Sends a widget and what to do with it to the plugin
|
|
||||||
// parent = n, child = c
|
|
||||||
/*
|
|
||||||
func action(a *toolkit.Action) {
|
|
||||||
for _, aplug := range allPlugins {
|
|
||||||
log(debugPlugin, "Action() aplug =", aplug.name, "Action type=", a.Type)
|
|
||||||
if (aplug.Action == nil) {
|
|
||||||
log(debugPlugin, "Failed Action() == nil for", aplug.name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
aplug.Action(a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Sends a widget and what to do with it to the plugin
|
// Sends a widget and what to do with it to the plugin
|
||||||
// parent = n, child = c
|
// parent = n, child = c
|
||||||
|
|
||||||
|
@ -268,16 +233,19 @@ func action(a *toolkit.Action) {
|
||||||
func newaction(a *toolkit.Action, n *Node, where *Node) {
|
func newaction(a *toolkit.Action, n *Node, where *Node) {
|
||||||
if (n != nil) {
|
if (n != nil) {
|
||||||
a.Widget = &n.widget
|
a.Widget = &n.widget
|
||||||
|
a.WidgetId = n.id
|
||||||
|
a.WidgetT = n.widget.Type
|
||||||
}
|
}
|
||||||
// action(&a, newNode, n)
|
// action(&a, newNode, n)
|
||||||
// newaction(&a, newNode, n)
|
// newaction(&a, newNode, n)
|
||||||
|
|
||||||
if (where != nil) {
|
if (where != nil) {
|
||||||
log(debugGui, "Action() START on where X,Y, Next X,Y =", where.Name, where.X, where.Y, where.NextX, where.NextY)
|
log(debugGui, "Action() START on where X,Y, Next X,Y =", where.Name, where.X, where.Y, where.NextX, where.NextY)
|
||||||
a.Where = &where.widget
|
// a.Where = &where.widget
|
||||||
|
a.WhereId = where.id
|
||||||
switch where.widget.Type {
|
switch where.widget.Type {
|
||||||
case toolkit.Grid:
|
case toolkit.Grid:
|
||||||
where.Dump(true)
|
// where.Dump(true)
|
||||||
log(debugGui, "Action() START on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
log(debugGui, "Action() START on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
||||||
//
|
//
|
||||||
// fix values here if they are invalid. Index starts at 1
|
// fix values here if they are invalid. Index starts at 1
|
||||||
|
@ -288,8 +256,8 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
|
||||||
where.NextY = 1
|
where.NextY = 1
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
a.Where.X = where.NextX
|
a.X = where.NextX
|
||||||
a.Where.Y = where.NextY
|
a.Y = where.NextY
|
||||||
log(debugGui, "Action() END on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
log(debugGui, "Action() END on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
@ -307,19 +275,19 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
|
||||||
if (where != nil) {
|
if (where != nil) {
|
||||||
switch where.widget.Type {
|
switch where.widget.Type {
|
||||||
case toolkit.Grid:
|
case toolkit.Grid:
|
||||||
log(debugNow, "Action() START size (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
log(logInfo, "Action() START size (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
||||||
where.NextY += 1
|
where.NextY += 1
|
||||||
if (where.NextY > where.Y) {
|
if (where.NextY > where.Y) {
|
||||||
where.NextX += 1
|
where.NextX += 1
|
||||||
where.NextY = 1
|
where.NextY = 1
|
||||||
}
|
}
|
||||||
log(debugNow, "Action() END size (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
log(logInfo, "Action() END size (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
||||||
where.Name = "jwc gridlaksdfjkl"
|
where.Name = "jwc gridlaksdfjkl"
|
||||||
where.Width = 320
|
where.Width = 320
|
||||||
where.Height = 240
|
where.Height = 240
|
||||||
// where.NextX = 5
|
// where.NextX = 5
|
||||||
// where.NextY = 7
|
// where.NextY = 7
|
||||||
where.Dump(true)
|
// where.Dump(logInfo)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
tab.go
4
tab.go
|
@ -12,7 +12,9 @@ func (n *Node) NewTab(text string) *Node {
|
||||||
|
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
a.Type = toolkit.Add
|
a.Type = toolkit.Add
|
||||||
|
a.Title = text
|
||||||
newaction(&a, newNode, n)
|
newaction(&a, newNode, n)
|
||||||
|
|
||||||
return newNode
|
newBox := newNode.NewBox(text, true)
|
||||||
|
return newBox
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,40 +4,40 @@ import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
"git.wit.org/wit/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func show(w *toolkit.Widget) {
|
func show(a *toolkit.Action) {
|
||||||
if (w == nil) {
|
if (a == nil) {
|
||||||
log(debugError, "nil is probably already hidden")
|
log(debugError, "nil is probably already hidden")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log(debugError, "show()", w.Name)
|
log(debugError, "show()", a.WidgetId)
|
||||||
|
|
||||||
t := mapToolkits[w]
|
t := andlabs[a.WidgetId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "show() toolkit struct == nil. for", w.Name)
|
log(debugError, "show() toolkit struct == nil. for", a.WidgetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w.B) {
|
if (a.B) {
|
||||||
t.uiControl.Show()
|
t.uiControl.Show()
|
||||||
} else {
|
} else {
|
||||||
t.uiControl.Hide()
|
t.uiControl.Hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func enable(w *toolkit.Widget) {
|
func enable(a *toolkit.Action) {
|
||||||
if (w == nil) {
|
if (a == nil) {
|
||||||
log(debugError, "nil is probably already hidden")
|
log(debugError, "nil is probably already hidden")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log(debugError, "enable()", w.Name)
|
log(debugError, "enable() name =", a.WidgetId)
|
||||||
|
|
||||||
t := mapToolkits[w]
|
t := andlabs[a.WidgetId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "enable() toolkit struct == nil. for", w.Name)
|
log(debugToolkit, "enable() toolkit struct == nil. for id =", a.WidgetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w.B) {
|
if (a.B) {
|
||||||
t.uiControl.Enable()
|
t.uiControl.Enable()
|
||||||
} else {
|
} else {
|
||||||
t.uiControl.Disable()
|
t.uiControl.Disable()
|
||||||
|
@ -45,19 +45,19 @@ func enable(w *toolkit.Widget) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func pad(a *toolkit.Action) {
|
func pad(a *toolkit.Action) {
|
||||||
if (a.Widget == nil) {
|
if (a == nil) {
|
||||||
log(debugError, "pad() ERROR: nil is probably already hidden")
|
log(debugError, "pad() ERROR: nil is probably already hidden")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log(debugError, "pad()", a.Widget.Name)
|
log(debugError, "pad()")
|
||||||
|
|
||||||
t := mapToolkits[a.Widget]
|
t := andlabs[a.WidgetId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "pad() toolkit struct == nil. for", a.Widget.Name)
|
log(debugError, "pad() toolkit struct == nil. for", a.WidgetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch a.Widget.Type {
|
switch t.Type {
|
||||||
case toolkit.Group:
|
case toolkit.Group:
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
case toolkit.Margin:
|
case toolkit.Margin:
|
||||||
|
@ -124,29 +124,21 @@ func pad(a *toolkit.Action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func move(a *toolkit.Action) {
|
func move(a *toolkit.Action) {
|
||||||
if (a.Where == nil) {
|
log(debugNow, "move()", a.WidgetId, "to", a.WhereId)
|
||||||
log(debugError, "move() ERROR: can not move to nil")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (a.Widget == nil) {
|
|
||||||
log(debugError, "move() ERROR: can not move nil")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log(debugNow, "move()", a.Widget.Name, "to", a.Where.Name)
|
|
||||||
|
|
||||||
tWidget := mapToolkits[a.Widget]
|
tWidget := andlabs[a.WidgetId]
|
||||||
if (tWidget == nil) {
|
if (tWidget == nil) {
|
||||||
log(debugError, "move() ERROR: toolkit struct == nil. for", a.Widget.Name)
|
log(debugError, "move() ERROR: toolkit struct == nil. for", a.WidgetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tWhere := mapToolkits[a.Where]
|
tWhere := andlabs[a.WhereId]
|
||||||
if (tWhere == nil) {
|
if (tWhere == nil) {
|
||||||
log(debugError, "move() ERROR: toolkit struct == nil. for", a.Where.Name)
|
log(debugError, "move() ERROR: toolkit struct == nil. for", a.WhereId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch a.Where.Type {
|
switch tWhere.Type {
|
||||||
case toolkit.Group:
|
case toolkit.Group:
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
case toolkit.Margin:
|
case toolkit.Margin:
|
||||||
|
@ -169,8 +161,8 @@ func move(a *toolkit.Action) {
|
||||||
}
|
}
|
||||||
case toolkit.Box:
|
case toolkit.Box:
|
||||||
log(debugNow, "TODO: move() for a =", a.Type)
|
log(debugNow, "TODO: move() for a =", a.Type)
|
||||||
log(debugNow, "TODO: move() where =", a.Where.Type)
|
log(debugNow, "TODO: move() where =", a.WhereId)
|
||||||
log(debugNow, "TODO: move() for widget =", a.Widget.Type)
|
log(debugNow, "TODO: move() for widget =", a.WidgetId)
|
||||||
|
|
||||||
stretchy = true
|
stretchy = true
|
||||||
tWhere.uiBox.Append(tWidget.uiControl, stretchy)
|
tWhere.uiBox.Append(tWidget.uiControl, stretchy)
|
||||||
|
@ -182,35 +174,35 @@ func move(a *toolkit.Action) {
|
||||||
// sleep(.8)
|
// sleep(.8)
|
||||||
default:
|
default:
|
||||||
log(debugError, "TODO: need to implement move() for a =", a.Type)
|
log(debugError, "TODO: need to implement move() for a =", a.Type)
|
||||||
log(debugError, "TODO: need to implement move() for where =", a.Where.Type)
|
log(debugError, "TODO: need to implement move() for where =", a.WhereId)
|
||||||
log(debugError, "TODO: need to implement move() for widget =", a.Widget.Type)
|
log(debugError, "TODO: need to implement move() for widget =", a.WidgetId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func uiDelete(a *toolkit.Action) {
|
func uiDelete(a *toolkit.Action) {
|
||||||
if (a.Where == nil) {
|
if (andlabs[a.WhereId] == nil) {
|
||||||
log(debugError, "uiDelete() ERROR: can not uiDelete to nil")
|
log(debugError, "uiDelete() ERROR: can not uiDelete to nil")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (a.Widget == nil) {
|
if (andlabs[a.WidgetId] == nil) {
|
||||||
log(debugError, "uiDelete() ERROR: can not uiDelete nil")
|
log(debugError, "uiDelete() ERROR: can not uiDelete nil")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log(debugNow, "uiDelete()", a.Widget.Name, "to", a.Where.Name)
|
log(debugNow, "uiDelete()", a.WidgetId, "to", a.WhereId)
|
||||||
|
|
||||||
tWidget := mapToolkits[a.Widget]
|
tWidget := andlabs[a.WidgetId]
|
||||||
if (tWidget == nil) {
|
if (tWidget == nil) {
|
||||||
log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.Widget.Name)
|
log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.WidgetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tWhere := mapToolkits[a.Where]
|
tWhere := andlabs[a.WhereId]
|
||||||
if (tWhere == nil) {
|
if (tWhere == nil) {
|
||||||
log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.Where.Name)
|
log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.WhereId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch a.Where.Type {
|
switch tWhere.Type {
|
||||||
case toolkit.Group:
|
case toolkit.Group:
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
case toolkit.Margin:
|
case toolkit.Margin:
|
||||||
|
@ -247,7 +239,7 @@ func uiDelete(a *toolkit.Action) {
|
||||||
// tWhere.uiBox.Append(tWidget.uiControl, stretchy)
|
// tWhere.uiBox.Append(tWidget.uiControl, stretchy)
|
||||||
default:
|
default:
|
||||||
log(debugError, "TODO: need to implement uiDelete() for a =", a.Type)
|
log(debugError, "TODO: need to implement uiDelete() for a =", a.Type)
|
||||||
log(debugError, "TODO: need to implement uiDelete() for where =", a.Where.Type)
|
log(debugError, "TODO: need to implement uiDelete() for where =", a.WhereId)
|
||||||
log(debugError, "TODO: need to implement uiDelete() for widget =", a.Widget.Type)
|
log(debugError, "TODO: need to implement uiDelete() for widget =", a.WidgetId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,40 +8,45 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func actionDump(b bool, a *toolkit.Action) {
|
func actionDump(b bool, a *toolkit.Action) {
|
||||||
log(b, "dump() Widget.Type =", a.Type)
|
log(b, "actionDump() Widget.Type =", a.Type)
|
||||||
log(b, "dump() Widget.S =", a.S)
|
log(b, "actionDump() Widget.S =", a.S)
|
||||||
log(b, "dump() Widget.I =", a.I)
|
log(b, "actionDump() Widget.I =", a.I)
|
||||||
log(b, "dump() Widget =", a.Widget)
|
log(b, "actionDump() WidgetId =", a.WidgetId)
|
||||||
log(b, "dump() Where =", a.Where)
|
log(b, "actionDump() WhereId =", a.WhereId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(a *toolkit.Action) {
|
func add(a *toolkit.Action) {
|
||||||
if (a.Widget == nil) {
|
if (andlabs[a.WidgetId] != nil) {
|
||||||
log(debugError, "add() error. w.Widget == nil")
|
log(debugError, "add() error. can't make a widget that already exists. id =", a.WidgetId)
|
||||||
actionDump(debugError, a)
|
actionDump(debugError, a)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (a.WidgetId == 0) {
|
||||||
|
log(debugError, "add() error. w.WidgetId == 0")
|
||||||
|
actionDump(debugError, a)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// for now, window gets handled without checking where == nil)
|
// for now, window gets handled without checking where == nil)
|
||||||
if (a.Widget.Type == toolkit.Window) {
|
if (a.WidgetT == toolkit.Window) {
|
||||||
doWindow(a)
|
doWindow(a)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
t := mapToolkits[a.Where]
|
if (andlabs[a.WhereId] == nil) {
|
||||||
if (t == nil) {
|
|
||||||
// listMap(debugError) // memory corruption?
|
// listMap(debugError) // memory corruption?
|
||||||
log(debugError, "add() Widget.Name =", a.Widget.Name, a.Widget.Type)
|
log(debugError, "add() Widget.Name =", a.Title, a.WidgetT)
|
||||||
// log(debugError, "add() Where.Name =", a.Where.Name)
|
// log(debugError, "add() Where.Name =", a.Where.Name)
|
||||||
log(debugError, "ERROR add() ERROR a.Where map to t == nil.")
|
log(debugError, "ERROR add() ERROR a.Where map to t == nil.", a.WidgetId, a.WhereId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch a.Widget.Type {
|
switch a.WidgetT {
|
||||||
case toolkit.Window:
|
case toolkit.Window:
|
||||||
doWindow(a)
|
doWindow(a)
|
||||||
return
|
return
|
||||||
case toolkit.Tab:
|
case toolkit.Tab:
|
||||||
doTab(a)
|
newTab(a)
|
||||||
return
|
return
|
||||||
case toolkit.Label:
|
case toolkit.Label:
|
||||||
newLabel(a)
|
newLabel(a)
|
||||||
|
@ -80,7 +85,7 @@ func add(a *toolkit.Action) {
|
||||||
newImage(a)
|
newImage(a)
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
log(debugError, "add() error TODO: ", a.Widget.Type, a.Widget.Name)
|
log(debugError, "add() error TODO: ", a.WidgetT, a.Title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,18 +114,34 @@ func add(a *toolkit.Action) {
|
||||||
// -- (0,1) -- (1,1) -- (1,1) --
|
// -- (0,1) -- (1,1) -- (1,1) --
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool {
|
func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool {
|
||||||
log(debugAction, "place() START", a.Widget.Type, a.Widget.Name)
|
log(debugAction, "place() START", a.WidgetT, a.Title)
|
||||||
|
|
||||||
|
// add the structure to the array
|
||||||
|
if (andlabs[a.WidgetId] == nil) {
|
||||||
|
log(logInfo, "newTab() MAPPED", a.WidgetId, a.WhereId)
|
||||||
|
andlabs[a.WidgetId] = newt
|
||||||
|
newt.Type = a.WidgetT
|
||||||
|
} else {
|
||||||
|
log(debugError, "newTab() DO WHAT?", a.WidgetId, a.WhereId)
|
||||||
|
log(debugError, "THIS IS BAD")
|
||||||
|
}
|
||||||
|
|
||||||
if (newt.uiControl == nil) {
|
if (newt.uiControl == nil) {
|
||||||
log(debugError, "place() ERROR uiControl == nil", a.Where.Type, a.Where.Name)
|
log(debugError, "place() ERROR uiControl == nil", a.WhereId)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
switch a.Where.Type {
|
where := andlabs[a.WhereId]
|
||||||
|
if (where == nil) {
|
||||||
|
log(debugError, "place() ERROR where == nil", a.WhereId)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
switch where.Type {
|
||||||
case toolkit.Grid:
|
case toolkit.Grid:
|
||||||
log(debugGrid, "add() Grid try at Where X,Y =", a.Where.X, a.Where.Y)
|
log(debugGrid, "add() Grid try at Where X,Y =", a.X, a.Y)
|
||||||
newt.gridX = a.Where.X
|
newt.gridX = a.X
|
||||||
newt.gridY = a.Where.Y
|
newt.gridY = a.Y
|
||||||
log(debugGrid, "add() Grid try at gridX,gridY", newt.gridX, newt.gridY)
|
log(debugGrid, "add() Grid try at gridX,gridY", newt.gridX, newt.gridY)
|
||||||
// at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero
|
// at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero
|
||||||
t.uiGrid.Append(newt.uiControl,
|
t.uiGrid.Append(newt.uiControl,
|
||||||
|
@ -130,14 +151,14 @@ func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool {
|
||||||
case toolkit.Group:
|
case toolkit.Group:
|
||||||
if (t.uiBox == nil) {
|
if (t.uiBox == nil) {
|
||||||
t.uiGroup.SetChild(newt.uiControl)
|
t.uiGroup.SetChild(newt.uiControl)
|
||||||
log(debugGrid, "add() hack Group to use this as the box?", a.Widget.Name, a.Widget.Type)
|
log(debugGrid, "add() hack Group to use this as the box?", a.Title, a.WidgetT)
|
||||||
t.uiBox = newt.uiBox
|
t.uiBox = newt.uiBox
|
||||||
} else {
|
} else {
|
||||||
t.uiBox.Append(newt.uiControl, stretchy)
|
t.uiBox.Append(newt.uiControl, stretchy)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
case toolkit.Tab:
|
case toolkit.Tab:
|
||||||
t.uiBox.Append(newt.uiControl, stretchy)
|
t.uiTab.Append(a.Title, newt.uiControl)
|
||||||
t.boxC += 1
|
t.boxC += 1
|
||||||
return true
|
return true
|
||||||
case toolkit.Box:
|
case toolkit.Box:
|
||||||
|
@ -148,7 +169,7 @@ func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool {
|
||||||
t.uiWindow.SetChild(newt.uiControl)
|
t.uiWindow.SetChild(newt.uiControl)
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
log(debugError, "add() how?", a.Where.Type)
|
log(debugError, "add() how?", a.WhereId)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,19 +9,17 @@ import (
|
||||||
|
|
||||||
// make new Box here
|
// make new Box here
|
||||||
func newBox(a *toolkit.Action) {
|
func newBox(a *toolkit.Action) {
|
||||||
w := a.Widget
|
log(debugToolkit, "newBox()", a.Title)
|
||||||
parentW := a.Where
|
|
||||||
log(debugToolkit, "newBox()", w.Name)
|
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "newBox() toolkit struct == nil. name=", parentW.Name, w.Name)
|
log(debugToolkit, "newBox() toolkit struct == nil. name=", a.Title)
|
||||||
listMap(debugToolkit)
|
listMap(debugToolkit)
|
||||||
}
|
}
|
||||||
newt := t.rawBox(w.Name, a.B)
|
newt := t.rawBox(a.Title, a.B)
|
||||||
newt.boxC = 0
|
newt.boxC = 0
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
andlabs[a.WidgetId] = newt
|
||||||
}
|
}
|
||||||
|
|
||||||
// make new Box using andlabs/ui
|
// make new Box using andlabs/ui
|
||||||
|
|
|
@ -10,27 +10,27 @@ import (
|
||||||
func newButton(a *toolkit.Action) {
|
func newButton(a *toolkit.Action) {
|
||||||
var t, newt *andlabsT
|
var t, newt *andlabsT
|
||||||
var b *ui.Button
|
var b *ui.Button
|
||||||
w := a.Widget
|
log(debugToolkit, "newButton()", a.Title)
|
||||||
log(debugToolkit, "newButton()", w.Name)
|
|
||||||
|
|
||||||
t = mapToolkits[a.Where]
|
t = andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "newButton() toolkit struct == nil. name=", a.Where.Name, w.Name)
|
log(debugToolkit, "newButton() toolkit struct == nil. name=", a.Title)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
newt = new(andlabsT)
|
newt = new(andlabsT)
|
||||||
|
|
||||||
b = ui.NewButton(w.Name)
|
b = ui.NewButton(a.Title)
|
||||||
newt.uiButton = b
|
newt.uiButton = b
|
||||||
newt.uiControl = b
|
newt.uiControl = b
|
||||||
newt.tw = w
|
newt.tw = a.Widget
|
||||||
|
newt.Type = a.WidgetT
|
||||||
newt.parent = t
|
newt.parent = t
|
||||||
|
|
||||||
b.OnClicked(func(*ui.Button) {
|
b.OnClicked(func(*ui.Button) {
|
||||||
newt.commonChange(newt.tw)
|
newt.commonChange(newt.tw, a.WidgetId)
|
||||||
})
|
})
|
||||||
|
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
// mapWidgetsToolkits(a, newt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,13 @@ import (
|
||||||
_ "github.com/andlabs/ui/winmanifest"
|
_ "github.com/andlabs/ui/winmanifest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *andlabsT) newCheckbox(w *toolkit.Widget) *andlabsT {
|
func (t *andlabsT) newCheckbox(a *toolkit.Action) *andlabsT {
|
||||||
log(debugToolkit, "newCheckbox()", w.Name, w.Type)
|
|
||||||
var newt andlabsT
|
var newt andlabsT
|
||||||
|
w := a.Widget
|
||||||
|
log(debugToolkit, "newCheckbox()", w.Name, w.Type)
|
||||||
newt.tw = w
|
newt.tw = w
|
||||||
|
newt.Type = w.Type
|
||||||
|
newt.wId = a.WidgetId
|
||||||
|
|
||||||
newt.uiCheckbox = ui.NewCheckbox(w.Name)
|
newt.uiCheckbox = ui.NewCheckbox(w.Name)
|
||||||
newt.uiControl = newt.uiCheckbox
|
newt.uiControl = newt.uiCheckbox
|
||||||
|
@ -17,7 +20,7 @@ func (t *andlabsT) newCheckbox(w *toolkit.Widget) *andlabsT {
|
||||||
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
|
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
|
||||||
newt.tw.B = newt.checked()
|
newt.tw.B = newt.checked()
|
||||||
log(debugChange, "val =", newt.tw.B)
|
log(debugChange, "val =", newt.tw.B)
|
||||||
newt.commonChange(newt.tw)
|
newt.commonChange(newt.tw, a.WidgetId)
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
@ -28,16 +31,13 @@ func (t *andlabsT) checked() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCheckbox(a *toolkit.Action) {
|
func newCheckbox(a *toolkit.Action) {
|
||||||
w := a.Widget
|
log(debugToolkit, "newCheckbox()", a.Title)
|
||||||
parentW := a.Where
|
|
||||||
log(debugToolkit, "newCheckbox()", w.Name)
|
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
listMap(debugError)
|
listMap(debugError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newt := t.newCheckbox(w)
|
newt := t.newCheckbox(a)
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,14 @@ import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
"git.wit.org/wit/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *andlabsT) newCombobox(w *toolkit.Widget) *andlabsT {
|
func (t *andlabsT) newCombobox(a *toolkit.Action) *andlabsT {
|
||||||
var newt andlabsT
|
var newt andlabsT
|
||||||
|
w := a.Widget
|
||||||
log(debugToolkit, "newCombobox() START", w.Name)
|
log(debugToolkit, "newCombobox() START", w.Name)
|
||||||
|
|
||||||
newt.tw = w
|
newt.tw = w
|
||||||
|
newt.wId = a.WidgetId
|
||||||
|
newt.Type = w.Type
|
||||||
s := ui.NewEditableCombobox()
|
s := ui.NewEditableCombobox()
|
||||||
newt.uiEditableCombobox = s
|
newt.uiEditableCombobox = s
|
||||||
newt.uiControl = s
|
newt.uiControl = s
|
||||||
|
@ -21,7 +24,7 @@ func (t *andlabsT) newCombobox(w *toolkit.Widget) *andlabsT {
|
||||||
|
|
||||||
s.OnChanged(func(spin *ui.EditableCombobox) {
|
s.OnChanged(func(spin *ui.EditableCombobox) {
|
||||||
newt.tw.S = spin.Text()
|
newt.tw.S = spin.Text()
|
||||||
newt.commonChange(newt.tw)
|
newt.commonChange(newt.tw, a.WidgetId)
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
@ -42,17 +45,14 @@ func (t *andlabsT) AddComboboxName(title string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCombobox(a *toolkit.Action) {
|
func newCombobox(a *toolkit.Action) {
|
||||||
w := a.Widget
|
log(debugToolkit, "newCombobox()", a.Title)
|
||||||
parentW := a.Where
|
|
||||||
log(debugToolkit, "newCombobox()", w.Name)
|
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "newCombobox() toolkit struct == nil. name=", parentW.Name, w.Name)
|
log(debugToolkit, "newCombobox() toolkit struct == nil. name=", a.Title)
|
||||||
listMap(debugToolkit)
|
listMap(debugToolkit)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newt := t.newCombobox(w)
|
newt := t.newCombobox(a)
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
"git.wit.org/wit/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *andlabsT) commonChange(tw *toolkit.Widget) {
|
func (t *andlabsT) commonChange(tw *toolkit.Widget, wId int) {
|
||||||
log(debugChange, "commonChange() START widget =", t.tw.Name, t.tw.Type)
|
log(debugChange, "commonChange() START widget =", t.tw.Name, t.tw.Type)
|
||||||
if (tw == nil) {
|
if (tw == nil) {
|
||||||
log(true, "commonChange() What the fuck. there is no widget t.tw == nil")
|
log(true, "commonChange() What the fuck. there is no widget t.tw == nil")
|
||||||
|
@ -15,23 +15,21 @@ func (t *andlabsT) commonChange(tw *toolkit.Widget) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tw.Custom()
|
tw.Custom()
|
||||||
|
|
||||||
|
if (andlabs[wId] == nil) {
|
||||||
|
log(debugError, "commonChange() ERROR: wId map == nil", wId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sendToChan(wId)
|
||||||
|
|
||||||
log(debugChange, "commonChange() END Widget.Custom()", t.tw.Name, t.tw.Type)
|
log(debugChange, "commonChange() END Widget.Custom()", t.tw.Name, t.tw.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dump(p *toolkit.Widget, c *toolkit.Widget, b bool) {
|
func sendToChan(i int) {
|
||||||
log(b, "Parent:")
|
if (callback == nil) {
|
||||||
pt := mapToolkits[p]
|
log(debugError, "commonChange() SHOULD SEND int back here, but callback == nil", i)
|
||||||
if (pt == nil) {
|
|
||||||
log(b, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pt.Dump(b)
|
log(debugError, "commonChange() Running callback() i =", i)
|
||||||
|
callback(i)
|
||||||
log(b, "Child:")
|
|
||||||
ct := mapToolkits[c]
|
|
||||||
if (ct == nil) {
|
|
||||||
log(b, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ct.Dump(b)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,21 @@ import "git.wit.org/wit/gui/toolkit"
|
||||||
|
|
||||||
// delete the child widget from the parent
|
// delete the child widget from the parent
|
||||||
// p = parent, c = child
|
// p = parent, c = child
|
||||||
func destroy(p *toolkit.Widget, c *toolkit.Widget) {
|
func destroy(pId int, cId int) {
|
||||||
log(true, "delete()", c.Name, c.Type)
|
log(true, "delete()", pId, cId)
|
||||||
|
|
||||||
pt := mapToolkits[p]
|
pt := andlabs[pId]
|
||||||
ct := mapToolkits[c]
|
ct := andlabs[cId]
|
||||||
if (ct == nil) {
|
if (ct == nil) {
|
||||||
log(true, "delete FAILED (ct = mapToolkit[c] == nil) for c", c.Name, c.Type)
|
log(true, "delete FAILED (ct = mapToolkit[c] == nil) for c", pId, cId)
|
||||||
// this pukes out a whole universe of shit
|
// this pukes out a whole universe of shit
|
||||||
// listMap()
|
// listMap()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ct.tw.Type {
|
switch ct.Type {
|
||||||
case toolkit.Button:
|
case toolkit.Button:
|
||||||
log(true, "Should delete Button here:", c.Name)
|
log(true, "Should delete Button here:", ct.Name)
|
||||||
log(true, "Parent:")
|
log(true, "Parent:")
|
||||||
pt.Dump(true)
|
pt.Dump(true)
|
||||||
log(true, "Child:")
|
log(true, "Child:")
|
||||||
|
@ -38,16 +38,15 @@ func destroy(p *toolkit.Widget, c *toolkit.Widget) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case toolkit.Window:
|
case toolkit.Window:
|
||||||
log(true, "Should delete Window here:", c.Name)
|
log(true, "Should delete Window here:", ct.Name)
|
||||||
default:
|
default:
|
||||||
log(true, "Don't know how to delete c =", c.Type, c.Name)
|
|
||||||
log(true, "Don't know how to delete pt =", pt.tw.Type, pt.tw.Name, pt.uiButton)
|
log(true, "Don't know how to delete pt =", pt.tw.Type, pt.tw.Name, pt.uiButton)
|
||||||
log(true, "Don't know how to delete ct =", ct.tw.Type, ct.tw.Name, ct.uiButton)
|
log(true, "Don't know how to delete ct =", ct.tw.Type, ct.tw.Name, ct.uiButton)
|
||||||
log(true, "Parent:")
|
log(true, "Parent:")
|
||||||
pt.Dump(true)
|
pt.Dump(true)
|
||||||
log(true, "Child:")
|
log(true, "Child:")
|
||||||
ct.Dump(true)
|
ct.Dump(true)
|
||||||
log(true, "Fuckit, let's destroy a button", c.Name, c.Type)
|
log(true, "Fuckit, let's destroy a button")
|
||||||
if (ct.uiButton != nil) {
|
if (ct.uiButton != nil) {
|
||||||
pt.uiBox.Delete(4)
|
pt.uiBox.Delete(4)
|
||||||
ct.uiButton.Destroy()
|
ct.uiButton.Destroy()
|
||||||
|
|
|
@ -6,11 +6,14 @@ import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
"git.wit.org/wit/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *andlabsT) newDropdown(w *toolkit.Widget) *andlabsT {
|
func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
|
||||||
var newt andlabsT
|
var newt andlabsT
|
||||||
log(debugToolkit, "gui.Toolbox.newDropdown() START", w.Name)
|
w := a.Widget
|
||||||
|
log(debugToolkit, "gui.Toolbox.newDropdown() START", a.Title)
|
||||||
|
|
||||||
newt.tw = w
|
newt.tw = w
|
||||||
|
newt.Type = w.Type
|
||||||
|
newt.wId = a.WidgetId
|
||||||
s := ui.NewCombobox()
|
s := ui.NewCombobox()
|
||||||
newt.uiCombobox = s
|
newt.uiCombobox = s
|
||||||
newt.uiControl = s
|
newt.uiControl = s
|
||||||
|
@ -26,7 +29,7 @@ func (t *andlabsT) newDropdown(w *toolkit.Widget) *andlabsT {
|
||||||
newt.text = "error"
|
newt.text = "error"
|
||||||
}
|
}
|
||||||
newt.tw.S = newt.val[i]
|
newt.tw.S = newt.val[i]
|
||||||
newt.commonChange(newt.tw)
|
newt.commonChange(newt.tw, a.WidgetId)
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
@ -53,9 +56,9 @@ func (t *andlabsT) SetDropdown(i int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddDropdownName(a *toolkit.Action) {
|
func AddDropdownName(a *toolkit.Action) {
|
||||||
log(debugToolkit, "gui.andlabs.AddDropdownName()", a.Widget.Name, "add:", a.S)
|
log(debugToolkit, "gui.andlabs.AddDropdownName()", a.WidgetId, "add:", a.S)
|
||||||
|
|
||||||
t := mapToolkits[a.Widget]
|
t := andlabs[a.WidgetId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", a.Widget.Name, a.S)
|
log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", a.Widget.Name, a.S)
|
||||||
listMap(debugToolkit)
|
listMap(debugToolkit)
|
||||||
|
@ -64,31 +67,30 @@ func AddDropdownName(a *toolkit.Action) {
|
||||||
t.AddDropdownName(a.S)
|
t.AddDropdownName(a.S)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetDropdownName(w *toolkit.Widget, s string) {
|
func SetDropdownName(a *toolkit.Action, s string) {
|
||||||
log(debugChange, "gui.andlabs.SetDropdown()", w.Name, ",", s)
|
log(debugChange, "gui.andlabs.SetDropdown()", a.WidgetId, ",", s)
|
||||||
|
|
||||||
t := mapToolkits[w]
|
t := andlabs[a.WidgetId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", w.Name, s)
|
log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", a.WidgetId, s)
|
||||||
listMap(debugError)
|
listMap(debugError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.SetDropdown(1)
|
t.SetDropdown(1)
|
||||||
|
// TODO: send back to wit/gui goroutine with the chan
|
||||||
t.tw.S = s
|
t.tw.S = s
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDropdown(a *toolkit.Action) {
|
func newDropdown(a *toolkit.Action) {
|
||||||
w := a.Widget
|
log(debugToolkit, "gui.andlabs.newDropdown()", a.Title)
|
||||||
parentW := a.Where
|
|
||||||
log(debugToolkit, "gui.andlabs.newDropdown()", w.Name)
|
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", parentW.Name, w.Name)
|
log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", a.WidgetId)
|
||||||
listMap(debugToolkit)
|
listMap(debugToolkit)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newt := t.newDropdown(w)
|
newt := t.newDropdown(a)
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
// mapWidgetsToolkits(a, newt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,7 @@ import (
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
func newGrid(a *toolkit.Action) {
|
func newGrid(a *toolkit.Action) {
|
||||||
var newt *andlabsT
|
var newt *andlabsT
|
||||||
log(debugToolkit, "newGrid()", a.Widget.Name, "to", a.Where.Type)
|
log(debugToolkit, "newGrid()", a.WidgetId, "to", a.WhereId)
|
||||||
|
|
||||||
t := mapToolkits[a.Where]
|
|
||||||
|
|
||||||
newt = new(andlabsT)
|
newt = new(andlabsT)
|
||||||
|
|
||||||
|
@ -24,9 +22,10 @@ func newGrid(a *toolkit.Action) {
|
||||||
newt.uiGrid = c
|
newt.uiGrid = c
|
||||||
newt.uiControl = c
|
newt.uiControl = c
|
||||||
newt.tw = a.Widget
|
newt.tw = a.Widget
|
||||||
|
newt.Type = toolkit.Grid
|
||||||
newt.gridX = 0
|
newt.gridX = 0
|
||||||
newt.gridY = 0
|
newt.gridY = 0
|
||||||
|
|
||||||
|
t := andlabs[a.WhereId]
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,17 +9,15 @@ import (
|
||||||
|
|
||||||
func newGroup(a *toolkit.Action) {
|
func newGroup(a *toolkit.Action) {
|
||||||
w := a.Widget
|
w := a.Widget
|
||||||
parentW := a.Where
|
|
||||||
log(debugToolkit, "NewGroup()", w.Name)
|
log(debugToolkit, "NewGroup()", w.Name)
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "NewGroup() toolkit struct == nil. name=", parentW.Name, w.Name)
|
log(debugToolkit, "NewGroup() toolkit struct == nil. name=", w.Name)
|
||||||
listMap(debugToolkit)
|
listMap(debugToolkit)
|
||||||
}
|
}
|
||||||
newt := t.rawGroup(w.Name)
|
newt := t.rawGroup(w.Name)
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make new Group here
|
// make new Group here
|
||||||
|
@ -34,13 +32,5 @@ func (t *andlabsT) rawGroup(title string) *andlabsT {
|
||||||
newt.uiGroup = g
|
newt.uiGroup = g
|
||||||
newt.uiControl = g
|
newt.uiControl = g
|
||||||
|
|
||||||
// hbox := ui.NewVerticalBox()
|
|
||||||
// hbox.SetPadded(padded)
|
|
||||||
// g.SetChild(hbox)
|
|
||||||
|
|
||||||
// newt.uiBox = hbox
|
|
||||||
// newt.uiWindow = t.uiWindow
|
|
||||||
// newt.uiTab = t.uiTab
|
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,17 +10,15 @@ import (
|
||||||
// make new Image here
|
// make new Image here
|
||||||
func newImage(a *toolkit.Action) {
|
func newImage(a *toolkit.Action) {
|
||||||
w := a.Widget
|
w := a.Widget
|
||||||
parentW := a.Where
|
|
||||||
log(debugToolkit, "newImage()", w.Name)
|
log(debugToolkit, "newImage()", w.Name)
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "newImage() toolkit struct == nil. name=", parentW.Name, w.Name)
|
log(debugToolkit, "newImage() toolkit struct == nil. name=", w.Name)
|
||||||
listMap(debugToolkit)
|
listMap(debugToolkit)
|
||||||
}
|
}
|
||||||
newt := t.rawImage(w.Name)
|
newt := t.rawImage(w.Name)
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make new Image using andlabs/ui
|
// make new Image using andlabs/ui
|
||||||
|
|
|
@ -12,7 +12,7 @@ func newLabel(a *toolkit.Action) {
|
||||||
w := a.Widget
|
w := a.Widget
|
||||||
log(debugToolkit, "NewLabel()", w.Name)
|
log(debugToolkit, "NewLabel()", w.Name)
|
||||||
|
|
||||||
t := mapToolkits[a.Where]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
listMap(debugError)
|
listMap(debugError)
|
||||||
log(debugError, "ERROR newLabel() listMap()")
|
log(debugError, "ERROR newLabel() listMap()")
|
||||||
|
@ -30,5 +30,4 @@ func newLabel(a *toolkit.Action) {
|
||||||
newt.uiControl = c
|
newt.uiControl = c
|
||||||
|
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,137 +1,25 @@
|
||||||
//
|
|
||||||
// version v1.2
|
|
||||||
//
|
|
||||||
// I like things to be easy.
|
|
||||||
//
|
|
||||||
// this means all the log settings are in one place. it should allow
|
|
||||||
// things to be over-ridden externally to the library
|
|
||||||
// but still allow command line --args to pass debugging settings
|
|
||||||
//
|
|
||||||
// I also have a generic sleep() and exit() in here because it's simple
|
|
||||||
//
|
|
||||||
// Usage:
|
|
||||||
//
|
|
||||||
// log("something", foo, bar)
|
|
||||||
// var DEBUG bool = true
|
|
||||||
// log(DEBUG, "something else", someOtherVariable) # if DEBUG == false, return doing nothing
|
|
||||||
// log(SPEW, "something else", someOtherVariable) # this get's sent to spew.Dump(). Very useful for debugging!
|
|
||||||
//
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
witlog "git.wit.org/wit/gui/log"
|
||||||
"runtime"
|
|
||||||
"runtime/pprof"
|
|
||||||
golog "log"
|
|
||||||
"time"
|
|
||||||
"reflect"
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
// "net"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var LOGOFF bool = false // turn this off, all logging stops
|
// various debugging flags
|
||||||
var WARN bool
|
var logNow bool = true // useful for active development
|
||||||
var INFO bool
|
var logError bool = true
|
||||||
|
var logWarn bool = false
|
||||||
type spewt struct {
|
var logInfo bool = false
|
||||||
a bool
|
var logVerbose bool = false
|
||||||
}
|
|
||||||
|
|
||||||
var SPEW spewt
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
sleep() # you know what this does? sleeps for 1 second. yep. dump. easy.
|
|
||||||
sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second
|
|
||||||
*/
|
|
||||||
func sleep(a ...any) {
|
|
||||||
if (a == nil) {
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log(true, "sleep", a[0])
|
|
||||||
|
|
||||||
switch a[0].(type) {
|
|
||||||
case int:
|
|
||||||
time.Sleep(time.Duration(a[0].(int)) * time.Second)
|
|
||||||
case float64:
|
|
||||||
time.Sleep(time.Duration(a[0].(float64) * 1000) * time.Millisecond)
|
|
||||||
default:
|
|
||||||
log("sleep a[0], type = ", a[0], reflect.TypeOf(a[0]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
exit() # yep. exits. I guess everything must be fine
|
|
||||||
exit(3) # I guess 3 it is then
|
|
||||||
exit("dont like apples") # ok. I'll make a note of that
|
|
||||||
*/
|
|
||||||
func exit(a ...any) {
|
|
||||||
log(true, "exit", a)
|
|
||||||
//if (a) {
|
|
||||||
// os.Exit(a)
|
|
||||||
//}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
I've spent, am spending, too much time thinking about 'logging'. 'log', 'logrus', 'zap', whatever.
|
|
||||||
I'm not twitter. i don't give a fuck about how many nanoseconds it takes to log. Anyway, this
|
|
||||||
implementation is probably faster than all of those because you just set one bool to FALSE
|
|
||||||
and it all stops.
|
|
||||||
Sometimes I need to capture to stdout, sometimes stdout can't
|
|
||||||
work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread
|
|
||||||
over 8 million references in every .go file. I'm tapping out and putting
|
|
||||||
it in one place. here it is. Also, this makes having debug levels really fucking easy.
|
|
||||||
You can define whatever level of logging you want from anywhere (command line) etc.
|
|
||||||
|
|
||||||
log() # doesn't do anything
|
|
||||||
log(stuff) # sends it to whatever log you define in a single place. here is the place
|
|
||||||
*/
|
|
||||||
|
|
||||||
func log(a ...any) {
|
func log(a ...any) {
|
||||||
if (LOGOFF) {
|
witlog.Where = "wit/gui/andlabs"
|
||||||
return
|
witlog.Log(a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a == nil) {
|
func sleep(a ...any) {
|
||||||
return
|
witlog.Sleep(a...)
|
||||||
}
|
|
||||||
var tbool bool
|
|
||||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(tbool)) {
|
|
||||||
if (a[0] == false) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
a[0] = "GUI/Toolkit/Andlabs"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) {
|
func exit(a ...any) {
|
||||||
// a = a[1:]
|
witlog.Exit(a...)
|
||||||
a[0] = "GUI/Toolkit/Andlabs"
|
|
||||||
if (debugToolkit) {
|
|
||||||
scs := spew.ConfigState{MaxDepth: 1}
|
|
||||||
scs.Dump(a)
|
|
||||||
// spew.Dump(a)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
golog.Println(a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func loggo() {
|
|
||||||
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
|
||||||
golog.Println("runtime.NumGoroutine() = ", runtime.NumGoroutine())
|
|
||||||
}
|
|
||||||
|
|
||||||
func logindent(depth int, format string, a ...interface{}) {
|
|
||||||
var tabs string
|
|
||||||
for i := 0; i < depth; i++ {
|
|
||||||
tabs = tabs + format
|
|
||||||
}
|
|
||||||
|
|
||||||
// newFormat := tabs + strconv.Itoa(depth) + " " + format
|
|
||||||
newFormat := tabs + format
|
|
||||||
log(debugToolkit, newFormat, a)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"git.wit.org/wit/gui/toolkit"
|
// "git.wit.org/wit/gui/toolkit"
|
||||||
|
|
||||||
"github.com/andlabs/ui"
|
"github.com/andlabs/ui"
|
||||||
// the _ means we only need this for the init()
|
// the _ means we only need this for the init()
|
||||||
|
@ -43,8 +43,10 @@ func Init() {
|
||||||
// log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
|
// log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
|
||||||
setDefaultBehavior(true)
|
setDefaultBehavior(true)
|
||||||
|
|
||||||
mapWidgets = make(map[*andlabsT]*toolkit.Widget)
|
// mapWidgets = make(map[*andlabsT]*toolkit.Widget)
|
||||||
mapToolkits = make(map[*toolkit.Widget]*andlabsT)
|
// mapToolkits = make(map[*toolkit.Widget]*andlabsT)
|
||||||
|
|
||||||
|
andlabs = make(map[int]*andlabsT)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: properly exit the plugin since Quit() doesn't do it
|
// TODO: properly exit the plugin since Quit() doesn't do it
|
||||||
|
|
|
@ -31,6 +31,13 @@ func Action(a *toolkit.Action) {
|
||||||
rawAction(a)
|
rawAction(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (callback == nil) {
|
||||||
|
if (a.Callback != nil) {
|
||||||
|
log(debugNow, "setting Callback", a.Callback)
|
||||||
|
callback = a.Callback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// f()
|
// f()
|
||||||
Queue(f)
|
Queue(f)
|
||||||
}
|
}
|
||||||
|
@ -41,27 +48,29 @@ func rawAction(a *toolkit.Action) {
|
||||||
log(debugAction, "Action() START a.S =", a.S)
|
log(debugAction, "Action() START a.S =", a.S)
|
||||||
log(debugAction, "Action() START a.Widget =", a.Widget)
|
log(debugAction, "Action() START a.Widget =", a.Widget)
|
||||||
|
|
||||||
|
log(logInfo, "Action() START a.WidgetId =", a.WidgetId, "a.WhereId =", a.WhereId)
|
||||||
|
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
case toolkit.Add:
|
case toolkit.Add:
|
||||||
add(a)
|
add(a)
|
||||||
case toolkit.Show:
|
case toolkit.Show:
|
||||||
a.Widget.B = true
|
a.Widget.B = true
|
||||||
show(a.Widget)
|
show(a)
|
||||||
case toolkit.Hide:
|
case toolkit.Hide:
|
||||||
a.Widget.B = false
|
a.Widget.B = false
|
||||||
show(a.Widget)
|
show(a)
|
||||||
case toolkit.Enable:
|
case toolkit.Enable:
|
||||||
a.Widget.B = true
|
a.Widget.B = true
|
||||||
enable(a.Widget)
|
enable(a)
|
||||||
case toolkit.Disable:
|
case toolkit.Disable:
|
||||||
a.Widget.B = false
|
a.Widget.B = false
|
||||||
enable(a.Widget)
|
enable(a)
|
||||||
case toolkit.Get:
|
case toolkit.Get:
|
||||||
setText(a)
|
setText(a)
|
||||||
case toolkit.GetText:
|
case toolkit.GetText:
|
||||||
switch a.Widget.Type {
|
switch a.Widget.Type {
|
||||||
case toolkit.Textbox:
|
case toolkit.Textbox:
|
||||||
t := mapToolkits[a.Widget]
|
t := andlabs[a.WidgetId]
|
||||||
a.S = t.s
|
a.S = t.s
|
||||||
}
|
}
|
||||||
case toolkit.Set:
|
case toolkit.Set:
|
||||||
|
@ -122,16 +131,15 @@ func flag(a *toolkit.Action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setText(a *toolkit.Action) {
|
func setText(a *toolkit.Action) {
|
||||||
w := a.Widget
|
t := andlabs[a.WidgetId]
|
||||||
if (w == nil) {
|
if (t == nil) {
|
||||||
log(debugError, "setText error. w.Widget == nil")
|
log(debugError, "setText error. andlabs[id] == nil", a.WidgetId)
|
||||||
actionDump(debugError, a)
|
actionDump(debugError, a)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t := mapToolkits[w]
|
log(debugChange, "setText() Attempt on", t.Type, "with", a.S)
|
||||||
log(debugChange, "setText() Attempt on", w.Type, "with", a.S)
|
|
||||||
|
|
||||||
switch w.Type {
|
switch t.Type {
|
||||||
case toolkit.Window:
|
case toolkit.Window:
|
||||||
t.uiWindow.SetTitle(a.S)
|
t.uiWindow.SetTitle(a.S)
|
||||||
case toolkit.Tab:
|
case toolkit.Tab:
|
||||||
|
@ -142,12 +150,13 @@ func setText(a *toolkit.Action) {
|
||||||
case toolkit.SetText:
|
case toolkit.SetText:
|
||||||
t.uiCheckbox.SetText(a.S)
|
t.uiCheckbox.SetText(a.S)
|
||||||
case toolkit.Get:
|
case toolkit.Get:
|
||||||
w.B = t.uiCheckbox.Checked()
|
t.tw.B = t.uiCheckbox.Checked()
|
||||||
case toolkit.Set:
|
case toolkit.Set:
|
||||||
t.uiCheckbox.SetChecked(a.B)
|
// TODO: commented out while working on chan
|
||||||
w.B = a.B
|
// t.uiCheckbox.SetChecked(a.B)
|
||||||
|
t.tw.B = a.B
|
||||||
default:
|
default:
|
||||||
log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name)
|
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name)
|
||||||
}
|
}
|
||||||
case toolkit.Textbox:
|
case toolkit.Textbox:
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
|
@ -156,11 +165,11 @@ func setText(a *toolkit.Action) {
|
||||||
case toolkit.SetText:
|
case toolkit.SetText:
|
||||||
t.uiMultilineEntry.SetText(a.S)
|
t.uiMultilineEntry.SetText(a.S)
|
||||||
case toolkit.Get:
|
case toolkit.Get:
|
||||||
w.S = t.s
|
t.tw.S = t.s
|
||||||
case toolkit.GetText:
|
case toolkit.GetText:
|
||||||
w.S = t.s
|
t.tw.S = t.s
|
||||||
default:
|
default:
|
||||||
log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name)
|
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name)
|
||||||
}
|
}
|
||||||
case toolkit.Label:
|
case toolkit.Label:
|
||||||
t.uiLabel.SetText(a.S)
|
t.uiLabel.SetText(a.S)
|
||||||
|
@ -169,20 +178,20 @@ func setText(a *toolkit.Action) {
|
||||||
case toolkit.Slider:
|
case toolkit.Slider:
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
case toolkit.Get:
|
case toolkit.Get:
|
||||||
w.I = t.uiSlider.Value()
|
t.tw.I = t.uiSlider.Value()
|
||||||
case toolkit.Set:
|
case toolkit.Set:
|
||||||
t.uiSlider.SetValue(a.I)
|
t.uiSlider.SetValue(a.I)
|
||||||
default:
|
default:
|
||||||
log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name)
|
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name)
|
||||||
}
|
}
|
||||||
case toolkit.Spinner:
|
case toolkit.Spinner:
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
case toolkit.Get:
|
case toolkit.Get:
|
||||||
w.I = t.uiSpinbox.Value()
|
t.tw.I = t.uiSpinbox.Value()
|
||||||
case toolkit.Set:
|
case toolkit.Set:
|
||||||
t.uiSpinbox.SetValue(a.I)
|
t.uiSpinbox.SetValue(a.I)
|
||||||
default:
|
default:
|
||||||
log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name)
|
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name)
|
||||||
}
|
}
|
||||||
case toolkit.Dropdown:
|
case toolkit.Dropdown:
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
|
@ -199,7 +208,7 @@ func setText(a *toolkit.Action) {
|
||||||
log(debugChange, "i, s", i, s)
|
log(debugChange, "i, s", i, s)
|
||||||
if (a.S == s) {
|
if (a.S == s) {
|
||||||
t.uiCombobox.SetSelected(i)
|
t.uiCombobox.SetSelected(i)
|
||||||
log(debugChange, "setText() Dropdown worked.", w.S)
|
log(debugChange, "setText() Dropdown worked.", t.tw.S)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,11 +222,11 @@ func setText(a *toolkit.Action) {
|
||||||
t.uiCombobox.SetSelected(i)
|
t.uiCombobox.SetSelected(i)
|
||||||
}
|
}
|
||||||
case toolkit.Get:
|
case toolkit.Get:
|
||||||
w.S = t.s
|
t.tw.S = t.s
|
||||||
case toolkit.GetText:
|
case toolkit.GetText:
|
||||||
w.S = t.s
|
t.tw.S = t.s
|
||||||
default:
|
default:
|
||||||
log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name)
|
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name)
|
||||||
}
|
}
|
||||||
case toolkit.Combobox:
|
case toolkit.Combobox:
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
|
@ -230,13 +239,13 @@ func setText(a *toolkit.Action) {
|
||||||
t.uiEditableCombobox.SetText(a.S)
|
t.uiEditableCombobox.SetText(a.S)
|
||||||
t.s = a.S
|
t.s = a.S
|
||||||
case toolkit.Get:
|
case toolkit.Get:
|
||||||
w.S = t.s
|
t.tw.S = t.s
|
||||||
case toolkit.GetText:
|
case toolkit.GetText:
|
||||||
w.S = t.s
|
t.tw.S = t.s
|
||||||
default:
|
default:
|
||||||
log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name)
|
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log(debugError, "plugin Send() Don't know how to setText on", w.Type, "yet", a.Type)
|
log(debugError, "plugin Send() Don't know how to setText on", t.tw.Type, "yet", a.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,19 +7,21 @@ import (
|
||||||
_ "github.com/andlabs/ui/winmanifest"
|
_ "github.com/andlabs/ui/winmanifest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *andlabsT) newSlider(w *toolkit.Widget) *andlabsT {
|
func (t *andlabsT) newSlider(a *toolkit.Action) *andlabsT {
|
||||||
// make new node here
|
|
||||||
log(debugToolkit, w.Name, w.Type, w.X, w.Y)
|
|
||||||
var newt andlabsT
|
var newt andlabsT
|
||||||
|
w := a.Widget
|
||||||
|
log(debugToolkit, w.Name, w.Type, w.X, w.Y)
|
||||||
|
|
||||||
s := ui.NewSlider(w.X, w.Y)
|
s := ui.NewSlider(w.X, w.Y)
|
||||||
newt.uiSlider = s
|
newt.uiSlider = s
|
||||||
newt.uiControl = s
|
newt.uiControl = s
|
||||||
newt.tw = w
|
newt.tw = w
|
||||||
|
newt.Type = toolkit.Slider
|
||||||
|
newt.wId = a.WidgetId
|
||||||
|
|
||||||
s.OnChanged(func(spin *ui.Slider) {
|
s.OnChanged(func(spin *ui.Slider) {
|
||||||
newt.tw.I = newt.uiSlider.Value()
|
newt.tw.I = newt.uiSlider.Value()
|
||||||
newt.commonChange(newt.tw)
|
newt.commonChange(newt.tw, a.WidgetId)
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
@ -28,17 +30,15 @@ func (t *andlabsT) newSlider(w *toolkit.Widget) *andlabsT {
|
||||||
func newSlider(a *toolkit.Action) {
|
func newSlider(a *toolkit.Action) {
|
||||||
var newt *andlabsT
|
var newt *andlabsT
|
||||||
w := a.Widget
|
w := a.Widget
|
||||||
parentW := a.Where
|
|
||||||
log(debugToolkit, "newSlider()", w.Name)
|
log(debugToolkit, "newSlider()", w.Name)
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugError, "newSlider() ERROR toolkit struct == nil. name=", parentW.Name, w.Name)
|
log(debugError, "newSlider() ERROR toolkit struct == nil. name=", w.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.X = a.X
|
w.X = a.X
|
||||||
w.Y = a.Y
|
w.Y = a.Y
|
||||||
newt = t.newSlider(w)
|
newt = t.newSlider(a)
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,19 +7,21 @@ import (
|
||||||
_ "github.com/andlabs/ui/winmanifest"
|
_ "github.com/andlabs/ui/winmanifest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *andlabsT) newSpinner(w *toolkit.Widget) *andlabsT {
|
func (t *andlabsT) newSpinner(a *toolkit.Action) *andlabsT {
|
||||||
// make new node here
|
|
||||||
log(debugToolkit, "newSpinner()", w.X, w.Y)
|
|
||||||
var newt andlabsT
|
var newt andlabsT
|
||||||
|
w := a.Widget
|
||||||
|
log(debugToolkit, "newSpinner()", w.X, w.Y)
|
||||||
|
|
||||||
s := ui.NewSpinbox(w.X, w.Y)
|
s := ui.NewSpinbox(w.X, w.Y)
|
||||||
newt.uiSpinbox = s
|
newt.uiSpinbox = s
|
||||||
newt.uiControl = s
|
newt.uiControl = s
|
||||||
newt.tw = w
|
newt.tw = w
|
||||||
|
newt.wId = a.WidgetId
|
||||||
|
newt.Type = toolkit.Spinner
|
||||||
|
|
||||||
s.OnChanged(func(s *ui.Spinbox) {
|
s.OnChanged(func(s *ui.Spinbox) {
|
||||||
newt.tw.I = newt.uiSpinbox.Value()
|
newt.tw.I = newt.uiSpinbox.Value()
|
||||||
newt.commonChange(newt.tw)
|
newt.commonChange(newt.tw, a.WidgetId)
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
@ -28,16 +30,14 @@ func (t *andlabsT) newSpinner(w *toolkit.Widget) *andlabsT {
|
||||||
func newSpinner(a *toolkit.Action) {
|
func newSpinner(a *toolkit.Action) {
|
||||||
var newt *andlabsT
|
var newt *andlabsT
|
||||||
w := a.Widget
|
w := a.Widget
|
||||||
parentW := a.Where
|
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugError, "NewSpinner() toolkit struct == nil. name=", parentW.Name, w.Name)
|
log(debugError, "NewSpinner() toolkit struct == nil. name=", w.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.X = a.X
|
w.X = a.X
|
||||||
w.Y = a.Y
|
w.Y = a.Y
|
||||||
newt = t.newSpinner(w)
|
newt = t.newSpinner(a)
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,19 @@ import "git.wit.org/wit/gui/toolkit"
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
import _ "github.com/andlabs/ui/winmanifest"
|
import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
|
var andlabs map[int]*andlabsT
|
||||||
|
var callback func(int)
|
||||||
|
|
||||||
// stores the raw toolkit internals
|
// stores the raw toolkit internals
|
||||||
type andlabsT struct {
|
type andlabsT struct {
|
||||||
id string
|
wId int // widget ID
|
||||||
|
Type toolkit.WidgetType
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
// Type toolkit.WidgetType
|
// Type toolkit.WidgetType
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
|
|
||||||
tw *toolkit.Widget
|
tw *toolkit.Widget
|
||||||
parent *andlabsT
|
parent *andlabsT
|
||||||
|
|
||||||
|
|
|
@ -19,36 +19,43 @@ import (
|
||||||
once there is one. If you send a Window here, it will replace
|
once there is one. If you send a Window here, it will replace
|
||||||
any existing tabs rather than adding a new one
|
any existing tabs rather than adding a new one
|
||||||
*/
|
*/
|
||||||
func (t *andlabsT) newTab(name string) *andlabsT {
|
func (t *andlabsT) newTab(a *toolkit.Action) {
|
||||||
// var w *ui.Window
|
// var w *ui.Window
|
||||||
var newt *andlabsT
|
var newt *andlabsT
|
||||||
|
|
||||||
log(debugToolkit, "gui.toolkit.AddTab()")
|
log(debugToolkit, "newTab() START", a.WidgetId, a.WhereId)
|
||||||
|
|
||||||
if (t.uiWindow == nil) {
|
|
||||||
log(debugToolkit, "gui.Toolkit.UiWindow == nil. I can't add a toolbar without window")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.uiTab == nil) {
|
if (t.uiTab == nil) {
|
||||||
|
if (t.uiWindow == nil) {
|
||||||
|
log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", a.WidgetId, a.WhereId)
|
||||||
|
return
|
||||||
|
}
|
||||||
// this means you have to make a new tab
|
// this means you have to make a new tab
|
||||||
log(debugToolkit, "gui.toolkit.NewTab() GOOD. This should be the first tab:", name)
|
log(debugToolkit, "newTab() GOOD. This should be the first tab:", a.WidgetId, a.WhereId)
|
||||||
newt = rawTab(t.uiWindow, name)
|
newt = rawTab(t.uiWindow, a.Title)
|
||||||
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(debugToolkit, "gui.toolkit.NewTab() GOOD. This should be an additional tab:", name)
|
log(debugToolkit, "newTab() GOOD. This should be an additional tab:", a.WidgetId, a.WhereId)
|
||||||
newt = t.appendTab(name)
|
newt = t.appendTab(a.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
newt.Name = name
|
// add the structure to the array
|
||||||
|
if (andlabs[a.WidgetId] == nil) {
|
||||||
|
log(logInfo, "newTab() MAPPED", a.WidgetId, a.WhereId)
|
||||||
|
andlabs[a.WidgetId] = newt
|
||||||
|
newt.Type = a.Widget.Type
|
||||||
|
} else {
|
||||||
|
log(debugError, "newTab() DO WHAT?", a.WidgetId, a.WhereId)
|
||||||
|
log(debugError, "THIS IS BAD")
|
||||||
|
}
|
||||||
|
|
||||||
|
newt.Name = a.Title
|
||||||
|
|
||||||
log(debugToolkit, "t:")
|
log(debugToolkit, "t:")
|
||||||
t.Dump(debugToolkit)
|
t.Dump(debugToolkit)
|
||||||
log(debugToolkit, "newt:")
|
log(debugToolkit, "newt:")
|
||||||
newt.Dump(debugToolkit)
|
newt.Dump(debugToolkit)
|
||||||
|
|
||||||
return newt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This sets _all_ the tabs to Margin = true
|
// This sets _all_ the tabs to Margin = true
|
||||||
|
@ -64,29 +71,21 @@ func tabSetMargined(tab *ui.Tab, b bool) {
|
||||||
|
|
||||||
func rawTab(w *ui.Window, name string) *andlabsT {
|
func rawTab(w *ui.Window, name string) *andlabsT {
|
||||||
var newt andlabsT
|
var newt andlabsT
|
||||||
log(debugToolkit, "gui.toolkit.NewTab() ADD", name)
|
log(debugToolkit, "rawTab() START", name)
|
||||||
|
|
||||||
if (w == nil) {
|
if (w == nil) {
|
||||||
log(debugToolkit, "gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
|
log(debugError, "UiWindow == nil. I can't add a tab without a window")
|
||||||
log(debugToolkit, "gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
|
log(debugError, "UiWindow == nil. I can't add a tab without a window")
|
||||||
log(debugToolkit, "gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
|
log(debugError, "UiWindow == nil. I can't add a tab without a window")
|
||||||
sleep(1)
|
sleep(1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log(debugToolkit, "gui.toolkit.AddTab() START name =", name)
|
|
||||||
tab := ui.NewTab()
|
tab := ui.NewTab()
|
||||||
w.SetMargined(margin)
|
|
||||||
|
|
||||||
hbox := ui.NewHorizontalBox() // this makes everything go along the horizon
|
|
||||||
hbox.SetPadded(padded)
|
|
||||||
tab.Append(name, hbox)
|
|
||||||
tabSetMargined(tab, margin) // TODO: run this in the right place(?)
|
|
||||||
w.SetChild(tab)
|
w.SetChild(tab)
|
||||||
|
|
||||||
newt.uiWindow = w
|
|
||||||
newt.uiTab = tab
|
newt.uiTab = tab
|
||||||
newt.uiControl = tab
|
newt.uiControl = tab
|
||||||
newt.uiBox = hbox
|
log(debugToolkit, "rawTab() END", name)
|
||||||
return &newt
|
return &newt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,20 +119,14 @@ func (t *andlabsT) appendTab(name string) *andlabsT {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTab(a *toolkit.Action) {
|
func newTab(a *toolkit.Action) {
|
||||||
parentW := a.Where
|
// w := a.Widget
|
||||||
w := a.Widget
|
log(debugToolkit, "newTab()", a.WhereId)
|
||||||
var newt *andlabsT
|
|
||||||
log(debugToolkit, "gui.andlabs.NewTab()", w.Name)
|
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "go.andlabs.NewTab() toolkit struct == nil. name=", parentW.Name, w.Name)
|
log(debugToolkit, "newTab() parent toolkit == nil. new tab can not be made =", a.WhereId)
|
||||||
|
log(debugToolkit, "look for a window? check for an existing tab?")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newt = t.newTab(w.Name)
|
t.newTab(a)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
|
||||||
|
|
||||||
func doTab(a *toolkit.Action) {
|
|
||||||
newTab(a)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ func (t *andlabsT) newTextbox(w *toolkit.Widget) *andlabsT {
|
||||||
|
|
||||||
newt.Name = w.Name
|
newt.Name = w.Name
|
||||||
newt.tw = w
|
newt.tw = w
|
||||||
|
newt.Type = toolkit.Textbox
|
||||||
|
|
||||||
c.OnChanged(func(spin *ui.MultilineEntry) {
|
c.OnChanged(func(spin *ui.MultilineEntry) {
|
||||||
t.s = spin.Text()
|
t.s = spin.Text()
|
||||||
|
@ -29,16 +30,14 @@ func (t *andlabsT) newTextbox(w *toolkit.Widget) *andlabsT {
|
||||||
|
|
||||||
func newTextbox(a *toolkit.Action) {
|
func newTextbox(a *toolkit.Action) {
|
||||||
w := a.Widget
|
w := a.Widget
|
||||||
parentW := a.Where
|
|
||||||
log(debugToolkit, "newCombobox()", w.Name)
|
log(debugToolkit, "newCombobox()", w.Name)
|
||||||
|
|
||||||
t := mapToolkits[parentW]
|
t := andlabs[a.WhereId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugToolkit, "newCombobox() toolkit struct == nil. name=", parentW.Name, w.Name)
|
log(debugToolkit, "newCombobox() toolkit struct == nil. name=", w.Name)
|
||||||
listMap(debugToolkit)
|
listMap(debugToolkit)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newt := t.newTextbox(w)
|
newt := t.newTextbox(w)
|
||||||
place(a, t, newt)
|
place(a, t, newt)
|
||||||
mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,69 +1,24 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
// "git.wit.org/wit/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This is a map between the widgets in wit/gui and the internal structures of gocui
|
// This is a map between the widgets in wit/gui and the internal structures of gocui
|
||||||
|
|
||||||
var mapWidgets map[*andlabsT]*toolkit.Widget
|
// var mapWidgets map[*andlabsT]*toolkit.Widget
|
||||||
var mapToolkits map[*toolkit.Widget]*andlabsT
|
// var mapToolkits map[*toolkit.Widget]*andlabsT
|
||||||
|
|
||||||
// This lists out the known mappings
|
// This lists out the known mappings
|
||||||
// deprecate and use instead the GUI interface
|
// deprecate and use instead the GUI interface
|
||||||
func listMap(b bool) {
|
func listMap(b bool) {
|
||||||
log(b, "listMap() disabled HERE. output too big")
|
log(b, "listMap() disabled HERE. output too big")
|
||||||
return
|
return
|
||||||
for t, w := range mapWidgets {
|
|
||||||
log(b, "andlabs =", t.Name, "widget =", w.Name)
|
|
||||||
}
|
|
||||||
log(b, "listMap() HERE mapToolkits()")
|
log(b, "listMap() HERE mapToolkits()")
|
||||||
for w, t := range mapToolkits {
|
for i, t := range andlabs {
|
||||||
log(b, "andlabs =", t, "widget =", w.Name)
|
log(b, "andlabs =", t, "widgetId =", i)
|
||||||
t.Dump(b)
|
t.Dump(b)
|
||||||
}
|
}
|
||||||
log(b, "listMap() HERE mapWidgets()")
|
log(b, "listMap() HERE mapWidgets()")
|
||||||
log(b, "listMap() HERE FIXME. output too big")
|
log(b, "listMap() HERE FIXME. output too big")
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapWidgetsToolkits(a *toolkit.Action, t *andlabsT) {
|
|
||||||
w := a.Widget
|
|
||||||
if ((mapToolkits[w] == nil) && (mapWidgets[t] == nil)) {
|
|
||||||
log(debugToolkit, "map a new widget", w, t)
|
|
||||||
mapToolkits[w] = t
|
|
||||||
mapWidgets[t] = w
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mapToolkits[w] != nil) {
|
|
||||||
tw := mapToolkits[w]
|
|
||||||
if (tw == nil) {
|
|
||||||
// logic corruption somewhere? Have you been deleting things recently?
|
|
||||||
log(true, "mapToolkits[w] is set, but mapWidgets[t] is nil")
|
|
||||||
panic("WTF mapWidgets[t] == nil")
|
|
||||||
}
|
|
||||||
log(debugToolkit, "mapToolkits[w] is", tw)
|
|
||||||
if (tw == nil) {
|
|
||||||
log(debugError, "BAD map? mapWidgets[w] tw == nil")
|
|
||||||
} else {
|
|
||||||
log(debugError, "BAD map? mapWidgets[w] is", tw)
|
|
||||||
tw.Dump(debugError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mapWidgets[t] != nil) {
|
|
||||||
wt := mapWidgets[t]
|
|
||||||
if (mapToolkits[w] == nil) {
|
|
||||||
// logic corruption somewhere? Have you been deleting things recently?
|
|
||||||
log(true, "mapWidgets[t] is set, but mapToolkits[w] is nil")
|
|
||||||
panic("WTF mapToolkits[w] == nil")
|
|
||||||
}
|
|
||||||
if (wt == nil) {
|
|
||||||
log(debugError, "BAD map? mapWidgets[t] wt == nil")
|
|
||||||
} else {
|
|
||||||
log(debugError, "BAD map? mapWidgets[t] is", wt)
|
|
||||||
widgetDump(debugError, wt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log(debugToolkit, "map of widget worked", w.Type, ",", w.Name)
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,13 +27,15 @@ func newWindow(a *toolkit.Action) {
|
||||||
}
|
}
|
||||||
newt = new(andlabsT)
|
newt = new(andlabsT)
|
||||||
newt.tw = w
|
newt.tw = w
|
||||||
|
newt.Type = toolkit.Window
|
||||||
|
newt.wId = a.WidgetId
|
||||||
|
|
||||||
// menubar bool is if the OS defined border on the window should be used
|
// menubar bool is if the OS defined border on the window should be used
|
||||||
win := ui.NewWindow(w.Name, w.Width, w.Height, menubar)
|
win := ui.NewWindow(w.Name, w.Width, w.Height, menubar)
|
||||||
win.SetBorderless(canvas)
|
win.SetBorderless(canvas)
|
||||||
win.SetMargined(margin)
|
win.SetMargined(margin)
|
||||||
win.OnClosing(func(*ui.Window) bool {
|
win.OnClosing(func(*ui.Window) bool {
|
||||||
newt.commonChange(newt.tw)
|
newt.commonChange(newt.tw, a.WidgetId)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
win.Show()
|
win.Show()
|
||||||
|
@ -42,16 +44,17 @@ func newWindow(a *toolkit.Action) {
|
||||||
// newt.UiWindowBad = win // deprecate this as soon as possible
|
// newt.UiWindowBad = win // deprecate this as soon as possible
|
||||||
newt.Name = w.Name
|
newt.Name = w.Name
|
||||||
|
|
||||||
mapWidgetsToolkits(a, newt)
|
andlabs[a.WidgetId] = newt
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *andlabsT) SetWindowTitle(title string) {
|
func (t *andlabsT) SetWindowTitle(title string) {
|
||||||
log(debugToolkit, "toolkit NewWindow", t.Name, "title", title)
|
log(debugToolkit, "toolkit NewWindow", t.Name, "title", title)
|
||||||
win := t.uiWindow
|
win := t.uiWindow
|
||||||
if (win != nil) {
|
if (win == nil) {
|
||||||
win.SetTitle(title)
|
log(debugError, "Error: no window", t.wId)
|
||||||
} else {
|
} else {
|
||||||
|
win.SetTitle(title)
|
||||||
log(debugToolkit, "Setting the window title", title)
|
log(debugToolkit, "Setting the window title", title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,135 +1,22 @@
|
||||||
//
|
|
||||||
// version v1.3
|
|
||||||
//
|
|
||||||
// I like things to be easy.
|
|
||||||
//
|
|
||||||
// combining logging inside of a gui made me do this
|
|
||||||
//
|
|
||||||
// this means all the log settings are in one place. it should allow
|
|
||||||
// things to be over-ridden externally to the library
|
|
||||||
// but still allow command line --args to pass debugging settings
|
|
||||||
//
|
|
||||||
// I also have a generic sleep() and exit() in here because it's simple
|
|
||||||
//
|
|
||||||
// Usage:
|
|
||||||
//
|
|
||||||
// log("something", foo, bar)
|
|
||||||
// var DEBUG bool = true
|
|
||||||
// log(DEBUG, "something else", someOtherVariable) # if DEBUG == false, return doing nothing
|
|
||||||
// log(SPEW, "something else", someOtherVariable) # this get's sent to spew.Dump(). Very useful for debugging!
|
|
||||||
//
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
golog "log"
|
witlog "git.wit.org/wit/gui/log"
|
||||||
"time"
|
|
||||||
"reflect"
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var LOGOFF bool = false // turn this off, all logging stops
|
|
||||||
var WARN bool
|
|
||||||
var INFO bool
|
|
||||||
|
|
||||||
type spewt struct {
|
|
||||||
a bool
|
|
||||||
}
|
|
||||||
|
|
||||||
var SPEW spewt
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
sleep() # you know what this does? sleeps for 1 second. yep. dump. easy.
|
|
||||||
sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second
|
|
||||||
*/
|
|
||||||
func sleep(a ...any) {
|
|
||||||
if (a == nil) {
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log(true, "sleep", a[0])
|
|
||||||
|
|
||||||
switch a[0].(type) {
|
|
||||||
case int:
|
|
||||||
time.Sleep(time.Duration(a[0].(int)) * time.Second)
|
|
||||||
case float64:
|
|
||||||
time.Sleep(time.Duration(a[0].(float64) * 1000) * time.Millisecond)
|
|
||||||
default:
|
|
||||||
log("sleep a[0], type = ", a[0], reflect.TypeOf(a[0]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
exit() # yep. exits. I guess everything must be fine
|
|
||||||
exit(3) # I guess 3 it is then
|
|
||||||
exit("dont like apples") # ok. I'll make a note of that
|
|
||||||
*/
|
|
||||||
func exit(a ...any) {
|
|
||||||
log(true, "exit", a)
|
|
||||||
//if (a) {
|
|
||||||
// os.Exit(a)
|
|
||||||
//}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
I've spent, am spending, too much time thinking about 'logging'. 'log', 'logrus', 'zap', whatever.
|
|
||||||
I'm not twitter. i don't give a fuck about how many nanoseconds it takes to log. Anyway, this
|
|
||||||
implementation is probably faster than all of those because you just set one bool to FALSE
|
|
||||||
and it all stops.
|
|
||||||
Sometimes I need to capture to stdout, sometimes stdout can't
|
|
||||||
work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread
|
|
||||||
over 8 million references in every .go file. I'm tapping out and putting
|
|
||||||
it in one place. here it is. Also, this makes having debug levels really fucking easy.
|
|
||||||
You can define whatever level of logging you want from anywhere (command line) etc.
|
|
||||||
|
|
||||||
log() # doesn't do anything
|
|
||||||
log(stuff) # sends it to whatever log you define in a single place. here is the place
|
|
||||||
*/
|
|
||||||
|
|
||||||
func log(a ...any) {
|
func log(a ...any) {
|
||||||
if (LOGOFF) {
|
witlog.Log(a...)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a == nil) {
|
func sleep(a ...any) {
|
||||||
return
|
witlog.Sleep(a...)
|
||||||
}
|
|
||||||
var tbool bool
|
|
||||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(tbool)) {
|
|
||||||
if (a[0] == false) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
a[0] = "GUI/Toolkit/gocui"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) {
|
func exit(a ...any) {
|
||||||
// a = a[1:]
|
witlog.Exit(a...)
|
||||||
a[0] = "GUI/Toolkit/gocui"
|
|
||||||
if (debugToolkit) {
|
|
||||||
scs := spew.ConfigState{MaxDepth: 1}
|
|
||||||
scs.Dump(a)
|
|
||||||
// spew.Dump(a)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
golog.Println(a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func logindent(depth int, format string, a ...interface{}) {
|
|
||||||
var tabs string
|
|
||||||
for i := 0; i < depth; i++ {
|
|
||||||
tabs = tabs + format
|
|
||||||
}
|
|
||||||
|
|
||||||
// newFormat := tabs + strconv.Itoa(depth) + " " + format
|
|
||||||
newFormat := tabs + format
|
|
||||||
log(debugToolkit, newFormat, a)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setOutput(f *os.File) {
|
func setOutput(f *os.File) {
|
||||||
golog.SetOutput(f)
|
witlog.SetOutput(f)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,135 +1,22 @@
|
||||||
//
|
|
||||||
// version v1.3
|
|
||||||
//
|
|
||||||
// I like things to be easy.
|
|
||||||
//
|
|
||||||
// combining logging inside of a gui made me do this
|
|
||||||
//
|
|
||||||
// this means all the log settings are in one place. it should allow
|
|
||||||
// things to be over-ridden externally to the library
|
|
||||||
// but still allow command line --args to pass debugging settings
|
|
||||||
//
|
|
||||||
// I also have a generic sleep() and exit() in here because it's simple
|
|
||||||
//
|
|
||||||
// Usage:
|
|
||||||
//
|
|
||||||
// log("something", foo, bar)
|
|
||||||
// var DEBUG bool = true
|
|
||||||
// log(DEBUG, "something else", someOtherVariable) # if DEBUG == false, return doing nothing
|
|
||||||
// log(SPEW, "something else", someOtherVariable) # this get's sent to spew.Dump(). Very useful for debugging!
|
|
||||||
//
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
golog "log"
|
witlog "git.wit.org/wit/gui/log"
|
||||||
"time"
|
|
||||||
"reflect"
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var LOGOFF bool = false // turn this off, all logging stops
|
|
||||||
var WARN bool
|
|
||||||
var INFO bool
|
|
||||||
|
|
||||||
type spewt struct {
|
|
||||||
a bool
|
|
||||||
}
|
|
||||||
|
|
||||||
var SPEW spewt
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
sleep() # you know what this does? sleeps for 1 second. yep. dump. easy.
|
|
||||||
sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second
|
|
||||||
*/
|
|
||||||
func sleep(a ...any) {
|
|
||||||
if (a == nil) {
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log(true, "sleep", a[0])
|
|
||||||
|
|
||||||
switch a[0].(type) {
|
|
||||||
case int:
|
|
||||||
time.Sleep(time.Duration(a[0].(int)) * time.Second)
|
|
||||||
case float64:
|
|
||||||
time.Sleep(time.Duration(a[0].(float64) * 1000) * time.Millisecond)
|
|
||||||
default:
|
|
||||||
log("sleep a[0], type = ", a[0], reflect.TypeOf(a[0]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
exit() # yep. exits. I guess everything must be fine
|
|
||||||
exit(3) # I guess 3 it is then
|
|
||||||
exit("dont like apples") # ok. I'll make a note of that
|
|
||||||
*/
|
|
||||||
func exit(a ...any) {
|
|
||||||
log(true, "exit", a)
|
|
||||||
//if (a) {
|
|
||||||
// os.Exit(a)
|
|
||||||
//}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
I've spent, am spending, too much time thinking about 'logging'. 'log', 'logrus', 'zap', whatever.
|
|
||||||
I'm not twitter. i don't give a fuck about how many nanoseconds it takes to log. Anyway, this
|
|
||||||
implementation is probably faster than all of those because you just set one bool to FALSE
|
|
||||||
and it all stops.
|
|
||||||
Sometimes I need to capture to stdout, sometimes stdout can't
|
|
||||||
work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread
|
|
||||||
over 8 million references in every .go file. I'm tapping out and putting
|
|
||||||
it in one place. here it is. Also, this makes having debug levels really fucking easy.
|
|
||||||
You can define whatever level of logging you want from anywhere (command line) etc.
|
|
||||||
|
|
||||||
log() # doesn't do anything
|
|
||||||
log(stuff) # sends it to whatever log you define in a single place. here is the place
|
|
||||||
*/
|
|
||||||
|
|
||||||
func log(a ...any) {
|
func log(a ...any) {
|
||||||
if (LOGOFF) {
|
witlog.Log(a...)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a == nil) {
|
func sleep(a ...any) {
|
||||||
return
|
witlog.Sleep(a...)
|
||||||
}
|
|
||||||
var tbool bool
|
|
||||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(tbool)) {
|
|
||||||
if (a[0] == false) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
a[0] = "GUI/Toolkit/gocui"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) {
|
func exit(a ...any) {
|
||||||
// a = a[1:]
|
witlog.Exit(a...)
|
||||||
a[0] = "GUI/Toolkit/gocui"
|
|
||||||
if (debugToolkit) {
|
|
||||||
scs := spew.ConfigState{MaxDepth: 1}
|
|
||||||
scs.Dump(a)
|
|
||||||
// spew.Dump(a)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
golog.Println(a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func logindent(depth int, format string, a ...interface{}) {
|
|
||||||
var tabs string
|
|
||||||
for i := 0; i < depth; i++ {
|
|
||||||
tabs = tabs + format
|
|
||||||
}
|
|
||||||
|
|
||||||
// newFormat := tabs + strconv.Itoa(depth) + " " + format
|
|
||||||
newFormat := tabs + format
|
|
||||||
log(debugToolkit, newFormat, a)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setOutput(f *os.File) {
|
func setOutput(f *os.File) {
|
||||||
golog.SetOutput(f)
|
witlog.SetOutput(f)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ type ActionType int
|
||||||
// Could a protobuf be used here? (Can functions be passed?)
|
// Could a protobuf be used here? (Can functions be passed?)
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
Name string
|
Name string
|
||||||
// Action string // "New", "Delete", "Set", aka something to do
|
|
||||||
Type WidgetType
|
Type WidgetType
|
||||||
|
|
||||||
// This function is how you interact with the toolkit
|
// This function is how you interact with the toolkit
|
||||||
|
@ -57,14 +56,17 @@ type Widget struct {
|
||||||
|
|
||||||
type Action struct {
|
type Action struct {
|
||||||
Type ActionType
|
Type ActionType
|
||||||
|
ActionT ActionType
|
||||||
|
WidgetT WidgetType
|
||||||
|
|
||||||
|
WidgetId int
|
||||||
|
WhereId int
|
||||||
|
Title string
|
||||||
|
|
||||||
// this should be the widget
|
// this should be the widget
|
||||||
// if the action is New, Hide, Enable, etc
|
// if the action is New, Hide, Enable, etc
|
||||||
Widget *Widget
|
Widget *Widget
|
||||||
|
Callback func(int)
|
||||||
// this is the widget
|
|
||||||
// where the other one should be put on New, Move, etc
|
|
||||||
Where *Widget
|
|
||||||
|
|
||||||
// This is how the values are passed back and forth
|
// This is how the values are passed back and forth
|
||||||
// values from things like checkboxes & dropdown's
|
// values from things like checkboxes & dropdown's
|
||||||
|
|
Loading…
Reference in New Issue