Wednesday, 16 January 2013

Application Structure


Application Structure

Many S60 applications share the same user interface layout. Take a
look at Figure 4.1 or almost any application on your S60 mobile phone,
including the PyS60 interpreter and you will notice the same structure in
the user interface.

Figure 4.1(a) shows the structure of the S60 user interface. To see how
the diagram maps to reality, compare it to Figure 4.1(b), which shows
a typical user interface that is built using the S60 UI framework. In the
following description, text in parentheses refers to text in the screenshot.
At the top of the screen, you see the application title (Tabs). Below the
title, you may see a row of navigation tabs (One and Two). The large area
in the middle is the application body which may be used by a number of
different UI elements (the list: red, green, blue, brown). Various dialogs,
such as popup notes, may appear on the application body, as we saw in
Chapter 3.
At the bottom, you see two items that are activated by two dedicated
keys, the left and right softkeys, on your mobile phone keyboard. If no
dialog is active, the left softkey activates the application menu (Options)
and the right softkey quits the running application (Exit). If a dialog
is shown, the left softkey corresponds to Accept and the right one to
Cancel.
In PyS60, you can access the UI elements through a special app
object that is part of the appuifw module. We talk more about objects
in Section 4.2. Modifying the UI elements is easy: each of the elements
(title, body, menu and exit key handler) is a special variable
inside the appuifw.app object and you can assign values to them as
you can to any other variable. Just remember to use the full name, for
instance appuifw.app.title. Whenever you change any of these
variables, the corresponding UI element changes accordingly.
The first application is a minimalist application that uses the UI framework
provided by the appuifw module. It does not do anything useful
but it illustrates the minimum requirements for a working application. It
runs until the user chooses to quit the application, as opposed to previous
examples, which executed deterministically from the beginning to the
end. Figure 4.2 shows it in action.



Example 11: First application
import appuifw, e32
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.
The language lesson about callback functions clarifies the concept.































No comments:

Post a Comment