Hi all ->

  I am having trouble porting an application from gtk1.2 to gtk2.  I have
a c module with subclasses with corresponding python wrapper classes.  For
example, C subclasses B subclasses A, where A is some gtk widget:

  c code           auto-generated wrappers            python
class A                   _m.a                    A(_m.a)
      + B                 + _m.b                  + B(_m.b, A)
        + C                 + _m.c                  + C(_m.c, B)

  With the old pygtk, the python classes wrapped the c module classes by
assigning an instance of the c module class to ._o, and the wrapper magic
made it so python object calls forwarded the calls to the underlying c
instance.  This meant that the python classes looked like:

class A(gtk.<superclass of A in c code>)
      + B(A)
        + C(B)

  The python classes could add extra code to the wrapped c module classes,
and you could create a new C object by simply assigning an instance of
_m.c to the ._o in the C instance, and then with the C instance you could
call all _m.c functions as well as the additional methods added at the
pure python level in classes C, B or A.

  The problem I am having is when the c code creates a new instance of
another c object, and I want to use it at the python level.  For example,
if _m.c has a function get_b() that returns an _m.b, I could try my_b =
my_c.get_b() and use this _m.b instance to call anything defined in B at
the c code level, but I can not call anything defined in A or B at the
python level.  What I really want is to replicate what was possible with
the old pygtk, which is create a new instance of B at the python level
that wraps the _m.b instance, so that calls to functions in B are really
calls to the underlying _m.b instance.  This way the higher level programs
only deal with the python A, B, and C objects, and they don't have to
worry about which methods are defined in the underlying c module or at the
pure python level.

  I have tried having the B(_m.b, A) __init__ method take an _m.b
parameter, and if specified then I bypass the _m.b init call (which would
create a second instance of _m.b, which would be bad), and instead assign
the _m.b instance to a ._o attribute, and I modifiy __getattribute__ to
pass any calls to the ._o, if it exists.  This works in that I can call
_m.b methods using the B object, but not all of the magic is working,
as B is not considered an initialized instance of _m.b, and these gtk
widgets don't display properly.

  Does anyone know how to solve this?  The documentation I've seen on c
modules does not offer much help with more complex objects that are
subclassed both at the c and at the python level.  Since this was easy to
do with the old pygtk and seems like a reasonable thing to want to do,
some things being easier to implement in python and some better in c,
seems there should be some good way of tackling this...

  Thanks for any advice,

-> Pete

--------------------------------------------------------------------

====================================================================
Pete Nagy                                        tel: (303) 583-0248
Vexcel Corporation                               fax: (303) 583-0246
http://www.vexcel.com                           home: (303) 823-2336
====================================================================

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to