Categories: S60 | Python
This page was last modified 18:21, 5 August 2008.
Basic PyS60 Application: Series2
From Forum Nokia Wiki
Contents |
Introduction
The first article in this series was very important because it focused mainly on how to guide your application by using a proper architecture. In that article there were the basic things to consider when building a PyS60 application.
Now it is time to go more technical and learn about other important fundamentals application development. In PyS60, a developer should always keep in mind that application s/he is designing should always exit properly when the user wants to do so.
This article will help in understanding this point.
A Simple Application
Consider the code snippet written below:
import appuifw appuifw.note(u"HI","info)
When someone runs this application on a device, it simply shows a note saying HI. One important thing to notice is that the application displays the note for a few seconds, and then it vanishes automatically without user intervention.
Next Important Step
Now consider another important code snippet below:
import appuifw,e32 def quit(): print u"exit key pressed" app_lock.signal() def main(): appuifw.note(u"HI","info") appuifw.app.title = u"Main" main() appuifw.app.exit_key_handler = quit app_lock = e32.Ao_lock() app_lock.wait()
In this example, our application has Main as its title and it displays a note. One important thing to notice is that this application does not exit automatically.
This application exits only when the user presses the right soft key (i.e. the exit key).
Explanation
Some important things about the previous code snippet:
- we have used two modules: one is the e32 module and the other is the appuifw module.
- We have used a function named exit_key_handler which is a member of the app object of the appuifw module.
- Whatever callback function we assign to exit_key_handler is called when the right soft key is pressed.
- We have used an object from the e32 module, Ao_lock. This object is mainly responsible for creating a lock for the application.
- The Ao_lock object has two functions named wait and signal.
- When we call the function wait, a lock is created on the application. The lock is released when the corresponding signal function is called.
- So we have called the signal function in a callback function quit which the exit_key_handler function calls.
- This makes our application user-controlled, which means that whenever the user presses the exit button, the application exits.
Conclusion
This is a very important concept one should always keep in mind when designing an application.
Useful links
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| new to symbian | iris36 | General Symbian C++ | 6 | 2007-05-16 08:54 |
| PyS60 GPRS connectivity issue | dani2mobile | Python | 8 | 2008-02-04 17:42 |
| Python Imaging Library extension for PyS60? | phishboh | Python | 0 | 2008-02-21 09:28 |
| putools + execute scripts | freaky_911 | Python | 1 | 2008-03-18 14:20 |
| Hiding the application | ajitac | Symbian Signing, Certification and Security | 8 | 2007-07-24 09:34 |
