16 |
If no mapping can be found then default data will |
If no mapping can be found then default data will |
17 |
be returned. Input values must be hashable objects |
be returned. Input values must be hashable objects |
18 |
|
|
19 |
See the description of GetGroup() for more information |
See the description of FindGroup() for more information |
20 |
on the mapping algorithm. |
on the mapping algorithm. |
21 |
""" |
""" |
22 |
|
|
23 |
# fix for people using python2.1 |
# fix for people using python2.1 |
24 |
from __future__ import nested_scopes |
from __future__ import nested_scopes |
25 |
|
|
26 |
|
import copy |
27 |
|
|
28 |
|
from Thuban import _ |
29 |
|
|
30 |
from types import * |
from types import * |
31 |
|
|
32 |
from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \ |
from messages import \ |
33 |
LAYER_VISIBILITY_CHANGED |
LAYER_PROJECTION_CHANGED, \ |
34 |
|
LAYER_LEGEND_CHANGED, \ |
35 |
|
LAYER_VISIBILITY_CHANGED |
36 |
|
|
|
from Thuban import _ |
|
37 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
38 |
|
|
39 |
import Thuban.Model.layer |
import Thuban.Model.layer |
40 |
|
|
|
|
|
|
# constants |
|
|
RANGE_MIN = 0 |
|
|
RANGE_MAX = 1 |
|
|
RANGE_DATA = 2 |
|
|
|
|
41 |
class Classification: |
class Classification: |
42 |
"""Encapsulates the classification of layer. The Classification |
"""Encapsulates the classification of layer. |
43 |
divides some kind of data into Groups which are associated with |
|
44 |
properties. Later the properties can be retrieved by matching |
The Classification divides some kind of data into Groups which |
45 |
data values to the appropriate group.""" |
are associated with properties. Later the properties can be |
46 |
|
retrieved by matching data values to the appropriate group. |
47 |
|
""" |
48 |
|
|
49 |
def __init__(self, layer = None, field = None): |
def __init__(self, layer = None, field = None): |
50 |
"""Initialize a classification. |
"""Initialize a classification. |
51 |
|
|
52 |
layer -- the Layer object who owns this classification |
layer -- the Layer object who owns this classification |
53 |
|
|
54 |
field -- the name of the data table field that |
field -- the name of the data table field that |
55 |
is to be used to classify layer properties |
is to be used to classify layer properties |
56 |
""" |
""" |
57 |
|
|
58 |
self.layer = None |
self.layer = None |
59 |
self.field = None |
self.field = None |
60 |
self.fieldType = None |
self.fieldType = None |
61 |
self.groups = [] |
self.__groups = [] |
62 |
self.__sendMessages = False |
|
63 |
|
self.__setLayerLock = False |
64 |
|
|
|
self.__ToggleMessages(False) |
|
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 __deepcopy__(self, memo): |
74 |
|
clazz = Classification() |
75 |
|
|
76 |
|
clazz.__groups[0] = copy.deepcopy(self.__groups[0]) |
77 |
|
|
78 |
|
for i in range(1, len(self.__groups)): |
79 |
|
clazz.__groups.append(copy.deepcopy(self.__groups[i])) |
80 |
|
|
81 |
def __ToggleMessages(self, on): |
print "Classification.__deepcopy__" |
82 |
self.__sendMessages = on |
return clazz |
83 |
|
|
84 |
def __SendMessage(self, message): |
def __SendNotification(self): |
85 |
"""Send the message 'message' to the parent layer.""" |
"""Notify the layer that this class has changed.""" |
86 |
if self.__sendMessages and self.layer is not None: |
if self.layer is not None: |
87 |
self.layer.changed(message, self.layer) |
self.layer.ClassChanged() |
88 |
|
|
89 |
def SetField(self, field = None): |
def SetField(self, field): |
90 |
"""Set the name of the data table field to use. |
"""Set the name of the data table field to use. |
91 |
|
|
92 |
field -- if None then all values map to the default data |
If there is no layer then the field type is set to None, |
93 |
|
otherwise the layer is queried to find the type of the |
94 |
|
field data |
95 |
|
|
96 |
|
field -- if None then all values map to the default data |
97 |
""" |
""" |
98 |
|
|
99 |
if field == "": |
if field == "": |
100 |
field = None |
field = None |
101 |
|
|
|
self.field = field |
|
102 |
|
|
103 |
if self.layer is not None: |
if field is None: |
104 |
fieldType = self.layer.GetFieldType(field) |
if self.layer is not None: |
105 |
|
self.fieldType = None |
106 |
else: |
else: |
107 |
fieldType = None |
if self.layer is not None: |
108 |
|
fieldType = self.layer.GetFieldType(field) |
109 |
|
if fieldType is None: |
110 |
|
raise ValueError("'%s' was not found in the layer's table." |
111 |
|
% self.field) |
112 |
|
|
113 |
|
# |
114 |
|
# unfortunately we cannot call SetFieldType() because it |
115 |
|
# requires the layer to be None |
116 |
|
# |
117 |
|
self.fieldType = fieldType |
118 |
|
#self.SetFieldType(fieldType) |
119 |
|
|
120 |
self.SetFieldType(fieldType) |
self.field = field |
|
|
|
|
# XXX: if fieldType comes back None then field isn't in the table! |
|
121 |
|
|
122 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__SendNotification() |
123 |
|
|
124 |
def GetField(self): |
def GetField(self): |
125 |
"""Return the name of the field.""" |
"""Return the name of the field.""" |
130 |
return self.fieldType |
return self.fieldType |
131 |
|
|
132 |
def SetFieldType(self, type): |
def SetFieldType(self, type): |
133 |
self.fieldType = type |
"""Set the type of the field used by this classification. |
134 |
|
|
135 |
|
A ValueError is raised if the owning layer is not None and |
136 |
|
'type' is different from the current field type. |
137 |
|
""" |
138 |
|
|
139 |
|
if type != self.fieldType: |
140 |
|
if self.layer is not None: |
141 |
|
raise ValueError() |
142 |
|
else: |
143 |
|
self.fieldType = type |
144 |
|
self.__SendNotification() |
145 |
|
|
146 |
def SetLayer(self, layer): |
def SetLayer(self, layer): |
147 |
"""Set the owning Layer of this classification.""" |
"""Set the owning Layer of this classification. |
148 |
|
|
149 |
|
A ValueError exception will be thrown either the field or |
150 |
|
field type mismatch the information in the layer's table. |
151 |
|
""" |
152 |
|
|
153 |
if __debug__: |
# prevent infinite recursion when calling SetClassification() |
154 |
if layer is not None: |
if self.__setLayerLock: return |
|
assert(isinstance(layer, Thuban.Model.layer.Layer)) |
|
155 |
|
|
156 |
self.layer = layer |
self.__setLayerLock = True |
|
self.SetField(self.GetField()) # XXX: this sync's the fieldType |
|
157 |
|
|
158 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
if layer is None: |
159 |
|
if self.layer is not None: |
160 |
|
l = self.layer |
161 |
|
self.layer = None |
162 |
|
l.SetClassification(None) |
163 |
|
else: |
164 |
|
assert isinstance(layer, Thuban.Model.layer.Layer) |
165 |
|
|
166 |
def GetLayer(self): |
old_layer = self.layer |
|
"""Return the parent layer.""" |
|
|
return self.layer |
|
167 |
|
|
168 |
def SetDefaultGroup(self, group): |
self.layer = layer |
|
"""Set the group to be used when a value can't be classified. |
|
169 |
|
|
170 |
group -- group that the value maps to. |
try: |
171 |
""" |
self.SetField(self.GetField()) # this sync's the fieldType |
172 |
|
except ValueError: |
173 |
|
self.layer = old_layer |
174 |
|
self.__setLayerLock = False |
175 |
|
raise ValueError |
176 |
|
else: |
177 |
|
self.layer.SetClassification(self) |
178 |
|
|
179 |
assert(isinstance(group, ClassGroupDefault)) |
self.__setLayerLock = False |
180 |
self.AddGroup(group) |
|
181 |
|
def GetLayer(self): |
182 |
|
"""Return the parent layer.""" |
183 |
|
return self.layer |
184 |
|
|
|
def GetDefaultGroup(self): |
|
|
"""Return the default group.""" |
|
|
return self.groups[0] |
|
185 |
|
|
186 |
# |
# |
187 |
# these SetDefault* methods are really only provided for |
# these SetDefault* methods are really only provided for |
194 |
|
|
195 |
fill -- a Color object. |
fill -- a Color object. |
196 |
""" |
""" |
197 |
assert(isinstance(fill, Color)) |
assert isinstance(fill, Color) |
198 |
self.GetDefaultGroup().GetProperties().SetFill(fill) |
self.GetDefaultGroup().GetProperties().SetFill(fill) |
199 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__SendNotification() |
200 |
|
|
201 |
def GetDefaultFill(self): |
def GetDefaultFill(self): |
202 |
"""Return the default fill color.""" |
"""Return the default fill color.""" |
207 |
|
|
208 |
color -- a Color object. |
color -- a Color object. |
209 |
""" |
""" |
210 |
assert(isinstance(color, Color)) |
assert isinstance(color, Color) |
211 |
self.GetDefaultGroup().GetProperties().SetLineColor(color) |
self.GetDefaultGroup().GetProperties().SetLineColor(color) |
212 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__SendNotification() |
213 |
|
|
214 |
def GetDefaultLineColor(self): |
def GetDefaultLineColor(self): |
215 |
"""Return the default line color.""" |
"""Return the default line color.""" |
220 |
|
|
221 |
lineWidth -- an integer > 0. |
lineWidth -- an integer > 0. |
222 |
""" |
""" |
223 |
assert(isinstance(lineWidth, IntType)) |
assert isinstance(lineWidth, IntType) |
224 |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
225 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__SendNotification() |
226 |
|
|
227 |
def GetDefaultLineWidth(self): |
def GetDefaultLineWidth(self): |
228 |
"""Return the default line width.""" |
"""Return the default line width.""" |
229 |
return self.GetDefaultGroup().GetProperties().GetLineWidth() |
return self.GetDefaultGroup().GetProperties().GetLineWidth() |
230 |
|
|
231 |
def AddGroup(self, item): |
|
232 |
"""Add a new ClassGroup item to the classification. |
# |
233 |
|
# The methods that manipulate self.__groups have to be kept in |
234 |
|
# sync. We store the default group in index 0 to make it |
235 |
|
# convienent to iterate over the classification's groups, but |
236 |
|
# from the user's perspective the first (non-default) group is |
237 |
|
# at index 0 and the DefaultGroup is a special entity. |
238 |
|
# |
239 |
|
|
240 |
|
def SetDefaultGroup(self, group): |
241 |
|
"""Set the group to be used when a value can't be classified. |
242 |
|
|
243 |
|
group -- group that the value maps to. |
244 |
|
""" |
245 |
|
|
246 |
|
assert isinstance(group, ClassGroupDefault) |
247 |
|
if len(self.__groups) > 0: |
248 |
|
self.__groups[0] = group |
249 |
|
else: |
250 |
|
self.__groups.append(group) |
251 |
|
|
252 |
|
def GetDefaultGroup(self): |
253 |
|
"""Return the default group.""" |
254 |
|
return self.__groups[0] |
255 |
|
|
256 |
|
def AppendGroup(self, item): |
257 |
|
"""Append a new ClassGroup item to the classification. |
258 |
|
|
259 |
item -- this must be a valid ClassGroup object |
item -- this must be a valid ClassGroup object |
260 |
""" |
""" |
261 |
|
|
262 |
assert(isinstance(item, ClassGroup)) |
self.InsertGroup(self.GetNumGroups(), item) |
263 |
|
|
264 |
if len(self.groups) > 0 and isinstance(item, ClassGroupDefault): |
def InsertGroup(self, index, group): |
265 |
self.groups[0] = item |
|
266 |
#self.SetDefaultGroup(item) |
assert isinstance(group, ClassGroup) |
267 |
else: |
|
268 |
self.groups.append(item) |
self.__groups.insert(index + 1, group) |
269 |
|
|
270 |
|
self.__SendNotification() |
271 |
|
|
272 |
|
def RemoveGroup(self, index): |
273 |
|
return self.__groups.pop(index + 1) |
274 |
|
|
275 |
|
def ReplaceGroup(self, index, group): |
276 |
|
assert isinstance(group, ClassGroup) |
277 |
|
|
278 |
self.__SendMessage(LAYER_LEGEND_CHANGED) |
self.__groups[index + 1] = group |
279 |
|
|
280 |
def GetGroup(self, value): |
self.__SendNotification() |
281 |
|
|
282 |
|
def GetGroup(self, index): |
283 |
|
return self.__groups[index + 1] |
284 |
|
|
285 |
|
def GetNumGroups(self): |
286 |
|
"""Return the number of non-default groups in the classification.""" |
287 |
|
return len(self.__groups) - 1 |
288 |
|
|
289 |
|
|
290 |
|
def FindGroup(self, value): |
291 |
"""Return the associated group, or the default group. |
"""Return the associated group, or the default group. |
292 |
|
|
293 |
Groups are checked in the order the were added to the |
Groups are checked in the order the were added to the |
294 |
Classification. |
Classification. |
295 |
|
|
296 |
value -- the value to classify. If there is no mapping, |
value -- the value to classify. If there is no mapping, |
297 |
or value is None, return the default properties |
the field is None or value is None, |
298 |
|
return the default properties |
299 |
""" |
""" |
300 |
|
|
301 |
if self.field is not None and value is not None: |
if self.GetField() is not None and value is not None: |
302 |
|
|
303 |
for i in range(1, len(self.groups)): |
for i in range(1, len(self.__groups)): |
304 |
group = self.groups[i] |
group = self.__groups[i] |
305 |
if group.Matches(value): |
if group.Matches(value): |
306 |
return group |
return group |
307 |
|
|
308 |
return self.GetDefaultGroup() |
return self.GetDefaultGroup() |
309 |
|
|
310 |
def GetProperties(self, value): |
def GetProperties(self, value): |
311 |
"""Return the properties associated with the given value.""" |
"""Return the properties associated with the given value. |
312 |
|
|
313 |
|
Use this function rather than Classification.FindGroup().GetProperties() |
314 |
|
since the returned group may be a ClassGroupMap which doesn't support |
315 |
|
a call to GetProperties(). |
316 |
|
""" |
317 |
|
|
318 |
group = self.GetGroup(value) |
group = self.FindGroup(value) |
319 |
if isinstance(group, ClassGroupMap): |
if isinstance(group, ClassGroupMap): |
320 |
return group.GetPropertiesFromValue(value) |
return group.GetPropertiesFromValue(value) |
321 |
else: |
else: |
325 |
items = [] |
items = [] |
326 |
|
|
327 |
def build_color_item(text, color): |
def build_color_item(text, color): |
328 |
if color is Color.None: |
if color is Color.Transparent: |
329 |
return ("%s: %s" % (text, _("None")), None) |
return ("%s: %s" % (text, _("None")), None) |
330 |
|
|
331 |
return ("%s: (%.3f, %.3f, %.3f)" % |
return ("%s: (%.3f, %.3f, %.3f)" % |
350 |
return (label, i) |
return (label, i) |
351 |
|
|
352 |
for p in self: |
for p in self: |
353 |
if isinstance(p, ClassGroupDefault): |
items.append(build_item(p, p.GetDisplayText())) |
354 |
items.append(build_item(self.GetDefaultGroup(), _("'DEFAULT'"))) |
|
355 |
elif isinstance(p, ClassGroupSingleton): |
# if isinstance(p, ClassGroupDefault): |
356 |
items.append(build_item(p, str(p.GetValue()))) |
# items.append(build_item(self.GetDefaultGroup(), _("'DEFAULT'"))) |
357 |
elif isinstance(p, ClassGroupRange): |
# elif isinstance(p, ClassGroupSingleton): |
358 |
items.append(build_item(p, "%s - %s" % |
# items.append(build_item(p, str(p.GetValue()))) |
359 |
(p.GetMin(), p.GetMax()))) |
# elif isinstance(p, ClassGroupRange): |
360 |
|
# items.append(build_item(p, "%s - %s" % |
361 |
|
# (p.GetMin(), p.GetMax()))) |
362 |
|
|
363 |
return (_("Classification"), items) |
return (_("Classification"), items) |
364 |
|
|
422 |
|
|
423 |
props -- a ClassGroupProperties object. The class is copied if |
props -- a ClassGroupProperties object. The class is copied if |
424 |
prop is not None. Otherwise, a default set of properties |
prop is not None. Otherwise, a default set of properties |
425 |
is created. |
is created such that: line color = Color.Black, line width = 1, |
426 |
|
and fill color = Color.Transparent |
427 |
""" |
""" |
428 |
|
|
429 |
self.stroke = None |
self.stroke = None |
433 |
if props is not None: |
if props is not None: |
434 |
self.SetProperties(props) |
self.SetProperties(props) |
435 |
else: |
else: |
436 |
self.SetLineColor(Color.None) |
self.SetLineColor(Color.Black) |
437 |
self.SetLineWidth(1) |
self.SetLineWidth(1) |
438 |
self.SetFill(Color.None) |
self.SetFill(Color.Transparent) |
439 |
|
|
440 |
def SetProperties(self, props): |
def SetProperties(self, props): |
441 |
"""Set this class's properties to those in class props.""" |
"""Set this class's properties to those in class props.""" |
442 |
|
|
443 |
assert(isinstance(props, ClassGroupProperties)) |
assert isinstance(props, ClassGroupProperties) |
444 |
self.SetLineColor(props.GetLineColor()) |
self.SetLineColor(props.GetLineColor()) |
445 |
self.SetLineWidth(props.GetLineWidth()) |
self.SetLineWidth(props.GetLineWidth()) |
446 |
self.SetFill(props.GetFill()) |
self.SetFill(props.GetFill()) |
455 |
color -- the color of the line. This must be a Color object. |
color -- the color of the line. This must be a Color object. |
456 |
""" |
""" |
457 |
|
|
458 |
assert(isinstance(color, Color)) |
assert isinstance(color, Color) |
459 |
self.stroke = color |
self.stroke = color |
460 |
|
|
461 |
def GetLineWidth(self): |
def GetLineWidth(self): |
467 |
|
|
468 |
lineWidth -- the new line width. This must be > 0. |
lineWidth -- the new line width. This must be > 0. |
469 |
""" |
""" |
470 |
assert(isinstance(lineWidth, IntType)) |
assert isinstance(lineWidth, IntType) |
471 |
if (lineWidth < 1): |
if (lineWidth < 1): |
472 |
raise ValueError(_("lineWidth < 1")) |
raise ValueError(_("lineWidth < 1")) |
473 |
|
|
483 |
fill -- the color of the fill. This must be a Color object. |
fill -- the color of the fill. This must be a Color object. |
484 |
""" |
""" |
485 |
|
|
486 |
assert(isinstance(fill, Color)) |
assert isinstance(fill, Color) |
487 |
self.fill = fill |
self.fill = fill |
488 |
|
|
489 |
|
def __eq__(self, other): |
490 |
|
"""Return true if 'props' has the same attributes as this class""" |
491 |
|
|
492 |
|
return isinstance(other, ClassGroupProperties) \ |
493 |
|
and self.stroke == other.GetLineColor() \ |
494 |
|
and self.strokeWidth == other.GetLineWidth() \ |
495 |
|
and self.fill == other.GetFill() |
496 |
|
|
497 |
|
def __ne__(self, other): |
498 |
|
return not self.__eq__(other) |
499 |
|
|
500 |
|
def __copy__(self): |
501 |
|
return ClassGroupProperties(self) |
502 |
|
|
503 |
|
def __deepcopy__(self): |
504 |
|
return ClassGroupProperties(self) |
505 |
|
|
506 |
class ClassGroup: |
class ClassGroup: |
507 |
"""A base class for all Groups within a Classification""" |
"""A base class for all Groups within a Classification""" |
526 |
label -- a string representing the Group's label. This must |
label -- a string representing the Group's label. This must |
527 |
not be None. |
not be None. |
528 |
""" |
""" |
529 |
assert(isinstance(label, StringType)) |
assert isinstance(label, StringType) |
530 |
self.label = label |
self.label = label |
531 |
|
|
532 |
|
def GetDisplayText(self): |
533 |
|
assert False, "GetDisplay must be overridden by subclass!" |
534 |
|
return "" |
535 |
|
|
536 |
def Matches(self, value): |
def Matches(self, value): |
537 |
"""Determines if this Group is associated with the given value. |
"""Determines if this Group is associated with the given value. |
538 |
|
|
539 |
Returns True or False. This needs to be implemented by all subclasses. |
Returns False. This needs to be overridden by all subclasses. |
540 |
""" |
""" |
541 |
pass |
assert False, "GetMatches must be overridden by subclass!" |
542 |
|
return False |
543 |
|
|
544 |
def GetProperties(self): |
def GetProperties(self): |
545 |
"""Return the properties associated with the given value. |
"""Return the properties associated with the given value. |
546 |
|
|
547 |
This needs to be implemented by all subclasses. |
Returns None. This needs to be overridden by all subclasses. |
548 |
""" |
""" |
549 |
pass |
assert False, "GetProperties must be overridden by subclass!" |
550 |
|
return None |
551 |
|
|
552 |
|
|
553 |
class ClassGroupSingleton(ClassGroup): |
class ClassGroupSingleton(ClassGroup): |
572 |
self.SetProperties(prop) |
self.SetProperties(prop) |
573 |
|
|
574 |
def __copy__(self): |
def __copy__(self): |
575 |
return ClassGroupSingleton(self.value, self.prop, self.label) |
return ClassGroupSingleton(self.GetValue(), |
576 |
|
self.GetProperties(), |
577 |
|
self.GetLabel()) |
578 |
|
|
579 |
|
def __deepcopy__(self, memo): |
580 |
|
return ClassGroupSingleton(copy.copy(self.GetValue()), |
581 |
|
copy.copy(self.GetProperties()), |
582 |
|
copy.copy(self.GetLabel())) |
583 |
|
|
584 |
def GetValue(self): |
def GetValue(self): |
585 |
"""Return the associated value.""" |
"""Return the associated value.""" |
609 |
""" |
""" |
610 |
|
|
611 |
if prop is None: prop = ClassGroupProperties() |
if prop is None: prop = ClassGroupProperties() |
612 |
assert(isinstance(prop, ClassGroupProperties)) |
assert isinstance(prop, ClassGroupProperties) |
613 |
self.prop = prop |
self.prop = prop |
614 |
|
|
615 |
|
def GetDisplayText(self): |
616 |
|
label = self.GetLabel() |
617 |
|
|
618 |
|
if label != "": return label |
619 |
|
|
620 |
|
return str(self.GetValue()) |
621 |
|
|
622 |
|
def __eq__(self, other): |
623 |
|
return isinstance(other, ClassGroupSingleton) \ |
624 |
|
and self.GetProperties() == other.GetProperties() \ |
625 |
|
and self.GetValue() == other.GetValue() |
626 |
|
|
627 |
|
def __ne__(self, other): |
628 |
|
return not self.__eq__(other) |
629 |
|
|
630 |
class ClassGroupDefault(ClassGroupSingleton): |
class ClassGroupDefault(ClassGroup): |
631 |
"""The default Group. When values do not match any other |
"""The default Group. When values do not match any other |
632 |
Group within a Classification, the properties from this |
Group within a Classification, the properties from this |
633 |
class are used.""" |
class are used.""" |
641 |
label -- a label for this group. |
label -- a label for this group. |
642 |
""" |
""" |
643 |
|
|
644 |
ClassGroupSingleton.__init__(self, 0, prop, label) |
ClassGroup.__init__(self, label) |
645 |
|
self.SetProperties(prop) |
646 |
|
|
647 |
def __copy__(self): |
def __copy__(self): |
648 |
return ClassGroupDefault(self.prop, self.label) |
return ClassGroupDefault(self.GetProperties(), self.GetLabel()) |
649 |
|
|
650 |
|
def __deepcopy__(self, memo): |
651 |
|
return ClassGroupDefault(copy.copy(self.GetProperties()), |
652 |
|
copy.copy(self.GetLabel())) |
653 |
|
|
654 |
|
def Matches(self, value): |
655 |
|
return True |
656 |
|
|
657 |
def GetProperties(self): |
def GetProperties(self): |
658 |
"""Return the Properties associated with this Group.""" |
"""Return the Properties associated with this Group.""" |
659 |
return self.prop |
return self.prop |
660 |
|
|
661 |
|
def SetProperties(self, prop): |
662 |
|
"""Set the properties associated with this Group. |
663 |
|
|
664 |
|
prop -- a ClassGroupProperties object. if prop is None, |
665 |
|
a default set of properties is created. |
666 |
|
""" |
667 |
|
|
668 |
|
if prop is None: prop = ClassGroupProperties() |
669 |
|
assert isinstance(prop, ClassGroupProperties) |
670 |
|
self.prop = prop |
671 |
|
|
672 |
|
def GetDisplayText(self): |
673 |
|
label = self.GetLabel() |
674 |
|
|
675 |
|
if label != "": return label |
676 |
|
|
677 |
|
return _("DEFAULT") |
678 |
|
|
679 |
|
def __eq__(self, other): |
680 |
|
return isinstance(other, ClassGroupDefault) \ |
681 |
|
and self.GetProperties() == other.GetProperties() |
682 |
|
|
683 |
|
def __ne__(self, other): |
684 |
|
return not self.__eq__(other) |
685 |
|
|
686 |
class ClassGroupRange(ClassGroup): |
class ClassGroupRange(ClassGroup): |
687 |
"""A Group that represents a range of values that map to the same |
"""A Group that represents a range of values that map to the same |
688 |
set of properties.""" |
set of properties.""" |
711 |
self.SetProperties(prop) |
self.SetProperties(prop) |
712 |
|
|
713 |
def __copy__(self): |
def __copy__(self): |
714 |
return ClassGroupRange(self.min, self.max, self.prop, self.label) |
return ClassGroupRange(self.GetMin(), |
715 |
|
self.GetMax(), |
716 |
|
self.GetProperties(), |
717 |
|
self.GetLabel()) |
718 |
|
|
719 |
|
def __deepcopy__(self, memo): |
720 |
|
return ClassGroupRange(copy.copy(self.GetMin()), |
721 |
|
copy.copy(self.GetMax()), |
722 |
|
copy.copy(self.GetProperties()), |
723 |
|
copy.copy(self.GetLabel())) |
724 |
|
|
725 |
def GetMin(self): |
def GetMin(self): |
726 |
"""Return the range's minimum value.""" |
"""Return the range's minimum value.""" |
785 |
a default set of properties is created. |
a default set of properties is created. |
786 |
""" |
""" |
787 |
if prop is None: prop = ClassGroupProperties() |
if prop is None: prop = ClassGroupProperties() |
788 |
assert(isinstance(prop, ClassGroupProperties)) |
assert isinstance(prop, ClassGroupProperties) |
789 |
self.prop = prop |
self.prop = prop |
790 |
|
|
791 |
|
def GetDisplayText(self): |
792 |
|
label = self.GetLabel() |
793 |
|
|
794 |
|
if label != "": return label |
795 |
|
|
796 |
|
return _("%s - %s") % (self.GetMin(), self.GetMax()) |
797 |
|
|
798 |
|
def __eq__(self, other): |
799 |
|
return isinstance(other, ClassGroupRange) \ |
800 |
|
and self.GetProperties() == other.GetProperties() \ |
801 |
|
and self.GetRange() == other.GetRange() |
802 |
|
|
803 |
|
def __ne__(self, other): |
804 |
|
return not self.__eq__(other) |
805 |
|
|
806 |
class ClassGroupMap(ClassGroup): |
class ClassGroupMap(ClassGroup): |
807 |
"""Currently, this class is not used.""" |
"""Currently, this class is not used.""" |
808 |
|
|
826 |
def GetPropertiesFromValue(self, value): |
def GetPropertiesFromValue(self, value): |
827 |
pass |
pass |
828 |
|
|
829 |
|
def GetDisplayText(self): |
830 |
|
return "Map: " + self.map_type |
831 |
|
|
832 |
# |
# |
833 |
# built-in mappings |
# built-in mappings |
834 |
# |
# |