Skip to content

Commit 8cc9cc2

Browse files
hhslepickan-elie
andauthored
Fixed and updated Python integration (#127)
* FIX: Add Q_OS_MACOS flag to moc compiler. * (Python) Demo and example from @n-elie. * FIX: Addressing some sip files that were inconsistent with the header files. * (Python) Addressing comments by @n-elie and switching to use WS_X11 for platform checks. * (Python) Wrap definition of tFloatingWidgetBase to avoid 'Already Defined' error and fix include path for sip/linux/FloatingWidgetTitleBar.sip. * Remove simple.py * Fix case sensitive ui file loading in Linux * Add windows case in get_moc_args * Remove conda recipe Co-authored-by: n-elie <[email protected]>
1 parent c90fb94 commit 8cc9cc2

14 files changed

+427
-350
lines changed

demo/demo.py

Lines changed: 339 additions & 150 deletions
Large diffs are not rendered by default.

example/example.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import datetime
2+
import logging
3+
import os
4+
import sys
5+
6+
from PyQt5 import uic
7+
from PyQt5.QtCore import Qt
8+
from PyQt5.QtWidgets import QApplication, QLabel
9+
10+
from PyQtAds import QtAds
11+
12+
UI_FILE = os.path.join(os.path.dirname(__file__), 'MainWindow.ui')
13+
MainWindowUI, MainWindowBase = uic.loadUiType(UI_FILE)
14+
15+
16+
class MainWindow(MainWindowUI, MainWindowBase):
17+
18+
def __init__(self, parent=None):
19+
super().__init__(parent)
20+
21+
self.setupUi(self)
22+
23+
# Create the dock manager. Because the parent parameter is a QMainWindow
24+
# the dock manager registers itself as the central widget.
25+
self.dock_manager = QtAds.CDockManager(self)
26+
27+
# Create example content label - this can be any application specific
28+
# widget
29+
l = QLabel()
30+
l.setWordWrap(True)
31+
l.setAlignment(Qt.AlignTop | Qt.AlignLeft);
32+
l.setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ")
33+
34+
# Create a dock widget with the title Label 1 and set the created label
35+
# as the dock widget content
36+
dock_widget = QtAds.CDockWidget("Label 1")
37+
dock_widget.setWidget(l)
38+
39+
# Add the toggleViewAction of the dock widget to the menu to give
40+
# the user the possibility to show the dock widget if it has been closed
41+
self.menuView.addAction(dock_widget.toggleViewAction())
42+
43+
# Add the dock widget to the top dock widget area
44+
self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
45+
46+
47+
if __name__ == '__main__':
48+
app = QApplication(sys.argv)
49+
50+
w = MainWindow()
51+
w.show()
52+
app.exec_()

recipes/meta.yaml

Lines changed: 0 additions & 41 deletions
This file was deleted.

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ def build_extension(self, ext):
201201
def get_moc_args(out_file, source):
202202
if sys.platform.startswith('linux'):
203203
return ["moc", "-D", "Q_OS_LINUX=1", "-o", out_file, source]
204+
if sys.platform.startswith('darwin'):
205+
return ["moc", "-D", "Q_OS_MACOS=1", "-o", out_file, source]
206+
if sys.platform.startswith('win'):
207+
return ["moc", "-D", "Q_OS_WIN=1", "-o", out_file, source]
204208
return ["moc", "-o", out_file, source]
205209

206210
# Run moc on all header files.

simple.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

sip/DockManager.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ protected:
134134
ads::CDockOverlay* containerOverlay() const;
135135
ads::CDockOverlay* dockAreaOverlay() const;
136136

137+
virtual void showEvent(QShowEvent *event);
138+
137139
public:
138140
enum eViewMenuInsertionOrder
139141
{

sip/DockOverlay.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public:
2727
ads::DockWidgetArea showOverlay(QWidget* target);
2828
void hideOverlay();
2929
void enableDropPreview(bool Enable);
30+
bool dropPreviewEnabled() const;
3031
QRect dropOverlayRect() const;
3132
virtual bool event(QEvent *e);
3233

@@ -58,6 +59,8 @@ protected:
5859
void setIconOverlayColor(const QColor& Color);
5960
void setIconArrowColor(const QColor& Color);
6061
void setIconShadowColor(const QColor& Color);
62+
virtual void showEvent(QShowEvent* e);
63+
void setAreaWidgets(const QHash<ads::DockWidgetArea, QWidget*>& widgets);
6164

6265
public:
6366
CDockOverlayCross(ads::CDockOverlay* overlay /TransferThis/);

sip/DockWidget.sip

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public:
3030
DockWidgetMovable,
3131
DockWidgetFloatable,
3232
DockWidgetDeleteOnClose,
33-
AllDockWidgetFeatures,
33+
CustomCloseHandling,
34+
DefaultDockWidgetFeatures,
35+
AllDockWidgetFeatures,
3436
NoDockWidgetFeatures
3537
};
3638
typedef QFlags<ads::CDockWidget::DockWidgetFeature> DockWidgetFeatures;
@@ -83,6 +85,9 @@ public:
8385
Qt::ToolButtonStyle toolBarStyle(ads::CDockWidget::eState State) const;
8486
void setToolBarIconSize(const QSize& IconSize, ads::CDockWidget::eState State);
8587
QSize toolBarIconSize(eState State) const;
88+
void setTitleBarActions(QList<QAction*> actions);
89+
virtual QList<QAction*> titleBarActions() const;
90+
8691
void setTabToolTip(const QString &text);
8792

8893
public:
@@ -92,12 +97,14 @@ public slots:
9297
void toggleView(bool Open = true);
9398
void setFloating();
9499
void deleteDockWidget();
100+
void closeDockWidget();
95101

96102
signals:
97103
void viewToggled(bool Open);
98104
void closed();
99105
void titleChanged(const QString& Title);
100106
void topLevelChanged(bool topLevel);
107+
void closeRequested();
101108
void visibilityChanged(bool visible);
102109
void featuresChanged(ads::CDockWidget::DockWidgetFeatures features);
103110
};

sip/DockWidgetTab.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public:
2323
virtual ~CDockWidgetTab();
2424
bool isActiveTab() const;
2525
void setActiveTab(bool active);
26-
ads::CDockWidget* dockWidget() const;
2726
void setDockAreaWidget(ads::CDockAreaWidget* DockArea /Transfer/);
2827
ads::CDockAreaWidget* dockAreaWidget() const;
28+
ads::CDockWidget* dockWidget() const;
2929
void setIcon(const QIcon& Icon);
3030
const QIcon& icon() const;
3131
QString text() const;

sip/FloatingDockContainer.sip

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
%If (Qt_5_0_0 -)
77

8+
%If (WS_X11)
9+
typedef QDockWidget tFloatingWidgetBase;
10+
%End
11+
%If (!WS_X11)
12+
typedef QWidget tFloatingWidgetBase;
13+
%End
14+
815
namespace ads
916
{
1017

@@ -23,7 +30,7 @@ public:
2330
};
2431

2532

26-
class CFloatingDockContainer : QWidget, ads::IFloatingWidget
33+
class CFloatingDockContainer : tFloatingWidgetBase, ads::IFloatingWidget
2734
{
2835

2936
%TypeHeaderCode

0 commit comments

Comments
 (0)