You Are Here:

Community: Developer Discussion Boards

#1 Old Post Search in contacts (sample code) - 2008-10-26, 20:35

Join Date: Oct 2008
Posts: 2
pythonkid
Offline
Registered User
One cool feature of windows based phones is that you can search contacts by typing their numbers, my idea is to simulate that in symbian, with this program user will be able to search in numbers, names, email addressed, URLs and even notes.
this program will seprate numbers to three parts, so you don't have to type area code in your search.
this will categorize data using their contents, not field names, so if you type an E-mail address in notes field, it will categorized as E-mail.

Code:
import e32
import string
import appuifw
import contacts
import telephone
from key_codes import EScancode0, EScancode1, EScancode2, EScancode3, EScancode4, EScancode5

digits='0123456789+'

currentList=[]
mailList=[]
nameList=[]
numList=[]
otherList=[]
wwwList=[]
myDic={}

db=contacts.open()

def FillLists():
	global currentList, mailList, nameList, numList, otherList, wwwList, myDic
	for recordKey in db:
		nameList.append(db[recordKey].title)
		myDic[db[recordKey].title]=recordKey
		for field in db[recordKey]:
			data=field.value
			if string.find(digits, data[0])>-1:
				str=data[0:len(data)-7]+" "+data[len(data)-7:len(data)-4]+" "+data[len(data)-4:len(data)]
				numList.append(str)
			elif string.find(data,'@')>-1:
				str=data[0:string.find(data,'@')+1]+" "+data[string.find(data,'@')+1:len(data)]
				mailList.append(str)
			elif string.find(data,'www.')>-1:
				str=data[0:string.find(data,'.')+1]+" "+data[string.find(data,'.')+1:string.rfind(data,'.')+1]+" "+data[string.rfind(data,'.')+1:len(data)]
				wwwList.append(str)
			elif string.find(data,'http:')>-1:
				str=data[0:string.find(data,'/')+2]+" "+data[string.find(data,'/')+2:string.rfind(data,'.')+1]+" "+data[string.rfind(data,'.')+1:len(data)]
				wwwList.append(str)
			else:
				str=data
				otherList.append(str)
			myDic[str]=recordKey

def Call():
	oldTitle=appuifw.app.title
	appuifw.app.title=u'Dial'
	tmpList=[]
	for i in db[myDic[currentList[mainList.current()]]]:
		if string.find(digits, i.value[0])>-1:
			tmpList.append(i.value)
	if len(tmpList)==0:
		appuifw.note(u'No numbers found' ,'error')
	elif len(tmpList)==1:
		telephone.dial(tmpList[0])
	else:
		index=appuifw.selection_list(tmpList)
		telephone.dial(tmpList[index])
	appuifw.app.title=oldTitle

def Search(inList):
	oldTitle=appuifw.app.title
	appuifw.app.title=u'Search'
	index=appuifw.multi_selection_list(inList,'checkbox',1)
	tmpList=[]
	for i in index:
		dbID=myDic[inList[i]]
		tmpList.append(db[dbID].title)
	global currentList
	if len(tmpList)>0:
        	currentList=tmpList
        	mainList.set_list(currentList)
	appuifw.app.title=oldTitle

APP_LOCK=e32.Ao_lock()
mainList=appuifw.Listbox([u'Collecting data...', u'Please wait'])
mainList.bind(EScancode1, lambda:Search(nameList))
mainList.bind(EScancode2, lambda:Search(numList))
mainList.bind(EScancode3, lambda:Search(mailList))
mainList.bind(EScancode4, lambda:Search(wwwList))
mainList.bind(EScancode5, lambda:Search(otherList))
mainList.bind(EScancode0, lambda:mainList.set_list(nameList))
appuifw.app.body=mainList
appuifw.app.exit_key_handler=APP_LOCK.signal
appuifw.app.title=u'Contact search'
appuifw.app.menu=[(u"Call",                  lambda:Call()),
		  (u"[1] Search in names",   lambda:Search(nameList)),
		  (u"[2] Search in numbers", lambda:Search(numList)),
		  (u"[3] Search in mails",   lambda:Search(mailList)),
		  (u"[4] Search in URLs",    lambda:Search(wwwList)),
		  (u"[5] Search in others",  lambda:Search(otherList)),
		  (u"[0] View all",          lambda:mainList.set_list(nameList))]
FillLists()
currentList=nameList
mainList.set_list(currentList)
APP_LOCK.wait()
Last edited by pythonkid : 2008-10-27 at 11:56. Reason: typing mistake
Reply With Quote

#2 Old Re: Search in contacts (sample code) - 2008-10-26, 20:41

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Hi pythonkid,

Now we have another great idea here. I've seen applications like that in Symbian C++ already, but never in PyS60

I'll probably use this many times, since the application I used for this is too buggy.

Thanks for contributing with the Python DiBo!

Keep it up!


BR,

Rafael.
Last edited by Rafael T. : 2008-10-26 at 20:53.
Reply With Quote

#3 Old Re: Search in contacts (sample code) - 2008-10-26, 20:45

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Nice work. Maybe you should add it to the Wiki as example code.
Reply With Quote

#4 Old Re: Search in contacts (sample code) - 2008-10-26, 20:59

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Having it as a code example at Forum Nokia would certainly be great

Please go to the Wiki and just get your code into there

Don't forget to tag Code Examples and Python categories


BR,

Rafael.
Reply With Quote

#5 Old Re: Search in contacts (sample code) - 2008-10-26, 23:12

Join Date: Sep 2007
Posts: 395
Location: Bhavnagar
Send a message via Yahoo to james1980
james1980's Avatar
james1980
Offline
Forum Nokia Champion
Hi python kid,
its really a nice idea and great work done.
Do add your code at wiki also.
Best regards.


Jajal Mehul
Reply With Quote

#6 Old Re: Search in contacts (sample code) - 2008-10-27, 08:50

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Online
Forum Nokia Champion
hi pythonkid

this is a very excellent code.
Good work keep it up.

Enjoy Pythoning
Gaba88


Gargi Das- http://gargidas.blogsot.com

Forum Nokia Python Wiki


Learn Python at http://mobapps.org/PyS60
Reply With Quote

#7 Old Talking Re: Search in contacts (sample code) - 2008-10-27, 12:00

Join Date: Oct 2008
Posts: 2
pythonkid
Offline
Registered User
Hi guys
glad u like it

I've just added it to WIKI here. maybe it needs experts edit

thank you very much
Reply With Quote

#8 Old Re: Search in contacts (sample code) - 2008-10-27, 12:20

Join Date: May 2007
Posts: 2,737
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by pythonkid View Post
Hi guys
glad u like it

I've just added it to WIKI here. maybe it needs experts edit

thank you very much
Looks good! I made few necessary changes to it already

I guess you can still add some more comments to the Search and Call functions, in the code snippet, so that others can understand it better

Best Regards,
Croozeus
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
[Announce] Sensor API Sample Code JOM Python 2 2008-05-01 11:44
New sample code "Sensor" has been developed! liuxg Symbian 2 2008-03-06 02:50
Getting started using Carbide c++ 1.1 -> how to import the sample code terchris Carbide.c++ IDE and plug-ins 3 2007-11-20 10:12
Where can i find sample code? eqing2008 General Symbian C++ 2 2006-11-30 08:15
Symbian Source Code Repository and Search Engine SimonJudge General Symbian C++ 0 2005-07-08 19:38

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 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ