Skip to content

Commit c90fb94

Browse files
hhslepickaklauer
andauthored
FIX: Update Python SIP bindings 3.2.1 & Linux Crash (#126)
* (Python) WIP: attempt to update to 3.2.0 * (Python) MAINT: move demo.py to demo/ to avoid PyQtAds import issue * (Python) STY: remove trailing whitespace * (Python) Missing/incorrect /Transfer/ annotations * (Python) n-elie's fix for setup.py moc generation * (Python) FIX: Q_OS_LINUX is not defined by default with moc * (Python) FIX: split FloatingDockContainer.sip to be platform-specific %If (Platform) blocks around the class definition in FloatingDockContainer.sip did not seem to work. Co-authored-by: K Lauer <[email protected]>
1 parent dec170e commit c90fb94

16 files changed

+209
-65
lines changed

demo.py renamed to demo/demo.py

File renamed without changes.

setup.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
MODULE_NAME = "ads"
2020
SRC_PATH = "PyQtAds"
21-
21+
2222
REQUIRE_PYQT = True
2323
if "--conda-recipe" in sys.argv:
2424
REQUIRE_PYQT = False
@@ -40,7 +40,7 @@ def __init__(self):
4040
else:
4141
self.data_dir = sys.prefix + '/share'
4242
self.lib_dir = sys.prefix + '/lib'
43-
43+
4444

4545
class TargetQtConfiguration(object):
4646
def __init__(self, qmake):
@@ -63,12 +63,12 @@ def __init__(self, qmake):
6363
setattr(self, name, value)
6464

6565
pipe.close()
66-
66+
6767

6868
class build_ext(sipdistutils.build_ext):
69-
69+
7070
description = "Builds the " + MODULE_NAME + " module."
71-
71+
7272
user_options = sipdistutils.build_ext.user_options + [
7373
('qmake-bin=', None, "Path to qmake binary"),
7474
('sip-bin=', None, "Path to sip binary"),
@@ -78,7 +78,7 @@ class build_ext(sipdistutils.build_ext):
7878
('sip-dir=', None, "Path to module's SIP files"),
7979
('inc-dir=', None, "Path to module's include files")
8080
]
81-
81+
8282
def initialize_options (self):
8383
super().initialize_options()
8484
self.qmake_bin = 'qmake'
@@ -92,16 +92,16 @@ def initialize_options (self):
9292
self.inc_dir = None
9393
self.pyconfig = HostPythonConfiguration()
9494
self.qtconfig = TargetQtConfiguration(self.qmake_bin)
95-
self.config = sipconfig.Configuration()
95+
self.config = sipconfig.Configuration()
9696
self.config.default_mod_dir = ("/usr/local/lib/python%i.%i/dist-packages" %
9797
(sys.version_info.major, sys.version_info.minor))
98-
98+
9999
def finalize_options (self):
100100
super().finalize_options()
101101

102102
if not self.qt_include_dir:
103103
self.qt_include_dir = self.qtconfig.QT_INSTALL_HEADERS
104-
104+
105105
if not self.qt_libinfix:
106106
try:
107107
with open(os.path.join(self.qtconfig.QT_INSTALL_PREFIX, 'mkspecs', 'qconfig.pri'), 'r') as f:
@@ -113,16 +113,16 @@ def finalize_options (self):
113113

114114
if not self.pyqt_sip_dir:
115115
self.pyqt_sip_dir = os.path.join(self.pyconfig.data_dir, 'sip', 'PyQt5')
116-
116+
117117
if not self.pyqt_sip_flags:
118118
self.pyqt_sip_flags = PYQT_CONFIGURATION.get('sip_flags', '')
119-
119+
120120
if not self.sip_files_dir:
121121
self.sip_files_dir = os.path.abspath(os.path.join(".", "sip"))
122-
122+
123123
if not self.sip_inc_dir:
124124
self.sip_inc_dir = self.pyconfig.venv_inc_dir
125-
125+
126126
if not self.inc_dir:
127127
self.inc_dir = os.path.abspath(os.path.join(".", "src"))
128128

@@ -138,12 +138,12 @@ def finalize_options (self):
138138
if not self.pyqt_sip_flags:
139139
raise SystemExit('Could not find PyQt SIP flags. '
140140
'Please specify via --pyqt-sip-flags=')
141-
141+
142142
def _find_sip(self):
143143
"""override _find_sip to allow for manually speficied sip path."""
144144
return self.sip_bin or super()._find_sip()
145-
146-
def _sip_compile(self, sip_bin, source, sbf):
145+
146+
def _sip_compile(self, sip_bin, source, sbf):
147147
cmd = [sip_bin]
148148
if hasattr(self, 'sip_opts'):
149149
cmd += self.sip_opts
@@ -157,11 +157,11 @@ def _sip_compile(self, sip_bin, source, sbf):
157157
"-c", self._sip_output_dir(),
158158
"-b", sbf,
159159
"-w", "-o"]
160-
160+
161161
cmd += shlex.split(self.pyqt_sip_flags) # use same SIP flags as for PyQt5
162162
cmd.append(source)
163163
self.spawn(cmd)
164-
164+
165165
def swig_sources (self, sources, extension=None):
166166
if not self.extensions:
167167
return
@@ -179,7 +179,7 @@ def swig_sources (self, sources, extension=None):
179179
extension.libraries += ['Qt5Core' + self.qt_libinfix,
180180
'Qt5Gui' + self.qt_libinfix,
181181
'Qt5Widgets' + self.qt_libinfix]
182-
182+
183183
if sys.platform == 'win32':
184184
extension.library_dirs += [self.qtconfig.QT_INSTALL_LIBS,
185185
self.inc_dir, self._sip_output_dir()]
@@ -192,30 +192,42 @@ def swig_sources (self, sources, extension=None):
192192
extension.extra_compile_args += ['-std=c++11']
193193

194194
return super().swig_sources(sources, extension)
195-
195+
196196
def build_extension(self, ext):
197197
cppsources = [source for source in ext.sources if source.endswith(".cpp")]
198-
198+
199199
dir_util.mkpath(self.build_temp, dry_run=self.dry_run)
200200

201+
def get_moc_args(out_file, source):
202+
if sys.platform.startswith('linux'):
203+
return ["moc", "-D", "Q_OS_LINUX=1", "-o", out_file, source]
204+
return ["moc", "-o", out_file, source]
205+
201206
# Run moc on all header files.
202207
for source in cppsources:
208+
# *.cpp -> *.moc
209+
moc_file = os.path.basename(source).replace(".cpp", ".moc")
210+
out_file = os.path.join(self.build_temp, moc_file)
211+
212+
if newer(source, out_file) or self.force:
213+
spawn.spawn(get_moc_args(out_file, source), dry_run=self.dry_run)
214+
203215
header = source.replace(".cpp", ".h")
204216
if os.path.exists(header):
217+
# *.h -> moc_*.cpp
205218
moc_file = "moc_" + os.path.basename(header).replace(".h", ".cpp")
206219
out_file = os.path.join(self.build_temp, moc_file)
207-
220+
208221
if newer(header, out_file) or self.force:
209-
call_arg = ["moc", "-o", out_file, header]
210-
spawn.spawn(call_arg, dry_run=self.dry_run)
211-
222+
spawn.spawn(get_moc_args(out_file, header), dry_run=self.dry_run)
223+
212224
if os.path.getsize(out_file) > 0:
213225
ext.sources.append(out_file)
214226

215227
# Add the temp build directory to include path, for compiler to find
216228
# the created .moc files
217229
ext.include_dirs += [self._sip_output_dir()]
218-
230+
219231
sipdistutils.build_ext.build_extension(self, ext)
220232

221233

@@ -253,7 +265,7 @@ def run(self):
253265
install_requires = ["PyQt5"]
254266
if sys.platform == 'win32':
255267
install_requires.append("pywin32")
256-
268+
257269

258270
with open('README.md', 'r') as f:
259271
LONG_DESCRIPTION = f.read()

sip/DockAreaTabBar.sip

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ class CDockAreaTabBar : QScrollArea
1313

1414
protected:
1515
virtual void wheelEvent(QWheelEvent* Event);
16-
virtual void mousePressEvent(QMouseEvent* ev);
17-
virtual void mouseReleaseEvent(QMouseEvent* ev);
18-
virtual void mouseMoveEvent(QMouseEvent* ev);
19-
virtual void mouseDoubleClickEvent(QMouseEvent *event);
20-
void startFloating(const QPoint& Offset);
21-
ads::IFloatingWidget* makeAreaFloating(const QPoint& Offset,
22-
ads::eDragState DragState);
23-
ads::eDragState dragState() const;
2416

2517
public:
2618
CDockAreaTabBar(ads::CDockAreaWidget* parent /TransferThis/);
@@ -35,6 +27,7 @@ public:
3527
bool isTabOpen(int Index) const;
3628
virtual QSize minimumSizeHint() const;
3729
virtual QSize sizeHint() const;
30+
void elidedChanged(bool elided);
3831

3932
public slots:
4033
void setCurrentIndex(int Index);
@@ -54,4 +47,4 @@ signals:
5447

5548
};
5649

57-
%End
50+
%End

sip/DockAreaTitleBar.sip

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ class CDockAreaTitleBar : QFrame
1111
#include <DockAreaTitleBar.h>
1212
%End
1313

14+
protected:
15+
virtual void mousePressEvent(QMouseEvent* ev);
16+
virtual void mouseReleaseEvent(QMouseEvent* ev);
17+
virtual void mouseMoveEvent(QMouseEvent* ev);
18+
virtual void mouseDoubleClickEvent(QMouseEvent *event);
19+
virtual void contextMenuEvent(QContextMenuEvent *event);
20+
1421
public slots:
1522
void markTabsMenuOutdated();
1623

@@ -20,7 +27,10 @@ public:
2027
virtual ~CDockAreaTitleBar();
2128
ads::CDockAreaTabBar* tabBar() const;
2229
QAbstractButton* button(ads::TitleBarButton which) const;
30+
void updateDockWidgetActionsButtons();
2331
virtual void setVisible(bool Visible);
32+
void insertWidget(int index, QWidget *widget /Transfer/ );
33+
int indexOf(QWidget *widget) const;
2434

2535

2636
signals:

sip/DockAreaWidget.sip

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ public:
4242
int currentIndex() const;
4343
int indexOfFirstOpenDockWidget() const;
4444
ads::CDockWidget* currentDockWidget() const;
45-
void setCurrentDockWidget(ads::CDockWidget* DockWidget /Transfer/);
45+
void setCurrentDockWidget(ads::CDockWidget* DockWidget);
4646
void saveState(QXmlStreamWriter& Stream) const;
47-
ads::CDockWidget::DockWidgetFeatures features() const;
47+
ads::CDockWidget::DockWidgetFeatures features(ads::eBitwiseOperator Mode = ads::BitwiseAnd) const;
4848
QAbstractButton* titleBarButton(ads::TitleBarButton which) const;
4949
virtual void setVisible(bool Visible);
5050

51+
void setAllowedAreas(DockWidgetAreas areas);
52+
DockWidgetAreas allowedAreas() const;
53+
CDockAreaTitleBar* titleBar() const;
54+
5155
public slots:
5256
void setCurrentIndex(int index);
5357
void closeArea();

sip/DockComponentsFactory.sip

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
%If (Qt_5_0_0 -)
2+
3+
namespace ads
4+
{
5+
6+
class CDockComponentsFactory
7+
{
8+
9+
%TypeHeaderCode
10+
#include <DockComponentsFactory.h>
11+
%End
12+
13+
public:
14+
virtual ~CDockComponentsFactory();
15+
virtual CDockWidgetTab* createDockWidgetTab(CDockWidget* DockWidget /Transfer/ ) const;
16+
virtual CDockAreaTabBar* createDockAreaTabBar(CDockAreaWidget* DockArea /Transfer/ ) const;
17+
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea /Transfer/ ) const;
18+
static const CDockComponentsFactory* factory();
19+
static void setFactory(CDockComponentsFactory* Factory);
20+
static void resetDefaultFactory();
21+
22+
};
23+
24+
};
25+
26+
%End

sip/DockContainerWidget.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ protected:
2525
void dropFloatingWidget(ads::CFloatingDockContainer* FloatingWidget, const QPoint& TargetPos);
2626
void dropWidget(QWidget* widget, const QPoint& TargetPos);
2727
void addDockArea(ads::CDockAreaWidget* DockAreaWidget /Transfer/, ads::DockWidgetArea area = ads::CenterDockWidgetArea);
28-
void removeDockArea(ads::CDockAreaWidget* area /Transfer/);
28+
void removeDockArea(ads::CDockAreaWidget* area /TransferBack/);
2929
void saveState(QXmlStreamWriter& Stream) const;
3030
bool restoreState(CDockingStateReader& Stream, bool Testing);
3131
ads::CDockAreaWidget* lastAddedDockAreaWidget(ads::DockWidgetArea area) const;
32-
bool hasTopLevelDockWidget() const;
3332
ads::CDockWidget* topLevelDockWidget() const;
3433
ads::CDockAreaWidget* topLevelDockArea() const;
3534
QList<ads::CDockWidget*> dockWidgets() const;
@@ -88,6 +87,7 @@ public:
8887
* If all dock widgets in a dock area are closed, the dock area will be closed
8988
*/
9089
QList<ads::CDockAreaWidget*> openedDockAreas() const;
90+
bool hasTopLevelDockWidget() const;
9191

9292
/**
9393
* Returns the number of dock areas in this container

sip/DockManager.sip

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public:
143143

144144
enum eConfigFlag
145145
{
146-
ActiveTabHasCloseButton,
146+
ActiveTabHasCloseButton,
147147
DockAreaHasCloseButton,
148148
DockAreaCloseButtonClosesTab,
149149
OpaqueSplitterResize,
@@ -152,13 +152,22 @@ public:
152152
TabCloseButtonIsToolButton,
153153
AllTabsHaveCloseButton,
154154
RetainTabSizeWhenCloseButtonHidden,
155-
OpaqueUndocking,
156-
DragPreviewIsDynamic,
157-
DragPreviewShowsContentPixmap,
158-
DragPreviewHasWindowFrame,
159-
DefaultConfig,
160-
DefaultNonOpaqueConfig,
161-
NonOpaqueWithWindowFrame,
155+
OpaqueUndocking,
156+
DragPreviewIsDynamic,
157+
DragPreviewShowsContentPixmap,
158+
DragPreviewHasWindowFrame,
159+
AlwaysShowTabs,
160+
DockAreaHasUndockButton,
161+
DockAreaHasTabsMenuButton,
162+
DockAreaHideDisabledButtons,
163+
DockAreaDynamicTabsMenuButtonVisibility,
164+
FloatingContainerHasWidgetTitle,
165+
FloatingContainerHasWidgetIcon,
166+
DefaultDockAreaButtons,
167+
DefaultBaseConfig,
168+
DefaultOpaqueConfig,
169+
DefaultNonOpaqueConfig,
170+
NonOpaqueWithWindowFrame,
162171
};
163172
typedef QFlags<ads::CDockManager::eConfigFlag> ConfigFlags;
164173

@@ -167,6 +176,7 @@ public:
167176
static ads::CDockManager::ConfigFlags configFlags();
168177
static void setConfigFlags(const ads::CDockManager::ConfigFlags Flags);
169178
static void setConfigFlag(ads::CDockManager::eConfigFlag Flag, bool On = true);
179+
static bool testConfigFlag(eConfigFlag Flag);
170180
static ads::CIconProvider& iconProvider();
171181
ads::CDockAreaWidget* addDockWidget(ads::DockWidgetArea area, ads::CDockWidget* Dockwidget /Transfer/,
172182
ads::CDockAreaWidget* DockAreaWidget /Transfer/ = 0);
@@ -180,7 +190,7 @@ public:
180190
QMap<QString, ads::CDockWidget*> dockWidgetsMap() const;
181191
const QList<ads::CDockContainerWidget*> dockContainers() const;
182192
const QList<ads::CFloatingDockContainer*> floatingWidgets() const;
183-
virtual unsigned int zOrderIndex() const;
193+
unsigned int zOrderIndex() const;
184194
QByteArray saveState(int version = 1) const;
185195
bool restoreState(const QByteArray &state, int version = 1);
186196
void addPerspective(const QString& UniquePrespectiveName);
@@ -206,6 +216,7 @@ signals:
206216
void stateRestored();
207217
void openingPerspective(const QString& PerspectiveName);
208218
void perspectiveOpened(const QString& PerspectiveName);
219+
void floatingWidgetCreated(CFloatingDockContainer* FloatingWidget);
209220
void dockAreaCreated(ads::CDockAreaWidget* DockArea);
210221
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);
211222
void dockWidgetRemoved(ads::CDockWidget* DockWidget);

0 commit comments

Comments
 (0)