move to go.wit.com/log !!!
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
84897041b2
commit
df5fd148c6
51
args.go
51
args.go
|
@ -3,9 +3,14 @@ package gui
|
||||||
import (
|
import (
|
||||||
arg "github.com/alexflint/go-arg"
|
arg "github.com/alexflint/go-arg"
|
||||||
|
|
||||||
newlog "go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var GUI log.LogFlag
|
||||||
|
var NODE log.LogFlag
|
||||||
|
var PLUG log.LogFlag
|
||||||
|
var INFO log.LogFlag
|
||||||
|
|
||||||
var argGui ArgsGui
|
var argGui ArgsGui
|
||||||
|
|
||||||
// This struct can be used with the go-arg package
|
// This struct can be used with the go-arg package
|
||||||
|
@ -14,17 +19,41 @@ type ArgsGui struct {
|
||||||
GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"`
|
GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
arg.Register(&argGui)
|
|
||||||
|
|
||||||
newlog.Register("gui", "debugGui", &debugGui)
|
|
||||||
|
|
||||||
for _, s := range newlog.ListFlags() {
|
|
||||||
newlog.Info("go.wit.com/gui/gui ListFlags() returned:", s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns the toolkit
|
// returns the toolkit
|
||||||
func ArgToolkit() string {
|
func ArgToolkit() string {
|
||||||
return argGui.GuiPlugin
|
return argGui.GuiPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
arg.Register(&argGui)
|
||||||
|
|
||||||
|
log.Register("gui", "debugGui", &debugGui)
|
||||||
|
|
||||||
|
INFO.B = false
|
||||||
|
INFO.Name = "INFO"
|
||||||
|
INFO.Subsystem = "gui"
|
||||||
|
INFO.Desc = "Enable log.Info()"
|
||||||
|
INFO.Register()
|
||||||
|
|
||||||
|
GUI.B = false
|
||||||
|
GUI.Name = "GUI"
|
||||||
|
GUI.Subsystem = "gui"
|
||||||
|
GUI.Desc = "basic GUI debugging"
|
||||||
|
GUI.Register()
|
||||||
|
|
||||||
|
NODE.B = false
|
||||||
|
NODE.Name = "NODE"
|
||||||
|
NODE.Subsystem = "gui"
|
||||||
|
NODE.Desc = "basic NODE debugging"
|
||||||
|
NODE.Register()
|
||||||
|
|
||||||
|
PLUG.B = false
|
||||||
|
PLUG.Name = "PLUG"
|
||||||
|
PLUG.Subsystem = "gui"
|
||||||
|
PLUG.Desc = "basic PLUG debugging"
|
||||||
|
PLUG.Register()
|
||||||
|
|
||||||
|
for _, s := range log.ListFlags() {
|
||||||
|
log.Info("go.wit.com/gui/gui ListFlags() returned:", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
66
debug.go
66
debug.go
|
@ -4,7 +4,10 @@ package gui
|
||||||
// A function dump out the binary tree
|
// A function dump out the binary tree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,12 +32,6 @@ func SetDebug (s bool) {
|
||||||
debugGui = s
|
debugGui = s
|
||||||
debugTabs = s
|
debugTabs = s
|
||||||
|
|
||||||
logNow = s
|
|
||||||
logInfo = s
|
|
||||||
logWarn = s
|
|
||||||
logError = s
|
|
||||||
logVerbose = s
|
|
||||||
|
|
||||||
SetFlag("Node", s)
|
SetFlag("Node", s)
|
||||||
SetFlag("Tabs", s)
|
SetFlag("Tabs", s)
|
||||||
SetFlag("Dump", s)
|
SetFlag("Dump", s)
|
||||||
|
@ -68,7 +65,7 @@ func SetFlag (s string, b bool) {
|
||||||
case "Show":
|
case "Show":
|
||||||
// ShowDebugValues() // print them here?
|
// ShowDebugValues() // print them here?
|
||||||
default:
|
default:
|
||||||
log(debugGui, "Can't set unknown flag", s)
|
log.Log(GUI, "Can't set unknown flag", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
a := new(toolkit.Action)
|
a := new(toolkit.Action)
|
||||||
|
@ -82,20 +79,19 @@ func SetFlag (s string, b bool) {
|
||||||
func ShowDebugValues() {
|
func ShowDebugValues() {
|
||||||
// The order here should match the order in the GUI
|
// The order here should match the order in the GUI
|
||||||
// TODO: get the order from the node binary tree
|
// TODO: get the order from the node binary tree
|
||||||
log(true, "Debug =", debugGui)
|
log.Log(true, "Debug =", debugGui)
|
||||||
log(true, "DebugError =", debugError)
|
log.Log(true, "DebugError =", debugError)
|
||||||
log(true, "DebugChange =", debugChange)
|
log.Log(true, "DebugChange =", debugChange)
|
||||||
log(true, "DebugDump =", debugDump)
|
log.Log(true, "DebugDump =", debugDump)
|
||||||
log(true, "DebugTabs =", debugTabs)
|
log.Log(true, "DebugTabs =", debugTabs)
|
||||||
log(true, "DebugPlugin =", debugPlugin)
|
log.Log(true, "DebugPlugin =", debugPlugin)
|
||||||
log(true, "DebugNode =", debugNode)
|
log.Log(true, "DebugNode =", debugNode)
|
||||||
|
|
||||||
SetFlag("Show", true)
|
SetFlag("Show", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) Dump() {
|
func (n *Node) Dump() {
|
||||||
b := true
|
b := true
|
||||||
// log("Dump() dump =", b)
|
|
||||||
Indent(b, "NODE DUMP START")
|
Indent(b, "NODE DUMP START")
|
||||||
Indent(b, "id = ", n.id)
|
Indent(b, "id = ", n.id)
|
||||||
Indent(b, "Name = ", n.Name)
|
Indent(b, "Name = ", n.Name)
|
||||||
|
@ -129,7 +125,7 @@ func (n *Node) dumpWidget(b bool) string {
|
||||||
var info, d string
|
var info, d string
|
||||||
|
|
||||||
if (n == nil) {
|
if (n == nil) {
|
||||||
log(debugError, "dumpWidget() node == nil")
|
log.Error(errors.New("dumpWidget() node == nil"))
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
info = n.WidgetType.String()
|
info = n.WidgetType.String()
|
||||||
|
@ -159,32 +155,32 @@ func (n *Node) ListChildren(dump bool) {
|
||||||
if (n.parent == nil) {
|
if (n.parent == nil) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log(debugNode, "\t\t\tparent =",n.parent.id)
|
log.Log(NODE, "\t\t\tparent =",n.parent.id)
|
||||||
if (listChildrenParent != nil) {
|
if (listChildrenParent != nil) {
|
||||||
log(debugNode, "\t\t\tlistChildrenParent =",listChildrenParent.id)
|
log.Log(NODE, "\t\t\tlistChildrenParent =",listChildrenParent.id)
|
||||||
if (listChildrenParent.id != n.parent.id) {
|
if (listChildrenParent.id != n.parent.id) {
|
||||||
log(true, "parent =",n.parent.id, n.parent.Name)
|
log.Log(true, "parent =",n.parent.id, n.parent.Name)
|
||||||
log(true, "listChildrenParent =",listChildrenParent.id, listChildrenParent.Name)
|
log.Log(true, "listChildrenParent =",listChildrenParent.id, listChildrenParent.Name)
|
||||||
log(true, listChildrenParent.id, "!=", n.parent.id)
|
log.Log(true, listChildrenParent.id, "!=", n.parent.id)
|
||||||
exit("parent.child does not match child.parent")
|
log.Exit("parent.child does not match child.parent")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log(debugNode, "\t\t", n.id, "has no children")
|
log.Log(NODE, "\t\t", n.id, "has no children")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, child := range n.children {
|
for _, child := range n.children {
|
||||||
if (child.parent != nil) {
|
if (child.parent != nil) {
|
||||||
log(debugNode, "\t\t\tparent =",child.parent.id)
|
log.Log(NODE, "\t\t\tparent =",child.parent.id)
|
||||||
} else {
|
} else {
|
||||||
log(debugGui, "\t\t\tno parent")
|
log.Log(GUI, "\t\t\tno parent")
|
||||||
// memory corruption? non-threadsafe access?
|
// memory corruption? non-threadsafe access?
|
||||||
// can all binary tree changes to Node.parent & Node.child be forced into a singular goroutine?
|
// can all binary tree changes to Node.parent & Node.child be forced into a singular goroutine?
|
||||||
panic("something is wrong with the wit golang gui logic and the binary tree is broken. child has no parent")
|
panic("something is wrong with the wit golang gui logic and the binary tree is broken. child has no parent")
|
||||||
}
|
}
|
||||||
if (child.children == nil) {
|
if (child.children == nil) {
|
||||||
log(debugNode, "\t\t", child.id, "has no children")
|
log.Log(NODE, "\t\t", child.id, "has no children")
|
||||||
} else {
|
} else {
|
||||||
log(debugNode, "\t\t\tHas children:", child.children)
|
log.Log(NODE, "\t\t\tHas children:", child.children)
|
||||||
}
|
}
|
||||||
listChildrenParent = n
|
listChildrenParent = n
|
||||||
listChildrenDepth += 1
|
listChildrenDepth += 1
|
||||||
|
@ -194,3 +190,19 @@ func (n *Node) ListChildren(dump bool) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// b bool, print if true
|
||||||
|
func logindent(b bool, depth int, format string, a ...any) {
|
||||||
|
var tabs string
|
||||||
|
for i := 0; i < depth; i++ {
|
||||||
|
tabs = tabs + format
|
||||||
|
}
|
||||||
|
|
||||||
|
// newFormat := tabs + strconv.Itoa(depth) + " " + format
|
||||||
|
newFormat := tabs + format
|
||||||
|
|
||||||
|
// array prepend(). Why isn't this a standard function. It should be:
|
||||||
|
// a.prepend(debugGui, newFormat)
|
||||||
|
a = append([]any{b, newFormat}, a...)
|
||||||
|
log.Log(b, a...)
|
||||||
|
}
|
||||||
|
|
3
grid.go
3
grid.go
|
@ -1,6 +1,7 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ func (n *Node) At(w int, h int) *Node {
|
||||||
|
|
||||||
n.gridIncrement()
|
n.gridIncrement()
|
||||||
if (n.NextW != w) || (n.NextH != h) {
|
if (n.NextW != w) || (n.NextH != h) {
|
||||||
log(logError, "At() (W,H)", w, h, " was moved to avoid a collision (W,H) =", n.NextW, n.NextH)
|
log.Warn("At() (W,H)", w, h, " was moved to avoid a collision (W,H) =", n.NextW, n.NextH)
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
43
log.go
43
log.go
|
@ -1,43 +0,0 @@
|
||||||
package gui
|
|
||||||
|
|
||||||
import (
|
|
||||||
witlog "go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
// various debugging flags
|
|
||||||
var logNow bool = true // useful for active development
|
|
||||||
var logError bool = true
|
|
||||||
var logWarn bool = false
|
|
||||||
var logInfo bool = false
|
|
||||||
var logVerbose bool = false
|
|
||||||
|
|
||||||
// var log interface{}
|
|
||||||
|
|
||||||
func log(b bool, a ...any) {
|
|
||||||
// witlog.Where = "wit/gui"
|
|
||||||
witlog.Log(b, a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sleep(a ...any) {
|
|
||||||
witlog.Sleep(a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func exit(a ...any) {
|
|
||||||
witlog.Exit(a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// b bool, print if true
|
|
||||||
func logindent(b bool, depth int, format string, a ...any) {
|
|
||||||
var tabs string
|
|
||||||
for i := 0; i < depth; i++ {
|
|
||||||
tabs = tabs + format
|
|
||||||
}
|
|
||||||
|
|
||||||
// newFormat := tabs + strconv.Itoa(depth) + " " + format
|
|
||||||
newFormat := tabs + format
|
|
||||||
|
|
||||||
// array prepend(). Why isn't this a standard function. It should be:
|
|
||||||
// a.prepend(debugGui, newFormat)
|
|
||||||
a = append([]any{b, newFormat}, a...)
|
|
||||||
witlog.Log(b, a...)
|
|
||||||
}
|
|
148
log/log.go
148
log/log.go
|
@ -1,148 +0,0 @@
|
||||||
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
|
|
||||||
//
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"runtime/pprof"
|
|
||||||
golog "log"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
"reflect"
|
|
||||||
// "net"
|
|
||||||
)
|
|
||||||
|
|
||||||
// various debugging flags
|
|
||||||
var LogNow bool = true // useful for active development
|
|
||||||
var LogError bool = true
|
|
||||||
var LogWarn bool = false
|
|
||||||
var LogInfo bool = false
|
|
||||||
var LogVerbose bool = false
|
|
||||||
var LogSleep bool = false
|
|
||||||
|
|
||||||
var LOGOFF bool = false // turn this off, all logging stops
|
|
||||||
var debugToolkit bool = false // does spew stuff?
|
|
||||||
|
|
||||||
var Where string = "gui/log"
|
|
||||||
|
|
||||||
var externalLog func(...any)
|
|
||||||
|
|
||||||
type Spewt struct {
|
|
||||||
a bool
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
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(LogSleep, "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(LogError, "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
|
|
||||||
}
|
|
||||||
|
|
||||||
golog.Println(a...)
|
|
||||||
if (externalLog == nil) {
|
|
||||||
// golog.Println(a...)
|
|
||||||
} else {
|
|
||||||
externalLog(fmt.Sprint(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(w io.Writer) {
|
|
||||||
golog.SetOutput(w)
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetToolkitOutput(newLog func(...any)) {
|
|
||||||
externalLog = newLog
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package witlog
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
// Attempt to switch logging to syslog on linux
|
|
||||||
//
|
|
||||||
|
|
||||||
// This struct can be used with the go-arg package
|
|
||||||
type LogArgs struct {
|
|
||||||
Log []string `arg:"--log" help:"Where to log [syslog,stdout]"`
|
|
||||||
}
|
|
58
main.go
58
main.go
|
@ -3,6 +3,7 @@ package gui
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ const Xaxis = 0 // stack things horizontally
|
||||||
const Yaxis = 1 // stack things vertically
|
const Yaxis = 1 // stack things vertically
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log(true, "init() has been run")
|
log.Log(true, "init() has been run")
|
||||||
|
|
||||||
me.counter = 0
|
me.counter = 0
|
||||||
me.prefix = "wit"
|
me.prefix = "wit"
|
||||||
|
@ -36,28 +37,29 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func watchCallback() {
|
func watchCallback() {
|
||||||
log(logInfo, "watchCallback() START")
|
log.Info("watchCallback() START")
|
||||||
for {
|
for {
|
||||||
log(logInfo, "watchCallback() restarted select for toolkit user events")
|
log.Info("watchCallback() restarted select for toolkit user events")
|
||||||
select {
|
select {
|
||||||
case a := <-me.guiChan:
|
case a := <-me.guiChan:
|
||||||
if (a.ActionType == toolkit.UserQuit) {
|
if (a.ActionType == toolkit.UserQuit) {
|
||||||
log(logInfo, "doUserEvent() User sent Quit()")
|
log.Info("doUserEvent() User sent Quit()")
|
||||||
me.rootNode.doCustom()
|
me.rootNode.doCustom()
|
||||||
exit("wit/gui toolkit.UserQuit")
|
log.Exit("wit/gui toolkit.UserQuit")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if (a.ActionType == toolkit.EnableDebug) {
|
if (a.ActionType == toolkit.EnableDebug) {
|
||||||
log(logInfo, "doUserEvent() Enable Debugging Window")
|
log.Warn("doUserEvent() Enable Debugging Window")
|
||||||
|
log.Warn("doUserEvent() TODO: not implemented")
|
||||||
// DebugWindow()
|
// DebugWindow()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
n := me.rootNode.FindId(a.WidgetId)
|
n := me.rootNode.FindId(a.WidgetId)
|
||||||
if (n == nil) {
|
if (n == nil) {
|
||||||
log(logError, "watchCallback() UNKNOWN widget id =", a.WidgetId, a.Name)
|
log.Warn("watchCallback() UNKNOWN widget id =", a.WidgetId, a.Name)
|
||||||
} else {
|
} else {
|
||||||
log(logInfo, "watchCallback() FOUND widget id =", n.id, n.Name)
|
log.Info("watchCallback() FOUND widget id =", n.id, n.Name)
|
||||||
n.doUserEvent(a)
|
n.doUserEvent(a)
|
||||||
}
|
}
|
||||||
// this maybe a good idea?
|
// this maybe a good idea?
|
||||||
|
@ -68,49 +70,49 @@ func watchCallback() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) doCustom() {
|
func (n *Node) doCustom() {
|
||||||
log(logInfo, "doUserEvent() widget =", n.id, n.Name, n.WidgetType, n.B)
|
log.Info("doUserEvent() widget =", n.id, n.Name, n.WidgetType, n.B)
|
||||||
if (n.Custom == nil) {
|
if (n.Custom == nil) {
|
||||||
log(debugError, "Custom() = nil. SKIPPING")
|
log.Warn("Custom() = nil. SKIPPING")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go n.Custom()
|
go n.Custom()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) doUserEvent(a toolkit.Action) {
|
func (n *Node) doUserEvent(a toolkit.Action) {
|
||||||
log(logInfo, "doUserEvent() node =", n.id, n.Name)
|
log.Info("doUserEvent() node =", n.id, n.Name)
|
||||||
switch n.WidgetType {
|
switch n.WidgetType {
|
||||||
case toolkit.Checkbox:
|
case toolkit.Checkbox:
|
||||||
n.B = a.B
|
n.B = a.B
|
||||||
log(logInfo, "doUserEvent() node =", n.id, n.Name, "set to:", n.B)
|
log.Info("doUserEvent() node =", n.id, n.Name, "set to:", n.B)
|
||||||
n.doCustom()
|
n.doCustom()
|
||||||
case toolkit.Button:
|
case toolkit.Button:
|
||||||
log(logInfo, "doUserEvent() node =", n.id, n.Name, "button clicked")
|
log.Info("doUserEvent() node =", n.id, n.Name, "button clicked")
|
||||||
n.doCustom()
|
n.doCustom()
|
||||||
case toolkit.Combobox:
|
case toolkit.Combobox:
|
||||||
n.S = a.S
|
n.S = a.S
|
||||||
log(logInfo, "doUserEvent() node =", n.id, n.Name, "set to:", n.S)
|
log.Info("doUserEvent() node =", n.id, n.Name, "set to:", n.S)
|
||||||
n.doCustom()
|
n.doCustom()
|
||||||
case toolkit.Dropdown:
|
case toolkit.Dropdown:
|
||||||
n.S = a.S
|
n.S = a.S
|
||||||
log(logInfo, "doUserEvent() node =", n.id, n.Name, "set to:", n.S)
|
log.Info("doUserEvent() node =", n.id, n.Name, "set to:", n.S)
|
||||||
n.doCustom()
|
n.doCustom()
|
||||||
case toolkit.Textbox:
|
case toolkit.Textbox:
|
||||||
n.S = a.S
|
n.S = a.S
|
||||||
log(logInfo, "doUserEvent() node =", n.id, n.Name, "set to:", n.S)
|
log.Info("doUserEvent() node =", n.id, n.Name, "set to:", n.S)
|
||||||
n.doCustom()
|
n.doCustom()
|
||||||
case toolkit.Spinner:
|
case toolkit.Spinner:
|
||||||
n.I = a.I
|
n.I = a.I
|
||||||
log(logInfo, "doUserEvent() node =", n.id, n.Name, "set to:", n.I)
|
log.Info("doUserEvent() node =", n.id, n.Name, "set to:", n.I)
|
||||||
n.doCustom()
|
n.doCustom()
|
||||||
case toolkit.Slider:
|
case toolkit.Slider:
|
||||||
n.I = a.I
|
n.I = a.I
|
||||||
log(logInfo, "doUserEvent() node =", n.id, n.Name, "set to:", n.I)
|
log.Info("doUserEvent() node =", n.id, n.Name, "set to:", n.I)
|
||||||
n.doCustom()
|
n.doCustom()
|
||||||
case toolkit.Window:
|
case toolkit.Window:
|
||||||
log(logInfo, "doUserEvent() node =", n.id, n.Name, "window closed")
|
log.Info("doUserEvent() node =", n.id, n.Name, "window closed")
|
||||||
n.doCustom()
|
n.doCustom()
|
||||||
default:
|
default:
|
||||||
log(logInfo, "doUserEvent() type =", n.WidgetType)
|
log.Info("doUserEvent() type =", n.WidgetType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,14 +127,14 @@ func New() *Node {
|
||||||
// try to load andlabs, if that doesn't work, fall back to the console
|
// try to load andlabs, if that doesn't work, fall back to the console
|
||||||
func (n *Node) Default() *Node {
|
func (n *Node) Default() *Node {
|
||||||
if (argGui.GuiPlugin != "") {
|
if (argGui.GuiPlugin != "") {
|
||||||
log(logError, "New.Default() try toolkit =", argGui.GuiPlugin)
|
log.Warn("New.Default() try toolkit =", argGui.GuiPlugin)
|
||||||
return n.LoadToolkit(argGui.GuiPlugin)
|
return n.LoadToolkit(argGui.GuiPlugin)
|
||||||
}
|
}
|
||||||
// if DISPLAY isn't set, return since gtk can't load
|
// if DISPLAY isn't set, return since gtk can't load
|
||||||
// TODO: figure out how to check what to do in macos and mswindows
|
// TODO: figure out how to check what to do in macos and mswindows
|
||||||
if (os.Getenv("DISPLAY") == "") {
|
if (os.Getenv("DISPLAY") == "") {
|
||||||
if (n.LoadToolkit("gocui") == nil) {
|
if (n.LoadToolkit("gocui") == nil) {
|
||||||
log(logError, "New() failed to load gocui")
|
log.Warn("New() failed to load gocui")
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
@ -145,17 +147,17 @@ func (n *Node) Default() *Node {
|
||||||
|
|
||||||
// The window is destroyed but the application does not quit
|
// The window is destroyed but the application does not quit
|
||||||
func (n *Node) StandardClose() {
|
func (n *Node) StandardClose() {
|
||||||
log(debugGui, "wit/gui Standard Window Close. name =", n.Name)
|
log.Log(GUI, "wit/gui Standard Window Close. name =", n.Name)
|
||||||
log(debugGui, "wit/gui Standard Window Close. n.Custom exit =", n.Custom)
|
log.Log(GUI, "wit/gui Standard Window Close. n.Custom exit =", n.Custom)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The window is destroyed and the application exits
|
// The window is destroyed and the application exits
|
||||||
// TODO: properly exit the plugin since Quit() doesn't do it
|
// TODO: properly exit the plugin since Quit() doesn't do it
|
||||||
func StandardExit() {
|
func StandardExit() {
|
||||||
log(true, "wit/gui Standard Window Exit. running os.Exit()")
|
log.Log(true, "wit/gui Standard Window Exit. running os.Exit()")
|
||||||
log(true, "StandardExit() attempt to exit each toolkit plugin")
|
log.Log(true, "StandardExit() attempt to exit each toolkit plugin")
|
||||||
for i, plug := range allPlugins {
|
for i, plug := range allPlugins {
|
||||||
log(true, "NewButton()", i, plug)
|
log.Log(true, "NewButton()", i, plug)
|
||||||
}
|
}
|
||||||
exit(0)
|
log.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
13
node.go
13
node.go
|
@ -1,6 +1,9 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import "go.wit.com/gui/gui/toolkit"
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
|
"go.wit.com/gui/gui/toolkit"
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
generic function to create a new node on the binary tree
|
generic function to create a new node on the binary tree
|
||||||
|
@ -30,7 +33,7 @@ func addNode(title string) *Node {
|
||||||
n.Name = title
|
n.Name = title
|
||||||
n.Text = title
|
n.Text = title
|
||||||
n.id = me.counter
|
n.id = me.counter
|
||||||
log(debugNode, "addNode = widget setid =", n.id)
|
log.Log(NODE, "addNode = widget setid =", n.id)
|
||||||
|
|
||||||
me.counter += 1
|
me.counter += 1
|
||||||
return n
|
return n
|
||||||
|
@ -42,12 +45,12 @@ func (n *Node) Parent() *Node {
|
||||||
|
|
||||||
func (n *Node) Delete(d *Node) {
|
func (n *Node) Delete(d *Node) {
|
||||||
for i, child := range n.children {
|
for i, child := range n.children {
|
||||||
log(debugNode, "\t", i, child.id, child.Name)
|
log.Log(NODE, "\t", i, child.id, child.Name)
|
||||||
if (child.id == d.id) {
|
if (child.id == d.id) {
|
||||||
log(debugNode, "\t\t Deleting this")
|
log.Log(NODE, "\t\t Deleting this")
|
||||||
n.children = append(n.children[:i], n.children[i+1:]...)
|
n.children = append(n.children[:i], n.children[i+1:]...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log(debugError, "did not find node to delete", d.id, d.Name)
|
log.Warn("did not find node to delete", d.id, d.Name)
|
||||||
}
|
}
|
||||||
|
|
66
plugin.go
66
plugin.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"plugin"
|
"plugin"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,12 +51,12 @@ var allPlugins []*aplug
|
||||||
// loads and initializes a toolkit (andlabs/ui, gocui, etc)
|
// loads and initializes a toolkit (andlabs/ui, gocui, etc)
|
||||||
// attempts to locate the .so file
|
// attempts to locate the .so file
|
||||||
func initPlugin(name string) *aplug {
|
func initPlugin(name string) *aplug {
|
||||||
log(logInfo, "initPlugin() START")
|
log.Log(PLUG, "initPlugin() START")
|
||||||
|
|
||||||
for _, aplug := range allPlugins {
|
for _, aplug := range allPlugins {
|
||||||
log(debugGui, "initPlugin() already loaded toolkit plugin =", aplug.name)
|
log.Log(PLUG, "initPlugin() already loaded toolkit plugin =", aplug.name)
|
||||||
if (aplug.name == name) {
|
if (aplug.name == name) {
|
||||||
log(debugError, "initPlugin() SKIPPING", name, "as you can't load it twice")
|
log.Warn("initPlugin() SKIPPING", name, "as you can't load it twice")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,13 +72,13 @@ func getPluginChannel(p *aplug, funcName string) func() chan toolkit.Action {
|
||||||
|
|
||||||
test, err = p.plug.Lookup(funcName)
|
test, err = p.plug.Lookup(funcName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(debugGui, "DID NOT FIND: name =", test, "err =", err)
|
log.Error(err, "DID NOT FIND: name =", test)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
newfunc, ok = test.(func() chan toolkit.Action)
|
newfunc, ok = test.(func() chan toolkit.Action)
|
||||||
if !ok {
|
if !ok {
|
||||||
log(debugGui, "function name =", funcName, "names didn't map correctly. Fix the plugin name =", p.name)
|
log.Log(PLUG, "function name =", funcName, "names didn't map correctly. Fix the plugin name =", p.name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return newfunc
|
return newfunc
|
||||||
|
@ -90,13 +91,13 @@ func sendCallback(p *aplug, funcName string) func(chan toolkit.Action) {
|
||||||
|
|
||||||
test, err = p.plug.Lookup(funcName)
|
test, err = p.plug.Lookup(funcName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(debugGui, "DID NOT FIND: name =", test, "err =", err)
|
log.Error(err, "DID NOT FIND: name =", test)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
newfunc, ok = test.(func(chan toolkit.Action))
|
newfunc, ok = test.(func(chan toolkit.Action))
|
||||||
if !ok {
|
if !ok {
|
||||||
log(debugGui, "function name =", funcName, "names didn't map correctly. Fix the plugin name =", p.name)
|
log.Log(PLUG, "function name =", funcName, "names didn't map correctly. Fix the plugin name =", p.name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return newfunc
|
return newfunc
|
||||||
|
@ -120,7 +121,7 @@ func searchPaths(name string) *aplug {
|
||||||
pfile, err = me.resFS.ReadFile(filename)
|
pfile, err = me.resFS.ReadFile(filename)
|
||||||
if (err == nil) {
|
if (err == nil) {
|
||||||
filename = "/tmp/" + name + ".so"
|
filename = "/tmp/" + name + ".so"
|
||||||
log(logError, "write out file here", name, filename, len(pfile))
|
log.Error(err, "write out file here", name, filename, len(pfile))
|
||||||
f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
|
f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
f.Write(pfile)
|
f.Write(pfile)
|
||||||
f.Close()
|
f.Close()
|
||||||
|
@ -129,7 +130,7 @@ func searchPaths(name string) *aplug {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log(logError, filename, "was not embedded in the binary. Error:", err)
|
log.Error(err, filename, "was not embedded in the binary")
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempt to write out the file from the internal resource
|
// attempt to write out the file from the internal resource
|
||||||
|
@ -141,7 +142,7 @@ func searchPaths(name string) *aplug {
|
||||||
|
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(logError, "searchPaths() error. exiting here?")
|
log.Error(err, "searchPaths() error. exiting here?")
|
||||||
} else {
|
} else {
|
||||||
filename = homeDir + "/go/src/go.wit.com/gui/toolkits/" + name + ".so"
|
filename = homeDir + "/go/src/go.wit.com/gui/toolkits/" + name + ".so"
|
||||||
p = initToolkit(name, filename)
|
p = initToolkit(name, filename)
|
||||||
|
@ -152,7 +153,7 @@ func searchPaths(name string) *aplug {
|
||||||
|
|
||||||
homeDir, err = os.UserHomeDir()
|
homeDir, err = os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(logError, "searchPaths() error. exiting here?")
|
log.Error(err, "searchPaths() error. exiting here?")
|
||||||
} else {
|
} else {
|
||||||
filename = homeDir + "/go/src/go.wit.com/toolkits/" + name + ".so"
|
filename = homeDir + "/go/src/go.wit.com/toolkits/" + name + ".so"
|
||||||
p = initToolkit(name, filename)
|
p = initToolkit(name, filename)
|
||||||
|
@ -180,18 +181,18 @@ func searchPaths(name string) *aplug {
|
||||||
func initToolkit(name string, filename string) *aplug {
|
func initToolkit(name string, filename string) *aplug {
|
||||||
if _, err := os.Stat(filename); err != nil {
|
if _, err := os.Stat(filename); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
log(true, "missing plugin", name, "as filename", filename)
|
log.Log(true, "missing plugin", name, "as filename", filename)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log(true, "Found plugin", name, "as filename", filename)
|
log.Log(true, "Found plugin", name, "as filename", filename)
|
||||||
|
|
||||||
plug, err := plugin.Open(filename)
|
plug, err := plugin.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(debugError, "plugin FAILED =", filename, err)
|
log.Error(err, "plugin FAILED =", filename)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log(debugPlugin, "initToolkit() loading plugin =", filename)
|
log.Log(PLUG, "initToolkit() loading plugin =", filename)
|
||||||
|
|
||||||
var newPlug *aplug
|
var newPlug *aplug
|
||||||
newPlug = new(aplug)
|
newPlug = new(aplug)
|
||||||
|
@ -214,12 +215,12 @@ func initToolkit(name string, filename string) *aplug {
|
||||||
// set the communication to the plugins
|
// set the communication to the plugins
|
||||||
newPlug.pluginChan = newPlug.PluginChannel()
|
newPlug.pluginChan = newPlug.PluginChannel()
|
||||||
if (newPlug.pluginChan == nil) {
|
if (newPlug.pluginChan == nil) {
|
||||||
log(debugError, "initToolkit() ERROR PluginChannel() returned nil for plugin:", newPlug.name, filename)
|
log.Warn("initToolkit() ERROR PluginChannel() returned nil for plugin:", newPlug.name, filename)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
newPlug.Callback(me.guiChan)
|
newPlug.Callback(me.guiChan)
|
||||||
|
|
||||||
log(debugPlugin, "initToolkit() END", newPlug.name, filename)
|
log.Log(PLUG, "initToolkit() END", newPlug.name, filename)
|
||||||
return newPlug
|
return newPlug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,16 +256,16 @@ func newAction(n *Node, atype toolkit.ActionType) *toolkit.Action {
|
||||||
// sends the action/event to each toolkit via a golang plugin channel
|
// sends the action/event to each toolkit via a golang plugin channel
|
||||||
func sendAction(a *toolkit.Action) {
|
func sendAction(a *toolkit.Action) {
|
||||||
for _, aplug := range allPlugins {
|
for _, aplug := range allPlugins {
|
||||||
log(debugPlugin, "Action() aplug =", aplug.name, "Action type=", a.ActionType)
|
log.Log(PLUG, "Action() aplug =", aplug.name, "Action type=", a.ActionType)
|
||||||
if (aplug.pluginChan == nil) {
|
if (aplug.pluginChan == nil) {
|
||||||
log(logInfo, "Action() retrieving the aplug.PluginChannel()", aplug.name)
|
log.Info("Action() retrieving the aplug.PluginChannel()", aplug.name)
|
||||||
aplug.pluginChan = aplug.PluginChannel()
|
aplug.pluginChan = aplug.PluginChannel()
|
||||||
log(logInfo, "Action() retrieved", aplug.pluginChan)
|
log.Info("Action() retrieved", aplug.pluginChan)
|
||||||
}
|
}
|
||||||
log(logInfo, "Action() SEND to pluginChan", aplug.name)
|
log.Info("Action() SEND to pluginChan", aplug.name)
|
||||||
aplug.pluginChan <- *a
|
aplug.pluginChan <- *a
|
||||||
// added during debugging. might be a good idea in general for a tactile experience
|
// added during debugging. might be a good idea in general for a tactile experience
|
||||||
sleep(.02) // this delay makes it so SetText() works on initial widget creation
|
log.Sleep(.02) // this delay makes it so SetText() works on initial widget creation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,15 +276,16 @@ func (n *Node) InitEmbed(resFS embed.FS) *Node {
|
||||||
|
|
||||||
func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node {
|
func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node {
|
||||||
for _, aplug := range allPlugins {
|
for _, aplug := range allPlugins {
|
||||||
log(logInfo, "LoadToolkitEmbed() already loaded toolkit plugin =", aplug.name)
|
log.Info("LoadToolkitEmbed() already loaded toolkit plugin =", aplug.name)
|
||||||
if (aplug.name == name) {
|
if (aplug.name == name) {
|
||||||
log(logError, "LoadToolkitEmbed() SKIPPING", name, "as you can't load it twice")
|
log.Warn("LoadToolkitEmbed() SKIPPING", name, "as you can't load it twice")
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.CreateTemp("", "sample." + name + ".so")
|
f, err := os.CreateTemp("", "sample." + name + ".so")
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
|
log.Error(err, "LoadToolkitEmbed() SKIPPING", name, "as you can't load it twice")
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
|
@ -291,25 +293,25 @@ func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node {
|
||||||
|
|
||||||
p := initToolkit(name, f.Name())
|
p := initToolkit(name, f.Name())
|
||||||
if (p == nil) {
|
if (p == nil) {
|
||||||
log(logError, "LoadToolkitEmbed() embedded go file failed", name)
|
log.Warn("LoadToolkitEmbed() embedded go file failed", name)
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) ListToolkits() {
|
func (n *Node) ListToolkits() {
|
||||||
for _, aplug := range allPlugins {
|
for _, aplug := range allPlugins {
|
||||||
log(logNow, "ListToolkits() already loaded toolkit plugin =", aplug.name)
|
log.Log(PLUG, "ListToolkits() already loaded toolkit plugin =", aplug.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) LoadToolkit(name string) *Node {
|
func (n *Node) LoadToolkit(name string) *Node {
|
||||||
log(logInfo, "LoadToolkit() START for name =", name)
|
log.Log(PLUG, "LoadToolkit() START for name =", name)
|
||||||
plug := initPlugin(name)
|
plug := initPlugin(name)
|
||||||
if (plug == nil) {
|
if (plug == nil) {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
log(logInfo, "LoadToolkit() sending InitToolkit action to the plugin channel")
|
log.Log(PLUG, "LoadToolkit() sending InitToolkit action to the plugin channel")
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
a.ActionType = toolkit.InitToolkit
|
a.ActionType = toolkit.InitToolkit
|
||||||
plug.pluginChan <- a
|
plug.pluginChan <- a
|
||||||
|
@ -317,16 +319,16 @@ func (n *Node) LoadToolkit(name string) *Node {
|
||||||
|
|
||||||
// TODO: find a new way to do this that is locking, safe and accurate
|
// TODO: find a new way to do this that is locking, safe and accurate
|
||||||
me.rootNode.redraw(plug)
|
me.rootNode.redraw(plug)
|
||||||
log(logInfo, "LoadToolkit() END for name =", name)
|
log.Log(PLUG, "LoadToolkit() END for name =", name)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) CloseToolkit(name string) bool {
|
func (n *Node) CloseToolkit(name string) bool {
|
||||||
log(logInfo, "CloseToolkit() for name =", name)
|
log.Log(PLUG, "CloseToolkit() for name =", name)
|
||||||
for _, plug := range allPlugins {
|
for _, plug := range allPlugins {
|
||||||
log(debugGui, "CloseToolkit() found", plug.name)
|
log.Log(PLUG, "CloseToolkit() found", plug.name)
|
||||||
if (plug.name == name) {
|
if (plug.name == name) {
|
||||||
log(debugNow, "CloseToolkit() sending close", name)
|
log.Log(PLUG, "CloseToolkit() sending close", name)
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
a.ActionType = toolkit.CloseToolkit
|
a.ActionType = toolkit.CloseToolkit
|
||||||
plug.pluginChan <- a
|
plug.pluginChan <- a
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ func (n *Node) redraw(p *aplug) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) redo(plug *aplug) {
|
func (n *Node) redo(plug *aplug) {
|
||||||
log(logNow, "redo()", plug.name, n.id, n.WidgetType, n.Name)
|
log.Info("redo()", plug.name, n.id, n.WidgetType, n.Name)
|
||||||
|
|
||||||
var a *toolkit.Action
|
var a *toolkit.Action
|
||||||
a = new(toolkit.Action)
|
a = new(toolkit.Action)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,7 +9,7 @@ func (parent *Node) NewSlider(name string, x int, y int) *Node {
|
||||||
newNode := parent.newNode(name, toolkit.Slider)
|
newNode := parent.newNode(name, toolkit.Slider)
|
||||||
|
|
||||||
newNode.Custom = func() {
|
newNode.Custom = func() {
|
||||||
log(debugGui, "even newer clicker() name in NewSlider name =", name)
|
log.Log(GUI, "even newer clicker() name in NewSlider name =", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode.X = x
|
newNode.X = x
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,7 +9,7 @@ func (parent *Node) NewSpinner(name string, x int, y int) *Node {
|
||||||
newNode := parent.newNode(name, toolkit.Spinner)
|
newNode := parent.newNode(name, toolkit.Spinner)
|
||||||
|
|
||||||
newNode.Custom = func() {
|
newNode.Custom = func() {
|
||||||
log(debugChange, "default NewSpinner() change", name)
|
log.Info("default NewSpinner() change", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode.X = x
|
newNode.X = x
|
||||||
|
|
10
tab.go
10
tab.go
|
@ -1,6 +1,8 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
|
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,16 +14,16 @@ func (n *Node) NewTab(text string) *Node {
|
||||||
|
|
||||||
if (n.WidgetType != toolkit.Window) {
|
if (n.WidgetType != toolkit.Window) {
|
||||||
// figure out what the actual window is
|
// figure out what the actual window is
|
||||||
log(logError, "NewTab() is being requested on something that isn't a Window. node =", n)
|
log.Warn("NewTab() is being requested on something that isn't a Window. node =", n)
|
||||||
if (n.parent == nil) {
|
if (n.parent == nil) {
|
||||||
// TODO: find a window. any window. never give up. never die.
|
// TODO: find a window. any window. never give up. never die.
|
||||||
log(logError, "NewTab() TODO: make a window here", n)
|
log.Warn("NewTab() TODO: make a window here", n)
|
||||||
panic("NewTab did not get passed a window")
|
panic("NewTab did not get passed a window")
|
||||||
}
|
}
|
||||||
log(logError, "NewTab() parent =", n.parent)
|
log.Warn("NewTab() parent =", n.parent)
|
||||||
if (n.parent.WidgetType == toolkit.Root) {
|
if (n.parent.WidgetType == toolkit.Root) {
|
||||||
// also broken
|
// also broken
|
||||||
log(logError, "NewTab() TODO: make or find a window here", n)
|
log.Warn("NewTab() TODO: make or find a window here", n)
|
||||||
panic("NewTab() did not get passed a window")
|
panic("NewTab() did not get passed a window")
|
||||||
}
|
}
|
||||||
// go up the binary tree until we find a window widget to add a tab too
|
// go up the binary tree until we find a window widget to add a tab too
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
|
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,7 +10,7 @@ func (parent *Node) NewTextbox(name string) *Node {
|
||||||
newNode := parent.newNode(name, toolkit.Textbox)
|
newNode := parent.newNode(name, toolkit.Textbox)
|
||||||
|
|
||||||
newNode.Custom = func() {
|
newNode.Custom = func() {
|
||||||
log(debugGui, "NewTextbox changed =", name)
|
log.Log(GUI, "NewTextbox changed =", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
a := newAction(newNode, toolkit.Add)
|
a := newAction(newNode, toolkit.Add)
|
||||||
|
@ -22,7 +24,7 @@ func (parent *Node) NewEntryLine(name string) *Node {
|
||||||
newNode.X = 1
|
newNode.X = 1
|
||||||
|
|
||||||
newNode.Custom = func() {
|
newNode.Custom = func() {
|
||||||
log(debugGui, "NewTextbox changed =", name)
|
log.Log(GUI, "NewTextbox changed =", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
a := newAction(newNode, toolkit.Add)
|
a := newAction(newNode, toolkit.Add)
|
||||||
|
|
39
watchdog.go
39
watchdog.go
|
@ -2,6 +2,8 @@ package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var watchtime time.Duration = 100 // in tenths of seconds
|
var watchtime time.Duration = 100 // in tenths of seconds
|
||||||
|
@ -16,43 +18,8 @@ var watchtime time.Duration = 100 // in tenths of seconds
|
||||||
func Watchdog() {
|
func Watchdog() {
|
||||||
var i = 1
|
var i = 1
|
||||||
for {
|
for {
|
||||||
log(logInfo, "gui.Watchdog() is alive. give me something to do.", i)
|
log.Verbose("gui.Watchdog() is alive. give me something to do.", i)
|
||||||
if (me.rootNode == nil) {
|
|
||||||
log(logInfo, "me.rootNode == nil", i)
|
|
||||||
} else {
|
|
||||||
if (logVerbose) {
|
|
||||||
me.rootNode.ListChildren(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i += 1
|
i += 1
|
||||||
time.Sleep(watchtime * time.Second / 10)
|
time.Sleep(watchtime * time.Second / 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// https://www.reddit.com/r/golang/comments/12em87q/how_to_run_periodic_tasks/
|
|
||||||
/*
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
ticker := time.NewTicker(time.Second)
|
|
||||||
defer ticker.Stop()
|
|
||||||
done := make(chan bool)
|
|
||||||
go func() {
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
done <- true
|
|
||||||
}()
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
fmt.Println("Done!")
|
|
||||||
return
|
|
||||||
case t := <-ticker.C:
|
|
||||||
fmt.Println("Current time: ", t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/gui/toolkit"
|
"go.wit.com/gui/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ func (parent *Node) NewWindow(title string) *Node {
|
||||||
newNode = parent.newNode(title, toolkit.Window)
|
newNode = parent.newNode(title, toolkit.Window)
|
||||||
newNode.Custom = StandardExit
|
newNode.Custom = StandardExit
|
||||||
|
|
||||||
log(logInfo, "NewWindow()", title)
|
log.Info("NewWindow()", title)
|
||||||
|
|
||||||
a := newAction(newNode, toolkit.Add)
|
a := newAction(newNode, toolkit.Add)
|
||||||
sendAction(a)
|
sendAction(a)
|
||||||
|
|
Loading…
Reference in New Issue