PyGTK + Glade = weird problem

S

sapo

Hi all, i ve started learning pygtk with glade, i m just making some
test stuff. but i got some problems with simple things.

I designed 2 windows on glade, then exported it and loaded in the
python script, the second window is hidden by default, then i wrote a
function to show it up, ok it shows, them i wrote another function to
hide it.. ok it hides...

But in the second time i show the window.. the window appear EMPTY,
with just the title and NOTHING inside..

This is well explained here:

http://ubuntuforums.org/showthread.php?p=768219

Hope someone can help me, i tried irc, forums, googled a lot.. but
nothing solves my problem, even rewriting the code by hand results on
the same thing!

thanx for any help
 
G

gsteff

We'd need to see your "scc.glade" file to be sure, but basically,
calling the "show" method on the "w_cadcli" object only shows it, not
the objects it contains. Again, to be clear, showing a container
object doesn't automatically show the objects it contains. In glade,
use the "common" tab of the property editor to make sure that the
"visible" property is set to "Yes" for all of the widgets in the
windows you want to show. In general, if you always do that, you'll be
able to show or hide the entire window by simply calling "show" or
"hide" on the window object, like you're trying to do.

But this is just a guess; post your "scc.glade" file if the above
advice doesn't work.

Greg
 
G

gsteff

Oops- I didn't read your question carefully enough. That's probably
not the problem.

Greg
 
G

gsteff

Sorry about that. Your problem is that the show_hide_janela method is
setup to be called both on a gtk signal ("destroy") and an
event("delete_event"). Callback methods for events take a slightly
different signature than signals; they take one extra argument, which
represents the triggering event. When you close the window, the
delete_event is triggered, which calls show_hide_janella, but the call
fails, because show_hide_janella is called with 3 arguments, when its
only expecting 2. So, to fix the code you have posted in the thread
you linked, replace the line

def show_hide_janela(self,obj):

with the line

def show_hide_janela(self,obj, event=None):

The modified code works on my machine. Hope this helps,

Greg
 
S

sapo

Man, you saved my day.

I spent all day writing and rewriting stuff, i asked several times on
the #python channel on irc.freenode.org, asked in the ubuntuforums,
asked all people i know that uses python.. and nobody solved it.

And it was a very simple and stupid thing!

thanx a lot it worked perfectly!
 
S

sapo

Anyway, now i tried in my glade app and i m getting this error when i
try to show the window:

GtkWarning: gtk_paint_flat_box: assertion `style->depth ==
gdk_drawable_get_depth (window)' failed

here is the code:

class main:
def __init__(self):
self.principal = gtk.glade.XML("scc.glade")
self.w_cadcli = self.principal.get_widget("w_cadcli")
dic = {"on_principal_destroy" : self.DestroyFunction,
"on_sair_activate" : self.DestroyFunction,
"on_w_cadcli_destroy" : self.show_hide_window,
"on_cadcli_activate" : self.show_hide_window}
self.principal.signal_autoconnect(dic)
principal = self.principal.get_widget("principal")
gtk.main()

def DestroyFunction(self,*args):
gtk.main_quit()

def show_hide_window(self,obj,event=None):
#if the second window is open hide it, if dont show it
if self.w_cadcli.get_property("visible") == True:
self.w_cadcli.hide()
else:
self.w_cadcli.show()
return True
 
S

sapo

Finally solved this stuff, the problem wasnt with glade, the problem
was that i was using the "destroy" event in glade, i just changed the
"destroy" to "delete-event" and it worked like a charm.

thanx :)
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top