Python Glade could not create GladeXML Object

Posted by Peter on Stack Overflow See other posts from Stack Overflow or by Peter
Published on 2010-04-19T15:24:56Z Indexed on 2010/04/19 16:43 UTC
Read the original article Hit count: 608

Filed under:
|
|
|

Hey,

I've created a simple window GUI in Glade 3.6.7 and I am trying to import it into Python. Every time I try to do so I get the following error:

(queryrelevanceevaluation.py:8804): libglade-WARNING **: Expected <glade-interface>.    Got <interface>.

(queryrelevanceevaluation.py:8804): libglade-WARNING **: did not finish in PARSER_FINISH   state
Traceback (most recent call last):
  File "queryrelevanceevaluation.py", line 17, in <module>
    app = QueryRelevanceEvaluationApp()
  File "queryrelevanceevaluation.py", line 10, in __init__
    self.widgets = gtk.glade.XML(gladefile)
RuntimeError: could not create GladeXML object

My Python Code:

#!/usr/bin/env python

import gtk
import gtk.glade

class  QueryRelevanceEvaluationApp:

def __init__(self):
    gladefile = "foo.glade"
    self.widgets = gtk.glade.XML(gladefile)
    dic = {"on_buttonGenerate_clicked" : self.on_buttonGenerate_clicked}
    self.widgets.signal_autoconnect(dic)

def on_buttonGenerate_clicked(self, widget):
    print "You clicked the button"

app = QueryRelevanceEvaluationApp()
gtk.main()

And the foo.glade file:

<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="windowRelevanceEvaluation">
<property name="visible">True</property>
<property name="title" translatable="yes">Query Result Relevance Evaluation</property>
<child>
  <object class="GtkVBox" id="vbox1">
    <property name="visible">True</property>
    <property name="orientation">vertical</property>
    <child>
      <object class="GtkHBox" id="hbox2">
        <property name="visible">True</property>
        <child>
          <object class="GtkLabel" id="labelQuery">
            <property name="visible">True</property>
            <property name="label" translatable="yes">Query:</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="padding">4</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkEntry" id="entry1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="invisible_char">&#x25CF;</property>
          </object>
          <packing>
            <property name="padding">4</property>
            <property name="position">1</property>
          </packing>
        </child>
      </object>
      <packing>
        <property name="position">0</property>
      </packing>
    </child>
    <child>
      <object class="GtkFrame" id="frameSource">
        <property name="visible">True</property>
        <property name="label_xalign">0</property>
        <child>
          <object class="GtkAlignment" id="alignment1">
            <property name="visible">True</property>
            <property name="left_padding">12</property>
            <child>
              <object class="GtkHButtonBox" id="hbuttonbox1">
                <property name="visible">True</property>
                <child>
                  <object class="GtkRadioButton" id="radiobuttonGoogle">
                    <property name="label" translatable="yes">Google</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">False</property>
                    <property name="active">True</property>
                    <property name="draw_indicator">True</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">False</property>
                    <property name="position">0</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkRadioButton" id="radiobuttonBing">
                    <property name="label" translatable="yes">Bing</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">False</property>
                    <property name="active">True</property>
                    <property name="draw_indicator">True</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">False</property>
                    <property name="position">1</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkRadioButton" id="radiobuttonBoden">
                    <property name="label" translatable="yes">Boden</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">False</property>
                    <property name="active">True</property>
                    <property name="draw_indicator">True</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">False</property>
                    <property name="position">2</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkRadioButton" id="radiobuttonCSV">
                    <property name="label" translatable="yes">CSV</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">False</property>
                    <property name="active">True</property>
                    <property name="draw_indicator">True</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">False</property>
                    <property name="position">3</property>
                  </packing>
                </child>
              </object>
            </child>
          </object>
        </child>
        <child type="label">
          <object class="GtkLabel" id="labelFrameSource">
            <property name="visible">True</property>
            <property name="label"    translatable="yes">&lt;b&gt;Source&lt;/b&gt;</property>
            <property name="use_markup">True</property>
          </object>
        </child>
      </object>
      <packing>
        <property name="position">1</property>
      </packing>
    </child>
    <child>
      <object class="GtkFrame" id="frame1">
        <property name="visible">True</property>
        <property name="label_xalign">0</property>
        <child>
          <object class="GtkHBox" id="hbox3">
            <property name="visible">True</property>
            <child>
              <object class="GtkLabel" id="labelResults">
                <property name="visible">True</property>
                <property name="label" translatable="yes">Number Results:</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkSpinButton" id="spinbuttonResults">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="invisible_char">&#x25CF;</property>
              </object>
              <packing>
                <property name="padding">4</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
        </child>
        <child type="label">
          <object class="GtkLabel" id="labelFrameResults">
            <property name="visible">True</property>
            <property name="label" translatable="yes">&lt;b&gt;Results&lt;/b&gt;</property>
            <property name="use_markup">True</property>
          </object>
        </child>
      </object>
      <packing>
        <property name="padding">2</property>
        <property name="position">2</property>
      </packing>
    </child>
    <child>
      <object class="GtkButton" id="buttonGenerateResults">
        <property name="label" translatable="yes">Generate!</property>
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
      </object>
      <packing>
        <property name="position">3</property>
      </packing>
    </child>
  </object>
</child>
</object>
</interface>

foo.glade and the above python script are in the same directory, and I have tried using a fully-qualified path but still get the same error (I am certain that the path is correct!).

Any ideas?

Cheers,

Pete

© Stack Overflow or respective owner

Related posts about python

Related posts about glade