Tuesday, May 13, 2008

Beginning to Code

I started to code as well. I've been writing a LoCalTools.py file and a LoCalObjects.py file.

The first file contains random functions that could be useful for us. For example, so far there is a function to check for the existence of an AP, a function to returns all APs in the area, and a function calculating the meter distance between two GPS coords.

The second file contains all the LoCal objects for the phone. Everything inherits from a LoCalObject class. This class just has an id. I'm thinking we could also have each of these objects inherit from LoCalXMLObject as well. Python supports multiple inheritance. The base XML class can provide base toXML() and fromXML() methods and base XML tag attributes (i.e. tagname, attributes). If set up properly, we should only have to write one toXML function and have sub classes set a few attributes to handle their own type. For example:



class BaseXML:
def __init__ (self):
self.tagname = 'NoName'
self.attr = []
self.children = []
def toXML (self):
val = '<'+self.tagName+' '
for i in self.attr:
val = val + i['name'] + '=\'' +\
str(i['val']) + '\' '
val = val + '>'
for c in self.children:
val = val + c.toXML()
val = val + ''
return val

class MyTag (BaseXML):
def __init__ (self):
self.tagname = 'MyTag'
self.attr.append({'name':'counter','val':0})


The above code is just an example. There are probably some typos. When we find a nice central location to put files, I'll link it. Goodnight.

Powered By Blogger