-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New, more modern KivaFont trait (#929)
* Add a new font-editor that uses Enable to draw fonts This font editor is laregly toolkit independent - it embeds a Window with a Label component to display the font and the simple editor uses the Pyface font dialog to get new font values. Some functionality is broken out into experimental base classes for building editors with components. * New more modern KivaFont trait This creates a KivaFont TraitType, which is: - in enable, rather than Kiva, meaning Kiva can potentially not need traits - has a better font parser that supports more weight types - the font parser can be swapped out for something better easily - uses the new KivaFontEditor, which is available for Qt - converts Pyface Fonts to Kiva Fonts * Fix long line. * Save all files before finishing merge! * Fix tests. * Apply suggestions from code review Co-authored-by: Mark Dickinson <mdickinson@enthought.com> * Handle color editor tests for null backend. * Fixes from PR review. * Some more small fixes coming from PR discussion. Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
- Loading branch information
1 parent
c23a50a
commit 74536e0
Showing
28 changed files
with
670 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# (C) Copyright 2008-2022 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! | ||
|
||
import unittest | ||
|
||
from kiva import constants | ||
from kiva.fonttools.font import Font, FAMILIES, WEIGHTS, STYLES | ||
from pyface.font import Font as PyfaceFont | ||
from traits.api import HasTraits, TraitError | ||
|
||
from enable.trait_defs.kiva_font_trait import KivaFont | ||
|
||
|
||
class FontExample(HasTraits): | ||
|
||
font = KivaFont() | ||
|
||
|
||
class TestKivaFont(unittest.TestCase): | ||
|
||
def test_validate_str(self): | ||
expected_outcomes = {} | ||
expected_outcomes[""] = Font(size=10, family=constants.DEFAULT) | ||
|
||
for weight, kiva_weight in WEIGHTS.items(): | ||
expected_outcomes[weight] = Font( | ||
weight=kiva_weight, size=10, family=constants.DEFAULT) | ||
|
||
for style, kiva_style in STYLES.items(): | ||
expected_outcomes[style] = Font( | ||
style=kiva_style, size=10, family=constants.DEFAULT) | ||
|
||
expected_outcomes["underline"] = Font( | ||
underline=True, size=10, family=constants.DEFAULT) | ||
|
||
expected_outcomes["18"] = Font(size=18, family=constants.DEFAULT) | ||
expected_outcomes["18 pt"] = Font(size=18, family=constants.DEFAULT) | ||
expected_outcomes["18 point"] = Font(size=18, family=constants.DEFAULT) | ||
|
||
for family, kiva_family in FAMILIES.items(): | ||
expected_outcomes[family] = Font(family=kiva_family, size=10) | ||
|
||
expected_outcomes["Courier"] = Font( | ||
"Courier", size=10, family=constants.DEFAULT) | ||
expected_outcomes["Comic Sans"] = Font( | ||
"Comic Sans", size=10, family=constants.DEFAULT) | ||
expected_outcomes["18 pt Bold Italic Underline Comic Sans script"] = Font( # noqa: E501 | ||
"Comic Sans", 18, constants.SCRIPT, weight=constants.WEIGHT_BOLD, | ||
style=constants.ITALIC, underline=True, | ||
) | ||
|
||
for name, expected in expected_outcomes.items(): | ||
with self.subTest(name=name): | ||
example = FontExample(font=name) | ||
result = example.font | ||
|
||
# test we get expected font | ||
self.assertIsInstance(result, Font) | ||
self.assertEqual(result, expected) | ||
|
||
def test_validate_font(self): | ||
font = Font("Comic Sans", 18) | ||
example = FontExample(font=font) | ||
|
||
result = example.font | ||
|
||
# test we get expected font | ||
self.assertIsInstance(result, Font) | ||
self.assertIs(result, font) | ||
|
||
def test_validate_pyface_font(self): | ||
font = Font("Comic Sans", 18, constants.DEFAULT) | ||
pyface_font = PyfaceFont(family=["Comic Sans"], size=18) | ||
example = FontExample(font=pyface_font) | ||
|
||
result = example.font | ||
|
||
# test we get expected font | ||
self.assertIsInstance(result, Font) | ||
self.assertEqual(result, font) | ||
|
||
def test_font_trait_default(self): | ||
example = FontExample() | ||
|
||
self.assertIsInstance(example.font, Font) | ||
self.assertEqual(example.font, Font(size=12, family=constants.SWISS)) | ||
|
||
def test_font_trait_none(self): | ||
with self.assertRaises(TraitError): | ||
FontExample(font=None) |
Oops, something went wrong.