Skip to content

Commit

Permalink
Deprecate the str_to_font in enable.base (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiggins committed Mar 25, 2021
1 parent 5811cab commit 42cee22
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
1 change: 0 additions & 1 deletion enable/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
===========
- :class:`~.IDroppedOnHandler`
- :func:`~.str_to_font`
- :func:`~.intersect_bounds`
Constants
Expand Down
19 changes: 11 additions & 8 deletions enable/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@


def str_to_font(object, name, value):
"Converts a (somewhat) free-form string into a valid Font object."
# FIXME: Make this less free-form and more well-defined.
""" Converts a (somewhat) free-form string into a valid Font object.
"""
import warnings

warnings.warn(
("str_to_font should not be imported from enable.api. Use the version "
"from kiva.fonttools instead."),
DeprecationWarning,
stacklevel=2,
)
try:
point_size = 10
family = SWISS
Expand Down Expand Up @@ -115,14 +123,9 @@ def str_to_font(object, name, value):
raise TraitError(object, name, "a font descriptor string", repr(value))


str_to_font.info = (
"a string describing a font (e.g. '12 pt bold italic "
+ "swiss family Arial' or 'default 12')"
)

# Pick a default font that should work on all platforms.
default_font_name = "modern 10"
default_font = str_to_font(None, None, default_font_name)
default_font = Font(family=MODERN, size=10)


def bounding_box(components):
Expand Down
5 changes: 3 additions & 2 deletions enable/examples/demo/enable/filled_container_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
from numpy import array
from traits.api import Any, Enum, Float, Instance, Tuple

from enable.api import Container, Component, Pointer, str_to_font
from enable.api import Container, Component, Pointer
from enable.example_support import DemoFrame, demo_main
from kiva.fonttools import str_to_font


class MyFilledContainer(Container):
Expand All @@ -35,7 +36,7 @@ class MyFilledContainer(Container):
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")
self._font = str_to_font("modern 10")

with gc:
gc.set_fill_color(self.bgcolor_)
Expand Down
5 changes: 3 additions & 2 deletions enable/examples/demo/enable/hidpi_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from traits.api import Any, HasTraits, Instance, Str
from traitsui.api import HGroup, UItem, View

from enable.api import Component, ComponentEditor, str_to_font
from enable.api import Component, ComponentEditor
from kiva.fonttools import str_to_font


class MyComponent(Component):
Expand All @@ -27,7 +28,7 @@ class MyComponent(Component):

def draw(self, gc, **kwargs):
if not self._font:
self._font = str_to_font(None, None, "modern 48")
self._font = str_to_font("modern 48")

gc.clear((0.5, 0.5, 0.5))
mx = self.x + self.width / 2.0
Expand Down

0 comments on commit 42cee22

Please sign in to comment.