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., 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)
29
from pitivi.ui.gstwidget import GstElementSettingsWidget
30
from pitivi.ui.dynamic import FractionWidget
32
PROPS_TO_IGNORE = ['name', 'qos', 'silent', 'message']
34
class EffectsPropertiesHandling:
35
def __init__(self, action_log):
37
self._current_effect_setting_ui = None
38
self._current_element_values = {}
39
self.action_log = action_log
41
def getEffectConfigurationUI(self, effect):
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}
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,
57
self.cache_dict[effect] = effect_configuration_ui
58
self._connectAllWidgetCbs(effect_set_ui, effect)
59
self._postConfiguration(effect, effect_set_ui)
61
effect_set_ui = self._getUiToSetEffect(effect)
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)
69
return self.cache_dict[effect]
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)
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"])
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]
88
effect_set_ui = self.cache_dict[effect]
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)
96
def _onSetDefaultCb(self, widget, dynamic):
97
dynamic.setWidgetToDefault()
99
def _onValueChangedCb(self, widget, dynamic, prop):
100
value = dynamic.getWidgetValue()
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))
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