

destroy event of window1. We have to do
this because we want to tell the program to quit when we destroy the window.
Otherwise the program will keep running and we would have to kill it by hand.
Select the window1 widget, then in the Properties window, select
the Signals tab. Click the elipses button, and select the destroy
signal. Glade will automatically suggest a name for the handler,
"on_window1_destroy", which is fine for our purposes. Click the Add button
and we've made our app listen for the destroy signal. When this
signal arrives, it will call the on_window1_destroy function,
which we will define in python.

#!/usr/bin/python
from gtk import * #---------
from gnome.ui import * # Import necessary modules for this tutorial
from libglade import * #---------
#----------------
# DestroyFunction
# this function is called when the window gets destroyed
#----------------
def DestroyFunction(obj):
mainquit()
widgetTree = GladeXML("project1.glade") #create a widget tree from a glade
#file, also does the work of showing
#the window
dic = { "on_window1_destroy" : DestroyFunction } #maps signal handlers
widgetTree.signal_autoconnect (dic) #connects signal handlers defined in
#the glade file to actual Python
#functions
mainloop ()
chmod +x hw.py) and run hw.py.
You should see a window that says "Hello World".




class SillyWalk: def __init__(self, cost, speed, desc): self.researchCost = cost self.speed = speed self.description = desc
class GnomeAppView:
def __init__(self, specFileName="project2.glade"):
self.specFileName = specFileName
self.widgetTree = None
def Show(self):
self.widgetTree = GladeXML( self.specFileName )
dic = { "on_window1_destroy" : self.Destroy }
self.widgetTree.signal_autoconnect (dic)
def Destroy(self, obj):
mainquit() #make the program quit
Show() is called, the
application window displays. We've hooked the on_window1_destroy
signal to the GnomeAppView object's Destroy() method.
When Destroy() gets called, the program terminates.
#!/usr/bin/python
from gtk import * #---------
from gnome.ui import * # Import necessary modules for this tutorial
from libglade import * #---------
class SillyWalk:
def __init__(self, cost, speed, desc):
self.researchCost = cost
self.speed = speed
self.description = desc
class GnomeAppView:
def __init__(self, specFileName="project2.glade"):
self.specFileName = specFileName
self.widgetTree = None
def Show(self):
self.widgetTree = GladeXML( self.specFileName )
dic = { "on_window1_destroy" : self.Destroy }
self.widgetTree.signal_autoconnect (dic)
def Destroy(self, obj):
mainquit() #make the program quit
class SillyWalkApp:
def __init__(self ):
self.view = GnomeAppView( )
self.walks = []
def Start(self):
self.view.Show()
mainloop ()
myApp = SillyWalkApp()
myApp.Start()
