]> git.plutz.net Git - viper/blob - PlayerControl.py
moved from svn.imp.fu-berlin.de/viper rev33
[viper] / PlayerControl.py
1 #encoding: utf-8
2 #Copyright 2009 - 2010 Paul Hänsch
3
4 #This file is part of Viper.
5
6 #Viper is free software: you can redistribute it and/or modify
7 #it under the terms of the GNU General Public License as published by
8 #the Free Software Foundation, either version 3 of the License, or
9 #(at your option) any later version.
10
11 #Viper is distributed in the hope that it will be useful,
12 #but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #GNU General Public License for more details.
15
16 #You should have received a copy of the GNU General Public License
17 #along with Viper.  If not, see <http://www.gnu.org/licenses/>
18
19 from Tkinter import *
20 import Pmw
21
22 class PlayerControl(Frame):
23     def __init__(self, parent, player, extrabuttons = []):
24         Frame.__init__(self, parent)
25         self.player = player
26         self.params = []
27         self.loop = BooleanVar(value = True)
28
29         tooltip = Pmw.Balloon()
30         self.subgets = {}
31
32         self.subgets['s_pos'] = Scrollbar(self, orient=HORIZONTAL)
33         self.subgets['s_pos'].pack(side = TOP, anchor = W, fill = X)
34         self.subgets['b_stop'] = Button(self, text = 'Stop',
35                                         command = self.player.stop_video)
36         self.subgets['b_stop'].pack(side = LEFT, anchor = S)
37         tooltip.bind(self.subgets['b_stop'], 'Stop playback (time position to zero).')
38         self.subgets['b_play'] = Button(self, text='Play',
39                                             width=5, command=self.play)
40         self.subgets['b_play'].pack(side = LEFT, anchor = S)
41         tooltip.bind(self.subgets['b_play'], 'Play / Pause the video.')
42         self.subgets['b_step'] = Button(self, text = 'Step',
43                                         command = self.player.step_video)
44         self.subgets['b_step'].pack(side = LEFT, anchor = S)
45         tooltip.bind(self.subgets['b_step'], 'Step a single frame forward.')
46         self.subgets['c_loop'] = Checkbutton(self, text = 'Loop',
47                                              variable = self.loop)
48         self.subgets['c_loop'].pack(side = LEFT, anchor = S)
49
50         for xbut in extrabuttons:
51             self.subgets['xb_' + xbut[0]] = Button(self, text = xbut[0],
52                                                    command = xbut[1])
53             self.subgets['xb_' + xbut[0]].pack(side = RIGHT, anchor = S)
54             try: tooltip.bind(self.subgets['xb_' + xbut[0]], xbut[2])
55             except: pass
56
57         self.player.configure(callback = self.status, slider = self.subgets['s_pos'])
58
59     def configure(self, player):
60         self.player = player
61         self.player.configure(callback = self.status, slider = self.subgets['s_pos'])
62
63     def play(self):
64         self.player.play_video(loop = self.loop.get(),
65                                params = self.params)
66
67     def status(self, state):
68         if state == 'stopped':
69             self.subgets['b_play'].configure(text = 'Play', command = self.play)
70         elif state == 'paused':
71             self.subgets['b_play'].configure(text = 'Play', command = self.play)
72         elif state == 'playing':
73             self.subgets['b_play'].configure(text = 'Pause', command =
74                                                  self.player.pause_video)