~ubuntu-branches/ubuntu/utopic/pitivi/utopic

« back to all changes in this revision

Viewing changes to pitivi/ui/effectsconfiguration.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
 
#
2
 
#       ui/effectsconfiguration.py
3
 
#
4
 
# Copyright (C) 2010 Thibault Saunier <tsaunier@gnome.org>
5
 
#
6
 
# This program is free software; you can redistribute it and/or
7
 
# modify it under the terms of the GNU Lesser General Public
8
 
# License as published by the Free Software Foundation; either
9
 
# version 2.1 of the License, or (at your option) any later version.
10
 
#
11
 
# This program 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 GNU
14
 
# Lesser General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU Lesser General Public
17
 
# License along with this program; if not, write to the
18
 
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19
 
# Boston, MA 02110-1301, USA.
20
 
 
21
 
import gst
22
 
import gtk
23
 
import gobject
24
 
 
25
 
from pitivi.ui.gstwidget import GstElementSettingsWidget
26
 
from pitivi.ui.dynamic import FractionWidget
27
 
 
28
 
PROPS_TO_IGNORE = ['name', 'qos', 'silent', 'message']
29
 
 
30
 
 
31
 
class EffectsPropertiesHandling:
32
 
    def __init__(self, action_log):
33
 
        self.cache_dict = {}
34
 
        self._current_effect_setting_ui = None
35
 
        self._current_element_values = {}
36
 
        self.action_log = action_log
37
 
 
38
 
    def getEffectConfigurationUI(self, effect):
39
 
        """
40
 
            Permit to get a configuration GUI for the effect
41
 
            @param effect: The effect for which we want the configuration UI
42
 
            @type effect: C{gst.Element}
43
 
        """
44
 
 
45
 
        if effect not in self.cache_dict:
46
 
            #Here we should handle special effects configuration UI
47
 
            effect_set_ui = GstElementSettingsWidget()
48
 
            effect_set_ui.setElement(effect, ignore=PROPS_TO_IGNORE,
49
 
                                     default_btn=True, use_element_props=True)
50
 
            nb_rows = effect_set_ui.get_children()[0].get_property('n-rows')
51
 
            effect_configuration_ui = gtk.ScrolledWindow()
52
 
            effect_configuration_ui.add_with_viewport(effect_set_ui)
53
 
            effect_configuration_ui.set_policy(gtk.POLICY_AUTOMATIC,
54
 
                                               gtk.POLICY_AUTOMATIC)
55
 
            self.cache_dict[effect] = effect_configuration_ui
56
 
            self._connectAllWidgetCbs(effect_set_ui, effect)
57
 
            self._postConfiguration(effect, effect_set_ui)
58
 
 
59
 
        effect_set_ui = self._getUiToSetEffect(effect)
60
 
 
61
 
        self._current_effect_setting_ui = effect_set_ui
62
 
        element = self._current_effect_setting_ui.element
63
 
        for prop in gobject.list_properties(element):
64
 
            if prop.flags & gobject.PARAM_READABLE:
65
 
                self._current_element_values[prop.name] = element.get_property(prop.name)
66
 
 
67
 
        return self.cache_dict[effect]
68
 
 
69
 
    def cleanCache(self, effect):
70
 
        if effect in self.cache_dict:
71
 
            conf_ui = self.cache_dict.get(effect)
72
 
            self.cache_dict.pop(effect)
73
 
            return conf_ui
74
 
 
75
 
    def _postConfiguration(self, effect, effect_set_ui):
76
 
        if 'GstAspectRatioCrop' in effect.get_path_string():
77
 
            for widget in effect_set_ui.get_children()[0].get_children():
78
 
                if isinstance(widget, FractionWidget):
79
 
                    widget.addPresets(["4:3", "5:4", "9:3", "16:9", "16:10"])
80
 
 
81
 
    def _getUiToSetEffect(self, effect):
82
 
        """ Permit to get the widget to set the effect and not its container """
83
 
        if type(self.cache_dict[effect]) is gtk.ScrolledWindow:
84
 
            effect_set_ui = self.cache_dict[effect].get_children()[0].get_children()[0]
85
 
        else:
86
 
            effect_set_ui = self.cache_dict[effect]
87
 
 
88
 
        return effect_set_ui
89
 
 
90
 
    def _connectAllWidgetCbs(self, effect_configuration_ui, effect):
91
 
        for prop, widget in effect_configuration_ui.properties.iteritems():
92
 
            widget.connectValueChanged(self._onValueChangedCb, widget, prop)
93
 
 
94
 
    def _onSetDefaultCb(self, widget, dynamic):
95
 
        dynamic.setWidgetToDefault()
96
 
 
97
 
    def _onValueChangedCb(self, widget, dynamic, prop):
98
 
        value = dynamic.getWidgetValue()
99
 
 
100
 
        #FIXME Workaround in order to make aspectratiocrop working
101
 
        if isinstance(value, gst.Fraction):
102
 
            value = gst.Fraction(int(value.num), int(value.denom))
103
 
 
104
 
        if value != self._current_element_values.get(prop.name):
105
 
            self.action_log.begin("Effect property change")
106
 
            self._current_effect_setting_ui.element.set_property(prop.name, value)
107
 
            self.action_log.commit()
108
 
            self._current_element_values[prop.name] = value