3.1.6 Text Type

Text is a text editor UI control. For examples on the options available with Text, see Figure 3.5.

Figure 3.5: Examples of the options available for Text type
\includegraphics[width=\screenwidth]{text-styles-1} \includegraphics[width=\screenwidth]{text-styles-2}

Instances of Text type have the following attributes:

color
The color of the text. color supports the same color representation models as the graphics module. For the supported color representation models, see Section 3.3.

focus
A Boolean attribute that indicates the focus state of the control. Editor control also takes the ownership of the navigation bar, and this feature is needed to enable the usage of this control in applications that use the navigation bar - for example, navigation tabs.

font
The font of the text. There are two possible ways to set this attribute:

The attribute value retrieved is always a Unicode string. If the font has been set with a label, for example, 'title', the attribute will retrieve the font associated with that label.

highlight_color
The highlight color of the text. highlight_color supports the same color representation models as the graphics module. For the supported color representation models, see Section 3.3.

style
The style of the text. The flags for this attribute are defined in the appuifw module. These flags can be combined by using the binary operator |. The flags can be divided into two types: text style and text highlight. Text style flags can be freely combined with each other. However, one or more text style flags can be combined with only one text highlight flag. The flags are:

Text style:

STYLE_BOLD
Enables bold text.

STYLE_UNDERLINE
Enables underlined text.

STYLE_ITALIC
Enables italic text.

STYLE_STRIKETHROUGH
Enables strikethrough.

Text highlight:

HIGHLIGHT_STANDARD
Enables standard highlight.

HIGHLIGHT_ROUNDED
Enables rounded highlight.

HIGHLIGHT_SHADOW
Enables shadow highlight.

Only one highlight is allowed to be used at once. Therefore, it is possible to combine only one highlight with one or more text styles.

Examples:

t = appuifw.Text()

# These and other similar values and combinations are valid:
t.style = appuifw.STYLE_BOLD
t.style = appuifw.STYLE_UNDERLINE
t.style = appuifw.STYLE_ITALIC
t.style = appuifw.STYLE_STRIKETHROUGH
t.style = (appuifw.STYLE_BOLD|
	   appuifw.STYLE_ITALIC|
	   appuifw.STYLE_UNDERLINE)

# These values are valid:
t.style = appuifw.HIGHLIGHT_STANDARD
t.style = appuifw.HIGHLIGHT_ROUNDED
t.style = appuifw.HIGHLIGHT_SHADOW

# This combination is NOT valid:
# Invalid code, do not try!
t.style = (appuifw.HIGHLIGHT_SHADOW|appuifw.HIGHLIGHT_ROUNDED)

Instances of Text type have the following methods:

add( text)
Inserts the Unicode string text to the current cursor position.

bind( event_code, callback)
Binds the callable Python object callback to event event_code. The key codes are defined in the key_codes library module. The call bind(event_code, None) clears an existing binding. In the current implementation the event is always passed also to the underlying native UI control.

clear( )
Clears the editor.

delete( [pos=0, length=len()])
Deletes length characters of the text held by the editor control, starting from the position pos.

get_pos( )
Returns the current cursor position.

len( )
Returns the length of the text string held by the editor control.

get( [pos=0, length=len()])
Retrieves length characters of the text held by the editor control, starting from the position pos.

set( text)
Sets the text content of the editor control to Unicode string text.

set_pos( cursor_pos)
Sets the cursor to cursor_pos.

See About this document... for information on suggesting changes.