mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-12 08:10:25 +08:00
Update Python Bindings again (#262)
* Update Python bindings * Add X11Extras to setup.py for Linux builds * Update Python Bindings
This commit is contained in:
parent
5fad43377b
commit
81afe2d3cb
24
demo/demo.py
24
demo/demo.py
@ -65,7 +65,7 @@ def append_feature_string_to_window_title(dock_widget: QtAds.CDockWidget):
|
|||||||
def svg_icon(filename: str):
|
def svg_icon(filename: str):
|
||||||
'''Helper function to create an SVG icon'''
|
'''Helper function to create an SVG icon'''
|
||||||
# This is a workaround, because because in item views SVG icons are not
|
# This is a workaround, because because in item views SVG icons are not
|
||||||
# properly scaled an look blurry or pixelate
|
# properly scaled and look blurry or pixelate
|
||||||
icon = QIcon(filename)
|
icon = QIcon(filename)
|
||||||
icon.addPixmap(icon.pixmap(92))
|
icon.addPixmap(icon.pixmap(92))
|
||||||
return icon
|
return icon
|
||||||
@ -104,6 +104,8 @@ class MainWindow(MainWindowUI, MainWindowBase):
|
|||||||
self.perspective_list_action = None
|
self.perspective_list_action = None
|
||||||
self.perspective_combo_box = None
|
self.perspective_combo_box = None
|
||||||
self.dock_manager = None
|
self.dock_manager = None
|
||||||
|
self.window_title_test_dock_widget = None
|
||||||
|
self.last_docked_editor = None
|
||||||
|
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.create_actions()
|
self.create_actions()
|
||||||
@ -184,6 +186,7 @@ class MainWindow(MainWindowUI, MainWindowBase):
|
|||||||
# special_dock_area.setAllowedAreas(QtAds.LeftDockWidgetArea | QtAds.RightDockWidgetArea) # just for testing
|
# special_dock_area.setAllowedAreas(QtAds.LeftDockWidgetArea | QtAds.RightDockWidgetArea) # just for testing
|
||||||
|
|
||||||
dock_widget = self.create_long_text_label_dock_widget()
|
dock_widget = self.create_long_text_label_dock_widget()
|
||||||
|
self.window_title_test_dock_widget = dock_widget
|
||||||
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetFocusable, False)
|
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetFocusable, False)
|
||||||
self.dock_manager.addDockWidget(QtAds.LeftDockWidgetArea, dock_widget)
|
self.dock_manager.addDockWidget(QtAds.LeftDockWidgetArea, dock_widget)
|
||||||
file_system_widget = self.create_file_system_tree_dock_widget()
|
file_system_widget = self.create_file_system_tree_dock_widget()
|
||||||
@ -354,7 +357,6 @@ class MainWindow(MainWindowUI, MainWindowBase):
|
|||||||
def create_editor(self):
|
def create_editor(self):
|
||||||
sender = self.sender()
|
sender = self.sender()
|
||||||
floating = sender.property("Floating")
|
floating = sender.property("Floating")
|
||||||
print("Floating:", floating)
|
|
||||||
dock_widget = self.create_editor_widget()
|
dock_widget = self.create_editor_widget()
|
||||||
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetDeleteOnClose, True)
|
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetDeleteOnClose, True)
|
||||||
dock_widget.closeRequested.connect(self.on_editor_close_requested)
|
dock_widget.closeRequested.connect(self.on_editor_close_requested)
|
||||||
@ -363,7 +365,13 @@ class MainWindow(MainWindowUI, MainWindowBase):
|
|||||||
floating_widget = self.dock_manager.addDockWidgetFloating(dock_widget)
|
floating_widget = self.dock_manager.addDockWidgetFloating(dock_widget)
|
||||||
floating_widget.move(QPoint(20, 20))
|
floating_widget.move(QPoint(20, 20))
|
||||||
else:
|
else:
|
||||||
self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
|
editor_area = self.last_docked_editor.dockAreaWidget() if self.last_docked_editor is not None else None
|
||||||
|
if editor_area is not None:
|
||||||
|
self.dock_manager.setConfigFlag(QtAds.CDockManager.EqualSplitOnInsertion, True)
|
||||||
|
self.dock_manager.addDockWidget(QtAds.RightDockWidgetArea, dock_widget, editor_area)
|
||||||
|
else:
|
||||||
|
self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
|
||||||
|
self.last_docked_editor = dock_widget
|
||||||
|
|
||||||
def on_editor_close_requested(self):
|
def on_editor_close_requested(self):
|
||||||
dock_widget = self.sender()
|
dock_widget = self.sender()
|
||||||
@ -382,6 +390,16 @@ class MainWindow(MainWindowUI, MainWindowBase):
|
|||||||
dialog = CStatusDialog(self.dock_manager)
|
dialog = CStatusDialog(self.dock_manager)
|
||||||
dialog.exec_()
|
dialog.exec_()
|
||||||
|
|
||||||
|
|
||||||
|
def toggle_dock_widget_window_title(self):
|
||||||
|
title = self.window_title_test_dock_widget.windowTitle()
|
||||||
|
i = title.find(" (Test) ")
|
||||||
|
if i == -1:
|
||||||
|
title += " (Test) "
|
||||||
|
else:
|
||||||
|
title = title[i]
|
||||||
|
self.window_title_test_dock_widget.setWindowTitle(title)
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
'''
|
'''
|
||||||
Saves the dock manager state and the main window geometry
|
Saves the dock manager state and the main window geometry
|
||||||
|
@ -2,16 +2,28 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PyQt5 import uic
|
from PyQt5 import uic
|
||||||
from PyQt5.QtCore import Qt, QTimer, QDir
|
from PyQt5.QtCore import Qt, QTimer, QDir, QSignalBlocker
|
||||||
from PyQt5.QtGui import QCloseEvent
|
from PyQt5.QtGui import QCloseEvent, QIcon
|
||||||
from PyQt5.QtWidgets import (QApplication, QLabel, QCalendarWidget, QFrame, QTreeView,
|
from PyQt5.QtWidgets import (QApplication, QLabel, QCalendarWidget, QFrame, QTreeView,
|
||||||
QTableWidget, QFileSystemModel)
|
QTableWidget, QFileSystemModel, QPlainTextEdit, QToolBar,
|
||||||
|
QWidgetAction, QComboBox, QAction, QSizePolicy, QInputDialog)
|
||||||
|
|
||||||
from PyQtAds import QtAds
|
from PyQtAds import QtAds
|
||||||
|
|
||||||
UI_FILE = os.path.join(os.path.dirname(__file__), 'mainwindow.ui')
|
UI_FILE = os.path.join(os.path.dirname(__file__), 'mainwindow.ui')
|
||||||
MainWindowUI, MainWindowBase = uic.loadUiType(UI_FILE)
|
MainWindowUI, MainWindowBase = uic.loadUiType(UI_FILE)
|
||||||
|
|
||||||
|
import demo_rc # pyrcc5 demo\demo.qrc -o examples\centralWidget\demo_rc.py
|
||||||
|
|
||||||
|
|
||||||
|
def svg_icon(filename: str):
|
||||||
|
'''Helper function to create an SVG icon'''
|
||||||
|
# This is a workaround, because because in item views SVG icons are not
|
||||||
|
# properly scaled and look blurry or pixelate
|
||||||
|
icon = QIcon(filename)
|
||||||
|
icon.addPixmap(icon.pixmap(92))
|
||||||
|
return icon
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(MainWindowUI, MainWindowBase):
|
class MainWindow(MainWindowUI, MainWindowBase):
|
||||||
|
|
||||||
@ -22,12 +34,14 @@ class MainWindow(MainWindowUI, MainWindowBase):
|
|||||||
|
|
||||||
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.OpaqueSplitterResize, True)
|
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.OpaqueSplitterResize, True)
|
||||||
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.XmlCompressionEnabled, False)
|
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.XmlCompressionEnabled, False)
|
||||||
|
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.FocusHighlighting, True)
|
||||||
self.dock_manager = QtAds.CDockManager(self)
|
self.dock_manager = QtAds.CDockManager(self)
|
||||||
|
|
||||||
# Set central widget
|
# Set central widget
|
||||||
calendar = QCalendarWidget()
|
text_edit = QPlainTextEdit()
|
||||||
|
text_edit.setPlaceholderText("This is the central editor. Enter your text here.")
|
||||||
central_dock_widget = QtAds.CDockWidget("CentralWidget")
|
central_dock_widget = QtAds.CDockWidget("CentralWidget")
|
||||||
central_dock_widget.setWidget(calendar)
|
central_dock_widget.setWidget(text_edit)
|
||||||
central_dock_area = self.dock_manager.setCentralWidget(central_dock_widget)
|
central_dock_area = self.dock_manager.setCentralWidget(central_dock_widget)
|
||||||
central_dock_area.setAllowedAreas(QtAds.DockWidgetArea.OuterDockAreas)
|
central_dock_area.setAllowedAreas(QtAds.DockWidgetArea.OuterDockAreas)
|
||||||
|
|
||||||
@ -65,7 +79,33 @@ class MainWindow(MainWindowUI, MainWindowBase):
|
|||||||
properties_dock_widget.setMinimumSize(200,150)
|
properties_dock_widget.setMinimumSize(200,150)
|
||||||
self.dock_manager.addDockWidget(QtAds.DockWidgetArea.RightDockWidgetArea, properties_dock_widget, central_dock_area)
|
self.dock_manager.addDockWidget(QtAds.DockWidgetArea.RightDockWidgetArea, properties_dock_widget, central_dock_area)
|
||||||
self.menuView.addAction(properties_dock_widget.toggleViewAction())
|
self.menuView.addAction(properties_dock_widget.toggleViewAction())
|
||||||
|
|
||||||
|
self.create_perspective_ui()
|
||||||
|
|
||||||
|
def create_perspective_ui(self):
|
||||||
|
save_perspective_action = QAction("Create Perspective", self)
|
||||||
|
save_perspective_action.setIcon(svg_icon(":/adsdemo/images/picture_in_picture.svg"))
|
||||||
|
save_perspective_action.triggered.connect(self.save_perspective)
|
||||||
|
perspective_list_action = QWidgetAction(self)
|
||||||
|
self.perspective_combobox = QComboBox(self)
|
||||||
|
self.perspective_combobox.setSizeAdjustPolicy(QComboBox.AdjustToContents)
|
||||||
|
self.perspective_combobox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
|
||||||
|
self.perspective_combobox.activated[str].connect(self.dock_manager.openPerspective)
|
||||||
|
perspective_list_action.setDefaultWidget(self.perspective_combobox)
|
||||||
|
self.toolBar.addSeparator()
|
||||||
|
self.toolBar.addAction(perspective_list_action)
|
||||||
|
self.toolBar.addAction(save_perspective_action)
|
||||||
|
|
||||||
|
def save_perspective(self):
|
||||||
|
perspective_name, ok = QInputDialog.getText(self, "Save Perspective", "Enter Unique name:")
|
||||||
|
if not ok or not perspective_name:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.dock_manager.addPerspective(perspective_name)
|
||||||
|
blocker = QSignalBlocker(self.perspective_combobox)
|
||||||
|
self.perspective_combobox.clear()
|
||||||
|
self.perspective_combobox.addItems(self.dock_manager.perspectiveNames())
|
||||||
|
self.perspective_combobox.setCurrentText(perspective_name)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
@ -20,6 +20,7 @@ public:
|
|||||||
|
|
||||||
void notifyWidgetOrAreaRelocation(QWidget* RelocatedWidget);
|
void notifyWidgetOrAreaRelocation(QWidget* RelocatedWidget);
|
||||||
void notifyFloatingWidgetDrop(ads::CFloatingDockContainer* FloatingWidget);
|
void notifyFloatingWidgetDrop(ads::CFloatingDockContainer* FloatingWidget);
|
||||||
|
ads::CDockWidget* focusedDockWidget() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setDockWidgetFocused(ads::CDockWidget* focusedNow);
|
void setDockWidgetFocused(ads::CDockWidget* focusedNow);
|
||||||
|
@ -135,6 +135,7 @@ protected:
|
|||||||
ads::CDockOverlay* dockAreaOverlay() const;
|
ads::CDockOverlay* dockAreaOverlay() const;
|
||||||
void notifyWidgetOrAreaRelocation(QWidget* RelocatedWidget);
|
void notifyWidgetOrAreaRelocation(QWidget* RelocatedWidget);
|
||||||
void notifyFloatingWidgetDrop(ads::CFloatingDockContainer* FloatingWidget);
|
void notifyFloatingWidgetDrop(ads::CFloatingDockContainer* FloatingWidget);
|
||||||
|
ads::CDockWidget* focusedDockWidget() const;
|
||||||
|
|
||||||
virtual void showEvent(QShowEvent *event);
|
virtual void showEvent(QShowEvent *event);
|
||||||
|
|
||||||
@ -230,6 +231,7 @@ signals:
|
|||||||
void perspectiveOpened(const QString& PerspectiveName);
|
void perspectiveOpened(const QString& PerspectiveName);
|
||||||
void floatingWidgetCreated(ads::CFloatingDockContainer*);
|
void floatingWidgetCreated(ads::CFloatingDockContainer*);
|
||||||
void dockAreaCreated(ads::CDockAreaWidget*);
|
void dockAreaCreated(ads::CDockAreaWidget*);
|
||||||
|
void dockWidgetAdded(ads::CDockWidget* DockWidget);
|
||||||
void dockWidgetAboutToBeRemoved(ads::CDockWidget*);
|
void dockWidgetAboutToBeRemoved(ads::CDockWidget*);
|
||||||
void dockWidgetRemoved(ads::CDockWidget*);
|
void dockWidgetRemoved(ads::CDockWidget*);
|
||||||
void focusedDockWidgetChanged(ads::CDockWidget*, ads::CDockWidget*);
|
void focusedDockWidgetChanged(ads::CDockWidget*, ads::CDockWidget*);
|
||||||
|
Loading…
Reference in New Issue
Block a user