Archived:How to use Text in PySymbian
This article explains how to use the Text class of the appuifw module in Python.
Trying to set a font which is not supported by the device has no effect. A list of supported fonts can be retrieved by using appuifw.available_fonts().
import appuifw, e32
app_lock = e32.Ao_lock()
#Define the exit function
appuifw.app.exit_key_handler = quit
#Create an instance of Text and set it as the application's body
t = appuifw.Text()
appuifw.app.body = t
#Set the color of the text
t.color = 0xFF0000
#Set the font by name, size and flags
t.font = (u"Nokia Hindi S60", 25, None)
#Set the color in which the text will be highlighted
t.highlight_color = 0xFFFF00
#Highlight the text in a normal way and set the style of the text to underlined
t.style = (appuifw.HIGHLIGHT_STANDARD | appuifw.STYLE_UNDERLINE)
#Write text to see the effect
t.add(u"This is an example")
#Wait for the user to request the exit
Text with the specified characteristics is shown.
Instances of Text type have the following attributes:
The color of the text.
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.
The font of the text. This attribute can be set in two ways:
- Using a supported Unicode font, for example u"Nokia Hindi S60".
- Using one of the default device fonts that are associated with the following labels (plain strings): 'annotation', 'title', 'legend', 'symbol', 'dense', 'normal'.
The highlight color of the text.
The style of the text. The flags for this attribute are defined in the appuifw module. These flags can be combined using the binary operator | and can be placed in two categories: 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 text style flags are: STYLE_BOLD, STYLE_UNDERLINE, STYLE_ITALIC and STYLE_STRIKETHROUGH.
The text highlight flags are: HIGHLIGHT_STANDARD, HIGHLIGHT_ROUNDED and HIGHLIGHT_SHADOW.
Instances of Text type have the following methods:
Inserts the Unicode string text at the current cursor position.
- bind(event_code, callback)
Binds the callable Python object callback to event event_code.
Clears all the text in the editor.
- delete([pos=0, length=len()])
Deletes length (by default, the length of the entire text) characters of the text starting from the position pos.
Returns the current position of the cursor.
Sets the position of the cursor to cursor_pos, where cursor_pos represents the number of characters from the beginning of the text.
Return the lenght (number of characters) of the text in the editor.
Sets the text content of the editor to the Unicode string text.
- get([pos=0, length=len()])
Returns length (by default, the length of the entire text) characters from the text starting from the position pos.