| 1 | # Set the version of Pmw to use for the demonstrations based on the |
| 2 | # directory name. |
| 3 | |
| 4 | import imp |
| 5 | import os |
| 6 | import string |
| 7 | |
| 8 | def expandLinks(path): |
| 9 | if not os.path.isabs(path): |
| 10 | path = os.path.join(os.getcwd(), path) |
| 11 | while 1: |
| 12 | if not os.path.islink(path): |
| 13 | break |
| 14 | dir = os.path.dirname(path) |
| 15 | path = os.path.join(dir, os.readlink(path)) |
| 16 | |
| 17 | return path |
| 18 | |
| 19 | def setPmwVersion(): |
| 20 | file = imp.find_module(__name__)[1] |
| 21 | file = os.path.normpath(file) |
| 22 | file = expandLinks(file) |
| 23 | |
| 24 | dir = os.path.dirname(file) |
| 25 | dir = expandLinks(dir) |
| 26 | dir = os.path.dirname(dir) |
| 27 | dir = expandLinks(dir) |
| 28 | dir = os.path.basename(dir) |
| 29 | |
| 30 | version = string.replace(dir[4:], '_', '.') |
| 31 | import Pmw |
| 32 | if version in Pmw.installedversions(): |
| 33 | Pmw.setversion(version) |
| 34 | else: |
| 35 | print 'No such Pmw version', `version` + '.', |
| 36 | print 'Using default version', `Pmw.version()` |