コード例 #1
0
    def create(self, parent):
        """ Create and set the dock widget that contains the pane contents.
        """
        self.control = control = QtGui.QDockWidget(parent)

        # Set the widget's object name. This important for QMainWindow state
        # saving. Use the task ID and the pane ID to avoid collisions when a
        # pane is present in multiple tasks attached to the same window.
        control.setObjectName(self.task.id + ':' + self.id)

        # Configure the dock widget according to the DockPane settings.
        self._set_dock_features()
        self._set_dock_title()
        self._set_floating()
        self._set_visible()

        # Connect signal handlers for updating DockPane traits.
        control.dockLocationChanged.connect(self._receive_dock_area)
        control.topLevelChanged.connect(self._receive_floating)
        control.visibilityChanged.connect(self._receive_visible)

        # Add the pane contents to the dock widget.
        contents = self.create_contents(control)
        control.setWidget(contents)

        # For some reason the QDockWidget doesn't respect the minimum size
        # of its widgets
        control.setMinimumSize(contents.minimumSize())

        # Hide the control by default. Otherwise, the widget will visible in its
        # parent immediately!
        control.hide()
コード例 #2
0
    def setup_qt4_dock_window(self):
        from pyface.qt import QtGui

        # set up the dock window for qt
        main_window = QtGui.QMainWindow()
        dock = QtGui.QDockWidget("testing", main_window)
        dock.setWidget(QtGui.QMainWindow())
        return main_window, dock
コード例 #3
0
    def setup_qt4_dock_window(self):
        from pyface.qt import QtGui

        # set up the dock window for qt
        main_window = QtGui.QMainWindow()
        self.addCleanup(process_cascade_events)
        self.addCleanup(main_window.close)
        dock = QtGui.QDockWidget("testing", main_window)
        dock.setWidget(QtGui.QMainWindow())
        return main_window, dock
コード例 #4
0
def create_dummy_dock_widget(parent):
    """ Create a dummy QDockWidget with a dummy child widget for test.

    Parameters
    ----------
    parent : QObject

    Returns
    -------
    dock_widget : QDockWidget
    """
    dock_widget = QtGui.QDockWidget(parent)
    content_widget = QtGui.QWidget(parent)
    dock_widget.setWidget(content_widget)
    return dock_widget
コード例 #5
0
    def create(self, parent):
        """ Create and set the dock widget that contains the pane contents.
        """
        self.control = control = QtGui.QDockWidget(parent)

        # Set the widget's object name. This important for QMainWindow state
        # saving. Use the task ID and the pane ID to avoid collisions when a
        # pane is present in multiple tasks attached to the same window.
        control.setObjectName(self.task.id + ":" + self.id)

        # Ensure that undocked ("floating") windows are visible on macOS
        # when focus is switched, for consistency with Linux and Windows.
        control.setAttribute(
            QtCore.Qt.WidgetAttribute.WA_MacAlwaysShowToolWindow)

        # Configure the dock widget according to the DockPane settings.
        self._set_dock_features(event=None)
        self._set_dock_title(event=None)
        self._set_floating(event=None)
        self._set_visible(event=None)

        # Connect signal handlers for updating DockPane traits.
        control.dockLocationChanged.connect(self._receive_dock_area)
        control.topLevelChanged.connect(self._receive_floating)
        control.visibilityChanged.connect(self._receive_visible)

        # Add the pane contents to the dock widget.
        contents = self.create_contents(control)
        control.setWidget(contents)

        # For some reason the QDockWidget doesn't respect the minimum size
        # of its widgets
        contents_minsize = contents.minimumSize()
        style = control.style()
        contents_minsize.setHeight(
            contents_minsize.height() +
            style.pixelMetric(style.PM_DockWidgetHandleExtent))
        control.setMinimumSize(contents_minsize)

        # Hide the control by default. Otherwise, the widget will visible in its
        # parent immediately!
        control.hide()
コード例 #6
0
    def _qt4_create_view_dock_widget(self, view, size=(-1, -1)):
        """ Create a dock widget that wraps a view. """

        # See if it has already been created.
        try:
            dw = view._qt4_dock
        except AttributeError:
            dw = QtGui.QDockWidget(view.name, self.window.control)
            dw.setWidget(_ViewContainer(size, self.window.control))
            dw.setObjectName(view.id)
            dw.connect(dw.toggleViewAction(), QtCore.SIGNAL('toggled(bool)'),
                    self._qt4_handle_dock_visibility)
            dw.connect(dw, QtCore.SIGNAL('visibilityChanged(bool)'),
                    self._qt4_handle_dock_visibility)

            # Save the dock window.
            view._qt4_dock = dw

            def on_name_changed():
                view._qt4_dock.setWindowTitle(view.name)

            view.on_trait_change(on_name_changed, 'name')

        # Make sure the view control exists.
        if view.control is None:
            # Make sure that the view knows which window it is in.
            view.window = self.window

            try:
                view.control = view.create_control(self.window.control)
            except:
                # Tidy up if the view couldn't be created.
                delattr(view, '_qt4_dock')
                self.window.control.removeDockWidget(dw)
                dw.deleteLater()
                del dw
                raise

        dw.widget().setCentralWidget(view.control)

        return dw