Read from .glade

davelist at mac.com davelist at mac.com
Wed Sep 6 11:58:35 EDT 2006


 
On Wednesday, September 06, 2006, at 10:36AM, <ralfbrand50 at gmail.com> wrote:

>Hello,
>
>I've got the following problem: I've got a Userinterface that is made
>in Glade, so i've got a
>.glade file. What I want is to get the id's of every widget from the
>class GtkEntry from a given window.
>
>The glade file is like
>
><?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
><!DOCTYPE glade-interface SYSTEM
>"http://glade.gnome.org/glade-2.0.dtd">
>
><glade-interface>
>
><widget class="GtkWindow" id="TEVOinvoeren">

<snip rest of glade xml file>

>Kind regards,
>
>Ralf Brand
>


You want to use one of the XML processing libraries. The simplest (and should be fine for this use) is dom.

Here is some code I wrote as part of GladeGen - see http://www.linuxjournal.com/article/7421
that you should be able to easily extract the piece you need:

        doc = xml.dom.minidom.parse(self.glade_file)

        # look for widgets and get their widget type and name
        for node in doc.getElementsByTagName('widget'):
            widget = str(node.getAttribute('class'))
            name = str(node.getAttribute('id'))
            if self.top_window is None and widget == 'GtkWindow':
                self.top_window = name

            # if the widget type is in list of widgets user specified
            # in config file, include it in the list
            
            if widget in GladeGenConfig.include_widget_types:
                # (widget type, name)
                # ('GtkWindow', 'window1')
                self.widgets.append((widget, name))


HTH,
Dave




More information about the Python-list mailing list