How to use the traits.api.Instance function in traits

To help you get started, we’ve selected a few traits examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enthought / chaco / chaco / tools / range_selection.py View on Github external
left_button_selects = Bool(False)

    # Disable all left-mouse button interactions?
    disable_left_mouse = Bool(False)

    # Allow the tool to be put into the deselected state via mouse clicks
    allow_deselection = Bool(True)

    # The minimum span, in pixels, of a selection region.  Any attempt to
    # select a region smaller than this will be treated as a deselection.
    minimum_selection = Int(5)

    # The key which, if held down while the mouse is being dragged, will
    # indicate that the selection should be appended to an existing selection
    # as opposed to overwriting it.
    append_key = Instance(KeySpec, args=(None, "control"))

    #------------------------------------------------------------------------
    # Private traits
    #------------------------------------------------------------------------

    # The value of the override plot to use, if any.  If None, then uses
    # self.component.
    _plot = Trait(None, Any)

    # The value of the override mapper to use, if any.  If None, then uses the
    # mapper on self.component.
    _mapper = Trait(None, Any)

    # Shadow trait for the **axis_index** property.
    _axis_index = Trait(None, None, Int)
github enthought / pyface / pyface / tasks / task_layout.py View on Github external
class Splitter(LayoutContainer):
    """ A split area in a Task layout.
    """

    # The orientation of the splitter.
    orientation = Enum("horizontal", "vertical")

    # The sub-items of the splitter, which are PaneItems, Tabbed layouts, and
    # other Splitters.
    items = List(
        Either(
            Instance(PaneItem),
            Instance(Tabbed),
            Instance("pyface.tasks.task_layout.Splitter"),
        ),
        pretty_skip=True,
    )


class HSplitter(Splitter):
    """ A convenience class for horizontal splitters.
    """

    orientation = Str("horizontal")


class VSplitter(Splitter):
    """ A convenience class for vertical splitters.
    """
github enthought / pyface / pyface / workbench / workbench.py View on Github external
# The active workbench window (the last one to get focus).
    active_window = Instance(WorkbenchWindow)

    # The editor manager is used to create/restore editors.
    editor_manager = Instance(IEditorManager)

    # The optional application scripting manager.
    script_manager = Instance("apptools.appscripting.api.IScriptManager")

    # A directory on the local file system that we can read and write to at
    # will. This is used to persist window layout information, etc.
    state_location = Str()

    # The optional undo manager.
    undo_manager = Instance("apptools.undo.api.IUndoManager")

    # The user-defined perspectives manager.
    user_perspective_manager = Instance(UserPerspectiveManager)

    # All of the workbench windows created by the workbench.
    windows = List(WorkbenchWindow)

    # Workbench lifecycle events -------------------------------------------

    # Fired when the workbench is about to exit.
    #
    # This can be caused by either:-
    #
    # a) The 'exit' method being called.
    # b) The last open window being closed.
    #
github hyperspy / hyperspy / hyperspy / defaults_parser.py View on Github external
if not defaults_file_exists or rewrite is True:
    _logger.info('Writing the config file')
    with open(defaults_file, "w") as df:
        config.write(df)

# Use the traited classes to cast the content of the ConfigParser
config2template(template, config)


@add_gui_method(toolkey="Preferences")
class Preferences(t.HasTraits):
    EELS = t.Instance(EELSConfig)
    EDS = t.Instance(EDSConfig)
    General = t.Instance(GeneralConfig)
    GUIs = t.Instance(GUIs)
    Plot = t.Instance(PlotConfig)

    def save(self):
        config = configparser.ConfigParser(allow_no_value=True)
        template2config(template, config)
        config.write(open(defaults_file, 'w'))


preferences = Preferences(
    EELS=template['EELS'],
    EDS=template['EDS'],
    General=template['General'],
    GUIs=template['GUIs'],
    Plot=template['Plot'],
)
github enthought / mayavi / mayavi / core / mouse_pick_dispatcher.py View on Github external
################################################################################
# class `MousePickDispatcher`
################################################################################
class MousePickDispatcher(HasTraits):
    """ An event dispatcher to send pick event on mouse clicks.

        This objects wires VTK observers so that picking callbacks
        can be bound to mouse click without movement.

        The object deals with adding and removing the VTK-level
        callbacks.
    """

    # The scene events are wired to.
    scene = Instance(Scene)

    # The list of callbacks, with the picker type they should be using,
    # and the mouse button that triggers them.
    callbacks = List(Tuple(
                        Callable,
                        Enum('cell', 'point', 'world'),
                        Enum('Left', 'Middle', 'Right'),
                        ),
                    help="The list of callbacks, with the picker type they "
                         "should be using, and the mouse button that "
                         "triggers them. The callback is passed "
                         "as an argument the tvtk picker."
                    )

    #--------------------------------------------------------------------------
    # Private traits
github NMGRL / pychron / pychron / experiment / experiment_executor.py View on Github external
connectables = List
    active_editor = Any
    console_bgcolor = 'black'
    selected_run = Instance('pychron.experiment.automated_run.spec.AutomatedRunSpec', )
    autoplot_event = Event
    run_completed = Event

    ms_pumptime_start = None
    # ===========================================================================
    # control
    # ===========================================================================

    can_start = Property(depends_on='executable, _alive')
    delaying_between_runs = Bool
    experiment_status = Instance(ExperimentStatus, ())

    end_at_run_completion = Bool(False)
    truncate_style = Enum('Normal', 'Quick')
    '''
        immediate 0= measure_iteration stopped at current step, script continues
        quick     1= measure_iteration stopped at current step, script continues using 0.25*counts

        old-style
            immediate 0= is the standard truncation, measure_iteration stopped at current step and measurement_script
                         truncated
            quick     1= the current measure_iteration is truncated and a quick baseline is collected, peak center?
            next_int. 2= same as setting ncounts to < current step. measure_iteration is truncated but script continues
    '''
    # ===========================================================================
    #
    # ===========================================================================
github aestrivex / cvu / cvu / viewport.py View on Github external
#FIXME there is no reason to have modular viewports anymore since as
    #it turns out the viewport has to be rebuilt in order to update the view.
    #this is something that could be modularly managed.
    #The benefit of changing what now works is however low.  It is basically
    #a very weak form of static type checking, and a way to save a miniscule
    #amount of time and space on managing pointers.




    #by keeping these views on the viewport object itself, we can change
    #the dataset without making traitsui think that the view is inaccessible
    #and it is time to be thrown away immediately upon loading a new dataset
    scene=Instance(MlabSceneModel)
    conn_mat=Instance(Plot)
    circ=Instance(Figure)

    view_type=Enum('dummy','3D Brain','Connection Matrix','Circular plot')

    dummy_view=View(
        Item(editor=NullEditor(),height=500,width=500,label='empty'))

    mayavi_view=View(
        Item(name='scene',
            editor=SceneEditor(scene_class=MayaviScene),
            height=500,width=500,show_label=False,resizable=True))

    matrix_view=View(
        Item(name='conn_mat',
            editor=ComponentEditor(),
            height=500,width=500,show_label=False,resizable=True))
github NMGRL / pychron / pychron / experiment / stats.py View on Github external
from traits.api import Property, String, Float, Any, Int, List, Instance

from pychron.core.helpers.timer import Timer
from pychron.experiment.duration_tracker import AutomatedRunDurationTracker
from pychron.loggable import Loggable
from pychron.pychron_constants import NULL_STR


class ExperimentStats(Loggable):
    delay_between_analyses = Float
    delay_before_analyses = Float
    delay_after_blank = Float
    delay_after_air = Float

    duration_tracker = Instance(AutomatedRunDurationTracker, ())

    def update_run_duration(self, run, t):
        a = self.duration_tracker
        a.update(run, t)

    def calculate_duration(self, runs=None):
        self.duration_tracker.load()
        dur = self._calculate_duration(runs)
        return dur

        # self._total_time = dur
        # return self._total_time

    def get_run_duration(self, run, as_str=False):
        sh = run.script_hash
        if sh in self.duration_tracker:
github gallantlab / pycortex / cortex / mayavi_aligner.py View on Github external
self.circle.data.points = np.array(self._gen_circle()).T
    
    @on_trait_change("enabled")
    def _enable(self):
        if self.enabled:
            self.center.on()
            self.edge.on()
        else:
            self.center.off()
            self.edge.off()
        
        self.circle.visible = self.enabled

class ThreeDScene(MayaviScene):
    #this will not work for qt4 windows, but its functionality is not important!
    aligner = Instance("Align")
    state = Array(value=[1,1,1])

    def OnKeyDown(self, evt):
        key = chr(evt.GetKeyCode() % 256)
        focus = self.aligner.scene_3d.camera.focal_point
        if key == "1":
            self.aligner.scene_3d.camera.position = focus + [0, self.state[1]*500, 0]
            self.state[1] = -self.state[1]
        elif key == "3":
            self.aligner.scene_3d.camera.position = focus + [self.state[0]*500, 0, 0]
            self.state[0] = -self.state[0]
        elif key == "5":
            self.aligner.scene_3d.parallel_projection = not self.aligner.scene_3d.parallel_projection
        elif key == "7":
            self.aligner.scene_3d.camera.position = focus + [0, 1e-6, self.state[2]*500]
            self.state[2] = -self.state[2]
github enthought / pyface / pyface / ui / wx / action / tool_bar_manager.py View on Github external
# The toolbar name (used to distinguish multiple toolbars).
    name = Str("ToolBar")

    # The orientation of the toolbar.
    orientation = Enum("horizontal", "vertical")

    # Should we display the name of each tool bar tool under its image?
    show_tool_names = Bool(True)

    # Should we display the horizontal divider?
    show_divider = Bool(False)

    # Private interface ----------------------------------------------------

    # Cache of tool images (scaled to the appropriate size).
    _image_cache = Instance(ImageCache)

    # ------------------------------------------------------------------------
    # 'object' interface.
    # ------------------------------------------------------------------------

    def __init__(self, *args, **traits):
        """ Creates a new tool bar manager. """

        # Base class contructor.
        super(ToolBarManager, self).__init__(*args, **traits)

        # An image cache to make sure that we only load each image used in the
        # tool bar exactly once.
        self._image_cache = ImageCache(self.image_size[0], self.image_size[1])

        return