How to use the traits.api.Tuple 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 / lineplot.py View on Github external
class LinePlot(BaseXYPlot):
    """ A plot consisting of a line.

    This is the most fundamental object to use to create line plots. However,
    it is somewhat low-level and therefore creating one properly to do what
    you want can require some verbose code. The create_line_plot() function
    in plot_factory.py can hide some of this verbosity for common cases.
    """
    #: The color of the line.
    color = black_color_trait

    #: The RGBA tuple for rendering lines.  It is always a tuple of length 4.
    #: It has the same RGB values as color_, and its alpha value is the alpha
    #: value of self.color multiplied by self.alpha.
    effective_color = Property(Tuple, depends_on=['color', 'alpha'])

    #: The color to use to highlight the line when selected.
    selected_color = ColorTrait("lightyellow")

    #: The style of the selected line.
    selected_line_style = LineStyle("solid")

    #: The name of the key in self.metadata that holds the selection mask
    metadata_name = Str("selections")

    #: The thickness of the line.
    line_width = Float(1.0)

    #: The line dash style.
    line_style = LineStyle
github enthought / chaco / chaco / tools / rectangle_selection.py View on Github external
#: selection operation; if False, the user must press a key to enter
    #: selection mode.
    always_on = Bool(False)

    #: Defines a meta-key, that works with always_on to set the selection mode.
    #: This is useful when the selection tool is used in conjunction with the
    #: pan tool.
    always_on_modifier = Enum('control', 'shift', 'control', 'alt')

    #: The minimum amount of screen space the user must select in order for
    #: the tool to actually take effect.
    minimum_screen_delta = Int(10)

    #: Bounding box of selected region: (xmin, xmax, ymin, ymax)
    #TODO: Rename to `selection`?
    selected_box = Tuple()

    #: Key press to clear selected box
    clear_selected_key = KeySpec('Esc')

    #-------------------------------------------------------------------------
    # Appearance properties (for Box mode)
    #-------------------------------------------------------------------------

    #: The pointer to use when drawing a selection box.
    pointer = "magnifier"

    #: The color of the selection box.
    color = ColorTrait("lightskyblue")

    #: The alpha value to apply to **color** when filling in the selection
    #: region.  Because it is almost certainly useless to have an opaque
github enthought / mayavi / tvtk / tvtk_base.py View on Github external
DOING_UPDATE = 10

    ########################################
    # Private traits.

    # This trait is only used internally and should not activate any
    # notifications when set which is why we use `Python`.
    _in_set = traits.Python

    # The wrapped VTK object.
    _vtk_obj = traits.Trait(None, None, vtk.vtkObjectBase())

    # Stores the names of the traits whose VTK Get methods may return
    # invalid values (e.g. reference to a point) or uninitialised values
    # We would try to update but allow it to fail
    _allow_update_failure_ = traits.Tuple

    # Stores the names of the traits that need to be updated.
    _updateable_traits_ = traits.Tuple

    # List of trait names that are to be included in the full traits view of
    # this object.
    _full_traitnames_list_ = traits.List

    #################################################################
    # `object` interface.
    #################################################################
    def __init__(self, klass, obj=None, update=True, **traits):
        """Object initialization.

        Parameters
        ----------
github enthought / chaco / chaco / tools / simple_zoom.py View on Github external
# Key mappings
    #------------------------------------------------------------------------

    # The key that cancels the zoom and resets the view to the original defaults.
    cancel_zoom_key = Instance(KeySpec, args=("Esc",))

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

    # If **always_on** is False, this attribute indicates whether the tool
    # is currently enabled.
    _enabled = Bool(False)

    # the original numerical screen ranges
    _orig_low_setting = Trait(None, Tuple, Float, Str)
    _orig_high_setting = Trait(None, Tuple, Float, Str)

    # The (x,y) screen point where the mouse went down.
    _screen_start = Trait(None, None, Tuple)

    # The (x,,y) screen point of the last seen mouse move event.
    _screen_end = Trait(None, None, Tuple)

    def __init__(self, component=None, *args, **kw):
        # Support AbstractController-style constructors so that this can be
        # handed in the component it will be overlaying in the constructor
        # without using kwargs.
        self.component = component
        super(SimpleZoom, self).__init__(*args, **kw)
        self._reset_state_to_current()
        if self.tool_mode == "range":
github enthought / pyface / pyface / ui / wx / splash_screen.py View on Github external
# 'ISplashScreen' interface --------------------------------------------

    image = Instance(ImageResource, ImageResource("splash"))

    log_level = Int(DEBUG)

    show_log_messages = Bool(True)

    text = Str()

    text_color = Any()

    text_font = Any()

    text_location = Tuple(5, 5)

    # ------------------------------------------------------------------------
    # Protected 'IWidget' interface.
    # ------------------------------------------------------------------------

    def _create_control(self, parent):
        # Get the splash screen image.
        image = self.image.create_image()

        splash_screen = wx.adv.SplashScreen(
            # The bitmap to display on the splash screen.
            image.ConvertToBitmap(),
            # Splash Style.
            wx.adv.SPLASH_NO_TIMEOUT | wx.adv.SPLASH_CENTRE_ON_SCREEN,
            # Timeout in milliseconds (we don't currently timeout!).
            0,
github enthought / traitsui / examples / demo / Advanced / Date_range_editor_demo.py View on Github external
#  Copyright (c) 2007-2009, Enthought, Inc.
#  License: BSD Style.

"""
A Traits UI editor that wraps a Qt calendar panel.
"""
from __future__ import absolute_import, print_function

from traits.api import HasTraits, Date, Tuple
from traitsui.api import View, Item, DateRangeEditor, Group


class DateRangeEditorDemo(HasTraits):
    """ Demo class to show DateRangeEditor. """
    date_range = Tuple(Date, Date)

    view = View(
                Group(Item('date_range',
                           editor=DateRangeEditor(),
                           style='custom',
                           label='Date range'),
                      label='Date range'),
                resizable=True)

    def _date_range_changed(self):
        print(self.date_range)


#-- Set Up The Demo ------------------------------------------------------

demo = DateRangeEditorDemo()
github enthought / chaco / chaco / subdivision_cells.py View on Github external
""" A cell optimized for storing lists of continuous points.

    Rather than storing each individual point index as an element in an array,
    RangedCell stores a list of index ranges; each range is a (start,end) tuple).
    """

    # A list of indices into **data** that reflect the points inside this cell
    # (overrides AbstractCell).
    indices = Property

    # Don't use the _indices shadow trait; rather, the getters and setters
    # for 'index' procedurally generate indices from **ranges**.
    _indices = Disallow

    # Ranges are an additional interface on RangedCells.
    ranges = Property(List(Tuple))

    # Shadow trait for ranges.
    _ranges = List(Tuple)

    #---------------------------------------------------------------------
    # AbstractCell methods
    #---------------------------------------------------------------------

    def add_indices(self, indices):
        """ Adds a list of integer indices to the existing list of indices.

        Implements AbstractCell.
        """
        self.add_ranges(find_runs(indices))
        return
github enthought / pyface / pyface / ui / null / action / tool_palette_manager.py View on Github external
from traits.api import Any, Bool, Enum, Instance, Tuple


from pyface.image_cache import ImageCache
from pyface.action.action_manager import ActionManager
from .tool_palette import ToolPalette


class ToolPaletteManager(ActionManager):
    """ A tool bar manager realizes itself in a tool palette bar control. """

    # 'ToolPaletteManager' interface ---------------------------------------

    # The size of tool images (width, height).
    image_size = Tuple((16, 16))

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

    # 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. """
github bpteague / cytoflow / cytoflowgui / workflow_pane.py View on Github external
from cytoflowgui.view_pane import HintedMainWindow

@provides(IDockPane)
class WorkflowDockPane(TraitsDockPane):
    
    id = 'edu.mit.synbio.cytoflowgui.workflow_pane'
    name = "Workflow"
    
    # the application instance from which to get plugin instances
    plugins = List(IOperationPlugin)
    
    # the task serving as the dock pane's controller
    task = Instance(Task)
    
    # IN INCHES
    image_size = Tuple((0.33, 0.33))

    def create_contents(self, parent):
        """ 
        Create and return the toolkit-specific contents of the dock pane.
        """
 
        dpi = self.control.physicalDpiX()
        image_size = (int(self.image_size[0] * dpi),
                      int(self.image_size[1] * dpi))
 
        self.toolbar = ToolBarManager(orientation='vertical',
                                      show_tool_names = False,
                                      image_size = image_size)
                 
        for plugin in self.plugins:
github enthought / chaco / chaco / tools / drag_zoom.py View on Github external
# Whether to restrict zoom to the domain of the mappers
    restrict_domain = Bool(False)

    zoom_to_mouse = Bool(False)

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

    # (x,y) of the point where the mouse button was pressed.
    _original_xy = Tuple()

    # Data coordinates of **_original_xy**.  This may be either (index,value)
    # or (value,index) depending on the component's orientation.
    _original_data = Tuple()

    # A tuple of ((x,y), (x2,y2)) of the original, unzoomed screen bounds
    _orig_screen_bounds = Tuple()

    # The x and y positions of the previous mouse event.  The zoom rate is
    # based on the percentage change in position between the previous position
    # and the current mouse position, possibly in both axes.
    _prev_x = Float()
    _prev_y = Float()

    def __init__(self, component=None, *args, **kw):
        super(DragZoom, self).__init__(component, *args, **kw)
        c = component
        if c is not None:
            self._orig_screen_bounds = ((c.x, c.y), (c.x2, c.y2))