×
Namespaces

Variants
Actions
Revision as of 23:57, 30 December 2008 by bogdan.galiceanu (Talk | contribs)

Archived:How to use Text in PySymbian

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N95, Nokia E90
Compatibility
Platform(s): S60 1st Edition, S60 2nd Edition, S60 3rd Edition
Article
Keywords: appuifw
Created: (29 Aug 2008)
Last edited: bogdan.galiceanu (30 Dec 2008)


Contents

Overview

This article explains how to use the Text class of the appuifw module in Python.

Preconditions

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().

Source code

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()

Postconditions

Text with the specified characteristics is shown.

Text.jpg

Additional information

Instances of Text type have the following attributes:

  • color

The color of the text.

  • 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. 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'.


  • highlight_color

The highlight color of the text.

  • style

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:

  • add(text)

Inserts the Unicode string text at the current cursor position.

  • bind(event_code, callback)

Binds the callable Python object callback to event event_code.

  • clear()

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.

  • get_pos()

Returns the current position of the cursor.

  • set_pos(cursor_pos)

Sets the position of the cursor to cursor_pos, where cursor_pos represents the number of characters from the beginning of the text.

  • len()

Return the lenght (number of characters) of the text in the editor.

  • set(text)

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.

54 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×