]> git.plutz.net Git - viper/blob - videoview.py
implemeted most basic cropping controls
[viper] / videoview.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 from player import *
21 from PlayerControl import *
22 import Pmw
23 import os
24 import threading
25
26 class VideoView(Frame):
27     """
28     Widget for video main view
29     """
30     def __init__(self, parent):
31         Frame.__init__(self, parent)
32         self.ext_fullscreen = BooleanVar(value = False)
33         self.ext_loop = BooleanVar(value = True)
34         self.prev_loop = BooleanVar(value = False)
35         self.loop = BooleanVar(False)
36         self.attached_view = True
37
38         self.params = []
39         self.subgets = {}
40         tooltip = Pmw.Balloon()
41         
42         self.subgets['tablist'] = Pmw.NoteBook(self)
43         self.subgets['extopts'] = self.subgets['tablist'].add('External View')
44         self.subgets['f_extparam'] = Frame(self.subgets['extopts'])
45         self.subgets['f_extparam'].pack(side = TOP)
46         self.subgets['e_display'] = Entry(self.subgets['f_extparam'])
47         self.subgets['e_display'].pack(side = LEFT, anchor = N, fill = X,
48                                        expand = True, padx = 10)
49         self.subgets['b_extdisplay'] = Button(self.subgets['f_extparam'],
50                                               text = 'Set Display',
51                                               command = self.b_ext_display)
52         self.subgets['b_extdisplay'].pack(side = LEFT, anchor = N, expand = True)
53         self.subgets['c_extfullscreen'] = Checkbutton(self.subgets['extopts'],
54                                                       text = 'Fullscreen',
55                                                       command = self.c_ext_fullscreen,
56                                                       variable = self.ext_fullscreen)
57         self.subgets['c_extfullscreen'].pack(side = TOP)
58
59         self.subgets['ext_surf'] = Frame(self, width = 320, height = 240, bg="#000000")
60         self.subgets['ext_player'] = Player(self, surface = self.subgets['ext_surf'])
61         self.subgets['ext_ctl'] = PlayerControl(self.subgets['extopts'],
62                                                 self.subgets['ext_player'],
63                                                 [('Attach', self.attach_view,
64                                                   'Reattach external player window')])
65         self.subgets['ext_ctl'].pack(side = BOTTOM, anchor = W, fill = X)
66
67         self.subgets['preview'] = self.subgets['tablist'].add('Preview')
68         self.subgets['prev_surf'] = Frame(self, width = 160, height = 120, bg="#000000")
69         self.subgets['prev_surf'].pack(side = TOP, anchor = W, fill = BOTH,
70                                        expand = True)
71         self.subgets['prev_player'] = Player(self, surface = self.subgets['prev_surf'])
72         self.subgets['prev_ctl'] = PlayerControl(self.subgets['preview'],
73                                                  self.subgets['prev_player'],
74                                                 [('To Main View', self.prev_apply,
75                                                   'Play this on external view')])
76         self.subgets['prev_ctl'].pack(side = BOTTOM, anchor = W, fill = X)
77         self.subgets['main_ctl'] = PlayerControl(self, self.subgets['prev_player'],
78                                                  [('Detach', self.detach_view,
79                                                    'Detach external player window')])
80         self.subgets['main_ctl'].pack(side = BOTTOM, anchor = W, fill = X)
81
82     def set_playback_params(self, params):
83         self.subgets['ext_ctl'].params = params
84         self.subgets['prev_ctl'].params = params
85         self.subgets['main_ctl'].params = params
86
87     def prev_apply(self):
88         """
89         Put video from preview to main display
90         """
91         self.subgets['ext_player'].stop_video()
92         self.after(100, self.subgets['ext_ctl'].play)
93
94     def c_ext_fullscreen(self):
95         """
96         Toggle fullscreen mode of main displaye
97         """
98         if self.ext_fullscreen.get():
99             #self.subgets['view'].overrideredirect(1)
100             self.subgets['ext_view'].geometry(
101                 str(self.subgets['ext_view'].winfo_screenwidth()) + 'x' +
102                 str(self.subgets['ext_view'].winfo_screenheight()) + '+0+0')
103         else: self.subgets['ext_view'].geometry('320x240')
104
105     def stop_video(self):
106         self.subgets['ext_player'].stop_video()
107         self.subgets['prev_player'].stop_video()
108
109     def b_ext_display(self):
110         """
111         Button handler. Move External video window to X11 display given in entry box.
112         """
113         try:
114             Tk(screenName=self.subgets['e_display'].get()).destroy()
115             print self.subgets['e_display'].get()
116             self.subgets['ext_view'].destroy()
117             self.subgets['ext_view'] = Tk(screenName=self.subgets['e_display'].get())
118             self.subgets['ext_view'].config(width = 320, height = 240, bg = '#000000')
119             self.subgets['ext_view'].protocol('WM_DELETE_WINDOW', self.attach_view)
120             self.subgets['e_display'].configure(bg='#44FF44')
121         except:
122             self.subgets['e_display'].configure(bg='#FF4444')
123
124     def detach_view(self):
125         """
126         Spawn a detached video display, replacing the display area with a preview tab
127         and a control tab. A currently playing video continues to run as preview.
128         """
129         self.subgets['main_ctl'].forget()
130         self.subgets['prev_surf'].forget()
131
132         self.subgets['ext_view'] = Tk()
133         self.subgets['ext_view'].title('Viper Display')
134         self.subgets['ext_view'].config(width = 320, height = 240, bg = '#000000')
135         self.subgets['ext_view'].protocol('WM_DELETE_WINDOW', self.attach_view) #Callback to attach_view when window is closed
136         self.subgets['ext_player'].configure(surface = self.subgets['ext_view'])
137
138         self.subgets['prev_surf'].pack(in_ = self.subgets['preview'],
139                                        before = self.subgets['prev_ctl'],
140                                        side = TOP, anchor = W, fill = BOTH,
141                                        expand = True)
142         self.subgets['prev_ctl'].configure(self.subgets['prev_player'])
143
144         self.subgets['tablist'].pack(in_= self, side=TOP,anchor=W,
145                                      fill=BOTH, expand=True)
146         self.attached_view = False
147
148     def attach_view(self):
149         """
150         Reembed detached view into the main interface, stopping the playing video.
151         """
152         self.subgets['ext_player'].stop_video()
153         self.subgets['prev_player'].stop_video()
154         self.subgets['ext_view'].destroy()
155         self.subgets['tablist'].forget()
156         self.subgets['main_ctl'].forget()
157         self.subgets['prev_surf'].forget()
158
159         self.subgets['prev_surf'].pack(in_ = self, side = TOP, anchor = W,
160                                        fill = BOTH, expand = True)
161         self.subgets['main_ctl'].pack(side = BOTTOM, anchor = W, fill = X)
162         self.subgets['main_ctl'].configure(self.subgets['prev_player'])
163         self.subgets['main_ctl'].status('stopped')
164         self.attached_view = True