]> git.plutz.net Git - viper/blob - vframeset.py
implemeted most basic cropping controls
[viper] / vframeset.py
1 #encoding: utf-8
2 #Copyright 2011 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 from flic import *
22
23 class VFrameset(LabelFrame, Flic):
24     """
25     Visual frameset widget
26
27     This widget represents a set of frames and provides controls for manipulating
28     and positioning it.
29
30     Properties are:
31     schedule (string)   - commands to the owning object, values can be
32                             mv left : move this chunk left
33                             mv right: move this chunk right
34                             copy    : double this chunk
35                             apply   : realize new video properties
36                             delete  : remove this chunk
37     
38     subgets             - dictionary of widgets forming this
39                           complex widget
40     played (Tk.Boolean) - indicates status of the play checkbox (use ...play.get())
41     marked (Tk.Boolean) - indicates status of the mark checkbox (use ...mark.get())
42     """
43
44     def __init__(self, master = None, vurl = '', play = True):
45         """
46         Constructor
47
48         master - the holding widget
49         """
50         self.vurl = vurl
51         self.subgets = {}
52         self.schedule = ''
53         self.animate = play
54         self.played = BooleanVar(value = True)
55         self.marked = BooleanVar(value = True)
56
57         tooltips = Pmw.Balloon()
58
59         Flic.__init__(self)
60         LabelFrame.__init__(self, master = master, text = vurl.split('/')[-1])
61         self.subgets['video'] = Frame(self, height=90, width=120, bg = '#000000')
62         self.subgets['video'].grid(column=0, row=0, rowspan=4, sticky=W)
63
64         self.subgets['b_edit'] = Button(self, text = 'Edit', command = self.edit)
65         self.subgets['b_edit'].grid(column = 1, row=1, columnspan = 4, rowspan = 2)
66         tooltips.bind(self.subgets['b_edit'], 'Select and remove single frames from frameset.')
67
68         self.subgets['b_mvbw'] = Button(self, text = '<-', command=self.mvbw)
69         self.subgets['b_mvbw'].grid(column = 1, row = 3, rowspan = 1, columnspan = 2, sticky=E)
70         tooltips.bind(self.subgets['b_mvbw'],
71                       'Swap this chunk with its left neighbour (move it left).')
72
73         self.subgets['b_copy'] = Button(self, text = 'Copy', command=self.copy)
74         self.subgets['b_copy'].grid(column = 3, columnspan = 2, row = 3, rowspan = 1)
75         tooltips.bind(self.subgets['b_copy'],
76                       'Create another chunk with the same properties as this one.')
77
78         self.subgets['b_mvfw'] = Button(self, text = '->', command=self.mvfw)
79         self.subgets['b_mvfw'].grid(column = 5, row = 3, rowspan = 1, sticky=W)
80         tooltips.bind(self.subgets['b_mvfw'],
81                       'Swap this chunk with its right neighbour (move it right).')
82
83         self.subgets['c_play'] = Checkbutton(self, text='Play', offvalue=False,
84                                              onvalue=True, variable = self.played)
85 #        self.subgets['c_play'].select()
86         self.subgets['c_play'].grid(column=1, columnspan = 2, row=0)
87         tooltips.bind(self.subgets['c_play'],
88                       'Mark this chunk for playback in main window.')
89
90         self.subgets['c_mark'] = Checkbutton(self, text='Mark', offvalue=False,
91                                              onvalue=True, variable = self.marked)
92 #        self.subgets['c_mark'].select()
93         self.subgets['c_mark'].grid(column=3, columnspan = 2, row=0)
94         tooltips.bind(self.subgets['c_mark'],
95                       'Mark this chunk for application of choosen filters and effects.')
96
97         self.subgets['b_del'] = Button(self, text='Del', command = self.delete)
98         self.subgets['b_del'].grid(column=5, row=0, sticky=NE)
99         tooltips.bind(self.subgets['b_del'],
100                       'Remove this chunk from the project.')
101         self.schedule = 'apply'
102
103     def load_filters(self, dbcur, num):
104         """
105         Load filter list from database
106
107         db  - sqlite database cursor
108         num - database primary key id of this chunk
109         """
110
111         dbcur.execute('SELECT iorder FROM filters ' +
112                       'WHERE chunk = ' + str(num) + ' ORDER BY iorder')
113         for filter in dbcur.fetchall():
114             dbcur.execute('SELECT line FROM filter_lines WHERE filter = ' +
115                           str(filter[0]) + ' ORDER BY iorder')
116             line = []
117             for item in dbcur.fetchall():
118                 line.append(item[0])
119             self.add_filter(line)
120
121     def delete(self):
122         """
123         Scheduler for internal use
124         """
125         self.schedule = 'delete'
126
127     def mvbw(self):
128         """
129         Scheduler for internal use
130         """
131         self.schedule = 'mv left'
132
133     def mvfw(self):
134         """
135         Scheduler for internal use
136         """
137         self.schedule = 'mv right'
138
139     def copy(self):
140         """
141         Scheduler for internal use
142         """
143         self.schedule = 'copy'
144
145     def store(self, dbcur):
146         """
147         Store chunk to database
148
149         The tables "chunks", "filters" and "filter_lines"
150         must be prepared in database.
151
152         dbcur - sqlite database cursor
153         """
154         if self.played.get(): played = '1'
155         else: played = '0'
156         if self.marked.get(): marked = '1'
157         else: marked = '0'
158         dbcur.execute('INSERT INTO chunks (filename, start, frames, played, marked) ' + 
159                       'VALUES ("' + self.vurl + '", 0, 0, ' + played + ', ' + marked + ');')
160
161         dbcur.execute('SELECT last_insert_rowid();')
162         chunk_id = str(dbcur.fetchone()[0])
163
164         for filter in self.filters:
165             dbcur.execute('INSERT INTO filters (chunk) VALUES (' + chunk_id + ');')
166             dbcur.execute('SELECT last_insert_rowid();')
167             filter_id = str(dbcur.fetchone()[0])
168             for line in filter:
169                 dbcur.execute('INSERT INTO filter_lines (line, filter) ' +
170                               'VALUES ("' + line + '", ' + filter_id + ')')
171     def slave_video(self):
172         return [self.vurl]
173
174     def edit(self):
175         self.schedule = 'apply'
176
177     def play(self):
178         Flic.play(self, self.subgets['video'].winfo_id(), width=120, height=90)