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

Source Code for Module gen.lib.markertype

 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  # $Id: markertype.py 10103 2008-02-24 13:55:55Z acraphae $ 
21   
22  """ 
23  Marker types. 
24  """ 
25   
26  #------------------------------------------------------------------------- 
27  # 
28  # Python modules 
29  # 
30  #------------------------------------------------------------------------- 
31  from gettext import gettext as _ 
32   
33  #------------------------------------------------------------------------- 
34  # 
35  # GRAMPS modules 
36  # 
37  #------------------------------------------------------------------------- 
38  from gen.lib.grampstype import GrampsType, init_map 
39   
40 -class MarkerType(GrampsType):
41 """ 42 Class for handling data markers. 43 """ 44 45 NONE = -1 46 CUSTOM = 0 47 COMPLETE = 1 48 TODO_TYPE = 2 49 50 _CUSTOM = CUSTOM 51 _DEFAULT = NONE 52 53 _DATAMAP = [ 54 (NONE, "", ""), 55 (CUSTOM, _("Custom"), "Custom"), 56 (COMPLETE, _("Complete"), "Complete"), 57 (TODO_TYPE, _("ToDo"), "ToDo"), 58 ] 59 60 _I2SMAP = init_map(_DATAMAP, 0, 1) 61 _S2IMAP = init_map(_DATAMAP, 1, 0) 62 _I2EMAP = init_map(_DATAMAP, 0, 2) 63 _E2IMAP = init_map(_DATAMAP, 2, 0) 64
65 - def __init__(self, value=None):
66 GrampsType.__init__(self, value)
67
68 - def set(self, value):
69 """ 70 Set the marker value. 71 """ 72 if isinstance(value, self.__class__): 73 if value.val == self.CUSTOM and value.string == u'': 74 self.val = self.NONE 75 self.string = u'' 76 else: 77 self.val = value.val 78 self.string = value.string 79 elif type(value) == tuple: 80 if value[0] == self.CUSTOM and value[1] == u'': 81 self.value = self.NONE 82 self.string = u'' 83 else: 84 self.val = value[0] 85 self.string = value[1] 86 elif type(value) == int: 87 self.val = value 88 self.string = u'' 89 elif type(value) == str: 90 self.val = self._S2IMAP.get(value, self._CUSTOM) 91 if self.val == self._CUSTOM: 92 self.string = value 93 else: 94 self.string = u'' 95 else: 96 self.val = self._DEFAULT 97 self.string = u''
98