How to use the enable.component.Component function in enable

To help you get started, we’ve selected a few enable 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 / enable / enable / controls.py View on Github external
def __init__ ( self, text = '', **traits ):
        self.text = text
        Component.__init__( self, **traits )
github enthought / enable / enable / primitives / image.py View on Github external
""" Defines the Image component class.
"""

from __future__ import absolute_import

# Enthought library imports
from traits.api import Array, Bool, Enum, Instance, Property, cached_property

# Local imports
from enable.component import Component
from kiva.image import GraphicsContext


class Image(Component):
    """ Component that displays a static image

    This is extremely simple right now.  By default it will draw the array into
    the entire region occupied by the component, stretching or shrinking as
    needed.  By default the bounds are set to the width and height of the data
    array, and we provide the same information to constraints-based layout
    with the layout_size_hint trait.

    """

    #: the image data as an array
    data = Array(shape=(None, None, (3,4)), dtype='uint8')

    #: the format of the image data (eg. RGB vs. RGBA)
    format = Property(Enum('rgb24', 'rgba32'), depends_on='data')
github enthought / enable / enable / abstract_overlay.py View on Github external
""" Abstract base class for overlays.

This class is primarily used so that tools can easily distinguish between
items underneath them.
"""

from traits.api import Instance

from .component import Component


class AbstractOverlay(Component):
    """ The base class for overlays and underlays of the area.

    The only default additional feature of an overlay is that it implements
    an overlay() drawing method that overlays this component on top of
    another, without the components necessarily having an object
    containment-ownership relationship.
    """

    # The component that this object overlays. This can be None. By default, if
    # this object is called to draw(), it tries to render onto this component.
    component = Instance(Component)

    # The default layer that this component draws into.
    draw_layer = "overlay"

    # The background color (overrides PlotComponent).
github enthought / enable / enable / base_tool.py View on Github external
return cls(key, *modifiers, ignore=ignore)



class BaseTool(Interactor):
    """ The base class for Chaco tools.

    Tools are not Enable components, but they can draw.  They do not
    participate in layout, but are instead attached to a Component, which
    dispatches methods to the tool and calls the tools' draw() method.

    See docs/event_handling.txt for more information on how tools are structured.
    """

    # The component that this tool is attached to.
    component = Instance(Component)

    # Is this tool's visual representation visible?  For passive inspector-type
    # tools, this is a constant value set in the class definition;
    # for stateful or modal tools, the tool's listener sets this attribute.
    visible = Bool(False)

    # How the tool draws on top of its component.  This, in conjuction with a
    # a tool's status on the component, is used by the component to determine
    # how to render itself.  In general, the meanings of the draw modes are:
    #
    # normal:
    #     The appearance of part of the component is modified such that
    #     the component is redrawn even if it has not otherwise
    #     received any indication that its previous rendering is invalid.
    #     The tool controls its own drawing loop, and calls out to this
    #     tool after it is done drawing itself.
github enthought / enable / enable / viewport.py View on Github external
def _dispatch_stateful_event(self, event, suffix):
        if isinstance(self.component, Component):
            transform = self.get_event_transform(event, suffix)
            event.push_transform(transform, caller=self)
            try:
                self.component.dispatch(event, suffix)
            finally:
                event.pop(caller=self)

        return
github enthought / enable / enable / viewport.py View on Github external
from enable.tools.viewport_zoom_tool import ViewportZoomTool
from enable.simple_layout import simple_container_get_preferred_size, \
                                            simple_container_do_layout
from traits.api import (Bool, Delegate, Float, Instance, Enum, List,
        Any, on_trait_change)
from kiva import affine

# Local relative imports
from .enable_traits import bounds_trait, coordinate_trait
from .base import empty_rectangle, intersect_bounds
from .component import Component
from .container import Container
from .canvas import Canvas


class Viewport(Component):
    """
    A "window" or "view" into a sub-region of another component.
    """

    # The component we are viewing
    component = Instance(Component)

    # The position of our viewport into our component (in the component's
    # coordinate space)
    view_position = coordinate_trait

    # The bounds of our viewport in the space of our component
    view_bounds = bounds_trait

    # Whether or not this viewport should stay constrained to the bounds
    # of the viewed component
github enthought / enable / enable / primitives / shape.py View on Github external
# Standard library imports.
from __future__ import print_function

import math

# Enthought library imports.
from enable.colors import ColorTrait
from enable.component import Component
from enable.enable_traits import Pointer
from kiva.constants import MODERN
from kiva.fonttools import Font
from traits.api import Float, Property, Str, Tuple


class Shape(Component):
    """ The base class for moveable shapes. """

    #### 'Component' interface ################################################

    # The background color of this component.
    bgcolor = 'transparent'

    #### 'Shape' interface ####################################################

    # The coordinates of the center of the shape.
    center = Property(Tuple)

    # The fill color.
    fill_color = ColorTrait

    # The pointer for the 'normal' event state.
github enthought / enable / enable / canvas.py View on Github external
def _bounds_changed(self, old, new):
        Component._bounds_changed(self, old, new)
        self.invalidate_draw()
github enthought / enable / enable / viewport.py View on Github external
def get_event_transform(self, event=None, suffix=""):
        transform = affine.affine_identity()

        if isinstance(self.component, Component):
            # If we have zoom enabled, scale events.  Since affine transforms
            # multiply from the left, we build up the transform from the
            # inside of the viewport outwards.
            if self.enable_zoom and self.zoom != 1.0:
                transform = affine.translate(transform, *self.view_position)
                transform = affine.scale(transform, 1/self.zoom, 1/self.zoom)
                transform = affine.translate(transform, -self.outer_position[0],
                                                        -self.outer_position[1])
            else:
                x_offset = self.view_position[0] - self.outer_position[0]
                y_offset = self.view_position[1] - self.outer_position[1]
                transform = affine.translate(transform, x_offset, y_offset)

        return transform
github NMGRL / pychron / pychron / managers / bandwidth_imager.py View on Github external
color = Color
    use = Bool(False)
    def traits_view(self):
        v = View(HGroup(Item('use', show_label=False,), Item('center'), Item('threshold'), Item('color', style='custom', show_label=False)))
        return v

class BandwidthImager(HasTraits):
    use_threshold = Bool(False)
    low = Int(120, enter_set=True, auto_set=False)
    high = Int(150, enter_set=True, auto_set=False)
    contrast_low = Int(2, enter_set=True, auto_set=False)
    contrast_high = Int(98, enter_set=True, auto_set=False)
    histogram_equalize = Bool(False)
    container = Instance(HPlotContainer)
    plot = Instance(Component)
    oplot = Instance(Component)
    highlight = Int(enter_set=True, auto_set=False)
    highlight_threshold = Int(enter_set=True, auto_set=False)

    area = Float
    colormap_name_1 = Str('gray')
    colormap_name_2 = Str('gray')
    save_button = Button('Save')
    save_mode = Enum('both', 'orig', 'thresh')
    path = File
#    save_both = Bool
#    save_orig = Bool
#    save_thresh = Bool

#    calc_area_button = Button
    calc_area_value = Int(auto_set=False, enter_set=True)
    calc_area_threshold = Int(4, auto_set=False, enter_set=True)