Source code for exopy.measurement.editors.base_editor

# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright 2015-2018 by Exopy Authors, see AUTHORS for more details.
#
# Distributed under the terms of the BSD license.
#
# The full license is in the file LICENCE, distributed with this software.
# -----------------------------------------------------------------------------
"""Base classes for all editors.

"""
from atom.api import Str, Typed, Bool, ForwardTyped, Int
from enaml.core.api import Declarative, d_, d_func
from enaml.widgets.api import Page

from ...utils.enaml_destroy_hook import add_destroy_hook
from ...tasks.api import BaseTask


DestroyablePage = add_destroy_hook(Page)


[docs]class BaseEditor(DestroyablePage): """Base class for all editors. """ #: Declaration defining this editor. declaration = ForwardTyped(lambda: Editor) #: Currently selected task in the tree. selected_task = d_(Typed(BaseTask)) #: Should the tree be visible when this editor is selected. tree_visible = d_(Bool(True)) #: Should the tree be enabled when this editor is selected. tree_enabled = d_(Bool(True))
[docs] @d_func def react_to_selection(self, workbench): """Take any necessary actions when the editor is selected. This method is called by the framework at the appropriate time. Parameters ---------- workbench : Workbench Reference to the application workbench. """ pass
[docs] @d_func def react_to_unselection(self, workbench): """Take any necessary actions when the editor is unselected. This method is called by the framework at the appropriate time. Parameters ---------- workbench : Workbench Reference to the application workbench. """ pass
def _default_name(self): """Set the name of the widget otherwise the notebook does not work well """ return self.declaration.id
[docs]class Editor(Declarative): """A declarative class for contributing a measurement editor. Editor object can be contributed as extensions child to the 'editors' extension point of the 'exopy.measurement' plugin. """ #: Unique name used to identify the editor. #: The usual format is top_level_package_name.tool_name id = d_(Str()) #: Editor description. description = d_(Str()) #: Rank of this editor. Editors are displayed by rank and alphabetical #: order rank = d_(Int(100))
[docs] @d_func def new(self, workbench, default=True): """Create a new instance of the editor. Parameters ---------- workbench : Workbench Reference to the application workbench. default : bool Whether to use default parameters or not when creating the object. """ raise NotImplementedError()
[docs] @d_func def is_meant_for(self, workbench, selected_task): """Determine if the editor is fit to be used for the selected task. Parameters ---------- workbench : Workbench Reference to the application workbench. selected_task : BaseTask Currently selected task. Returns ------- answer : bool """ raise NotImplementedError()