HomePython Page 2 - Mobile Programming in Python using PyS60: UI Controls
UI Controls: Query and Notes - Python
In this discussion I will focus on the basics of using a UI library provided by PyS60. The first section will focus on the types of controls. The second and third sections will be about two basic controls – query and note. In the fourth section, a simple application will be developed that uses the controls discussed in the second and third sections. That’s the agenda for this discussion.
Query and Notes controls are the most commonly used of all the controls. They are used to take input and display messages. Here are the details:
Query is a dialog type. It is used to gather input from the user. It presents a single line text box with a label to the user. Since query is a dialog, it is also implemented as a function. There are three parameters to the function. They are label, type, and initial value. The first two are mandatory parameters, whereas the third is optional. Here are the details:
The label is the question or prompt that is shown to the user when the dialog box is displayed. The value for this argument is a Unicode string. For example, to show “Enter name” as the prompt, one will use the following as the value of the argument:
Type can be compared with the standard input dialog box that is common on the PC. Since it is a dialog, it can be of different dialog types. The type is decided by the type parameter of the query function. The different types are:
Text – is a simple text. The text is of Unicode type.
Number – in this case, the input box will accept only numbers and not decimals.
Date – the input is just a date.
Time – to take time as input, the type needs to be set to time.
Float – to accept only decimals, this type can be used.
All of these are string values. For example, to set the type to number, the value passed will be:
The initial value is an optional parameter. It sets the initial value shown to the user. However, for the type float, setting this value does not have any effect. For text fields (i.e. the type having the value of either ‘text’ or ‘code’), the value for this argument is Unicode. If the type is ‘number,’ the value that can be passed is a numeric value only. If the type is date, then the initial value will be seconds, since an epoch is rounded to the nearest local midnight. For example, to set the initial value to 3, the value passed will be:
The return value of the query is the value provided by the user and the type of the input box. Therefore, to display a query with “Enter any number between 1 and 9” as a message, with number as the only acceptable data type and 0 as the initial value, the statement will be:
guess=query(u“Enter any number between 1 and 9”, ‘number’,0)
This is the end of the second section. In the next section, we will discuss the note control.