Beispiel #1
0
    def init_floating_frame(self, frame, layout):
        """ Initialize a floating frame.

        This initializer sets up the geometry, maximized state, and
        linked state for the floating frame.

        Parameters
        ----------
        frame : QDockFrame
            The floating dock frame of interest.

        layout : ItemLayout or AreaLayout
            The layout describing the floating state of the frame.

        """
        rect = QRect(*layout.geometry)
        if rect.isValid():
            rect = ensure_on_screen(rect)
            frame.setGeometry(rect)
        frame.show()
        if layout.linked:
            frame.setLinked(True)
        if layout.maximized:
            frame.showMaximized()
Beispiel #2
0
    def init_floating_frame(self, frame, layout):
        """ Initialize a floating frame.

        This initializer sets up the geometry, maximized state, and
        linked state for the floating frame.

        Parameters
        ----------
        frame : QDockFrame
            The floating dock frame of interest.

        layout : ItemLayout or AreaLayout
            The layout describing the floating state of the frame.

        """
        rect = QRect(*layout.geometry)
        if rect.isValid():
            rect = ensure_on_screen(rect)
            frame.setGeometry(rect)
        frame.show()
        if layout.linked:
            frame.setLinked(True)
        if layout.maximized:
            frame.showMaximized()
Beispiel #3
0
    def apply_layout(self, layout):
        """ Apply a layout to the dock area.

        Parameters
        ----------
        layout : docklayout
            The docklayout to apply to the managed area.

        """
        # Remove the layout widget before resetting the handlers. This
        # prevents a re-used container from being hidden by the call to
        # setLayoutWidget after it has already been reset. The reference
        # is held to the old widget so the containers are not destroyed
        # before they are reset.
        widget = self._dock_area.layoutWidget()
        self._dock_area.setLayoutWidget(None)
        containers = list(self._dock_containers())
        for container in containers:
            container.reset()
        for window in list(self._dock_windows()):
            window.close()

        # Emit a warning for an item referenced in the layout which
        # has not been added to the dock manager.
        names = set(container.objectName() for container in containers)
        filter_func = lambda item: isinstance(item, dockitem)
        for item in filter(filter_func, layout.traverse()):
            if item.name not in names:
                msg = "dock item '%s' was not found in the dock manager"
                warnings.warn(msg % item.name, stacklevel=2)

        # A convenience closure for populating a dock area.
        def popuplate_area(area, layout):
            widget = build_layout(layout.child, containers)
            area.setLayoutWidget(widget)
            if layout.maximized_item:
                maxed = self._find_container(layout.maximized_item)
                if maxed is not None:
                    maxed.showMaximized()

        # Setup the layout for the primary dock area widget.
        primary = layout.primary
        if primary is not None:
            if isinstance(primary, dockarea):
                popuplate_area(self._dock_area, primary)
            else:
                widget = build_layout(primary, containers)
                self._dock_area.setLayoutWidget(widget)

        # Setup the layout for the secondary floating dock area. This
        # classifies the secondary items according to their type as
        # each type has subtle differences in how they area handled.
        single_items = []
        single_areas = []
        multi_areas = []
        for secondary in layout.secondary:
            if isinstance(secondary, dockitem):
                single_items.append(secondary)
            elif isinstance(secondary.child, dockitem):
                single_areas.append(secondary)
            else:
                multi_areas.append(secondary)

        targets = []
        for item in single_items:
            target = self._find_container(item.name)
            if target is not None:
                target.float()
                targets.append((target, item))
        for item in single_areas:
            target = self._find_container(item.child.name)
            if target is not None:
                target.float()
                targets.append((target, item))
        for item in multi_areas:
            target = QDockWindow.create(self, self._dock_area)
            win_area = target.dockArea()
            popuplate_area(win_area, item)
            win_area.installEventFilter(self._area_filter)
            self._dock_frames.append(target)
            self._proximity_handler.addFrame(target)
            targets.append((target, item))

        for target, item in targets:
            rect = QRect(*item.geometry)
            if rect.isValid():
                rect = ensure_on_screen(rect)
                target.setGeometry(rect)
            target.show()
            if item.linked:
                target.setLinked(True)
            if item.maximized:
                target.showMaximized()