Basic play controls are now working
[watersofshiloah] / src / playcontrol.py
1 import logging
2
3 import gtk
4
5 import util.misc as misc_utils
6
7
8 _moduleLogger = logging.getLogger(__name__)
9
10
11 class PlayControl(object):
12
13         def __init__(self, player, store):
14                 self._store = store
15
16                 self._player = player
17                 self._player.connect("state-change", self._on_player_state_change)
18                 self._player.connect("navigate-change", self._on_player_nav_change)
19
20                 img = store.get_image_from_store("prev.png")
21                 self._back = gtk.Button()
22                 self._back.set_image(img)
23                 self._back.connect("clicked", self._on_back_clicked)
24
25                 img = store.get_image_from_store("stop.png")
26                 self._stop = gtk.Button()
27                 self._stop.set_image(img)
28                 self._stop.connect("clicked", self._on_stop_clicked)
29
30                 img = store.get_image_from_store("pause.png")
31                 self._pause = gtk.Button()
32                 self._pause.set_image(img)
33                 self._pause.connect("clicked", self._on_pause_clicked)
34
35                 img = store.get_image_from_store("play.png")
36                 self._play = gtk.Button()
37                 self._play.set_image(img)
38                 self._play.connect("clicked", self._on_play_clicked)
39
40                 img = store.get_image_from_store("next.png")
41                 self._next = gtk.Button()
42                 self._next.set_image(img)
43                 self._next.connect("clicked", self._on_next_clicked)
44
45                 self._controls = gtk.HBox()
46                 self._controls.pack_start(self._back)
47                 self._controls.pack_start(self._stop)
48                 self._controls.pack_start(self._pause)
49                 self._controls.pack_start(self._play)
50                 self._controls.pack_start(self._next)
51
52         @property
53         def toplevel(self):
54                 return self._controls
55
56         @misc_utils.log_exception(_moduleLogger)
57         def _on_player_state_change(self, player, newState):
58                 if newState == "play":
59                         self._pause.show()
60                         self._play.hide()
61                 elif newState == "pause":
62                         self._pause.hide()
63                         self._play.show()
64                 elif newState == "stop":
65                         self._pause.hide()
66                         self._play.show()
67
68                 if self._player.can_navigate:
69                         self._back.show()
70                         self._next.show()
71                 else:
72                         self._back.hide()
73                         self._next.hide()
74
75         @misc_utils.log_exception(_moduleLogger)
76         def _on_player_nav_change(self, player, canNavigate):
77                 if canNavigate:
78                         self._back.show()
79                         self._next.show()
80                 else:
81                         self._back.hide()
82                         self._next.hide()
83
84         @misc_utils.log_exception(_moduleLogger)
85         def _on_back_clicked(self, *args):
86                 self._player.back()
87
88         @misc_utils.log_exception(_moduleLogger)
89         def _on_stop_clicked(self, *args):
90                 self._pause.hide()
91                 self._play.show()
92                 self._player.stop()
93
94         @misc_utils.log_exception(_moduleLogger)
95         def _on_pause_clicked(self, *args):
96                 self._pause.show()
97                 self._play.hide()
98                 self._player.pause()
99
100         @misc_utils.log_exception(_moduleLogger)
101         def _on_play_clicked(self, *args):
102                 self._pause.hide()
103                 self._play.show()
104                 self._player.play()
105
106         @misc_utils.log_exception(_moduleLogger)
107         def _on_next_clicked(self, *args):
108                 self._player.next()