×
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
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix ArticleMetaData and RevieweApproval)
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{FeaturedArticle}}
+
{{ArticleMetaData <!-- v1.1 -->
[[Category:S60]][[Category:Location Based Services]][[Category:Python]][[Category:Code_Examples]]
+
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|id= <!-- Article Id (Knowledge base articles only) -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20080711
 +
|author= [[User:Croozeus]]
 +
}}
 +
[[Category:Location]][[Category:PySymbian]]
  
== Introduction ==
+
{{FeaturedArticle|timestamp=20080810}}
  
 +
 +
== Introduction ==
  
 
Do you want to develop location-based applications?  
 
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.
+
This article is the first in a series approaching all the basics for developing a location-based application for mobile devices. The application can be defined as a Geo-Scheduler or a Location scheduler. The simplest rapid mobile application development tool, [[:Category:PySymbian|PySymbian]], is used to develop the application.
  
The following modules are used to develop this application:
+
The following modules are used when developing this application:
  
 
*appuifw module
 
*appuifw module
Line 15: Line 39:
 
*audio module
 
*audio module
  
*[http://ssalmine.googlepages.com/somepys60extensions appswitch module (extension)]
+
*[http://sites.google.com/site/ssalmine2/somepys60extensions appswitch module (extension)]
  
 
*e32 module
 
*e32 module
Line 25: Line 49:
 
*location module
 
*location module
  
*[http://discussion.forum.nokia.com/forum/showthread.php?t=122897&highlight=envy envy module (extension)]
+
*[http://www.developer.nokia.com/Community/Discussion/showthread.php?122897-announce-envy-1.0.4-3rd-unsigned-Make-your-application-invisible-!&highlight=envy envy module (extension)]
  
  
The extensions mentioned above can be downloaded from the [[C++ Python Extensions]].
+
The extensions listed above can be downloaded from the [[PySymbian C++ Extensions]].
  
 
== Development tools ==
 
== Development tools ==
Line 36: Line 60:
 
(Preferred editor: Python's IDLE - Integrated DeveLopment Environment)
 
(Preferred editor: Python's IDLE - Integrated DeveLopment Environment)
  
2) Python for S60
+
2) PySymbian
  
 
(Preferred version: latest release 1.4.4)
 
(Preferred version: latest release 1.4.4)
  
3) Python for S60 script shell  
+
3) PySymbian script shell  
  
 
(Preferred version: Latest release 1.4.4)
 
(Preferred version: Latest release 1.4.4)
Line 47: Line 71:
  
  
The PyS60 tools can be downloaded from [http://sourceforge.net/projects/pys60 Sourceforge resources].
+
The PySymbian tools can be downloaded from [http://sourceforge.net/projects/pys60/ Sourceforge resources].
  
  
 
== Basic approach ==
 
== 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.  
+
In this application, localization is done using the network information. The network information can be provided using the location module, ''cellid''. If you are not familiar with retrieving the cellid using Pys60, using the appswitch module, or using the envy module, read the following articles before you proceed.  
  
 
[[How to switch application in foreground]]
 
[[How to switch application in foreground]]
  
[[How to use the envy module]]
+
[[How to use the PySymbian Envy module]]
  
 
[[How to get info on cell location]]
 
[[How to get info on cell location]]
Line 63: Line 87:
 
==Methods and functions==
 
==Methods and functions==
  
The following methods or functions will be used:
+
The following methods or functions are used:
  
 
===File functions ===
 
===File functions ===
  
1) save_location: Save location information into file
+
1) <tt>save_location</tt>: Save location information into file
  
2) load_location: Read location information into variables
+
2) <tt>load_location</tt>: Read location information into variables
  
3) save_reminder: Save reminder information into a file
+
3) <tt>save_reminder</tt>: Save reminder information into a file
  
4) load_reminder: Read reminder information into variables
+
4) <tt>load_reminder</tt>: Read reminder information into variables
  
5) dictionary_copy: Dictionary copy
+
5) <tt>dictionary_copy</tt>: Dictionary copy
  
6) location_list: Return the location names
+
6) <tt>location_list</tt>: Return the location names
  
  
Line 84: Line 108:
  
  
1) add_location: Add a new location
+
1) <tt>add_location</tt>: Add a new location
  
2) edit_location: Edit a location
+
2) <tt>edit_location</tt>: Edit a location
  
3) add_reminder: Add a new reminder
+
3) <tt>add_reminder</tt>: Add a new reminder
  
4) edit_reminder: Editing screen function
+
4) <tt>edit_reminder</tt>: Editing screen function
  
5) edit_reminder_bylocation: Edit reminder by location function
+
5) <tt>edit_reminder_bylocation</tt>: Edit reminder by location function
  
6) edit_reminder_byreminder: Edit reminder by reminder function
+
6) <tt>edit_reminder_byreminder</tt>: Edit reminder by reminder function
  
  
Line 100: Line 124:
  
  
1) ms_handler: MS option handler
+
1) <tt>ms_handler</tt>: MS option handler
  
2) main: Start program
+
2) <tt>main</tt>: Start program
  
3) tracker: Main tracker function
+
3) <tt>tracker</tt>: Main tracker function
  
4) background_handler: Background handler options
+
4) <tt>background_handler</tt>: Background handler options
  
  
Line 118: Line 142:
  
  
This function adds the location information to the database file.
+
This function adds the location information to the database file. A file handler named <tt>file_handler</tt> is created to handle file operations. A .dat file specified by the variable <tt>file_handler_location</tt> is accessed here. In this example, the  <tt>location.dat</tt> file is in C:, and it is assigned to the <tt>file_handler_location</tt>.
  
A file handler named file_handler is created to handle file operations. A .dat file specified by the variable file_handler_location is accessed here. In this example, the  location.dat file is in C:, and it is assigned to the file_handler_location.
+
'''Note:''' <tt>location.dat</tt> contains locations added by the <tt>save_location()</tt> function.
 
+
'''Note:''' location.dat contains locations added by the save_location() function.
+
  
 
<code python>
 
<code python>
Line 130: Line 152:
 
The geo and cellids are populated before running the file functions to NULL.
 
The geo and cellids are populated before running the file functions to NULL.
  
'''Note:''' The geo and cellids must be cleared by using the clear() function so that they do not contain any previously used values.
+
'''Note:''' The geo and cellids must be cleared by using the <tt>clear()</tt> function so that they do not contain any previously used values.
  
The definition for the save_location() function is as follows:
+
The definition for the <tt>save_location()</tt> function is as follows:
  
 
<code python>
 
<code python>
Line 149: Line 171:
 
</code>
 
</code>
  
The function dictionary_copy(cellids) is defined [http://wiki.forum.nokia.com/index.php/How_to_develop_a_Geo-scheduler_application_-_Part_1#dictionary_copy.28dictionary.29 here].
+
The function <tt>dictionary_copy(cellids)</tt> is defined [[How to develop a Geo-scheduler application - Part 1#dictionary copy.28dictionary.29|here]].
  
  
Line 158: Line 180:
 
This function is responsible for loading the locations into variables. Here the value of the cellid is stored into variables.
 
This function is responsible for loading the locations into variables. Here the value of the cellid is stored into variables.
  
The same file_handler and the fil_handler_location are used to access the location.dat this time to read the location values.
+
The same <tt>file_handler</tt> and the <tt>file_handler_location</tt> are used to access the <tt>location.dat</tt> this time to read the location values.
  
 
<code python> file_handler = file(file_handler_location, "r")</code>
 
<code python> file_handler = file(file_handler_location, "r")</code>
  
  
Using iterations, the location.dat is read for locations/values of cellid. The values are loaded to variable geo[loc].
+
Using iterations, <tt>location.dat</tt> is read for locations/values of cellid. The values are loaded to variable geo[loc].
  
 
geo and cellids variables are populated before calling the load function.
 
geo and cellids variables are populated before calling the load function.
Line 171: Line 193:
  
  
The definition for the load_location() function is as follows:
+
The definition for the <tt>load_location()</tt> function is as follows:
  
 
<code python>
 
<code python>
Line 189: Line 211:
 
== save_reminder() ==
 
== save_reminder() ==
  
The save_reminder() function adds a new reminder to the file.
+
The <tt>save_reminder()</tt> function adds a new reminder to the file.
  
The file_handler_reminder is referenced to the .dat file which used to record reminders.
+
The <tt>file_handler_reminder</tt> is referenced in the .dat file used to record reminders.
  
In the following example, the reminder.dat file is in C:, and it is assigned to the variable file_handler_reminder.
+
In the following example, the <tt>reminder.dat</tt> file is in C:, and it is assigned to the variable <tt>file_handler_reminder</tt>.
  
 
<code python>file_handler_reminder = "c:\\reminder.dat"</code>
 
<code python>file_handler_reminder = "c:\\reminder.dat"</code>
  
dictionary_copy(items) is defined [http://wiki.forum.nokia.com/index.php/How_to_develop_a_Geo-scheduler_application_-_Part_1#dictionary_copy.28dictionary.29 here]. It returns the value of the temporary variable which was initialized as NULL in the scope of the dictionary_copy(dictionary) function.
+
<tt>dictionary_copy(items)</tt> is defined [[How to develop a Geo-scheduler application - Part 1#dictionary copy.28dictionary.29|here]]. It returns the value of the temporary variable which was initialized as NULL in the scope of the <tt>dictionary_copy(dictionary)</tt> function.
  
The reminder string and the value of the cell are written to the file reminder.dat.
+
The reminder string and the value of the cell are written to the file <tt>reminder.dat</tt>.
  
The definition for the save_reminder() function is as follows:
+
The definition for the <tt>save_reminder()</tt> function is as follows:
  
 
<code python>
 
<code python>
 
def save_reminder():
 
def save_reminder():
 
     file_handler = file(file_handler_reminder, "w")
 
     file_handler = file(file_handler_reminder, "w")
    i = 0
 
 
     temporary = dictionary_copy(rems)
 
     temporary = dictionary_copy(rems)
 
     rems.clear()
 
     rems.clear()
     for key, value in temporary.items():
+
     for i, value in enumerate(temporary.values()):
 
         file_handler.write(str(i) + ':' + str(value['cell']) + ':' + str(value['date']) + ':' + value['desc'] + '\n')
 
         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']}
 
         rems[str(i)] = {'cell':value['cell'], 'date':value['date'], 'desc':value['desc']}
        i += 1
 
 
     file_handler.close()</code>
 
     file_handler.close()</code>
  
Line 219: Line 239:
 
   
 
   
  
This function reads the reminders in the file_handler_reminder, that is, from the reminder.dat file.
+
This function reads the reminders in the <tt>file_handler_reminder</tt>, that is, from the <tt>reminder.dat</tt> file.
  
file_handler is used to open the reminder.dat to read values.
+
<tt>file_handler</tt> is used to open the <tt>reminder.dat</tt> to read values.
  
The values of the reminder.dat (description) are loaded into the variable rems (reminders).
+
The values of the </tt>reminder.dat<tt> (description) are loaded into the variable <tt>rems</tt> (reminders).
  
 
<code python>
 
<code python>
Line 229: Line 249:
 
</code>
 
</code>
  
Finally, the definition for load_reminder() is as follows:
+
Finally, the definition for <tt>load_reminder()</tt> is as follows:
  
 
<code python>
 
<code python>
Line 248: Line 268:
 
== dictionary_copy(dictionary) ==
 
== dictionary_copy(dictionary) ==
  
In the save_location and save_reminder, the function returns the value of the temporary variable.
+
In <tt>save_location</tt> and <tt>save_reminder</tt>, the function returns the value of the temporary variable.
  
 
A parameter must be passed to the dictionary function.
 
A parameter must be passed to the dictionary function.
  
For example, in the ave_location() function it is used as follows:
+
For example, in the <tt>ave_location()</tt> function it is used as follows:
  
  
Line 258: Line 278:
 
temporary = dictionary_copy(cellids)</code>
 
temporary = dictionary_copy(cellids)</code>
  
The definition of dictionary_copy() is:
+
The definition of <tt>dictionary_copy()</tt> is:
  
 
<code python>
 
<code python>
 
def dictionary_copy(dictionary):
 
def dictionary_copy(dictionary):
     temporary = {}
+
     return dict(dictionary)
    for key, value in dictionary.items():
+
        temporary[key] = value
+
    return temporary
+
 
</code>
 
</code>
  
Line 271: Line 288:
 
== location_list() ==
 
== location_list() ==
  
location_list(): Return the location names
+
<tt>location_list()</tt>: 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.
+
There is no need to pass a parameter to this function. However, the variable <tt>cellids</tt> can always be passed for its global. However, the preferred way is to have it without the parameters.
  
It would be preferred to have it without the parameters.
+
In the same way as the function <tt>dictionary_copy(dictionary)</tt>, this also returns the temporary variable, but from the items of the <tt>cellids</tt> variable.
  
Like the dictionary_copy(dictionary) this also returns the temporaty variable but from the items of ''cellids'' variable.
+
The definition for the <tt>location_list()</tt> function is:
 
+
The definition for the location_list() function could be as follows:
+
  
 
<code python>
 
<code python>
  
 
def location_list():
 
def location_list():
     temporary = []
+
     return [unicode(loc) for loc in cellids.values()]
    for cell, loc in cellids.items():
+
        temporary.append(unicode(loc))
+
    return temporary
+
 
</code>
 
</code>
  
Line 293: Line 305:
 
That finishes the file functions (Part 1) for the Geo-scheduler.  
 
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.
+
These functions are called when the user selects an action from a custom menu.
  
  
 
= Screenshots =
 
= Screenshots =
  
Here are some screenshots which demonstrate the menu and how these functions would be used:
+
These screenshots demonstrate the menu and how these functions are be used. The screenshots are relevant only to Part 1.
 
+
(Below screenshots have been filtered to show only screenshots only pertaining to Part 1)
+
  
  
[[Image:Screenshot0016.jpg]]        [[Image:Screenshot0017.jpg]]
+
[[File:Screenshot0016.jpg]]        [[File:Screenshot0017.jpg]]
  
[[Image:Screenshot0021.jpg]]        [[Image:Screenshot0022.jpg]]
+
[[File:Screenshot0021.jpg]]        [[File:Screenshot0022.jpg]]
  
  
  
=Go to=
+
=See also=
  
  
* [[How do develop a Geo-scheduler application - Part 2]]
+
* [[How to develop a Geo-scheduler application - Part 2]]
* [[How do develop a Geo-scheduler application - Part 3]]
+
* [[How to develop a Geo-scheduler application - Part 3]]
* [[PyS60]]
+
* [[:Category:PySymbian|PySymbian]][[Category:S60]]
 +
[[Category:Code Snippet]]

Revision as of 06:19, 8 February 2012

Article Metadata
Article
Created: croozeus (11 Jul 2008)
Last edited: hamishwillee (08 Feb 2012)
{{{width}}}
10 Aug
2008


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 devices. The application can be defined as a Geo-Scheduler or a Location scheduler. The simplest rapid mobile application development tool, PySymbian, is used to develop the application.

The following modules are used when developing this application:

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


The extensions listed above can be downloaded from the PySymbian C++ Extensions.

Development tools

1) A text editor

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

2) PySymbian

(Preferred version: latest release 1.4.4)

3) PySymbian script shell

(Preferred version: Latest release 1.4.4)

4) Extensions listed above which are not bundled with PyS60


The PySymbian tools can be downloaded from Sourceforge resources.


Basic approach

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

How to switch application in foreground

How to use the PySymbian Envy module

How to get info on cell location


Methods and functions

The following methods or functions are 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 adds the location information to the database file. A file handler named file_handler is created to handle file operations. A .dat file specified by the variable file_handler_location is accessed here. In this example, the location.dat file is in C:, and it is assigned 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 are populated before running the file functions to NULL.

Note: The geo and cellids must be cleared by using the clear() function so that they do not contain any previously used values.

The definition for the save_location() function is 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()

The function dictionary_copy(cellids) is defined here.


load_location()

This function is responsible for loading the locations into variables. Here the value of the cellid is stored into variables.

The same file_handler and the file_handler_location are used to access the location.dat this time to read the location values.

 file_handler = file(file_handler_location, "r")


Using iterations, location.dat is read for locations/values of cellid. The values are loaded to variable geo[loc].

geo and cellids variables are populated before calling the load function.

 cellids = {}
 geo = {}


The definition for the load_location() function is 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 in the .dat file used to record reminders.

In the following example, the reminder.dat file is in C:, and it is assigned to the variable file_handler_reminder.

file_handler_reminder = "c:\\reminder.dat"

dictionary_copy(items) is defined here. It returns the value of the temporary variable which was initialized as NULL in the scope of the 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 is as follows:

def save_reminder():
file_handler = file(file_handler_reminder, "w")
temporary = dictionary_copy(rems)
rems.clear()
for i, value in enumerate(temporary.values()):
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']}
file_handler.close()


load_reminder()

This function reads the reminders in the file_handler_reminder, that is, from the reminder.dat file.

file_handler is used to open the reminder.dat to read values.

The values of the </tt>reminder.dat (description) are loaded into the variable <tt>rems (reminders).

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

Finally, the definition for load_reminder() is 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 save_location and save_reminder, the function returns the value of the temporary variable.

A parameter must be passed to the dictionary function.

For example, in the ave_location() function it is used as follows:


temporary = dictionary_copy(cellids)

The definition of dictionary_copy() is:

def dictionary_copy(dictionary):
return dict(dictionary)


location_list()

location_list(): Return the location names

There is no need to pass a parameter to this function. However, the variable cellids can always be passed for its global. However, the preferred way is to have it without the parameters.

In the same way as the function dictionary_copy(dictionary), this also returns the temporary variable, but from the items of the cellids variable.

The definition for the location_list() function is:

def location_list():
return [unicode(loc) for loc in cellids.values()]


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

These functions are called when the user selects an action from a custom menu.


Screenshots

These screenshots demonstrate the menu and how these functions are be used. The screenshots are relevant only to Part 1.


Screenshot0016.jpg Screenshot0017.jpg

Screenshot0021.jpg Screenshot0022.jpg


See also

138 page views in the last 30 days.