How to use the enable.api.KeySpec 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 / chaco / chaco / tools / image_inspector_tool.py View on Github external
#: This event fires whenever the mouse moves over a new image point.
    #: Its value is a dict with a key "color_value", and possibly a key
    #: "data_value" if the plot is a color-mapped image plot.
    new_value = Event

    #: Indicates whether overlays listening to this tool should be visible.
    visible = Bool(True)

    #: Stores the last mouse position.  This can be used by overlays to
    #: position themselves around the mouse.
    last_mouse_position = Tuple

    #: This key will show and hide any ImageInspectorOverlays associated
    #: with this tool.
    inspector_key = KeySpec('p')

    # Stores the value of self.visible when the mouse leaves the tool,
    # so that it can be restored when the mouse enters again.
    _old_visible = Enum(None, True, False) #Trait(None, Bool(True))

    def normal_key_pressed(self, event):
        if self.inspector_key.match(event):
            self.visible = not self.visible
            event.handled = True

    def normal_mouse_leave(self, event):
        if self._old_visible is None:
            self._old_visible = self.visible
            self.visible = False

    def normal_mouse_enter(self, event):
github enthought / chaco / chaco / tools / better_selecting_zoom.py View on Github external
#-------------------------------------------------------------------------
    # deprecated interaction controls, used for API compatability with
    # SimpleZoom
    #-------------------------------------------------------------------------

    # Conversion ratio from wheel steps to zoom factors.
    wheel_zoom_step = Property(Float, depends_on='zoom_factor')

    # The key press to enter zoom mode, if **always_on** is False.  Has no effect
    # if **always_on** is True.
    enter_zoom_key = Instance(KeySpec, args=("z",))

    # The key press to leave zoom mode, if **always_on** is False.  Has no effect
    # if **always_on** is True.
    exit_zoom_key = Instance(KeySpec, args=("z",))

    # Disable the tool after the zoom is completed?
    disable_on_complete = Property()


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

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

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

    # The alpha value to apply to **color** when filling in the selection
github enthought / chaco / chaco / tools / pan_tool.py View on Github external
# The cursor to use when panning.
    drag_pointer = Pointer("hand")

    # Scaling factor on the panning "speed".
    speed = Float(1.0)

    # The modifier key that, if depressed when the drag is initiated, constrains
    # the panning to happen in the only direction of largest initial motion.
    # It is possible to permanently restrict this tool to always drag along one
    # direction.  To do so, set constrain=True, constrain_key=None, and
    # constrain_direction to the desired direction.
    constrain_key = Enum(None, "shift", "control", "alt")

    # Keys to Pan via keyboard
    pan_right_key = Instance(KeySpec, args=("Right",))
    pan_left_key = Instance(KeySpec, args=("Left",))
    pan_up_key = Instance(KeySpec, args=("Up",))
    pan_down_key = Instance(KeySpec, args=("Down",))

    # number of pixels the keys should pan
    # disabled if 0.0
    pan_keys_step = Float(0.0)

    # Constrain the panning to one direction?
    constrain = Bool(False)

    # The direction of constrained draw. A value of None means that the user
    # has initiated the drag and pressed the constrain_key, but hasn't moved
    # the mouse yet; the magnitude of the components of the next mouse_move
    # event will determine the constrain_direction.
    constrain_direction = Enum(None, "x", "y")
github enthought / chaco / chaco / tools / better_selecting_zoom.py View on Github external
# The minimum amount of screen space the user must select in order for
    # the tool to actually take effect.
    minimum_screen_delta = Int(10)


    #-------------------------------------------------------------------------
    # deprecated interaction controls, used for API compatability with
    # SimpleZoom
    #-------------------------------------------------------------------------

    # Conversion ratio from wheel steps to zoom factors.
    wheel_zoom_step = Property(Float, depends_on='zoom_factor')

    # The key press to enter zoom mode, if **always_on** is False.  Has no effect
    # if **always_on** is True.
    enter_zoom_key = Instance(KeySpec, args=("z",))

    # The key press to leave zoom mode, if **always_on** is False.  Has no effect
    # if **always_on** is True.
    exit_zoom_key = Instance(KeySpec, args=("z",))

    # Disable the tool after the zoom is completed?
    disable_on_complete = Property()


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

    # The pointer to use when drawing a zoom box.
    pointer = "magnifier"
github enthought / chaco / chaco / tools / tool_history_mixin.py View on Github external
""" A mix-in class for tools to maintain a tool state history and to move
    backwards and forwards through that history stack.

    This mix-in listens for keypressed events; to handle keypresses in a
    subclass, call self._history_handle_key(event) to have this mix-in properly
    process the event.
    """

    # Key to go to the original or start state in the history.
    reset_state_key = Instance(KeySpec, args=("Esc",))

    # Key to go to the previous state in the history.
    prev_state_key = Instance(KeySpec, args=("Left", "control"))

    # Key to go to the next state in the history.
    next_state_key = Instance(KeySpec, args=("Right", "control"))

    # The state stack.
    _history = List

    # The current index into _history
    _history_index = Int

    #------------------------------------------------------------------------
    # Abstract methods that subclasses must implement to handle keypresses
    #------------------------------------------------------------------------

    def _next_state_pressed(self):
        """ Called when the tool needs to advance to the next state in the
        stack.

        The **_history_index** will have already been set to the index
github enthought / chaco / chaco / tools / pan_tool.py View on Github external
#: The cursor to use when panning.
    drag_pointer = Pointer("hand")

    #: Scaling factor on the panning "speed".
    speed = Float(1.0)

    #: The modifier key that, if depressed when the drag is initiated, constrains
    #: the panning to happen in the only direction of largest initial motion.
    #: It is possible to permanently restrict this tool to always drag along one
    #: direction.  To do so, set constrain=True, constrain_key=None, and
    #: constrain_direction to the desired direction.
    constrain_key = Enum(None, "shift", "control", "alt")

    #: Keys to Pan via keyboard
    pan_right_key = Instance(KeySpec, args=("Right",))
    pan_left_key = Instance(KeySpec, args=("Left",))
    pan_up_key = Instance(KeySpec, args=("Up",))
    pan_down_key = Instance(KeySpec, args=("Down",))

    #: number of pixels the keys should pan
    #: disabled if 0.0
    pan_keys_step = Float(0.0)

    #: Constrain the panning to one direction?
    constrain = Bool(False)

    #: The direction of constrained draw. A value of None means that the user
    #: has initiated the drag and pressed the constrain_key, but hasn't moved
    #: the mouse yet; the magnitude of the components of the next mouse_move
    #: event will determine the constrain_direction.
    constrain_direction = Enum(None, "x", "y")
github enthought / chaco / chaco / tools / select_tool.py View on Github external
#:     clicking it again deselects it. The modifier key to use is set by
    #:     **multiselect_modifier**. The only way to deselect points is by
    #:     clicking on them; clicking on a screen space outside of the plot does
    #:     not deselect points.
    #: "multi"
    #:     Like **toggle** mode, except that the user can deselect all points
    #:     at once by clicking on the plot area away from a point.
    #: "single"
    #:     The user can only select a single point at a time.
    #: "off"
    #:     The user cannot select points via clicking.
    selection_mode = Enum("toggle", "multi", "single", "off")

    #: The modifier key to use to multi-select points.  Only used in **toggle**
    #: and **multi** selection modes.
    multiselect_modifier = Instance(KeySpec, args=(None, "control"), allow_none=True)


    def _get_selection_state(self, event):
        """ Returns a tuple reflecting the current selection state

        Parameters
        ----------
        event : enable KeyEvent or MouseEvent

        Returns
        -------
        (already_selected, clicked) : tuple of Bool
            clicked is True if the item corresponding to the input event has
            just been clicked.
            already_selected indicates that the item corresponding to the
            input event is already selected.
github enthought / chaco / chaco / tools / pan_tool.py View on Github external
#: Scaling factor on the panning "speed".
    speed = Float(1.0)

    #: The modifier key that, if depressed when the drag is initiated, constrains
    #: the panning to happen in the only direction of largest initial motion.
    #: It is possible to permanently restrict this tool to always drag along one
    #: direction.  To do so, set constrain=True, constrain_key=None, and
    #: constrain_direction to the desired direction.
    constrain_key = Enum(None, "shift", "control", "alt")

    #: Keys to Pan via keyboard
    pan_right_key = Instance(KeySpec, args=("Right",))
    pan_left_key = Instance(KeySpec, args=("Left",))
    pan_up_key = Instance(KeySpec, args=("Up",))
    pan_down_key = Instance(KeySpec, args=("Down",))

    #: number of pixels the keys should pan
    #: disabled if 0.0
    pan_keys_step = Float(0.0)

    #: Constrain the panning to one direction?
    constrain = Bool(False)

    #: The direction of constrained draw. A value of None means that the user
    #: has initiated the drag and pressed the constrain_key, but hasn't moved
    #: the mouse yet; the magnitude of the components of the next mouse_move
    #: event will determine the constrain_direction.
    constrain_direction = Enum(None, "x", "y")

    #: Restrict to the bounds of the plot data
    restrict_to_data = Bool(False)
github enthought / chaco / chaco / tools / pan_tool.py View on Github external
# The cursor to use when panning.
    drag_pointer = Pointer("hand")

    # Scaling factor on the panning "speed".
    speed = Float(1.0)

    # The modifier key that, if depressed when the drag is initiated, constrains
    # the panning to happen in the only direction of largest initial motion.
    # It is possible to permanently restrict this tool to always drag along one
    # direction.  To do so, set constrain=True, constrain_key=None, and
    # constrain_direction to the desired direction.
    constrain_key = Enum(None, "shift", "control", "alt")

    # Keys to Pan via keyboard
    pan_right_key = Instance(KeySpec, args=("Right",))
    pan_left_key = Instance(KeySpec, args=("Left",))
    pan_up_key = Instance(KeySpec, args=("Up",))
    pan_down_key = Instance(KeySpec, args=("Down",))

    # number of pixels the keys should pan
    # disabled if 0.0
    pan_keys_step = Float(0.0)

    # Constrain the panning to one direction?
    constrain = Bool(False)

    # The direction of constrained draw. A value of None means that the user
    # has initiated the drag and pressed the constrain_key, but hasn't moved
    # the mouse yet; the magnitude of the components of the next mouse_move
    # event will determine the constrain_direction.
    constrain_direction = Enum(None, "x", "y")
github enthought / chaco / chaco / tools / better_zoom.py View on Github external
from .tool_history_mixin import ToolHistoryMixin
from .tool_states import ZoomState, PanState, GroupedToolState, ToolState


class BetterZoom(BaseTool, ToolHistoryMixin):

    # Keys to zoom in/out
    zoom_in_key = Instance(KeySpec, args=("+",), kw={'ignore': ['shift']})
    zoom_out_key = Instance(KeySpec, args=("-",))

    # Keys to zoom in/out in x direction only
    zoom_in_x_key = Instance(KeySpec, args=("Right", "shift"))
    zoom_out_x_key = Instance(KeySpec, args=("Left", "shift"))

    # Keys to zoom in/out in y direction only
    zoom_in_y_key = Instance(KeySpec, args=("Up", "shift"))
    zoom_out_y_key = Instance(KeySpec, args=("Down", "shift"))

    # Key to go to the previous state in the history.
    prev_state_key = Instance(KeySpec, args=("z", "control"))

    # Key to go to the next state in the history.
    next_state_key = Instance(KeySpec, args=("y", "control"))

    # Enable the mousewheel for zooming?
    enable_wheel = Bool(True)

    # if the mouse pointer should be used to control the center
    # of the zoom action
    zoom_to_mouse = Bool(True)

    # if the mouse pointer should be used to control the center