Join Now
Quality Rating:
  • Currently 3.0 / 5
(3.0 / 5 - 2 votes cast)
This page was last modified 02:54, 27 July 2008.

Basic PyS60 Application: Series3

From Forum Nokia Wiki


Contents

Introduction

The first two articles of this series focused on application structure and a user friendly application. First Article explained how to design a application and the second one explained how to make a application which is user controlled.

In the previous article we all must have heard two terms very frequently they are

callback functions and

objects

This article will describe these terms. Callback functions and Objects are a very important terms when we want to develop applications in Python. Callback functions are not the same as normal functions and the difference will be emphasized in next paragraphs.


Callback Function

Callback function is more or less same as a normal function. Callback functions are defined similarly as a normal function. There is not a much of technical difference between a callback function and normal function but callback functions are rather used for some specific purpose. Generally a Callback function is called by a function to respond to a specific event for example in PyS60 when we choose a menu or decide to quit an application then a callback function is called. The code below explains the callback function:

import appuifw, e32
  appuifw.app.menu = [(u"menu1", callbck_1),
                      (u"menu2", callbck_2),
                      (u"menu3", callback_3),
                      (u"menu4", callback_4)]

Another key term of great importance is known as binding. Attaching a event with a function is called binding. Certain objects in PyS60 like Canvas have a bind() function so that a callback function is attached a to a specific event.

A callback function and a normal function differ only in one way when calling a callback function the parentheses are not used. Look at the code below:

def quit():
   print u"exit key pressed"
 
appuifw.app.exit_key_handler = quit # calling a callback function
 
quit() #calling a normal function

Objects

Object handling is very easy in python. Objects had the job of holding the variables and functions together that manipulate the objects. variables and functions are having many things in common so its not good to keep the variables and functions different. Objects are generally very much useful in large and complex applications where its good to divide the whole application into small, small parts. with the code below we can explain the objects concept in detail:

app_lock = e32.Ao_lock()
 
app_lock.wait()
 
app_lock.signal()

in the code above a object of module e32 i.e. Ao_lock is assigned to the variable app_lock and following to that the variable can be assigned to use the functions of the objects using the dot notation. As we are using the two functions wait and signal with the variable app_lock.

In simple language we can say that objects are modules inside modules.

Related Links

Related Discussions
Thread Thread Starter Forum Replies Last Post
Database in Python S60 Faisal Rehman Python 14 2008-07-31 18:29
[Announce] SOURCE CODE and PyS60 1.3.1 is HERE ! cyke64 Python 3 2006-02-02 11:12
Developing S60 3rd edition using Linux stone4x4 Python 4 2006-07-28 17:54
install PyS60 and python apps on MEMORY CARD cyke64 Python 2 2007-02-19 18:05
Question about dialog rsf Python 9 2007-10-27 04:58
 
Powered by MediaWiki
RDF Facets: qfnZtopicQUqfnTopicZpythonQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX