3
# pitivi/dialogs/clipmediaprops.py
5
# Copyright (c) 2011, Parthasarathi Susarla <partha@collabora.co.uk>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU Lesser General Public
9
# License as published by the Free Software Foundation; either
10
# version 2.1 of the License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public
18
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
22
from gi.repository import Gdk
23
from gi.repository import Gst
24
from gi.repository import Gtk
26
from gettext import gettext as _
28
from pitivi.configure import get_ui_dir
29
from pitivi.utils.ui import frame_rates, audio_rates, \
30
audio_channels, pixel_aspect_ratios, get_value_from_model
33
class ClipMediaPropsDialog(object):
35
Displays the properties of an asset, and allows applying them to a project.
37
@type project: L{Project}
38
@type asset: L{GES.UriClipAsset}
41
def __init__(self, project, asset):
42
self.project = project
43
info = asset.get_info()
44
self.audio_streams = info.get_audio_streams()
45
self.video_streams = info.get_video_streams()
46
self.has_audio = False
47
self.has_video = False
50
builder = Gtk.Builder()
51
builder.add_from_file(os.path.join(get_ui_dir(), "clipmediaprops.ui"))
52
builder.connect_signals(self)
53
self.dialog = builder.get_object("Import Settings")
54
# Checkbuttons (with their own labels) in the first table column:
55
self.size_checkbutton = builder.get_object("size_checkbutton")
56
self.framerate_checkbutton = builder.get_object("framerate_checkbutton")
57
self.PAR_checkbutton = builder.get_object("PAR_checkbutton")
58
self.channels_checkbutton = builder.get_object("channels_checkbutton")
59
self.samplerate_checkbutton = builder.get_object("samplerate_checkbtn")
60
# These labels are in a separate table col on the right of checkboxes:
61
self.channels = builder.get_object("channels")
62
self.size_height = builder.get_object("size_height")
63
self.size_width = builder.get_object("size_width")
64
self.frame_rate = builder.get_object("frame_rate")
65
self.aspect_ratio = builder.get_object("aspect_ratio")
66
self.sample_rate = builder.get_object("sample_rate")
67
# Various other layout widgets
68
self.frame1 = builder.get_object("frame1")
69
self.frame2 = builder.get_object("frame2")
70
self.hbox2 = builder.get_object("hbox2")
71
self.hbox3 = builder.get_object("hbox3")
72
self.video_header_label = builder.get_object("label2")
75
"""Set up widgets and run the dialog"""
76
# TODO: in "onApplyButtonClicked", we only use the first stream...
77
# If we have multiple audio or video streams, we should reflect that
78
# in the UI, instead of acting as if there was only one. But that means
79
# dynamically creating checkboxes and labels in a table and such.
80
for stream in self.audio_streams:
81
self.channels.set_text(
82
get_value_from_model(audio_channels, stream.get_channels()))
83
self.sample_rate.set_text(
84
get_value_from_model(audio_rates, stream.get_sample_rate()))
88
for stream in self.video_streams:
89
self.size_width.set_text(str(stream.get_width()))
90
self.size_height.set_text(str(stream.get_height()))
91
self.is_image = stream.is_image()
93
# When gst returns a crazy framerate such as 0/1, that either
94
# means it couldn't determine it, or it is a variable framerate
95
framerate_num = stream.get_framerate_num()
96
framerate_denom = stream.get_framerate_denom()
97
if framerate_num != 0 and framerate_denom != 0:
98
self.frame_rate.set_text(
99
get_value_from_model(frame_rates,
100
Gst.Fraction(framerate_num, framerate_denom)
103
foo = str(framerate_num) + "/" + str(framerate_denom)
104
# Translators: a label showing an invalid framerate value
105
self.frame_rate.set_text(_("invalid (%s fps)" % foo))
106
self.framerate_checkbutton.set_active(False)
107
# For consistency, insensitize the checkbox AND value labels
108
self.framerate_checkbutton.set_sensitive(False)
109
self.frame_rate.set_sensitive(False)
111
# Aspect ratio (probably?) doesn't need such a check:
112
self.aspect_ratio.set_text(
113
get_value_from_model(pixel_aspect_ratios, Gst.Fraction(
114
stream.get_par_num(),
115
stream.get_par_denom())))
117
self.has_video = True
120
if not self.has_video:
122
if not self.has_audio:
127
self.video_header_label.set_markup("<b>" + _("Image:") + "</b>")
129
self.dialog.connect("key-press-event", self._keyPressCb)
132
def _applyButtonCb(self, unused_button):
133
"""Apply widget values to the project"""
134
project = self.project
136
# This also handles the case where the video is a still image
137
video = self.video_streams[0]
138
if self.size_checkbutton.get_active():
139
project.videowidth = video.get_width()
140
project.videoheight = video.get_height()
141
if self.framerate_checkbutton.get_active() and not self.is_image:
142
project.videorate = Gst.Fraction(video.get_framerate_num(),
143
video.get_framerate_denom())
144
if self.PAR_checkbutton.get_active() and not self.is_image:
145
project.videopar = Gst.Fraction(video.get_par_num(),
146
video.get_par_denom())
148
audio = self.audio_streams[0]
149
if self.channels_checkbutton.get_active():
150
project.audiochannels = audio.get_channels()
151
if self.samplerate_checkbutton.get_active():
152
project.audiorate = audio.get_sample_rate()
153
self.dialog.destroy()
155
def _cancelButtonCb(self, unused_button):
156
"""Destroy the dialog"""
157
self.dialog.destroy()
159
def _keyPressCb(self, unused_widget, event):
160
if event.keyval in (Gdk.KEY_Escape, Gdk.KEY_Q, Gdk.KEY_q):
161
self.dialog.destroy()