Merge pull request #1385 from davvid/bindir
[git-cola.git] / qtpy / enums_compat.py
blob89a7d114dba097301ff46d8bcbb58c46ed98bfe9
1 # Copyright © 2009- The Spyder Development Team
2 # Copyright © 2012- University of North Carolina at Chapel Hill
3 # Luke Campagnola ('luke.campagnola@%s.com' % 'gmail')
4 # Ogi Moore ('ognyan.moore@%s.com' % 'gmail')
5 # KIU Shueng Chuan ('nixchuan@%s.com' % 'gmail')
6 # Licensed under the terms of the MIT License
8 """
9 Compatibility functions for scoped and unscoped enum access.
10 """
12 from . import PYQT6
14 if PYQT6:
15 import enum
17 from . import sip
19 def promote_enums(module):
20 """
21 Search enums in the given module and allow unscoped access.
23 Taken from:
24 https://github.com/pyqtgraph/pyqtgraph/blob/pyqtgraph-0.12.1/pyqtgraph/Qt.py#L331-L377
25 and adapted to also copy enum values aliased under different names.
27 """
28 class_names = [name for name in dir(module) if name.startswith("Q")]
29 for class_name in class_names:
30 klass = getattr(module, class_name)
31 if not isinstance(klass, sip.wrappertype):
32 continue
33 attrib_names = [name for name in dir(klass) if name[0].isupper()]
34 for attrib_name in attrib_names:
35 attrib = getattr(klass, attrib_name)
36 if not isinstance(attrib, enum.EnumMeta):
37 continue
38 for name, value in attrib.__members__.items():
39 setattr(klass, name, value)