blob: d053068ba1756c0d2d1cb3a46522de04c499f639 (
plain) (
tree)
|
|
# -*- coding: utf-8 -*-
# date: 23 Mai 2009
class Priority:
def __init__(self, name, id, color=None):
self.name = name.__str__()
self.id = id
if color is not None:
self.color = color
else:
self.color = id
def getId(self):
return self.id
def getName(self):
return self.name
def getColor(self):
return self.color
def __str__(self):
return self.getName()
class Priorities:
__shared_state = {}
priorities = {}
prioritiesMap = {}
def __init__(self):
self.__dict__ = self.__shared_state
if len(self.priorities) == 0:
self.__add__(Priority('Low', -100))
self.__add__(Priority('Normal', 0))
self.__add__(Priority('High', 100))
def __getitem__(self, id):
return self.priorities[id]
def __setitem__(self, id, priority):
self.priorities[id] = priority
self.prioritiesMap[priority.getName()] = priority
def __delitem__(self, id):
priority = prioritie[key]
del(self.priorities[key])
del(self.prioritiesMap[priority.getName()])
def remove(self, priority):
del(self.priorities[key])
del(self.prioritiesMap[priority.getName()])
def __contians__(self, priority):
return (priority in self.priorities)
def append(self, priority):
self.__setitem__(priority.getId(), priority)
def __add__(self, priority):
self.__setitem__(priority.getId(), priority)
return self
def __iter__(self):
return self.priorities.__iter__()
def getPriority(self, id=None, name=None):
try:
if id is not None:
return self[id]
if name is not None:
return self.prioritiesMap[name]
except(KeyError):
if name is None:
name = id
if id is None:
id = name
priority = Priority(id, name)
self.__add__(priority)
return priority
return None
|