Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, component, **traits):
self.component = component
Container.__init__( self, **traits )
self._viewport_component_changed()
return
def _bounds_changed(self, old, new):
# crappy... calling our parent's handler seems like a common traits
# event handling problem
super(Container, self)._bounds_changed(old, new)
self._layout_needed = True
self.invalidate_draw()
from __future__ import with_statement
# Enthought library imports
from traits.api import Any, Bool, DelegatesTo, Float, Instance, Int
# Local, relative imports
from .base import intersect_bounds, empty_rectangle
from .colors import ColorTrait
from .component import Component
from .container import Container
from .viewport import Viewport
from .native_scrollbar import NativeScrollBar
class Scrolled(Container):
"""
A Scrolled acts like a viewport with scrollbars for positioning the view
position. Rather than subclassing from viewport, it delegates to one.
"""
# The component that we are viewing
component = Instance(Component)
# The viewport onto our component
viewport_component = Instance(Viewport, ())
# Whether or not the viewport should stay constrained to the bounds
# of the viewed component
stay_inside = DelegatesTo('viewport_component')
# Where to anchor vertically on resizes
def _component_changed(self, old, new):
if old is not None:
old.on_trait_change(self.component_bounds_changed, 'bounds', remove=True)
old.window = None
if new is None:
self.component = Container()
return
new.window = self
# If possible, size the new component according to the size of the
# toolkit control
size = self._get_control_size()
if (size is not None) and hasattr(self.component, "bounds"):
new.on_trait_change(self.component_bounds_changed, 'bounds')
if getattr(self.component, "fit_window", False):
self.component.outer_position = [0,0]
self.component.outer_bounds = list(size)
elif hasattr(self.component, "resizable"):
if "h" in self.component.resizable:
self.component.outer_x = 0
self.component.outer_width = size[0]
def _draw_underlay(self, gc, view_bounds=None, mode="default"):
if self.draw_axes:
x, y, x2, y2 = self.view_bounds
if (x <= 0 <= x2) or (y <= 0 <= y2):
with gc:
gc.set_stroke_color((0,0,0,1))
gc.set_line_width(1.0)
gc.move_to(0, y)
gc.line_to(0, y2)
gc.move_to(x, 0)
gc.line_to(x2, 0)
gc.stroke_path()
super(Container, self)._draw_underlay(gc, view_bounds, mode)
def components_at(self, x, y, add_containers = False):
"""
Returns the list of components inside the viewport at the given (x,y)
in the viewport's native coordinate space (not in the space of the
component it is viewing).
Although Viewports are not containers, they support this method.
"""
if self.is_in(x, y):
if self.component is not None:
# Transform (scale + translate) the incoming X and Y
# coordinates from our coordinate system into the coordinate
# system of the component we are viewing.
x_trans, y_trans = self.viewport_to_component(x, y)
if isinstance(self.component, Container):
return self.component.components_at(x_trans, y_trans)
elif self.component.is_in(x_trans, y_trans):
return [self.component]
else:
return []
else:
return []
""" Containers which lay out their components horizontally or vertically
"""
from traits.api import Enum, Float
from .container import Container
from .stacked_layout import stacked_preferred_size, stack_layout
class StackedContainer(Container):
""" Base class for stacked containers
"""
# The dimension along which to stack components that are added to
# this container.
stack_dimension = Enum("h", "v")
# The "other" dimension, i.e., the dual of the stack dimension.
other_dimension = Enum("v", "h")
# The index into obj.position and obj.bounds that corresponds to
# **stack_dimension**. This is a class-level and not an instance-level
# attribute. It must be 0 or 1.
stack_index = 0
# The amount of space to put between components.
import six
# traits imports
from traits.api import Any, Bool, Callable, Dict, Either, Instance, List, \
Property
# local imports
from .container import Container
from .coordinate_box import CoordinateBox
from .layout.layout_helpers import expand_constraints
from .layout.layout_manager import LayoutManager
from .layout.utils import (
add_symbolic_contents_constraints, get_from_constraints_namespace)
class ConstraintsContainer(Container):
""" A Container which lays out its child components using a
constraints-based layout solver.
"""
# A read-only symbolic object that represents the left boundary of
# the component
contents_left = Property(fget=get_from_constraints_namespace)
# A read-only symbolic object that represents the right boundary
# of the component
contents_right = Property(fget=get_from_constraints_namespace)
# A read-only symbolic object that represents the bottom boundary
# of the component
contents_bottom = Property(fget=get_from_constraints_namespace)
def __init__(self, **traits):
self._scroll_origin = (0.0, 0.0)
self._update_region = None
self._gc = None
self._pointer_owner = None
HasTraits.__init__(self, **traits)
# Create a default component (if necessary):
if self.component is None:
self.component = Container()
return
""" Defines the enable Canvas class """
from __future__ import with_statement
# Enthought library imports
from traits.api import Bool, Trait, Tuple, List
from kiva.constants import FILL
# Local relative imports
from .component import Component
from .container import Container
class Canvas(Container):
"""
An infinite canvas with components on it. It can optionally be given
a "view region" which will be used as the notional bounds of the
canvas in all operations that require bounds.
A Canvas can be nested inside another container, but usually a
viewport is more appropriate.
Note: A Canvas has infinite bounds, but its .bounds attribute is
overloaded to be something more meaningful, namely, the bounding
box of its child components and the optional view area of the
viewport that is looking at it. (TODO: add support for multiple
viewports.)
"""
# This optional tuple of (x,y,x2,y2) allows viewports to inform the canvas of