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 588762 - do_* methods are not bound to class instances to which they refer
do_* methods are not bound to class instances to which they refer
Status: RESOLVED NOTABUG
Product: pygtk
Classification: Bindings
Component: gtk
2.15.x
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2009-07-16 10:01 UTC by Pietro Battiston
Modified: 2010-12-23 21:36 UTC
See Also:
GNOME target: ---
GNOME version: 2.27/2.28


Attachments
virtual_methods example (410 bytes, application/force-download)
2010-12-23 21:33 UTC, Dieter Verfaillie
Details

Description Pietro Battiston 2009-07-16 10:01:20 UTC
Please describe the problem:
(apparently all) do_* methods are not bound to class instances to which they (should) refer.

Steps to reproduce:
1. ipython
2. import gtk
3. r = gtk.CellRendererText()
4. r.do_get_size(gtk.Window())


Actual results:
TypeError                                 Traceback (most recent call last)

/home/pietro/<ipython console> in <module>()

TypeError: GtkCellRenderer.do_get_size() argument 1 must be gtk.CellRenderer, not gtk.Window


Expected results:
Out[5]: (0, 0, 4, 17)


Does this happen every time?
Yes

Other information:
The following works (apparently across all classes and do_* methods):

In [6]: r.do_get_size(r, gtk.Window())
Out[6]: (0, 0, 4, 17)
Comment 1 Gian Mario Tagliaretti 2009-07-18 14:53:34 UTC
This is not a bug, the do_foo_bar_* methods take the class itself as first parameter, why do you think this is a bug?
Comment 2 Pietro Battiston 2009-07-19 02:55:15 UTC
With the following code:

import gtk, gobject

class CellRendererBig(gtk.CellRendererText):
    def do_get_size(self, widget, cell_area):
        print "self is", self
        return gtk.CellRendererText.do_get_size(self, widget, cell_area)

gobject.type_register(CellRendererBig)

w=gtk.Window()
r=CellRendererBig()
print "r is", r
t=gtk.TreeView()
c=gtk.TreeViewColumn("title", r)
c.add_attribute(r, 'text', 0)
t.append_column(c)
m=gtk.ListStore(str)
t.set_model(m)
m.insert(1000, ["long text to check get_size still works"])
w.add(t)
w.show_all()
gtk.main()

we see that (as one would expect) "self" is exactly "r", not its class... so I don't get what you mean.
Comment 3 Pietro Battiston 2010-04-24 15:00:03 UTC
OK, I'll say it in another way:

r.do_get_size(r, gtk.Window())

doesn't pass "the class itself" as first parameter, it passes the _instance_. So
1) again, I don't see what you mean in your answer
2) it seems to me really not pythonic that a method on an object must be _called_ with the object also as parameter.

but then, it's certainly not an unsurmountable problem, so if you say _this_ is the right way because of some reason I'm missing, the bug can be certainly closed.
Comment 4 Dieter Verfaillie 2010-12-23 21:33:28 UTC
Created attachment 176974 [details]
virtual_methods example
Comment 5 Dieter Verfaillie 2010-12-23 21:36:12 UTC
I'd agree with Gian Mario that this is not a bug. I do see why the
behavior described above would take people by surprise. Normal methods,
when called on an instance, implicitly fill in the first parameter (the
instance of the object the method was called on, also known as "self":

>>> class Test(object):
...     def hello(self, param):
...         print self, param
...
>>> test = Test()
>>> test.hello('sometext')
<__main__.Test object at 0x011BA330> sometext
>>>

Virtual methods (do_*) are however not really intended to be used
outside (sub)class definitions. For the original question, the
do_get_size virtual method is the implementation behind the get_size
method [1]. The attached virtual_methods.py shows an example of
how the get_size method relates to the do_get_size virtual method.

[1] http://library.gnome.org/devel/pygtk/2.22/class-gtkcellrenderer.html#method-gtkcellrenderer--get-size