polychromatic thoughts……………..

September 7, 2008

MOBIVISION WORKSHOP DAY 3 AND 4…..OVERVIEW

Filed under: mobile — maniacmind @ 6:02 PM

AS PROMISED ITS SUNDAY AND I M WRITEING THE DOCUMENTATION OF THE THIRD DAY OF WORKSHOP………………

we covered messaging here is a sample code with comments explaining the process…

# import the messaging module
import appuifw
import messaging

# create text input field
data = appuifw.query(u"Type your name:", "text")

# define the mobile numbers here
nbr1 = "123456"
nbr2 = "234567"

# define the text that the sms shall contain
txt = u"Greetings from:" +data

# create a query with type: "query" -> appuifw.query(label, type)
# by using an if statement one can check whether the user has pressed "ok" -> True or "cancel" -> False
if appuifw.query(u"Send message to your 2 friends","query") == True:
    # send out the sms; include the mobile number and the text to be sent
    messaging.sms_send(nbr1, txt)
    messaging.sms_send(nbr2, txt)

    # confirm with a pop-up note that the sms has been sent out
    appuifw.note(u"Messages sent", "info")
else:
    # in case the user had pressed "cancel", send a pop-up note that the messages have not been sent out
    appuifw.note(u"Well, your Messages are not sent then", "info")

then we learned how to create an appilictaion menu…

# this script lets you create a simple application menu

# NOTE:
# press the options key in order to open the applicaion menu
# when running the script!

import appuifw, e32

# create the "callback functions" for the application menu
def item1():
appuifw.note(u"booooom", "info")

def item2():
appuifw.note(u"gotcha", "info")

# define an exit handler function
def quit():
app_lock.signal()

# create the application menu include the selectable options (one, two)
# and the related callback functions (item1, item2)
appuifw.app.menu = [(u"one", item1),
(u"two", item2)]

appuifw.app.exit_key_handler = quit

# create an active object
app_lock = e32.Ao_lock()

# start a scheduler
app_lock.wait()

then we learned how to make forms Here is the code tried in the workshop….

import appuifw
import e32

# create an Active Object
app_lock = e32.Ao_lock()

def forming():
# create a list to be used in 'combo' selection mode
model = [u'6600', u'6630', u'7610', u'N90', u'N70']

 # define the field list (consists of tuples: (label, type ,value)); label is a unicode string
# type is one of the following strings: 'text', 'number', 'date', 'time',or 'combo'
data = [(u'Mobile','text', u'Nokia'),(u'Model','combo', (model,0)),(u'Amount','number', 5),(u'Date','date'),(u'Time','time')]

# set the view/edit mode of the form 
flags = appuifw.FFormEditModeOnly

# creates the form
f = appuifw.Form(data, flags)

 # make the form visible on the UI
f.execute()

def exit_key_handler():
app_lock.signal()

# set the title of the script
appuifw.app.title = u'Form'

# call the function that creates the form
forming()

appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()
a saple of form

a sample of form

then location id script was written its as follows:-

import e32
import appuifw
import location   #we imported a module named location whose function will beome clear as we move dowm the script

class gsm_location :
	def __init__(self) :
		self.text = u""

	def gsm_location(self) :
		(self.mcc, self.mnc, self.lac, self.cellid) = location.gsm_location()
		self.text = u"MCC: %s\nMNC: %s\nLAC: %s\nCell id: %s\n" % (self.mcc, self.mnc, self.lac, self.cellid)
		return self.text

	def close(self) :
		pass

e32.ao_yield() 

class gsm_location_app:
    def __init__(self):
        self.lock = e32.Ao_lock()

        self.old_title = appuifw.app.title
        appuifw.app.title = u"GSM Location"

        self.exit_flag = False
        appuifw.app.exit_key_handler = self.abort

        self.db = gsm_location()

        appuifw.app.body = appuifw.Text()
        appuifw.app.menu = [(u"Refresh", self.refresh)] 

    def loop(self):
        try:
            self.refresh()
            self.lock.wait()
            while not self.exit_flag:
                self.refresh()
                self.lock.wait()
        finally:
            self.db.close()

    def close(self):
        appuifw.app.menu = []
        appuifw.app.body = None
        appuifw.app.exit_key_handler = None
        appuifw.app.title = self.old_title

    def abort(self):
        # Exit-key handler.
        self.exit_flag = True
        self.lock.signal()

    def refresh(self):
		self.db.gsm_location()
		appuifw.app.body.set(self.db.text)

def main():
    app = gsm_location_app()
    try:
        app.loop()
    finally:
        app.close()

if __name__ == "__main__":
    main()

well this was the program after which the programming basics like classes ,objects and modules were
undertaken for all that stuff please refer books if stiil got a problem discuss it on forums.lugmanipal.org

Now we wrote the scripts for getting battery information of the mobile

import appuifw
import e32
import sysinfo

def check_battery_level():
    batty = sysinfo.battery()
    print batty

def exit_key_handler():
    script_lock.signal()
    appuifw.app.set_exit()

script_lock = e32.Ao_lock()

appuifw.app.title = u"Battery level"

appuifw.app.menu = [(u"check battery", check_battery_level)]

appuifw.app.exit_key_handler = exit_key_handler
script_lock.wait()

here we defined a function called check_battery_life and used the module sysinfo

now i will end with the keyboard script done on the last day for any explainations please ask your mentors or leave a comment here…with your email-id

# Dialing script by Jurgen Scheible

import appuifw
import e32
import telephone

def main_menu_setup():
    appuifw.app.menu = [(u"dial", dialing),\
                        (u"hang-up", hangingup)]

def hangingup():
    telephone.hang_up()
    main_menu_setup()

def dialing():
    number = u'+1234566'
    telephone.dial(number)
    main_menu_setup()

def exit_key_handler():
    global script_lock
    script_lock.signal()

script_lock = e32.Ao_lock()

old_title = appuifw.app.title
appuifw.app.title = u"Dialer"
main_menu_setup()
appuifw.app.exit_key_handler = exit_key_handler
script_lock.wait()

if i have left of forgotten something please leave a comment or email me on shane2418@gmail.com

Blog at WordPress.com.