[pygtk] reparent problem

Tim Evans t.evans at aranz.com
Mon Jun 30 06:44:13 WST 2008


Frédéric wrote:
> Hello,
> 
> To integrate my shootingArea widget (which inherits gtk.Drawingarea) in my 
> GTU (defined with glade), I follow theses steps:
> 
> 1) in glade, I create a dummy widget where I want to put my custom widget;
> 
> 2) in my code, right after loading the glade file, I do:
> 
> dummyWidget = self.wTree.get_widget(dummyWidget)
> parent = dummyWidget.parent
> del dummyWidget
> self.shootingArea = ShootingArea()
> self.shootingArea.set_parent(parent)
> self.shootingArea.show()
> 
> But my widget does not work, and neither displayed (none of the 'realize' 
> or 'configure-event' or expose-event' callabck is called).
> 
> Any idea?
> 

This is the function I use when I'm replacing a placeholder widget in a 
glade file:

def replace_widget(old, new):
     parent = old.get_parent()
     if parent is not None:
         props = []
         for pspec in parent.list_child_properties():
             props.append(pspec.name)
             props.append(parent.child_get_property(old, pspec.name))
         parent.remove(old)
         parent.add_with_properties(new, *props)
     if old.flags() & gtk.VISIBLE:
         new.show()
     else:
         new.hide()

Just call "replace_widget(dummyWidget, self.shootingArea)" and wherever 
dummyWidget was (and with whatever packing properties) your shootingArea 
widget will be put there instead.  You could add more copying of 
properties is you need it, this function only copies visibility.

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/


More information about the pygtk mailing list