Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:How to use Listbox in PySymbian

From Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

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: kevin_s2f (09 Jul 2007)
Last edited: hamishwillee (31 May 2013)

Contents

Overview

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

Preconditions

The icons can be taken from either an MIF file (from S60 2nd Edition FP3 onwards) or an MBM file.

In S60 1st Edition and S60 2nd Edition the path of the MBM file containing data for the icons is z:\\system\\data\\avkon.mbm. In S60 3rd Edition the path of the MIF file containing data for the icons is z:\\resource\\apps\\avkon2.mif and information about the indexes for various icons can be found in the avkon.mbg file located in \Epoc32\include.

Source code

Basic, single-line item listbox

import appuifw, e32
 
 
app_lock = e32.Ao_lock()
#Define the exit function
def quit():
app_lock.signal()
appuifw.app.exit_key_handler = quit
 
#Create a list of items to be displayed (Unicode strings)
items = [u"Item 1", u"Item 2", u"Item 3"]
 
#Create an instance of Listbox and set it as the application's body
lb = appuifw.Listbox(items, lambda:None)
appuifw.app.body = lb
 
#Wait for the user to request the exit
app_lock.wait()

Advanced, double-item listbox with icons

import appuifw, e32
 
 
app_lock = e32.Ao_lock()
#Define the exit function
def quit():
app_lock.signal()
appuifw.app.exit_key_handler = quit
 
#Define the icons to be used
icon1 = appuifw.Icon(u"z:\\resource\\apps\\avkon2.mif", 16412, 16413)
icon2 = appuifw.Icon(u"z:\\resource\\apps\\avkon2.mif", 16424, 16425)
 
#Create a list of items to be displayed
#An item consists of two fields (Unicode strings) and an icon
items = [(u"Signal", u"Strong", icon1), (u"Battery", u"Full", icon2)]
 
#Define a function that is called when an item is selected
def handle_selection():
appuifw.note(items[lb.current()][0] + u" has been selected.", 'info')
 
#Create an instance of Listbox and set it as the application's body
lb = appuifw.Listbox(items, handle_selection)
appuifw.app.body = lb
 
#Wait for the user to request the exit
app_lock.wait()

Postconditions

The listbox is created and displayed.

Basic, single-line item listbox
Advanced, double-item listbox with icons

Additional information

Instances of Listbox have the following attributes:

  • size

Read only. A tuple containing the width and height of the listbox. Available starting with S60 3rd Edition.

  • position

Read only. A tuple containing the coordinates of the top left corner of the listbox. Available starting with S60 3rd Edition.


Instances of Listbox have the following methods:

  • bind(event_code, callback)

Binds the callable Python object callback to event event_code.

  • current()

Returns the index of the currently selected item.

  • set_list(list[, current])

Sets the contents of the listbox to list, which is a list of Unicode strings or a list of tuples. current is the index of the focused item.

This page was last modified on 31 May 2013, at 01:09.
50 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.

×