start moving to standard internal TK functions

This commit is contained in:
Jeff Carr 2025-03-02 13:34:09 -06:00
parent f24c509859
commit 0638183356
4 changed files with 108 additions and 51 deletions

102
help.go
View File

@ -15,6 +15,8 @@ import (
"github.com/awesome-gocui/gocui" "github.com/awesome-gocui/gocui"
log "go.wit.com/log" log "go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
) )
/* /*
@ -86,37 +88,81 @@ func showHelp() error {
} }
g.SetViewOnTop("help") g.SetViewOnTop("help")
me.helpLabel = help me.helpLabel = help
if me.clock.tk == nil { if me.treeRoot == nil {
makeClock() log.Info("gogui makeClock() error. treeRoot == nil")
me.clock.tk.MoveToOffset(maxX-10, 1) return nil
me.clock.tk.Hide() } else {
me.clock.tk.Show() if me.notify.clock.tk == nil {
} makeClock(me.notify.clock.wId)
if me.clock.tk != nil { me.notify.clock.tk.MoveToOffset(maxX-10, 1)
me.clock.tk.MoveToOffset(maxX-10, 1) me.notify.clock.tk.Hide()
me.clock.tk.Hide() me.notify.clock.tk.Show()
me.clock.tk.Show() }
} if me.notify.clock.tk != nil {
if me.stdout.tk == nil { me.notify.clock.tk.MoveToOffset(maxX-10, 1)
makeOutputWidget(me.baseGui, "made this in showHelp()") me.notify.clock.tk.Hide()
msg := fmt.Sprintf("test to stdout from in showHelp() %d\n", me.ecount) me.notify.clock.tk.Show()
me.stdout.Write([]byte(msg)) }
log.Log(NOW, "log.log(NOW) test") if me.stdout.tk == nil {
makeOutputWidget(me.baseGui, "made this in showHelp()")
msg := fmt.Sprintf("test to stdout from in showHelp() %d\n", me.ecount)
me.stdout.Write([]byte(msg))
log.Log(NOW, "log.log(NOW) test")
}
} }
return nil return nil
} }
func makeClock() { // create a new widget in the binary tree
me.clock.tk = makeNewFlagWidget(me.clock.wId) func makeNewInternalWidget(wId int) *guiWidget {
me.clock.tk.dumpWidget("init() clock") if me.treeRoot == nil {
log.Info("GOGUI Init ERROR. treeRoot == nil")
return nil
}
n := new(tree.Node)
n.WidgetType = widget.Flag
n.WidgetId = wId
n.ParentId = 0
// store the internal toolkit information
tk := new(guiWidget)
tk.frame = true
tk.node = n
tk.node.Parent = me.treeRoot
// set the name used by gocui to the id
tk.cuiName = fmt.Sprintf("%d DR", wId)
tk.setColorInput()
// add this new widget on the binary tree
tk.parent = me.treeRoot.TK.(*guiWidget)
if tk.parent == nil {
panic("makeNewFlagWidget() didn't get treeRoot guiWidget")
} else {
tk.parent.children = append(tk.parent.children, tk)
}
n.TK = tk
return tk
}
func makeClock(wId int) {
if me.treeRoot == nil {
log.Info("gogui makeClock() error. treeRoot == nil")
return
}
me.notify.clock.tk = makeNewInternalWidget(wId)
me.notify.clock.tk.dumpWidget("init() clock")
w, h := me.baseGui.MousePosition() w, h := me.baseGui.MousePosition()
me.clock.tk.MoveToOffset(w, h) me.notify.clock.tk.MoveToOffset(w, h)
me.clock.tk.labelN = time.Now().Format("15:04:05") me.notify.clock.tk.labelN = time.Now().Format("15:04:05")
me.clock.tk.frame = false me.notify.clock.tk.frame = false
me.clock.tk.setColorLabel() me.notify.clock.tk.setColorLabel()
me.clock.tk.Show() me.notify.clock.tk.Show()
me.clock.active = true me.notify.clock.active = true
me.clock.tk.dumpWidget("showClock()") me.notify.clock.tk.dumpWidget("showClock()")
} }
// in the very end of redrawing things, this will place the help and stdout on the top or botton // in the very end of redrawing things, this will place the help and stdout on the top or botton
@ -127,8 +173,8 @@ func setThingsOnTop() {
} else { } else {
me.baseGui.SetViewOnTop("help") me.baseGui.SetViewOnTop("help")
} }
if me.clock.tk != nil { if me.notify.clock.tk != nil {
me.baseGui.SetViewOnTop(me.clock.tk.v.Name()) me.baseGui.SetViewOnTop(me.notify.clock.tk.v.Name())
} }
if me.stdout.tk == nil { if me.stdout.tk == nil {

23
init.go
View File

@ -68,7 +68,8 @@ func initPlugin() {
me.dropdown.wId = -77 me.dropdown.wId = -77
me.textbox.wId = -55 me.textbox.wId = -55
me.stdout.wId = -4 me.stdout.wId = -4
me.clock.wId = -5 me.notify.clock.wId = -5
me.notify.menu.wId = -5
Set(&me.dropdown, "default") Set(&me.dropdown, "default")
// s := fmt.Sprintln("fake default check =", me.FakeW, "dropdown.Id", me.dropdown.Id) // s := fmt.Sprintln("fake default check =", me.FakeW, "dropdown.Id", me.dropdown.Id)
@ -252,24 +253,24 @@ func refreshGocui() {
// todo: add logic here to see if the application has changed anything // todo: add logic here to see if the application has changed anything
// me.baseGui.UpdateAsync(testRefresh) // probably don't need this // me.baseGui.UpdateAsync(testRefresh) // probably don't need this
me.baseGui.Update(testRefresh) me.baseGui.Update(testRefresh)
if me.clock.tk != nil && !me.showHelp { if me.notify.clock.tk != nil && !me.showHelp {
// also double check the gocui view exists // also double check the gocui view exists
if me.clock.tk.v != nil { if me.notify.clock.tk.v != nil {
me.clock.tk.v.Clear() me.notify.clock.tk.v.Clear()
me.clock.tk.labelN = time.Now().Format("15:04:05") me.notify.clock.tk.labelN = time.Now().Format("15:04:05")
me.clock.tk.v.WriteString(me.clock.tk.labelN) me.notify.clock.tk.v.WriteString(me.notify.clock.tk.labelN)
} }
} }
lastRefresh = time.Now() lastRefresh = time.Now()
} else { } else {
me.baseGui.Update(testRefresh) me.baseGui.Update(testRefresh)
if time.Since(lastRefresh) > 3*time.Second { if time.Since(lastRefresh) > 3*time.Second {
if me.clock.tk != nil && !me.showHelp { if me.notify.clock.tk != nil && !me.showHelp {
// also double check the gocui view exists // also double check the gocui view exists
if me.clock.tk.v != nil { if me.notify.clock.tk.v != nil {
me.clock.tk.v.Clear() me.notify.clock.tk.v.Clear()
me.clock.tk.labelN = time.Now().Format("15:04:05") me.notify.clock.tk.labelN = time.Now().Format("15:04:05")
me.clock.tk.v.WriteString(me.clock.tk.labelN) me.notify.clock.tk.v.WriteString(me.notify.clock.tk.labelN)
} }
} }
lastRefresh = time.Now() lastRefresh = time.Now()

View File

@ -77,13 +77,14 @@ type config struct {
stdout stdout // information for the STDOUT window stdout stdout // information for the STDOUT window
dropdown dropdown // the dropdown menu dropdown dropdown // the dropdown menu
textbox dropdown // the textbox popup window textbox dropdown // the textbox popup window
clock dropdown // the textbox popup window // clock dropdown // the textbox popup window
allwin []*guiWidget // for tracking which window is next notify libnotify // emulates the desktop libnotify menu
dark bool // use a 'dark' color palette allwin []*guiWidget // for tracking which window is next
mouse mouse // mouse settings dark bool // use a 'dark' color palette
showDebug bool // todo: move this into config struct mouse mouse // mouse settings
debug bool // todo: move this into config struct showDebug bool // todo: move this into config struct
starttime time.Time // checks how long it takes on startup debug bool // todo: move this into config struct
starttime time.Time // checks how long it takes on startup
} }
// stuff controlling how the mouse works // stuff controlling how the mouse works
@ -127,14 +128,23 @@ type dropdown struct {
h int // the height h int // the height
active bool // is the dropdown menu currently in use? active bool // is the dropdown menu currently in use?
init bool // moves the window offscreen on startup init bool // moves the window offscreen on startup
Id int `default:"-78"` // the widget id to use // Id int `default:"-78"` // the widget id to use
wId int `default:"-78"` // the widget id to use wId int `default:"-78"` // the widget id to use
}
// settings for the dropdown window
type internalTK struct {
tk *guiWidget // where to show STDOUT
callerTK *guiWidget // which widget called the dropdown menu
wId int // the widget id to use
active bool // is the internal widget currently in use?
} }
// the desktop libnotify menu // the desktop libnotify menu
type libnotify struct { type libnotify struct {
clock *guiWidget // where to show the clock clock internalTK // widget for the clock
menu *guiWidget // where to show the clock menu internalTK // libnotify menu icon
window internalTK // the libnotify menu
} }
// this is the gocui way // this is the gocui way

View File

@ -109,7 +109,7 @@ func textboxClosed() {
me.textbox.tk.Hide() me.textbox.tk.Hide()
// log.Info("textbox closed with text:", newtext, me.textbox.callerTK.cuiName) // log.Info("textbox closed with text:", newtext, me.textbox.callerTK.cuiName)
if me.clock.tk.v != nil { if me.notify.clock.tk.v != nil {
me.baseGui.SetCurrentView("help") me.baseGui.SetCurrentView("help")
} else { } else {
me.baseGui.SetCurrentView("msg") me.baseGui.SetCurrentView("msg")