a clock
This commit is contained in:
parent
77b4bcb94b
commit
90083d5bcb
|
@ -5,6 +5,7 @@ package main
|
|||
|
||||
import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/awesome-gocui/gocui"
|
||||
"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
|
||||
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)
|
||||
// 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
|
||||
}
|
||||
|
||||
|
|
6
help.go
6
help.go
|
@ -85,6 +85,12 @@ func showHelp() error {
|
|||
}
|
||||
g.SetViewOnTop("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
|
||||
}
|
||||
|
||||
|
|
13
init.go
13
init.go
|
@ -49,6 +49,7 @@ func init() {
|
|||
me.dropdown.wId = -77
|
||||
me.textbox.wId = -55
|
||||
me.stdout.wId = -4
|
||||
me.clock.wId = -5
|
||||
|
||||
me.mouse.mouseUp = true
|
||||
me.mouse.clicktime = time.Millisecond * 100
|
||||
|
@ -230,16 +231,24 @@ func refreshGocui() {
|
|||
var lastRefresh time.Time
|
||||
lastRefresh = time.Now()
|
||||
for {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
// log.Info("refresh checking ok")
|
||||
if !me.ok {
|
||||
continue
|
||||
}
|
||||
if time.Since(lastRefresh) > 100*time.Millisecond {
|
||||
if time.Since(lastRefresh) > 1000*time.Millisecond {
|
||||
if me.mouse.mouseUp {
|
||||
// log.Info("refresh now on mouseUp")
|
||||
// todo: add logic here to see if the application has changed anything
|
||||
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 {
|
||||
// log.Info("refresh skip on mouseDown")
|
||||
// me.baseGui.Update()
|
||||
|
|
|
@ -65,12 +65,13 @@ type config struct {
|
|||
depth int // used for listWidgets() debugging
|
||||
newWindowTrigger chan *guiWidget // work around hack to redraw windows a bit after NewWindow()
|
||||
stdout stdout // information for the STDOUT window
|
||||
showDebug bool // todo: move this into config struct
|
||||
dropdown dropdown // the dropdown menu
|
||||
textbox dropdown // the textbox popup window
|
||||
clock dropdown // the textbox popup window
|
||||
allwin []*guiWidget // for tracking which window is next
|
||||
dark bool // use a 'dark' color palette
|
||||
mouse mouse // mouse settings
|
||||
showDebug bool // todo: move this into config struct
|
||||
}
|
||||
|
||||
// stuff controlling how the mouse works
|
||||
|
|
Loading…
Reference in New Issue