Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:How to use Form in PySymbian

From 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.

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
Devices(s): Nokia N95, Nokia E90
Compatibility
Platform(s): S60 1st Edition, S60 2nd Edition, S60 3rd Edition
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: appuifw
Created: lfd (14 May 2007)
Last edited: hamishwillee (31 May 2013)

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.

Form.jpg

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.

This page was last modified on 31 May 2013, at 01:09.
61 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×