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 (
|
||||
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
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
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
|
||||
func ArgToolkit() string {
|
||||
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
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/gui/toolkit"
|
||||
)
|
||||
|
||||
|
@ -29,12 +32,6 @@ func SetDebug (s bool) {
|
|||
debugGui = s
|
||||
debugTabs = s
|
||||
|
||||
logNow = s
|
||||
logInfo = s
|
||||
logWarn = s
|
||||
logError = s
|
||||
logVerbose = s
|
||||
|
||||
SetFlag("Node", s)
|
||||
SetFlag("Tabs", s)
|
||||
SetFlag("Dump", s)
|
||||
|
@ -68,7 +65,7 @@ func SetFlag (s string, b bool) {
|
|||
case "Show":
|
||||
// ShowDebugValues() // print them here?
|
||||
default:
|
||||
log(debugGui, "Can't set unknown flag", s)
|
||||
log.Log(GUI, "Can't set unknown flag", s)
|
||||
}
|
||||
|
||||
a := new(toolkit.Action)
|
||||
|
@ -82,20 +79,19 @@ func SetFlag (s string, b bool) {
|
|||
func ShowDebugValues() {
|
||||
// The order here should match the order in the GUI
|
||||
// TODO: get the order from the node binary tree
|
||||
log(true, "Debug =", debugGui)
|
||||
log(true, "DebugError =", debugError)
|
||||
log(true, "DebugChange =", debugChange)
|
||||
log(true, "DebugDump =", debugDump)
|
||||
log(true, "DebugTabs =", debugTabs)
|
||||
log(true, "DebugPlugin =", debugPlugin)
|
||||
log(true, "DebugNode =", debugNode)
|
||||
log.Log(true, "Debug =", debugGui)
|
||||
log.Log(true, "DebugError =", debugError)
|
||||
log.Log(true, "DebugChange =", debugChange)
|
||||
log.Log(true, "DebugDump =", debugDump)
|
||||
log.Log(true, "DebugTabs =", debugTabs)
|
||||
log.Log(true, "DebugPlugin =", debugPlugin)
|
||||
log.Log(true, "DebugNode =", debugNode)
|
||||
|
||||
SetFlag("Show", true)
|
||||
}
|
||||
|
||||
func (n *Node) Dump() {
|
||||
b := true
|
||||
// log("Dump() dump =", b)
|
||||
Indent(b, "NODE DUMP START")
|
||||
Indent(b, "id = ", n.id)
|
||||
Indent(b, "Name = ", n.Name)
|
||||
|
@ -129,7 +125,7 @@ func (n *Node) dumpWidget(b bool) string {
|
|||
var info, d string
|
||||
|
||||
if (n == nil) {
|
||||
log(debugError, "dumpWidget() node == nil")
|
||||
log.Error(errors.New("dumpWidget() node == nil"))
|
||||
return ""
|
||||
}
|
||||
info = n.WidgetType.String()
|
||||
|
@ -159,32 +155,32 @@ func (n *Node) ListChildren(dump bool) {
|
|||
if (n.parent == nil) {
|
||||
return
|
||||
}
|
||||
log(debugNode, "\t\t\tparent =",n.parent.id)
|
||||
log.Log(NODE, "\t\t\tparent =",n.parent.id)
|
||||
if (listChildrenParent != nil) {
|
||||
log(debugNode, "\t\t\tlistChildrenParent =",listChildrenParent.id)
|
||||
log.Log(NODE, "\t\t\tlistChildrenParent =",listChildrenParent.id)
|
||||
if (listChildrenParent.id != n.parent.id) {
|
||||
log(true, "parent =",n.parent.id, n.parent.Name)
|
||||
log(true, "listChildrenParent =",listChildrenParent.id, listChildrenParent.Name)
|
||||
log(true, listChildrenParent.id, "!=", n.parent.id)
|
||||
exit("parent.child does not match child.parent")
|
||||
log.Log(true, "parent =",n.parent.id, n.parent.Name)
|
||||
log.Log(true, "listChildrenParent =",listChildrenParent.id, listChildrenParent.Name)
|
||||
log.Log(true, listChildrenParent.id, "!=", n.parent.id)
|
||||
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
|
||||
}
|
||||
for _, child := range n.children {
|
||||
if (child.parent != nil) {
|
||||
log(debugNode, "\t\t\tparent =",child.parent.id)
|
||||
log.Log(NODE, "\t\t\tparent =",child.parent.id)
|
||||
} else {
|
||||
log(debugGui, "\t\t\tno parent")
|
||||
log.Log(GUI, "\t\t\tno parent")
|
||||
// memory corruption? non-threadsafe access?
|
||||
// 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")
|
||||
}
|
||||
if (child.children == nil) {
|
||||
log(debugNode, "\t\t", child.id, "has no children")
|
||||
log.Log(NODE, "\t\t", child.id, "has no children")
|
||||
} else {
|
||||
log(debugNode, "\t\t\tHas children:", child.children)
|
||||
log.Log(NODE, "\t\t\tHas children:", child.children)
|
||||
}
|
||||
listChildrenParent = n
|
||||
listChildrenDepth += 1
|
||||
|
@ -194,3 +190,19 @@ func (n *Node) ListChildren(dump bool) {
|
|||
}
|
||||
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
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/gui/toolkit"
|
||||
)
|
||||
|
||||
|
@ -73,7 +74,7 @@ func (n *Node) At(w int, h int) *Node {
|
|||
|
||||
n.gridIncrement()
|
||||
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
|
||||
}
|
||||
|
|
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 (
|
||||
"os"
|
||||
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/gui/toolkit"
|
||||
)
|
||||
|
||||
|
@ -15,7 +16,7 @@ const Xaxis = 0 // stack things horizontally
|
|||
const Yaxis = 1 // stack things vertically
|
||||
|
||||
func init() {
|
||||
log(true, "init() has been run")
|
||||
log.Log(true, "init() has been run")
|
||||
|
||||
me.counter = 0
|
||||
me.prefix = "wit"
|
||||
|
@ -36,28 +37,29 @@ func init() {
|
|||
}
|
||||
|
||||
func watchCallback() {
|
||||
log(logInfo, "watchCallback() START")
|
||||
log.Info("watchCallback() START")
|
||||
for {
|
||||
log(logInfo, "watchCallback() restarted select for toolkit user events")
|
||||
log.Info("watchCallback() restarted select for toolkit user events")
|
||||
select {
|
||||
case a := <-me.guiChan:
|
||||
if (a.ActionType == toolkit.UserQuit) {
|
||||
log(logInfo, "doUserEvent() User sent Quit()")
|
||||
log.Info("doUserEvent() User sent Quit()")
|
||||
me.rootNode.doCustom()
|
||||
exit("wit/gui toolkit.UserQuit")
|
||||
log.Exit("wit/gui toolkit.UserQuit")
|
||||
break
|
||||
}
|
||||
if (a.ActionType == toolkit.EnableDebug) {
|
||||
log(logInfo, "doUserEvent() Enable Debugging Window")
|
||||
log.Warn("doUserEvent() Enable Debugging Window")
|
||||
log.Warn("doUserEvent() TODO: not implemented")
|
||||
// DebugWindow()
|
||||
break
|
||||
}
|
||||
|
||||
n := me.rootNode.FindId(a.WidgetId)
|
||||
if (n == nil) {
|
||||
log(logError, "watchCallback() UNKNOWN widget id =", a.WidgetId, a.Name)
|
||||
log.Warn("watchCallback() UNKNOWN widget id =", a.WidgetId, a.Name)
|
||||
} else {
|
||||
log(logInfo, "watchCallback() FOUND widget id =", n.id, n.Name)
|
||||
log.Info("watchCallback() FOUND widget id =", n.id, n.Name)
|
||||
n.doUserEvent(a)
|
||||
}
|
||||
// this maybe a good idea?
|
||||
|
@ -68,49 +70,49 @@ func watchCallback() {
|
|||
}
|
||||
|
||||
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) {
|
||||
log(debugError, "Custom() = nil. SKIPPING")
|
||||
log.Warn("Custom() = nil. SKIPPING")
|
||||
return
|
||||
}
|
||||
go n.Custom()
|
||||
}
|
||||
|
||||
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 {
|
||||
case toolkit.Checkbox:
|
||||
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()
|
||||
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()
|
||||
case toolkit.Combobox:
|
||||
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()
|
||||
case toolkit.Dropdown:
|
||||
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()
|
||||
case toolkit.Textbox:
|
||||
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()
|
||||
case toolkit.Spinner:
|
||||
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()
|
||||
case toolkit.Slider:
|
||||
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()
|
||||
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()
|
||||
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
|
||||
func (n *Node) Default() *Node {
|
||||
if (argGui.GuiPlugin != "") {
|
||||
log(logError, "New.Default() try toolkit =", argGui.GuiPlugin)
|
||||
log.Warn("New.Default() try toolkit =", argGui.GuiPlugin)
|
||||
return n.LoadToolkit(argGui.GuiPlugin)
|
||||
}
|
||||
// if DISPLAY isn't set, return since gtk can't load
|
||||
// TODO: figure out how to check what to do in macos and mswindows
|
||||
if (os.Getenv("DISPLAY") == "") {
|
||||
if (n.LoadToolkit("gocui") == nil) {
|
||||
log(logError, "New() failed to load gocui")
|
||||
log.Warn("New() failed to load gocui")
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
@ -145,17 +147,17 @@ func (n *Node) Default() *Node {
|
|||
|
||||
// The window is destroyed but the application does not quit
|
||||
func (n *Node) StandardClose() {
|
||||
log(debugGui, "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. name =", n.Name)
|
||||
log.Log(GUI, "wit/gui Standard Window Close. n.Custom exit =", n.Custom)
|
||||
}
|
||||
|
||||
// The window is destroyed and the application exits
|
||||
// TODO: properly exit the plugin since Quit() doesn't do it
|
||||
func StandardExit() {
|
||||
log(true, "wit/gui Standard Window Exit. running os.Exit()")
|
||||
log(true, "StandardExit() attempt to exit each toolkit plugin")
|
||||
log.Log(true, "wit/gui Standard Window Exit. running os.Exit()")
|
||||
log.Log(true, "StandardExit() attempt to exit each toolkit plugin")
|
||||
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
|
||||
|
||||
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
|
||||
|
@ -30,7 +33,7 @@ func addNode(title string) *Node {
|
|||
n.Name = title
|
||||
n.Text = title
|
||||
n.id = me.counter
|
||||
log(debugNode, "addNode = widget setid =", n.id)
|
||||
log.Log(NODE, "addNode = widget setid =", n.id)
|
||||
|
||||
me.counter += 1
|
||||
return n
|
||||
|
@ -42,12 +45,12 @@ func (n *Node) Parent() *Node {
|
|||
|
||||
func (n *Node) Delete(d *Node) {
|
||||
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) {
|
||||
log(debugNode, "\t\t Deleting this")
|
||||
log.Log(NODE, "\t\t Deleting this")
|
||||
n.children = append(n.children[:i], n.children[i+1:]...)
|
||||
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"
|
||||
"plugin"
|
||||
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/gui/toolkit"
|
||||
)
|
||||
|
||||
|
@ -50,12 +51,12 @@ var allPlugins []*aplug
|
|||
// loads and initializes a toolkit (andlabs/ui, gocui, etc)
|
||||
// attempts to locate the .so file
|
||||
func initPlugin(name string) *aplug {
|
||||
log(logInfo, "initPlugin() START")
|
||||
log.Log(PLUG, "initPlugin() START")
|
||||
|
||||
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) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -71,13 +72,13 @@ func getPluginChannel(p *aplug, funcName string) func() chan toolkit.Action {
|
|||
|
||||
test, err = p.plug.Lookup(funcName)
|
||||
if err != nil {
|
||||
log(debugGui, "DID NOT FIND: name =", test, "err =", err)
|
||||
log.Error(err, "DID NOT FIND: name =", test)
|
||||
return nil
|
||||
}
|
||||
|
||||
newfunc, ok = test.(func() chan toolkit.Action)
|
||||
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 newfunc
|
||||
|
@ -90,13 +91,13 @@ func sendCallback(p *aplug, funcName string) func(chan toolkit.Action) {
|
|||
|
||||
test, err = p.plug.Lookup(funcName)
|
||||
if err != nil {
|
||||
log(debugGui, "DID NOT FIND: name =", test, "err =", err)
|
||||
log.Error(err, "DID NOT FIND: name =", test)
|
||||
return nil
|
||||
}
|
||||
|
||||
newfunc, ok = test.(func(chan toolkit.Action))
|
||||
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 newfunc
|
||||
|
@ -120,7 +121,7 @@ func searchPaths(name string) *aplug {
|
|||
pfile, err = me.resFS.ReadFile(filename)
|
||||
if (err == nil) {
|
||||
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.Write(pfile)
|
||||
f.Close()
|
||||
|
@ -129,7 +130,7 @@ func searchPaths(name string) *aplug {
|
|||
return p
|
||||
}
|
||||
} 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
|
||||
|
@ -141,7 +142,7 @@ func searchPaths(name string) *aplug {
|
|||
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
log(logError, "searchPaths() error. exiting here?")
|
||||
log.Error(err, "searchPaths() error. exiting here?")
|
||||
} else {
|
||||
filename = homeDir + "/go/src/go.wit.com/gui/toolkits/" + name + ".so"
|
||||
p = initToolkit(name, filename)
|
||||
|
@ -152,7 +153,7 @@ func searchPaths(name string) *aplug {
|
|||
|
||||
homeDir, err = os.UserHomeDir()
|
||||
if err != nil {
|
||||
log(logError, "searchPaths() error. exiting here?")
|
||||
log.Error(err, "searchPaths() error. exiting here?")
|
||||
} else {
|
||||
filename = homeDir + "/go/src/go.wit.com/toolkits/" + name + ".so"
|
||||
p = initToolkit(name, filename)
|
||||
|
@ -180,18 +181,18 @@ func searchPaths(name string) *aplug {
|
|||
func initToolkit(name string, filename string) *aplug {
|
||||
if _, err := os.Stat(filename); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log(true, "missing plugin", name, "as filename", filename)
|
||||
log.Log(true, "missing plugin", name, "as filename", filename)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
log(true, "Found plugin", name, "as filename", filename)
|
||||
log.Log(true, "Found plugin", name, "as filename", filename)
|
||||
|
||||
plug, err := plugin.Open(filename)
|
||||
if err != nil {
|
||||
log(debugError, "plugin FAILED =", filename, err)
|
||||
log.Error(err, "plugin FAILED =", filename)
|
||||
return nil
|
||||
}
|
||||
log(debugPlugin, "initToolkit() loading plugin =", filename)
|
||||
log.Log(PLUG, "initToolkit() loading plugin =", filename)
|
||||
|
||||
var newPlug *aplug
|
||||
newPlug = new(aplug)
|
||||
|
@ -214,12 +215,12 @@ func initToolkit(name string, filename string) *aplug {
|
|||
// set the communication to the plugins
|
||||
newPlug.pluginChan = newPlug.PluginChannel()
|
||||
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
|
||||
}
|
||||
newPlug.Callback(me.guiChan)
|
||||
|
||||
log(debugPlugin, "initToolkit() END", newPlug.name, filename)
|
||||
log.Log(PLUG, "initToolkit() END", newPlug.name, filename)
|
||||
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
|
||||
func sendAction(a *toolkit.Action) {
|
||||
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) {
|
||||
log(logInfo, "Action() retrieving the aplug.PluginChannel()", aplug.name)
|
||||
log.Info("Action() retrieving the aplug.PluginChannel()", aplug.name)
|
||||
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
|
||||
// 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 {
|
||||
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) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
f, err := os.CreateTemp("", "sample." + name + ".so")
|
||||
if (err != nil) {
|
||||
log.Error(err, "LoadToolkitEmbed() SKIPPING", name, "as you can't load it twice")
|
||||
return n
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
|
@ -291,25 +293,25 @@ func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node {
|
|||
|
||||
p := initToolkit(name, f.Name())
|
||||
if (p == nil) {
|
||||
log(logError, "LoadToolkitEmbed() embedded go file failed", name)
|
||||
log.Warn("LoadToolkitEmbed() embedded go file failed", name)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *Node) ListToolkits() {
|
||||
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 {
|
||||
log(logInfo, "LoadToolkit() START for name =", name)
|
||||
log.Log(PLUG, "LoadToolkit() START for name =", name)
|
||||
plug := initPlugin(name)
|
||||
if (plug == nil) {
|
||||
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
|
||||
a.ActionType = toolkit.InitToolkit
|
||||
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
|
||||
me.rootNode.redraw(plug)
|
||||
log(logInfo, "LoadToolkit() END for name =", name)
|
||||
log.Log(PLUG, "LoadToolkit() END for name =", name)
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *Node) CloseToolkit(name string) bool {
|
||||
log(logInfo, "CloseToolkit() for name =", name)
|
||||
log.Log(PLUG, "CloseToolkit() for name =", name)
|
||||
for _, plug := range allPlugins {
|
||||
log(debugGui, "CloseToolkit() found", plug.name)
|
||||
log.Log(PLUG, "CloseToolkit() found", plug.name)
|
||||
if (plug.name == name) {
|
||||
log(debugNow, "CloseToolkit() sending close", name)
|
||||
log.Log(PLUG, "CloseToolkit() sending close", name)
|
||||
var a toolkit.Action
|
||||
a.ActionType = toolkit.CloseToolkit
|
||||
plug.pluginChan <- a
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/gui/toolkit"
|
||||
)
|
||||
|
||||
|
@ -20,7 +21,7 @@ func (n *Node) redraw(p *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
|
||||
a = new(toolkit.Action)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"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.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
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"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.Custom = func() {
|
||||
log(debugChange, "default NewSpinner() change", name)
|
||||
log.Info("default NewSpinner() change", name)
|
||||
}
|
||||
|
||||
newNode.X = x
|
||||
|
|
10
tab.go
10
tab.go
|
@ -1,6 +1,8 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
|
||||
"go.wit.com/gui/gui/toolkit"
|
||||
)
|
||||
|
||||
|
@ -12,16 +14,16 @@ func (n *Node) NewTab(text string) *Node {
|
|||
|
||||
if (n.WidgetType != toolkit.Window) {
|
||||
// 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) {
|
||||
// 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")
|
||||
}
|
||||
log(logError, "NewTab() parent =", n.parent)
|
||||
log.Warn("NewTab() parent =", n.parent)
|
||||
if (n.parent.WidgetType == toolkit.Root) {
|
||||
// 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")
|
||||
}
|
||||
// go up the binary tree until we find a window widget to add a tab too
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
|
||||
"go.wit.com/gui/gui/toolkit"
|
||||
)
|
||||
|
||||
|
@ -8,7 +10,7 @@ func (parent *Node) NewTextbox(name string) *Node {
|
|||
newNode := parent.newNode(name, toolkit.Textbox)
|
||||
|
||||
newNode.Custom = func() {
|
||||
log(debugGui, "NewTextbox changed =", name)
|
||||
log.Log(GUI, "NewTextbox changed =", name)
|
||||
}
|
||||
|
||||
a := newAction(newNode, toolkit.Add)
|
||||
|
@ -22,7 +24,7 @@ func (parent *Node) NewEntryLine(name string) *Node {
|
|||
newNode.X = 1
|
||||
|
||||
newNode.Custom = func() {
|
||||
log(debugGui, "NewTextbox changed =", name)
|
||||
log.Log(GUI, "NewTextbox changed =", name)
|
||||
}
|
||||
|
||||
a := newAction(newNode, toolkit.Add)
|
||||
|
|
39
watchdog.go
39
watchdog.go
|
@ -2,6 +2,8 @@ package gui
|
|||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
var watchtime time.Duration = 100 // in tenths of seconds
|
||||
|
@ -16,43 +18,8 @@ var watchtime time.Duration = 100 // in tenths of seconds
|
|||
func Watchdog() {
|
||||
var i = 1
|
||||
for {
|
||||
log(logInfo, "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)
|
||||
}
|
||||
}
|
||||
log.Verbose("gui.Watchdog() is alive. give me something to do.", i)
|
||||
i += 1
|
||||
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
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/gui/toolkit"
|
||||
)
|
||||
|
||||
|
@ -13,7 +14,7 @@ func (parent *Node) NewWindow(title string) *Node {
|
|||
newNode = parent.newNode(title, toolkit.Window)
|
||||
newNode.Custom = StandardExit
|
||||
|
||||
log(logInfo, "NewWindow()", title)
|
||||
log.Info("NewWindow()", title)
|
||||
|
||||
a := newAction(newNode, toolkit.Add)
|
||||
sendAction(a)
|
||||
|
|
Loading…
Reference in New Issue