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 | |
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.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | gtk/Makefile.am | 9 | ||||
-rw-r--r-- | gtk/__init__.py | 10 | ||||
-rw-r--r-- | gtk/_lazyutils.py | 33 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/test_api.py | 8 |
6 files changed, 64 insertions, 8 deletions
@@ -2,6 +2,17 @@ * 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. + +2006-07-05 Johan Dahlin <jdahlin@async.com.br> + + * gtk/Makefile.am: + * gtk/__init__.py: * gtk/deprecation.py: Move deprecation related classes to a separate python file diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 7f233c06..64f31d73 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -20,10 +20,11 @@ pygtkexec_LTLIBRARIES = # gtk python scripts pygtkdir = $(pkgpythondir)/gtk -pygtk_PYTHON = \ - __init__.py \ - compat.py \ - deprecation.py \ +pygtk_PYTHON = \ + __init__.py \ + _lazyutils.py \ + compat.py \ + deprecation.py \ keysyms.py # gtk headers diff --git a/gtk/__init__.py b/gtk/__init__.py index b880c8ca..853e9b87 100644 --- a/gtk/__init__.py +++ b/gtk/__init__.py @@ -22,7 +22,7 @@ import os import sys -from types import ModuleType as _module +from types import ModuleType # this can go when things are a little further along try: @@ -40,11 +40,12 @@ if not hasattr(sys, 'argv'): import gobject as _gobject from gtk._gtk import * +from gtk._lazyutils import LazyModule from gtk.deprecation import _Deprecated, _DeprecatedConstant -from gtk import keysyms - import gdk +keysyms = LazyModule('keysyms', locals()) + def _init(): import sys @@ -64,6 +65,7 @@ def _init(): # install the default log handlers add_log_handlers() + gdk.INPUT_READ = _gobject.IO_IN | _gobject.IO_HUP | _gobject.IO_ERR gdk.INPUT_WRITE = _gobject.IO_OUT | _gobject.IO_HUP gdk.INPUT_EXCEPTION = _gobject.IO_PRI @@ -98,6 +100,6 @@ FALSE = _DeprecatedConstant(False, 'gtk.FALSE', 'False') # Can't figure out how to deprecate gdk.Warning gdk.Warning = Warning -del _Deprecated, _DeprecatedConstant, _gobject, _module, +del _Deprecated, _DeprecatedConstant, _gobject _init() 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) diff --git a/tests/Makefile.am b/tests/Makefile.am index 56dd262d..a10bdd68 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,7 @@ EXTRA_DIST = $(tests) common.py runtests.py testmodule.py leak.glade tests = \ + test_api.py \ test_glade.py \ test_conversion.py \ test_dialog.py \ diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 00000000..9b715cd5 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,8 @@ +import unittest + +from common import gtk + +class APITest(unittest.TestCase): + def testKeysyms(self): + self.failUnless(hasattr(gtk.keysyms, 'Escape')) + self.assertEqual(gtk.keysyms.Escape, 0xFF1B) |