|
30 | 30 | # Redistribution and use is allowed according to the terms of the BSD license.
|
31 | 31 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
32 | 32 |
|
| 33 | +import argparse |
| 34 | + |
| 35 | +parser = argparse.ArgumentParser(description='Find the PyQt on the system.') |
| 36 | +parser.add_argument('--version', type=int, help='The major pyqt version to find (4 or 5, Default: 4)', default=4) |
| 37 | + |
| 38 | +version = parser.parse_args().version |
| 39 | + |
| 40 | +if version == 4: |
| 41 | + from PyQt4 import QtCore |
| 42 | + pyqt_sip_dir = 'PyQt4' |
| 43 | +elif version == 5: |
| 44 | + from PyQt5 import QtCore |
| 45 | + pyqt_sip_dir = 'PyQt5' |
| 46 | +else: |
| 47 | + parser.print_help() |
| 48 | + exit(1) |
| 49 | + |
33 | 50 | try:
|
34 |
| - import PyQt4.pyqtconfig |
35 |
| - pyqtcfg = PyQt4.pyqtconfig.Configuration() |
36 |
| -except ImportError: |
37 |
| - import PyQt4.QtCore |
38 | 51 | import sipconfig # won't work for SIP v5
|
39 | 52 | import os.path
|
40 | 53 | cfg = sipconfig.Configuration()
|
41 | 54 | sip_dir = cfg.default_sip_dir
|
42 |
| - for p in (os.path.join(sip_dir, "PyQt4"), sip_dir): |
| 55 | + for p in (os.path.join(sip_dir, pyqt_sip_dir), sip_dir): |
43 | 56 | if os.path.exists(os.path.join(p, "QtCore", "QtCoremod.sip")):
|
44 | 57 | sip_dir = p
|
45 | 58 | break
|
46 | 59 | cfg = {
|
47 |
| - 'pyqt_version': PyQt4.QtCore.PYQT_VERSION, |
48 |
| - 'pyqt_version_str': PyQt4.QtCore.PYQT_VERSION_STR, |
49 |
| - 'pyqt_sip_flags': PyQt4.QtCore.PYQT_CONFIGURATION['sip_flags'], |
| 60 | + 'pyqt_version': QtCore.PYQT_VERSION, |
| 61 | + 'pyqt_version_str': QtCore.PYQT_VERSION_STR, |
| 62 | + 'pyqt_sip_flags': QtCore.PYQT_CONFIGURATION['sip_flags'], |
50 | 63 | 'pyqt_mod_dir': cfg.default_mod_dir,
|
51 | 64 | 'pyqt_sip_dir': sip_dir,
|
52 | 65 | 'pyqt_bin_dir': cfg.default_bin_dir,
|
53 | 66 | }
|
54 | 67 | pyqtcfg = sipconfig.Configuration([cfg])
|
| 68 | +except AttributeError: |
| 69 | + # Legacy code |
| 70 | + import PyQt4.pyqtconfig |
| 71 | + pyqtcfg = PyQt4.pyqtconfig.Configuration() |
55 | 72 |
|
56 | 73 | print("pyqt_version:%06.0x" % pyqtcfg.pyqt_version)
|
57 | 74 | print("pyqt_version_num:%d" % pyqtcfg.pyqt_version)
|
|
0 commit comments