59 |
self.field = None |
self.field = None |
60 |
self.fieldType = None |
self.fieldType = None |
61 |
self.groups = [] |
self.groups = [] |
|
self.__sendMessages = False |
|
62 |
|
|
63 |
self.__ToggleMessages(False) |
self.__setLayerLock = False |
64 |
|
|
65 |
self.SetDefaultGroup(ClassGroupDefault()) |
self.SetDefaultGroup(ClassGroupDefault()) |
66 |
|
|
67 |
self.SetLayer(layer) |
self.SetLayer(layer) |
68 |
self.SetField(field) |
self.SetField(field) |
69 |
|
|
|
self.__ToggleMessages(True) |
|
|
|
|
70 |
def __iter__(self): |
def __iter__(self): |
71 |
return ClassIterator(self.groups) |
return ClassIterator(self.groups) |
72 |
|
|
73 |
def __ToggleMessages(self, on): |
def __SendNotification(self): |
74 |
self.__sendMessages = on |
"""Notify the layer that this class has changed.""" |
75 |
|
if self.layer is not None: |
76 |
def __SendMessage(self, message): |
self.layer.ClassChanged() |
|
"""Send the message 'message' to the parent layer.""" |
|
|
if self.__sendMessages and self.layer is not None: |
|
|
self.layer.changed(message, self.layer) |
|
77 |
|
|
78 |
def SetField(self, field = None): |
def SetField(self, field): |
79 |
"""Set the name of the data table field to use. |
"""Set the name of the data table field to use. |
80 |
|
|
81 |
If there is no layer then the field type is set to None, |
If there is no layer then the field type is set to None, |
88 |
if field == "": |
if field == "": |
89 |
field = None |
field = None |
90 |
|
|
|
self.field = field |
|
91 |
|
|
92 |
if self.layer is not None: |
if field is None: |
93 |
fieldType = self.layer.GetFieldType(field) |
if self.layer is not None: |
94 |
|
self.fieldType = None |
95 |
else: |
else: |
96 |
fieldType = None |
if self.layer is not None: |
97 |
|
fieldType = self.layer.GetFieldType(field) |
98 |
|
if fieldType is None: |
99 |
|
raise ValueError("'%s' was not found in the layer's table." |
100 |
|
% self.field) |
101 |
|
|
102 |
|
# |
103 |
|
# unfortunately we cannot call SetFieldType() because it |
104 |
|
# requires the layer to be None |
105 |
|
# |
106 |
|
self.fieldType = fieldType |
107 |
|
#self.SetFieldType(fieldType) |
108 |
|
|
109 |
self.SetFieldType(fieldType) |
self.field = field |
|
|
|
|
# XXX: if fieldType comes back None then field isn't in the table! |
|
110 |
|
|
111 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__SendNotification() |
112 |
|
|
113 |
def GetField(self): |
def GetField(self): |
114 |
"""Return the name of the field.""" |
"""Return the name of the field.""" |
119 |
return self.fieldType |
return self.fieldType |
120 |
|
|
121 |
def SetFieldType(self, type): |
def SetFieldType(self, type): |
122 |
self.fieldType = type |
"""Set the type of the field used by this classification. |
123 |
|
|
124 |
def SetLayer(self, layer): |
A ValueError is raised if the owning layer is not None and |
125 |
"""Set the owning Layer of this classification.""" |
'type' is different from the current field type. |
126 |
|
""" |
127 |
|
|
128 |
|
if type != self.fieldType: |
129 |
|
if self.layer is not None: |
130 |
|
raise ValueError() |
131 |
|
else: |
132 |
|
self.fieldType = type |
133 |
|
self.__SendNotification() |
134 |
|
|
135 |
if __debug__: |
def SetLayer(self, layer): |
136 |
if layer is not None: |
"""Set the owning Layer of this classification. |
137 |
assert(isinstance(layer, Thuban.Model.layer.Layer)) |
|
138 |
|
A ValueError exception will be thrown either the field or |
139 |
|
field type mismatch the information in the layer's table. |
140 |
|
""" |
141 |
|
|
142 |
# prevent infinite recursion when calling SetClassification() |
# prevent infinite recursion when calling SetClassification() |
143 |
if self.layer is not None and layer == self.layer: |
if self.__setLayerLock: return |
|
return |
|
144 |
|
|
145 |
self.layer = layer |
self.__setLayerLock = True |
|
self.SetField(self.GetField()) # XXX: this sync's the fieldType |
|
146 |
|
|
147 |
if self.layer is not None: |
if layer is None: |
148 |
self.layer.SetClassification(self) |
if self.layer is not None: |
149 |
|
l = self.layer |
150 |
|
self.layer = None |
151 |
|
l.SetClassification(None) |
152 |
|
else: |
153 |
|
assert(isinstance(layer, Thuban.Model.layer.Layer)) |
154 |
|
|
155 |
|
old_layer = self.layer |
156 |
|
|
157 |
|
self.layer = layer |
158 |
|
|
159 |
|
try: |
160 |
|
self.SetField(self.GetField()) # this sync's the fieldType |
161 |
|
except ValueError: |
162 |
|
self.layer = old_layer |
163 |
|
self.__setLayerLock = False |
164 |
|
raise ValueError |
165 |
|
else: |
166 |
|
self.layer.SetClassification(self) |
167 |
|
|
168 |
#self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__setLayerLock = False |
169 |
|
|
170 |
def GetLayer(self): |
def GetLayer(self): |
171 |
"""Return the parent layer.""" |
"""Return the parent layer.""" |
197 |
""" |
""" |
198 |
assert(isinstance(fill, Color)) |
assert(isinstance(fill, Color)) |
199 |
self.GetDefaultGroup().GetProperties().SetFill(fill) |
self.GetDefaultGroup().GetProperties().SetFill(fill) |
200 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__SendNotification() |
201 |
|
|
202 |
def GetDefaultFill(self): |
def GetDefaultFill(self): |
203 |
"""Return the default fill color.""" |
"""Return the default fill color.""" |
210 |
""" |
""" |
211 |
assert(isinstance(color, Color)) |
assert(isinstance(color, Color)) |
212 |
self.GetDefaultGroup().GetProperties().SetLineColor(color) |
self.GetDefaultGroup().GetProperties().SetLineColor(color) |
213 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__SendNotification() |
214 |
|
|
215 |
def GetDefaultLineColor(self): |
def GetDefaultLineColor(self): |
216 |
"""Return the default line color.""" |
"""Return the default line color.""" |
223 |
""" |
""" |
224 |
assert(isinstance(lineWidth, IntType)) |
assert(isinstance(lineWidth, IntType)) |
225 |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
226 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__SendNotification() |
227 |
|
|
228 |
def GetDefaultLineWidth(self): |
def GetDefaultLineWidth(self): |
229 |
"""Return the default line width.""" |
"""Return the default line width.""" |
239 |
|
|
240 |
if len(self.groups) > 0 and isinstance(item, ClassGroupDefault): |
if len(self.groups) > 0 and isinstance(item, ClassGroupDefault): |
241 |
self.groups[0] = item |
self.groups[0] = item |
|
#self.SetDefaultGroup(item) |
|
242 |
else: |
else: |
243 |
self.groups.append(item) |
self.groups.append(item) |
244 |
|
|
245 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__SendNotification() |
246 |
|
|
247 |
def GetGroup(self, value): |
def GetGroup(self, value): |
248 |
"""Return the associated group, or the default group. |
"""Return the associated group, or the default group. |
476 |
assert(isinstance(label, StringType)) |
assert(isinstance(label, StringType)) |
477 |
self.label = label |
self.label = label |
478 |
|
|
479 |
|
def GetDisplayText(self): |
480 |
|
assert(False, "GetDisplay must be overridden by subclass!") |
481 |
|
return "" |
482 |
|
|
483 |
def Matches(self, value): |
def Matches(self, value): |
484 |
"""Determines if this Group is associated with the given value. |
"""Determines if this Group is associated with the given value. |
485 |
|
|
486 |
Returns False. This needs to be overridden by all subclasses. |
Returns False. This needs to be overridden by all subclasses. |
487 |
""" |
""" |
488 |
|
assert(False, "GetMatches must be overridden by subclass!") |
489 |
return False |
return False |
490 |
|
|
491 |
def GetProperties(self): |
def GetProperties(self): |
493 |
|
|
494 |
Returns None. This needs to be overridden by all subclasses. |
Returns None. This needs to be overridden by all subclasses. |
495 |
""" |
""" |
496 |
|
assert(False, "GetProperties must be overridden by subclass!") |
497 |
return None |
return None |
498 |
|
|
499 |
|
|
559 |
assert(isinstance(prop, ClassGroupProperties)) |
assert(isinstance(prop, ClassGroupProperties)) |
560 |
self.prop = prop |
self.prop = prop |
561 |
|
|
562 |
|
def GetDisplayText(self): |
563 |
|
label = self.GetLabel() |
564 |
|
|
565 |
|
if label != "": return label |
566 |
|
|
567 |
|
return str(self.GetValue()) |
568 |
|
|
569 |
def __eq__(self, other): |
def __eq__(self, other): |
570 |
return isinstance(other, ClassGroupSingleton) \ |
return isinstance(other, ClassGroupSingleton) \ |
571 |
and self.GetProperties() == other.GetProperties() \ |
and self.GetProperties() == other.GetProperties() \ |
616 |
assert(isinstance(prop, ClassGroupProperties)) |
assert(isinstance(prop, ClassGroupProperties)) |
617 |
self.prop = prop |
self.prop = prop |
618 |
|
|
619 |
|
def GetDisplayText(self): |
620 |
|
label = self.GetLabel() |
621 |
|
|
622 |
|
if label != "": return label |
623 |
|
|
624 |
|
return "DEFAULT" |
625 |
|
|
626 |
def __eq__(self, other): |
def __eq__(self, other): |
627 |
return isinstance(other, ClassGroupDefault) \ |
return isinstance(other, ClassGroupDefault) \ |
628 |
and self.GetProperties() == other.GetProperties() |
and self.GetProperties() == other.GetProperties() |
735 |
assert(isinstance(prop, ClassGroupProperties)) |
assert(isinstance(prop, ClassGroupProperties)) |
736 |
self.prop = prop |
self.prop = prop |
737 |
|
|
738 |
|
def GetDisplayText(self): |
739 |
|
label = self.GetLabel() |
740 |
|
|
741 |
|
if label != "": return label |
742 |
|
|
743 |
|
return _("%s - %s") % (self.GetMin(), self.GetMax()) |
744 |
|
|
745 |
def __eq__(self, other): |
def __eq__(self, other): |
746 |
return isinstance(other, ClassGroupRange) \ |
return isinstance(other, ClassGroupRange) \ |
747 |
and self.GetProperties() == other.GetProperties() \ |
and self.GetProperties() == other.GetProperties() \ |
773 |
def GetPropertiesFromValue(self, value): |
def GetPropertiesFromValue(self, value): |
774 |
pass |
pass |
775 |
|
|
776 |
|
def GetDisplayText(self): |
777 |
|
return "Map: " + self.map_type |
778 |
|
|
779 |
# |
# |
780 |
# built-in mappings |
# built-in mappings |
781 |
# |
# |