diff options
author | Johan Dahlin <johan@src.gnome.org> | 2006-07-05 14:52:26 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2006-07-05 14:52:26 +0000 |
commit | 0c54799197712812735ab19401379023792b8829 (patch) | |
tree | e419a819957a975c03321d0a322009ca9669e1b1 /gtk/_lazyutils.py | |
parent | 158516210b4e9a8704dc4abdf859e500b6470b97 (diff) | |
download | pygtk-0c54799197712812735ab19401379023792b8829.tar.gz |
Add infrastructure to handle lazy loading. Move keysyms to be loaded
* gtk/Makefile.am:
* gtk/__init__.py:
* gtk/_lazyutils.py:
* tests/Makefile.am:
* tests/test_api.py:
Add infrastructure to handle lazy loading.
Move keysyms to be loaded lazily.
Add API tests to make sure keysyms works.
Diffstat (limited to 'gtk/_lazyutils.py')
-rw-r--r-- | gtk/_lazyutils.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/gtk/_lazyutils.py b/gtk/_lazyutils.py new file mode 100644 index 00000000..f43a4df1 --- /dev/null +++ b/gtk/_lazyutils.py @@ -0,0 +1,33 @@ +# -*- Mode: Python; py-indent-offset: 4 -*- +# pygtk - Python bindings for the GTK toolkit. +# Copyright (C) 2006 Johan Dahlin +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA + +# Private to PyGTK, do not use in applications + +import sys + +class LazyModule(object): + def __init__(self, name, locals): + self._name = name + self._locals = locals + self._modname = '%s.%s' % (self._locals.get('__name__'), self._name) + + def __getattr__(self, attr): + module = __import__(self._name, self._locals, {}, ' ') + sys.modules[self._modname] = module + return getattr(module, attr) |