1
# OpenShot Video Editor is a program that creates, modifies, and edits video files.
2
# Copyright (C) 2009 Jonathan Thomas
4
# This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
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.
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.
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/>.
21
from classes import clip, files, transition
23
# init the foreign language
24
from language import Language_Init
27
"""The track class contains a simple grouping of clips on the same layer (aka track)."""
29
#----------------------------------------------------------------------
30
def __init__(self, track_name, parent_sequence):
33
# Add language support
34
translator = Language_Init.Translator(parent_sequence.project)
35
_ = translator.lang.gettext
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())
47
# init the tracks on the sequence
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)
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
65
# Add clip to track's clip list
66
self.clips.append(NewClip)
68
# mark project as modified
69
self.parent.project.set_project_modified(is_modified=True, refresh_xml=True)
75
def AddTransition(self, transition_name, position_on_track, length, resource):
77
# mark project as modified
78
self.parent.project.set_project_modified(is_modified=True, refresh_xml=True)
80
# create a new transition object
81
new_transition = transition.transition(transition_name, position_on_track, length, resource, self)
83
# insert new transition
84
self.transitions.append(new_transition)
94
# loop through each track
95
for MyClip in self.clips:
103
def GenerateXML(self, dom, xmlParentNode):
105
playlist = dom.createElement("playlist")
106
playlist.setAttribute("id", self.name)
107
xmlParentNode.appendChild(playlist)
111
# loop through each track
112
for MyClip in self.clips:
115
current_frame = MyClip.GenerateXML(dom, playlist, current_frame)
119
#----------------------------------------------------------------------
120
def RenderTrack(self):
121
"""This adds a track to the canvas with 3 images: a left, middle, and right"""
123
# get the pixels per second from the parent sequence
124
pixels_per_second = self.parent.get_pixels_per_second()
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
130
previous_y_bottom = 0
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
137
# set the top coordinate of this track to the bottom coordinate of the last track
138
self.y_top = previous_y_bottom + 6
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
145
# Add an item to the goocanvas
146
root_left = canvas_left.get_root_item ()
147
root_right = canvas_right.get_root_item ()
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))
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()
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)
162
# Resize Middle pixbuf
163
middlePixBuf = imgTrack_Middle.get_pixbuf()
164
pixbuf_list = self.parent.split_images(middlePixBuf, imgTrack_Left_Height, Size_Of_Middle)
166
# Create Group (for the track)
167
GroupTrack = goocanvas.Group (parent = root_right)
168
GroupTrack_Left = goocanvas.Group (parent = root_left)
170
# set the unique ID of the group
171
GroupTrack.set_data ("id", self.unique_id)
173
# Add Left Image to Group
174
image1 = goocanvas.Image (parent = GroupTrack_Left,
175
pixbuf = imgTrack_Left.get_pixbuf(),
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)
184
# Add Middle Image to Group (this can be multiple image tiled together
186
for pixbuf in pixbuf_list:
187
# get width of this pixbuf
188
pixbuf_width = pixbuf.get_width()
190
image2 = goocanvas.Image (parent = GroupTrack,
196
pixbuf_x = pixbuf_x + pixbuf_width
198
# Add Middle Image to Group
199
image3 = goocanvas.Image (parent = GroupTrack,
200
pixbuf = imgTrack_Right.get_pixbuf(),
201
x = Size_Of_Middle - 1,
204
# Add Text to the Track
205
text1 = goocanvas.Text (parent = GroupTrack_Left,
206
text = "%s" % self.name,
214
imgTrack_Visible = gtk.image_new_from_file("%s/openshot/themes/%s/visible.png" % (self.parent.project.form.openshot_path, theme))
216
imgTrack_Visible = gtk.image_new_from_file("%s/openshot/themes/%s/not_visible.png" % (self.parent.project.form.openshot_path, theme))
218
imgTrack_Audio = gtk.image_new_from_file("%s/openshot/themes/%s/speaker.png" % (self.parent.project.form.openshot_path, theme))
220
imgTrack_Audio = gtk.image_new_from_file("%s/openshot/themes/%s/speaker_mute.png" % (self.parent.project.form.openshot_path, theme))
222
# Add Visible Image to Group
223
image4 = goocanvas.Image (parent = GroupTrack_Left,
224
pixbuf = imgTrack_Visible.get_pixbuf(),
228
# Track the state of the hover over image
229
image4.connect ("button_press_event", self.on_visible_click)
231
# Add Visible Image to Group
232
image5 = goocanvas.Image (parent = GroupTrack_Left,
233
pixbuf = imgTrack_Audio.get_pixbuf(),
237
# Track the state of the hover over image
238
image5.connect ("button_press_event", self.on_audio_click)
240
# Increment the Y cooridinate (by the height of the left image)
241
self.y_bottom = self.y_top + imgTrack_Left_Height
246
def on_visible_click (self, item, target, event):
248
# get the parent left group
249
parent_group = item.get_parent()
251
# mark project as modified
252
self.parent.project.set_project_modified(is_modified=True, refresh_xml=True)
254
if self.play_video == True:
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())
259
# update play video variable
260
self.play_video = False
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())
267
# update play video variable
268
self.play_video = True
273
def on_audio_click (self, item, target, event):
275
# get the parent left group
276
parent_group = item.get_parent()
278
# mark project as modified
279
self.parent.project.set_project_modified(is_modified=True, refresh_xml=True)
281
if self.play_audio == True:
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())
286
# update play audio variable
287
self.play_audio = False
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())
294
# update play audio variable
295
self.play_audio = True
300
def on_focus_in (self, item, target, event):
301
isinstance(item, goocanvas.Image)
302
id = item.get_data ("id")
304
if event.button == 3:
305
# show the track popup menu
306
self.parent.project.form.mnuTrack1.showmnu(event, self)
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")
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")
323
def reorder_clips(self):
324
# get a list of all clips on this track
325
self.clips.sort(self.compare_clip)
328
def compare_clip(self, MyClip1, MyClip2):
329
if MyClip1.position_on_track > MyClip2.position_on_track:
331
elif MyClip1.position_on_track == MyClip2.position_on_track:
337
def reorder_transitions(self):
338
# get a list of all clips on this track
339
self.transitions.sort(self.compare_transitions)
342
def compare_transitions(self, MyClip1, MyClip2):
343
if MyClip1.position_on_track > MyClip2.position_on_track:
345
elif MyClip1.position_on_track == MyClip2.position_on_track:
b'\\ No newline at end of file'