-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathproject.py
104 lines (89 loc) · 3.58 KB
/
project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""The build configuration file for PyQt-Qwt, used by sip."""
import os
from os.path import abspath, join
from sipbuild import Option
from pyqtbuild import PyQtBindings, PyQtProject
def read_define(filename, define):
""" Read the value of a #define from a file. filename is the name of the
file. define is the name of the #define. None is returned if there was no
such #define.
"""
f = open(filename)
for l in f:
wl = l.split()
if len(wl) >= 3 and wl[0] == "#define" and wl[1] == define:
# Take account of embedded spaces.
value = ' '.join(wl[2:])[1:-1]
break
else:
value = None
f.close()
return value
class QwtProject(PyQtProject):
"""The Qwt Project class."""
def __init__(self):
super().__init__()
self.bindings_factories = [QwtBindings]
#def update(self, tool):
# """Allows SIP to find PyQt5 .sip files."""
# super().update(tool)
# self.sip_include_dirs.append(join(PyQt5.__path__[0], 'bindings'))
class QwtBindings(PyQtBindings):
"""The Qwt Bindings class."""
def __init__(self, project):
super().__init__(project, name='Qwt')
def get_options(self):
"""Our custom options that a user can pass to sip-build."""
options = super().get_options()
options += [
Option('qwt_incdir',
help='the directory containing the Qwt header file',
metavar='DIR'),
Option('qwt_featuresdir',
help='the directory containing the qwt.prf features file',
metavar='DIR'),
Option('qwt_libdir',
help='the directory containing the Qwt library',
metavar='DIR'),
Option('qwt_lib',
help='the Qwt library',
metavar='LIB',
default='qwt'),
]
return options
def apply_user_defaults(self, tool):
"""Apply values from user-configurable options."""
project = self.project
qt6 = (project.builder.qt_version >= 0x060000)
# Set the name of the .sip file now that we know the Qt version number.
if qt6:
self.sip_file = 'Qwt_Qt6.sip'
self.builder_settings.append('QT += widgets')
self.builder_settings.append('QT += openglwidgets')
self.builder_settings.append('QT += svg')
print("Qt6")
else:
self.sip_file = 'Qwt_Qt5.sip'
self.builder_settings.append('QT += widgets')
self.builder_settings.append('QT += opengl')
self.builder_settings.append('QT += svg')
if self.qwt_incdir is not None:
self.include_dirs.append(self.qwt_incdir)
if self.qwt_featuresdir is not None:
os.environ['QMAKEFEATURES'] = abspath(self.qsci_features_dir)
if self.qwt_libdir is not None:
self.library_dirs.append(self.qwt_libdir)
if self.qwt_lib is not None:
self.libraries.append(self.qwt_lib)
self.define_macros.append('QWT_PYTHON_WRAPPER')
# Add Qwt version tag. Used for Timeline
qwtglobal = os.path.join(self.qwt_incdir, '', 'qwt_global.h')
qwt_version = read_define(qwtglobal, 'QWT_VERSION_STR')
if qwt_version is None:
print("The Qwt version number could not be determined by "
"reading %s." % qwtglobal)
tag = "Qwt_"+qwt_version.replace('.','_')
#tag = "Qwt_6_1_5"
self.tags.append(tag)
print(tag)
super().apply_user_defaults(tool)