Archived:Basic PySymbian app - series2
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 PySymbian application.
Now it is time to go more technical and learn about other important fundamentals application development. In PySymbian, 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:
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:
print u"exit key pressed"
appuifw.app.title = u"Main"
appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
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).
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.
This is a very important concept one should always keep in mind when designing an application.