1 |
|
# Orca |
2 |
|
# |
3 |
|
# Copyright 2006 Sun Microsystems Inc. |
4 |
|
# |
5 |
|
# This library is free software; you can redistribute it and/or |
6 |
|
# modify it under the terms of the GNU Library General Public |
7 |
|
# License as published by the Free Software Foundation; either |
8 |
|
# version 2 of the License, or (at your option) any later version. |
9 |
|
# |
10 |
|
# This library is distributed in the hope that it will be useful, |
11 |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 |
|
# Library General Public License for more details. |
14 |
|
# |
15 |
|
# You should have received a copy of the GNU Library General Public |
16 |
|
# License along with this library; if not, write to the |
17 |
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 |
|
# Boston, MA 02111-1307, USA. |
19 |
|
|
20 |
1 |
"""Displays a GUI for the user to quit Orca.""" |
21 |
|
|
22 |
1 |
__id__ = "$Id: orca_glade.py 1496 2006-09-28 17:52:26Z richb $" |
23 |
1 |
__version__ = "$Revision: 1496 $" |
24 |
1 |
__date__ = "$Date: 2006-09-28 13:52:26 -0400 (Thu, 28 Sep 2006) $" |
25 |
1 |
__copyright__ = "Copyright (c) 2005-2006 Sun Microsystems Inc." |
26 |
1 |
__license__ = "LGPL" |
27 |
|
|
28 |
1 |
import os |
29 |
1 |
import sys |
30 |
1 |
import debug |
31 |
1 |
import gettext |
32 |
1 |
import gtk |
33 |
1 |
import gtk.glade |
34 |
1 |
import locale |
35 |
|
|
36 |
2 |
class GladeWrapper: |
37 |
|
""" |
38 |
|
Superclass for glade based applications. Just derive from this |
39 |
|
and your subclass should create methods whose names correspond to |
40 |
|
the signal handlers defined in the glade file. Any other attributes |
41 |
|
in your class will be safely ignored. |
42 |
|
|
43 |
|
This class will give you the ability to do: |
44 |
|
subclass_instance.GtkWindow.method(...) |
45 |
|
subclass_instance.widget_name... |
46 |
1 |
""" |
47 |
|
|
48 |
1 |
def __init__(self, Filename, WindowName): |
49 |
|
# Load glade file. |
50 |
2 |
self.widgets = gtk.glade.XML(Filename, WindowName, gettext.textdomain()) |
51 |
2 |
self.GtkWindow = getattr(self, WindowName) |
52 |
|
|
53 |
2 |
instance_attributes = {} |
54 |
22 |
for attribute in dir(self.__class__): |
55 |
20 |
instance_attributes[attribute] = getattr(self, attribute) |
56 |
2 |
self.widgets.signal_autoconnect(instance_attributes) |
57 |
|
|
58 |
1 |
def __getattr__(self, attribute): # Called when no attribute in __dict__ |
59 |
2 |
widget = self.widgets.get_widget(attribute) |
60 |
2 |
if widget is None: |
61 |
0 |
raise AttributeError("Widget [" + attribute + "] not found") |
62 |
2 |
self.__dict__[attribute] = widget # Add reference to cache. |
63 |
|
|
64 |
2 |
return widget |