W
Will Ware
In July there was a thread about problems on Red Hat 9 with PyGTK
not playing nice with Glade. I was tinkering with this a little bit
tonight, starting with the code I found in this article:
http://www.linuxjournal.com/article.php?sid=6586
Based on what was written, I tried this and had no joy:
######################################
import gtk
import gtk.glade
class BadGui:
def __init__(self):
gladefile = "project1.glade"
windowname = "window1"
self.wTree = tree = gtk.glade.XML(gladefile, windowname)
d = { }
for name in dir(self.__class__):
d[name] = getattr(self, name)
tree.signal_autoconnect(d)
gtk.mainloop()
def on_button1_clicked(self, *args):
print "button 1 clicked"
gtk.mainquit()
def on_button2_clicked(self, *args):
print "button 2 clicked"
def on_window1_destroy(self, *args):
print args
gtk.mainquit()
BadGui()
###################################
After some puttering, I came up with the following, which
works just fine:
########################################
import gtk
import gtk.glade
class GoodGui:
def __init__(self):
gladefile = "project1.glade"
windowname = "window1"
self.wTree = tree = gtk.glade.XML(gladefile, windowname)
for name in dir(self.__class__):
if name.startswith("on_"):
widgetname = name.split("_")[1]
widget = tree.get_widget(widgetname)
action = name[4 + len(widgetname):]
widget.connect(action, getattr(self, name))
gtk.mainloop()
def on_button1_clicked(self, *args):
print "button 1 clicked"
gtk.mainquit()
def on_button2_clicked(self, *args):
print "button 2 clicked"
def on_window1_destroy(self, *args):
print args
gtk.mainquit()
GoodGui()
########################################
As far as I can tell, there seems to be a problem with
signal_autoconnect, either how it's implemented in libglade
or how it gets connected to Python. Anyway, I'm passing this
along for any who might find it helpful.
not playing nice with Glade. I was tinkering with this a little bit
tonight, starting with the code I found in this article:
http://www.linuxjournal.com/article.php?sid=6586
Based on what was written, I tried this and had no joy:
######################################
import gtk
import gtk.glade
class BadGui:
def __init__(self):
gladefile = "project1.glade"
windowname = "window1"
self.wTree = tree = gtk.glade.XML(gladefile, windowname)
d = { }
for name in dir(self.__class__):
d[name] = getattr(self, name)
tree.signal_autoconnect(d)
gtk.mainloop()
def on_button1_clicked(self, *args):
print "button 1 clicked"
gtk.mainquit()
def on_button2_clicked(self, *args):
print "button 2 clicked"
def on_window1_destroy(self, *args):
print args
gtk.mainquit()
BadGui()
###################################
After some puttering, I came up with the following, which
works just fine:
########################################
import gtk
import gtk.glade
class GoodGui:
def __init__(self):
gladefile = "project1.glade"
windowname = "window1"
self.wTree = tree = gtk.glade.XML(gladefile, windowname)
for name in dir(self.__class__):
if name.startswith("on_"):
widgetname = name.split("_")[1]
widget = tree.get_widget(widgetname)
action = name[4 + len(widgetname):]
widget.connect(action, getattr(self, name))
gtk.mainloop()
def on_button1_clicked(self, *args):
print "button 1 clicked"
gtk.mainquit()
def on_button2_clicked(self, *args):
print "button 2 clicked"
def on_window1_destroy(self, *args):
print args
gtk.mainquit()
GoodGui()
########################################
As far as I can tell, there seems to be a problem with
signal_autoconnect, either how it's implemented in libglade
or how it gets connected to Python. Anyway, I'm passing this
along for any who might find it helpful.