2
# ui/effectsconfiguration.py
4
# Copyright (C) 2010 Thibault Saunier <tsaunier@gnome.org>
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.
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.
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.
25
from pitivi.ui.gstwidget import GstElementSettingsWidget
26
from pitivi.ui.dynamic import FractionWidget
28
PROPS_TO_IGNORE = ['name', 'qos', 'silent', 'message']
31
class EffectsPropertiesHandling:
32
def __init__(self, action_log):
34
self._current_effect_setting_ui = None
35
self._current_element_values = {}
36
self.action_log = action_log
38
def getEffectConfigurationUI(self, effect):
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}
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,
55
self.cache_dict[effect] = effect_configuration_ui
56
self._connectAllWidgetCbs(effect_set_ui, effect)
57
self._postConfiguration(effect, effect_set_ui)
59
effect_set_ui = self._getUiToSetEffect(effect)
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)
67
return self.cache_dict[effect]
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)
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"])
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]
86
effect_set_ui = self.cache_dict[effect]
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)
94
def _onSetDefaultCb(self, widget, dynamic):
95
dynamic.setWidgetToDefault()
97
def _onValueChangedCb(self, widget, dynamic, prop):
98
value = dynamic.getWidgetValue()
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))
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