a clock
This commit is contained in:
parent
77b4bcb94b
commit
90083d5bcb
|
@ -5,6 +5,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
"github.com/awesome-gocui/gocui"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -76,13 +77,23 @@ func addDropdown() *tree.Node {
|
||||||
|
|
||||||
// use this to test code ideas // put whatever you want here and hit '2' to activate it
|
// use this to test code ideas // put whatever you want here and hit '2' to activate it
|
||||||
func theNotsure(g *gocui.Gui, v *gocui.View) error {
|
func theNotsure(g *gocui.Gui, v *gocui.View) error {
|
||||||
if me.dark {
|
|
||||||
me.dark = false
|
|
||||||
} else {
|
|
||||||
me.dark = true
|
|
||||||
}
|
|
||||||
log.Info("got keypress 2. now what? dark =", me.dark)
|
log.Info("got keypress 2. now what? dark =", me.dark)
|
||||||
// findBG()
|
if me.clock.tk == nil {
|
||||||
|
me.clock.tk = makeNewFlagWidget(me.clock.wId)
|
||||||
|
me.clock.tk.dumpWidget("init() clock")
|
||||||
|
w, h := me.baseGui.MousePosition()
|
||||||
|
me.clock.tk.MoveToOffset(w, h)
|
||||||
|
me.clock.tk.labelN = time.Now().Format("15:04:05")
|
||||||
|
me.clock.tk.frame = false
|
||||||
|
me.clock.tk.setColorLabel()
|
||||||
|
me.clock.tk.Show()
|
||||||
|
me.clock.active = true
|
||||||
|
me.clock.tk.dumpWidget("showClock()")
|
||||||
|
} else {
|
||||||
|
me.clock.tk.v.Clear()
|
||||||
|
me.clock.tk.labelN = time.Now().Format("15:04:05")
|
||||||
|
me.clock.tk.v.WriteString(me.clock.tk.labelN)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
help.go
6
help.go
|
@ -85,6 +85,12 @@ func showHelp() error {
|
||||||
}
|
}
|
||||||
g.SetViewOnTop("help")
|
g.SetViewOnTop("help")
|
||||||
me.helpLabel = help
|
me.helpLabel = help
|
||||||
|
if me.clock.tk != nil {
|
||||||
|
g.SetView("help", maxX-(newW+me.FramePadW), 0, maxX-1, len(helpText)+me.FramePadH, 0)
|
||||||
|
me.clock.tk.MoveToOffset(maxX-10, 1)
|
||||||
|
me.clock.tk.Hide()
|
||||||
|
me.clock.tk.Show()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
init.go
13
init.go
|
@ -49,6 +49,7 @@ func init() {
|
||||||
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.mouse.mouseUp = true
|
me.mouse.mouseUp = true
|
||||||
me.mouse.clicktime = time.Millisecond * 100
|
me.mouse.clicktime = time.Millisecond * 100
|
||||||
|
@ -230,16 +231,24 @@ func refreshGocui() {
|
||||||
var lastRefresh time.Time
|
var lastRefresh time.Time
|
||||||
lastRefresh = time.Now()
|
lastRefresh = time.Now()
|
||||||
for {
|
for {
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
// log.Info("refresh checking ok")
|
// log.Info("refresh checking ok")
|
||||||
if !me.ok {
|
if !me.ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if time.Since(lastRefresh) > 100*time.Millisecond {
|
if time.Since(lastRefresh) > 1000*time.Millisecond {
|
||||||
if me.mouse.mouseUp {
|
if me.mouse.mouseUp {
|
||||||
// log.Info("refresh now on mouseUp")
|
// log.Info("refresh now on mouseUp")
|
||||||
// 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.Update(testRefresh)
|
me.baseGui.Update(testRefresh)
|
||||||
|
if me.clock.tk != nil && !me.showHelp {
|
||||||
|
// also double check the gocui view exists
|
||||||
|
if me.clock.tk.v != nil {
|
||||||
|
me.clock.tk.v.Clear()
|
||||||
|
me.clock.tk.labelN = time.Now().Format("15:04:05")
|
||||||
|
me.clock.tk.v.WriteString(me.clock.tk.labelN)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// log.Info("refresh skip on mouseDown")
|
// log.Info("refresh skip on mouseDown")
|
||||||
// me.baseGui.Update()
|
// me.baseGui.Update()
|
||||||
|
|
|
@ -65,12 +65,13 @@ type config struct {
|
||||||
depth int // used for listWidgets() debugging
|
depth int // used for listWidgets() debugging
|
||||||
newWindowTrigger chan *guiWidget // work around hack to redraw windows a bit after NewWindow()
|
newWindowTrigger chan *guiWidget // work around hack to redraw windows a bit after NewWindow()
|
||||||
stdout stdout // information for the STDOUT window
|
stdout stdout // information for the STDOUT window
|
||||||
showDebug bool // todo: move this into config struct
|
|
||||||
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
|
||||||
allwin []*guiWidget // for tracking which window is next
|
allwin []*guiWidget // for tracking which window is next
|
||||||
dark bool // use a 'dark' color palette
|
dark bool // use a 'dark' color palette
|
||||||
mouse mouse // mouse settings
|
mouse mouse // mouse settings
|
||||||
|
showDebug bool // todo: move this into config struct
|
||||||
}
|
}
|
||||||
|
|
||||||
// stuff controlling how the mouse works
|
// stuff controlling how the mouse works
|
||||||
|
|
Loading…
Reference in New Issue