コード例 #1
0
ファイル: figuremanager.py プロジェクト: luzpaz/mantid
    def on_button_press(self, event):
        if not event.dblclick:
            # shortcut
            return
        # We assume this is used for editing axis information e.g. labels
        # which are outside of the axes so event.inaxes is no use.
        canvas = self.canvas
        figure = canvas.figure
        axes = figure.get_axes()

        def move_and_show(editor):
            editor.move(event.x,
                        figure.bbox.height - event.y + self.window.y())
            editor.exec_()

        for ax in axes:
            if ax.title.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.title))
            elif ax.xaxis.label.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.xaxis.label))
            elif ax.yaxis.label.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.yaxis.label))
            elif ax.xaxis.contains(event)[0]:
                move_and_show(XAxisEditor(canvas, ax))
            elif ax.yaxis.contains(event)[0]:
                move_and_show(YAxisEditor(canvas, ax))
コード例 #2
0
    def _show_axis_editor(self, event):
        # We assume this is used for editing axis information e.g. labels
        # which are outside of the axes so event.inaxes is no use.
        canvas = self.canvas
        figure = canvas.figure
        axes = figure.get_axes()

        def move_and_show(editor):
            editor.move(QCursor.pos())
            editor.exec_()

        for ax in axes:
            if ax.title.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.title))
            elif ax.xaxis.label.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.xaxis.label))
            elif ax.yaxis.label.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.yaxis.label))
            elif (ax.xaxis.contains(event)[0] or any(
                    tick.contains(event)[0] for tick in ax.get_xticklabels())):
                move_and_show(XAxisEditor(canvas, ax))
            elif (ax.yaxis.contains(event)[0] or any(
                    tick.contains(event)[0] for tick in ax.get_yticklabels())):
                if type(ax) == Axes:
                    move_and_show(ColorbarAxisEditor(canvas, ax))
                else:
                    move_and_show(YAxisEditor(canvas, ax))
            elif hasattr(ax, 'zaxis'):
                if ax.zaxis.label.contains(event)[0]:
                    move_and_show(LabelEditor(canvas, ax.zaxis.label))
                elif (ax.zaxis.contains(event)[0] or any(
                        tick.contains(event)[0]
                        for tick in ax.get_zticklabels())):
                    move_and_show(ZAxisEditor(canvas, ax))
コード例 #3
0
    def _show_axis_editor(self, event):
        # We assume this is used for editing axis information e.g. labels
        # which are outside of the axes so event.inaxes is no use.
        canvas = self.canvas
        figure = canvas.figure
        axes = figure.get_axes()

        def move_and_show(editor):
            editor.move(QCursor.pos())
            editor.exec_()

        for ax in axes:
            if ax.title.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.title))
            elif ax.xaxis.label.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.xaxis.label))
            elif ax.yaxis.label.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.yaxis.label))
            elif (ax.xaxis.contains(event)[0]
                  or any(tick.contains(event)[0] for tick in ax.get_xticklabels())):
                move_and_show(XAxisEditor(canvas, ax))
            elif (ax.yaxis.contains(event)[0]
                  or any(tick.contains(event)[0] for tick in ax.get_yticklabels())):
                if type(ax) == Axes:
                    move_and_show(ColorbarAxisEditor(canvas, ax))
                else:
                    move_and_show(YAxisEditor(canvas, ax))
            elif hasattr(ax, 'zaxis'):
                if ax.zaxis.label.contains(event)[0]:
                    move_and_show(LabelEditor(canvas, ax.zaxis.label))
                elif (ax.zaxis.contains(event)[0]
                      or any(tick.contains(event)[0] for tick in ax.get_zticklabels())):
                    move_and_show(ZAxisEditor(canvas, ax))
            elif ax.get_legend() is not None and ax.get_legend().contains(event)[0]:
                # We have to set the legend as non draggable else we hold onto the legend
                # until the mouse button is clicked again
                ax.get_legend().set_draggable(False)
                legend_texts = ax.get_legend().get_texts()
                active_lines = datafunctions.get_legend_handles(ax)
                for legend_text, curve in zip(legend_texts, active_lines):
                    if legend_text.contains(event)[0]:
                        move_and_show(LegendEditor(canvas, legend_text, curve))
                ax.get_legend().set_draggable(True)
コード例 #4
0
    def _show_axis_editor(self, event):
        """
        Decides whether to show a dialog to edit axis information based on the contents of the
        event. Shows a dialog if necessary.
        @param event: the object representing the event
        @return: a flag to denote whether an action was taken e.g. opening a dialog.
        """
        # We assume this is used for editing axis information e.g. labels
        # which are outside of the axes so event.inaxes is no use.
        canvas = self.canvas
        figure = canvas.figure
        axes = figure.get_axes()
        action_taken = False

        def move_and_show(editor):
            nonlocal action_taken
            action_taken = True
            editor.move(QCursor.pos())
            editor.exec_()

        for ax in axes:
            if ax.title.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.title))
            elif ax.xaxis.label.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.xaxis.label))
            elif ax.yaxis.label.contains(event)[0]:
                move_and_show(LabelEditor(canvas, ax.yaxis.label))
            elif (ax.xaxis.contains(event)[0] or any(
                    tick.contains(event)[0] for tick in ax.get_xticklabels())):
                move_and_show(XAxisEditor(canvas, ax))
            elif (ax.yaxis.contains(event)[0] or any(
                    tick.contains(event)[0] for tick in ax.get_yticklabels())):
                if type(ax) == Axes:
                    move_and_show(ColorbarAxisEditor(canvas, ax))
                else:
                    move_and_show(YAxisEditor(canvas, ax))
            elif hasattr(ax, 'zaxis'):
                if ax.zaxis.label.contains(event)[0]:
                    move_and_show(LabelEditor(canvas, ax.zaxis.label))
                elif (ax.zaxis.contains(event)[0] or any(
                        tick.contains(event)[0]
                        for tick in ax.get_zticklabels())):
                    move_and_show(ZAxisEditor(canvas, ax))
            elif ax.get_legend() is not None and ax.get_legend().contains(
                    event)[0]:
                # We have to set the legend as non draggable else we hold onto the legend
                # until the mouse button is clicked again
                legend_set_draggable(ax.get_legend(), False)
                legend_texts = ax.get_legend().get_texts()
                active_lines = datafunctions.get_legend_handles(ax)

                remove_legend_flag = True  # remove the legend if no curve texts were clicked
                for legend_text, curve in zip(legend_texts, active_lines):
                    if legend_text.contains(event)[0]:
                        remove_legend_flag = False
                        move_and_show(LegendEditor(canvas, legend_text, curve))
                legend_set_draggable(ax.get_legend(), True)

                if remove_legend_flag:
                    action_taken = True
                    legend = ax.get_legend()
                    legend.set_visible(False)
                    canvas.draw()

        return action_taken