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 680009 - gtk_tree_model_sort_new_with_model() is not annotated as a constructor
gtk_tree_model_sort_new_with_model() is not annotated as a constructor
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: .General
3.5.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2012-07-16 13:31 UTC by Manuel Kaufmann
Modified: 2018-02-10 04:37 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Manuel Kaufmann 2012-07-16 13:31:33 UTC
Hello,

I'm porting an Log Activity (from Sugar) and I found this gtk2 code on it:

 self._treemodel = gtk.TreeStore(gobject.TYPE_STRING)
 sorted = gtk.TreeModelSort(self._treemodel)

So, after running the pygi-convert.sh script it replaced this chunk of code by:

 self._treemodel = Gtk.TreeStore(GObject.TYPE_STRING)
 sorted = Gtk.TreeModelSort(self._treemodel)

but I noticed that Gtk.TreeModelSort can be instanciated with an argument. I got this error:

 Traceback (most recent call last):
  • File "/home/humitos/sugar-jhbuild/install/bin/sugar-activity", line 154 in <module>
    main()
  • File "/home/humitos/sugar-jhbuild/install/bin/sugar-activity", line 149 in main
    instance = create_activity_instance(activity_constructor, activity_handle)
  • File "/home/humitos/sugar-jhbuild/install/bin/sugar-activity", line 36 in create_activity_instance
    activity = constructor(handle)
  • File "/home/humitos/Activities/Log.activity/logviewer.py", line 364 in __init__
    self.viewer = MultiLogView(paths, ext_files)
  • File "/home/humitos/Activities/Log.activity/logviewer.py", line 67 in __init__
    self._build_treeview()
  • File "/home/humitos/Activities/Log.activity/logviewer.py", line 83 in _build_treeview
    sorted = Gtk.TreeModelSort(self._treemodel)
TypeError: GObject.__init__() takes exactly 0 arguments (1 given)

First, I tried to use the .new_with_model() constructor:

 from gi.repository import GObject
 from gi.repository import Gtk
 _treemodel = Gtk.TreeStore(GObject.TYPE_STRING)
 s = Gtk.TreeModelSort.new_with_model(_treemodel)
 [...]
 AttributeError: type object 'TreeModelSort' has no attribute 'new_with_model'

So, I tried to set it using .set_property() method:

 s = Gtk.TreeModelSort()
 s.set_property('model', _treemodel)
 [...]
 TypeError: property 'model' can only be set in constructor

I think this is a bug because I didn't find the way to do this.
Comment 1 Martin Pitt 2012-07-16 14:32:43 UTC
Indeed it is wrongly annotated to be a method of Gtk.TreeModel right now. I. e. if you have a treemodel "model", you currently need to call

   sorted = model.sort_new_with_model()

to get a Gtk.TreeModelSort instance. This looks confusing, and should rather be

   sorted = Gtk.TreeModelSort.new_with_model(model)
Comment 2 Martin Pitt 2012-07-17 03:52:06 UTC
This is actually not that simple to fix with a mere (constructor) annotation, because gtk_tree_model_sort_new_with_model() is not a real constructor in the sense that it returns a GtkTreeModel*, not a GtkTreeModelSort*. So the g-i scanner complains about constructors needing to return the type that they are supposed to construct. However, changing it to return a GtkTreeModelSort* changes the API in the sense of introducing type incompatibility and thus compiler warnings into previously warning-free code.
Comment 3 Matthias Clasen 2018-02-10 04:37:23 UTC
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and
still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue
for it.