×
Namespaces

Variants
Actions

Archived:Basic PySymbian app - series2

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Article Metadata
Article
Created: gaba88 (19 Jul 2008)
Last edited: hamishwillee (31 May 2013)

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 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:

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

This page was last modified on 31 May 2013, at 04:02.
60 page views in the last 30 days.
×