diff options
| author | Pietro Gagliardi <[email protected]> | 2014-03-12 17:31:13 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-03-12 17:31:13 -0400 |
| commit | 6ee8d96a6e8c1e95b8ca2ab19fcc6a3a856d50c8 (patch) | |
| tree | 110c533c390b09eedeeeb45c370a42d6201b4a60 /sysdata_unix.go | |
| parent | bf093d534c0bc64fa7da38708c05e5a632964ae7 (diff) | |
Added GTK+ indeterminate ProgressBars.
Diffstat (limited to 'sysdata_unix.go')
| -rw-r--r-- | sysdata_unix.go | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/sysdata_unix.go b/sysdata_unix.go index 6947e20..91b301c 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -4,7 +4,7 @@ package ui import ( - // ... + "time" ) type sysData struct { @@ -12,6 +12,7 @@ type sysData struct { widget *gtkWidget container *gtkWidget // for moving + pulse chan bool // for sysData.progressPulse() } type classData struct { @@ -285,7 +286,56 @@ func (s *sysData) delete(index int) { <-ret } +// With GTK+, we must manually pulse the indeterminate progressbar ourselves. This goroutine does that. +func (s *sysData) progressPulse() { + pulse := func() { + ret := make(chan struct{}) + defer close(ret) + uitask <- func() { + gtk_progress_bar_pulse(s.widget) + ret <- struct{}{} + } + <-ret + } + + var ticker *time.Ticker + var tickchan <-chan time.Time + + // the default on Windows + const pulseRate = 30 * time.Millisecond + + for { + select { + case start := <-s.pulse: + if start { + ticker = time.NewTicker(pulseRate) + tickchan = ticker.C + pulse() // start the pulse animation now, not 30ms later + } else { + if ticker != nil { + ticker.Stop() + } + ticker = nil + tickchan = nil + s.pulse <- true // notify sysData.setProgress() + } + case <-tickchan: + pulse() + } + } +} + func (s *sysData) setProgress(percent int) { + if s.pulse == nil { + s.pulse = make(chan bool) + go s.progressPulse() + } + if percent == -1 { + s.pulse <- true + return + } + s.pulse <- false + <-s.pulse // wait for sysData.progressPulse() to register that ret := make(chan struct{}) defer close(ret) uitask <- func() { |
