Red Hat 9, Python and Glade - a mixure not working?

H

Hans Deragon

Greetings.


Total newbie to Glade here. I created an interface using glade-2
and I want to use it with my python program. Following is what I
wrote (test prg):

-------------------------
#!/usr/bin/python

import gtk
import gtk.glade
import sys

def on_button4_clicked(source=None, event=None):
sys.exit();

gtk.glade.XML('project3.glade')
xml.autoconnect({
'on_button4_clicked': on_button4_clicked
})

gtk.main()
-------------------------

Now when I am running it, I get the following error:

-------------------------
(run2.py:11714): GLib-GObject-CRITICAL **: file gobject.c: line 1002
(g_object_get): assertion `G_IS_OBJECT (object)' failed

(run2.py:11714): GLib-GObject-CRITICAL **: file gobject.c: line 1002
(g_object_get): assertion `G_IS_OBJECT (object)' failed
Erreur de segmentation
-------------------------

I am running redhat 9 with the lastest updates and glade-2. Anybody
has a clue how to get it running? Is there a python program that
comes in one of RH 9 packages that makes use of glade? I could use it
as an example.


Regards,
Hans Deragon
 
D

David M. Cook

Hans Deragon said:
def on_button4_clicked(source=None, event=None):

You should exit the mainloop here:

gtk.main_quit()
sys.exit();

gtk.glade.XML('project3.glade')

Should be

xml = gtk.glade.XML('project3.glade')
xml.autoconnect({
'on_button4_clicked': on_button4_clicked
})

Or you can just use

xml.signal_autoconnect(locals())

See glade_demo.py in the /usr/share/doc/pygtk2-1.99.14/examples/glade/.

For more info on pygtk see

http://www.async.com.br/faq/pygtk/index.py?req=index
http://www.moeraki.com/pygtkreference/pygtk2reference/

Dave Cook
 
H

Hans Deragon

David M. Cook said:

[...deleted lines...]
Should be

xml = gtk.glade.XML('project3.glade')

Ok, here I am embarrassed... forgetting to assign xml... ;)
Or you can just use

xml.signal_autoconnect(locals())

See glade_demo.py in the /usr/share/doc/pygtk2-1.99.14/examples/glade/.

Thanks for the tips. But the problem still persist. Now I run the
following:

------------------
[root@world project3]#
/usr/share/doc/pygtk2-1.99.14/examples/glade/glade-demo.py
project3.glade

(glade-demo.py:3405): GLib-GObject-CRITICAL **: file gobject.c: line
1002 (g_object_get): assertion `G_IS_OBJECT (object)' failed

(glade-demo.py:3405): GLib-GObject-CRITICAL **: file gobject.c: line
1002 (g_object_get): assertion `G_IS_OBJECT (object)' failed
Segmentation fault
------------------

So the problem is not my code. I must assume that the glade module
for gnome is not adapted for taking in Glade 2 xml?

Then I tried with a Glade 1 xml:

-----------------
[root@world project2]#
/usr/share/doc/pygtk2-1.99.14/examples/glade/glade-demo.p
y project2.glade

(glade-demo.py:3541): libglade-WARNING **: Expected <glade-interface>.
Got <GTK
-Interface>.

(glade-demo.py:3541): libglade-WARNING **: did not finish in
PARSER_FINISH state
Traceback (most recent call last):
File "/usr/share/doc/pygtk2-1.99.14/examples/glade/glade-demo.py",
line 12, in
?
xml = gtk.glade.XML(fname)
RuntimeError: could not create GladeXML object
-----------------

Different errors, same results. Nothing works. However the
test.glade xml file provided as an example works fine. I believe that
there is some widget in my glade2 xml file that is simply not
supported by python. I will investigate further the issue later.

Thanks,
Hans Deragon
 
D

David M. Cook

Hans Deragon wrote: said:
Thanks for the tips. But the problem still persist. Now I run the
following:

Do you have gnome widgets in your xml file? You'll need to import gnome.ui
and do a gnome.init().

See the pygtk FAQ:

http://www.async.com.br/faq/pygtk/index.py?req=all

You might also try putting the line

import pygtk; pygtk.require('2.0')

at the top of your file. Also try running with python -v so you can see
what modules are being loaded.
So the problem is not my code. I must assume that the glade module
for gnome is not adapted for taking in Glade 2 xml?

In fact, libglade2 *only* works with glade 2 files. glade 1 files have to
be converted first.
Different errors, same results. Nothing works. However the
test.glade xml file provided as an example works fine. I believe that
there is some widget in my glade2 xml file that is simply not
supported by python. I will investigate further the issue later.

I've never encountered this problem with my own glade 2 files. However, I
don't have a "pristine" RH 9 installation to play with right now.

I suggest taking this problem to the pygtk mailing list. If it's not
quickly fixable then it needs to be fixed somewhere up the line.

Dave Cook
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top