×
Namespaces

Variants
Actions
(Difference between revisions)

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

From Nokia Developer Wiki
Jump to: navigation, search
copyeditor (Talk | contribs)
m
copyeditor (Talk | contribs)
m
Line 5: Line 5:
  
  
Do you want to develop location-based applications ?  
+
Do you want to develop location-based applications?  
  
This article is the first in a series where we are going to approach all the basics for developing a location-based application for mobile phones. We can see it as a Geo-Scheduler or a Location scheduler. We use the simplest rapid mobile application development tool for this - [[PyS60]].
+
This article is the first in a series approaching all the basics for developing a location-based application for mobile device. The application can be defined as a Geo-Scheduler or a Location scheduler. The simplest rapid mobile application development tool, [[PyS60]], is used to develop the application.
  
We would be using the following modules in the course of developing this application:
+
The following modules are used to develop this application:
  
 
*appuifw module
 
*appuifw module
Line 28: Line 28:
  
  
The extensions mentioned above could be downloaded from the [[C++ Python Extensions]].
+
The extensions mentioned above can be downloaded from the [[C++ Python Extensions]].
  
== Development Tools ==
+
== Development tools ==
  
 
1) A text editor
 
1) A text editor
  
(Preferable : Pythons IDLE- Integrated DeveLopment Environment)
+
(Preferred editor: Python's IDLE - Integrated DeveLopment Environment)
  
 
2) Python for S60  
 
2) Python for S60  
  
(Preferable : Latest release 1.4.4)
+
(Preferred version: latest release 1.4.4)
  
 
3) Python for S60 script shell  
 
3) Python for S60 script shell  
  
(Preferable : Latest release 1.4.4)
+
(Preferred version: Latest release 1.4.4)
  
4) Extensions listed in above which are not bundled with Pys60
+
4) Extensions listed above which are not bundled with PyS60
  
  
The Pys60 tools can be downloaded from [http://sourceforge.net/projects/pys60 Sourceforge resources].
+
The PyS60 tools can be downloaded from [http://sourceforge.net/projects/pys60 Sourceforge resources].
  
  
 
== Basic approach ==
 
== Basic approach ==
  
In this application we do the localization using the network info. The network info could be provided using the location module. We call this ''cellid''. If you are not familiar about how to retrieve the cellid using Pys60, How to use the appswitch module, How to use the envy module, I would suggest you to read the following  articles before moving ahead.  
+
In this application, localization is done using the network info. The network info can be provided using the location module, ''cellid''. If you are not familiar with retrieving the cellid using Pys60, using the appswitch module, usingthe envy module, read the following  articles before proceeding.  
  
 
[[How to switch application in foreground]]
 
[[How to switch application in foreground]]
Line 61: Line 61:
  
  
We would be using the following methods or functions
+
==Methods and functions==
  
 +
The following methods or functions will be used:
  
==File Functions ==
+
===File functions ===
  
1) save_location : Save location info back into file
+
1) save_location: Save location information into file
  
2) load_location : Read location info into variables
+
2) load_location: Read location information into variables
  
3) save_reminder : Save reminder info into file
+
3) save_reminder: Save reminder information into a file
  
4) load_reminder : Read reminder info into variables
+
4) load_reminder: Read reminder information into variables
  
5) dictionary_copy : Dictionary copy
+
5) dictionary_copy: Dictionary copy
  
6) location_list : Return the location names.
+
6) location_list: Return the location names
  
  
  
== Feature Functions ==
+
=== Feature functions ===
  
  
1) add_location : Add a new location
+
1) add_location: Add a new location
  
2) edit_location : Edit a location
+
2) edit_location: Edit a location
  
3) add_reminder : Add a new reminder
+
3) add_reminder: Add a new reminder
  
4) edit_reminder : Editing screen function.
+
4) edit_reminder: Editing screen function
  
5) edit_reminder_bylocation : Edit reminder by location function
+
5) edit_reminder_bylocation: Edit reminder by location function
  
6) edit_reminder_byreminder : Edit reminder by reminder function
+
6) edit_reminder_byreminder: Edit reminder by reminder function
  
  
== Application operations ==
+
=== Application operations ===
  
  
1) ms_handler : MS option handler
+
1) ms_handler: MS option handler
  
2) main : Start program
+
2) main: Start program
  
3) tracker : The main tracker function
+
3) tracker: Main tracker function
  
4) background_handler : The background handler options
+
4) background_handler: Background handler options
  
  
Line 111: Line 112:
 
= Part 1 =
 
= Part 1 =
  
In this article - Part 1 - we would discuss about the '''File Functions''' in detail.
+
This article - Part 1 - discusses the '''File functions''' in detail.
  
  

Revision as of 12:02, 14 August 2008

Featured Article

Contents

Introduction

Do you want to develop location-based applications?

This article is the first in a series approaching all the basics for developing a location-based application for mobile device. The application can be defined as a Geo-Scheduler or a Location scheduler. The simplest rapid mobile application development tool, PyS60, is used to develop the application.

The following modules are used to develop this application:

  • appuifw module
  • audio module
  • e32 module
  • time module
  • os module
  • location module


The extensions mentioned above can be downloaded from the C++ Python Extensions.

Development tools

1) A text editor

(Preferred editor: Python's IDLE - Integrated DeveLopment Environment)

2) Python for S60

(Preferred version: latest release 1.4.4)

3) Python for S60 script shell

(Preferred version: Latest release 1.4.4)

4) Extensions listed above which are not bundled with PyS60


The PyS60 tools can be downloaded from Sourceforge resources.


Basic approach

In this application, localization is done using the network info. The network info can be provided using the location module, cellid. If you are not familiar with retrieving the cellid using Pys60, using the appswitch module, usingthe envy module, read the following articles before proceeding.

How to switch application in foreground

How to use the envy module

How to get info on cell location


Methods and functions

The following methods or functions will be used:

File functions

1) save_location: Save location information into file

2) load_location: Read location information into variables

3) save_reminder: Save reminder information into a file

4) load_reminder: Read reminder information into variables

5) dictionary_copy: Dictionary copy

6) location_list: Return the location names


Feature functions

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


Application operations

1) ms_handler: MS option handler

2) main: Start program

3) tracker: Main tracker function

4) background_handler: Background handler options


Part 1

This article - Part 1 - discusses the File functions in detail.


save_location()

This function would add the location information to the database file.

For this we create a file handler named file_handler. We would use this to handle file operations. Here we are accessing a .dat file which is to be specified by the variable file_handler_location. Assuming that we the location.dat file in C: we assign it to the file_handler_location.

Note: location.dat contains locations added by the save_location() function

file_handler_location = "c:\\location.dat"

The geo and cellids would be populated before running the file functions to NULL.

Note: We need to clear the geo and cellids by using the clear() function so that it doesn't contain any previously used values.

The definition for the save_location() function could be be as follows:

def save_location():
file_handler = file(file_handler_location, "w")
temporary = dictionary_copy(cellids)
 
cellids.clear()
geo.clear()
 
for cell, loc in temporary.items():
file_handler.write(str(cell) + ':' + str(loc) + '\n')
cellids[cell] = loc
geo[loc] = cell
file_handler.close()

dictionary_copy(cellids) is a function defined here.


load_location()

This function would be responsible for loading the locations into variables. Here we would store the value of the cellid into variables.

We use the same file_handler and the fil_handler_location to access the location.dat this time to read the location values.

 file_handler = file(file_handler_location, "r")


Using iterations we load the read the location.dat for locations/values of cellid in this case and load them to variable geo[loc].

geo and cellids variables would be populated before calling the load function.

 cellids = {}
 geo = {}


The definition for the load_location() function could be as follows:

def load_location():
file_handler = file(file_handler_location, "r")
for line in file_handler:
cell, loc = line.split(":")
cell = cell.strip()
loc = loc.strip()
cellids[cell] = loc
geo[loc] = cell
file_handler.close()


save_reminder()

The save_reminder() function adds a new reminder to the file.

The file_handler_reminder is referenced to .dat file which we use to record reminders.

Assuming that reminder.dat is in C: , we assign it to variable file_handler_reminder.

file_handler_reminder = "c:\\reminder.dat"

dictionary_copy(items) is defined here and returns the value of temporary variable which was initialized as NULL in the scope of dictionary_copy(dictionary) function.

The reminder string and the value of the cell are written to the file - reminder.dat

The definition for the save_reminder() function could be as follows:

def save_reminder():
file_handler = file(file_handler_reminder, "w")
i = 0
temporary = dictionary_copy(rems)
rems.clear()
for key, value in temporary.items():
file_handler.write(str(i) + ':' + str(value['cell']) + ':' + str(value['date']) + ':' + value['desc'] + '\n')
rems[str(i)] = {'cell':value['cell'], 'date':value['date'], 'desc':value['desc']}
i += 1
file_handler.close()


load_reminder()

This function would read the reminders in the file_handler_reminder i.e from the reminder.dat file.

We use the file_handler to open the reminder.dat to read value.

The values of the reminder.dat (description)are loaded into variable rems which is a short for reminders.

rems[id] = {'cell':cell, 'date':str(date), 'desc':desc}

Finally the definition for load_reminder() could be as follows:

def load_reminder():
temporary = {}
file_handler = file(file_handler_reminder, "r")
for line in file_handler:
id, cell, date, desc = line.split(":")
id = id.strip()
cell = cell.strip()
date = date.strip()
desc = desc.strip()
rems[id] = {'cell':cell, 'date':str(date), 'desc':desc}
file_handler.close()


dictionary_copy(dictionary)

In the save_location and save_reminder we have used this function which returns the value of temporary variable.

We need to pass a parameter to this function i.e dictionary.

For example in ave_location() function we have used as below


temporary = dictionary_copy(cellids)

The definition of dictionary_copy() could be as below:

def dictionary_copy(dictionary):
temporary = {}
for key, value in dictionary.items():
temporary[key] = value
return temporary


location_list()

location_list() : Return the location names

We do not need to pass a parameter to this function. However we could always pass the variable cellids for its global.

It would be preferred to have it without the parameters.

Like the dictionary_copy(dictionary) this also returns the temporaty variable but from the items of cellids variable.

The definition for the location_list() function could be as follows:

def location_list():
temporary = []
for cell, loc in cellids.items():
temporary.append(unicode(loc))
return temporary


That finishes the file functions (Part 1) for the Geo-scheduler.

We will use these functions to be called when the user would select the action from a custom menu.


Screenshots

Here are some screenshots which demonstrate the menu and how these functions would be used:

(Below screenshots have been filtered to show only screenshots only pertaining to Part 1)


Screenshot0016.jpg Screenshot0017.jpg

Screenshot0021.jpg Screenshot0022.jpg


Go to

159 page views in the last 30 days.
×