1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # pygtk - Python bindings for the GTK+ widget set.
3 # Copyright (C) 1998-2002 James Henstridge
5 # pygtk.py: pygtk version selection code.
7 # This library is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
30 _our_dir
= os
.path
.dirname(os
.path
.abspath(os
.path
.normpath(__file__
)))
31 _pygtk_2_0_dir
= os
.path
.normpath('%s/gtk-2.0' % _our_dir
)
33 _pygtk_dir_pat
= 'gtk-[0-9].[0-9]'
35 _pygtk_required_version
= None
37 def _get_available_versions():
43 if not os
.path
.isdir(dir):
46 # if the dir is a pygtk dir, skip it
47 if fnmatch
.fnmatchcase(os
.path
.basename(dir), _pygtk_dir_pat
):
50 for filename
in glob
.glob(os
.path
.join(dir, _pygtk_dir_pat
)):
51 pathname
= os
.path
.join(dir, filename
)
53 # skip non directories
54 if not os
.path
.isdir(pathname
):
57 # skip empty directories
58 if not os
.listdir(pathname
):
61 if not versions
.has_key(filename
[-3:]):
62 versions
[filename
[-3:]] = pathname
66 if _pygtk_2_0_dir
not in sys
.path
:
67 sys
.path
.insert(0, _pygtk_2_0_dir
)
73 global _pygtk_required_version
75 if _pygtk_required_version
!= None:
76 assert _pygtk_required_version
== version
, \
77 "a different version of gtk was already required"
80 assert not sys
.modules
.has_key('gtk'), \
81 "pygtk.require() must be called before importing gtk"
83 versions
= _get_available_versions()
84 assert versions
.has_key(version
), \
85 "required version '%s' not found on system" % version
87 # remove any pygtk dirs first ...
89 if fnmatch
.fnmatchcase(os
.path
.basename(dir), _pygtk_dir_pat
):
92 # prepend the pygtk path ...
93 sys
.path
.insert(0, versions
[version
])
95 _pygtk_required_version
= version