]> git.plutz.net Git - viper/blob - videoview.py
886d2f49c28cba64e4f17e90e594366e55953332
[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         self.subgets['ext_player'].stop_video()
89         self.after(100, self.subgets['ext_ctl'].play)
90
91     def c_ext_fullscreen(self):
92         if self.ext_fullscreen.get():
93             #self.subgets['view'].overrideredirect(1)
94             self.subgets['ext_view'].geometry(
95                 str(self.subgets['ext_view'].winfo_screenwidth()) + 'x' +
96                 str(self.subgets['ext_view'].winfo_screenheight()) + '+0+0')
97         else: self.subgets['ext_view'].geometry('320x240')
98
99     def stop_video(self):
100         self.subgets['ext_player'].stop_video()
101         self.subgets['prev_player'].stop_video()
102
103     def b_ext_display(self):
104         try:
105             Tk(screenName=self.subgets['e_display'].get()).destroy()
106             print self.subgets['e_display'].get()
107             self.subgets['ext_view'].destroy()
108             self.subgets['ext_view'] = Tk(screenName=self.subgets['e_display'].get())
109             self.subgets['ext_view'].config(width = 320, height = 240, bg = '#000000')
110             self.subgets['ext_view'].protocol('WM_DELETE_WINDOW', self.attach_view)
111             self.subgets['e_display'].configure(bg='#44FF44')
112         except:
113             self.subgets['e_display'].configure(bg='#FF4444')
114
115     def detach_view(self):
116         self.subgets['main_ctl'].forget()
117         self.subgets['prev_surf'].forget()
118
119         self.subgets['ext_view'] = Tk()
120         self.subgets['ext_view'].title('Viper Display')
121         self.subgets['ext_view'].config(width = 320, height = 240, bg = '#000000')
122         self.subgets['ext_view'].protocol('WM_DELETE_WINDOW', self.attach_view)
123         self.subgets['ext_player'].configure(surface = self.subgets['ext_view'])
124
125         self.subgets['prev_surf'].pack(in_ = self.subgets['preview'],
126                                        before = self.subgets['prev_ctl'],
127                                        side = TOP, anchor = W, fill = BOTH,
128                                        expand = True)
129         self.subgets['prev_ctl'].configure(self.subgets['prev_player'])
130
131         self.subgets['tablist'].pack(in_= self, side=TOP,anchor=W,
132                                      fill=BOTH, expand=True)
133         self.attached_view = False
134
135     def attach_view(self):
136         self.subgets['ext_player'].stop_video()
137         self.subgets['prev_player'].stop_video()
138         self.subgets['ext_view'].destroy()
139         self.subgets['tablist'].forget()
140         self.subgets['main_ctl'].forget()
141         self.subgets['prev_surf'].forget()
142
143         self.subgets['prev_surf'].pack(in_ = self, side = TOP, anchor = W,
144                                        fill = BOTH, expand = True)
145         self.subgets['main_ctl'].pack(side = BOTTOM, anchor = W, fill = X)
146         self.subgets['main_ctl'].configure(self.subgets['prev_player'])
147         self.attached_view = True