×
Namespaces

Variants
Actions
(Difference between revisions)

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

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Add timestamp to ReviewerApproved template)
hamishwillee (Talk | contribs)
m (Text replace - "Category:Python" to "Category:PySymbian")
Line 1: Line 1:
[[Category:Location]][[Category:Python]][[Category:S60]][[Category:Code_Examples]]
+
[[Category:Location]][[Category:PySymbian]][[Category:S60]][[Category:Code_Examples]]
 
{{ArticleMetaData
 
{{ArticleMetaData
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->

Revision as of 06:04, 30 November 2011

Article Metadata
Article
Created: croozeus (31 Jul 2008)
Last edited: hamishwillee (30 Nov 2011)
{{{width}}}
17 Sep
2009

Contents

Introduction

Finally we have the last article in the series of "How to develop a Geo-Scheduler or a Location Based Scheduler application" The first two articles can be found here- Part 1 and Part 2. If you have followed this series of articles, then after finishing this one, you should be capable enough to create your own location based application.

In this article - Part 3, we would learn about the Application operations (functions) of the Geo-scheduler application. The application operations consists of functions responsible for the UI of the Geo-scheduler. It contains functions which generate menus, selection lists,etc.

Application operations are listed below:

  • ms_handler() : The main screen handler
  • main() : The first and the main screen
  • help() : method for using the help screen
  • tracker() : The main tracker function
  • background_handler() : Provided Background handling options
  • Calling the methods : Sequence in which we call the defined methods.

As the functions are responsible for UI and generating menus, selection lists, they could be modified according to the requirements of the developer.

Lets discuss the above in detail.

Part 3

ms_handler()

ms_handler is a short for main screen handler. Using this method - we create a custom menu and a UI. The ms_lb.current() is used to trigger or direct to a specific method.

index= ms_lb.current()

For example if index = 0 then the method to add a new reminder is called - add_reminder()

Thus the code of ms_handler() could be as follows:

# MS option handler.
def ms_handler():
index = ms_lb.current()
# ADDING REMINDER
if index == 0:
add_reminder()
 
# EDITING REMINDER
if index == 1:
# Show menu.
editreminder_opts = [u"Location", u"Reminder description"]
search_by = appuifw.popup_menu(editreminder_opts, u"Search by:")
if search_by == 0:
# Edit reminder by location.
edit_reminder_bylocation()
if search_by == 1:
# Edit reminder by reminder.
edit_reminder_byreminder()
 
# ADDING LOCATION
if index == 2:
add_location()
 
# EDITING LOCATION
if index == 3:
edit_location()


main()

This would be the first method to be called on the launch of the application. Its responsibility is to set appuifw.app.body to ms_lb.

where the below is true:

ms_opts = [u"Add Reminder", u"Edit Reminder", u"Add Location", u"Edit Location"]
ms_lb = appuifw.Listbox(ms_opts, ms_handler)

The function can be modified for better enhancement of the UI (may be a startup image on the canvas)

The function also generates a main menu for the application, including options like Help and Start Tracker.

The code for the main() could be as follows:

def main():
appuifw.app.body = ms_lb
appuifw.app.quit = quit
 
# Set application initial menu.
appuifw.app.menu = [(u"Help", help),(u"Start Tracker", background_handler)]


help()

As the name suggests this function provides information and instructions to the user of the application.

The code for the help() function could be as follows:

# Help screen.
def help():
helptext = appuifw.Text()
helptext.set(u"Scheduler:\nHere you can manage the locations and the reminders associated with those locations.")
appuifw.app.body = helptext
appuifw.app.quit = main

The help text can be more descriptive and instructions may be added to the sample statement.

Also a text file containing the instructions for using the application could be opened through this functions.


tracker()

This is the main tracker function, however only background_handler() is called from the menu in the main function.

We use the tracker to assign the current cellid to variable curr_cellid or the last cellid variable, last_cellid.

The appswitch module is used in this function. We can use it to trigger the application to foreground and background as follows:

appswitch.switch_to_fg(unicode(app_name))
appswitch.switch_to_background(unicode(app_name))

The appswitch extension could be downloaded here.

The code for the tracker() could be as follows:

# The main tracker function.
def tracker():
(mcc, mnc, lac, cellid) = location.gsm_location()
 
while track == 1:
(mcc, mnc, lac, cellid) = location.gsm_location()
curr_cellid = cellid
 
if not curr_cellid == last_cellid:
reminderscnt = len(reminders)
tracker_log = ""
curr_date = time.strftime("%d/%m/%Y")
for i in range(reminderscnt):
j = str(i)
reminder_date = time.strftime("%d/%m/%Y", time.gmtime(float(reminders[j]['date']) + 5400))
if str(reminders[j]['cell']) == str(curr_cellid) and curr_date == reminder_date:
tracker_log += j + ": (" + str(curr_cellid) + ") " + str(reminders[j]['desc']) + "\n"
appswitch.switch_to_fg(unicode(app_name))
S.play()
appuifw.query(unicode(str(reminders[j]['desc'])), "query")
S.stop()
appswitch.switch_to_background(unicode(app_name))
 
last_cellid = curr_cellid
e32.ao_sleep(5)

Here we use e32.ao_sleep(5) so that the function repeats, (if recursive ) every 5 seconds. The time can be adjusted according to the needs of the developer.

Other option is the timers, instead for sleep function.

The sample code for timers could be found here. sleep is used here to avoid complexity.

background_handler()

The background_handler() is called from the main menu when "Start Tracking" is selected.

A menu including "Stop Tracker" and "Help" is created using appuifw.app.menu function.

appswitch is used to set the application is background using switch_to_background(app_name) method. The appswitch extension could be downloaded here.


The code for background_handler() could be as follows.

def background_handler():
global track
if not track or track == 0:
track = 1
appuifw.app.menu = [(u"Help", help),
(u"Stop Tracker", background_handler)]
appswitch.switch_to_background(app_name)
tracker()
elif track == 1:
track = 0
main()


Calling the methods

The defined methods need to be called in a proper sequence, and some variables need to be populated.

The file handler for alarm or alert could be set as:

file_handler_alert = "Path to the sound file"

The sound file should be .wav, .mp3, .acc (supported to be played by the specific Mobile device)

Sequence of initializing and calling methods:


# Populate cellids and geo dictionary and loclist list.
cellids = {}
geo = {}
load_location()
track = 0
# Populate reminder and remsdesc dictionary.
reminders = {}
remindersdesc = {}
load_reminder()
# temporary cell id list for testing without network requirement.
cellidlist = [1563, 1671, 1523, 1111, 1111, 1671]
 
S = audio.Sound.open(file_handler_alert)
 
# Start program.
main()
 
app_lock = e32.Ao_lock()
appuifw.app.title = u'Geo-Sheduler'
app_lock.wait()

Screenshots

Screenshot0026x.jpg

Screenshot0016.jpg Screenshot0017.jpg Screenshot0018.jpg

Screenshot0019.jpg Screenshot0020.jpg Screenshot0021.jpg

Screenshot0022.jpg Screenshot0023x.jpg Screenshot0024x.jpg

Screenshot0025x.jpg

Conclusion

We have concluded the series of the articles on "How do develop a Geo-scheduler application"

If you have been following the series, you may now be able to make location based application - logic, design and UI - Using the template from the geo-scheduler application

The links to the previous articles in the series could be found below.

Go to

58 page views in the last 30 days.