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 <klauer@users.noreply.github.com>
This commit is contained in:
Hugo Slepicka 2020-02-21 13:47:09 -08:00 committed by GitHub
parent dec170ed24
commit c90fb9413c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 209 additions and 65 deletions

View File

@ -18,7 +18,7 @@ from PyQt5.pyrcc_main import processResourceFile
MODULE_NAME = "ads"
SRC_PATH = "PyQtAds"
REQUIRE_PYQT = True
if "--conda-recipe" in sys.argv:
REQUIRE_PYQT = False
@ -40,7 +40,7 @@ class HostPythonConfiguration(object):
else:
self.data_dir = sys.prefix + '/share'
self.lib_dir = sys.prefix + '/lib'
class TargetQtConfiguration(object):
def __init__(self, qmake):
@ -63,12 +63,12 @@ class TargetQtConfiguration(object):
setattr(self, name, value)
pipe.close()
class build_ext(sipdistutils.build_ext):
description = "Builds the " + MODULE_NAME + " module."
user_options = sipdistutils.build_ext.user_options + [
('qmake-bin=', None, "Path to qmake binary"),
('sip-bin=', None, "Path to sip binary"),
@ -78,7 +78,7 @@ class build_ext(sipdistutils.build_ext):
('sip-dir=', None, "Path to module's SIP files"),
('inc-dir=', None, "Path to module's include files")
]
def initialize_options (self):
super().initialize_options()
self.qmake_bin = 'qmake'
@ -92,16 +92,16 @@ class build_ext(sipdistutils.build_ext):
self.inc_dir = None
self.pyconfig = HostPythonConfiguration()
self.qtconfig = TargetQtConfiguration(self.qmake_bin)
self.config = sipconfig.Configuration()
self.config = sipconfig.Configuration()
self.config.default_mod_dir = ("/usr/local/lib/python%i.%i/dist-packages" %
(sys.version_info.major, sys.version_info.minor))
def finalize_options (self):
super().finalize_options()
if not self.qt_include_dir:
self.qt_include_dir = self.qtconfig.QT_INSTALL_HEADERS
if not self.qt_libinfix:
try:
with open(os.path.join(self.qtconfig.QT_INSTALL_PREFIX, 'mkspecs', 'qconfig.pri'), 'r') as f:
@ -113,16 +113,16 @@ class build_ext(sipdistutils.build_ext):
if not self.pyqt_sip_dir:
self.pyqt_sip_dir = os.path.join(self.pyconfig.data_dir, 'sip', 'PyQt5')
if not self.pyqt_sip_flags:
self.pyqt_sip_flags = PYQT_CONFIGURATION.get('sip_flags', '')
if not self.sip_files_dir:
self.sip_files_dir = os.path.abspath(os.path.join(".", "sip"))
if not self.sip_inc_dir:
self.sip_inc_dir = self.pyconfig.venv_inc_dir
if not self.inc_dir:
self.inc_dir = os.path.abspath(os.path.join(".", "src"))
@ -138,12 +138,12 @@ class build_ext(sipdistutils.build_ext):
if not self.pyqt_sip_flags:
raise SystemExit('Could not find PyQt SIP flags. '
'Please specify via --pyqt-sip-flags=')
def _find_sip(self):
"""override _find_sip to allow for manually speficied sip path."""
return self.sip_bin or super()._find_sip()
def _sip_compile(self, sip_bin, source, sbf):
def _sip_compile(self, sip_bin, source, sbf):
cmd = [sip_bin]
if hasattr(self, 'sip_opts'):
cmd += self.sip_opts
@ -157,11 +157,11 @@ class build_ext(sipdistutils.build_ext):
"-c", self._sip_output_dir(),
"-b", sbf,
"-w", "-o"]
cmd += shlex.split(self.pyqt_sip_flags) # use same SIP flags as for PyQt5
cmd.append(source)
self.spawn(cmd)
def swig_sources (self, sources, extension=None):
if not self.extensions:
return
@ -179,7 +179,7 @@ class build_ext(sipdistutils.build_ext):
extension.libraries += ['Qt5Core' + self.qt_libinfix,
'Qt5Gui' + self.qt_libinfix,
'Qt5Widgets' + self.qt_libinfix]
if sys.platform == 'win32':
extension.library_dirs += [self.qtconfig.QT_INSTALL_LIBS,
self.inc_dir, self._sip_output_dir()]
@ -192,30 +192,42 @@ class build_ext(sipdistutils.build_ext):
extension.extra_compile_args += ['-std=c++11']
return super().swig_sources(sources, extension)
def build_extension(self, ext):
cppsources = [source for source in ext.sources if source.endswith(".cpp")]
dir_util.mkpath(self.build_temp, dry_run=self.dry_run)
def get_moc_args(out_file, source):
if sys.platform.startswith('linux'):
return ["moc", "-D", "Q_OS_LINUX=1", "-o", out_file, source]
return ["moc", "-o", out_file, source]
# Run moc on all header files.
for source in cppsources:
# *.cpp -> *.moc
moc_file = os.path.basename(source).replace(".cpp", ".moc")
out_file = os.path.join(self.build_temp, moc_file)
if newer(source, out_file) or self.force:
spawn.spawn(get_moc_args(out_file, source), dry_run=self.dry_run)
header = source.replace(".cpp", ".h")
if os.path.exists(header):
# *.h -> moc_*.cpp
moc_file = "moc_" + os.path.basename(header).replace(".h", ".cpp")
out_file = os.path.join(self.build_temp, moc_file)
if newer(header, out_file) or self.force:
call_arg = ["moc", "-o", out_file, header]
spawn.spawn(call_arg, dry_run=self.dry_run)
spawn.spawn(get_moc_args(out_file, header), dry_run=self.dry_run)
if os.path.getsize(out_file) > 0:
ext.sources.append(out_file)
# Add the temp build directory to include path, for compiler to find
# the created .moc files
ext.include_dirs += [self._sip_output_dir()]
sipdistutils.build_ext.build_extension(self, ext)
@ -253,7 +265,7 @@ ext_modules = [Extension('PyQtAds.QtAds.ads', cpp_sources + sip_sources)]
install_requires = ["PyQt5"]
if sys.platform == 'win32':
install_requires.append("pywin32")
with open('README.md', 'r') as f:
LONG_DESCRIPTION = f.read()

View File

@ -13,14 +13,6 @@ class CDockAreaTabBar : QScrollArea
protected:
virtual void wheelEvent(QWheelEvent* Event);
virtual void mousePressEvent(QMouseEvent* ev);
virtual void mouseReleaseEvent(QMouseEvent* ev);
virtual void mouseMoveEvent(QMouseEvent* ev);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
void startFloating(const QPoint& Offset);
ads::IFloatingWidget* makeAreaFloating(const QPoint& Offset,
ads::eDragState DragState);
ads::eDragState dragState() const;
public:
CDockAreaTabBar(ads::CDockAreaWidget* parent /TransferThis/);
@ -35,6 +27,7 @@ public:
bool isTabOpen(int Index) const;
virtual QSize minimumSizeHint() const;
virtual QSize sizeHint() const;
void elidedChanged(bool elided);
public slots:
void setCurrentIndex(int Index);
@ -54,4 +47,4 @@ signals:
};
%End
%End

View File

@ -11,6 +11,13 @@ class CDockAreaTitleBar : QFrame
#include <DockAreaTitleBar.h>
%End
protected:
virtual void mousePressEvent(QMouseEvent* ev);
virtual void mouseReleaseEvent(QMouseEvent* ev);
virtual void mouseMoveEvent(QMouseEvent* ev);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void contextMenuEvent(QContextMenuEvent *event);
public slots:
void markTabsMenuOutdated();
@ -20,7 +27,10 @@ public:
virtual ~CDockAreaTitleBar();
ads::CDockAreaTabBar* tabBar() const;
QAbstractButton* button(ads::TitleBarButton which) const;
void updateDockWidgetActionsButtons();
virtual void setVisible(bool Visible);
void insertWidget(int index, QWidget *widget /Transfer/ );
int indexOf(QWidget *widget) const;
signals:

View File

@ -42,12 +42,16 @@ public:
int currentIndex() const;
int indexOfFirstOpenDockWidget() const;
ads::CDockWidget* currentDockWidget() const;
void setCurrentDockWidget(ads::CDockWidget* DockWidget /Transfer/);
void setCurrentDockWidget(ads::CDockWidget* DockWidget);
void saveState(QXmlStreamWriter& Stream) const;
ads::CDockWidget::DockWidgetFeatures features() const;
ads::CDockWidget::DockWidgetFeatures features(ads::eBitwiseOperator Mode = ads::BitwiseAnd) const;
QAbstractButton* titleBarButton(ads::TitleBarButton which) const;
virtual void setVisible(bool Visible);
void setAllowedAreas(DockWidgetAreas areas);
DockWidgetAreas allowedAreas() const;
CDockAreaTitleBar* titleBar() const;
public slots:
void setCurrentIndex(int index);
void closeArea();

View File

@ -0,0 +1,26 @@
%If (Qt_5_0_0 -)
namespace ads
{
class CDockComponentsFactory
{
%TypeHeaderCode
#include <DockComponentsFactory.h>
%End
public:
virtual ~CDockComponentsFactory();
virtual CDockWidgetTab* createDockWidgetTab(CDockWidget* DockWidget /Transfer/ ) const;
virtual CDockAreaTabBar* createDockAreaTabBar(CDockAreaWidget* DockArea /Transfer/ ) const;
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea /Transfer/ ) const;
static const CDockComponentsFactory* factory();
static void setFactory(CDockComponentsFactory* Factory);
static void resetDefaultFactory();
};
};
%End

View File

@ -25,11 +25,10 @@ protected:
void dropFloatingWidget(ads::CFloatingDockContainer* FloatingWidget, const QPoint& TargetPos);
void dropWidget(QWidget* widget, const QPoint& TargetPos);
void addDockArea(ads::CDockAreaWidget* DockAreaWidget /Transfer/, ads::DockWidgetArea area = ads::CenterDockWidgetArea);
void removeDockArea(ads::CDockAreaWidget* area /Transfer/);
void removeDockArea(ads::CDockAreaWidget* area /TransferBack/);
void saveState(QXmlStreamWriter& Stream) const;
bool restoreState(CDockingStateReader& Stream, bool Testing);
ads::CDockAreaWidget* lastAddedDockAreaWidget(ads::DockWidgetArea area) const;
bool hasTopLevelDockWidget() const;
ads::CDockWidget* topLevelDockWidget() const;
ads::CDockAreaWidget* topLevelDockArea() const;
QList<ads::CDockWidget*> dockWidgets() const;
@ -88,6 +87,7 @@ public:
* If all dock widgets in a dock area are closed, the dock area will be closed
*/
QList<ads::CDockAreaWidget*> openedDockAreas() const;
bool hasTopLevelDockWidget() const;
/**
* Returns the number of dock areas in this container

View File

@ -143,7 +143,7 @@ public:
enum eConfigFlag
{
ActiveTabHasCloseButton,
ActiveTabHasCloseButton,
DockAreaHasCloseButton,
DockAreaCloseButtonClosesTab,
OpaqueSplitterResize,
@ -152,13 +152,22 @@ public:
TabCloseButtonIsToolButton,
AllTabsHaveCloseButton,
RetainTabSizeWhenCloseButtonHidden,
OpaqueUndocking,
DragPreviewIsDynamic,
DragPreviewShowsContentPixmap,
DragPreviewHasWindowFrame,
DefaultConfig,
DefaultNonOpaqueConfig,
NonOpaqueWithWindowFrame,
OpaqueUndocking,
DragPreviewIsDynamic,
DragPreviewShowsContentPixmap,
DragPreviewHasWindowFrame,
AlwaysShowTabs,
DockAreaHasUndockButton,
DockAreaHasTabsMenuButton,
DockAreaHideDisabledButtons,
DockAreaDynamicTabsMenuButtonVisibility,
FloatingContainerHasWidgetTitle,
FloatingContainerHasWidgetIcon,
DefaultDockAreaButtons,
DefaultBaseConfig,
DefaultOpaqueConfig,
DefaultNonOpaqueConfig,
NonOpaqueWithWindowFrame,
};
typedef QFlags<ads::CDockManager::eConfigFlag> ConfigFlags;
@ -167,6 +176,7 @@ public:
static ads::CDockManager::ConfigFlags configFlags();
static void setConfigFlags(const ads::CDockManager::ConfigFlags Flags);
static void setConfigFlag(ads::CDockManager::eConfigFlag Flag, bool On = true);
static bool testConfigFlag(eConfigFlag Flag);
static ads::CIconProvider& iconProvider();
ads::CDockAreaWidget* addDockWidget(ads::DockWidgetArea area, ads::CDockWidget* Dockwidget /Transfer/,
ads::CDockAreaWidget* DockAreaWidget /Transfer/ = 0);
@ -180,7 +190,7 @@ public:
QMap<QString, ads::CDockWidget*> dockWidgetsMap() const;
const QList<ads::CDockContainerWidget*> dockContainers() const;
const QList<ads::CFloatingDockContainer*> floatingWidgets() const;
virtual unsigned int zOrderIndex() const;
unsigned int zOrderIndex() const;
QByteArray saveState(int version = 1) const;
bool restoreState(const QByteArray &state, int version = 1);
void addPerspective(const QString& UniquePrespectiveName);
@ -206,6 +216,7 @@ signals:
void stateRestored();
void openingPerspective(const QString& PerspectiveName);
void perspectiveOpened(const QString& PerspectiveName);
void floatingWidgetCreated(CFloatingDockContainer* FloatingWidget);
void dockAreaCreated(ads::CDockAreaWidget* DockArea);
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);
void dockWidgetRemoved(ads::CDockWidget* DockWidget);

View File

@ -12,15 +12,16 @@ class CDockWidget : QFrame
%End
protected:
void setDockManager(ads::CDockManager* DockManager /Transfer/);
void setDockArea(ads::CDockAreaWidget* DockArea /Transfer/);
void setToggleViewActionChecked(bool Checked);
void saveState(QXmlStreamWriter& Stream) const;
void flagAsUnassigned();
static void emitTopLevelEventForWidget(ads::CDockWidget* TopLevelDockWidget, bool Floating);
void emitTopLevelChanged(bool Floating);
void setClosedState(bool Closed);
void toggleViewInternal(bool Open);
void setDockManager(ads::CDockManager* DockManager /Transfer/ );
void setDockArea(ads::CDockAreaWidget* DockArea /Transfer/ );
void setToggleViewActionChecked(bool Checked);
void saveState(QXmlStreamWriter& Stream) const;
void flagAsUnassigned();
static void emitTopLevelEventForWidget(ads::CDockWidget* TopLevelDockWidget, bool Floating);
void emitTopLevelChanged(bool Floating);
void setClosedState(bool Closed);
void toggleViewInternal(bool Open);
bool closeDockWidgetInternal(bool ForceClose = false);
public:
enum DockWidgetFeature
@ -77,7 +78,7 @@ public:
QIcon icon() const;
QToolBar* toolBar() const;
QToolBar* createDefaultToolBar();
void setToolBar(QToolBar* ToolBar);
void setToolBar(QToolBar* ToolBar /Transfer/ );
void setToolBarStyle(Qt::ToolButtonStyle Style, ads::CDockWidget::eState State);
Qt::ToolButtonStyle toolBarStyle(ads::CDockWidget::eState State) const;
void setToolBarIconSize(const QSize& IconSize, ads::CDockWidget::eState State);

View File

@ -30,6 +30,7 @@ public:
const QIcon& icon() const;
QString text() const;
void setText(const QString& title);
bool isTitleElided() const;
bool isClosable() const;
virtual bool event(QEvent *e);
@ -43,6 +44,7 @@ signals:
void closeRequested();
void closeOtherTabsRequested();
void moved(const QPoint& GlobalPos);
void elidedChanged(bool elided);
}; // class DockWidgetTab
};
// namespace ads

View File

@ -22,7 +22,7 @@ public:
virtual ~CElidingLabel();
Qt::TextElideMode elideMode() const;
void setElideMode(Qt::TextElideMode mode);
bool isElided() const;
public:
virtual QSize minimumSizeHint() const;
@ -33,6 +33,7 @@ public:
signals:
void clicked();
void doubleClicked();
void elidedChanged(bool elided);
};
};

View File

@ -1,3 +1,6 @@
// NOTE: there is a separate sip/linux/FloatingDockContainer.sip as the base
// class for CFloatingDockContainer changes for Linux.
%Import QtWidgets/QtWidgetsmod.sip
%If (Qt_5_0_0 -)
@ -46,7 +49,6 @@ protected:
virtual void closeEvent(QCloseEvent *event);
virtual void hideEvent(QHideEvent *event);
virtual void showEvent(QShowEvent *event);
virtual bool eventFilter(QObject *watched, QEvent *event);
public:
CFloatingDockContainer(ads::CDockManager* DockManager /TransferThis/);

View File

@ -12,6 +12,10 @@ class CFloatingDragPreview : QWidget, ads::IFloatingWidget
#include <FloatingDragPreview.h>
%End
protected:
virtual void moveEvent(QMoveEvent *event);
virtual void paintEvent(QPaintEvent *e);
CFloatingDragPreview(QWidget* Content /TransferThis/, QWidget* parent /TransferThis/);
public:
CFloatingDragPreview(ads::CDockWidget* Content /TransferThis/ );
@ -21,6 +25,7 @@ public:
virtual bool eventFilter(QObject* watched, QEvent* event);
public: // implements IFloatingWidget
virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size,
ads::eDragState DragState, QWidget* MouseEventHandler);
@ -35,4 +40,4 @@ signals:
};
%End
%End

View File

@ -8,6 +8,7 @@
%Include DockAreaTabBar.sip
%Include DockAreaTitleBar.sip
%Include DockAreaWidget.sip
%Include DockComponentsFactory.sip
%Include DockContainerWidget.sip
%Include DockingStateReader.sip
%Include DockManager.sip
@ -15,9 +16,12 @@
%Include DockSplitter.sip
%Include DockWidgetTab.sip
%Include ElidingLabel.sip
%Include FloatingDockContainer.sip
%Include FloatingDragPreview.sip
%Include IconProvider.sip
%If (Linux)
%Include linux/FloatingDockContainer.sip
%Include linux/FloatingWidgetTitleBar.sip
%End
%End
%If (!Linux)
%Include FloatingDockContainer.sip
%End

View File

@ -49,6 +49,12 @@ namespace ads
IconCount,
};
enum eBitwiseOperator
{
BitwiseAnd,
BitwiseOr
};
};
%End
%End

View File

@ -0,0 +1,67 @@
// NOTE: this is the Linux version, with QDockWidget as the
// CFloatingDockContainer base class.
%Import QtWidgets/QtWidgetsmod.sip
%If (Qt_5_0_0 -)
namespace ads
{
class IFloatingWidget
{
%TypeHeaderCode
#include <FloatingDockContainer.h>
%End
public:
virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size,
ads::eDragState DragState, QWidget* MouseEventHandler) = 0;
virtual void moveFloating() = 0;
virtual void finishDragging() = 0;
};
class CFloatingDockContainer : QDockWidget, ads::IFloatingWidget
{
%TypeHeaderCode
#include <FloatingDockContainer.h>
%End
protected:
virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size,
ads::eDragState DragState, QWidget* MouseEventHandler);
void startDragging(const QPoint& DragStartMousePos, const QSize& Size,
QWidget* MouseEventHandler);
virtual void finishDragging();
void initFloatingGeometry(const QPoint& DragStartMousePos, const QSize& Size);
void moveFloating();
bool restoreState(ads::CDockingStateReader& Stream, bool Testing);
void updateWindowTitle();
protected:
virtual void changeEvent(QEvent *event);
virtual void moveEvent(QMoveEvent *event);
virtual bool event(QEvent *e);
virtual void closeEvent(QCloseEvent *event);
virtual void hideEvent(QHideEvent *event);
virtual void showEvent(QShowEvent *event);
public:
CFloatingDockContainer(ads::CDockManager* DockManager /TransferThis/);
CFloatingDockContainer(ads::CDockAreaWidget* DockArea /TransferThis/);
CFloatingDockContainer(ads::CDockWidget* DockWidget /TransferThis/);
virtual ~CFloatingDockContainer();
ads::CDockContainerWidget* dockContainer() const;
bool isClosable() const;
bool hasTopLevelDockWidget() const;
ads::CDockWidget* topLevelDockWidget() const;
QList<ads::CDockWidget*> dockWidgets() const;
};
};
%End