~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to pitivi/dialogs/clipmediaprops.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-04-05 15:28:16 UTC
  • mfrom: (6.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20140405152816-6lijoax4cngiz5j5
Tags: 0.93-3
* debian/control:
  + Depend on python-gi (>= 3.10), older versions do not work
    with pitivi (Closes: #732813).
  + Add missing dependency on gir1.2-clutter-gst-2.0 (Closes: #743692).
  + Add suggests on gir1.2-notify-0.7 and gir1.2-gnomedesktop-3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Pitivi video editor
 
2
#
 
3
#       pitivi/dialogs/clipmediaprops.py
 
4
#
 
5
# Copyright (c) 2011, Parthasarathi Susarla <partha@collabora.co.uk>
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
 
 
20
import os
 
21
 
 
22
from gi.repository import Gdk
 
23
from gi.repository import Gst
 
24
from gi.repository import Gtk
 
25
 
 
26
from gettext import gettext as _
 
27
 
 
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
 
31
 
 
32
 
 
33
class ClipMediaPropsDialog(object):
 
34
    """
 
35
    Displays the properties of an asset, and allows applying them to a project.
 
36
 
 
37
    @type project: L{Project}
 
38
    @type asset: L{GES.UriClipAsset}
 
39
    """
 
40
 
 
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
 
48
        self.is_image = False
 
49
 
 
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")
 
73
 
 
74
    def run(self):
 
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()))
 
85
            self.has_audio = True
 
86
            break
 
87
 
 
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()
 
92
            if not self.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)
 
101
                        ))
 
102
                else:
 
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)
 
110
 
 
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())))
 
116
 
 
117
            self.has_video = True
 
118
            break
 
119
 
 
120
        if not self.has_video:
 
121
            self.frame1.hide()
 
122
        if not self.has_audio:
 
123
            self.frame2.hide()
 
124
        if self.is_image:
 
125
            self.hbox2.hide()
 
126
            self.hbox3.hide()
 
127
            self.video_header_label.set_markup("<b>" + _("Image:") + "</b>")
 
128
 
 
129
        self.dialog.connect("key-press-event", self._keyPressCb)
 
130
        self.dialog.run()
 
131
 
 
132
    def _applyButtonCb(self, unused_button):
 
133
        """Apply widget values to the project"""
 
134
        project = self.project
 
135
        if self.has_video:
 
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())
 
147
        if self.has_audio:
 
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()
 
154
 
 
155
    def _cancelButtonCb(self, unused_button):
 
156
        """Destroy the dialog"""
 
157
        self.dialog.destroy()
 
158
 
 
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()
 
162
        return True