~openshot.developers/openshot/debian-packages

« back to all changes in this revision

Viewing changes to openshot/openshot/classes/track.py

  • Committer: Jonathan Thomas
  • Date: 2010-02-08 00:38:50 UTC
  • Revision ID: jonathan@jonathan64-20100208003850-i03t93q4vob0wmp8
Fixed the following Debian packaging issues:
-----------
Updated the control file to include a better description,
 new standards-version, updated dependencies.

Removed the /openshot/ source from this branch... since
it should be added by renaming and extracting the source
tar.gz file.

Added 2 folders, one for debian and one for my 
LaunchPad ppa (which has a different changelog)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#       OpenShot Video Editor is a program that creates, modifies, and edits video files.
2
 
#   Copyright (C) 2009  Jonathan Thomas
3
 
#
4
 
#       This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
5
 
#
6
 
#       OpenShot Video Editor 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
 
#       OpenShot Video Editor 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 OpenShot Video Editor.  If not, see <http://www.gnu.org/licenses/>.
18
 
 
19
 
import uuid
20
 
import gtk, goocanvas
21
 
from classes import clip, files, transition
22
 
 
23
 
# init the foreign language
24
 
from language import Language_Init
25
 
 
26
 
class track:
27
 
        """The track class contains a simple grouping of clips on the same layer (aka track)."""
28
 
 
29
 
        #----------------------------------------------------------------------
30
 
        def __init__(self, track_name, parent_sequence):
31
 
                """Constructor"""
32
 
                
33
 
                # Add language support
34
 
                translator = Language_Init.Translator(parent_sequence.project)
35
 
                _ = translator.lang.gettext
36
 
                
37
 
                # init variables for sequence
38
 
                self.name = track_name
39
 
                self.x = 10              # left x coordinate to start the track
40
 
                self.y_top = 0    # top y coordinate of this track
41
 
                self.y_bottom = 0   # bottom y coordinate of this track
42
 
                self.parent = parent_sequence   # reference to parent sequence object
43
 
                self.play_video = True
44
 
                self.play_audio = True
45
 
                self.unique_id = str(uuid.uuid1())
46
 
 
47
 
                # init the tracks on the sequence
48
 
                self.clips = []
49
 
 
50
 
                # init transitions
51
 
                self.transitions = []
52
 
                
53
 
                
54
 
        
55
 
        def AddClip(self, clip_name, color, position_on_track, start_time, end_time, file_object):
56
 
                # Create new clip object and append to list
57
 
                NewClip = clip.clip(clip_name, color, position_on_track, start_time, end_time, self, file_object)
58
 
                
59
 
                # Adjust default length of images (all images default to 300 seconds.. i.e. 5 minutes)
60
 
                # But since nobody wants an image to default to 5 minutes long, we adjust it to the default image length.
61
 
                if NewClip.length() == 300.0:
62
 
                        from windows import preferences
63
 
                        NewClip.end_time = NewClip.start_time + float(preferences.Settings.general["imported_image_length"])#7.0
64
 
                
65
 
                # Add clip to track's clip list
66
 
                self.clips.append(NewClip)
67
 
                
68
 
                # mark project as modified
69
 
                self.parent.project.set_project_modified(is_modified=True, refresh_xml=True)
70
 
                
71
 
                # return the new clip
72
 
                return NewClip
73
 
                        
74
 
                        
75
 
        def AddTransition(self, transition_name, position_on_track, length, resource):
76
 
                
77
 
                # mark project as modified
78
 
                self.parent.project.set_project_modified(is_modified=True, refresh_xml=True)
79
 
                
80
 
                # create a new transition object
81
 
                new_transition = transition.transition(transition_name, position_on_track, length, resource, self)
82
 
                
83
 
                # insert new transition
84
 
                self.transitions.append(new_transition)
85
 
                return new_transition
86
 
                 
87
 
        
88
 
        
89
 
        def Render(self):
90
 
 
91
 
                # Render this track
92
 
                self.RenderTrack()
93
 
                
94
 
                # loop through each track
95
 
                for MyClip in self.clips:
96
 
                        
97
 
                        # Render track                  
98
 
                        MyClip.Render()                         
99
 
                
100
 
                        
101
 
                        
102
 
                        
103
 
        def GenerateXML(self, dom, xmlParentNode):
104
 
                
105
 
                playlist = dom.createElement("playlist")
106
 
                playlist.setAttribute("id", self.name)
107
 
                xmlParentNode.appendChild(playlist)
108
 
                
109
 
                current_frame = 0
110
 
                
111
 
                # loop through each track
112
 
                for MyClip in self.clips:
113
 
                        
114
 
                        # Render track                  
115
 
                        current_frame = MyClip.GenerateXML(dom, playlist, current_frame)
116
 
 
117
 
 
118
 
                        
119
 
        #----------------------------------------------------------------------
120
 
        def RenderTrack(self):
121
 
                """This adds a track to the canvas with 3 images: a left, middle, and right"""
122
 
 
123
 
                # get the pixels per second from the parent sequence
124
 
                pixels_per_second = self.parent.get_pixels_per_second()
125
 
                
126
 
                # get the previous track from the parent sequence (if any)
127
 
                previous_track_index = self.parent.tracks.index(self) - 1
128
 
                previous_track = None
129
 
                previous_y_top = 0
130
 
                previous_y_bottom = 0
131
 
                
132
 
                if (previous_track_index >= 0):
133
 
                        previous_track = self.parent.tracks[previous_track_index]
134
 
                        previous_y_top = previous_track.y_top
135
 
                        previous_y_bottom = previous_track.y_bottom
136
 
                
137
 
                # set the top coordinate of this track to the bottom coordinate of the last track
138
 
                self.y_top = previous_y_bottom + 6
139
 
                
140
 
                # get a reference to the 2 main canvas objects & theme
141
 
                theme = self.parent.project.theme
142
 
                canvas_left = self.parent.project.form.MyCanvas_Left
143
 
                canvas_right = self.parent.project.form.MyCanvas
144
 
                
145
 
                # Add an item to the goocanvas
146
 
                root_left = canvas_left.get_root_item ()
147
 
                root_right = canvas_right.get_root_item ()
148
 
 
149
 
                # Load all 3 images
150
 
                imgTrack_Left = gtk.image_new_from_file("%s/openshot/themes/%s/Track_Left.png" % (self.parent.project.form.openshot_path, theme))
151
 
                imgTrack_Middle = gtk.image_new_from_file("%s/openshot/themes/%s/Track_Middle.png" % (self.parent.project.form.openshot_path, theme))
152
 
                imgTrack_Right = gtk.image_new_from_file("%s/openshot/themes/%s/Track_Right.png" % (self.parent.project.form.openshot_path, theme))                     
153
 
 
154
 
                # Get Height and Width of Images 
155
 
                imgTrack_Left_Height = imgTrack_Left.get_pixbuf().get_height()
156
 
                imgTrack_Left_Width = imgTrack_Left.get_pixbuf().get_width()
157
 
                imgTrack_Right_Width = imgTrack_Right.get_pixbuf().get_width()          
158
 
 
159
 
                # Get Size of Window (to determine how wide the middle image should be streched)
160
 
                Size_Of_Middle = int(pixels_per_second * self.parent.length)
161
 
 
162
 
                # Resize Middle pixbuf
163
 
                middlePixBuf = imgTrack_Middle.get_pixbuf()
164
 
                pixbuf_list = self.parent.split_images(middlePixBuf, imgTrack_Left_Height, Size_Of_Middle)        
165
 
                
166
 
                # Create Group (for the track)
167
 
                GroupTrack = goocanvas.Group (parent = root_right)
168
 
                GroupTrack_Left = goocanvas.Group (parent = root_left)
169
 
                
170
 
                # set the unique ID of the group
171
 
                GroupTrack.set_data ("id", self.unique_id)
172
 
 
173
 
                # Add Left Image to Group
174
 
                image1 = goocanvas.Image (parent = GroupTrack_Left,
175
 
                                                                  pixbuf = imgTrack_Left.get_pixbuf(),
176
 
                                                                  x = self.x,
177
 
                                                                  y = self.y_top)
178
 
 
179
 
                # Track the state of the hover over image
180
 
                image1.set_data ("id", "normal")
181
 
                image1.connect ("button_press_event", self.on_focus_in)
182
 
 
183
 
                
184
 
                # Add Middle Image to Group (this can be multiple image tiled together
185
 
                pixbuf_x = 0
186
 
                for pixbuf in pixbuf_list:
187
 
                        # get width of this pixbuf
188
 
                        pixbuf_width = pixbuf.get_width()
189
 
                        
190
 
                        image2 = goocanvas.Image (parent = GroupTrack,
191
 
                                                                          pixbuf = pixbuf,
192
 
                                                                          x = pixbuf_x,
193
 
                                                                          y = self.y_top)  
194
 
                        
195
 
                        # increment the x
196
 
                        pixbuf_x = pixbuf_x + pixbuf_width
197
 
 
198
 
                # Add Middle Image to Group
199
 
                image3 = goocanvas.Image (parent = GroupTrack,
200
 
                                                                  pixbuf = imgTrack_Right.get_pixbuf(),
201
 
                                                                  x = Size_Of_Middle - 1,
202
 
                                                                  y = self.y_top)       
203
 
                
204
 
                # Add Text to the Track
205
 
                text1 = goocanvas.Text (parent = GroupTrack_Left,
206
 
                                                                text = "%s" % self.name,
207
 
                                                                font = "Sans 9",
208
 
                                                                antialias = False,
209
 
                                                                x = self.x + 8,
210
 
                                                                y = self.y_top + 7)
211
 
                
212
 
                # Load buttons
213
 
                if self.play_video:
214
 
                        imgTrack_Visible = gtk.image_new_from_file("%s/openshot/themes/%s/visible.png" % (self.parent.project.form.openshot_path, theme))
215
 
                else:
216
 
                        imgTrack_Visible = gtk.image_new_from_file("%s/openshot/themes/%s/not_visible.png" % (self.parent.project.form.openshot_path, theme))
217
 
                if self.play_audio:
218
 
                        imgTrack_Audio = gtk.image_new_from_file("%s/openshot/themes/%s/speaker.png" % (self.parent.project.form.openshot_path, theme))
219
 
                else:
220
 
                        imgTrack_Audio = gtk.image_new_from_file("%s/openshot/themes/%s/speaker_mute.png" % (self.parent.project.form.openshot_path, theme))
221
 
                
222
 
                # Add Visible Image to Group
223
 
                image4 = goocanvas.Image (parent = GroupTrack_Left,
224
 
                                                                  pixbuf = imgTrack_Visible.get_pixbuf(),
225
 
                                                                  x = self.x + 7,
226
 
                                                                  y = self.y_top + 27)  
227
 
                
228
 
                # Track the state of the hover over image
229
 
                image4.connect ("button_press_event", self.on_visible_click)
230
 
                
231
 
                # Add Visible Image to Group
232
 
                image5 = goocanvas.Image (parent = GroupTrack_Left,
233
 
                                                                  pixbuf = imgTrack_Audio.get_pixbuf(),
234
 
                                                                  x = self.x + 28,
235
 
                                                                  y = self.y_top + 27)  
236
 
                
237
 
                # Track the state of the hover over image
238
 
                image5.connect ("button_press_event", self.on_audio_click)
239
 
                
240
 
                # Increment the Y cooridinate (by the height of the left image)
241
 
                self.y_bottom = self.y_top + imgTrack_Left_Height
242
 
                
243
 
 
244
 
                
245
 
 
246
 
        def on_visible_click (self, item, target, event):
247
 
 
248
 
                # get the parent left group
249
 
                parent_group = item.get_parent()
250
 
                
251
 
                # mark project as modified
252
 
                self.parent.project.set_project_modified(is_modified=True, refresh_xml=True)
253
 
 
254
 
                if self.play_video == True:
255
 
                        # Load Hover Over
256
 
                        imgTrack_Left_Hover = gtk.image_new_from_file("%s/openshot/themes/%s/not_visible.png" % (self.parent.project.form.openshot_path, self.parent.project.theme))
257
 
                        item.set_properties(pixbuf = imgTrack_Left_Hover.get_pixbuf())
258
 
                        
259
 
                        # update play video variable
260
 
                        self.play_video = False
261
 
                        
262
 
                else: 
263
 
                        # Load normal image
264
 
                        imgTrack_Left_Hover = gtk.image_new_from_file("%s/openshot/themes/%s/visible.png" % (self.parent.project.form.openshot_path, self.parent.project.theme))
265
 
                        item.set_properties(pixbuf = imgTrack_Left_Hover.get_pixbuf())
266
 
 
267
 
                        # update play video variable
268
 
                        self.play_video = True
269
 
 
270
 
                return False
271
 
        
272
 
        
273
 
        def on_audio_click (self, item, target, event):
274
 
 
275
 
                # get the parent left group
276
 
                parent_group = item.get_parent()
277
 
                
278
 
                # mark project as modified
279
 
                self.parent.project.set_project_modified(is_modified=True, refresh_xml=True)
280
 
 
281
 
                if self.play_audio == True:
282
 
                        # Load Hover Over
283
 
                        imgTrack_Left_Hover = gtk.image_new_from_file("%s/openshot/themes/%s/speaker_mute.png" % (self.parent.project.form.openshot_path, self.parent.project.theme))
284
 
                        item.set_properties(pixbuf = imgTrack_Left_Hover.get_pixbuf())
285
 
                        
286
 
                        # update play audio variable
287
 
                        self.play_audio = False
288
 
                        
289
 
                else: 
290
 
                        # Load normal image
291
 
                        imgTrack_Left_Hover = gtk.image_new_from_file("%s/openshot/themes/%s/speaker.png" % (self.parent.project.form.openshot_path, self.parent.project.theme))
292
 
                        item.set_properties(pixbuf = imgTrack_Left_Hover.get_pixbuf())
293
 
                        
294
 
                        # update play audio variable
295
 
                        self.play_audio = True
296
 
 
297
 
                return False
298
 
 
299
 
                
300
 
        def on_focus_in (self, item, target, event):
301
 
                isinstance(item, goocanvas.Image)               
302
 
                id = item.get_data ("id")
303
 
                
304
 
                if event.button == 3:
305
 
                        # show the track popup menu
306
 
                        self.parent.project.form.mnuTrack1.showmnu(event, self)
307
 
 
308
 
                if id == "normal":
309
 
                        # Load Hover Over
310
 
                        imgTrack_Left_Hover = gtk.image_new_from_file("%s/openshot/themes/%s/Track_Left_Hover.png" % (self.parent.project.form.openshot_path, self.parent.project.theme))
311
 
                        item.set_properties(pixbuf = imgTrack_Left_Hover.get_pixbuf())
312
 
                        item.set_data("id", "hover")
313
 
                else: 
314
 
                        # Load normal image
315
 
                        imgTrack_Left_Hover = gtk.image_new_from_file("%s/openshot/themes/%s/Track_Left.png" % (self.parent.project.form.openshot_path, self.parent.project.theme))
316
 
                        item.set_properties(pixbuf = imgTrack_Left_Hover.get_pixbuf())
317
 
                        item.set_data("id", "normal")
318
 
 
319
 
 
320
 
                return False
321
 
        
322
 
        
323
 
        def reorder_clips(self):
324
 
                # get a list of all clips on this track
325
 
                self.clips.sort(self.compare_clip)
326
 
                
327
 
                
328
 
        def compare_clip(self, MyClip1, MyClip2):
329
 
                if MyClip1.position_on_track > MyClip2.position_on_track:
330
 
                        return 1
331
 
                elif MyClip1.position_on_track == MyClip2.position_on_track:
332
 
                        return 0
333
 
                else:
334
 
                        return -1
335
 
 
336
 
                
337
 
        def reorder_transitions(self):
338
 
                # get a list of all clips on this track
339
 
                self.transitions.sort(self.compare_transitions)
340
 
                
341
 
                
342
 
        def compare_transitions(self, MyClip1, MyClip2):
343
 
                if MyClip1.position_on_track > MyClip2.position_on_track:
344
 
                        return 1
345
 
                elif MyClip1.position_on_track == MyClip2.position_on_track:
346
 
                        return 0
347
 
                else:
348
 
                        return -1
 
 
b'\\ No newline at end of file'