| 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 |
# Imports: |
| 13 |
# ------------------------------------------------------------------------- |
| 14 |
|
| 15 |
from traits.api import HasPrivateTraits, Code |
| 16 |
|
| 17 |
from traitsui.api import View, Group, Item, HTMLEditor |
| 18 |
|
| 19 |
# ------------------------------------------------------------------------- |
| 20 |
# Constants: |
| 21 |
# ------------------------------------------------------------------------- |
| 22 |
|
| 23 |
sample = """This is a code block: |
| 24 |
|
| 25 |
def foo ( bar ): |
| 26 |
print 'bar:', bar |
| 27 |
|
| 28 |
This is an unordered list: |
| 29 |
- An |
| 30 |
- unordered |
| 31 |
- list |
| 32 |
|
| 33 |
This is an ordered list: |
| 34 |
* One |
| 35 |
* Two |
| 36 |
* Three |
| 37 |
|
| 38 |
Lists can be nested: |
| 39 |
* One |
| 40 |
* 1.1 |
| 41 |
* 1.2 |
| 42 |
* Two |
| 43 |
* 2.1 |
| 44 |
* 2.2 |
| 45 |
""" |
| 46 |
|
| 47 |
# ------------------------------------------------------------------------- |
| 48 |
# 'TestHTML' class: |
| 49 |
# ------------------------------------------------------------------------- |
| 50 |
|
| 51 |
|
| 52 |
class TestHTML(HasPrivateTraits): |
| 53 |
|
| 54 |
# ------------------------------------------------------------------------- |
| 55 |
# Trait definitions: |
| 56 |
# ------------------------------------------------------------------------- |
| 57 |
|
| 58 |
# Text string to display as HTML: |
| 59 |
html = Code(sample) |
| 60 |
|
| 61 |
# ------------------------------------------------------------------------- |
| 62 |
# Traits view definitions: |
| 63 |
# ------------------------------------------------------------------------- |
| 64 |
|
| 65 |
view = View( |
| 66 |
Group( |
| 67 |
[Item('html#@', editor=HTMLEditor(format_text=True)), '|<>'], |
| 68 |
['{Enter formatted text and/or HTML below:}@', 'html#@', '|<>'], |
| 69 |
'|<>', |
| 70 |
layout='split', |
| 71 |
), |
| 72 |
title='HTML Editor Test', |
| 73 |
resizable=True, |
| 74 |
width=0.4, |
| 75 |
height=0.6, |
| 76 |
) |
| 77 |
|
| 78 |
|
| 79 |
# ------------------------------------------------------------------------- |
| 80 |
# Run the test: |
| 81 |
# ------------------------------------------------------------------------- |
| 82 |
|
| 83 |
if __name__ == '__main__': |
| 84 |
TestHTML().configure_traits() |