How to use the enable.api.Container 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 / drawing / drawing_canvas.py View on Github external
new.on_trait_change(self._canvas_bounds_changed, "bounds_items")
        return

    def _canvas_bounds_changed(self):
        self.width = self.canvas.width
        self.y = self.canvas.height - self.height
        return

    def _dispatch_stateful_event(self, event, suffix):
        super(DrawingCanvasToolbar, self)._dispatch_stateful_event(event, suffix)
        event.handled = True
        return



class DrawingCanvas(Container):
    """
    A DrawingCanvas has some buttons which toggle what kind of drawing tools
    are active on the canvas, then allow arbitrary painting on the canvas.
    """

    # The active tool is the primary interactor on the canvas.  It gets
    # a chance to handle events before they are passed on to other components
    # and listener tools.
    active_tool = Any

    # Listening tools are always enabled and get all events (unless the active
    # tool has vetoed it), but they cannot prevent other tools from getting events.
    listening_tools = List

    # The background color of the canvas
    bgcolor = ColorTrait("white")
github enthought / chaco / examples / demo / canvas / plot_clone_tool.py View on Github external
from traits.api import Bool, Callable, Enum, Float, Instance, Int, Trait, Tuple
from enable.api import Container

# Chaco imports
from chaco.api import AbstractOverlay
from enable.tools.api import DragTool


class PlotCloneTool(AbstractOverlay, DragTool):
    """ On a drag operation, draws an overlay of self.component underneath
    the cursor.  On drag_end, a copy of the plot is dropped onto the
    self.dest container.
    """

    # The container to add the cloned plot to
    dest = Instance(Container)

    # A function that gets called on drag_end.  It gets passed this tool
    # and the position at which to place the new cloned plot.
    plot_cloner = Callable

    # The amount to fade the plot when we draw as overlay
    alpha = Float(0.5)

    # The possible event states for this tool.
    event_state = Enum("normal", "dragging")

    capture_mouse = True

    # The (x,y) position of the "last" mouse position we received
    _offset = Trait(None, None, Tuple)
github enthought / enable / enable / tools / toolbars / viewport_toolbar.py View on Github external
def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
        c = other_component
        self.do_layout(component=c)
        with gc:
            gc.clip_to_rect(c.x, c.y, c.width, c.height)
            Container._draw(self, gc, view_bounds)
        return
github enthought / enable / enable / savage / trait_defs / ui / wx / kiva_render_panel.py View on Github external
import wx

from enable.savage.svg.backends.kiva import renderer
from enable.savage.svg.document import SVGDocument
from enable.api import Container, Window
from traits.api import Instance, Float

class KivaContainer(Container):

    document = Instance(SVGDocument)
    zoom = Float(100.0)

    def draw(self, gc, view_bounds=None, mode="default"):
        gc.clear()
        if not self.document:
            gc.show_text_at_point("No Document", 20, 20)
            return

        with gc:
            # SVG origin is upper right with y positive is down. argh.
            # Set up the transforms to fix this up.
            gc.translate_ctm(0, gc.height())
            # zoom percentage
            scale = float(self.zoom) / 100.0
github enthought / graphcanvas / graphcanvas / graph_container.py View on Github external
# (C) Copyright 2009-2019 Enthought, Inc., Austin, TX
# All rights reserved.

import networkx
import numpy

from enable.api import Container
from kiva.constants import CAP_BUTT
from traits.api import Bool, Enum, Instance

from graphcanvas.layout import tree_layout

SUPPORTED_LAYOUTS = ['spring', 'tree', 'shell', 'circular', 'spectral']


class GraphContainer(Container):
    """ Enable Container for Directed Acyclic Graphs
    """

    bounds = [350, 350]
    graph = Instance(networkx.Graph)

    style = Enum(SUPPORTED_LAYOUTS)

    # graph layout is different than Enable's layout: graph layout is
    # the relative positioning on nodes, and is very expensive
    _graph_layout_needed = Bool(True)

    def do_layout(self, size=None, force=False):
        """ Nodes of the graph will be layed out based on the the style
            attribute
        """
github enthought / enable / examples / enable / tools / apptools / undoable_move_tool.py View on Github external
def _create_window(self):
        box = Box(bounds=[100,100], position=[50,50], color='red')

        move_tool = MoveCommandTool(component=box,
                                    command_stack=self.command_stack)
        box.tools.append(move_tool)

        container = Container(bounds=[600, 600])
        container.add(box)

        undo_tool = UndoTool(component=container,
                             undo_manager=self.undo_manager,
                             undo_keys=[KeySpec('Left')],
                             redo_keys=[KeySpec('Right')])
        container.tools.append(undo_tool)

        window = Window(self.control, -1, component=container)
        return window
github enthought / enable / examples / enable / scrolled_demo.py View on Github external
def _create_window(self):

        container = Container(bounds=[800, 600], bgcolor=(0.9, 0.7, 0.7, 1.0),
                              auto_size=False, fit_window=False)
        circle1 = Circle(bounds=[75,75], position=[100,100],
                         shadow_type="dashed")
        container.add(circle1)

        scr = Scrolled(container, bounds=[200,200], position=[50,50],
                       stay_inside=True, vertical_anchor='top',
                       horizontal_anchor='left', fit_window=False)

        return Window(self, -1, component=scr)
github enthought / chaco / examples / demo / advanced / lod_image_viewer.py View on Github external
index=index,
        index_mapper=index_mapper,
        use_downsampling=True,
    )

    container = HPlotContainer(bounds=(1200, 1000))
    container.add(renderer)
    renderer.tools.append(PanTool(renderer, constrain_key="shift"))
    renderer.overlays.append(ZoomTool(component=renderer,
                                      tool_mode="box", always_on=False))
    return container


class LODImageDemo(HasTraits):

    plot_container = Instance(Container)

    traits_view = View(
        Item(
            'plot_container',
            editor=ComponentEditor(size=(600, 500)),
            show_label=False,
        ),
        resizable=True,
    )


if __name__ == "__main__":
    lod_demo = LODImageDemo(plot_container=_create_lod_plot())
    lod_demo.configure_traits()
github enthought / enable / examples / enable / filled_container_demo.py View on Github external
filled container that contains two filled circles, each of which has a
different kind of "shadow" object that it dynamically adds to the
container when the user clicks and drags the circle around.  Because
the shadow objects are "first-class" components in the filled container,
and because containers default to auto-sizing around their components,
the container stretches to the minimum bounding box of its components
as the user drags the circles around.
"""
from numpy import array

from traits.api import Any, Enum, Float, Instance, Tuple
from enable.example_support import DemoFrame, demo_main
from enable.api import Container, Component, Pointer, str_to_font, Window


class MyFilledContainer(Container):

    fit_window = False
    border_width = 2
    resizable = ""
    _font = Any

    def _draw_container_mainlayer(self, gc, view_bounds, mode="default"):
        'Draws a filled container with the word "Container" in the center'
        if not self._font:
            self._font = str_to_font(None, None, "modern 10")

        with gc:
            gc.set_fill_color(self.bgcolor_)
            gc.rect(self.x, self.y, self.width, self.height)
            gc.draw_path()
            self._draw_border(gc)
github enthought / enable / enable / text_field_grid.py View on Github external
def _dispatch_draw(self, layer, gc, view_bounds, mode):
        self._position_cells()
        Container._dispatch_draw(self, layer, gc, view_bounds, mode)
        self._draw_grid(gc, view_bounds, mode)