Ejemplo n.º 1
0
    def __init__(self, context, parent):
        self.inst_view = InstrumentWidgetView(parent)
        self.grp_view = HomeGroupingWidgetView(parent)
        self.run_info_view = HomeRunInfoWidgetView(parent)
        self.plot_view = HomePlotWidgetView(parent)

        # keep a handle to the presenters of sub-widgets
        self.instrument_widget = InstrumentWidgetPresenter(self.inst_view,
                                                           InstrumentWidgetModel(context=context))
        self.group_widget = HomeGroupingWidgetPresenter(self.grp_view, HomeGroupingWidgetModel(context=context))
        self.run_info_widget = HomeRunInfoWidgetPresenter(self.run_info_view,
                                                          HomeRunInfoWidgetModel(context=context))
        self.plot_widget = HomePlotWidgetPresenter(self.plot_view, HomePlotWidgetModel(), context)
        self.home_tab_view = HomeTabView(parent=parent,
                                         widget_list=[self.inst_view,
                                                      self.grp_view,
                                                      self.plot_view,
                                                      self.run_info_view])
        self.home_tab_model = HomeTabModel(context=context)
        self.home_tab_widget = HomeTabPresenter(self.home_tab_view, self.home_tab_model,
                                                subwidgets=[self.instrument_widget,
                                                            self.group_widget,
                                                            self.plot_widget,
                                                            self.run_info_widget])

        context.update_view_from_model_notifier.add_subscriber(self.home_tab_widget.update_view_from_model_observer)
Ejemplo n.º 2
0
    def __init__(self, context, parent):
        self.inst_view = InstrumentWidgetView(parent)
        self.grp_view = HomeGroupingWidgetView(parent)
        self.plot_view = HomePlotWidgetView(parent)
        self.run_info_view = HomeRunInfoWidgetView(parent)

        # keep a handle to the presenters of sub-widgets
        self.instrument_widget = InstrumentWidgetPresenter(
            self.inst_view, InstrumentWidgetModel(muon_data=context))
        self.group_widget = HomeGroupingWidgetPresenter(
            self.grp_view, HomeGroupingWidgetModel(muon_data=context))
        self.plot_widget = HomePlotWidgetPresenter(self.plot_view,
                                                   HomePlotWidgetModel())
        self.run_info_widget = HomeRunInfoWidgetPresenter(
            self.run_info_view, HomeRunInfoWidgetModel(muon_data=context))

        self.home_tab_view = HomeTabView(parent=parent,
                                         widget_list=[
                                             self.inst_view, self.grp_view,
                                             self.plot_view, self.run_info_view
                                         ])
        self.home_tab_model = HomeTabModel(muon_data=context)
        self.home_tab_widget = HomeTabPresenter(self.home_tab_view,
                                                self.home_tab_model,
                                                subwidgets=[
                                                    self.instrument_widget,
                                                    self.group_widget,
                                                    self.plot_widget,
                                                    self.run_info_widget
                                                ])
Ejemplo n.º 3
0
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.obj = QtGui.QWidget()
        self.view = HomePlotWidgetView(self.obj)
        self.model = HomePlotWidgetModel()
        self.presenter = HomePlotWidgetPresenter(self.view, self.model)

        self.view.warning_popup = mock.MagicMock()
Ejemplo n.º 4
0
class HomeTabPlotModelTest(unittest.TestCase):
    def setUp(self):
        self.model = HomePlotWidgetModel()

    def create_workspace(self, name):
        x_range = range(1, 100)
        y_range = [x * x for x in x_range]
        return CreateWorkspace(DataX=x_range,
                               DataY=y_range,
                               OutputWorkspace=name)

    @mock.patch('Muon.GUI.Common.home_plot_widget.home_plot_widget_model.plot')
    def test_plot_creates_new_plot_window_and_plots_workspace_list(
            self, mock_plot):

        workspace_list = [
            'MUSR62260; Group; bottom; Asymmetry; MA',
            'MUSR62261; Group; bottom; Asymmetry; MA'
        ]
        workspace_object_list = [
            self.create_workspace(workspace) for workspace in workspace_list
        ]
        subplot_title = 'MUSR62260 bottom'

        self.model.plot(workspace_list, subplot_title, 'Time', False,
                        'Muon Analysis')

        mock_plot.assert_called_once_with(mock.ANY,
                                          spectrum_nums=[1],
                                          window_title=subplot_title,
                                          errors=True,
                                          plot_kwargs={
                                              'distribution': True,
                                              'autoscale_on_update': False
                                          })
        self.assertEqual(str(mock_plot.call_args[0][0][0]),
                         str(workspace_object_list[0]))
        self.assertEqual(str(mock_plot.call_args[0][0][1]),
                         str(workspace_object_list[1]))
Ejemplo n.º 5
0
 def setUp(self):
     self.model = HomePlotWidgetModel()
class HomeTabPlotModelTest(unittest.TestCase):
    def setUp(self):
        self.model = HomePlotWidgetModel()

    def create_workspace(self, name):
        x_range = range(1, 100)
        y_range = [x * x for x in x_range]
        return CreateWorkspace(DataX=x_range,
                               DataY=y_range,
                               OutputWorkspace=name)

    @mock.patch('Muon.GUI.Common.home_plot_widget.home_plot_widget_model.plot')
    def test_plot_creates_new_plot_window_and_plots_workspace_list(
            self, mock_plot):

        workspace_list = [
            'MUSR62260; Group; bottom; Asymmetry; MA',
            'MUSR62261; Group; bottom; Asymmetry; MA'
        ]
        workspace_object_list = [
            self.create_workspace(workspace) for workspace in workspace_list
        ]
        subplot_title = 'MUSR62260 bottom'

        self.model.plot(workspace_list, subplot_title, 'Time', False,
                        'Muon Analysis')

        mock_plot.assert_called_once_with(mock.ANY,
                                          wksp_indices=[0],
                                          window_title=subplot_title,
                                          errors=True,
                                          plot_kwargs={
                                              'distribution': True,
                                              'autoscale_on_update': False
                                          })
        self.assertEqual(str(mock_plot.call_args[0][0][0]),
                         str(workspace_object_list[0]))
        self.assertEqual(str(mock_plot.call_args[0][0][1]),
                         str(workspace_object_list[1]))

    def test_plot_logic_no_plot(self):
        mock_plot = mock.MagicMock()
        self.model.plot_figure = mock_plot
        workspace_list = []
        subplot_title = 'MUSR62260 bottom'

        self.assertEquals(
            self.model.plot(workspace_list, subplot_title, 'Time', False,
                            'Muon Analysis'), mock_plot)
        self.assertEquals(self.model.plotted_workspaces, [])
        self.assertEquals(self.model.plotted_workspaces_inverse_binning, {})
        self.assertEquals(self.model.plotted_fit_workspaces, [])

    @mock.patch('Muon.GUI.Common.home_plot_widget.home_plot_widget_model.plot')
    def test_plot_logic_force_new(self, mock_plot):

        workspace_list = [
            'MUSR62260; Group; bottom; Asymmetry; MA',
            'MUSR62261; Group; bottom; Asymmetry; MA'
        ]
        workspace_object_list = [
            self.create_workspace(workspace) for workspace in workspace_list
        ]
        subplot_title = 'MUSR62260 bottom'
        self.model.set_x_lim = mock.Mock()
        self.model.plot(workspace_list, subplot_title, 'Time', False,
                        'Muon Analysis')

        mock_plot.assert_called_once_with(mock.ANY,
                                          wksp_indices=[0],
                                          window_title=subplot_title,
                                          errors=True,
                                          plot_kwargs={
                                              'distribution': True,
                                              'autoscale_on_update': False
                                          })

        self.assertEquals(self.model.plot_figure.clear.call_count, 0)
        self.assertEquals(self.model.set_x_lim.call_count, 1)
        workspace_list = [
            'MUSR62260; Group; top; Asymmetry; MA',
            'MUSR62261; Group; top; Asymmetry; MA'
        ]
        workspace_object_list = [
            self.create_workspace(workspace) for workspace in workspace_list
        ]
        subplot_title = 'MUSR62260 top'

        self.model.plot(workspace_list, subplot_title, 'Time', True,
                        'Muon Analysis')
        self.assertEquals(self.model.plot_figure.clear.call_count, 1)
        self.assertEquals(self.model.set_x_lim.call_count, 2)

        self.assertEquals(mock_plot.call_count, 2)
        mock_plot.assert_any_call(mock.ANY,
                                  wksp_indices=[0],
                                  fig=self.model.plot_figure,
                                  window_title=subplot_title,
                                  plot_kwargs={
                                      'distribution': True,
                                      'autoscale_on_update': False
                                  },
                                  errors=True)