Read from .glade

R

ralfbrand50

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">
<property name="visible">True</property>
<property name="title" translatable="yes">Tevo - Invoeren</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>

<child>

<widget class="GtkWindow" id="TEVOklanttoevoegen">
<property name="visible">True</property>
<property name="title" translatable="yes">window1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="destroy" handler="on_TEVOklanttoevoegen_destroy"
last_modification_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_request">184</property>
<property name="height_request">16</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></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
 
D

davelist

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">

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top