Esempio n. 1
0
    def deleteHandle(self, _, workspace):
        """
        Called when the ADS has deleted a workspace. Checks the
        attached axes for any hold a plot from this workspace. If removing
        this leaves empty axes then the parent window is triggered for
        closer
        :param _: The name of the workspace. Unused
        :param workspace: A pointer to the workspace
        """
        # Find the axes with this workspace reference
        all_axes = self.canvas.figure.axes
        if not all_axes:
            return

        # Here we wish to delete any curves linked to the workspace being
        # deleted and if a figure is now empty, close it. We must avoid closing
        # any figures that were created via the script window that are not
        # managed via a workspace.
        # See https://github.com/mantidproject/mantid/issues/25135.
        empty_axes = []
        redraw = False
        for ax in all_axes:
            if isinstance(ax, MantidAxes):
                to_redraw = ax.remove_workspace_artists(workspace)
            else:
                to_redraw = False
            # Solution for filtering out colorbar axes. Works most of the time.
            if type(ax) is not Axes:
                empty_axes.append(MantidAxes.is_empty(ax))
            redraw = redraw | to_redraw

        if all(empty_axes):
            self.window.emit_close()
        elif redraw:
            self.canvas.draw()
Esempio n. 2
0
    def deleteHandle(self, _, workspace):
        """
        Called when the ADS has deleted a workspace. Checks the
        attached axes for any hold a plot from this workspace. If removing
        this leaves empty axes then the parent window is triggered for
        closer
        :param _: The name of the workspace. Unused
        :param workspace: A pointer to the workspace
        """
        # Find the axes with this workspace reference
        all_axes = self.canvas.figure.axes
        if not all_axes:
            return

        # Here we wish to delete any curves linked to the workspace being
        # deleted and if a figure is now empty, close it. We must avoid closing
        # any figures that were created via the script window that are not
        # managed via a workspace.
        # See https://github.com/mantidproject/mantid/issues/25135.
        empty_axes = []
        redraw = False
        for ax in all_axes:
            if isinstance(ax, MantidAxes):
                to_redraw = ax.remove_workspace_artists(workspace)
            else:
                to_redraw = False
            # We check for axes type below as a pseudo check for an axes being
            # a colorbar. Creating a colorfill plot creates 2 axes: one linked
            # to a workspace, the other a colorbar. Deleting the workspace
            # deletes the colorfill, but the plot remains open due to the
            # non-empty colorbar. This solution seems to work for the majority
            # of cases but could lead to unmanaged figures only containing an
            # Axes object being closed.
            if type(ax) is not Axes:
                empty_axes.append(MantidAxes.is_empty(ax))
            redraw = redraw | to_redraw

        if all(empty_axes):
            self.window.emit_close()
        elif redraw:
            self.canvas.draw()
Esempio n. 3
0
    def deleteHandle(self, _, workspace):
        """
        Called when the ADS has deleted a workspace. Checks the
        attached axes for any hold a plot from this workspace. If removing
        this leaves empty axes then the parent window is triggered for
        closer
        :param _: The name of the workspace. Unused
        :param workspace: A pointer to the workspace
        """
        # Find the axes with this workspace reference
        all_axes = self.canvas.figure.axes
        if not all_axes:
            return

        # Here we wish to delete any curves linked to the workspace being
        # deleted and if a figure is now empty, close it. We must avoid closing
        # any figures that were created via the script window that are not
        # managed via a workspace.
        # See https://github.com/mantidproject/mantid/issues/25135.
        empty_axes = []
        for ax in all_axes:
            if isinstance(ax, MantidAxes):
                ax.remove_workspace_artists(workspace)
            # We check for axes type below as a pseudo check for an axes being
            # a colorbar. Creating a colorfill plot creates 2 axes: one linked
            # to a workspace, the other a colorbar. Deleting the workspace
            # deletes the colorfill, but the plot remains open due to the
            # non-empty colorbar. This solution seems to work for the majority
            # of cases but could lead to unmanaged figures only containing an
            # Axes object being closed.
            if type(ax) is not Axes:
                empty_axes.append(MantidAxes.is_empty(ax))

        if all(empty_axes):
            self.window.emit_close()
        else:
            self.canvas.draw_idle()