| 1 |
# (C) Copyright 2004-2023 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
|
| 11 |
""" |
| 12 |
Font editor |
| 13 |
|
| 14 |
A Font editor in a Traits UI allows the user to select a font from the |
| 15 |
operating system. |
| 16 |
|
| 17 |
Typically, you then pass the Font trait to another UI editor, which uses it to |
| 18 |
display text. You can also read the Font trait as a string, or access its |
| 19 |
individual attributes (note that these attributes are specific to the UI |
| 20 |
toolkit -- QT or WX.) |
| 21 |
|
| 22 |
The default 'simple' Font editor style is usually the most useful and powerful |
| 23 |
style - it pops up a font selection dialog which is specific to the OS and |
| 24 |
toolkit. |
| 25 |
|
| 26 |
This example also displays some other less common style choices. |
| 27 |
|
| 28 |
Please refer to the `FontEditor API docs`_ for further information. |
| 29 |
|
| 30 |
.. _FontEditor API docs: https://docs.enthought.com/traitsui/api/traitsui.editors.font_editor.html#traitsui.editors.font_editor.FontEditor |
| 31 |
""" |
| 32 |
|
| 33 |
from traits.api import HasTraits |
| 34 |
|
| 35 |
from traitsui.api import Item, Group, View, Font |
| 36 |
|
| 37 |
|
| 38 |
class FontEditorDemo(HasTraits): |
| 39 |
"""Defines the main FontEditor demo class.""" |
| 40 |
|
| 41 |
# Define a Font trait to view: |
| 42 |
my_font_trait = Font() |
| 43 |
|
| 44 |
# Display specification (one Item per editor style): |
| 45 |
font_group = Group( |
| 46 |
Item('my_font_trait', style='simple', label='Simple'), |
| 47 |
Item('_'), |
| 48 |
Item('my_font_trait', style='custom', label='Custom'), |
| 49 |
Item('_'), |
| 50 |
Item('my_font_trait', style='text', label='Text'), |
| 51 |
Item('_'), |
| 52 |
Item('my_font_trait', style='readonly', label='ReadOnly'), |
| 53 |
) |
| 54 |
|
| 55 |
# Demo view: |
| 56 |
traits_view = View( |
| 57 |
font_group, title='FontEditor', buttons=['OK'], resizable=True |
| 58 |
) |
| 59 |
|
| 60 |
|
| 61 |
# Create the demo: |
| 62 |
demo = FontEditorDemo() |
| 63 |
|
| 64 |
|
| 65 |
# Run the demo (if invoked from the command line): |
| 66 |
if __name__ == '__main__': |
| 67 |
demo.configure_traits() |