You Are Here:

Community: Wiki

This page was last modified on 18 September 2009, at 18:07.

How to use Text in Python for S60

From Forum Nokia Wiki

(Redirected from How to use Text)


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
Reviewer Approved   


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.

Image: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.

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia