GNOME Bugzilla – Bug 677941
Gtk.ListStore doesn't have the method "reorder" as its documentation says
Last modified: 2012-06-12 15:18:26 UTC
Hello, I'm porting a Sugar Activity from gtk2 to Gtk3[1] and I found that Gtk.ListStore doesn't have the method "reorder". I took a look at the documentation[2] and I saw that the "reorder" method is there but it seems that it's not available from Python Binding. Here an example on the Python Interpreter: [humitos@michifus ~]$ python Python 2.7.3 (default, Apr 30 2012, 21:18:11) [GCC 4.7.0 20120416 (Red Hat 4.7.0-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gi.repository import Gtk >>> list_store = Gtk.ListStore() >>> list_store.reorder Traceback (most recent call last):
+ Trace 230352
>>> Thanks, [1] http://bugs.sugarlabs.org/ticket/3681 [2] http://developer.gnome.org/gtk3/3.0/GtkListStore.html#gtk-list-store-reorder
I can confirm this bug. The .gir file on /usr/share/gir-1.0/Gtk-3.0.gir shows: <method name="reorder" c:identifier="gtk_list_store_reorder" version="2.2" introspectable="0"> <doc xml:whitespace="preserve">Reorders @store to follow the order indicated by @new_order. Note that this function only works with unsorted stores.</doc> <return-value transfer-ownership="none"> <type name="none" c:type="void"/> </return-value> <parameters> <parameter name="new_order" transfer-ownership="none"> <doc xml:whitespace="preserve">an array of integers mapping the new position of each child to its old position before the re-ordering, i.e. @new_order<literal>[newpos] = oldpos</literal>.</doc> <array zero-terminated="0" c:type="gint*"> <type name="gint" c:type="gint"/> </array> </parameter> </parameters> </method> Maybe the problem is the xml attribute introspectable="0".
Indeed, it is marked as non-introspectable: <method name="reorder" c:identifier="gtk_list_store_reorder" version="2.2" introspectable="0"> [...] <parameter name="new_order" transfer-ownership="none"> [...] <array zero-terminated="0" c:type="gint*"> <type name="gint" c:type="gint"/> </array> I guess this is because the array is not zero-terminated and does not have a constant or specified length. I suppose it could be marked as zero-terminated, as this would not really hurt anything?
This was even explicitly marked as (skip) in http://git.gnome.org/browse/gtk+/commit/?id=374e76a19dac87676995356f6daacb10f4bb6e36 but this mostly looked like a mass-cleanup to reduce warnings.
Created attachment 216205 [details] [review] liststore: Make gtk_list_store_reorder() introspectable How about this? I verified that it builds and makes the method introspectable, but I have not yet tested it from an actual Python program.
Martin, Can you give me the steps to test that patch? Should I re-compile Gtk with this patch? Thanks,
Created attachment 216209 [details] Test case using "reorder". I'm attaching a Python example to show how "reorder" method should work. Besides, it has commented out some lines that work as I expect that "reorder" works for the example given. I hope it helps!
Thanks for this! With a slight fix: r = list(reversed(range(len(self.store)))) This example now fails as expected with current GTK release $ python /tmp/listview_reorder_example.py [4, 3, 2, 1, 0] Traceback (most recent call last):
+ Trace 230355
win = MyWindow()
self.store.reorder(r)
and succeeds with this GTK patch: I get a window with items 4 down to 0. According to the "you can push annotation fixes if you tested them" regime I pushed this patch. Thanks!