Debian Codegraph @

traitsui/examples/demo/Standard_Editors/HTMLEditor_demo.py

raw
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 HTML editor
13
14 The HTML editor displays simple formatted HTML text in a Traits UI view.
15
16 If the text is held in an HTML trait, then the HTMLEditor is the default. If
17 the text is held in a Str trait, then you may specify the HTMLEditor explicitly
18 if you wish to display it as HTML.
19
20 The supported subset of HTML tags and features depends on the UI toolkit (WX or
21 QT). This editor does not support style sheets. It does not support WYSIWYG
22 editing of the text, though the unformatted text can be edited in a plain text
23 editor.
24
25 The HTML editor can optionally be configured to do simple formatting of lists
26 and paragraphs without HTML tags, by setting the editor's 'format_text'
27 parameter True.
28
29 Please refer to the `HTMLEditor API docs`_ for further information.
30
31 .. _HTMLEditor API docs: https://docs.enthought.com/traitsui/api/traitsui.editors.html_editor.html#traitsui.editors.html_editor.HTMLEditor
32 """
33
34 from traits.api import HasTraits, HTML
35 from traitsui.api import UItem, View, HTMLEditor
36
37 # Sample text to display as HTML: header, plus module docstring, plus
38 # some lists. The docstring and lists will be auto-formatted
39 # (format_text=True).
40 sample_text = (
41 """
42 <html><body><h1>HTMLEditor example</h1>
43
44 """
45 + __doc__
46 + """
47 <i>Here are some lists formatted in this way:</i>
48
49 Numbered list:
50 * first
51 * second
52 * third
53
54 Bulleted list:
55 - eat
56 - drink
57 - be merry
58 """
59 )
60
61
62 class HTMLEditorDemo(HasTraits):
63 """Defines the main HTMLEditor demo class."""
64
65 # Define a HTML trait to view
66 my_html_trait = HTML(sample_text)
67
68 # Demo view
69 traits_view = View(
70 UItem(
71 'my_html_trait',
72 # we specify the editor explicitly in order to set format_text:
73 editor=HTMLEditor(format_text=True),
74 ),
75 title='HTMLEditor',
76 buttons=['OK'],
77 width=800,
78 height=600,
79 resizable=True,
80 )
81
82
83 # Create the demo:
84 demo = HTMLEditorDemo()
85
86 # Run the demo (if invoked from the command line):
87 if __name__ == '__main__':
88 demo.configure_traits()