×
Namespaces

Variants
Actions

Archived:How to develop a Geo-scheduler application - Part 2

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: croozeus (17 Jul 2008)
Last edited: hamishwillee (31 May 2013)

Contents

Introduction

In the Part 1 of this series of articles, we had an idea about the File Functions of the Geo-Scheduler or the Location-Scheduler application. In this article - Part 2, we would learn about the Feature Functions of the application.

Feature Functions of the application include options to add a new location, Edit a location, Edit a location, Editing screen function, etc. Below are the Listed Feature functions used in the application, which we would discuss in this article.

  1. add_location : Add a new location
  2. edit_location : Edit a location
  3. add_reminder : Add a new reminder
  4. edit_reminder : Editing screen function.
  5. edit_reminder_bylocation : Edit reminder by location function
  6. edit_reminder_byreminder : Edit reminder by reminder function

Part 2

add_location()

Using this function we create a selection list with options like "Cell Id: " + unicode(str(cellid)), "Add Location", "Refresh".

We fetch the current cellid to variable cellid using the location module.

The current cellid would be displayed as the first element in the list.

 (mcc, mnc, lac, cellid) = location.gsm_location()

We need to save a new added location to the file c:\\location.dat, for this we just call the save_location function which would write the values to the location.dat file.

When the entry has been successfully added we show a confirmation note "Location added!"

save_location function has been discussed in Part 1. You can view its definition here.

The definition of the add_location() could be as follows:

def add_location():
(mcc, mnc, lac, cellid) = location.gsm_location()
while True:
addlocationlist = [u"Cell Id: " + unicode(str(cellid)), u"Add Location", u"Refresh"]
location_opt = appuifw.selection_list(choices=addlocationlist)
if location_opt or location_opt == 0:
if location_opt == 0:
temporary_cellid = appuifw.query(u"Enter cell id:", "number", cellid)
if temporary_cellid:
cellid = temporary_cellid
elif location_opt == 1:
cellname = appuifw.query(u"Enter the location name for " + unicode(str(cellid)) + u":", "text")
if cellname:
cellids[str(cellid)] = str(cellname)
save_location()
appuifw.note(u"Location added!", "info")
elif location_opt == 2:
(mcc, mnc, lac, cellid) = location.gsm_location()
else:
break


edit_location()

The previous function add_location() was used to add location names corresponding to a particular cellid. Edit Location as the name suggests is used to modify a pre-added location to the database file.

We have disabled using ":" as a part of the location name, thus it induces an error while trying to have ":" (colon) as a part of the location name.

Here also we use the save_location() function to save the modified location.

save_location() function has been discussed in Part 1. You can view its definition here.

The definition of the add_location() could be as follows:

def edit_location():
locationlist = location_list()
location_in = appuifw.selection_list(choices=locationlist, search_field=1)
if location_in or location_in == 0:
ed_location = locationlist[location_in]
while True:
ed_location = appuifw.query(u"Edit location:", "text", ed_location)
if ed_location:
colons = ed_location.count(':')
if colons > 0:
appuifw.note(u"Cannot use ':' as part of location name.", "error")
else:
cellids[geo[locationlist[location_in]]] = ed_location
save_location()
edit_location()
break
else:
break


add_reminder()

Like add_location(), add_reminder() is also one of the key functions. add_reminder() adds a user defined reminder to a database file. The database file we use here is reminder.dat which is located in C: and is addressed by file_handler_reminder.

file_handler_reminder = "c:\\reminder.dat"

This file handler is used in the save_reminder() function defined in Part 1

Definition for save_location() can be seen here.

In add_reminder() variables like date and desc are used which store the date and description for the custom reminder to be added. We have also used flags like addreminder_cancelled in the function.

Again in the function ':' cannot be used as part of description and doing that throws an exception.

Notes are shown for various actions from the user, like "Reminder Saved" and "Reminder canceled"!

The definition of the add_reminder() could be as follows:

def add_reminder():
locationlist = location_list()
location_in = appuifw.selection_list(choices=locationlist, search_field=1)
# if location_in == null, means the area selection list was canceled,
# so dont show the rest of the options.
addreminder_cancelled = 0
if location_in or location_in == 0:
date = appuifw.query(u"Reminder date:", "date", time.time())
if date:
date = date
desc = u''
while True:
desc = appuifw.query(u"Reminder text:", "text", desc)
if desc:
colons = desc.count(':')
if colons > 0:
appuifw.note(u"Cannot use ':' as part of description.", "error")
else:
break
else:
addreminder_cancelled = 3
break
else:
addreminder_cancelled = 2
else:
addreminder_cancelled = 1
 
if addreminder_cancelled == 0:
reminders[str(len(reminders))] = {'cell':geo[locationlist[location_in]], 'date':str(date), 'desc':desc}
save_reminder()
appuifw.note(u"Reminder Added")
else:
appuifw.note(u"Reminder Canceled!", 'error')


edit_reminder_bylocation()

After a reminder has been added for a specific location, there can be two possible ways the user can edit this reminder entry.

1) By editing the reminder i.e the reminder description.

2) By editing the reminder location.

The edit_reminder_bylocation() modifies the reminder location. Thus the user would again be showed the location list and can reselect the location which is assigned to the reminder.

The reminder can also be canceled or deleted by the user. We use the edreminder_cancelled flag variable for this purposes. After deleting the user can again add the reminder and edit it as well.

We use the edit_reminder(reminder_id) function in edit_reminder_byreminder() which is defined here.

The definition of the edit_reminder_bylocation() could be as follows:

def edit_reminder_bylocation():
locationlist = location_list()
# Show reminder selection list.
edreminder_cancelled = 0
locationindex = appuifw.selection_list(choices=locationlist, search_field=1)
bylocation_list = []
if locationindex or locationindex == 0:
for key, value in reminders.items():
if value['cell'] == geo[locationlist[locationindex]]:
bylocation_list.append(unicode(str(key) + ": " + value['desc']))
 
reminderindex = appuifw.selection_list(choices=bylocation_list, search_field=1)
if reminderindex or reminderindex == 0:
reminder_id, reminder_desc = bylocation_list[reminderindex].split(':')
edreminder_cancelled = edit_reminder(reminder_id)
else:
edreminder_cancelled = 2
else:
edreminder_cancelled = 1
 
# Cancelled at some point.
if edreminder_cancelled > 1:
edit_reminder_bylocation()


edit_reminder_byreminder()

This function deals for modifying a pre-added reminder for its description.

Using this function the reminder can also be deleted if the user wishes. The edreminder_cancelled is the flag variable used for this purpose.

We use the edit_reminder(reminder_id) function in edit_reminder_byreminder() which is defined here.


The definition of the edit_reminder_byreminder) could be as follows:

def edit_reminder_byreminder():
# Show reminder selection list.
edreminder_cancelled = 0
byreminder_list = []
for key, value in reminders.items():
byreminder_list.append(unicode(str(key) + ": " + value['desc']))
 
reminderindex = appuifw.selection_list(choices=byreminder_list, search_field=1)
if reminderindex or reminderindex == 0:
reminder_id, reminder_desc = byreminder_list[reminderindex].split(':')
edreminder_cancelled = edit_reminder(reminder_id)
else:
edreminder_cancelled = 1
 
# Cancelled at some point.
if edreminder_cancelled > 1:
edit_reminder_byreminder()


edit_reminder(reminder_id)

This function is the primary function used to modify an pre-added reminder.

We have used this in modifying functions like edit_reminder_byreminder() and edit_reminder_bylocation().

This function would be responsible for modifying the reminder desc, date, time or location as per the function call.

The reminder that is to be edited or modified is identified by the parameter of the function. We have named this parameter as reminder_id and it is a parameter to be passed to the function according to the selection list index chosen by the user.

Warnings or notes are shown to the user for confirmation like "Saved!", "Deleted!" and "Not saved".

The definition for edit_reminder(reminder_id) could be as follows:

def edit_reminder(reminder_id):
locationlist = location_list()
 
edreminder_desc = unicode(reminders[reminder_id]['desc'])
edreminder_date = float(reminders[reminder_id]['date'])
edreminder_location = unicode(cellids[reminders[reminder_id]['cell']])
 
while True:
edreminder_values = [u"ID: " + reminder_id, u"Desc: " + edreminder_desc, u"Date: " + unicode(time.strftime
 
("%d/%m/%Y", time.gmtime(edreminder_date+5400))), u"Location: " + edreminder_location, u"[ save ]", u"[ delete ]"]
edreminder_index = appuifw.selection_list(choices=edreminder_values, search_field=1)
if edreminder_index == 0:
continue
elif edreminder_index == 1:
# Editing the description.
temporary_desc = edreminder_desc
while True:
temporary_desc = appuifw.query(u"Reminder text:", "text", temporary_desc)
if temporary_desc:
colons = temporary_desc.count(':')
if colons > 0:
appuifw.note(u"Cannot use ':' as part of description.", "error")
else:
edreminder_desc = temporary_desc
break
else:
break
 
elif edreminder_index == 2:
# Editing the date.
temporary_date = appuifw.query(u"Reminder date:", "date", float(edreminder_date))
if temporary_date:
edreminder_date = temporary_date
elif edreminder_index == 3:
# Editing the location.
temporary_location = appuifw.selection_list(choices=locationlist, search_field=1)
if temporary_location or temporary_location == 0:
edreminder_location = locationlist[temporary_location]
elif edreminder_index == 4:
# Save to dictionary.
reminders[reminder_id]['desc'] = edreminder_desc
reminders[reminder_id]['date'] = edreminder_date
reminders[reminder_id]['cell'] = geo[edreminder_location]
# Save edited values to file.
save_reminder()
appuifw.note(u"Saved!", 'info')
return 4
elif edreminder_index == 5:
# Save edited values to file.
del reminders[reminder_id]
save_reminder()
appuifw.note(u"Deleted!", 'info')
return 5
else:
# Cancelled.
appuifw.note(u"Not saved!", 'error')
return 3
# End while
# End def


That finishes the Feature functions (Part 2) for the Geo-scheduler.

The next article in the series : Part 3 for Geo-Scheduler, would cover Application Operations for the application and would conclude this application.


Screenshots

Screenshot0016.jpg Screenshot0017.jpg Screenshot0018.jpg

Screenshot0019.jpg Screenshot0020.jpg Screenshot0021.jpg

Screenshot0022.jpg Screenshot0023x.jpg Screenshot0024x.jpg


Go to

This page was last modified on 31 May 2013, at 01:08.
48 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.

×