Esempio n. 1
0
    def _populate_select_curve_combo_box(self):
        """
        Add curves on selected axes to the 'select curves' combo box.
        Return False if there are no lines on the axes (this can occur
        when a user uses the "Remove Curve" button), else return True.
        """
        with block_signals(self.view.select_curve_combo_box):
            self.view.select_curve_combo_box.clear()
        selected_ax = self.get_selected_ax()
        if not selected_ax:
            self.view.close()
            return False

        # Get the lines in the order that they are listed on the legend.
        active_lines = datafunctions.get_legend_handles(selected_ax)
        for line in active_lines:
            self._update_selected_curve_name(line)
        self.view.populate_select_curve_combo_box(list(self.curve_names_dict))
        return True
Esempio n. 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))
            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)
Esempio n. 3
0
    def create_legend(cls, props, ax):
        # Imported here to prevent circular import.
        from mantid.plots.datafunctions import get_legend_handles

        loc = ConfigService.getString('plots.legend.Location')
        font_size = float(ConfigService.getString('plots.legend.FontSize'))
        if not props:
            legend_set_draggable(
                ax.legend(handles=get_legend_handles(ax),
                          loc=loc,
                          prop={'size': font_size}), True)
            return

        if 'loc' in props.keys():
            loc = props['loc']

        if int(matplotlib.__version__[0]) >= 2:
            legend = ax.legend(
                handles=get_legend_handles(ax),
                ncol=props['columns'],
                prop={'size': props['entries_size']},
                numpoints=props['markers'],
                markerfirst=props['marker_position'] == "Left of Entries",
                frameon=props['box_visible'],
                fancybox=props['round_edges'],
                shadow=props['shadow'],
                framealpha=props['transparency'],
                facecolor=props['background_color'],
                edgecolor=props['edge_color'],
                title=props['title'],
                borderpad=props['border_padding'],
                labelspacing=props['label_spacing'],
                handlelength=props['marker_size'],
                handletextpad=props['marker_label_padding'],
                columnspacing=props['column_spacing'],
                loc=loc)
        else:
            legend = ax.legend(
                handles=get_legend_handles(ax),
                ncol=props['columns'],
                prop={'size': props['entries_size']},
                numpoints=props['markers'],
                markerfirst=props['marker_position'] == "Left of Entries",
                frameon=props['box_visible'],
                fancybox=props['round_edges'],
                shadow=props['shadow'],
                framealpha=props['transparency'],
                title=props['title'],
                borderpad=props['border_padding'],
                labelspacing=props['label_spacing'],
                handlelength=props['marker_size'],
                handletextpad=props['marker_label_padding'],
                columnspacing=props['column_spacing'],
                loc=loc)

        title = legend.get_title()
        title.set_fontname(props['title_font'])
        title.set_fontsize(props['title_size'])
        title.set_color(props['title_color'])

        for text in legend.get_texts():
            text.set_fontname(props['entries_font'])
            text.set_fontsize(props['entries_size'])
            text.set_color(props['entries_color'])

        legend.set_visible(props['visible'])
        legend_set_draggable(legend, True)
Esempio n. 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