1
"""This module contains the LibGladeApplication class."""
7
from GtkAttributesFacade import GtkAttributesFacade
10
class LibGladeApplication:
12
"""This is the base class for applications that use Glade.
14
The following attributes are used:
16
xml - This is an instance of glade.XML which encapsulates the Glade GUI.
18
The following private variables are used:
20
_signalsAreDone - The UNIX signal handlers only have to be set once.
24
_signalsAreDone = False
26
def __init__(self, gladeFile):
27
"""Setup the appropriate signal handlers and call setHandlers."""
28
if not self._signalsAreDone:
29
self._signalsAreDone = True
30
signal.signal(signal.SIGINT, signal.SIG_DFL)
31
self.xml = glade.XML(gladeFile)
34
def setHandlers(self):
35
"""Automatically autoconnect all of the handlers.
37
Any methods (even in subclasses) that start with "on_" will be treated
38
as a handler that is automatically connected to by
39
xml.signal_autoconnect.
44
if i.startswith("on_"):
45
handlers[i] = getattr(self, i)
46
self.xml.signal_autoconnect(handlers)
48
def __getattr__(self, name):
49
"""If self doesn't have the attribute, check self.xml.
51
If self.xml does have the attribute, wrap it in a GtkAttributesFacade
52
instance, cache it in self, and return it.
55
obj = self.xml.get_widget(name)
57
obj = GtkAttributesFacade(obj)
58
setattr(self, name, obj)
60
raise AttributeError("%s instance has no attribute '%s'" %
61
(self.__class__.__name__, name))
63
def on_quit_activate(self, *args):
64
"""Ignore args and call gtk.mainquit()."""