Archived:How to use Form in PySymbian
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.
This article explains how to use PySymbian's appuifw module's Form class, which implements a dynamically configurable, editable multi-field dialog. Form is useful for creating all sorts of dialogs because it offers free selectability of the combination of fields, possibility of validating the user input, and automatically producing the contents of some dialog fields before allowing the closing of the dialog.
Article Metadata
Tested with
Compatibility
Platform Security
Article
Source code
import appuifw, time
#Make a list of objects, for example phones
models = [u"6600", u"6630", u"7610", u"N90", u"N70"]
#Create the fields to be displayed in the form
fields = [(u"Company", 'text', u"Nokia"),
(u"Model", 'combo', (models, 0)),
(u"Amount",'number', 1),
(u"Date", 'date', time.time()),
(u"Time", 'time')]
#Initialize a boolean variable to know whether the form is saved
saved = False
#Define a function to be called when the form is saved
def save(arg):
global saved
saved = True
return True
#Create an instance of Form
myForm = appuifw.Form(fields, flags=appuifw.FFormEditModeOnly)
#Assign the save function
myForm.save_hook = save
#Execute the form
myForm.execute()
#After the form is saved and closed, display the information
if saved == True:
print myForm[0][2]
print models[myForm[1][2][1]]
print myForm[2][2]
print time.strftime("%d/%m/%Y", time.localtime(myForm[3][2]))
print time.strftime(time.ctime(myForm[4][2])[11:20])
Postconditions
The form is created and displayed.
Additional information
The constructor for the Form class is {{{1}}}, where fields is a list of field descriptors with the structure: (label, type[, value]).
- label is a Unicode string.
- type is one of the following strings: 'text', 'number', 'date', 'time', 'combo' or 'float'
- value is the default value of the field.
Instances of Form have the following attributes:
- flags
- FFormEditModeOnly - the form remains in edit mode while it is being executed.
- FFormViewModeOnly - the form cannot be edited at all.
- FFormAutoLabelEdit - allows the user to edit the labels of the form fields.
- FFormAutoFormEdit - allows the user to add or delete form fields.
- FFormDoubleSpaced - applies double-spaced layout.
- menu
A list of (title, callback) tuples where title (Unicode) is the name of the item and callback is the associated function.
- save_hook
Can be set to a callable object that takes one argument and returns a Boolean value. The argument is the currently visible contents of the form and is set as the new contents of the form if the callable returns True, otherwise the contents of the form are reset.
Instances of Form have the following methods:
- execute()
Executes the dialog by making it visible on the UI.
- insert(index, field_descriptor)
Inserts the field_descriptor into the form before the position represented by index.
- pop()
Removes the last field descriptor from the form and returns it.
- length()
The number of field descriptors in the form.



15 Sep
2009
how to use this myForm
how to use this myForm[0][2] [0] means?? and [2]???
print myForm[0][2] print models[myForm[1][2][1]] print myForm[2][2]