After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 677941 - Gtk.ListStore doesn't have the method "reorder" as its documentation says
Gtk.ListStore doesn't have the method "reorder" as its documentation says
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
3.5.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2012-06-12 13:08 UTC by Manuel Kaufmann
Modified: 2012-06-12 15:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
liststore: Make gtk_list_store_reorder() introspectable (1.59 KB, patch)
2012-06-12 13:44 UTC, Martin Pitt
committed Details | Review
Test case using "reorder". (1.24 KB, text/x-python)
2012-06-12 15:04 UTC, Manuel Kaufmann
  Details

Description Manuel Kaufmann 2012-06-12 13:08:32 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):
  • File "<stdin>", line 1 in <module>
AttributeError: 'ListStore' object has no attribute 'reorder'
>>>

Thanks,

[1] http://bugs.sugarlabs.org/ticket/3681
[2] http://developer.gnome.org/gtk3/3.0/GtkListStore.html#gtk-list-store-reorder
Comment 1 Ángel Guzmán Maeso (shakaran) 2012-06-12 13:32:30 UTC
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&lt;literal&gt;[newpos] = oldpos&lt;/literal&gt;.</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".
Comment 2 Martin Pitt 2012-06-12 13:34:09 UTC
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?
Comment 3 Martin Pitt 2012-06-12 13:36:01 UTC
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.
Comment 4 Martin Pitt 2012-06-12 13:44:15 UTC
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.
Comment 5 Manuel Kaufmann 2012-06-12 13:58:59 UTC
Martin,

Can you give me the steps to test that patch? 
Should I re-compile Gtk with this patch?

Thanks,
Comment 6 Manuel Kaufmann 2012-06-12 15:04:41 UTC
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!
Comment 7 Martin Pitt 2012-06-12 15:18:15 UTC
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):
  • File "/tmp/listview_reorder_example.py", line 46 in <module>
    win = MyWindow()
  • File "/tmp/listview_reorder_example.py", line 32 in __init__
    self.store.reorder(r)
AttributeError: 'ListStore' object has no attribute 'reorder'

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!