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

« back to all changes in this revision

Viewing changes to pitivi/ui/effectsconfiguration.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-05-26 15:29:58 UTC
  • mfrom: (3.1.20 experimental)
  • Revision ID: james.westby@ubuntu.com-20110526152958-90je1myzzjly26vw
Tags: 0.13.9.90-1ubuntu1
* Resynchronize on Debian
* debian/control:
  - Depend on python-launchpad-integration
  - Drop hal from Recommends to Suggests. This version has the patch applied
    to not crash without hal.
* debian/patches/01_lpi.patch:
  - launchpad integration  
* debian/rules:
  - Use gnome.mk so a translation template is built

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