complete the move to 'go.wit.com/log'

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-03 18:54:08 -06:00
parent df5fd148c6
commit dbbdb953f2
22 changed files with 50 additions and 320 deletions

12
args.go
View File

@ -6,10 +6,12 @@ import (
"go.wit.com/log"
)
var INFO log.LogFlag
var GUI log.LogFlag
var NODE log.LogFlag
var PLUG log.LogFlag
var INFO log.LogFlag
var CHANGE log.LogFlag
var argGui ArgsGui
@ -27,8 +29,6 @@ func ArgToolkit() string {
func init() {
arg.Register(&argGui)
log.Register("gui", "debugGui", &debugGui)
INFO.B = false
INFO.Name = "INFO"
INFO.Subsystem = "gui"
@ -53,6 +53,12 @@ func init() {
PLUG.Desc = "basic PLUG debugging"
PLUG.Register()
CHANGE.B = false
CHANGE.Name = "CHANGE"
CHANGE.Subsystem = "gui"
CHANGE.Desc = "user changed something"
CHANGE.Register()
for _, s := range log.ListFlags() {
log.Info("go.wit.com/gui/gui ListFlags() returned:", s)
}

2
box.go
View File

@ -1,7 +1,7 @@
package gui
import (
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
func (parent *Node) NewBox(name string, b bool) *Node {

View File

@ -1,6 +1,6 @@
package gui
import "go.wit.com/gui/gui/toolkit"
import "go.wit.com/gui/toolkits"
func (parent *Node) NewButton(name string, custom func()) *Node {
newNode := parent.newNode(name, toolkit.Button)

View File

@ -1,6 +1,6 @@
package gui
import "go.wit.com/gui/gui/toolkit"
import "go.wit.com/gui/toolkits"
func (n *Node) Checked() bool {
return n.B

View File

@ -4,8 +4,9 @@ package gui
import (
"regexp"
"go.wit.com/gui/gui/toolkit"
newlog "go.wit.com/log"
"errors"
"go.wit.com/log"
"go.wit.com/gui/toolkits"
)
// functions for handling text related GUI elements
@ -35,7 +36,7 @@ func (n *Node) Disable() *Node {
}
func (n *Node) Add(str string) {
newlog.Log(debugGui, "gui.Add() value =", str)
log.Log(GUI, "gui.Add() value =", str)
n.S = str
@ -44,7 +45,7 @@ func (n *Node) Add(str string) {
}
func (n *Node) AddText(str string) {
newlog.Log(debugChange, "AddText() value =", str)
log.Log(CHANGE, "AddText() value =", str)
n.Text = str
n.S = str
@ -54,7 +55,7 @@ func (n *Node) AddText(str string) {
}
func (n *Node) SetText(text string) *Node {
newlog.Log(debugChange, "SetText() value =", text)
log.Log(CHANGE, "SetText() value =", text)
n.Text = text
n.S = text
@ -67,11 +68,11 @@ func (n *Node) SetText(text string) *Node {
func (n *Node) SetNext(w int, h int) {
n.NextW = w
n.NextH = h
newlog.Log(debugNow, "SetNext() w,h =", n.NextW, n.NextH)
log.Info("SetNext() w,h =", n.NextW, n.NextH)
}
func (n *Node) Set(val any) {
newlog.Log(debugChange, "Set() value =", val)
log.Log(CHANGE, "Set() value =", val)
switch v := val.(type) {
case bool:
@ -82,7 +83,7 @@ func (n *Node) Set(val any) {
case int:
n.I = val.(int)
default:
newlog.Log(debugError, "Set() unknown type =", v)
log.Error(errors.New("Set() unknown type"), "v =", v)
}
a := newAction(n, toolkit.Set)
@ -106,9 +107,9 @@ func (n *Node) AppendText(str string) {
// should get the value of the node
func (n *Node) GetText() string {
if (n.S != n.Text) {
newlog.Warn("GetText() is screwed up. TODO: fix this dumb crap")
stuff := newlog.ListFlags()
newlog.Warn("ListFlags() =", stuff)
log.Warn("GetText() is screwed up. TODO: fix this dumb crap")
stuff := log.ListFlags()
log.Warn("ListFlags() =", stuff)
}
if (n.S != "") {
return n.S
@ -130,7 +131,7 @@ isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString
for _, username := range []string{"userone", "user2", "user-three"} {
if !isAlpha(username) {
newlog.Log(debugGui, "%q is not valid\n", username)
log.Log(GUI, "%q is not valid\n", username)
}
}
@ -150,11 +151,11 @@ func normalizeInt(s string) string {
// reg, err := regexp.Compile("[^a-zA-Z0-9]+")
reg, err := regexp.Compile("[^0-9]+")
if err != nil {
newlog.Log(debugGui, "normalizeInt() regexp.Compile() ERROR =", err)
log.Log(GUI, "normalizeInt() regexp.Compile() ERROR =", err)
return s
}
clean := reg.ReplaceAllString(s, "")
newlog.Log(debugGui, "normalizeInt() s =", clean)
log.Log(GUI, "normalizeInt() s =", clean)
return clean
}
@ -162,9 +163,9 @@ func commonCallback(n *Node) {
// TODO: make all of this common code to all the widgets
// This might be common everywhere finally (2023/03/01)
if (n.Custom == nil) {
newlog.Log(debugChange, "Not Running n.Custom(n) == nil")
log.Log(CHANGE, "Not Running n.Custom(n) == nil")
} else {
newlog.Log(debugChange, "Running n.Custom(n)")
log.Log(CHANGE, "Running n.Custom(n)")
n.Custom()
}
}
@ -206,7 +207,7 @@ func (n *Node) Expand() *Node {
// myFunnyWindow = myGui.NewWindow("Hello").Standard().SetText("Hola")
func (n *Node) Window(title string) *Node {
newlog.Log(debugError, "Window()", n)
log.Warn("Window()", n)
return n.NewWindow(title)
}
@ -214,12 +215,12 @@ func (n *Node) Window(title string) *Node {
// should be the default way
/*
func (n *Node) Standard() *Node {
newlog.Log(debugInfo, "Standard() not implemented yet")
log.Warn("Standard() not implemented yet")
return n
}
func (n *Node) SetMargin() *Node {
newlog.Log(debugError, "DoMargin() not implemented yet")
log.Warn("DoMargin() not implemented yet")
return n
}
*/

View File

@ -1,6 +1,7 @@
package gui
// Lots of debugging things:
// old debugging things. probably deprecate
// everything should be moved to "go.wit.com/gui/debugger"
// A function dump out the binary tree
import (
@ -8,88 +9,14 @@ import (
"strconv"
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
// various debugging flags
var debugNow bool = true // useful for active development
var debugGui bool = false
var debugError bool = true
var debugDump bool = false
var debugNode bool = false
var debugTabs bool = false
var debugFlags bool = false
var debugChange bool = false // shows user events like mouse and keyboard
var debugPlugin bool = false
var debugAction bool = false
// for printing out the binary tree
var listChildrenParent *Node
var listChildrenDepth int = 0
var defaultPadding = " "
func SetDebug (s bool) {
debugGui = s
debugTabs = s
SetFlag("Node", s)
SetFlag("Tabs", s)
SetFlag("Dump", s)
SetFlag("Flags", s)
SetFlag("Plugin", s)
SetFlag("Change", s)
SetFlag("Error", s)
// This flag is only for the internal toolkit debugging
SetFlag("Toolkit", s)
}
func SetFlag (s string, b bool) {
switch s {
case "Toolkit":
// This flag is only for internal toolkit debugging
case "Tabs":
debugTabs = b
case "Node":
debugNode = b
case "Dump":
debugDump = b
case "Error":
debugError = b
case "Change":
debugChange = b
case "Flags":
debugFlags = b
case "Plugin":
debugPlugin = b
case "Show":
// ShowDebugValues() // print them here?
default:
log.Log(GUI, "Can't set unknown flag", s)
}
a := new(toolkit.Action)
a.ActionType = toolkit.Set
a.WidgetType = toolkit.Flag
a.S = s
a.B = b
sendAction(a)
}
func ShowDebugValues() {
// The order here should match the order in the GUI
// TODO: get the order from the node binary tree
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
Indent(b, "NODE DUMP START")

View File

@ -6,7 +6,7 @@ package gui
// since it is the same. confusing names? maybe...
import (
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
// add a new entry to the dropdown name

View File

@ -2,7 +2,7 @@ package gui
import (
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
// Grid numbering examples (H) or (W,H)

View File

@ -1,7 +1,7 @@
package gui
import (
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
// TODO: make a "Group" a "Grid" ?

View File

@ -1,7 +1,7 @@
package gui
import (
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
func (parent *Node) NewImage(name string) *Node {

View File

@ -1,7 +1,7 @@
package gui
import (
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
func (parent *Node) NewLabel(text string) *Node {

View File

@ -4,7 +4,7 @@ import (
"os"
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
// TODO: make a fake 'plugin' channel of communication to andlabs for mswindows

View File

@ -2,7 +2,7 @@ package gui
import (
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
/*

View File

@ -11,7 +11,7 @@ import (
"plugin"
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
var err error

View File

@ -2,7 +2,7 @@ package gui
import (
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
// This recreates the whole GUI for a plugin

View File

@ -2,7 +2,7 @@ package gui
import (
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
func (parent *Node) NewSlider(name string, x int, y int) *Node {

View File

@ -2,7 +2,7 @@ package gui
import (
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
func (parent *Node) NewSpinner(name string, x int, y int) *Node {

View File

@ -3,7 +3,7 @@ package gui
import (
"sync"
"embed"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
//

2
tab.go
View File

@ -3,7 +3,7 @@ package gui
import (
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
// This function should make a new node with the parent and

View File

@ -3,7 +3,7 @@ package gui
import (
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
func (parent *Node) NewTextbox(name string) *Node {

View File

@ -1,204 +0,0 @@
package toolkit
// passes information between the toolkit library (plugin)
//
// This is the only thing that is passed between the toolkit plugin
//
// what names should be used? This is not part of [[Graphical Widget]]
// Event() seems like a good name.
// Event is used too much: web dev, cloud, etc
// I'm using "Action". Maybe it should really be
// "Interaction" as per wikipedia [[User interface]]
//
// TODO: convert this to a protobuf (?)
//
type WidgetType int // Button, Menu, Checkbox, etc.
type ActionType int // Add, SetText, Click, Hide, Append, Delete, etc
type Action struct {
ActionType ActionType
WidgetType WidgetType
WidgetId int
ParentId int
Text string // what is visable to the user
Name string // a name useful for programming
// This is how the values are passed back and forth
// values from things like checkboxes & dropdown's
B bool
I int
S string
// This is used for things like a slider(0,100)
X int
Y int
// This is for the grid size & widget position
W int
H int
AtW int
AtH int
// Put space around elements to improve look & feel
Margin bool
// Make widgets fill up the space available
Expand bool
A any // switch to this or deprecate this? pros/cons?
}
const (
Unknown WidgetType = iota
Root // the master 'root' node of the binary tree
Flag // used to send configuration values to plugins
Window // in certain gui's (ncurses), these are tabs
Tab // internally, this is a window
Frame // deprecate?
Grid // like drawers in a chest
Group // like the 'Appetizers' section on a menu
Box // a vertical or horizontal stack of widgets
Button
Checkbox // select 'on' or 'off'
Dropdown
Combobox // dropdown with edit=true
Label
Textbox // is this a Label with edit=true
Slider // like a progress bar
Spinner // like setting the oven temperature
Separator // TODO
Image // TODO
Area // TODO
Form // TODO
Font // TODO
Color // TODO
Dialog // TODO
Stdout // can be used to capture and display log output
)
const (
Add ActionType = iota
Delete
Get
Set
GetText
SetText
AddText
Show
Hide
Enable
Disable
Margin
Unmargin
Pad
Unpad
Append
Move
Dump
User // the user did something (mouse, keyboard, etc)
InitToolkit // initializes the toolkit
CloseToolkit // closes the toolkit
UserQuit // the user closed the GUI
EnableDebug // open the debugging window
)
func (s WidgetType) String() string {
switch s {
case Root:
return "Root"
case Flag:
return "Flag"
case Window:
return "Window"
case Tab:
return "Tab"
case Frame:
return "Frame"
case Grid:
return "Grid"
case Group:
return "Group"
case Box:
return "Box"
case Button:
return "Button"
case Checkbox:
return "Checkbox"
case Dropdown:
return "Dropdown"
case Combobox:
return "Combobox"
case Label:
return "Label"
case Textbox:
return "Textbox"
case Slider:
return "Slider"
case Spinner:
return "Spinner"
case Separator:
return "Separator"
case Image:
return "Image"
case Area:
return "Area"
case Form:
return "Form"
case Font:
return "Font"
case Color:
return "Color"
case Dialog:
return "Dialog"
case Stdout:
return "Stdout"
case Unknown:
return "Unknown"
}
return "WidgetType.String() Error"
}
func (s ActionType) String() string {
switch s {
case Add:
return "Add"
case Delete:
return "Delete"
case Get:
return "Get"
case Set:
return "Set"
case GetText:
return "GetText"
case SetText:
return "SetText"
case AddText:
return "AddText"
case Show:
return "Show"
case Hide:
return "Hide"
case Enable:
return "Enable"
case Disable:
return "Disable"
case Margin:
return "Margin"
case Unmargin:
return "Unmargin"
case Pad:
return "Pad"
case Unpad:
return "Unpad"
case Append:
return "Append"
case Move:
return "Move"
case Dump:
return "Dump"
}
return "ActionType.String() Error"
}

View File

@ -2,7 +2,7 @@ package gui
import (
"go.wit.com/log"
"go.wit.com/gui/gui/toolkit"
"go.wit.com/gui/toolkits"
)
// This routine creates a blank window with a Title and size (W x H)