diff --git a/enable/component.py b/enable/component.py index b889e1a70..c274eec1a 100644 --- a/enable/component.py +++ b/enable/component.py @@ -76,14 +76,6 @@ class Component(CoordinateBox, Interactor): # Layout traits # ------------------------------------------------------------------------ - # The layout system to use: - # - # * 'chaco': Chaco-level layout (the "old" system) - # * 'enable': Enable-level layout, based on the db/resolver containment - # model. - # NB: this is in preparation for future work - # layout_switch = Enum("chaco", "enable") - # Dimensions that this component is resizable in. For resizable # components, get_preferred_size() is called before their actual # bounds are set. @@ -326,12 +318,6 @@ class Component(CoordinateBox, Interactor): # The element ID of this component. id = Str - # These will be used by the new layout system, but are currently unused. - # max_width = Any - # min_width = Any - # max_height = Any - # min_height = Any - # ------------------------------------------------------------------------ # Private traits # ------------------------------------------------------------------------ diff --git a/enable/controls.py b/enable/controls.py deleted file mode 100644 index 6356d0b1d..000000000 --- a/enable/controls.py +++ /dev/null @@ -1,665 +0,0 @@ -# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! - -# Major library imports -import os.path - -# Enthought library imports -from enable.colors import ColorTrait -from traits.api import Bool, Delegate, HasTraits, PrefixList, Str, Trait -from traitsui.api import View, Group - -# Local relative imports -from .base import ( - BOTTOM, EMBOSSED, ENGRAVED, HCENTER, LEFT, RIGHT, TOP, VCENTER, - add_rectangles, transparent_color, xy_in_bounds -) -from .component import Component -from .enable_traits import ( - border_size_trait, image_trait, margin_trait, padding_trait, spacing_trait -) -from .enable_traits import position_trait, font_trait, engraving_trait -from .radio_group import RadioStyle, RadioGroup - - -# ----------------------------------------------------------------------------- -# Constants: -# ----------------------------------------------------------------------------- - -empty_text_info = (0, 0, 0, 0) -LEFT_OR_RIGHT = LEFT | RIGHT -TOP_OR_BOTTOM = TOP | BOTTOM - - -orientation_trait = PrefixList(["text", "component"], default_value="text") - - -class LabelTraits(HasTraits): - - text = Str - font = font_trait - text_position = position_trait("left") - color = ColorTrait("black") - shadow_color = ColorTrait("white") - style = engraving_trait - - image = image_trait - image_position = position_trait("left") - image_orientation = orientation_trait - - spacing_height = spacing_trait - spacing_width = spacing_trait - padding_left = padding_trait - padding_right = padding_trait - padding_top = padding_trait - padding_bottom = padding_trait - margin_left = margin_trait - margin_right = margin_trait - margin_top = margin_trait - margin_bottom = margin_trait - border_size = border_size_trait - border_color = ColorTrait("black") - bg_color = ColorTrait("clear") - - enabled = Bool(True) - selected = Bool(False) - - # ------------------------------------------------------------------------- - # Trait view definitions: - # ------------------------------------------------------------------------- - - traits_view = View( - Group("enabled", "selected", id="component"), - Group( - "text", - " ", - "font", - " ", - "color", - " ", - "shadow_color", - " ", - "style", - id="text", - style="custom", - ), - Group( - "bg_color{Background Color}", - "_", - "border_color", - "_", - "border_size", - id="border", - style="custom", - ), - Group( - "text_position", - "_", - "image_position", - "_", - "image_orientation", - " ", - "image", - id="position", - style="custom", - ), - Group( - "spacing_height", - "spacing_width", - "_", - "padding_left", - "padding_right", - "padding_top", - "padding_bottom", - "_", - "margin_left", - "margin_right", - "margin_top", - "margin_bottom", - id="margin", - ), - ) - - -default_label_traits = LabelTraits() - -# ----------------------------------------------------------------------------- -# 'Label' class: -# ----------------------------------------------------------------------------- - -LabelTraitDelegate = Delegate("delegate", redraw=True) -LayoutLabelTraitDelegate = LabelTraitDelegate(layout=True) -LabelContentDelegate = LayoutLabelTraitDelegate(content=True) - - -class Label(Component): - - # ------------------------------------------------------------------------- - # Trait definitions: - # ------------------------------------------------------------------------- - - delegate = Trait(default_label_traits) - text = LabelContentDelegate - font = LabelContentDelegate - text_position = LayoutLabelTraitDelegate - color = LabelTraitDelegate - shadow_color = LabelTraitDelegate - style = LabelTraitDelegate - - image = LayoutLabelTraitDelegate - image_position = LayoutLabelTraitDelegate - image_orientation = LayoutLabelTraitDelegate - - spacing_height = LayoutLabelTraitDelegate - spacing_width = LayoutLabelTraitDelegate - padding_left = LayoutLabelTraitDelegate - padding_right = LayoutLabelTraitDelegate - padding_top = LayoutLabelTraitDelegate - padding_bottom = LayoutLabelTraitDelegate - margin_left = LayoutLabelTraitDelegate - margin_right = LayoutLabelTraitDelegate - margin_top = LayoutLabelTraitDelegate - margin_bottom = LayoutLabelTraitDelegate - border_size = LayoutLabelTraitDelegate - border_color = LabelTraitDelegate - bg_color = LabelTraitDelegate - - enabled = LabelTraitDelegate - selected = LabelTraitDelegate - - # ------------------------------------------------------------------------- - # Trait view definitions: - # ------------------------------------------------------------------------- - - traits_view = View( - Group("", "enabled", "selected", id="component"), - Group("", "delegate", id="links"), - Group( - "text", - " ", - "font", - " ", - "color", - " ", - "shadow_color", - " ", - "style", - id="text", - style="custom", - ), - Group( - "bg_color{Background Color}", - "_", - "border_color", - "_", - "border_size", - id="border", - style="custom", - ), - Group( - "text_position", - "_", - "image_position", - "_", - "image_orientation", - " ", - "image", - id="position", - style="custom", - ), - Group( - "spacing_height", - "spacing_width", - "_", - "padding_left", - "padding_right", - "padding_top", - "padding_bottom", - "_", - "margin_left", - "margin_right", - "margin_top", - "margin_bottom", - id="margin", - ), - ) - - colorchip_map = { - "fg_color": "color", - "bg_color": "bg_color", - "shadow_color": "shadow_color", - "alt_color": "border_color", - } - - # ------------------------------------------------------------------------- - # Initialize the object: - # ------------------------------------------------------------------------- - - def __init__(self, text="", **traits): - self.text = text - Component.__init__(self, **traits) - - # ------------------------------------------------------------------------- - # Handle any trait being modified: - # ------------------------------------------------------------------------- - - def _anytrait_changed(self, name, old, new): - trait = self.trait(name) - if trait.content: - self.update_text() - if trait.redraw: - if trait.layout: - self.layout() - self.redraw() - - # ------------------------------------------------------------------------- - # Return the components that contain a specified (x,y) point: - # ------------------------------------------------------------------------- - - def _components_at(self, x, y): - if self._in_margins(x, y): - return [self] - return [] - - # ------------------------------------------------------------------------- - # Return whether not a specified point is inside the component margins: - # ------------------------------------------------------------------------- - - def _in_margins(self, x, y): - ml = self.margin_left - mb = self.margin_bottom - return xy_in_bounds( - x, - y, - add_rectangles( - self.bounds, - (ml, mb, -(self.margin_right + ml), -(self.margin_top + mb)), - ), - ) - - # ------------------------------------------------------------------------- - # Update any information related to the text content of the control: - # ------------------------------------------------------------------------- - - def update_text(self): - text = self.text - if text == "": - self._text = [] - self._tdx = [] - self._max_tdx = self._tdy = 0 - else: - self._text = _text = text.split("\n") - gc = self.gc_temp() - gc.set_font(self.font) - max_tdx = 0 - self._tdx = _tdx = [0] * len(_text) - for i, text in enumerate(_text): - tdx, tdy, descent, leading = gc.get_full_text_extent(text) - tdy += descent + 5 - max_tdx = max(max_tdx, tdx) - _tdx[i] = tdx - self._max_tdx = max_tdx - self._tdy = tdy - - # ------------------------------------------------------------------------- - # Layout and compute the minimum size of the control: - # ------------------------------------------------------------------------- - - def layout(self): - sdx = self.spacing_width - sdy = self.spacing_height - n = len(self._text) - if n == 0: - tdx = tdy = sdx = sdy = 0 - else: - tdx = self._max_tdx - tdy = self._tdy * n - image = self._image - if image is not None: - idx = image.width() - idy = image.height() - else: - idx = idy = sdx = sdy = 0 - image_position = self.image_position_ - if image_position & LEFT_OR_RIGHT: - itdx = tdx + sdx + idx - if image_position & LEFT: - ix = 0 - tx = idx + sdx - else: - tx = 0 - ix = tdx + sdx - else: - itdx = max(tdx, idx) - ix = (itdx - idx) / 2.0 - tx = (itdx - tdx) / 2.0 - if image_position & TOP_OR_BOTTOM: - itdy = tdy + sdy + idy - if image_position & TOP: - iy = tdy + sdy - ty = 0 - else: - iy = 0 - ty = idy + sdy - else: - itdy = max(tdy, idy) - iy = (itdy - idy) / 2.0 - ty = (itdy - tdy) / 2.0 - bs = 2 * self.border_size - self.min_width = itdx + ( - self.margin_left - + self.margin_right - + self.padding_left - + self.padding_right - + bs - ) - self.min_height = itdy + ( - self.margin_top - + self.margin_bottom - + self.padding_top - + self.padding_bottom - + bs - ) - self._info = (ix, iy, idx, idy, tx, ty, tdx, self._tdy, itdx, itdy) - - # ------------------------------------------------------------------------- - # Draw the contents of the control: - # ------------------------------------------------------------------------- - - def _draw(self, gc, view_bounds, mode): - - # Set up all the control variables for quick access: - ml = self.margin_left - mr = self.margin_right - mt = self.margin_top - mb = self.margin_bottom - pl = self.padding_left - pr = self.padding_right - pt = self.padding_top - pb = self.padding_bottom - bs = self.border_size - bsd = bs + bs - bsh = bs / 2.0 - x, y, dx, dy = self.bounds - - ix, iy, idx, idy, tx, ty, tdx, tdy, itdx, itdy = self._info - - # Fill the background region (if required); - bg_color = self.bg_color_ - if bg_color is not transparent_color: - with gc: - gc.set_fill_color(bg_color) - gc.begin_path() - gc.rect( - x + ml + bs, - y + mb + bs, - dx - ml - mr - bsd, - dy - mb - mt - bsd, - ) - gc.fill_path() - - # Draw the border (if required): - if bs > 0: - border_color = self.border_color_ - if border_color is not transparent_color: - with gc: - gc.set_stroke_color(border_color) - gc.set_line_width(bs) - gc.begin_path() - gc.rect( - x + ml + bsh, - y + mb + bsh, - dx - ml - mr - bs, - dy - mb - mt - bs, - ) - gc.stroke_path() - - # Calculate the origin of the image/text box: - text_position = self.text_position_ - - if self.image_orientation == "text": - # Handle the 'image relative to text' case: - if text_position & RIGHT: - itx = x + dx - mr - bs - pr - itdx - else: - itx = x + ml + bs + pl - if text_position & HCENTER: - itx += (dx - ml - mr - bsd - pl - pr - itdx) / 2.0 - if text_position & TOP: - ity = y + dy - mt - bs - pt - itdy - else: - ity = y + mb + bs + pb - if text_position & VCENTER: - ity += (dy - mb - mt - bsd - pb - pt - itdy) / 2.0 - else: - # Handle the 'image relative to component' case: - itx = ity = 0.0 - if text_position & RIGHT: - tx = x + dx - mr - bs - pr - tdx - else: - tx = x + ml + bs + pl - if text_position & HCENTER: - tx += (dx - ml - mr - bsd - pl - pr - tdx) / 2.0 - if text_position & TOP: - ty = y + dy - mt - bs - pt - tdy - else: - ty = y + mb + bs + pb - if text_position & VCENTER: - ty += (dy - mb - mt - bsd - pb - pt - tdy) / 2.0 - - image_position = self.image_position_ - if image_position & RIGHT: - ix = x + dx - mr - bs - pr - idx - else: - ix = x + ml + bs + pl - if image_position & HCENTER: - ix += (dx - ml - mr - bsd - pl - pr - idx) / 2.0 - if image_position & TOP: - iy = y + dy - mt - bs - pt - idy - else: - iy = y + mb + bs + pb - if image_position & VCENTER: - iy += (dy - mb - mt - bsd - pb - pt - idy) / 2.0 - - with gc: - # Draw the image (if required): - image = self._image - if image is not None: - gc.draw_image(image, (itx + ix, ity + iy, idx, idy)) - - # Draw the text (if required): - gc.set_font(self.font) - _text = self._text - _tdx = self._tdx - tx += itx - ty += ity + tdy * len(_text) - style = self.style_ - shadow_color = self.shadow_color_ - text_color = self.color_ - for i, text in enumerate(_text): - ty -= tdy - _tx = tx - if text_position & RIGHT: - _tx += tdx - _tdx[i] - elif text_position & HCENTER: - _tx += (tdx - _tdx[i]) / 2.0 - # Draw the 'shadow' text, if requested: - if (style != 0) and (shadow_color is not transparent_color): - if style == EMBOSSED: - gc.set_fill_color(shadow_color) - gc.set_text_position(_tx - 1.0, ty + 1.0) - elif style == ENGRAVED: - gc.set_fill_color(shadow_color) - gc.set_text_position(_tx + 1.0, ty - 1.0) - else: - gc.set_fill_color(shadow_color) - gc.set_text_position(_tx + 2.0, ty - 2.0) - gc.show_text(text) - - # Draw the normal text: - gc.set_fill_color(text_color) - gc.set_text_position(_tx, ty) - gc.show_text(text) - - # -- Pickling Protocol ---------------------------------------------------- - - def __getstate__(self): - dict = self.__dict__.copy() - try: - del dict["_image"] - except Exception: - pass - return dict - - def __setstate__(self, state): - self.__dict__.update(state) - self.image = self.image - - -# ----------------------------------------------------------------------------- -# 'CheckBox' class: -# ----------------------------------------------------------------------------- - - -class CheckBox(Label): - - # ------------------------------------------------------------------------- - # Trait definitions: - # ------------------------------------------------------------------------- - - image_base = Str("=checkbox") - - # ------------------------------------------------------------------------- - # Trait editor definition: - # ------------------------------------------------------------------------- - - position = Group("", "image_base") - - # ------------------------------------------------------------------------- - # Initialize the object: - # ------------------------------------------------------------------------- - - def __init__(self, text="", **traits): - Label.__init__(self, text, **traits) - self._select_image() - - # ------------------------------------------------------------------------- - # Select the correct image to display: - # ------------------------------------------------------------------------- - - def _select_image(self, *suffixes): - if len(suffixes) == 0: - suffixes = [self._suffix()] - base, ext = os.path.splitext(self.image_base) - for suffix in suffixes: - image = "%s%s%s" % (base, suffix, ext) - if self.image_for(image) is not None: - self.image = image - break - - # ------------------------------------------------------------------------- - # Select the image suffix based on the current selection state: - # ------------------------------------------------------------------------- - - def _suffix(self): - return ["", "_on"][self.selected] - - # ------------------------------------------------------------------------- - # Set the selection state of the component: - # ------------------------------------------------------------------------- - - def _select(self): - self.selected = not self.selected - - # ------------------------------------------------------------------------- - # Handle the 'selected' status of the checkbox being changed: - # ------------------------------------------------------------------------- - - def _selected_changed(self): - base = self._suffix() - self._select_image(base + ["", "_over"][self._over is True], base) - - # ------------------------------------------------------------------------- - # Handle mouse events: - # ------------------------------------------------------------------------- - - def _left_down_changed(self, event): - event.handled = True - if self._in_margins(event.x, event.y): - event.window.mouse_owner = self - base = self._suffix() - self._select_image(base + "_down", base) - self._down = True - - def _left_dclick_changed(self, event): - self._left_down_changed(event) - - def _left_up_changed(self, event): - event.handled = True - event.window.mouse_owner = self._down = None - if self._in_margins(event.x, event.y): - self._select() - - def _mouse_move_changed(self, event): - event.handled = True - self._over = self._in_margins(event.x, event.y) - if self._over: - event.window.mouse_owner = self - base = self._suffix() - self._select_image( - base + ["_over", "_down"][self._down is not None], base - ) - else: - if self._down is None: - event.window.mouse_owner = None - self._select_image() - - -# ----------------------------------------------------------------------------- -# 'RadioButton' class: -# ----------------------------------------------------------------------------- - - -class Radio(CheckBox, RadioStyle): - - # ------------------------------------------------------------------------- - # Trait definitions: - # ------------------------------------------------------------------------- - - image_base = Str("=radio") - - # ------------------------------------------------------------------------- - # Set the selection state of the component: - # ------------------------------------------------------------------------- - - def _select(self): - self.selected = True - - # ------------------------------------------------------------------------- - # Handle the container the component belongs to being changed: - # ------------------------------------------------------------------------- - - def _container_changed(self, old, new): - CheckBox._container_changed(self) - if self.radio_group is old.radio_group: - self.radio_group = None - if self.radio_group is None: - if new.radio_group is None: - new.radio_group = RadioGroup() - new.radio_group.add(self) - - # ------------------------------------------------------------------------- - # Handle the 'selected' status of the checkbox being changed: - # ------------------------------------------------------------------------- - - def _selected_changed(self): - CheckBox._selected_changed(self) - if self.selected: - self.radio_group.selection = self diff --git a/enable/drag.py b/enable/drag.py deleted file mode 100644 index d04969283..000000000 --- a/enable/drag.py +++ /dev/null @@ -1,226 +0,0 @@ -# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! - -from .base import ( - add_rectangles, bounds_to_coordinates, intersect_coordinates, send_event_to -) -from .events import DragEvent -from .interactor import Interactor - -# --------------------------------------------------------------------------- -# 'DragHandler' class: -# --------------------------------------------------------------------------- - - -class DragHandler(Interactor): - - # ------------------------------------------------------------------------- - # Initialize the object: - # ------------------------------------------------------------------------- - - def init(self, components, bounds_rect, drag_root, drag_bounds_rect, - drag_copy, drag_event, start_event): - self.components = components[:] - self.bounds_rect = bounds_rect - self.drag_root = drag_root - self.drag_bounds_rect = self.drag_bounds_rect_start = drag_bounds_rect - self.drag_copy = drag_copy - self.drag_event = drag_event - self.start_event = start_event - self.drag_x = self.start_x = start_event.x - self.drag_y = self.start_y = start_event.y - self.window = components[0].window - self.drag_over = [] - - self.on_trait_change(self.drag_done, drag_event) - - # ------------------------------------------------------------------------- - # Handle the mouse moving while dragging: - # ------------------------------------------------------------------------- - - def _mouse_move_changed(self, event): - # Get the current drag location: - x = event.x - y = event.y - - # If the mouse did not actually move, then ignore the event: - if (x == self.drag_x) and (y == self.drag_y): - return - - # Save the new position: - self.drag_x = x - self.drag_y = y - - # Calculate the distance moved from the original starting point: - dx = x - self.start_x - dy = y - self.start_y - - # Calculate the new drag bounds: - xl, yb, xr, yt = add_rectangles( - self.drag_bounds_rect_start, (dx, dy, dx, dy) - ) - - # Adjust the new drag location if it is not completely within the drag - # bounds. Exit if the result is the same as the previous location: - if self.bounds_rect is not None: - bxl, byb, bxr, byt = self.bounds_rect - if xl < bxl: - xr += bxl - xl - xl = bxl - elif xr > bxr: - xl -= xr - bxr - xr = bxr - if yb < byb: - yt += byb - yb - yb = byb - elif yt > byt: - yb -= yt - byt - yt = byt - x = xl - self.drag_bounds_rect[0] + self.drag_x - y = yb - self.drag_bounds_rect[1] + self.drag_y - - # If the new drag bounds is the same as the last one, nothing changed: - drag_bounds_rect = bounds_to_coordinates( - self.drag_validate(event, (xl, yb, xr - xl, yt - yb)) - ) - if drag_bounds_rect == self.drag_bounds_rect: - return - - # Update the drag bounds and current drag location: - self.drag_bounds_rect = drag_bounds_rect - - # Notify each drag component of its new drag location: - dx = drag_bounds_rect[0] - self.drag_bounds_rect_start[0] - dy = drag_bounds_rect[1] - self.drag_bounds_rect_start[1] - for component in self.components: - cx, cy = component.location() - component.dragged = DragEvent( - x=cx + dx, - y=cy + dy, - x0=self.start_x, - y0=self.start_y, - copy=self.drag_copy, - components=self.components, - start_event=self.start_event, - window=event.window, - ) - - # Process the 'drag_over' events for any objects being dragged over: - drag_over_event = DragEvent( - x=x, - y=y, - x0=self.start_x, - y0=self.start_y, - copy=self.drag_copy, - components=self.components, - start_event=self.start_event, - window=event.window, - ) - new_drag_over = [] - cur_drag_over = self.drag_over - for component in self.drag_root.components_at(x, y): - new_drag_over.append(component) - if component in cur_drag_over: - cur_drag_over.remove(component) - component.drag_over = drag_over_event - else: - component.drag_enter = drag_over_event - for component in cur_drag_over: - component.drag_leave = drag_over_event - self.drag_over = new_drag_over - - # Tell the Enable window where the drag is now: - self.window.set_drag_bounds_rect(drag_bounds_rect) - - # ------------------------------------------------------------------------- - # Validate the proposed new drag location (by default, just accept it): - # ------------------------------------------------------------------------- - - def drag_validate(self, event, drag_bounds): - return drag_bounds - - # ------------------------------------------------------------------------- - # Handle the user releasing the original drag button: - # ------------------------------------------------------------------------- - - def drag_done(self, event): - components = self.components - drag_copy = self.drag_copy - start_event = self.start_event - - # 'Unhook' the drag done notification handler: - self.on_trait_change(self.drag_done, self.drag_event, remove=True) - - # Compute the new drag bounds: - x = event.x - y = event.y - dx = x - self.start_x - dy = y - self.start_y - xl, yb, xr, yt = add_rectangles( - self.drag_bounds_rect_start, (dx, dy, dx, dy) - ) - drag_bounds_rect = bounds_to_coordinates( - self.drag_validate(event, (xl, yb, xr - xl, yt - yb)) - ) - - # If the new bounds are not within the drag area, use the last drag - # location: - if (self.bounds_rect is not None - and (intersect_coordinates(self.bounds_rect, drag_bounds_rect) - != drag_bounds_rect)): - drag_bounds_rect = self.drag_bounds_rect - - # Notify each dragged component where it was dropped: - dx = drag_bounds_rect[0] - self.drag_bounds_rect_start[0] - dy = drag_bounds_rect[1] - self.drag_bounds_rect_start[1] - for component in components: - cx, cy = component.location() - component.dropped = DragEvent( - x=cx + dx, - y=cy + dy, - x0=self.start_x, - y0=self.start_y, - copy=drag_copy, - components=components, - start_event=start_event, - window=event.window, - ) - - # Process the 'dropped_on' event for the object(s) it was dropped on: - components_at = self.drag_root.components_at(x, y) - drag_event = DragEvent( - x=self.start_x + dx, - y=self.start_y + dy, - x0=self.start_x, - y0=self.start_y, - copy=drag_copy, - components=components, - start_event=start_event, - window=event.window, - ) - index = send_event_to(components_at, "dropped_on", drag_event) - - # Send all the runner-ups a 'drag_leave' consolation prize: - drag_over = self.drag_over - for component in components_at[0:index]: - if component in drag_over: - component.drag_leave = drag_event - - # Make sure all of the dragged components are drawable again: - if not drag_copy: - for component in components: - component._drawable = True - - # Redraw the window to clean-up any drag artifacts: - self.window.redraw() - - # Finally, release any references we have been using: - self.components[:] = [] - self.drag_over = self.drag_root = self.window = None diff --git a/enable/drag_resize.py b/enable/drag_resize.py deleted file mode 100644 index 4da51e218..000000000 --- a/enable/drag_resize.py +++ /dev/null @@ -1,157 +0,0 @@ -# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! - -from traits.api import Any - -from .base import BOTTOM, LEFT, RIGHT, TOP, bounds_to_coordinates -from .interactor import Interactor - -# ----------------------------------------------------------------------------- -# 'DragResizeHandler' class: -# ----------------------------------------------------------------------------- - - -class DragResizeHandler(Interactor): - - # ------------------------------------------------------------------------- - # Trait definitions: - # ------------------------------------------------------------------------- - - # User-supplied drag event validation function: - drag_validate = Any - - # ------------------------------------------------------------------------- - # Initialize the object: - # ------------------------------------------------------------------------- - - def init(self, component, bounds_rect, anchor, unconstrain, drag_event, - start_event): - self.component = component - self.bounds_rect = bounds_rect - self.anchor = anchor - self.unconstrain = unconstrain - self.drag_event = drag_event - self.start_event = start_event - self.drag_x = self.start_x = start_event.x - self.drag_y = self.start_y = start_event.y - - # Get the coordinates of the anchor point: - xl, yb, xr, yt = bounds_to_coordinates(component.bounds) - if (anchor & LEFT) != 0: - self.anchor_x = xl - self.float_x = xr - else: - self.anchor_x = xr - self.float_x = xl - if (anchor & BOTTOM) != 0: - self.anchor_y = yb - self.float_y = yt - else: - self.anchor_y = yt - self.float_y = yb - - # Set up the drag termination handler: - self.on_trait_change(self.drag_done, drag_event) - - # ------------------------------------------------------------------------- - # Handle the mouse moving while resizing: - # ------------------------------------------------------------------------- - - def _mouse_move_changed(self, event): - # Get the current drag location: - x = event.x - y = event.y - - # If the mouse did not actually move, then ignore the event: - if (x == self.drag_x) and (y == self.drag_y): - return - - # Save the new position: - self.drag_x = x - self.drag_y = y - - # Calculate the new 'floating' point: - unconstrain = self.unconstrain - ax, ay = self.anchor_x, self.anchor_y - nx, ny = self.float_x, self.float_y - if (unconstrain & (LEFT | RIGHT)) != 0: - nx = self.float_x + x - self.start_x - if nx > ax: - if (unconstrain & RIGHT) == 0: - nx = ax - elif nx < ax: - if (unconstrain & LEFT) == 0: - nx = ax - if (unconstrain & (TOP | BOTTOM)) != 0: - ny = self.float_y + y - self.start_y - if ny > ay: - if (unconstrain & TOP) == 0: - ny = ay - elif ny < ay: - if (unconstrain & BOTTOM) == 0: - ny = ay - - # Make sure the new point is inside the drag bounds (if required): - if self.bounds_rect is not None: - bxl, byb, bxr, byt = self.bounds_rect - nx = max(min(nx, bxr), bxl) - ny = max(min(ny, byt), byb) - - # Calculate the new size of the component and make sure that it meets - # the min and max size requirements for the component: - component = self.component - mindx, maxdx = component.min_width, component.max_width - mindy, maxdy = component.min_height, component.max_height - ndx, ndy = abs(nx - ax) + 1, abs(ny - ay) + 1 - if ndx > maxdx: - if nx > ax: - nx = ax + maxdx - else: - nx = ax - maxdx - elif ndx < mindx: - if nx < ax: - nx = ax - mindx - elif (nx > ax) or ((unconstrain & RIGHT) != 0): - nx = ax + mindx - else: - nx = ax - mindx - if ndy > maxdy: - if ny > ay: - ny = ay + maxdy - else: - ny = ay - maxdy - elif ndy < mindy: - if ny < ay: - ny = ay - mindy - elif (ny > ay) or ((unconstrain & TOP) != 0): - ny = ay + mindy - else: - ny = ay - mindy - - # Update the bounds of the component: - bounds = (min(nx, ax), min(ny, ay), abs(nx - ax) + 1, abs(ny - ay) + 1) - if self.drag_validate is not None: - bounds = self.drag_validate(event, bounds) - if bounds != component.bounds: - component.bounds = bounds - - # Tell the 'paint' routine we are doing a drag resize operation: - event.window.drag_resize_update() - - # ------------------------------------------------------------------------- - # Handle the user releasing the original drag button: - # ------------------------------------------------------------------------- - - def drag_done(self, event): - # 'Unhook' the drag done notification handler: - self.on_trait_change(self.drag_done, self.drag_event, remove=True) - - # Inform the component that the resize operation is complete: - self.component.resized = True diff --git a/enable/qt4/base_window.py b/enable/qt4/base_window.py index ccd8b5f0d..54c478057 100644 --- a/enable/qt4/base_window.py +++ b/enable/qt4/base_window.py @@ -346,11 +346,6 @@ def dragMoveEvent(self, event): def dropEvent(self, event): self.handler.dropEvent(event) - # TODO: by symmetry this belongs here, but we need to test it - # def sizeHint(self): - # qt_size_hint = super(_QtGLWindow, self).sizeHint() - # return self.handler.sizeHint(qt_size_hint) - class _Window(AbstractWindow): diff --git a/enable/radio_group.py b/enable/radio_group.py deleted file mode 100644 index a78b41b2a..000000000 --- a/enable/radio_group.py +++ /dev/null @@ -1,95 +0,0 @@ -# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! - -# ----------------------------------------------------------------------------- -# Imports: -# ----------------------------------------------------------------------------- - -from traits.api import HasPrivateTraits, Trait - -# ----------------------------------------------------------------------------- -# Trait definitions: -# ----------------------------------------------------------------------------- - -# ARadioGroup = Instance( 'RadioGroup' ) - -# ----------------------------------------------------------------------------- -# 'RadioStyle' class: -# ----------------------------------------------------------------------------- - - -class RadioStyle(HasPrivateTraits): - - # ------------------------------------------------------------------------- - # Trait definitions: - # ------------------------------------------------------------------------- - - # radio_group = ARadioGroup - - # ------------------------------------------------------------------------- - # Handle the group the radio style component belongs to being changed: - # ------------------------------------------------------------------------- - - def _group_changed(self, old, new): - if old is not None: - old.remove(self) - if new is not None: - new.add(self) - - -# ----------------------------------------------------------------------------- -# 'RadioGroup' class: -# ----------------------------------------------------------------------------- - - -class RadioGroup(HasPrivateTraits): - - # ------------------------------------------------------------------------- - # Trait definitions: - # ------------------------------------------------------------------------- - - # selection = Instance( RadioStyle ) - selection = Trait(None, RadioStyle) - - # ------------------------------------------------------------------------- - # Handle elements being added to the group: - # ------------------------------------------------------------------------- - - def add(self, *components): - for component in components: - component.radio_group = self - if component.selected and (self.selection is not component): - if self.selection is not None: - component.selected = False - else: - self.selection = component - - # ------------------------------------------------------------------------- - # Handle components being removed from the group: - # ------------------------------------------------------------------------- - - def remove(self, *components): - for component in components: - if component is self.selection: - self.selection is None - break - - # ------------------------------------------------------------------------- - # Handle the selection being changed: - # ------------------------------------------------------------------------- - - def _selection_changed(self, old, new): - if old is not None: - old.selected = False - - -radio_group_trait = Trait(None, RadioGroup) - -RadioStyle.add_class_trait("radio_group", radio_group_trait) diff --git a/enable/render_controllers.py b/enable/render_controllers.py deleted file mode 100644 index ff6bea0b0..000000000 --- a/enable/render_controllers.py +++ /dev/null @@ -1,102 +0,0 @@ -# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! - -# Enthought library imports -from traits.api import HasTraits - - -class AbstractRenderController(HasTraits): - def draw(self, component, gc, view_bounds=None, mode="normal"): - raise NotImplementedError - - -class RenderController(AbstractRenderController): - """ The default Enable render controller for components """ - - # The default list of available layers. - LAYERS = [ - "background", - "image", - "underlay", - "component", - "overlay", - "border", - ] - - def draw(self, component, gc, view_bounds=None, mode="normal"): - if component.visible: - for layer in self.LAYERS: - func = getattr(component, "_draw_" + layer, None) - if func: - func(gc, view_bounds, mode) - - -class OldEnableRenderController(AbstractRenderController): - """ - Performs rendering of components and containers in the default way - that Enable used to, prior to the encapsulation of rendering in - RenderControllers. - - Note that containers have a default implementation of _draw() that - in turn calls _draw_container(), which is pass-through in the base class. - """ - - def draw(self, component, gc, view_bounds=None, mode="normal"): - component._draw_background(gc, view_bounds, mode) - component._draw(gc, view_bounds, mode) - component._draw_border(gc, view_bounds, mode) - - -class OldChacoRenderController(AbstractRenderController): - """ Performs render the way that it was done before the draw_order - changes were implemented. - - This has the name Chaco in it because this functionality used to be - in Chaco; however, with configurable rendering now in Enable, this - class resides in the Enable package, and will eventually be deprecated. - """ - - def draw(self, component, gc, view_bounds=None, mode="normal"): - if component.visible: - # Determine if the component has an active tool and if - # we need to transfer execution to it - tool = component._active_tool - if tool is not None and tool.draw_mode == "overlay": - tool.draw(gc, view_bounds) - else: - if component.use_backbuffer: - if mode == "overlay": - # Since kiva currently doesn't support blend modes, - # if we have to draw in overlay mode, we have to draw - # normally. - self._do_draw(component, gc, view_bounds, mode) - component._backbuffer = None - component.invalidate_draw() - if not self.draw_valid: - from .kiva_graphics_context import GraphicsContext - - bb = GraphicsContext(tuple(map(int, component.bounds))) - bb.translate_ctm(-component.x, -component.y) - self._do_draw( - component, bb, view_bounds=None, mode=mode - ) - component._backbufer = bb - component.draw_valid = True - - gc.draw_imge( - component._backbuffer, - component.position + component.bounds, - ) - - else: - self._do_draw(component, gc, view_bounds, mode) - - def _do_draw(self, component, gc, view_bounds=None, mode="normal"): - pass diff --git a/enable/scroll_handler.py b/enable/scroll_handler.py deleted file mode 100644 index 05e548e56..000000000 --- a/enable/scroll_handler.py +++ /dev/null @@ -1,47 +0,0 @@ -# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! -""" -Interface for scroll handlers. -""" - - -class ScrollHandler: - """ The interface for scroll handlers. - - A scroll handler handles the scroll events generated by scrollbar events - in a Scrolled component. By default, a Scrolled will serve as its own - ScrollHandler. In that role, Scrolled will merely move and clip the - child component. - - If a component wishes to manage its own scrolling, it may do so, by - implementing this interface and attaching itself as its parent's scroll - manager. - - """ - - def handle_vertical_scroll(self, position): - """ Called when the vertical scroll position has changed. - - The position parameter will be the current position of the vertical - scroll bar. - - """ - - raise NotImplementedError - - def handle_horizontal_scroll(self, position): - """ Called when the horizontal scroll position has changed. - - The position parameter will be the current position of the horizontal - scroll bar. - - """ - - raise NotImplementedError diff --git a/enable/scrollbar.py b/enable/scrollbar.py deleted file mode 100644 index 44f7b0526..000000000 --- a/enable/scrollbar.py +++ /dev/null @@ -1,481 +0,0 @@ -# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! -""" -Define a standard horizontal and vertical Enable 'scrollbar' component. - -The scrollbar uses images for the pieces of the scrollbar itself and stretches -them appropriately in the draw phase. -""" - -from functools import reduce - -# PZW: Define a scrollbar that uses the system/wx-native scrollbar instead -# of drawing our own. - -from traits.api import Event, Property, Trait, TraitError -from traitsui.api import Group, View - -# Relative imports -from .component import Component -from .enable_traits import layout_style_trait - - -# ----------------------------------------------------------------------------- -# Constants: -# ----------------------------------------------------------------------------- - -# Scroll bar zones: -NO_SCROLL = -1 -LINE_UP = 0 -PAGE_UP = 1 -LINE_DOWN = 2 -PAGE_DOWN = 3 -SLIDER = 4 - -# Scrollbar suffix names by zone: -zone_suffixes = [ - "_line_up_suffix", - "", - "_line_down_suffix", - "", - "_slider_suffix", -] - -# Scroll information look-up table: -scroll_info = [ - ("line_up", 1.0, 3), - ("page_up", 1.0, 2), - ("line_down", -1.0, 3), - ("page_down", -1.0, 2), -] - -# Scroll bar images and sizes: -sb_image = {} -v_width = 0 -v_height = 0 -vs_height = 0 -h_width = 0 -h_height = 0 -hs_width = 0 - - -# ----------------------------------------------------------------------------- -# Traits validators -# ----------------------------------------------------------------------------- - - -def valid_range(object, name, value): - "Verify that a set of range values for a scrollbar is valid" - try: - if (type(value) is tuple) and (len(value) == 4): - low, high, page_size, line_size = value - if high < low: - low, high = high, low - elif high == low: - high = low + 1.0 - page_size = max(min(page_size, high - low), 0.0) - line_size = max(min(line_size, page_size), 0.0) - return ( - float(low), - float(high), - float(page_size), - float(line_size), - ) - except Exception: - pass - raise TraitError - - -valid_range.info = "a (low,high,page_size,line_size) range tuple" - - -def valid_position(object, name, value): - "Verify that a specified scroll bar position is valid" - try: - low, high, page_size, line_size = object.range - return max(min(float(value), high - page_size), low) - except Exception: - pass - raise TraitError - - -class ScrollBar(Component): - - position = Trait(0.0, valid_position) - range = Trait((0.0, 100.0, 10.0, 1.0), valid_range) - style = layout_style_trait - - line_up = Event - line_down = Event - page_up = Event - page_down = Event - scroll_done = Event - - traits_view = View( - Group("", id="component"), - Group("", id="links"), - Group( - "style", - " ", - "position", - "low", - "high", - "page_size", - "line_size", - id="scrollbar", - style="custom", - ), - ) - - # ------------------------------------------------------------------------- - # Property definitions: - # ------------------------------------------------------------------------- - - def __low_get(self): - return self.range[0] - - def __low_set(self, low): - ignore, high, page_size, line_size = self.range - self.range = (low, high, page_size, line_size) - - def __high_get(self): - return self.range[1] - - def __high_set(self, high): - low, ignore, page_size, line_size = self.range - self.range = (low, high, page_size, line_size) - - def __page_size_get(self): - return self.range[2] - - def __page_size_set(self, page_size): - low, high, ignore, line_size = self.range - self.range = (low, high, page_size, line_size) - - def __line_size_get(self): - return self.range[3] - - def __line_size_set(self, line_size): - low, high, page_size, ignore = self.range - self.range = (low, high, page_size, line_size) - - # Define 'position, low, high, page_size' properties: - low = Property(__low_get, __low_set) - high = Property(__high_get, __high_set) - page_size = Property(__page_size_get, __page_size_set) - line_size = Property(__line_size_get, __line_size_set) - - def __init__(self, **traits): - if v_width == 0: - self._init_images() - Component.__init__(self, **traits) - self._scrolling = self._zone = NO_SCROLL - self._line_up_suffix = ( - self._line_down_suffix - ) = self._slider_suffix = "" - self._style_changed(self.style) - - def _init_images(self): - "One time initialization of the scrollbar images" - global sb_image, v_width, v_height, vs_height - global h_width, h_height, hs_width - - for name in [ - "aup", - "adown", - "aleft", - "aright", - "vtop", - "vbottom", - "vmid", - "vpad", - "hleft", - "hright", - "hmid", - "hpad", - ]: - sb_image[name] = self.image_for("=sb_%s" % name) - sb_image[name + "_over"] = self.image_for("=sb_%s_over" % name) - sb_image[name + "_down"] = self.image_for("=sb_%s_down" % name) - sb_image["vtrack"] = self.image_for("=sb_vtrack") - sb_image["htrack"] = self.image_for("=sb_htrack") - v_width = sb_image["vtrack"].width() - vs_height = reduce( - lambda a, b: a + sb_image[b].height(), - ["vtop", "vbottom", "vmid"], - 0, - ) - v_height = reduce( - lambda a, b: a + sb_image[b].height(), ["aup", "adown"], vs_height - ) - hs_width = reduce( - lambda a, b: a + sb_image[b].width(), - ["hleft", "hright", "hmid"], - 0, - ) - h_width = reduce( - lambda a, b: a + sb_image[b].width(), ["aleft", "aright"], hs_width - ) - h_height = sb_image["htrack"].height() - - def _range_changed(self): - "Handle any of the range elements values being changed" - low, high, page_size, line_size = self.range - self.position = max(min(self.position, high - page_size), low) - self.redraw() - - def _position_changed(self): - self.redraw() - - def _style_changed(self, style): - "Handle the orientation style being changed" - if style[0] == "v": - self.min_width = self.max_width = v_width - self.min_height = v_height - self.max_height = 99999.0 - self.stretch_width = 0.0 - self.stretch_height = 1.0 - else: - self.min_width = h_width - self.max_width = 99999.0 - self.min_height = self.max_height = h_height - self.stretch_width = 1.0 - self.stretch_height = 0.0 - - def _draw(self, gc): - "Draw the contents of the control" - with gc: - if self.style[0] == "v": - self._draw_vertical(gc) - else: - self._draw_horizontal(gc) - - def _draw_vertical(self, gc): - "Draw a vertical scrollbar" - low, high, page_size, line_size = self.range - position = self.position - x, y, dx, dy = self.bounds - adown = sb_image["adown" + self._line_down_suffix] - adown_dy = adown.height() - aup = sb_image["aup" + self._line_up_suffix] - aup_dy = aup.height() - vtrack = sb_image["vtrack"] - t_dy = dy - aup_dy - adown_dy - t_y = s_y = y + adown_dy - u_y = y + dy - aup_dy - gc.stretch_draw(vtrack, x, t_y, dx, t_dy) - gc.draw_image(adown, (x, y, dx, adown_dy)) - gc.draw_image(aup, (x, u_y, dx, aup_dy)) - if page_size > 0.0: - s_dy = max(vs_height, round((page_size * t_dy) / (high - low))) - self._range = range_dy = t_dy - s_dy - range = high - low - page_size - if range > 0.0: - s_y = round(s_y + (((position - low) * range_dy) / range)) - suffix = self._slider_suffix - vbottom = sb_image["vbottom" + suffix] - vbottom_dy = vbottom.height() - vtop = sb_image["vtop" + suffix] - vtop_dy = vtop.height() - vmid = sb_image["vmid" + suffix] - vmid_dy = vmid.height() - gc.stretch_draw( - sb_image["vpad" + suffix], - x, - s_y + vbottom_dy, - dx, - s_dy - vbottom_dy - vtop_dy, - ) - gc.draw_image(vbottom, (x, s_y, dx, vbottom_dy)) - gc.draw_image(vtop, (x, s_y + s_dy - vtop_dy, dx, vtop_dy)) - gc.draw_image( - vmid, - ( - x, - round( - s_y - + vbottom_dy - + (s_dy - vbottom_dy - vtop_dy - vmid_dy) / 2.0 - ), - dx, - vmid_dy, - ), - ) - self._info = (t_y, s_y, s_y + s_dy, u_y) - - def _draw_horizontal(self, gc): - "Draw a horizontal scroll bar" - low, high, page_size, line_size = self.range - position = self.position - x, y, dx, dy = self.bounds - aleft = sb_image["aleft" + self._line_up_suffix] - aleft_dx = aleft.width() - aright = sb_image["aright" + self._line_down_suffix] - aright_dx = aright.width() - htrack = sb_image["htrack"] - t_dx = dx - aleft_dx - aright_dx - t_x = s_x = x + aleft_dx - r_x = x + dx - aright_dx - gc.stretch_draw(htrack, t_x, y, t_dx, dy) - gc.draw_image(aleft, (x, y, aleft_dx, dy)) - gc.draw_image(aright, (r_x, y, aright_dx, dy)) - if page_size > 0.0: - s_dx = max(hs_width, round((page_size * t_dx) / (high - low))) - self._range = range_dx = t_dx - s_dx - range = high - low - page_size - if range > 0.0: - s_x = round(s_x + (((position - low) * range_dx) / range)) - suffix = self._slider_suffix - hleft = sb_image["hleft" + suffix] - hleft_dx = hleft.width() - hright = sb_image["hright" + suffix] - hright_dx = hright.width() - hmid = sb_image["hmid" + suffix] - hmid_dx = hmid.width() - gc.stretch_draw( - sb_image["hpad" + suffix], - s_x + hleft_dx, - y, - s_dx - hleft_dx - hright_dx, - dy, - ) - gc.draw_image(hleft, (s_x, y, hleft_dx, dy)) - gc.draw_image(hright, (s_x + s_dx - hright_dx, y, hright_dx, dy)) - gc.draw_image( - hmid, - ( - round( - s_x - + hleft_dx - + (s_dx - hleft_dx - hright_dx - hmid_dx) / 2.0 - ), - y, - hmid_dx, - dy, - ), - ) - self._info = (t_x, s_x, s_x + s_dx, r_x) - - def _get_zone(self, event): - "Determine which scrollbar zone the mouse pointer is over" - if not self.xy_in_bounds(event) or (self._info is None): - return NO_SCROLL - cbl, csl, csh, ctr = self._info - c = [event.x, event.y][self.style[0] == "v"] - if c < cbl: - return LINE_DOWN - if c >= ctr: - return LINE_UP - if c < csl: - return PAGE_DOWN - if c >= csh: - return PAGE_UP - return SLIDER - - def _scroll(self): - "Perform an incremental scroll (line up/down, page up/down)" - incr = self._scroll_incr - if incr != 0.0: - low, high, page_size, line_size = self.range - position = max(min(self.position + incr, high - page_size), low) - if position == self.position: - return - self.position = position - setattr(self, self._event_name, True) - - def _set_zone_suffix(self, zone, suffix): - "Set a particular zone's image suffix" - if zone != NO_SCROLL: - suffix_name = zone_suffixes[zone] - if suffix_name != "": - setattr(self, suffix_name, suffix) - self.redraw() - - # ------------------------------------------------------------------------- - # Handle mouse events: - # ------------------------------------------------------------------------- - - def _left_down_changed(self, event): - event.handled = True - if self.range[2] == 0.0: - return - zone = self._get_zone(event) - if zone != NO_SCROLL: - self.window.mouse_owner = self - self._scrolling = zone - self._set_zone_suffix(zone, "_down") - if zone == SLIDER: - self._xy = (event.x, event.y)[self.style[0] == "v"] - self._position = self.position - else: - self._event_name, sign, index = scroll_info[zone] - line_size = self.range[3] - incr = 0.0 - if line_size != 0.0: - incr = sign * self.range[index] - if index == 2: - incr -= sign * line_size - self._scroll_incr = incr - self._scroll() - self._in_zone = True - self.timer_interval = 0.5 - - def _left_dclick_changed(self, event): - self._left_down_changed(event) - - def _left_up_changed(self, event): - event.handled = True - scrolling = self._scrolling - if scrolling != NO_SCROLL: - zone = self._get_zone(event) - self._set_zone_suffix(scrolling, "") - self._set_zone_suffix(zone, "_over") - if scrolling != SLIDER: - self.timer_interval = None - self._scrolling = NO_SCROLL - self._zone = zone - if zone == NO_SCROLL: - self.window.mouse_owner = None - self.scroll_done = True - - def _mouse_move_changed(self, event): - event.handled = True - self.pointer = "arrow" - zone = self._get_zone(event) - scrolling = self._scrolling - if scrolling == SLIDER: - xy = (event.x, event.y)[self.style[0] == "v"] - low, high, page_size, line_size = self.range - position = self._position + ( - (xy - self._xy) * (high - low - page_size) / self._range - ) - self.position = max(min(position, high - page_size), low) - elif scrolling != NO_SCROLL: - in_zone = zone == scrolling - if in_zone != self._in_zone: - self._in_zone = in_zone - self._set_zone_suffix(scrolling, ["", "_down"][in_zone]) - elif zone != self._zone: - self._set_zone_suffix(self._zone, "") - self._set_zone_suffix(zone, "_over") - self._zone = zone - self.window.mouse_owner = [self, None][zone == NO_SCROLL] - - def _mouse_wheel_changed(self, event): - "Scrolls when the mouse scroll wheel is spun" - event.handled = True - self.position += (event.mouse_wheel * self.page_size) / 20 - - def _timer_changed(self): - "Handle timer events" - if self._scrolling != NO_SCROLL: - self.timer_interval = 0.1 - if self._in_zone: - self._scroll() diff --git a/enable/text_field.py b/enable/text_field.py index 5af856878..e328c2a68 100644 --- a/enable/text_field.py +++ b/enable/text_field.py @@ -567,9 +567,5 @@ def __style_changed(self): self.border_color = self._style.border_color self.metrics.set_font(self._style.font) - # FIXME!! The height being passed in gets over-written here - # if not self.multiline: - # self.height = (self.metrics.get_text_extent("T")[3] + - # self._style.text_offset*2) self.request_redraw() diff --git a/kiva/pdfmetrics.py b/kiva/pdfmetrics.py index 64037632b..a631478b0 100644 --- a/kiva/pdfmetrics.py +++ b/kiva/pdfmetrics.py @@ -399,7 +399,6 @@ def _loadGlyphs(self, pfbFileName): def _loadMetrics(self, afmFileName): """Loads in and parses font metrics.""" - #assert os.path.isfile(afmFileName), "AFM file %s not found" % afmFileName (topLevel, glyphData) = parseAFMFile(afmFileName) self.name = topLevel['FontName'] @@ -460,7 +459,6 @@ def registerEncoding(enc): def registerFont(font): "Registers a font, including setting up info for accelerated stringWidth" # FIXME: This doesn't work - #assert isinstance(font, Font), 'Not a Font: %s' % font fontName = font.fontName _fonts[fontName] = font if not font._multiByte: