-
Notifications
You must be signed in to change notification settings - Fork 45
Add a new font-editor that uses Enable to draw fonts #928
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
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # (C) Copyright 2005-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! | ||
| from traits.api import HasStrictTraits | ||
| from traitsui.api import View, Item | ||
|
|
||
| from enable.api import Container, TextField, font_trait | ||
| from enable.trait_defs.ui.api import KivaFontEditor | ||
| from enable.examples._example_support import demo_main | ||
|
|
||
| from kiva.api import Font | ||
| from kiva.constants import ITALIC, SWISS, WEIGHT_BOLD | ||
|
|
||
|
|
||
| size = (500, 200) | ||
|
|
||
| sample_text = "Sphinx of black quartz, judge my vow." | ||
|
|
||
|
|
||
| class Demo(HasStrictTraits): | ||
| """ An example which shows the KivaFontEditor's variations. """ | ||
|
|
||
| font = font_trait(Font("Times", 24, SWISS, WEIGHT_BOLD, ITALIC)) | ||
|
|
||
| view = View( | ||
| Item('font', editor=KivaFontEditor(), style='simple', label="Simple"), | ||
| Item('font', editor=KivaFontEditor(), style='custom', label="Custom"), | ||
| Item('font', editor=KivaFontEditor(), style='text', label="Text"), | ||
| Item('font', editor=KivaFontEditor(), style='readonly', label="Readonly"), | ||
| Item('font', editor=KivaFontEditor(sample_text=sample_text), style='readonly', label="sample text"), | ||
| resizable=True, | ||
| width=size[0], | ||
| height=size[1], | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| # Save demo so that it doesn't get garbage collected when run within | ||
| # existing event loop (i.e. from ipython). | ||
| demo = demo_main(Demo, size=size) |
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,180 @@ | ||
| # (C) Copyright 2005-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! | ||
| """ Test the interaction between traitsui and enable's ComponentEditor. | ||
| """ | ||
| import unittest | ||
|
|
||
| from traits.api import HasTraits | ||
| from traits.testing.api import UnittestTools | ||
| from traitsui.api import Item, View | ||
|
|
||
| from kiva.api import Font | ||
| from enable.enable_traits import font_trait | ||
| from enable.trait_defs.ui.kiva_font_editor import KivaFontEditor | ||
| from enable.tests._testing import skip_if_null | ||
|
|
||
|
|
||
| ITEM_WIDTH, ITEM_HEIGHT = 700, 200 | ||
|
|
||
|
|
||
| class KivaFontView(HasTraits): | ||
| """ View containing an item with ComponentEditor. """ | ||
|
|
||
| font = font_trait() | ||
|
|
||
| traits_view = View( | ||
| Item("font", editor=KivaFontEditor()), | ||
| resizable=True, | ||
| ) | ||
|
|
||
|
|
||
| class TestKivaFontEditor(UnittestTools, unittest.TestCase): | ||
|
|
||
| @skip_if_null | ||
| def test_readonly_default_view(self): | ||
| obj = KivaFontView() | ||
|
|
||
| ui = obj.edit_traits( | ||
| view=View( | ||
| Item("font", editor=KivaFontEditor(), style='readonly'), | ||
| resizable=True, | ||
| ) | ||
| ) | ||
| try: | ||
| # check initial state | ||
| editor = ui.info.font | ||
| component = editor.component | ||
| self.assertIs(editor.value, obj.font) | ||
| self.assertIs(editor.font, obj.font) | ||
| self.assertIs(component.font, obj.font) | ||
| self.assertEqual(editor.str_value, "10 point") | ||
| self.assertEqual(component.text, "10 point") | ||
|
|
||
| # check a change | ||
| new_font = Font( | ||
| face_name="Helvetica", | ||
| size=24, | ||
| weight=700, | ||
| style=2, | ||
| ) | ||
|
|
||
| obj.font = new_font | ||
|
|
||
| self.assertIs(editor.value, new_font) | ||
| self.assertIs(component.font, new_font) | ||
| self.assertEqual(editor.str_value, "24 point Helvetica Bold Italic") | ||
| self.assertEqual(component.text, "24 point Helvetica Bold Italic") | ||
| finally: | ||
| ui.dispose() | ||
|
|
||
| @skip_if_null | ||
| def test_simple_default_view(self): | ||
| obj = KivaFontView() | ||
|
|
||
| ui = obj.edit_traits( | ||
| view=View( | ||
| Item("font", editor=KivaFontEditor()), | ||
| resizable=True, | ||
| ) | ||
| ) | ||
| try: | ||
| editor = ui.info.font | ||
| component = editor.component | ||
| self.assertIs(editor.value, obj.font) | ||
| self.assertIs(editor.font, obj.font) | ||
| self.assertIs(component.font, obj.font) | ||
| self.assertEqual(editor.str_value, "10 point") | ||
| self.assertEqual(component.text, "10 point") | ||
| finally: | ||
| ui.dispose() | ||
|
|
||
| @skip_if_null | ||
| def test_simple_default_object_change(self): | ||
| obj = KivaFontView() | ||
|
|
||
| ui = obj.edit_traits( | ||
| view=View( | ||
| Item("font", editor=KivaFontEditor()), | ||
| resizable=True, | ||
| ) | ||
| ) | ||
| try: | ||
| editor = ui.info.font | ||
| component = editor.component | ||
|
|
||
| new_font = Font( | ||
| face_name="Helvetica", | ||
| size=24, | ||
| weight=700, | ||
| style=2, | ||
| ) | ||
| obj.font = new_font | ||
|
|
||
| self.assertIs(editor.value, new_font) | ||
| self.assertIs(editor.font, new_font) | ||
| self.assertIs(component.font, new_font) | ||
| self.assertEqual(editor.str_value, "24 point Helvetica Bold Italic") | ||
| self.assertEqual(component.text, "24 point Helvetica Bold Italic") | ||
| finally: | ||
| ui.dispose() | ||
|
|
||
| @skip_if_null | ||
| def test_simple_default_editor_change(self): | ||
| obj = KivaFontView() | ||
|
|
||
| ui = obj.edit_traits( | ||
| view=View( | ||
| Item("font", editor=KivaFontEditor()), | ||
| resizable=True, | ||
| ) | ||
| ) | ||
| try: | ||
| editor = ui.info.font | ||
| component = editor.component | ||
|
|
||
| new_font = Font( | ||
| face_name="Helvetica", | ||
| size=24, | ||
| weight=700, | ||
| style=2, | ||
| ) | ||
| editor.update_object(new_font) | ||
|
|
||
| self.assertIs(obj.font, new_font) | ||
| self.assertIs(editor.value, new_font) | ||
| self.assertIs(editor.font, new_font) | ||
| self.assertIs(component.font, new_font) | ||
| self.assertEqual(editor.str_value, "24 point Helvetica Bold Italic") | ||
| self.assertEqual(component.text, "24 point Helvetica Bold Italic") | ||
| finally: | ||
| ui.dispose() | ||
|
|
||
| @skip_if_null | ||
| def test_sample_text(self): | ||
| # this is a smoke test | ||
| obj = KivaFontView() | ||
|
|
||
| ui = obj.edit_traits( | ||
| view=View( | ||
| Item( | ||
| "font", | ||
| editor=KivaFontEditor(sample_text="sample text"), | ||
| style='readonly', | ||
| ), | ||
| resizable=True, | ||
| ) | ||
| ) | ||
| try: | ||
| editor = ui.info.font | ||
| component = editor.component | ||
| self.assertEqual(editor.str_value, "sample text") | ||
| self.assertEqual(component.text, "sample text") | ||
| finally: | ||
| ui.dispose() |
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
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.