Note that there are some explanatory texts on larger screens.

plurals
  1. POLooking for a child widget with pygtk
    primarykey
    data
    text
    <p>Let's explain the enviroment.</p> <p>I'm building a GUI using pygtk. At some point of my code I create a gtk.ScrolledWindow and set it a name (here the code):</p> <pre><code>top_swin = gtk.ScrolledWindow() top_swin.set_name('script-desc-swin') </code></pre> <p>Later on other part of the code I need to look for this widget so I have tried this:</p> <pre><code>self.gui.get_object('script-desc-swin') </code></pre> <p>self.gui is a gtk.Builder object, it was build from a XML file created with Glade. This line is returning None, so I though that it could be that get_object() can only be used to look for objects DEFINED ON THE GLADE FILE (note that the scrolled window is being created programatically in the code, no with Glade). I tried then the gtk.Buildable.get_internal_child() method but this time I had problems using it because the documentation says that the first parameter is a gtk.Builder (so I passed my self.gui) but then I got this:</p> <pre><code> swin = gtk.Buildable.get_internal_child(self.gui, 'script-desc-swin') TypeError: descriptor 'get_internal_child' requires a 'gtk.Buildable' object but received a 'gtk.Builder' </code></pre> <p>So I tried calling get_internal_child as if it were a method of gtk.Builder (even though I checked first the documentation and realized that gtk.Builder don't implement gtk.Buildable... anyway I tried):</p> <pre><code> swin = self.gui.get_internal_child('script-desc-swin') AttributeError: 'gtk.Builder' object has no attribute 'get_internal_child' </code></pre> <p>Of course I get this, as I said gtk.Builder (self.gui) doesn't implement gtk.Buildable.</p> <p>After all this mess I have no idea about how to look for the scrolled window (or any other widget) so what I'm doing is look for a widget specified in the XML file (in other words, created with Glade), and then I get its child/children and repeting this process. This is like "OMFG! WHAT A CRAPPY CODE!" so even with my application running I really want to change that ugly code:</p> <pre><code>box = self.gui.get_object('MAIN_VIEW_BOX') hpaned = box.get_children()[1] hpaned2 = hpaned.get_child2() swin = hpaned2.get_child1() </code></pre> <p>A box containing an hpaned containing as the second child another hpaned containing as the first child THE SCROLLED WINDOW.</p> <p>Almost sure the answer will be quite simple... :-s</p> <p>Thank!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload