~ubuntu-branches/ubuntu/utopic/python-traitsui/utopic

« back to all changes in this revision

Viewing changes to examples/demo/Standard_Editors/HTMLEditor_demo.py

  • Committer: Package Import Robot
  • Author(s): Varun Hiremath
  • Date: 2012-04-23 16:05:43 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20120423160543-bgafgw04y68arfjn
Tags: 4.1.0-1
* New upstream release
* Bump Standards-Version to 3.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#  Copyright (c) 2007, Enthought, Inc.
2
 
#  License: BSD Style.
3
 
 
4
 
"""
5
 
Implementation of a HTMLEditor demo plugin for the Traits UI demo program.
6
 
"""
7
 
 
8
 
# Imports:
 
1
"""
 
2
HTML editor
 
3
 
 
4
The HTML editor displays simple formatted HTML text in a Traits UI view.
 
5
 
 
6
If the text is held in an HTML trait, then the HTMLEditor is the default. If
 
7
the text is held in a Str trait, then you may specify the HTMLEditor explicitly
 
8
if you wish to display it as HTML.
 
9
 
 
10
The supported subset of HTML tags and features depends on the UI toolkit (WX or
 
11
QT). This editor does not support style sheets. It does not support WYSIWYG
 
12
editing of the text, though the unformatted text can be edited in a plain text
 
13
editor.
 
14
 
 
15
The HTML editor can optionally be configured to do simple formatting of lists
 
16
and paragraphs without HTML tags, by setting the editor's 'format_text'
 
17
parameter True.
 
18
 
 
19
"""
 
20
 
9
21
from traits.api import HasTraits, HTML
10
 
 
11
 
from traitsui.api import Item, Group, View
12
 
 
13
 
# Define the demo class:
 
22
from traitsui.api import UItem, View, HTMLEditor
 
23
 
 
24
# Sample text to display as HTML: header, plus module docstring, plus
 
25
# some lists. The docstring and lists will be auto-formatted (format_text=True).
 
26
sample_text = ("""
 
27
<html><body><h1>HTMLEditor example</h1>
 
28
 
 
29
""" +
 
30
__doc__ +
 
31
"""
 
32
<i>Here are some lists formatted in this way:</i>
 
33
 
 
34
Numbered list:
 
35
  * first
 
36
  * second
 
37
  * third
 
38
 
 
39
Bulleted list:
 
40
  - eat
 
41
  - drink
 
42
  - be merry
 
43
""")
 
44
 
 
45
 
14
46
class HTMLEditorDemo ( HasTraits ):
15
47
    """ Defines the main HTMLEditor demo class. """
16
48
 
17
49
    # Define a HTML trait to view
18
 
    html_trait = HTML("""<html><body><p>A HTMLEditor displaying</p>
19
 
<p>two paragraphs of text.</p></body></html>""")
 
50
    my_html_trait = HTML(sample_text)
20
51
 
21
52
    # Demo view
22
 
    view = View(Group(Item('html_trait',
23
 
                           style = 'simple',
24
 
                           label = 'Simple'),
25
 
                      show_labels = False),
 
53
    traits_view = View(
 
54
        UItem('my_html_trait',
 
55
              # we specify the editor explicitly in order to set format_text:
 
56
              editor=HTMLEditor(format_text=True)),
26
57
                title     = 'HTMLEditor',
27
58
                buttons   = ['OK'],
28
59
                width     = 800,