[pitivi] gstwidget.py: use the new dynamic widgets



commit 51b0512301f73ab02c0b41255d8a8a44b9fd6a92
Author: Thibault Saunier <tsaunier gnome org>
Date:   Thu Aug 12 16:38:08 2010 -0400

    gstwidget.py: use the new dynamic widgets

 pitivi/effects.py                 |    3 +-
 pitivi/ui/effectsconfiguration.py |   61 ++++++++++-------
 pitivi/ui/gstwidget.py            |  130 +++++++------------------------------
 3 files changed, 60 insertions(+), 134 deletions(-)
---
diff --git a/pitivi/effects.py b/pitivi/effects.py
index a0ba954..97fa43e 100644
--- a/pitivi/effects.py
+++ b/pitivi/effects.py
@@ -51,7 +51,8 @@ from pitivi.undo import UndoableAction
 
 (VIDEO_EFFECT, AUDIO_EFFECT)  = range(2)
 
-BLACKLISTED_EFFECTS = ["colorconvert", "coglogoinsert", "festival", "aspectratiocrop"]
+BLACKLISTED_EFFECTS = ["colorconvert", "coglogoinsert", "festival",
+                       "alphacolor", "cogcolorspace"]
 
 
 
diff --git a/pitivi/ui/effectsconfiguration.py b/pitivi/ui/effectsconfiguration.py
index 6680cc0..ff9126d 100644
--- a/pitivi/ui/effectsconfiguration.py
+++ b/pitivi/ui/effectsconfiguration.py
@@ -24,8 +24,8 @@
 
 import gtk
 
-from pitivi.ui.gstwidget import GstElementSettingsWidget
 from pitivi.pipeline import PipelineError
+from pitivi.ui.gstwidget import GstElementSettingsWidget
 
 PROPS_TO_IGNORE = ['name', 'qos']
 
@@ -44,17 +44,20 @@ class EffectsPropertiesHandling:
         """
         if effect not in self.cache_dict:
             #Here we should handle special effects configuration UI
-            effect_set_ui = GstElementSettingsWidget()
-            effect_set_ui.setElement(effect, ignore=PROPS_TO_IGNORE,
-                                               default_btn=True, use_element_props=True)
-            nb_rows = effect_set_ui.get_children()[0].get_property('n-rows')
-            if nb_rows > 4:
-                effect_configuration_ui = gtk.ScrolledWindow()
-                effect_configuration_ui.add_with_viewport(effect_set_ui)
-                self.cache_dict[effect] = effect_configuration_ui
+            if 'aspectratiocrop' in effect.get_name():
+                effect_set_ui = AspectRatioUi()
             else:
-                self.cache_dict[effect] = effect_set_ui
-            self._connectAllWidgetCbs(effect_set_ui, effect)
+                effect_set_ui = GstElementSettingsWidget()
+                effect_set_ui.setElement(effect, ignore=PROPS_TO_IGNORE,
+                                                   default_btn=True, use_element_props=True)
+                nb_rows = effect_set_ui.get_children()[0].get_property('n-rows')
+                if nb_rows > 4:
+                    effect_configuration_ui = gtk.ScrolledWindow()
+                    effect_configuration_ui.add_with_viewport(effect_set_ui)
+                    self.cache_dict[effect] = effect_configuration_ui
+                else:
+                    self.cache_dict[effect] = effect_set_ui
+                self._connectAllWidgetCbs(effect_set_ui, effect)
 
         effect_set_ui = self._getEffectSetUI(effect)
 
@@ -78,20 +81,26 @@ class EffectsPropertiesHandling:
 
     def _connectAllWidgetCbs(self, effect_configuration_ui, effect):
         for prop, widget in effect_configuration_ui.properties.iteritems():
-            if type(widget) in [gtk.SpinButton, gtk.HScale]:
-                widget.connect("value-changed", self._onValueChangedCb)
-            elif type(widget) in [gtk.Entry, gtk.ComboBox]:
-                widget.connect("changed", self._onValueChangedCb)
-            elif type(widget) in [gtk.CheckButton, gtk.Button]:
-                widget.connect("clicked", self._onValueChangedCb)
-
-        for button in effect_configuration_ui.buttons:
-                button.connect("clicked", self._onValueChangedCb, True)
-
-    def _onValueChangedCb(self, widget, with_default=False):
-        for prop, value in self._current_effect_setting_ui.getSettings(with_default).iteritems():
-            self.action_log.begin("Effect property change")
-            self._current_effect_setting_ui.element.set_property(prop, value)
-            self.action_log.commit()
+            widget.connectValueChanged(self._onValueChangedCb, widget, prop)
+
+    def _onSetDefaultCb(self, widget, dynamic):
+        dynamic.setWidgetToDefault()
+
+    def _onValueChangedCb(self, widget, dynamic, prop):
+        self.action_log.begin("Effect property change")
+
+        value = dynamic.getWidgetValue()
+        print "%s, %s" %(type(value), value)
+        self._current_effect_setting_ui.element.set_property(prop.name, value)
+        self.action_log.commit()
 
         self._flushSeekVideo()
+
+
+class AspectRatioUi(GstElementSettingsWidget):
+    """
+        UI to configure AspectRatio effects
+    """
+    def __init__(self):
+        GstElementSettingsWidget.__init__(self)
+
diff --git a/pitivi/ui/gstwidget.py b/pitivi/ui/gstwidget.py
index 82ff2f6..57664d8 100644
--- a/pitivi/ui/gstwidget.py
+++ b/pitivi/ui/gstwidget.py
@@ -25,30 +25,12 @@ Widget for gstreamer element properties viewing/setting
 
 import gobject
 import gtk
+import gst
 from pitivi.ui.glade import GladeWindow
 
 from gettext import gettext as _
-import pitivi.log.log as log
 from pitivi.log.loggable import Loggable
-
-def get_widget_propvalue(prop, widget):
-    """ returns the value of the given propertywidget """
-    # FIXME : implement the case for flags
-    type_name = gobject.type_name(prop.value_type.fundamental)
-
-    if (type_name == 'gchararray'):
-        return widget.get_text()
-    if (type_name in ['guint64', 'gint64', 'gint', 'gulong']):
-        return widget.get_value_as_int()
-    if (type_name in ['gfloat', 'gdouble']):
-        return widget.get_value()
-    if (type_name in ['gboolean']):
-        return widget.get_active()
-    if type_name in ['GEnum']:
-        # we don't want to have typed enums wondering around,
-        # we therefore convert it to it's numerical equivalent
-        return int(widget.get_model()[widget.get_active()][1])
-    return None
+import pitivi.ui.dynamic as dynamic
 
 def make_property_widget(unused_element, prop, value=None):
     """ Creates a Widget for the given element property """
@@ -58,80 +40,32 @@ def make_property_widget(unused_element, prop, value=None):
     if value == None:
         value = prop.default_value
     if (type_name == 'gchararray'):
-        widget = gtk.Entry()
-        widget.set_text(str(value))
+        widget = dynamic.TextWidget()
     elif (type_name in ['guint64', 'gint64', 'guint', 'gint', 'gfloat',
         'gulong', 'gdouble']):
+
         maximum , minimum = None, None
-        if hasattr(prop, "minimum") and hasattr(prop, "maximum"):
+        if hasattr(prop, "minimum"):
             minimum = prop.minimum
+        if hasattr(prop, "maximum"):
             maximum = prop.maximum
-        if minimum >- 10 and maximum < 10:
-            widget = gtk.HScale()
-            widget.set_draw_value(True)
-            widget.set_range(prop.minimum, prop.maximum)
-            widget.set_value(value)
-        else:
-            widget = gtk.SpinButton()
-            if type_name == 'gint':
-                minimum, maximum = (-(2**31), 2**31 - 1)
-                widget.set_increments(1.0, 10.0)
-            elif type_name == 'guint':
-                minimum, maximum = (0, 2**32 - 1)
-                widget.set_increments(1.0, 10.0)
-            elif type_name == 'gint64':
-                minimum, maximum = (-(2**63), 2**63 - 1)
-                widget.set_increments(1.0, 10.0)
-            elif type_name in ['gulong', 'guint64']:
-                minimum, maximum = (0, 2**64 - 1)
-                widget.set_increments(1.0, 10.0)
-            elif type_name in ['gfloat','gdouble']:
-                minimum, maximum = (float("-Infinity"), float("Infinity"))
-                widget.set_increments(0.00001, 0.01)
-                widget.set_digits(5)
-            if maximum and minimum:
-                widget.set_range(minimum, maximum)
-                widget.props.climb_rate = 0.01 * abs(min(maximum, 1000) -
-                    max(minimum, -1000))
-            widget.set_value(float(value))
+        widget = dynamic.NumericWidget(default=prop.default_value,
+                                       upper=maximum, lower=minimum)
     elif (type_name == 'gboolean'):
-        widget = gtk.CheckButton()
-        if value:
-            widget.set_active(True)
+        widget = dynamic.ToggleWidget(default=prop.default_value)
     elif (type_name == 'GEnum'):
-        model = gtk.ListStore(gobject.TYPE_STRING, prop.value_type)
-        widget = gtk.ComboBox(model)
-        cell = gtk.CellRendererText()
-        widget.pack_start(cell, True)
-        widget.add_attribute(cell, 'text', 0)
-
         idx = 0
+        choices = []
         for key, val in prop.enum_class.__enum_values__.iteritems():
-            log.log("gstwidget", "adding %s / %s", val.value_name, val)
-            model.append([val.value_name, val])
-            if val == value or key == value:
-                selected = idx
-            idx = idx + 1
-        widget.set_active(selected)
+            choices.append([val.value_name, int(val)])
+        widget = dynamic.ChoiceWidget(choices, default=prop.default_value)
     elif type_name == 'GstFraction':
-        widget = gtk.HBox()
-        widget1 = gtk.SpinButton()
-        widget1.set_range(0,100)
-        widget1.set_increments(1.0, 10.0)
-        #widget1.set_value(float(value))
-        widget2 = gtk.SpinButton()
-        widget2.set_range(0,100)
-        widget2.set_increments(1.0, 10.0)
-        #widget2.set_value(float(value))
-        widget.pack_start(widget1)
-        widget.pack_start(gtk.Label("/"))
-        widget.pack_start(widget2)
+        widget = dynamic.FractionWidget(None, None, default = prop.default_value)
     else:
-        widget = gtk.Label(type_name)
-        widget.set_alignment(1.0, 0.5)
+        widget = dynamic.DefaultWidget(type_name)
+
+    widget.setWidgetValue(value)
 
-    if not prop.flags & gobject.PARAM_WRITABLE:
-        widget.set_sensitive(False)
     return widget
 
 class GstElementSettingsWidget(gtk.VBox, Loggable):
@@ -145,7 +79,7 @@ class GstElementSettingsWidget(gtk.VBox, Loggable):
         self.element = None
         self.ignore = None
         self.properties = None
-        self.buttons = []
+        self.buttons = {}
 
     def setElement(self, element, properties={}, ignore=['name'],
                    default_btn = False, use_element_props=False):
@@ -193,17 +127,14 @@ class GstElementSettingsWidget(gtk.VBox, Loggable):
             if default_btn:
                 button = self._getResetToDefaultValueButton(prop, widget)
                 table.attach(button, 2, 3, y, y+1, xoptions=gtk.FILL, yoptions=gtk.FILL)
-                self.buttons.append(button)
-            self.element.connect('notify::' + prop.name,
-                                self._propertyChangedCb,
-                                widget)
+                self.buttons[button] = widget
             y += 1
 
         self.pack_start(table)
         self.show_all()
 
     def _propertyChangedCb(self, element, pspec, widget):
-        self._set_prop(widget, self.element.get_property(pspec.name))
+        widget.setWidgetValue(self.element.get_property(pspec.name))
 
     def _getResetToDefaultValueButton(self, prop, widget):
         icon = gtk.Image()
@@ -211,26 +142,11 @@ class GstElementSettingsWidget(gtk.VBox, Loggable):
         button = gtk.Button(label='')
         button.set_image(icon)
         button.set_tooltip_text(_("Reset to default value"))
-        button.connect('clicked', self._defaultBtnClickedCb, prop.default_value, widget)
+        button.connect('clicked', self._defaultBtnClickedCb, widget)
         return button
 
-    def _defaultBtnClickedCb(self, button,  default_value, widget):
-        self._set_prop(widget, default_value)
-
-    def _set_prop(self, widget, value):
-        def check_combobox_value(model, path, iter, widget_value):
-            if model.get_value(iter, 0) == str(widget_value[1].value_name):
-                widget_value[0].set_active_iter(iter)
-
-        if type(widget) in [gtk.SpinButton, gtk.HScale]:
-            widget.set_value(float(value))
-        elif type(widget) in [gtk.Entry]:
-            widget.set_text(str(value))
-        elif type(widget) in [gtk.ComboBox]:
-            model = widget.get_model()
-            model.foreach(check_combobox_value, [widget, value])
-        elif type(widget) in [gtk.CheckButton]:
-            widget.set_active(bool(value))
+    def _defaultBtnClickedCb(self, button, widget):
+        widget.setWidgetToDefault()
 
     def getSettings(self, with_default=False):
         """
@@ -240,7 +156,7 @@ class GstElementSettingsWidget(gtk.VBox, Loggable):
         for prop, widget in self.properties.iteritems():
             if not prop.flags & gobject.PARAM_WRITABLE:
                 continue
-            value = get_widget_propvalue(prop, widget)
+            value = widget.getWidgetValue()
             if value != None and (value != prop.default_value or with_default):
                 d[prop.name] = value
         return d



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]