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

September 6, 2008

MOBIVISION WRKSHOP DAY2-PYTHON

Filed under: linux — maniacmind @ 4:10 AM

Sorry guys for the delay in uploading the documentation…so without any further delay lets get started…………before that all the scripts done in class are uploaded on
http://www.esnips.com/web/shane2418sStuff
DAY 2
the day started with a brief revison and then we started with the following stuff…. firstly we started with pop up menu…..

import appuifw

# create a list with the content in []
L = [u"Python", u"Symbian", u"Mlab"]

# create the pop-up menu including the list of content
#and a label
# syntax--> appuifw.popup_menu(list , label)
test = appuifw.popup_menu(L, u"Select + press OK:")

# the variable test holds the indicator which list item (position in the list)
# has been selected
# trigger some action (here we print something)
if test == 0 :
    appuifw.note(u"Python, yeah", "info")
elif test == 1 :
    appuifw.note(u"Symbian, ok", "info")
elif test == 2 :
    appuifw.note(u"Mlab, cool students", "info")



well we hae seen single query earlier lets now see multiple query....
# This script creates 2 text input fields on one screen
# It uses the multi_query function of the appuifw module

import appuifw

# syntax-->  appuifw.multi_query(label1, label2)
data1,data2 = appuifw.multi_query(u"Type your first name:",u"Type your surname:")

# print the reuslts on the screen
  print data1
  print data2

Now lets move to the selection list…i.e a list from which we select single item

# This script executes a dialog  that allows the users to select an item
#in a list and returns the index (of the list) of the chosen item
#syntax --> appuifw.selection_list(choices=list , search_field=0 or 1)


import appuifw

# define the list of items (items must written in unicode! )
L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']

# create the selection list
index = appuifw.selection_list(choices=L , search_field=1)

# use the result of the selection to do some action
#(here we just print something)
if index == 0:
    print "cakewalk was selected"
else:
    print "thanks for choosing"

# the search_field=1 (set to 1) enables a search  for
# looking up items in the list. i.e to activate the find pane
# if search_field=0 no search pane is enabled.
selection list

selection list

After the selection list lets move on to other list called the multi -selection list there is two types of multi-selection lists:- i) with checkbox ii)with check mark

# 1. with checkbox:

import appuifw

# define the list of items (items must written in unicode!)

L = [u’cakewalk’, u’com-port’, u’computer’, u’bluetooth’, u’mobile’, u’screen’, u’keys’]

# create the multi-selection list with checkbox

index = appuifw.multi_selection_list(L , style=’checkbox’, search_field=1)

# create a new list (Lnew) that inlcudes only the selected items and print the new list (Lnew)

Lnew = index print Lnew

2.with check mark i

mport appuifw

# define the list of items (items must written in unicode!)

L = [u’cakewalk’, u’com-port’, u’computer’, u’bluetooth’, u’mobile’, u’screen’, u’camera’, u’keys’]

# create the multi-selection list

tuple = appuifw.multi_selection_list(L , style=’checkmark’, search_field=1)

# create a new list (Lnew) that inlcudes only the selected items and print the new list (Lnew)

Lnew = tuple print Lnew After that we moved on to the functions…i.e HOW TO DEFINE A FUNCTION AND HOW TO CALL IT

# defining a function :lets take an example here.....

import appuifw
function

function .eg+comments

Before moving on further i wou
ld like to explain about the exit key handler.. The exitkey handler gets activated when you press the right (exit) softkey. By assigning an extra function to the .exit_key_handler you can define what shall happen when it is pressed.

import appuifw
def quit():
     print "exit key pressed"
     app_lock.signal()
appuifw.app.exit_key_handler = quit
appuifw.app.title = u"First App!"
appuifw.note(u"Application is now running")
app_lock = e32.Ao_lock()
app_lock.wait()
print "Application exits"

Besides importing the familiar appuifw module, we also need a module named e32. This module offers many useful low-level utility objects and functions related to Symbian OS functionalities. Here we
need the object e32.Ao lock(). We define a new function, quit(), that takes care of shutting down
the application when the user presses the Exit key. Since we could have a number of functions to perform various tasks, we need to tell Python which function is dedicated to handling the Exit events.
This is done by assigning the function name (not its value) to the special appuifw.app.exit key handler variable. When the user presses the Exit key, the function that this variable refers to is called by
the UI framework. In many situations, Python expects you to provide a function name that is used to call the corresponding function when some event has occurred. Functions of this kind are called callback functions.

now lets see a python script
—————————————————————————————————————————————-

import appuifw
import e32 #importing e32 module

def exit_key_handler():
     app_lock.signal()    # stops the scheduler 

round = appuifw.Text()
round.set(u'hello')

# put the application screen size to full screen
appuifw.app.screen='full' #(a full screen)

# other options:
#appuifw.app.screen='normal' #(a normal screen with title pane and softkeys)
#appuifw.app.screen='large' #(only softkeys visible)

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

appuifw.app.body = round

appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()   # starts a scheduler -> the script processes events (e.g. from the UI) until lock.signal() is  callled.

——————————————————————————————————————————————
here is another python script covered just try to understand it……….try to figure it out what’s happening i m not telling u…..(for any doubts leave a comment or mail me on 1988.shashank@gmail.com…)

import appuifw
import e32

appuifw.app.screen='large'

# create your application logic ...

def item1():
print "hello"

def subitem1():
print "aha"

def subitem2():
print "good"
#creating a menu and submenu
appuifw.app.menu = [(u"item 1", item1),
(u"Submenu 1", ((u"sub item 1", subitem1), (u"sub item 2", subitem2)))]

def exit_key_handler():
app_lock.signal()

appuifw.app.title = u"drawing"    #gives the title of the page

app_lock = e32.Ao_lock()

appuifw.app.body = ...

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

——————————————————————————————————————————————–
i think all the stuff till the second day is covered here if anything is missing please notify me remember

to error is human

will cover rest of the portion by sunday (7th sept,08please bear patience)

September 1, 2008

MOBIVISION WORKSHOP DAY ONE………….

Filed under: computers,linux — maniacmind @ 11:49 PM

WELL TODAY A LOT MANY PEOPLE TURNED UP FOR THE WORKSHOP…about 200 people that too after leaving those without the delegate cards…i really felt bad those guys i wanted them all to attend the workshop after all we believe in freedom we believe in open source…………

so without wasting time of anyone i start with what all been taught today in the workshop leaving behind the installation process i will start with python portion

started with the modules….

what is a module….?

Technicallty saying module can be defined as a file that contains a collection of related functions and realted data grouped together…..or in a very crude way its something like iostream in c++

we started with appuifw module which stands for( APPLICATION  USER INTERFACE FRAMEWORK)

To use a module in our code we have to import it in the beginning  of the script only….

import appuifw

To call or address the function in a module
lets start with the function note of module appuifw
syntax

appuifw.note(text[,type[,global]])

The sample code given was

appuifw.note(u"hello world","info")

“info” gives the i symbol in the note it stands of any thing informing the user about something……like keypad getting locked or unlocked.Here u used in the symbol represents the unocode(about Unicode i would rather suggest you to refer wikipedia)
in place of “info” we can also use “error” and “conf”
i would suggest the people to try it out themselves and see what they do…………………
after the note function we moved on to query function………………
single feild dailog query
syntax

query(label,type[,initial value])

sample code
rather than using all the types of query function I’ll use all of them together…………

appuifw.query(u"type yor name:","text")
appuifw.query(u"number","number")
apappuifw.query(u"enter a date:","date")
apppuifw.query(u"enter a time:","time")
apppuifw.query(u"passwod:","code")
appuifw.query(u"u are working on python s60","float")

the initial vales can also be included
i would like to write something more
1—>for text fields,return value is Unicode string.
2–>for date fields the date is calculate in seconds since due to epoch.
(goggle out epoch)
(PS: I would suggest people to try all that given above by themselves i anyone face any problem i can be reached 99986411323 or leave a comment i would surely try to help to solve the problem
this is all for today will be back tomorrow with the progress of second day……………

Create a free website or blog at WordPress.com.