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:A contact list for choosing number(s) in PySymbian

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.


This PySymbian script shows a contact list class for choosing phone number(s), like the native one when sending SMS.

Article Metadata
Article
Created: okey3m (29 Jul 2008)
Last edited: hamishwillee (31 May 2013)
import appuifw, contacts
 
class ContactList:
 
'show a contact list for choosing phone number'
 
def __init__(self, sortable = None):
'initialize variables'
self.__db = contacts.open()
self.__contact = []
self.__number = {}
self.__load_contact(sortable)
 
def __load_contact(self, sortable = None):
'load contact list from database'
for id in self.__db:
name = self.__db[id].title
mobile = self.__db[id].find('mobile_number')
phone = self.__db[id].find('phone_number')
number_tmp = []
if mobile:
number_tmp.extend([field.value for field in mobile])
if phone:
number_tmp.extend([field.value for field in phone])
self.__number[name] = number_tmp
self.__contact.append(name)
if sortable:
self.__contact.sort(sortable)
 
def select_single(self):
'return a string contains a single number'
index = appuifw.selection_list(self.__contact, 1)
if index == None:
return None
number_list = self.__number[self.__contact[index]]
if not number_list:
return None
if len(number_list) > 1:
index = appuifw.popup_menu(number_list)
if index == None:
return None
else:
index = 0
return number_list[index]
 
def select_multi(self):
'return numbers in a list'
index = appuifw.multi_selection_list(self.__contact, 'checkbox', 1)
if not index:
return None
multi_number = []
for i in index:
number_list = self.__number[self.__contact[i]]
if not number_list:
continue
if len(number_list) > 1:
ind = appuifw.popup_menu(number_list)
if ind == None:
continue
else:
ind = 0
multi_number.append(number_list[ind])
if multi_number:
return multi_number
else:
return None
 
# here is some test
test = ContactList(lambda x, y:cmp(y, x))
print test.select_single()
print test.select_multi()
This page was last modified on 31 May 2013, at 01:06.
35 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.

×