-
Notifications
You must be signed in to change notification settings - Fork 45
New, more modern KivaFont trait #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3dcfb9e
Add a new font-editor that uses Enable to draw fonts
corranwebster d588a71
New more modern KivaFont trait
corranwebster bd05d4b
Merge branch 'main' into enh/new-font-trait
corranwebster 3fc6f67
Fix long line.
corranwebster 32a3b36
Save all files before finishing merge!
corranwebster 555419e
Fix tests.
corranwebster cb2b1da
Apply suggestions from code review
corranwebster 82ea9fd
Handle color editor tests for null backend.
corranwebster 01a4109
Fixes from PR review.
corranwebster ea32353
Some more small fixes coming from PR discussion.
corranwebster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.