[pygobject] overrides: Fix inconsistencies with drag and drop target list API
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] overrides: Fix inconsistencies with drag and drop target list API
- Date: Tue, 19 Feb 2013 11:09:27 +0000 (UTC)
commit 840c871441cb215f24cc6e7ed26b9f38e5aad0df
Author: Simon Feltman <sfeltman src gnome org>
Date: Mon Feb 18 01:46:22 2013 -0800
overrides: Fix inconsistencies with drag and drop target list API
Add support to Gtk.Widget.drag_dest_set_target_list and
Gtk.Widget.drag_source_set_target_list to accept iterables containing
mixed TargetEntry or a tuple of (target, flags, info).
Add support to Gtk.TreeView.enable_model_drag_source and
Gtk.TreeView.enable_model_drag_dest to accept a list of Gtk.TargetEntry
items.
https://bugzilla.gnome.org/show_bug.cgi?id=680640
gi/overrides/Gtk.py | 40 +++++++++++++++++++++++++++++-----------
tests/test_overrides_gtk.py | 32 ++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 11 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index dafdce1..002f22b 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -48,6 +48,22 @@ python module to use with Gtk 2.0"
warnings.warn(warn_msg, RuntimeWarning)
+def _construct_target_list(targets):
+ """Create a list of TargetEntry items from a list of tuples in the form (target, flags, info)
+
+ The list can also contain existing TargetEntry items in which case the existing entry
+ is re-used in the return list.
+ """
+ target_entries = []
+ for entry in targets:
+ if not isinstance(entry, Gtk.TargetEntry):
+ entry = Gtk.TargetEntry.new(*entry)
+ target_entries.append(entry)
+ return target_entries
+
+__all__.append('_construct_target_list')
+
+
class Widget(Gtk.Widget):
def translate_coordinates(self, dest_widget, src_x, src_y):
@@ -59,6 +75,17 @@ class Widget(Gtk.Widget):
def render_icon(self, stock_id, size, detail=None):
return super(Widget, self).render_icon(stock_id, size, detail)
+ def drag_dest_set_target_list(self, target_list):
+ if not isinstance(target_list, Gtk.TargetList):
+ target_list = Gtk.TargetList.new(_construct_target_list(target_list))
+ super(Widget, self).drag_dest_set_target_list(target_list)
+
+ def drag_source_set_target_list(self, target_list):
+ if not isinstance(target_list, Gtk.TargetList):
+ target_list = Gtk.TargetList.new(_construct_target_list(target_list))
+ super(Widget, self).drag_source_set_target_list(target_list)
+
+
Widget = override(Widget)
__all__.append('Widget')
@@ -1306,23 +1333,14 @@ class TreeView(Gtk.TreeView, Container):
if success:
return (path, pos,)
- def _construct_target_list(self, targets):
- # FIXME: this should most likely be part of Widget or a global helper
- # function
- target_entries = []
- for t in targets:
- entry = Gtk.TargetEntry.new(*t)
- target_entries.append(entry)
- return target_entries
-
def enable_model_drag_source(self, start_button_mask, targets, actions):
- target_entries = self._construct_target_list(targets)
+ target_entries = _construct_target_list(targets)
super(TreeView, self).enable_model_drag_source(start_button_mask,
target_entries,
actions)
def enable_model_drag_dest(self, targets, actions):
- target_entries = self._construct_target_list(targets)
+ target_entries = _construct_target_list(targets)
super(TreeView, self).enable_model_drag_dest(target_entries,
actions)
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index ae33c4f..69f0d38 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -552,6 +552,38 @@ class TestGtk(unittest.TestCase):
self.assertTrue(hasattr(widget.drag_dest_set_proxy, '__call__'))
self.assertTrue(hasattr(widget.drag_get_data, '__call__'))
+ def test_drag_target_list(self):
+ mixed_target_list = [Gtk.TargetEntry.new('test0', 0, 0),
+ ('test1', 1, 1),
+ Gtk.TargetEntry.new('test2', 2, 2),
+ ('test3', 3, 3)]
+
+ def _test_target_list(targets):
+ for i, target in enumerate(targets):
+ self.assertTrue(isinstance(target, Gtk.TargetEntry))
+ self.assertEqual(target.target, 'test' + str(i))
+ self.assertEqual(target.flags, i)
+ self.assertEqual(target.info, i)
+
+ _test_target_list(Gtk._construct_target_list(mixed_target_list))
+
+ widget = Gtk.Button()
+ widget.drag_dest_set(Gtk.DestDefaults.DROP, None, Gdk.DragAction.COPY)
+ widget.drag_dest_set_target_list(mixed_target_list)
+ widget.drag_dest_get_target_list()
+
+ widget.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, None, Gdk.DragAction.MOVE)
+ widget.drag_source_set_target_list(mixed_target_list)
+ widget.drag_source_get_target_list()
+
+ treeview = Gtk.TreeView()
+ treeview.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK,
+ mixed_target_list,
+ Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE)
+
+ treeview.enable_model_drag_dest(mixed_target_list,
+ Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE)
+
def test_scrollbar(self):
# PyGTK compat
adjustment = Gtk.Adjustment()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]