Package gen :: Package lib :: Module addressbase
[frames] | no frames]

Source Code for Module gen.lib.addressbase

  1  # 
  2  # Gramps - a GTK+/GNOME based genealogy program 
  3  # 
  4  # Copyright (C) 2000-2006  Donald N. Allingham 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the Free Software 
 18  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 19  # 
 20   
 21  # $Id: addressbase.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  AddressBase class for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # GRAMPS modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  from gen.lib.address import Address 
 33   
 34  #------------------------------------------------------------------------- 
 35  # 
 36  # AddressBase classes 
 37  # 
 38  #------------------------------------------------------------------------- 
39 -class AddressBase:
40 """ 41 Base class for address-aware objects. 42 """ 43
44 - def __init__(self, source=None):
45 """ 46 Initialize a AddressBase. 47 48 If the source is not None, then object is initialized from values of 49 the source object. 50 51 @param source: Object used to initialize the new object 52 @type source: AddressBase 53 """ 54 if source: 55 self.address_list = [ Address(address) \ 56 for address in source.address_list ] 57 else: 58 self.address_list = []
59
60 - def serialize(self):
61 """ 62 Convert the object to a serialized tuple of data. 63 """ 64 return [addr.serialize() for addr in self.address_list]
65
66 - def unserialize(self, data):
67 """ 68 Convert a serialized tuple of data to an object. 69 """ 70 self.address_list = [Address().unserialize(item) for item in data]
71
72 - def add_address(self, address):
73 """ 74 Add the L{Address} instance to the object's list of addresses. 75 76 @param address: L{Address} instance to add to the object's address list 77 @type address: list 78 """ 79 self.address_list.append(address)
80
81 - def remove_address(self, address):
82 """ 83 Remove the specified L{Address} instance from the address list. 84 85 If the instance does not exist in the list, the operation has 86 no effect. 87 88 @param address: L{Address} instance to remove from the list 89 @type address: L{Address} 90 91 @return: True if the address was removed, False if it was not in the list. 92 @rtype: bool 93 """ 94 if address in self.address_list: 95 self.address_list.remove(address) 96 return True 97 else: 98 return False
99
100 - def get_address_list(self):
101 """ 102 Return the list of L{Address} instances associated with the object. 103 104 @return: Returns the list of L{Address} instances 105 @rtype: list 106 """ 107 return self.address_list
108
109 - def set_address_list(self, address_list):
110 """ 111 Assign the passed list to the object's list of L{Address} instances. 112 113 @param address_list: List of L{Address} instances to be associated 114 with the object 115 @type address_list: list 116 """ 117 self.address_list = address_list
118