[pitivi] Disable scroll for widgets in a ScrolledWindow



commit b077470f9c29108522a9c2697347d4fccc822da7
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Jan 19 17:24:58 2016 +0100

    Disable scroll for widgets in a ScrolledWindow
    
    It's annoying when scrolling and then a SpinnerButton, ComboBox or Slider
    gets under the cursor. In this case the scrolling stops and instead the
    widget value changes.
    
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Differential Revision: https://phabricator.freedesktop.org/D691

 pitivi/clipproperties.py |    9 +++++----
 pitivi/utils/ui.py       |   14 +++++++++++++-
 pitivi/utils/widgets.py  |    6 +++++-
 3 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/pitivi/clipproperties.py b/pitivi/clipproperties.py
index cead537..ad77ad0 100644
--- a/pitivi/clipproperties.py
+++ b/pitivi/clipproperties.py
@@ -21,19 +21,19 @@
 
 import os
 
+from gettext import gettext as _
+
 from gi.repository import Gtk
 from gi.repository import Gdk
 from gi.repository import Pango
 from gi.repository import GES
 
-from gettext import gettext as _
-
 from pitivi.configure import get_ui_dir
 from pitivi.effects import AUDIO_EFFECT, VIDEO_EFFECT, HIDDEN_EFFECTS, \
     EffectsPropertiesManager
 from pitivi.utils.loggable import Loggable
-from pitivi.utils.ui import EFFECT_TARGET_ENTRY, PADDING, SPACING
-
+from pitivi.utils.ui import EFFECT_TARGET_ENTRY, PADDING, SPACING, \
+    disable_scroll
 
 (COL_ACTIVATED,
  COL_TYPE,
@@ -557,6 +557,7 @@ class TransformationProperties(Gtk.Expander, Loggable):
         """
         spinbtn = self.builder.get_object(widget_name)
         spinbtn.connect("output", self._onValueChangedCb, property_name)
+        disable_scroll(spinbtn)
         self.spin_buttons[property_name] = spinbtn
 
     def _onValueChangedCb(self, spinbtn, prop):
diff --git a/pitivi/utils/ui.py b/pitivi/utils/ui.py
index c527157..02fac47 100644
--- a/pitivi/utils/ui.py
+++ b/pitivi/utils/ui.py
@@ -35,8 +35,9 @@ import urllib.error
 
 from gettext import ngettext, gettext as _
 
-from gi.repository import GLib
 from gi.repository import GES
+from gi.repository import GLib
+from gi.repository import GObject
 from gi.repository import Gdk
 from gi.repository import Gio
 from gi.repository import Gst
@@ -514,6 +515,17 @@ def unset_children_state_recurse(widget, state):
             unset_children_state_recurse(child, state)
 
 
+def disable_scroll(widget):
+    """
+    Make sure the specified widget does not react to scroll events.
+    """
+    def scroll_event_cb(widget, unused_event):
+        GObject.signal_stop_emission_by_name(widget, "scroll-event")
+        return False
+
+    widget.connect("scroll-event", scroll_event_cb)
+
+
 # ----------------------- encoding datas --------------------------------------- #
 # FIXME This should into a special file
 frame_rates = model((str, object), (
diff --git a/pitivi/utils/widgets.py b/pitivi/utils/widgets.py
index 674166c..633f903 100644
--- a/pitivi/utils/widgets.py
+++ b/pitivi/utils/widgets.py
@@ -42,7 +42,7 @@ from gettext import gettext as _
 
 from pitivi.utils.loggable import Loggable
 from pitivi.configure import get_ui_dir
-from pitivi.utils.ui import beautify_length, \
+from pitivi.utils.ui import beautify_length, disable_scroll, \
     unpack_color, pack_color_32, pack_color_64, \
     time_to_string, SPACING, CONTROL_WIDTH
 from pitivi.utils.timeline import Zoomable
@@ -133,6 +133,7 @@ class TextWidget(Gtk.Box, DynamicWidget):
             self.combo = Gtk.ComboBoxText.new_with_entry()
             self.text = self.combo.get_child()
             self.combo.show()
+            disable_scroll(self.combo)
             self.pack_start(self.combo, expand=False, fill=False, padding=0)
             for choice in choices:
                 self.combo.append_text(choice)
@@ -245,6 +246,7 @@ class NumericWidget(Gtk.Box, DynamicWidget):
                 Gtk.Orientation.HORIZONTAL, self.adjustment)
             self.pack_end(self.slider, expand=False, fill=False, padding=0)
             self.slider.show()
+            disable_scroll(self.slider)
             self.slider.set_size_request(width=100, height=-1)
             self.slider.props.draw_value = False
             # Abuse GTK3's progressbar "fill level" feature to provide
@@ -257,6 +259,7 @@ class NumericWidget(Gtk.Box, DynamicWidget):
         self.spinner = Gtk.SpinButton(adjustment=self.adjustment)
         self.pack_start(self.spinner, expand=False, fill=False, padding=0)
         self.spinner.show()
+        disable_scroll(self.spinner)
 
     def connectValueChanged(self, callback, *args):
         self.adjustment.connect("value-changed", callback, *args)
@@ -467,6 +470,7 @@ class ChoiceWidget(Gtk.Box, DynamicWidget):
         self.pack_start(self.contents, expand=False, fill=False, padding=0)
         self.setChoices(choices)
         self.contents.show()
+        disable_scroll(self.contents)
         cell = self.contents.get_cells()[0]
         cell.props.ellipsize = Pango.EllipsizeMode.END
 


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