Re: Cannot subclass objects with constructor arguments



Hi,

                  في س، 11-02-2012 عند 01:21 -0600 ، كتب Kerrick Staley:
> Hello,
> I am having exactly the same issue (when trying to subclass
> Clutter.Box) as that described in this thread:
> http://lists.clutter-project.org/pipermail/clutter-app-devel-list/2011-September/000742.html
> 
> Using the workaround that Martin described, I was able to get my code
> to function, but I'd like to know how to solve this problem in
> general. If a GObject's .new() method takes arguments, how can you
> supply those arguments in the __init__() method of a subclass? Here is
> my code:

I'm not sure whether this is the recommended solution, but the following
works: 

from gi.repository import GObject, Clutter
class Editor(Clutter.Box):
    def __init__(self):
        super(Editor, self).__init__(layout_manager=Clutter.BinLayout.new(4,4))

The __init__function of GObject (which is GObject.Object in python, not
as you wrote in your "also does not work" example) is more or less the
same as g_object_new in C, and the new functions are just for
convenience. This is not very pythonic, but this is how GObject works.

HTH,
Abderrahim



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]