Read from .glade

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ralfbrand50@gmail.com

    #1

    Read from .glade

    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="GtkWindo w" id="TEVOinvoere n">
    <property name="visible"> True</property>
    <property name="title" translatable="y es">Tevo - Invoeren</property>
    <property name="type">GTK _WINDOW_TOPLEVE L</property>
    <property name="window_po sition">GTK_WIN _POS_NONE</property>
    <property name="modal">Fa lse</property>
    <property name="resizable ">True</property>
    <property name="destroy_w ith_parent">Fal se</property>
    <property name="decorated ">True</property>
    <property name="skip_task bar_hint">False </property>
    <property name="skip_page r_hint">False</property>
    <property name="type_hint ">GDK_WINDOW_TY PE_HINT_NORMAL</property>
    <property name="gravity"> GDK_GRAVITY_NOR TH_WEST</property>
    <property name="focus_on_ map">True</property>
    <property name="urgency_h int">False</property>

    <child>

    <widget class="GtkWindo w" id="TEVOklantto evoegen">
    <property name="visible"> True</property>
    <property name="title" translatable="y es">window1</property>
    <property name="type">GTK _WINDOW_TOPLEVE L</property>
    <property name="window_po sition">GTK_WIN _POS_NONE</property>
    <property name="modal">Fa lse</property>
    <property name="resizable ">True</property>
    <property name="destroy_w ith_parent">Fal se</property>
    <property name="decorated ">True</property>
    <property name="skip_task bar_hint">False </property>
    <property name="skip_page r_hint">False</property>
    <property name="type_hint ">GDK_WINDOW_TY PE_HINT_NORMAL</property>
    <property name="gravity"> GDK_GRAVITY_NOR TH_WEST</property>
    <property name="focus_on_ map">True</property>
    <property name="urgency_h int">False</property>
    <signal name="destroy" handler="on_TEV Oklanttoevoegen _destroy"
    last_modificati on_time="Wed, 06 Sep 2006 08:51:33 GMT"/>

    <child>
    <widget class="GtkFixed " id="fixed10">
    <property name="visible"> True</property>

    <child>
    <widget class="GtkEntry " id="entry_cnaam ">
    <property name="width_req uest">184</property>
    <property name="height_re quest">16</property>
    <property name="visible"> True</property>
    <property name="can_focus ">True</property>
    <property name="editable" >True</property>
    <property name="visibilit y">True</property>
    <property name="max_lengt h">0</property>
    <property name="text" translatable="y es"></property>
    <property name="has_frame ">True</property>
    <property name="invisible _char">*</property>
    <property name="activates _default">False </property>
    </widget>
    <packing>
    <property name="x">88</property>
    <property name="y">88</property>
    </packing>
    </child>

    .....

    Kind regards,

    Ralf Brand

  • davelist@mac.com

    #2
    Re: Read from .glade


    On Wednesday, September 06, 2006, at 10:36AM, <ralfbrand50@gm ail.comwrote:
    >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="GtkWindo w" id="TEVOinvoere n">
    <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.gla de_file)

    # look for widgets and get their widget type and name
    for node in doc.getElements ByTagName('widg et'):
    widget = str(node.getAtt ribute('class') )
    name = str(node.getAtt ribute('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.ap pend((widget, name))


    HTH,
    Dave

    Comment

    Working...