Beispiel #1
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)
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)
Beispiel #3
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
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
Beispiel #5
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