[pitivi/ges] Refactor the clip media properties code
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges] Refactor the clip media properties code
- Date: Tue, 27 Mar 2012 03:59:50 +0000 (UTC)
commit 02cbcafb01becbd256ef259a7ef7e47c8ef1a529
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date: Mon Mar 26 22:44:07 2012 -0400
Refactor the clip media properties code
data/ui/clipmediaprops.ui | 28 +++++------
pitivi/dialogs/clipmediaprops.py | 93 +++++++++++++++++---------------------
pitivi/medialibrary.py | 20 +++-----
3 files changed, 62 insertions(+), 79 deletions(-)
---
diff --git a/data/ui/clipmediaprops.ui b/data/ui/clipmediaprops.ui
index 86d4186..0ad6bc2 100644
--- a/data/ui/clipmediaprops.ui
+++ b/data/ui/clipmediaprops.ui
@@ -20,13 +20,12 @@
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">_Cancel</property>
- <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
- <signal name="clicked" handler="onCancelButtonClicked" swapped="no"/>
+ <signal name="clicked" handler="_cancelButtonCb" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -37,13 +36,12 @@
<child>
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">_Apply to project</property>
- <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
- <signal name="clicked" handler="onApplyButtonClicked" swapped="no"/>
+ <signal name="clicked" handler="_applyButtonCb" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -82,10 +80,10 @@
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="checkbutton1">
<property name="label" translatable="yes">Size (pixels):</property>
- <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -156,10 +154,10 @@
<object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="checkbutton2">
- <property name="label" translatable="yes">Frame rate: </property>
- <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">Frame rate:</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -196,10 +194,10 @@
<object class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="checkbutton3">
- <property name="label" translatable="yes">Pixel Aspect Ratio:</property>
- <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">Pixel aspect ratio:</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -240,7 +238,7 @@
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label" translatable="yes"> Video:</property>
+ <property name="label" translatable="yes">Video:</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -272,10 +270,10 @@
<object class="GtkHBox" id="hbox4">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="checkbutton4">
<property name="label" translatable="yes">Channels:</property>
- <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -312,10 +310,10 @@
<object class="GtkHBox" id="hbox5">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="checkbutton5">
- <property name="label" translatable="yes">Sample Rate: </property>
- <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">Sample rate:</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -352,10 +350,10 @@
<object class="GtkHBox" id="hbox6">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="checkbutton6">
- <property name="label" translatable="yes">Sample Depth: </property>
- <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">Sample depth:</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
diff --git a/pitivi/dialogs/clipmediaprops.py b/pitivi/dialogs/clipmediaprops.py
index a0af7e1..b86878a 100644
--- a/pitivi/dialogs/clipmediaprops.py
+++ b/pitivi/dialogs/clipmediaprops.py
@@ -20,41 +20,35 @@
# Boston, MA 02111-1307, USA.
"""
-Dialog box for display the properties of a clip from sources list
+Dialog box displaying the properties of a clip from media library, allowing
+to set those properties as the project settings.
"""
import gtk
import gst
import os
-import random
-import string
-from pwd import getpwuid
-from datetime import datetime
from gettext import gettext as _
from pitivi.configure import get_ui_dir
-from pitivi.utils.ui import model, frame_rates, audio_rates, audio_depths,\
- audio_channels, get_combo_value, set_combo_value, pixel_aspect_ratios,\
- get_value_from_model
-from pitivi.preset import AudioPresetManager, VideoPresetManager
+from pitivi.utils.ui import frame_rates, audio_rates, audio_depths,\
+ audio_channels, pixel_aspect_ratios, get_value_from_model
class clipmediapropsDialog():
+
def __init__(self, project, audio_streams, video_streams):
self.project = project
self.settings = self.project.getSettings()
- self.widgets = {}
- self.resets = {}
- self._current = None
- self._createUi()
self.audio_streams = audio_streams
self.video_streams = video_streams
+ self.has_audio = self.has_video = self.is_image = False
+ self._createUi()
def run(self):
- self.is_audio = len(self.audio_streams) > 0
- self.is_video = len(self.video_streams) > 0
- self.is_image = False
-
+ # TODO: in "onApplyButtonClicked", we only use the first stream...
+ # If we have multiple audio or video streams, we should reflect that
+ # in the UI, instead of acting as if there was only one. But that means
+ # dynamically creating checkboxes and labels in a table and such.
for stream in self.audio_streams:
self.channels.set_text(
get_value_from_model(audio_channels, stream.get_channels()))
@@ -62,28 +56,33 @@ class clipmediapropsDialog():
get_value_from_model(audio_rates, stream.get_sample_rate()))
self.sample_depth.set_text(
get_value_from_model(audio_depths, stream.get_depth()))
+ self.has_audio = True
+ break
for stream in self.video_streams:
self.size_width.set_text(str(stream.get_width()))
self.size_height.set_text(str(stream.get_height()))
- self.is_image = stream.get_framerate_num() == 0
+ self.is_image = stream.is_image()
if not self.is_image:
- self.frame_rate.set_text(get_value_from_model(frame_rates,
- gst.Fraction(stream.get_framerate_num(),
- stream.get_framerate_denom())))
+ self.frame_rate.set_text(
+ get_value_from_model(frame_rates, gst.Fraction(
+ stream.get_framerate_num(),
+ stream.get_framerate_denom())))
self.aspect_ratio.set_text(
- get_value_from_model(pixel_aspect_ratios,
- gst.Fraction(stream.get_par_num(),
- stream.get_par_denom())))
+ get_value_from_model(pixel_aspect_ratios, gst.Fraction(
+ stream.get_par_num(),
+ stream.get_par_denom())))
+ self.has_video = True
+ break
- if not self.is_video:
+ if not self.has_video:
self.frame1.hide()
- if not self.is_audio:
+ if not self.has_audio:
self.frame2.hide()
if self.is_image:
self.hbox2.hide()
self.hbox3.hide()
- self.label2.set_markup(_("<b>Image:</b>"))
+ self.label2.set_markup("<b>" + _("Image:") + "</b>")
self.dialog.run()
def _createUi(self):
@@ -110,15 +109,14 @@ class clipmediapropsDialog():
self.checkbutton5 = builder.get_object("checkbutton5")
self.checkbutton6 = builder.get_object("checkbutton6")
- def onApplyButtonClicked(self, button):
+ def _applyButtonCb(self, unused_button):
+ _width = _height = _framerate = _par = -1
+ _channels = _rate = _depth = -1
- if (self.is_video):
- _width = -1
- _height = -1
- _framerate = -1
- _par = -1
+ if self.has_video:
+ # This also handles the case where the video is a still image
video = self.video_streams[0]
- if (self.checkbutton1.get_active()):
+ if self.checkbutton1.get_active():
_width = video.get_width()
_height = video.get_height()
if (self.checkbutton2.get_active() and not self.is_image):
@@ -127,31 +125,22 @@ class clipmediapropsDialog():
if (self.checkbutton3.get_active() and not self.is_image):
_par = gst.Fraction(video.get_par_num(),
video.get_par_denom())
- self.settings.setVideoProperties(_width,
- _height,
- _framerate,
- _par)
-
- if (self.is_audio):
- _channels = -1
- _rate = -1
- _depth = -1
+ self.settings.setVideoProperties(_width, _height, _framerate, _par)
+
+ if self.has_audio:
audio = self.audio_streams[0]
- if (self.checkbutton4.get_active()):
+ if self.checkbutton4.get_active():
_channels = audio.get_channels()
- if (self.checkbutton5.get_active()):
+ if self.checkbutton5.get_active():
_rate = audio.get_sample_rate()
- if (self.checkbutton6.get_active()):
+ if self.checkbutton6.get_active():
_depth = audio.get_depth()
+ self.settings.setAudioProperties(_channels, _rate, _depth)
- self.settings.setAudioProperties(_channels,
- _rate,
- _depth)
-
- if (self.is_video or self.is_audio):
+ if self.has_video or self.has_audio:
self.project.setSettings(self.settings)
self.dialog.destroy()
- def onCancelButtonClicked(self, button):
+ def _cancelButtonCb(self, unused_button):
self.dialog.destroy()
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 6de5488..e804642 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -978,26 +978,22 @@ class MediaLibraryWidget(gtk.VBox, Loggable):
def _playButtonClickedCb(self, unused_widget=None):
""" Called when a user clicks on the play button """
- # get the selected filesourcefactory
- paths = self.getSelectedPaths()
+ paths = self.getSelectedPaths()[0] # Only use the first item
model = self.treeview.get_model()
- if len(paths) < 1:
- return
- paths = paths[0]
self.debug("Let's play %s", model[paths][COL_URI])
self.emit('play', model[paths][COL_URI])
def _clipPropButtonClickedCb(self, unused_widget=None):
- """ Called when user clicks clip properties button """
- paths = self.getSelectedPaths()
+ """
+ Show the clip properties (resolution, framerate, audio channels...)
+ and allow setting them as the new project settings.
+ """
+ paths = self.getSelectedPaths()[0] # Only use the first item
model = self.treeview.get_model()
- if len(paths) < 1:
- return
- paths = paths[0]
factory = model[paths][COL_FACTORY]
- self.debug("Let's import %s", model[paths][COL_URI])
d = clipmediapropsDialog(self.app.current,
- factory.get_audio_streams(), factory.get_video_streams())
+ factory.get_audio_streams(),
+ factory.get_video_streams())
d.run()
def _hideInfoBarClickedCb(self, unused_button):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]