| ID | ... | Creation date | August 29, 2008 |
| Platform | S60 1st Edition, S60 2nd Edition, S60 3rd Edition | Tested on devices | Nokia N95, Nokia E90 |
| Category | Python | Subcategory | UI |
| Keywords (APIs, classes, methods, functions): appuifw |
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
def quit():
app_lock.signal()
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
app_lock.wait()
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 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.
Binds the callable Python object callback to event event_code.
Clears all the text in the editor.
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.
Returns length (by default, the length of the entire text) characters from the text starting from the position pos.