How to use the enable.base_tool.BaseTool 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 NMGRL / pychron / pychron / graph / tools / info_inspector.py View on Github external
def intersperse(m, delim):
    """
        intersperse ```delim``` in m
         m=[1,2,3]
         delim='---'
         result=[1,'---',2,'---',3]

    """
    m = iter(m)
    yield next(m)
    for x in m:
        yield delim
        yield x


class InfoInspector(BaseTool):
    metadata_changed = Event
    current_position = None
    current_screen = None
    # use_pane = False
    inspector_item = Event
    # inspector_item_klass = BaseInspectorItem
    event_queue = None
    hittest_threshold = 5

    def normal_mouse_move(self, event):
        xy = event.x, event.y
        try:
            pos = self.component.hittest(xy, threshold=self.hittest_threshold)
            event.window.set_pointer('cross')
        except IndexError:
            event.window.set_pointer('arrow')
github enthought / enable / enable / tools / drag_tool.py View on Github external
consume = False
        if suffix == self.drag_button + "_down":
            consume = self._drag_button_down(event)
        elif suffix == self.drag_button + "_up":
            consume = self._drag_button_up(event)
        elif suffix == "mouse_move":
            consume = self._drag_mouse_move(event)
        elif suffix == "mouse_leave":
            consume = self._drag_mouse_leave(event)
        elif suffix == "mouse_enter":
            consume = self._drag_mouse_enter(event)
        elif suffix == "key_pressed":
            consume = self._drag_cancel_keypressed(event)

        if not consume:
            BaseTool._dispatch_stateful_event(self, event, suffix)
        else:
            event.handled = True
        return
github enthought / enable / enable / base_tool.py View on Github external
def __init__(self, component=None, **kwtraits):
        if "component" in kwtraits:
            component = kwtraits["component"]
        super(BaseTool, self).__init__(**kwtraits)
        self.component = component
        return
github NMGRL / pychron / pychron / processing / tasks / analysis_edit / plot_editor_pane.py View on Github external
#============= enthought library imports =======================
from traits.api import Any, Event, Instance, List
from traitsui.api import View, UItem, Group, VGroup
from enable.base_tool import BaseTool
from chaco.abstract_overlay import AbstractOverlay
from enable.colors import ColorTrait
from pyface.tasks.traits_dock_pane import TraitsDockPane
from chaco.plot import Plot

from pychron.processing.tasks.plot_editor import PlotEditor, AnnotationEditor



#============= standard library imports ========================
#============= local library imports  ==========================
class SelectorTool(BaseTool):
    editor = Any
    editor_event = Event

    def normal_key_pressed(self, event):
        if event.character == 's':
            self._toggle_state()

    def select_key_pressed(self, event):
        self.normal_key_pressed(event)

    def _toggle_state(self):
        if self.event_state == 'normal':
            self.event_state = 'select'
            self.editor_event = self.editor
        else:
            self.event_state = 'normal'
github NMGRL / pychron / pychron / graph / tools / data_tool.py View on Github external
# ===============================================================================

# ============= enthought library imports =======================
from __future__ import absolute_import
from chaco.text_box_overlay import TextBoxOverlay
from enable.base_tool import BaseTool, KeySpec
from traits.api import Event, Any, Enum, Tuple, Bool, Int

# ============= standard library imports ========================
from datetime import datetime
from six.moves import zip


# ============= local library imports  ==========================

class DataTool(BaseTool):
    new_value = Event
    last_mouse_position = Tuple
    visible = Bool(True)
    inspector_key = KeySpec('i')
    parent = Any
    plot = Any
    plotid = Int
    use_date_str = True
    normalize_time = False
    x_format = '{:0.2f}'

    def normal_key_pressed(self, event):
        if self.inspector_key.match(event):
            self.visible = not self.visible
            event.handled = True
github enthought / enable / enable / tools / drag_tool.py View on Github external
""" Defines the base DragTool class.
"""
import six.moves as sm
# Enthought library imports
from traits.api import Bool, Enum, Tuple, Property, cached_property, List, Str
from enable.base_tool import BaseTool, KeySpec


class DragTool(BaseTool):
    """ Base class for tools that are activated by a drag operation.

    This tool insulates the drag operation from double clicks and the like, and
    gracefully manages the transition into and out of drag mode.
    """

    # The mouse button used for this drag operation.
    drag_button = Enum("left", "right")

    # End the drag operation if the mouse leaves the associated component?
    end_drag_on_leave = Bool(True)

    # These keys, if pressed during drag, cause the drag operation to reset.
    cancel_keys = List(Str, ["Esc"])

    # The position of the initial mouse click that started the drag.
github NMGRL / pychron / pychron / media_server / browser.py View on Github external
#============= local library imports  ==========================
from pychron.loggable import Loggable
# from pychron.core.helpers.parsers.xml_parser import XMLParser
# #from pychron.core.ui.custom_label_editor import CustomLabelEditor
# from pychron.graph.tools.xy_inspector import XYInspectorOverlay, XYInspector
# from pychron.graph.image_underlay import ImageUnderlay
# from pychron.core.geometry.reference_point import ReferencePoint
from chaco.abstract_overlay import AbstractOverlay
from pyface.file_dialog import FileDialog
from pyface.constant import OK
# from pychron.regex import make_image_regex
from pychron.media_server.image_viewer import ImageViewer
from pychron.media_server.finder import Finder


class ReferencePointsTool(BaseTool):
    current_position = Tuple
    points = List
    def normal_left_down(self, event):
        pos = event.x, event.y
        self.current_position = pos
#        dp = self.component.map_data(pos, all_values=True)
        self.points.append(pos)

class ReferencePointsOverlay(AbstractOverlay):
    tool = Any
    _cached_points = None

#    def do_layout(self):
#        self._cached_points = None

    def overlay(self, component, gc, *args, **kw):
github NMGRL / pychron / pychron / spectrometer / spectrometer_scan_graph.py View on Github external
gc.set_fill_color((1,1,1,1))
        bb_width, bb_height = self.get_bounding_box(gc)

        offset = 2
        xoffset = self.xoffset
        gc.lines([(-xoffset,(bb_height+offset)/2.0),
        (0, bb_height+offset),
        (bb_width+offset, bb_height+offset),
        (bb_width+offset, -offset),
        (0,-offset),
        (-xoffset,(bb_height+offset)/2.0)])

        gc.draw_path()


class MarkerTool(BaseTool):
    overlay = None
    text = ''
    def normal_left_dclick(self, event):
        self.overlay.add_marker(event.x,event.y, self.text)

class MarkerOverlay(AbstractOverlay):
    _cached_labels = List

    def add_marker(self, x, y, text):
        # x=self.component.x+x
        self._cached_labels.append(MarkerLabel(x=x+10, y=y, text=text))

    def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
        with gc:
            # self._load_cached_labels()
            self._draw_labels(gc)
github NMGRL / pychron / pychron / graph / tools / limits_tool.py View on Github external
# limitations under the License.
# ===============================================================================

# ============= enthought library imports =======================
from traits.api import Float, Instance, Str, Tuple
from chaco.abstract_overlay import AbstractOverlay
from enable.base_tool import BaseTool
from enable.colors import ColorTrait
# ============= standard library imports ========================
import string
# ============= local library imports  ==========================
from pychron.core.helpers.formatting import floatfmt
from pychron.processing.plotters.ideogram.mean_indicator_overlay import XYPlotLabel


class LimitsTool(BaseTool):
    ruler_pos = Tuple
    ruler_data_pos = Float
    orientation = 'x'
    active = False

    entered_value = Str

    def _set_entered_value(self, c):
        if c == '.' or c in string.digits:
            self.entered_value += c
        elif c in ('Backspace', 'Delete'):
            self.entered_value = self.entered_value[:-1]

    def drag_key_pressed(self, event):
        c = event.character
        if c == 'Esc':
github jminardi / volume-from-shadow / selection_plot.py View on Github external
pd = ArrayPlotData()
        pd.set_data("imagedata", self.image)

        # Create the plot
        plot = Plot(pd)
        img_plot = plot.img_plot("imagedata")

        # Tweak some of the plot properties
        plot.padding = 0

        # Attach some tools to the plot
        plot.tools.append(ClickTool(plot))
        return plot


class ClickTool(BaseTool):

    vertices = List()

    def normal_left_down(self, event):
        self.vertices.append(self.component.map_data((event.x, event.y)))
        print self.vertices[-1]
        np.save('vertices.npy', np.array(self.vertices))


import enaml
from enaml.qt.qt_application import QtApplication


def main():
    import sys
    from scipy.ndimage import imread