summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-01-29 00:41:21 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2016-01-29 00:41:21 (GMT)
commitc8e6a5570cf122e47f54a1922fecb563e697aa37 (patch)
tree8a3653ee3ca5db9a52601c20e8c5207f0426739f
parent3c856f9ced4bee997611e78b64abd138645408ca (diff)
disable buttons when they do nothing
-rw-r--r--src/rhlibrary/player_widget.go46
-rw-r--r--src/rhlibrary/selector_widget.go11
2 files changed, 55 insertions, 2 deletions
diff --git a/src/rhlibrary/player_widget.go b/src/rhlibrary/player_widget.go
index 261c70d..b86d236 100644
--- a/src/rhlibrary/player_widget.go
+++ b/src/rhlibrary/player_widget.go
@@ -49,6 +49,7 @@ func addPlayPauseButton(box *gtk.Box, p *player.PlayerChan) (err error) {
return
}
btn.SetImage(playIcon)
+ btn.SetSensitive(false)
btn.Connect("clicked", func(_ *gtk.Button) {
if err := p.PlayPause(); err != nil {
@@ -60,10 +61,13 @@ func addPlayPauseButton(box *gtk.Box, p *player.PlayerChan) (err error) {
glib.IdleAdd(func() {
switch state {
case player.IDLE:
- fallthrough
+ btn.SetSensitive(false)
+ btn.SetImage(playIcon)
case player.PAUSED:
+ btn.SetSensitive(true)
btn.SetImage(playIcon)
case player.PLAYING:
+ btn.SetSensitive(true)
btn.SetImage(pauseIcon)
}
})
@@ -79,11 +83,28 @@ func addStopButton(box *gtk.Box, p *player.PlayerChan) (err error) {
if btn, err = gtk.ButtonNewFromIconName("media-playback-stop", gtk.ICON_SIZE_DIALOG); err != nil {
return
}
+ btn.SetSensitive(false)
+
btn.Connect("clicked", func(_ *gtk.Button) {
if err := p.Stop(); err != nil {
rhdl.Println(err) // TODO: feedback at GUI?
}
})
+
+ p.AddStateChangeHandler(func(state player.State, _ interface{}) bool {
+ glib.IdleAdd(func() {
+ switch state {
+ case player.IDLE:
+ btn.SetSensitive(false)
+ case player.PAUSED:
+ btn.SetSensitive(true)
+ case player.PLAYING:
+ btn.SetSensitive(true)
+ }
+ })
+ return true
+ }, nil)
+
box.PackStart(btn, false, false, 0)
return
}
@@ -130,9 +151,30 @@ func addScrubber(grid *gtk.Grid, p *player.PlayerChan) (err error) {
rhdl.Println(err) // TODO: feedback at GUI?
}
})
+ scale.SetSensitive(false)
p.AddUpdateHandler(func(duration time.Duration, pos time.Duration, _ player.Meter, _ interface{}) bool {
- glib.IdleAdd(func() { scale.SetValue(float64(pos) / float64(duration)) })
+ glib.IdleAdd(func() {
+ if duration > 0 {
+ scale.SetValue(float64(pos) / float64(duration))
+ } else {
+ scale.SetValue(0)
+ }
+ })
+ return true
+ }, nil)
+
+ p.AddStateChangeHandler(func(state player.State, _ interface{}) bool {
+ glib.IdleAdd(func() {
+ switch state {
+ case player.IDLE:
+ scale.SetSensitive(false)
+ case player.PAUSED:
+ scale.SetSensitive(true)
+ case player.PLAYING:
+ scale.SetSensitive(true)
+ }
+ })
return true
}, nil)
diff --git a/src/rhlibrary/selector_widget.go b/src/rhlibrary/selector_widget.go
index d571e3d..becf413 100644
--- a/src/rhlibrary/selector_widget.go
+++ b/src/rhlibrary/selector_widget.go
@@ -64,11 +64,22 @@ func getSelectorWidget(p *player.PlayerChan) (gtk.IWidget, error) {
}
})
+ var unloadBtn *gtk.Button
+ if unloadBtn, err = gtk.ButtonNewWithLabel("UNLOAD"); err != nil {
+ return nil, err
+ }
+ unloadBtn.Connect("clicked", func(_ *gtk.Button) {
+ if err := p.Unload(); err != nil {
+ rhdl.Println(err) // TODO: feedback at GUI?
+ }
+ })
+
grid.Attach(cartl, 1, 1, 1, 1)
grid.Attach(cart, 2, 1, 1, 1)
grid.Attach(cutl, 1, 2, 1, 1)
grid.Attach(cut, 2, 2, 1, 1)
grid.Attach(loadBtn, 1, 3, 2, 1)
+ grid.Attach(unloadBtn, 1, 4, 2, 1)
grid.SetHExpand(true)
grid.SetVExpand(true)