def insert_plot_panes(self):
     self.presenter = MainPlotWidgetPresenter(self.view, self._panes)
     self._current_plot_mode = self.presenter.get_plot_mode
     self.presenter.set_plot_mode_changed_slot(self.handle_plot_mode_changed_by_user)
     # add the observers
     for observer in self.presenter.workspace_replaced_in_ads_observers:
         self._context.update_plots_notifier.add_subscriber(observer)
     for observer in self.presenter.workspace_deleted_from_ads_observers:
         self._context.deleted_plots_notifier.add_subscriber(observer)
예제 #2
0
    def __init__(self,
                 context=None,
                 get_active_fit_results=lambda: [],
                 parent=None):

        self.data_model = EAPlotDataPaneModel(context)

        self.plotting_canvas_widgets = {
            self.data_model.name:
            PlottingCanvasWidget(
                parent,
                context=context.plot_panes_context[self.data_model.name],
                plot_model=self.data_model)
        }

        # The UI view
        self._view1 = BasePaneView(parent)
        self._view1.add_canvas_widget(
            self.plotting_canvas_widgets[self.data_model.name].widget)

        # set up presenter
        self.view = MainPlotWidgetView(parent)
        self.model = EAPlotDataPaneModel(context)
        # generate the presenter

        self.data_mode = EAPlotDataPanePresenter(
            self._view1, self.data_model, context,
            self.plotting_canvas_widgets[self.data_model.name].presenter)

        self.presenter = MainPlotWidgetPresenter(self.view, [self.data_mode])
        self._current_plot_mode = self.presenter.get_plot_mode
        self.presenter.set_plot_mode_changed_slot(
            self.handle_plot_mode_changed_by_user)

        for observer in self.presenter.workspace_replaced_in_ads_observers:
            context.update_plots_notifier.add_subscriber(observer)
        for observer in self.presenter.workspace_deleted_from_ads_observers:
            context.deleted_plots_notifier.add_subscriber(observer)
예제 #3
0
class EAPlotWidget(object):
    def __init__(self,
                 context=None,
                 get_active_fit_results=lambda: [],
                 parent=None):

        self.data_model = EAPlotDataPaneModel(context)

        self.plotting_canvas_widgets = {
            self.data_model.name:
            PlottingCanvasWidget(
                parent,
                context=context.plot_panes_context[self.data_model.name],
                plot_model=self.data_model)
        }

        # The UI view
        self._view1 = BasePaneView(parent)
        self._view1.add_canvas_widget(
            self.plotting_canvas_widgets[self.data_model.name].widget)

        # set up presenter
        self.view = MainPlotWidgetView(parent)
        self.model = EAPlotDataPaneModel(context)
        # generate the presenter

        self.data_mode = EAPlotDataPanePresenter(
            self._view1, self.data_model, context,
            self.plotting_canvas_widgets[self.data_model.name].presenter)

        self.presenter = MainPlotWidgetPresenter(self.view, [self.data_mode])
        self._current_plot_mode = self.presenter.get_plot_mode
        self.presenter.set_plot_mode_changed_slot(
            self.handle_plot_mode_changed_by_user)

        for observer in self.presenter.workspace_replaced_in_ads_observers:
            context.update_plots_notifier.add_subscriber(observer)
        for observer in self.presenter.workspace_deleted_from_ads_observers:
            context.deleted_plots_notifier.add_subscriber(observer)

    def set_plot_view(self, plot_mode):
        self.view.set_plot_mode(plot_mode)

    @property
    def data_changed_observers(self):
        return self.presenter.data_changed_observers

    @property
    def workspace_deleted_from_ads_observers(self):
        return self.presenter.workspace_deleted_from_ads_observers

    @property
    def rebin_options_set_observers(self):
        return self.presenter.rebin_options_set_observers

    @property
    def data_index(self):
        return self.view.get_index(self.data_mode.name)

    def handle_plot_mode_changed_by_user(self):
        pass

    def close(self):
        self.view.close()
    def __init__(self,
                 context=None,
                 get_active_fit_results=lambda: [],
                 parent=None):
        self.data_model = PlotDataPaneModel(context)
        self.fit_model = PlotFreqFitPaneModel(context)
        #self.raw_model = RawPaneModel(context)
        self.plot_maxent_model = DualPlotMaxentPaneModel(
            context, self.data_model, RawPaneModel(context))
        #models = [self.data_model, self.fit_model, self.raw_model, self.plot_maxent_model]
        models = [self.data_model, self.fit_model, self.plot_maxent_model]

        self.view = MainPlotWidgetView(parent)
        self.model = PlotDataPaneModel(context)
        # The plotting canvas widgets
        self.plotting_canvas_widgets = {}
        # The UI view
        self._views = {}

        for model in models:

            if model == self.plot_maxent_model:
                dual_quick_edit = DualQuickEditWidget(
                    context.plot_panes_context[model.name], parent)
                self.plotting_canvas_widgets[
                    model.name] = PlottingCanvasWidget(
                        parent,
                        context=context.plot_panes_context[model.name],
                        plot_model=model,
                        figure_options=dual_quick_edit)
                self._views[model.name] = DualPlotMaxentPaneView(parent)

            #elif model == self.raw_model:
            #    self.plotting_canvas_widgets[model.name] = PlottingCanvasWidget(parent, context=
            #                                                                     context.plot_panes_context[model.name],
            #                                                                     plot_model=model)
            #    self._views[model.name] = RawPaneView(parent)

            else:
                self.plotting_canvas_widgets[
                    model.name] = PlottingCanvasWidget(
                        parent,
                        context=context.plot_panes_context[model.name],
                        plot_model=model)
                self._views[model.name] = BasePaneView(parent)
            self._views[model.name].add_canvas_widget(
                self.plotting_canvas_widgets[model.name].widget)

        #self.plotting_canvas_widgets[self.raw_model.name].disable_plot_selection()
        # set up presenter

        # generate the presenters
        name = self.data_model.name
        self.data_mode = PlotDataPanePresenter(
            self._views[name], self.data_model, context,
            self.plotting_canvas_widgets[name].presenter)

        name = self.fit_model.name
        self.fit_mode = PlotFreqFitPanePresenter(
            self._views[name], self.fit_model, context,
            context.fitting_context,
            self.plotting_canvas_widgets[name].presenter)

        #name = self.raw_model.name
        #self.raw_mode = RawPanePresenter(self._views[name], self.raw_model,
        #                                         context,self.plotting_canvas_widgets[name].presenter)

        name = self.plot_maxent_model.name
        self.maxent_mode = DualPlotMaxentPanePresenter(
            self._views[name], self.plot_maxent_model, context,
            self.plotting_canvas_widgets[name].presenter)

        self.presenter = MainPlotWidgetPresenter(
            self.view, [self.data_mode, self.fit_mode, self.maxent_mode])
        #[self.data_mode, self.raw_mode, self.fit_mode, self.maxent_mode])

        self._current_plot_mode = self.presenter.get_plot_mode
        self.presenter.set_plot_mode_changed_slot(
            self.handle_plot_mode_changed_by_user)

        for observer in self.presenter.workspace_replaced_in_ads_observers:
            context.update_plots_notifier.add_subscriber(observer)
        for observer in self.presenter.workspace_deleted_from_ads_observers:
            context.deleted_plots_notifier.add_subscriber(observer)
class MuonAnalysisPlotWidget(object):
    def __init__(self, context=None, parent=None):
        self._parent = parent
        self._context = context
        self._panes = []
        self.modes = {}
        self._create_default_panes()

    def _create_default_panes(self):
        self.view = MainPlotWidgetView(self._parent)
        # The plotting canvas widgets
        self.plotting_canvas_widgets = {}
        # The UI view
        self._views = {}
        # create default panes
        self.create_data_pane()
        self.create_fit_pane()

    def insert_plot_panes(self):
        self.presenter = MainPlotWidgetPresenter(self.view, self._panes)
        self._current_plot_mode = self.presenter.get_plot_mode
        self.presenter.set_plot_mode_changed_slot(self.handle_plot_mode_changed_by_user)
        # add the observers
        for observer in self.presenter.workspace_replaced_in_ads_observers:
            self._context.update_plots_notifier.add_subscriber(observer)
        for observer in self.presenter.workspace_deleted_from_ads_observers:
            self._context.deleted_plots_notifier.add_subscriber(observer)

    @property
    def clear_plot_observers(self):
        return self.presenter.clear_plot_observers

    @property
    def data_changed_observers(self):
        return self.presenter.data_changed_observers

    def close(self):
        self.view.close()

    def set_plot_view(self, plot_mode):
        self.view.set_plot_mode(plot_mode)

    @property
    def rebin_options_set_observers(self):
        return self.presenter.rebin_options_set_observers

    def mode_name(self, name):
        if name in self.modes.keys():
            return self.modes[name].name
        else:
            return None

    def handle_plot_mode_changed_by_user(self):
        old_plot_mode = self._current_plot_mode
        self._current_plot_mode = self.presenter.get_plot_mode
        if old_plot_mode == self._current_plot_mode:
            return

        if old_plot_mode == self.mode_name(DATA) or old_plot_mode == self.mode_name(FIT):
            # make sure the fit and data pane quickedits are sync'd
            pane_to_match = self.mode_name(FIT) if old_plot_mode == self.mode_name(DATA) else self.mode_name(DATA)
            selection, x_range, auto, y_range, errors = self.plotting_canvas_widgets[old_plot_mode].get_quick_edit_info
            self.plotting_canvas_widgets[pane_to_match].set_quick_edit_info(selection, x_range, auto, y_range,
                                                                                  errors)

        if self._current_plot_mode==self.mode_name(RAW):
            # plot the raw data
            self.modes[RAW].handle_data_updated()

        self.presenter.hide(old_plot_mode)
        self.presenter.show(self._current_plot_mode)

    """ data pane """

    def create_data_pane(self):
        self.data_model = PlotDataPaneModel(self._context)
        # names need to match the model for the use outside of this file
        name = self.data_model.name
        self.plotting_canvas_widgets[name] = PlottingCanvasWidget(self._parent, context=
                                                                        self._context.plot_panes_context[name],
                                                                        plot_model=self.data_model)
        self._views[name] = BasePaneView(self._parent)
        self._views[name].add_canvas_widget(self.plotting_canvas_widgets[name].widget)

        self.modes[DATA] = PlotDataPanePresenter(self._views[name], self.data_model,
                                                 self._context,self.plotting_canvas_widgets[name].presenter)
        self._panes.append(self.modes[DATA])

    @property
    def data_index(self):
        return self.view.get_index(self.mode_name(DATA))

    @property
    def data_mode(self):
        return self.modes[DATA]

    """ Fit pane """
    def create_fit_pane(self):
        self.fit_model = PlotTimeFitPaneModel(self._context)
        name = self.fit_model.name
        self.plotting_canvas_widgets[name] = PlottingCanvasWidget(self._parent, context=
                                                                        self._context.plot_panes_context[name],
                                                                        plot_model=self.fit_model)
        self._views[name] = BasePaneView(self._parent)
        self._views[name].add_canvas_widget(self.plotting_canvas_widgets[name].widget)

        self.modes[FIT] = PlotFitPanePresenter(self._views[name], self.fit_model,
                                               self._context,self._context.fitting_context,
                                               self.plotting_canvas_widgets[name].presenter)
        self._panes.append(self.modes[FIT])

    @property
    def fit_index(self):
        return self.view.get_index(self.mode_name(FIT))

    @property
    def fit_mode(self):
        return self.modes[FIT]

    """ raw pane """
    def create_raw_pane(self):
        self.raw_model = RawPaneModel(self._context)
        name =self.raw_model.name
        self.plotting_canvas_widgets[name] = PlottingCanvasWidget(self._parent, context=
                                                                        self._context.plot_panes_context[name],
                                                                        plot_model=self.raw_model)
        self._views[name] = RawPaneView(self._parent)
        self._views[name].add_canvas_widget(self.plotting_canvas_widgets[name].widget)

        self.modes[RAW] = RawPanePresenter(self._views[name], self.raw_model,
                                                 self._context,self.plotting_canvas_widgets[name].presenter)
        self._panes.append(self.modes[RAW])

    @property
    def raw_index(self):
        if self.mode_name(RAW):
            return self.view.get_index(self.mode_name(RAW))
        else:
            # default to data if no model plot
            return self.view.get_index(self.mode_name(DATA))

    @property
    def raw_mode(self):
        return self.modes[RAW]

    """ model pane """
    def create_model_fit_pane(self):
        self.model_fit_model = PlotModelFitPaneModel(self._context)
        name = self.model_fit_model.name
        self.plotting_canvas_widgets[name] = PlottingCanvasWidget(self._parent, context=
                                                                        self._context.plot_panes_context[name],
                                                                        plot_model=self.model_fit_model)

        self._views[name] = BasePaneView(self._parent)
        self._views[name].add_canvas_widget(self.plotting_canvas_widgets[name].widget)

        self.modes[MODEL] = PlotModelFitPanePresenter(self._views[name], self.model_fit_model, self._context,
                                                        self._context.model_fitting_context,
                                                        self.plotting_canvas_widgets[name].presenter)
        self._panes.append(self.modes[MODEL])

    @property
    def model_fit_index(self):
        if self.mode_name(MODEL):
            return self.view.get_index(self.mode_name(MODEL))
        else:
            # default to fit if no model plot
            return self.view.get_index(self.mode_name(FIT))

    @property
    def model_fit_mode(self):
        return self.modes[MODEL]
class MuonAnalysisPlotWidget(object):
    def __init__(self,
                 context=None,
                 get_active_fit_results=lambda: [],
                 parent=None):

        self.data_model = PlotDataPaneModel(context)
        self.fit_model = PlotTimeFitPaneModel(context)

        #self.raw_model = RawPaneModel(context)
        #self.model_fit_model = PlotModelFitPaneModel(context)
        models = [self.data_model,
                  self.fit_model]  #, self.model_fit_model, self.raw_model]

        self.view = MainPlotWidgetView(parent)
        self.model = PlotDataPaneModel(context)
        # The plotting canvas widgets
        self.plotting_canvas_widgets = {}
        # The UI view
        self._views = {}

        for model in models:
            self.plotting_canvas_widgets[model.name] = PlottingCanvasWidget(
                parent,
                context=context.plot_panes_context[model.name],
                plot_model=model)
            #if model == self.raw_model:
            #    self._views[model.name] = RawPaneView(parent)
            #else:
            self._views[model.name] = BasePaneView(parent)
            self._views[model.name].add_canvas_widget(
                self.plotting_canvas_widgets[model.name].widget)

        #self.plotting_canvas_widgets[self.raw_model.name].disable_plot_selection()
        # set up presenter

        # generate the presenters
        name = self.data_model.name
        self.data_mode = PlotDataPanePresenter(
            self._views[name], self.data_model, context,
            self.plotting_canvas_widgets[name].presenter)

        name = self.fit_model.name
        self.fit_mode = PlotFitPanePresenter(
            self._views[name], self.fit_model, context,
            context.fitting_context,
            self.plotting_canvas_widgets[name].presenter)

        #name = self.model_fit_model.name
        #self.model_fit_mode = PlotModelFitPanePresenter(self._views[name], self.model_fit_model, context,
        #                                                context.model_fitting_context,
        #                                                self.plotting_canvas_widgets[name].presenter)
        #name = self.raw_model.name
        #self.raw_mode = RawPanePresenter(self._views[name], self.raw_model,
        #                                         context,self.plotting_canvas_widgets[name].presenter)

        self.presenter = MainPlotWidgetPresenter(
            self.view, [self.data_mode, self.fit_mode])
        #[self.data_mode, self.raw_mode, self.fit_mode, self.model_fit_mode])

        self._current_plot_mode = self.presenter.get_plot_mode
        self.presenter.set_plot_mode_changed_slot(
            self.handle_plot_mode_changed_by_user)

        for observer in self.presenter.workspace_replaced_in_ads_observers:
            context.update_plots_notifier.add_subscriber(observer)
        for observer in self.presenter.workspace_deleted_from_ads_observers:
            context.deleted_plots_notifier.add_subscriber(observer)

    def set_plot_view(self, plot_mode):
        self.view.set_plot_mode(plot_mode)

    @property
    def clear_plot_observers(self):
        return self.presenter.clear_plot_observers

    @property
    def data_changed_observers(self):
        return self.presenter.data_changed_observers

    @property
    def rebin_options_set_observers(self):
        return self.presenter.rebin_options_set_observers

    @property
    def data_index(self):
        return self.view.get_index(self.data_mode.name)

    @property
    def fit_index(self):
        return self.view.get_index(self.fit_mode.name)

    #@property
    #def raw_index(self):
    #    self.view.get_index(self.raw_mode.name)

    @property
    def model_fit_index(self):
        return self.view.get_index(self.model_fit_mode.name)

    def close(self):
        self.view.close()

    def handle_plot_mode_changed_by_user(self):
        old_plot_mode = self._current_plot_mode
        self._current_plot_mode = self.presenter.get_plot_mode
        if old_plot_mode == self.data_mode.name or old_plot_mode == self.fit_mode.name:
            pane_to_match = self.fit_mode.name if old_plot_mode == self.data_mode.name else self.data_mode.name
            selection, x_range, auto, y_range, errors = self.plotting_canvas_widgets[
                pane_to_match].get_quick_edit_info
            self.plotting_canvas_widgets[pane_to_match].set_quick_edit_info(
                selection, x_range, auto, y_range, errors)

        #if self._current_plot_mode==self.raw_mode.name:
        #    self.raw_mode.handle_data_updated()

        self.presenter.hide(old_plot_mode)
        self.presenter.show(self._current_plot_mode)