×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    2

    Post Random RingTone within Contact List for 3rd

    This is my first time to use python and write a program for Symbian OS 3rd.

    Random RingTone is a funny program for me and it's work fine in my N3250.


    ** Pure Python Program **

    Here is the concept and full source code:

    In pys60 1.4.1, we can only add a personal ringtone to each contact person.


    Code:
    contact.add_field('personal_ringtone', song)
    So... the Basic concept:
    HTML Code:
    When Incoming Call
        Store the phone number for later use
    When the call finished
        Search within the contact list with the stored phone number
        if not in list
            ignore
        else
            take a random ringtone from E:\Sounds\Simple\ and add to the contact person
    when that guy call you again next time, then the phone uses the new personal ringtone.




    How to make it more Random:

    We know that if no personal ringtone added to the contact person, the phone uese the default ringtone which is the profile ringtone.

    so... we need to add a random ringtone to each contact person at the first time.

    New flow:

    HTML Code:
    first time setup (only run at first time install)
        add a random ringtone to each contact personal
    
    Same as before:
    Incoming Call
        (use the new personal ringtone for that person)
        Store the phone number for later use
    when hangup
        Search within the contact list with the stored phone number
        if not in list
            ignore
        else
            take a random ringtone from E:\Sounds\Simple\ and add to the contact personal
    Now, when any contact person call you, then it uses the new personal ringtone. Funny!!

    Full source code share with you:
    Code:
    import appuifw
    import e32
    import telephone
    import contacts
    import os
    import random
    
    tele = ''
    whoid = 0
    num = 0
    
    def remove_all_ringtone():
        db = contacts.open()
        idlist = db.keys()
        for id in idlist:
            try:
                contact = db[id]
                num = contact.find('personal_ringtone')[0].index
                contact.__delitem__(num)
            except IndexError:
                pass
    
    def add_all_random_ringtone():
        db = contacts.open()
        idlist = db.keys()
        filesname = os.listdir('E:\Sounds\Simple')
        print 'List files'
        for id in idlist:
            try:
                contact = db[id]
                num = contact.find('personal_ringtone')[0].index
            except IndexError:
                num =  random.randrange(0, len(filesname)-1)
                song = u'E:\\Sounds\\Simple\\' + filesname[num].decode('utf-8')
                contact.add_field('personal_ringtone', song)
                pass
            else:
                pass
    
    def handle_ringtone():
        print 'handle_ringtone()'
        try:
            global whoid
            whoid = contacts.open().find(tele)[0].id
            print whoid
        except IndexError:
            print 'No record in the Contact DB!'
            pass
        else:
            print 'Have this number: ' + tele
            contact = contacts.open()
            print 'Open Contacts'
            filesname = os.listdir('E:\Sounds\Simple')
            print 'List files'
            try:
                global num
                num = contact[whoid].find('personal_ringtone')[0].index
                print 'personal ringtone found!'
            except IndexError:
                num =  random.randrange(0, len(filesname)-1)
                song = u'E:\\Sounds\\Simple\\' + filesname[num].decode('utf-8')
                contact[whoid].add_field('personal_ringtone', song)
                print 'No personal ringtone! Add one!'
                pass
            else:
                contact[whoid].__delitem__(num)
                num =  random.randrange(0, len(filesname)-1)
                song = u'E:\\Sounds\\Simple\\' + filesname[num].decode('utf-8')
                contact[whoid].add_field('personal_ringtone', song)
                print 'Remove old ringtone, add one!'
    
    def cb_calling(state):
        print unicode('0:' + str(state[0]) + ';1:' + str(state[1]))
        if (state[0]==telephone.EStatusRinging):
        	global tele
            tele = str(state[1])
            print 'Ring: ' + tele
            print "EStatusRinging.."
        if (state[0]==telephone.EStatusConnecting):
            print "EStatusConnecting.."
        if (state[0]==telephone.EStatusUnknown):
            print "EStatusUnknown.."
        if (state[0]==telephone.EStatusIdle):
            handle_ringtone()
            print "EStatusIdle.."
        if (state[0]==telephone.EStatusDialling):
            print "EStatusDialling.."
        if (state[0]==telephone.EStatusAnswering):
            print "EStatusAnswering.."
        if (state[0]==telephone.EStatusConnected):
            print "EStatusConnected.."
        if (state[0]==telephone.EStatusReconnectPending):
            print "EStatusReconnectPending.."
        if (state[0]==telephone.EStatusDisconnecting):
            print "EStatusDisconnecting.."
        if (state[0]==telephone.EStatusHold):
            print "EStatusHold.."
        if (state[0]==telephone.EStatusTransferring):
            print "EStatusTransferring.."
        if (state[0]==telephone.EStatusTransferAlerting):
            print "EStatusTransferAlerting.."
    
    
    
    def quit():
        app_lock.signal()
    
    appuifw.app.title = u'Incoming call Test'
    appuifw.app.menu = [(u"Init Setup", add_all_random_ringtone), 
                        (u"Remove Setup", remove_all_ringtone), 
                        (u"Exit", quit)]
    
    appuifw.app.exit_key_handler= quit
    app_lock=e32.Ao_lock()
    
    telephone.call_state(cb_calling)
    
    app_lock.wait()

    Usefull Links:

    Bind an incoming call
    http://discussion.forum.nokia.com/fo...d.php?t=120891

    [PDF]Python For S60 1.4.1 document
    http://sourceforge.net/projects/pys60
    Last edited by cckfranky; 2007-12-18 at 07:43.

  2. #2
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: Random RingTone within Contact List for 3rd

    Well done

    Only one post but very valuable post !
    I'll try that soon

    BR
    Cyke64
    pys60 1.4.5 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    7

    Smile Re: Random RingTone within Contact List for 3rd

    Great Idea!

    Let me try at my N73!

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    1

    Re: Random RingTone within Contact List for 3rd

    Hey Franky I've been waiting for an aplication like this for a long time for the 3rd series, but the thing is, I have no idea how to work with python, can u suggest me a place to start? Where should i put all these command lines?
    I would really appreciate that!

    Regards

    Rod

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2

    Re: Random RingTone within Contact List for 3rd

    Quote Originally Posted by rodmarcus View Post
    Hey Franky I've been waiting for an aplication like this for a long time for the 3rd series, but the thing is, I have no idea how to work with python, can u suggest me a place to start? Where should i put all these command lines?
    I would really appreciate that!

    Regards

    Rod
    Step 1: install the PythonScriptShell 1.4.1 3rdEd & PythonForS60 1.4.1 SDK 3rdEd
    Step 2: copy the source code & rename to .py, put it to 'E:\Python'
    Step 3: put all your ringtone to 'E:\Sounds\Simple'
    Step 4: start the Python application and run the source code (script)
    Step 5: press "Option" -> "Init Setup"
    Step 6: Enjoy the program!

    If you want to make it to .sis and auto start when you turn on the phone, Please search in this forum.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    568

    Re: Random RingTone within Contact List for 3rd

    Step 1: install the PythonScriptShell 1.4.1 3rdEd & PythonForS60 1.4.1 SDK 3rdEd
    Hmm. I think you meant Python runtime module, not the SDK?

    Regards

Similar Threads

  1. J2ME and contact list
    By morphine_titan in forum Mobile Java General
    Replies: 7
    Last Post: 2009-01-06, 07:49
  2. Enumarating contact list
    By shagishkumar in forum Mobile Java General
    Replies: 3
    Last Post: 2006-06-27, 05:34
  3. 6680 and bluetooth service profiles
    By ceruault in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-08, 22:24
  4. 6010 and contact list
    By buzlink in forum General Development Questions
    Replies: 0
    Last Post: 2005-01-11, 18:14
  5. Showing and accesing contact list library
    By djorge in forum Symbian User Interface
    Replies: 1
    Last Post: 2002-09-25, 11:01

Posting Permissions

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