Ejemplo n.º 1
0
    def __init__(self, parent, context):

        self._figure_options = QuickEditWidget(parent)
        self._plotting_view = PlottingCanvasView(parent)
        self._plotting_view.add_widget(self._figure_options.widget)
        self._model = PlottingCanvasModel(context)
        self._presenter = PlottingCanvasPresenter(self._plotting_view,
                                                  self._model,
                                                  self._figure_options)
Ejemplo n.º 2
0
    def __init__(self, context, parent=None):
        super(MultiPlotWidget, self).__init__()
        self._context = context
        layout = QtWidgets.QVBoxLayout()
        splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        self.quickEdit = QuickEditWidget(self)
        self.quickEdit.connect_x_range_changed(self._x_range_changed)
        self.quickEdit.connect_y_range_changed(self._y_range_changed)
        self.quickEdit.connect_errors_changed(self._errors_changed)
        self.quickEdit.connect_autoscale_changed(self._autoscale_changed)
        self.quickEdit.connect_plot_selection(self._selection_changed)

        # add some dummy plot
        self.plots = subplot(self._context)
        self.plots.connect_quick_edit_signal(self._update_quick_edit)
        self.plots.connect_rm_subplot_signal(self._update_quick_edit)
        # create GUI layout
        splitter.addWidget(self.plots)
        splitter.addWidget(self.quickEdit.widget)
        layout.addWidget(splitter)
        self.setLayout(layout)
Ejemplo n.º 3
0
    def __init__(self, context, parent=None):
        super(MultiPlotWidget, self).__init__()
        self._context = context
        layout = QtWidgets.QVBoxLayout()
        splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        self.quickEdit = QuickEditWidget(self)
        self.quickEdit.connect_x_range_changed(self._x_range_changed)
        self.quickEdit.connect_y_range_changed(self._y_range_changed)
        self.quickEdit.connect_errors_changed(self._errors_changed)
        self.quickEdit.connect_autoscale_changed(self._autoscale_changed)
        self.quickEdit.connect_plot_selection(self._selection_changed)

        # add some dummy plot
        self.plots = subplot(self._context)
        self.plots.connect_quick_edit_signal(self._update_quick_edit)
        self.plots.connect_rm_subplot_signal(self._update_quick_edit)
        # create GUI layout
        splitter.addWidget(self.plots)
        splitter.addWidget(self.quickEdit.widget)
        layout.addWidget(splitter)
        self.setLayout(layout)
Ejemplo n.º 4
0
 def setUp(self):
     self.pres = mock.create_autospec(QuickEditPresenter)
     self.widget = QuickEditWidget()
     self.slot = mock.Mock()
     self.widget.set_mock(self.pres)
Ejemplo n.º 5
0
class QuickEditWidgetTest(unittest.TestCase):
    def setUp(self):
        self.pres = mock.create_autospec(QuickEditPresenter)
        self.widget = QuickEditWidget()
        self.slot = mock.Mock()
        self.widget.set_mock(self.pres)

    def test_connect_autoscale(self):
        self.widget.connect_autoscale_changed(self.slot)
        self.pres.connect_autoscale_changed.assert_called_with(self.slot)

    def test_connect_errors(self):
        self.widget.connect_errors_changed(self.slot)
        self.pres.connect_errors_changed.assert_called_with(self.slot)

    def test_connect_x_range(self):
        self.widget.connect_x_range_changed(self.slot)
        self.pres.connect_x_range_changed.assert_called_with(self.slot)

    def test_connect_y_range(self):
        self.widget.connect_y_range_changed(self.slot)
        self.pres.connect_y_range_changed.assert_called_with(self.slot)

    def test_connect_plot_selection(self):
        self.widget.connect_plot_selection(self.slot)
        self.pres.connect_plot_selection.assert_called_with(self.slot)

    def test_add_subplot(self):
        name = "new plot"
        self.widget.add_subplot(name)
        self.assertEqual(self.pres.add_subplot.call_count, 1)
        self.pres.add_subplot.assert_called_with(name)

    def test_get_selection_one(self):
        name = "one plot"
        self.pres.widget.current_selection = mock.MagicMock(return_value = name)
        output = self.widget.get_selection()
        self.assertEqual([name], output)

    def test_get_selection_all(self):
        name = "All"
        self.pres.widget.current_selection = mock.MagicMock(return_value = name)
        output = self.widget.get_selection()
        self.assertEqual(self.pres.all.call_count, 1)

    def test_set_plot_x_range(self):
        self.widget.set_plot_x_range([0,1])
        self.pres.set_plot_x_range.assert_called_with([0,1])

    def test_set_plot_y_range(self):
        self.widget.set_plot_y_range([0,1])
        self.pres.set_plot_y_range.assert_called_with([0,1])

    def test_set_errors_TT(self):
        self.widget.set_errors(True)
        self.pres.set_errors.assert_called_with(True)
Ejemplo n.º 6
0
class MultiPlotWidget(QtWidgets.QWidget):
    closeSignal = QtCore.Signal()

    def __init__(self, context, parent=None):
        super(MultiPlotWidget, self).__init__()
        self._context = context
        layout = QtWidgets.QVBoxLayout()
        splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        self.quickEdit = QuickEditWidget(self)
        self.quickEdit.connect_x_range_changed(self._x_range_changed)
        self.quickEdit.connect_y_range_changed(self._y_range_changed)
        self.quickEdit.connect_errors_changed(self._errors_changed)
        self.quickEdit.connect_autoscale_changed(self._autoscale_changed)
        self.quickEdit.connect_plot_selection(self._selection_changed)

        # add some dummy plot
        self.plots = subplot(self._context)
        self.plots.connect_quick_edit_signal(self._update_quick_edit)
        self.plots.connect_rm_subplot_signal(self._update_quick_edit)
        # create GUI layout
        splitter.addWidget(self.plots)
        splitter.addWidget(self.quickEdit.widget)
        layout.addWidget(splitter)
        self.setLayout(layout)

    """ plotting """

    def add_subplot(self, name):
        self.plots.add_subplot(name, len(self.quickEdit.get_subplots()))

        self.quickEdit.add_subplot(name)

    def plot(self, subplot_name, ws, color=None, spec_num=1):
        self.plots.plot(subplot_name, ws, color=color, spec_num=spec_num)

    def remove_subplot(self, name):
        self.plots._remove_subplot(name)

    def get_subplots(self):
        return list(self._context.subplots.keys())

    def add_vline_and_annotate(self, subplotName, xvalue, label, color):
        self.add_annotate(subplotName, label)
        self.add_vline(subplotName, xvalue, label.text, color)

    def rm_vline_and_annotate(self, subplotName, name):
        self.rm_annotate(subplotName, name)
        self.rm_vline(subplotName, name)

    def add_annotate(self, subplotName, label):
        self.plots.add_annotate(subplotName, label)

    def add_vline(self, subplotName, xvalue, name, color):
        self.plots.add_vline(subplotName, xvalue, name, color)

    def rm_annotate(self, subplotName, name):
        self.plots.rm_annotate(subplotName, name)

    def rm_vline(self, subplotName, name):
        self.plots.rm_vline(subplotName, name)

    def remove_line(self, subplot_name, ws_name, spec=1):
        name = '{}: spec {}'.format(ws_name, spec)
        self.plots.remove_lines(subplot_name, [name])

    # gets initial values for quickEdit
    def set_all_values(self):
        names = self.quickEdit.get_selection()
        xrange = list(self._context.subplots[names[0]].xbounds)
        yrange = list(self._context.subplots[names[0]].ybounds)
        for name in names:
            xbounds = self._context.subplots[name].xbounds
            ybounds = self._context.subplots[name].ybounds
            if xrange[0] > xbounds[0]:
                xrange[0] = deepcopy(xbounds[0])
            if xrange[1] < xbounds[1]:
                xrange[1] = deepcopy(xbounds[1])
            if yrange[0] > ybounds[0]:
                yrange[0] = deepcopy(ybounds[0])
            if yrange[1] < ybounds[1]:
                yrange[1] = deepcopy(ybounds[1])
        self._context.set_xBounds(xrange)
        self._context.set_yBounds(yrange)
        self._x_range_changed(xrange)
        self._y_range_changed(yrange)
        # get tick boxes correct
        errors = self._check_all_errors(names)
        self.quickEdit.set_errors(errors)
        self._change_errors(errors, names)

    def connectCloseSignal(self, slot):
        self.closeSignal.connect(slot)

    def remove_subplot_connection(self, slot):
        self.plots.connect_rm_subplot_signal(slot)

    def remove_line_connection(self, slot):
        self.plots.connect_rm_line_signal(slot)

    def disconnectCloseSignal(self):
        self.closeSignal.disconnect()

    def removeSubplotDisonnect(self):
        self.plots.disconnect_rm_subplot_signal()

    """ update GUI """

    def _if_empty_close(self):
        if not self._context.subplots:
            self.closeSignal.emit()
            self.close()

    def _update_quick_edit(self, subplotName):
        names = self.quickEdit.get_selection()
        if subplotName not in self._context.subplots.keys():
            self.quickEdit.rm_subplot(subplotName)
            self._if_empty_close()
            return
        xrange = self._context.subplots[subplotName].xbounds
        yrange = self._context.subplots[subplotName].ybounds
        if len(names) == 0:
            return
        # if all selected update everyone
        if len(names) > 1:
            self.quickEdit.set_plot_x_range(xrange)
            self.quickEdit.set_plot_y_range(yrange)
        # if changed current selection
        elif names[0] == subplotName:
            self.quickEdit.set_plot_x_range(xrange)
            self.quickEdit.set_plot_y_range(yrange)
        # if a different plot changed
        else:
            pass

    def _selection_changed(self, index):
        names = self.quickEdit.get_selection()
        xrange = self._context.get_xBounds()
        yrange = self._context.get_yBounds()
        errors = True
        if len(names) == 1:
            xrange = self._context.subplots[names[0]].xbounds
            yrange = self._context.subplots[names[0]].ybounds
            errors = self._context.subplots[names[0]].errors
        else:
            errors = self._check_all_errors(names)
        # update values
        self.quickEdit.set_errors(errors)
        self._change_errors(errors, names)
        self.quickEdit.set_plot_x_range(xrange)
        self.quickEdit.set_plot_y_range(yrange)

        # force update of plots if selection is all
        if len(names) > 1:
            self._x_range_changed(xrange)
            self._y_range_changed(yrange)

    def _autoscale_changed(self, _):
        names = self.quickEdit.get_selection()
        self.plots.set_y_autoscale(names, True)

    def _change_errors(self, state, names):
        self.plots.change_errors(state, names)

    def _errors_changed(self, state):
        names = self.quickEdit.get_selection()
        self._change_errors(state, names)

    def _x_range_changed(self, xRange):
        names = self.quickEdit.get_selection()
        if len(names) > 1:
            self._context.set_xBounds(xRange)
        self.plots.set_plot_x_range(names, xRange)
        self.quickEdit.set_plot_x_range(xRange)

    def _y_range_changed(self, yRange):
        names = self.quickEdit.get_selection()
        if len(names) > 1:
            self._context.set_yBounds(yRange)
        self.plots.set_plot_y_range(names, yRange)
        self.quickEdit.set_plot_y_range(yRange)

    def _check_all_errors(self, names):
        for name in names:
            if self._context.subplots[name].errors is False:
                return False
        return True
Ejemplo n.º 7
0
    def setup_interface(self):
        self.setObjectName("PlotWidget")
        self.resize(500, 100)

        self.plot_label = QtWidgets.QLabel(self)
        self.plot_label.setObjectName("plotLabel")
        self.plot_label.setText("Plot type : ")

        self.tiled_type_label = QtWidgets.QLabel(self)
        self.tiled_type_label.setObjectName("tileTypeLabel")
        self.tiled_type_label.setText("Tile plots by: ")

        self.raw = QtWidgets.QCheckBox("plot raw", self)
        self.raw.setChecked(True)

        self.plot_selector = QtWidgets.QComboBox(self)
        self.plot_selector.setObjectName("plotSelector")
        self.plot_selector.addItems(["Asymmetry", "Counts"])
        self.plot_selector.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                         QtWidgets.QSizePolicy.Fixed)

        self.plot_type_selector = QtWidgets.QCheckBox(parent=self)
        self.plot_type_selector.setChecked(False)
        self.plot_type_selector.setObjectName("plotTypeSelector")
        self.plot_type_selector.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                              QtWidgets.QSizePolicy.Fixed)

        self.tile_type_selector = QtWidgets.QComboBox(self)
        self.tile_type_selector.setObjectName("tileTypeSelector")
        self.tile_type_selector.addItems(["Group/Pair", "Run"])

        self.horizontal_layout = QtWidgets.QHBoxLayout()
        self.horizontal_layout.setObjectName("horizontalLayout")
        self.horizontal_layout.addWidget(self.plot_label)
        self.horizontal_layout.addWidget(self.plot_selector)
        self.horizontal_layout.addSpacing(15)
        self.horizontal_layout.addStretch(0)
        self.horizontal_layout.addWidget(self.plot_type_selector)
        self.horizontal_layout.addWidget(self.tiled_type_label)
        self.horizontal_layout.addWidget(self.tile_type_selector)
        self.horizontal_layout.addSpacing(15)
        self.horizontal_layout.addStretch(0)
        self.horizontal_layout.addWidget(self.raw)
        self.horizontal_layout.addStretch(0)
        self.horizontal_layout.addSpacing(50)

        # plotting options
        self.plot_options = QuickEditWidget(self)
        self.plot_options.widget.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                               QtWidgets.QSizePolicy.Fixed)

        self.vertical_layout = QtWidgets.QVBoxLayout()
        self.vertical_layout.setObjectName("verticalLayout")
        self.vertical_layout.addItem(self.horizontal_layout)

        self.group = QtWidgets.QGroupBox("Plotting")
        self.group.setFlat(False)
        self.setStyleSheet(
            "QGroupBox {border: 1px solid grey;border-radius: 10px;margin-top: 1ex; margin-right: 0ex}"
            "QGroupBox:title {"
            'subcontrol-origin: margin;'
            "padding: 0 3px;"
            'subcontrol-position: top center;'
            'padding-top: 0px;'
            'padding-bottom: 0px;'
            "padding-right: 10px;"
            ' color: grey; }')

        self.group.setLayout(self.vertical_layout)

        # create the figure
        self.fig = Figure()
        self.fig.canvas = FigureCanvas(self.fig)
        self.toolBar = NavigationToolbar(self.fig.canvas, self)
        # set size policy
        self.toolBar.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                   QtWidgets.QSizePolicy.Fixed)

        # Create a set of Mantid axis for the figure
        self.fig, axes = get_plot_fig(overplot=False,
                                      ax_properties=None,
                                      axes_num=1,
                                      fig=self.fig)

        self.widget_layout = QtWidgets.QVBoxLayout(self)
        self.widget_layout.addWidget(self.group)
        self.vertical_layout.addWidget(self.toolBar)
        self.vertical_layout.addWidget(self.fig.canvas)

        self.vertical_layout.addWidget(self.plot_options.widget)

        self.setLayout(self.widget_layout)
Ejemplo n.º 8
0
class MultiPlotWidget(QtWidgets.QWidget):
    closeSignal = QtCore.Signal()

    def __init__(self, context, parent=None):
        super(MultiPlotWidget, self).__init__()
        self._context = context
        layout = QtWidgets.QVBoxLayout()
        splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        self.quickEdit = QuickEditWidget(self)
        self.quickEdit.connect_x_range_changed(self._x_range_changed)
        self.quickEdit.connect_y_range_changed(self._y_range_changed)
        self.quickEdit.connect_errors_changed(self._errors_changed)
        self.quickEdit.connect_autoscale_changed(self._autoscale_changed)
        self.quickEdit.connect_plot_selection(self._selection_changed)

        # add some dummy plot
        self.plots = subplot(self._context)
        self.plots.connect_quick_edit_signal(self._update_quick_edit)
        self.plots.connect_rm_subplot_signal(self._update_quick_edit)
        # create GUI layout
        splitter.addWidget(self.plots)
        splitter.addWidget(self.quickEdit.widget)
        layout.addWidget(splitter)
        self.setLayout(layout)

    """ plotting """

    def add_subplot(self, name):
        self.plots.add_subplot(name, len(self.quickEdit.get_selection()))

        self.quickEdit.add_subplot(name)

    def plot(self, subplotName, ws, specNum=1):
        self.plots.plot(subplotName, ws, specNum=specNum)

    def remove_subplot(self, name):
        self.plots._remove_subplot(name)

    def get_subplots(self):
        return list(self._context.subplots.keys())

    def add_vline_and_annotate(self, subplotName, xvalue, label):
        self.add_annotate(subplotName, label)
        self.add_vline(subplotName, xvalue, label.text)

    def rm_vline_and_annotate(self, subplotName, name):
        self.rm_annotate(subplotName, name)
        self.rm_vline(subplotName, name)

    def add_annotate(self, subplotName, label):
        self.plots.add_annotate(subplotName, label)

    def add_vline(self, subplotName, xvalue, name):
        self.plots.add_vline(subplotName, xvalue, name)

    def rm_annotate(self, subplotName, name):
        self.plots.rm_annotate(subplotName, name)

    def rm_vline(self, subplotName, name):
        self.plots.rm_vline(subplotName, name)

    # gets inital values for quickEdit
    def set_all_values(self):
        names = self.quickEdit.get_selection()
        xrange = list(self._context.subplots[names[0]].xbounds)
        yrange = list(self._context.subplots[names[0]].ybounds)
        for name in names:
            xbounds = self._context.subplots[name].xbounds
            ybounds = self._context.subplots[name].ybounds
            if xrange[0] > xbounds[0]:
                xrange[0] = deepcopy(xbounds[0])
            if xrange[1] < xbounds[1]:
                xrange[1] = deepcopy(xbounds[1])
            if yrange[0] > ybounds[0]:
                yrange[0] = deepcopy(ybounds[0])
            if yrange[1] < ybounds[1]:
                yrange[1] = deepcopy(ybounds[1])
        self._context.set_xBounds(xrange)
        self._context.set_yBounds(yrange)
        self._x_range_changed(xrange)
        self._y_range_changed(yrange)
        # get tick boxes correct
        errors = self._check_all_errors(names)
        self.quickEdit.set_errors(errors)
        self._change_errors(errors, names)

    def connectCloseSignal(self, slot):
        self.closeSignal.connect(slot)

    def removeSubplotConnection(self, slot):
        self.plots.connect_rm_subplot_signal(slot)

    def disconnectCloseSignal(selft):
        self.closeSignal.disconnect()

    def removeSubplotDisonnect(self):
        self.plots.disconnect_rm_subplot_signal()

    """ update GUI """

    def _if_empty_close(self):
        if not self._context.subplots:
            self.closeSignal.emit()
            self.close

    def _update_quick_edit(self, subplotName):
        names = self.quickEdit.get_selection()
        if subplotName not in self._context.subplots.keys():
            self.quickEdit.rm_subplot(subplotName)
            self._if_empty_close()
            return
        xrange = self._context.subplots[subplotName].xbounds
        yrange = self._context.subplots[subplotName].ybounds
        if len(names) == 0:
            return
        # if all selected update everyone
        if len(names) > 1:
            self.quickEdit.set_plot_x_range(xrange)
            self.quickEdit.set_plot_y_range(yrange)
        # if changed current selection
        elif names[0] == subplotName:
            self.quickEdit.set_plot_x_range(xrange)
            self.quickEdit.set_plot_y_range(yrange)
        # if a different plot changed
        else:
            pass

    def _selection_changed(self, index):
        names = self.quickEdit.get_selection()
        xrange = self._context.get_xBounds()
        yrange = self._context.get_yBounds()
        errors = True
        if len(names) == 1:
            xrange = self._context.subplots[names[0]].xbounds
            yrange = self._context.subplots[names[0]].ybounds
            errors = self._context.subplots[names[0]].errors
        else:
            errors = self._check_all_errors(names)
        # update values
        self.quickEdit.set_errors(errors)
        self._change_errors(errors, names)
        self.quickEdit.set_plot_x_range(xrange)
        self.quickEdit.set_plot_y_range(yrange)

        # force update of plots if selection is all
        if len(names) > 1:
            self._x_range_changed(xrange)
            self._y_range_changed(yrange)

    def _autoscale_changed(self, state):
        names = self.quickEdit.get_selection()
        self.plots.set_y_autoscale(names, True)

    def _change_errors(self, state, names):
        self.plots.change_errors(state, names)

    def _errors_changed(self, state):
        names = self.quickEdit.get_selection()
        self._change_errors(state, names)

    def _x_range_changed(self, xRange):
        names = self.quickEdit.get_selection()
        if len(names) > 1:
            self._context.set_xBounds(xRange)
        self.plots.set_plot_x_range(names, xRange)
        self.quickEdit.set_plot_x_range(xRange)

    def _y_range_changed(self, yRange):
        names = self.quickEdit.get_selection()
        if len(names) > 1:
            self._context.set_yBounds(yRange)
        self.plots.set_plot_y_range(names, yRange)
        self.quickEdit.set_plot_y_range(yRange)

    def _check_all_errors(self, names):
        for name in names:
            if self._context.subplots[name].errors is False:
                return False
        return True
Ejemplo n.º 9
0
class MultiPlotWidget(QtWidgets.QWidget):
    def __init__(self, context, parent=None):
        super(MultiPlotWidget, self).__init__()
        self._context = context
        layout = QtWidgets.QVBoxLayout()
        splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        self.quickEdit = QuickEditWidget(self)
        self.quickEdit.connect_x_range_changed(self._x_range_changed)
        self.quickEdit.connect_y_range_changed(self._y_range_changed)
        self.quickEdit.connect_errors_changed(self._errors_changed)
        self.quickEdit.connect_autoscale_changed(self._autoscale_changed)
        self.quickEdit.connect_plot_selection(self._selection_changed)

        # add some dummy plot
        self.plots = subplot(self._context)
        self.plots.connect_quick_edit_signal(self._update_quick_edit)

        # create GUI layout
        splitter.addWidget(self.plots)
        splitter.addWidget(self.quickEdit.widget)
        layout.addWidget(splitter)
        self.setLayout(layout)

    """ plotting """

    def add_subplot(self, name, code):
        self.plots.add_subplot(name, code)
        self.quickEdit.add_subplot(name)

    def plot(self, subplotName, ws, specNum=1):
        self.plots.plot(subplotName, ws, specNum=specNum)

    def add_vline_and_annotate(self, subplotName, xvalue, label):
        self.add_annotate(subplotName, label)
        self.add_vline(subplotName, xvalue, label.text)

    def add_annotate(self, subplotName, label):
        self.plots.add_annotate(subplotName, label)

    def add_vline(self, subplotName, xvalue, name):
        self.plots.add_vline(subplotName, xvalue, name)

    # gets inital values for quickEdit
    def set_all_values(self):
        names = self.quickEdit.get_selection()
        xrange = list(self._context.subplots[names[0]].xbounds)
        yrange = list(self._context.subplots[names[0]].ybounds)
        for name in names:
            xbounds = self._context.subplots[name].xbounds
            ybounds = self._context.subplots[name].ybounds
            if xrange[0] > xbounds[0]:
                xrange[0] = deepcopy(xbounds[0])
            if xrange[1] < xbounds[1]:
                xrange[1] = deepcopy(xbounds[1])
            if yrange[0] > ybounds[0]:
                yrange[0] = deepcopy(ybounds[0])
            if yrange[1] < ybounds[1]:
                yrange[1] = deepcopy(ybounds[1])
        self._context.set_xBounds(xrange)
        self._context.set_yBounds(yrange)
        self._x_range_changed(xrange)
        self._y_range_changed(yrange)
        # get tick boxes correct
        errors = self._check_all_errors(names)
        self.quickEdit.set_errors(errors)
        self._change_errors(errors, names)

    """ update GUI """

    def _update_quick_edit(self, subplotName):
        names = self.quickEdit.get_selection()
        xrange = self._context.subplots[subplotName].xbounds
        yrange = self._context.subplots[subplotName].ybounds
        if len(names) == 0:
            return
        # if all selected update everyone
        if len(names) > 1:
            self.quickEdit.set_plot_x_range(xrange)
            self.quickEdit.set_plot_y_range(yrange)
        # if changed current selection
        elif names[0] == subplotName:
            self.quickEdit.set_plot_x_range(xrange)
            self.quickEdit.set_plot_y_range(yrange)
        # if a different plot changed
        else:
            pass

    def _selection_changed(self, index):
        names = self.quickEdit.get_selection()
        xrange = self._context.get_xBounds()
        yrange = self._context.get_yBounds()
        errors = True
        if len(names) == 1:
            xrange = self._context.subplots[names[0]].xbounds
            yrange = self._context.subplots[names[0]].ybounds
            errors = self._context.subplots[names[0]].errors
        else:
            errors = self._check_all_errors(names)
        # update values
        self.quickEdit.set_errors(errors)
        self._change_errors(errors, names)
        self.quickEdit.set_plot_x_range(xrange)
        self.quickEdit.set_plot_y_range(yrange)

        # force update of plots if selection is all
        if len(names) > 1:
            self._x_range_changed(xrange)
            self._y_range_changed(yrange)

    def _autoscale_changed(self, state):
        names = self.quickEdit.get_selection()
        self.plots.set_y_autoscale(names, True)

    def _change_errors(self, state, names):
        self.plots.change_errors(state, names)

    def _errors_changed(self, state):
        names = self.quickEdit.get_selection()
        self._change_errors(state, names)

    def _x_range_changed(self, xRange):
        names = self.quickEdit.get_selection()
        if len(names) > 1:
            self._context.set_xBounds(xRange)
        self.plots.set_plot_x_range(names, xRange)
        self.quickEdit.set_plot_x_range(xRange)

    def _y_range_changed(self, yRange):
        names = self.quickEdit.get_selection()
        if len(names) > 1:
            self._context.set_yBounds(yRange)
        self.plots.set_plot_y_range(names, yRange)
        self.quickEdit.set_plot_y_range(yRange)

    def _check_all_errors(self, names):
        for name in names:
            if self._context.subplots[name].errors is False:
                return False
        return True
Ejemplo n.º 10
0
 def setUp(self):
     self._qapp = mock_widget.mockQapp()
     self.pres = mock.create_autospec(QuickEditPresenter)
     self.widget = QuickEditWidget()
     self.slot = mock.Mock()
     self.widget.set_mock(self.pres)
Ejemplo n.º 11
0
class QuickEditWidgetTest(unittest.TestCase):
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.pres = mock.create_autospec(QuickEditPresenter)
        self.widget = QuickEditWidget()
        self.slot = mock.Mock()
        self.widget.set_mock(self.pres)

    def test_connect_autoscale(self):
        self.widget.connect_autoscale_changed(self.slot)
        self.pres.connect_autoscale_changed.assert_called_with(self.slot)

    def test_connect_errors(self):
        self.widget.connect_errors_changed(self.slot)
        self.pres.connect_errors_changed.assert_called_with(self.slot)

    def test_connect_x_range(self):
        self.widget.connect_x_range_changed(self.slot)
        self.pres.connect_x_range_changed.assert_called_with(self.slot)
 
    def test_connect_y_range(self):
        self.widget.connect_y_range_changed(self.slot)
        self.pres.connect_y_range_changed.assert_called_with(self.slot)

    def test_connect_plot_selection(self):
        self.widget.connect_plot_selection(self.slot)
        self.pres.connect_plot_selection.assert_called_with(self.slot)

    def test_add_subplot(self):
        name = "new plot"
        self.widget.add_subplot(name)
        self.assertEquals(self.pres.add_subplot.call_count, 1)
        self.pres.add_subplot.assert_called_with(name)

    def test_get_selection_one(self):
        name = "one plot"
        self.pres.widget.current_selection = mock.MagicMock(return_value = name)
        output = self.widget.get_selection()
        self.assertEquals([name], output)

    def test_get_selection_all(self):
        name = "All"
        self.pres.widget.current_selection = mock.MagicMock(return_value = name)
        output = self.widget.get_selection()
        self.assertEquals(self.pres.all.call_count, 1)

    def test_set_plot_x_range(self):
        self.widget.set_plot_x_range([0,1])
        self.pres.set_plot_x_range.assert_called_with([0,1])
        
    def test_set_plot_y_range(self):
        self.widget.set_plot_y_range([0,1])
        self.pres.set_plot_y_range.assert_called_with([0,1])
           
    def test_set_errors_TT(self):
        self.widget.set_errors(True)
        self.pres.set_errors.assert_called_with(True)