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 |
|
|
25 |
|
|
26 |
import copy |
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 |
|
|
63 |
self.__setLayerLock = False |
self.__setLayerLock = False |
64 |
|
|
68 |
self.SetField(field) |
self.SetField(field) |
69 |
|
|
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 |
|
# note: the only thing that isn't copied is the layer reference |
77 |
|
clazz.field = self.field |
78 |
|
clazz.fieldType = self.fieldType |
79 |
|
clazz.__groups[0] = copy.deepcopy(self.__groups[0]) |
80 |
|
|
81 |
|
for i in range(1, len(self.__groups)): |
82 |
|
clazz.__groups.append(copy.deepcopy(self.__groups[i])) |
83 |
|
|
84 |
|
return clazz |
85 |
|
|
86 |
def __SendNotification(self): |
def __SendNotification(self): |
87 |
"""Notify the layer that this class has changed.""" |
"""Notify the layer that this class has changed.""" |
91 |
def SetField(self, field): |
def SetField(self, field): |
92 |
"""Set the name of the data table field to use. |
"""Set the name of the data table field to use. |
93 |
|
|
94 |
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, |
95 |
otherwise the layer is queried to find the type of the |
otherwise the layer is queried to find the type of the |
96 |
field data |
field data |
97 |
|
|
98 |
field -- if None then all values map to the default data |
field -- if None then all values map to the default data |
99 |
""" |
""" |
100 |
|
|
101 |
if field == "": |
if field == "": |
148 |
def SetLayer(self, layer): |
def SetLayer(self, layer): |
149 |
"""Set the owning Layer of this classification. |
"""Set the owning Layer of this classification. |
150 |
|
|
151 |
A ValueError exception will be thrown either the field or |
A ValueError exception will be thrown either the field or |
152 |
field type mismatch the information in the layer's table. |
field type mismatch the information in the layer's table. |
153 |
""" |
""" |
154 |
|
|
155 |
# prevent infinite recursion when calling SetClassification() |
# prevent infinite recursion when calling SetClassification() |
184 |
"""Return the parent layer.""" |
"""Return the parent layer.""" |
185 |
return self.layer |
return self.layer |
186 |
|
|
|
def SetDefaultGroup(self, group): |
|
|
"""Set the group to be used when a value can't be classified. |
|
|
|
|
|
group -- group that the value maps to. |
|
|
""" |
|
|
|
|
|
assert isinstance(group, ClassGroupDefault) |
|
|
self.AddGroup(group) |
|
|
|
|
|
def GetDefaultGroup(self): |
|
|
"""Return the default group.""" |
|
|
return self.groups[0] |
|
187 |
|
|
188 |
# |
# |
189 |
# these SetDefault* methods are really only provided for |
# these SetDefault* methods are really only provided for |
230 |
"""Return the default line width.""" |
"""Return the default line width.""" |
231 |
return self.GetDefaultGroup().GetProperties().GetLineWidth() |
return self.GetDefaultGroup().GetProperties().GetLineWidth() |
232 |
|
|
233 |
def AddGroup(self, item): |
|
234 |
"""Add a new ClassGroup item to the classification. |
# |
235 |
|
# The methods that manipulate self.__groups have to be kept in |
236 |
|
# sync. We store the default group in index 0 to make it |
237 |
|
# convienent to iterate over the classification's groups, but |
238 |
|
# from the user's perspective the first (non-default) group is |
239 |
|
# at index 0 and the DefaultGroup is a special entity. |
240 |
|
# |
241 |
|
|
242 |
|
def SetDefaultGroup(self, group): |
243 |
|
"""Set the group to be used when a value can't be classified. |
244 |
|
|
245 |
|
group -- group that the value maps to. |
246 |
|
""" |
247 |
|
|
248 |
|
assert isinstance(group, ClassGroupDefault) |
249 |
|
if len(self.__groups) > 0: |
250 |
|
self.__groups[0] = group |
251 |
|
else: |
252 |
|
self.__groups.append(group) |
253 |
|
|
254 |
|
def GetDefaultGroup(self): |
255 |
|
"""Return the default group.""" |
256 |
|
return self.__groups[0] |
257 |
|
|
258 |
|
def AppendGroup(self, item): |
259 |
|
"""Append a new ClassGroup item to the classification. |
260 |
|
|
261 |
item -- this must be a valid ClassGroup object |
item -- this must be a valid ClassGroup object |
262 |
""" |
""" |
263 |
|
|
264 |
assert isinstance(item, ClassGroup) |
self.InsertGroup(self.GetNumGroups(), item) |
265 |
|
|
266 |
if len(self.groups) > 0 and isinstance(item, ClassGroupDefault): |
def InsertGroup(self, index, group): |
267 |
self.groups[0] = item |
|
268 |
else: |
assert isinstance(group, ClassGroup) |
269 |
self.groups.append(item) |
|
270 |
|
self.__groups.insert(index + 1, group) |
271 |
|
|
272 |
|
self.__SendNotification() |
273 |
|
|
274 |
|
def RemoveGroup(self, index): |
275 |
|
return self.__groups.pop(index + 1) |
276 |
|
|
277 |
|
def ReplaceGroup(self, index, group): |
278 |
|
assert isinstance(group, ClassGroup) |
279 |
|
|
280 |
|
self.__groups[index + 1] = group |
281 |
|
|
282 |
self.__SendNotification() |
self.__SendNotification() |
283 |
|
|
284 |
def GetGroup(self, value): |
def GetGroup(self, index): |
285 |
|
return self.__groups[index + 1] |
286 |
|
|
287 |
|
def GetNumGroups(self): |
288 |
|
"""Return the number of non-default groups in the classification.""" |
289 |
|
return len(self.__groups) - 1 |
290 |
|
|
291 |
|
|
292 |
|
def FindGroup(self, value): |
293 |
"""Return the associated group, or the default group. |
"""Return the associated group, or the default group. |
294 |
|
|
295 |
Groups are checked in the order the were added to the |
Groups are checked in the order the were added to the |
296 |
Classification. |
Classification. |
297 |
|
|
298 |
value -- the value to classify. If there is no mapping, |
value -- the value to classify. If there is no mapping, |
299 |
the field is None or value is None, |
the field is None or value is None, |
300 |
return the default properties |
return the default properties |
301 |
""" |
""" |
302 |
|
|
303 |
if self.GetField() is not None and value is not None: |
if self.GetField() is not None and value is not None: |
304 |
|
|
305 |
for i in range(1, len(self.groups)): |
for i in range(1, len(self.__groups)): |
306 |
group = self.groups[i] |
group = self.__groups[i] |
307 |
if group.Matches(value): |
if group.Matches(value): |
308 |
return group |
return group |
309 |
|
|
310 |
return self.GetDefaultGroup() |
return self.GetDefaultGroup() |
311 |
|
|
312 |
def GetProperties(self, value): |
def GetProperties(self, value): |
313 |
"""Return the properties associated with the given value.""" |
"""Return the properties associated with the given value. |
314 |
|
|
315 |
|
Use this function rather than Classification.FindGroup().GetProperties() |
316 |
|
since the returned group may be a ClassGroupMap which doesn't support |
317 |
|
a call to GetProperties(). |
318 |
|
""" |
319 |
|
|
320 |
group = self.GetGroup(value) |
group = self.FindGroup(value) |
321 |
if isinstance(group, ClassGroupMap): |
if isinstance(group, ClassGroupMap): |
322 |
return group.GetPropertiesFromValue(value) |
return group.GetPropertiesFromValue(value) |
323 |
else: |
else: |
352 |
return (label, i) |
return (label, i) |
353 |
|
|
354 |
for p in self: |
for p in self: |
355 |
if isinstance(p, ClassGroupDefault): |
items.append(build_item(p, p.GetDisplayText())) |
356 |
items.append(build_item(self.GetDefaultGroup(), _("'DEFAULT'"))) |
|
357 |
elif isinstance(p, ClassGroupSingleton): |
# if isinstance(p, ClassGroupDefault): |
358 |
items.append(build_item(p, str(p.GetValue()))) |
# items.append(build_item(self.GetDefaultGroup(), _("'DEFAULT'"))) |
359 |
elif isinstance(p, ClassGroupRange): |
# elif isinstance(p, ClassGroupSingleton): |
360 |
items.append(build_item(p, "%s - %s" % |
# items.append(build_item(p, str(p.GetValue()))) |
361 |
(p.GetMin(), p.GetMax()))) |
# elif isinstance(p, ClassGroupRange): |
362 |
|
# items.append(build_item(p, "%s - %s" % |
363 |
|
# (p.GetMin(), p.GetMax()))) |
364 |
|
|
365 |
return (_("Classification"), items) |
return (_("Classification"), items) |
366 |
|
|
428 |
and fill color = Color.Transparent |
and fill color = Color.Transparent |
429 |
""" |
""" |
430 |
|
|
431 |
self.stroke = None |
#self.stroke = None |
432 |
self.strokeWidth = 0 |
#self.strokeWidth = 0 |
433 |
self.fill = None |
#self.fill = None |
434 |
|
|
435 |
if props is not None: |
if props is not None: |
436 |
self.SetProperties(props) |
self.SetProperties(props) |
449 |
|
|
450 |
def GetLineColor(self): |
def GetLineColor(self): |
451 |
"""Return the line color as a Color object.""" |
"""Return the line color as a Color object.""" |
452 |
return self.stroke |
return self.__stroke |
453 |
|
|
454 |
def SetLineColor(self, color): |
def SetLineColor(self, color): |
455 |
"""Set the line color. |
"""Set the line color. |
458 |
""" |
""" |
459 |
|
|
460 |
assert isinstance(color, Color) |
assert isinstance(color, Color) |
461 |
self.stroke = color |
self.__stroke = color |
462 |
|
|
463 |
def GetLineWidth(self): |
def GetLineWidth(self): |
464 |
"""Return the line width.""" |
"""Return the line width.""" |
465 |
return self.strokeWidth |
return self.__strokeWidth |
466 |
|
|
467 |
def SetLineWidth(self, lineWidth): |
def SetLineWidth(self, lineWidth): |
468 |
"""Set the line width. |
"""Set the line width. |
473 |
if (lineWidth < 1): |
if (lineWidth < 1): |
474 |
raise ValueError(_("lineWidth < 1")) |
raise ValueError(_("lineWidth < 1")) |
475 |
|
|
476 |
self.strokeWidth = lineWidth |
self.__strokeWidth = lineWidth |
477 |
|
|
478 |
def GetFill(self): |
def GetFill(self): |
479 |
"""Return the fill color as a Color object.""" |
"""Return the fill color as a Color object.""" |
480 |
return self.fill |
return self.__fill |
481 |
|
|
482 |
def SetFill(self, fill): |
def SetFill(self, fill): |
483 |
"""Set the fill color. |
"""Set the fill color. |
486 |
""" |
""" |
487 |
|
|
488 |
assert isinstance(fill, Color) |
assert isinstance(fill, Color) |
489 |
self.fill = fill |
self.__fill = fill |
490 |
|
|
491 |
def __eq__(self, other): |
def __eq__(self, other): |
492 |
"""Return true if 'props' has the same attributes as this class""" |
"""Return true if 'props' has the same attributes as this class""" |
493 |
|
|
494 |
|
# |
495 |
|
# using 'is' over '==' results in a huge performance gain |
496 |
|
# in the renderer |
497 |
|
# |
498 |
return isinstance(other, ClassGroupProperties) \ |
return isinstance(other, ClassGroupProperties) \ |
499 |
and self.stroke == other.GetLineColor() \ |
and (self.__stroke is other.__stroke or \ |
500 |
and self.strokeWidth == other.GetLineWidth() \ |
self.__stroke == other.__stroke) \ |
501 |
and self.fill == other.GetFill() |
and (self.__fill is other.__fill or \ |
502 |
|
self.__fill == other.__fill) \ |
503 |
|
and self.__strokeWidth == other.__strokeWidth |
504 |
|
|
505 |
def __ne__(self, other): |
def __ne__(self, other): |
506 |
return not self.__eq__(other) |
return not self.__eq__(other) |
514 |
class ClassGroup: |
class ClassGroup: |
515 |
"""A base class for all Groups within a Classification""" |
"""A base class for all Groups within a Classification""" |
516 |
|
|
517 |
def __init__(self, label = ""): |
def __init__(self, label = "", props = None, group = None): |
518 |
"""Constructor. |
"""Constructor. |
519 |
|
|
520 |
label -- A string representing the Group's label |
label -- A string representing the Group's label |
521 |
""" |
""" |
522 |
|
|
523 |
self.label = None |
if group is not None: |
524 |
|
self.SetLabel(copy.copy(group.GetLabel())) |
525 |
self.SetLabel(label) |
self.SetProperties(copy.copy(group.GetProperties())) |
526 |
|
self.SetVisible(group.IsVisible()) |
527 |
|
else: |
528 |
|
self.SetLabel(label) |
529 |
|
self.SetProperties(props) |
530 |
|
self.SetVisible(True) |
531 |
|
|
532 |
def GetLabel(self): |
def GetLabel(self): |
533 |
"""Return the Group's label.""" |
"""Return the Group's label.""" |
555 |
return False |
return False |
556 |
|
|
557 |
def GetProperties(self): |
def GetProperties(self): |
558 |
"""Return the properties associated with the given value. |
"""Return the properties associated with the given value.""" |
559 |
|
|
560 |
Returns None. This needs to be overridden by all subclasses. |
return self.prop |
|
""" |
|
|
assert False, "GetProperties must be overridden by subclass!" |
|
|
return None |
|
561 |
|
|
562 |
|
def SetProperties(self, prop): |
563 |
|
"""Set the properties associated with this Group. |
564 |
|
|
565 |
|
prop -- a ClassGroupProperties object. if prop is None, |
566 |
|
a default set of properties is created. |
567 |
|
""" |
568 |
|
|
569 |
|
if prop is None: prop = ClassGroupProperties() |
570 |
|
assert isinstance(prop, ClassGroupProperties) |
571 |
|
self.prop = prop |
572 |
|
|
573 |
|
def IsVisible(self): |
574 |
|
return self.visible |
575 |
|
|
576 |
|
def SetVisible(self, visible): |
577 |
|
self.visible = visible |
578 |
|
|
579 |
|
def __eq__(self, other): |
580 |
|
return isinstance(other, ClassGroup) \ |
581 |
|
and self.GetProperties() == other.GetProperties() |
582 |
|
|
583 |
|
def __ne__(self, other): |
584 |
|
return not self.__eq__(other) |
585 |
|
|
586 |
|
|
587 |
class ClassGroupSingleton(ClassGroup): |
class ClassGroupSingleton(ClassGroup): |
588 |
"""A Group that is associated with a single value.""" |
"""A Group that is associated with a single value.""" |
589 |
|
|
590 |
def __init__(self, value = 0, prop = None, label = ""): |
def __init__(self, value = 0, props = None, label = "", group = None): |
591 |
"""Constructor. |
"""Constructor. |
592 |
|
|
593 |
value -- the associated value. |
value -- the associated value. |
597 |
|
|
598 |
label -- a label for this group. |
label -- a label for this group. |
599 |
""" |
""" |
600 |
ClassGroup.__init__(self, label) |
ClassGroup.__init__(self, label, props, group) |
|
|
|
|
self.prop = None |
|
|
self.value = None |
|
601 |
|
|
602 |
self.SetValue(value) |
self.SetValue(value) |
|
self.SetProperties(prop) |
|
603 |
|
|
604 |
def __copy__(self): |
def __copy__(self): |
605 |
return ClassGroupSingleton(self.GetValue(), |
return ClassGroupSingleton(self.GetValue(), |
607 |
self.GetLabel()) |
self.GetLabel()) |
608 |
|
|
609 |
def __deepcopy__(self, memo): |
def __deepcopy__(self, memo): |
610 |
return ClassGroupSingleton(copy.copy(self.GetValue()), |
return ClassGroupSingleton(self.GetValue(), group = self) |
|
copy.copy(self.GetProperties()), |
|
|
copy.copy(self.GetLabel())) |
|
611 |
|
|
612 |
def GetValue(self): |
def GetValue(self): |
613 |
"""Return the associated value.""" |
"""Return the associated value.""" |
614 |
return self.value |
return self.__value |
615 |
|
|
616 |
def SetValue(self, value): |
def SetValue(self, value): |
617 |
"""Associate this Group with the given value.""" |
"""Associate this Group with the given value.""" |
618 |
self.value = value |
self.__value = value |
619 |
|
|
620 |
def Matches(self, value): |
def Matches(self, value): |
621 |
"""Determine if the given value matches the associated Group value.""" |
"""Determine if the given value matches the associated Group value.""" |
622 |
|
|
623 |
"""Returns True if the value matches, False otherwise.""" |
"""Returns True if the value matches, False otherwise.""" |
624 |
|
|
625 |
return self.value == value |
return self.__value == value |
|
|
|
|
def GetProperties(self): |
|
|
"""Return the Properties associated with this Group.""" |
|
|
|
|
|
return self.prop |
|
|
|
|
|
def SetProperties(self, prop): |
|
|
"""Set the properties associated with this Group. |
|
|
|
|
|
prop -- a ClassGroupProperties object. if prop is None, |
|
|
a default set of properties is created. |
|
|
""" |
|
|
|
|
|
if prop is None: prop = ClassGroupProperties() |
|
|
assert isinstance(prop, ClassGroupProperties) |
|
|
self.prop = prop |
|
626 |
|
|
627 |
def GetDisplayText(self): |
def GetDisplayText(self): |
628 |
label = self.GetLabel() |
label = self.GetLabel() |
632 |
return str(self.GetValue()) |
return str(self.GetValue()) |
633 |
|
|
634 |
def __eq__(self, other): |
def __eq__(self, other): |
635 |
return isinstance(other, ClassGroupSingleton) \ |
return ClassGroup.__eq__(self, other) \ |
636 |
and self.GetProperties() == other.GetProperties() \ |
and isinstance(other, ClassGroupSingleton) \ |
637 |
and self.GetValue() == other.GetValue() |
and self.__value == other.__value |
|
|
|
|
def __ne__(self, other): |
|
|
return not self.__eq__(other) |
|
638 |
|
|
639 |
class ClassGroupDefault(ClassGroup): |
class ClassGroupDefault(ClassGroup): |
640 |
"""The default Group. When values do not match any other |
"""The default Group. When values do not match any other |
641 |
Group within a Classification, the properties from this |
Group within a Classification, the properties from this |
642 |
class are used.""" |
class are used.""" |
643 |
|
|
644 |
def __init__(self, prop = None, label = ""): |
def __init__(self, props = None, label = "", group = None): |
645 |
"""Constructor. |
"""Constructor. |
646 |
|
|
647 |
prop -- a ClassGroupProperites object. If prop is None a default |
prop -- a ClassGroupProperites object. If prop is None a default |
650 |
label -- a label for this group. |
label -- a label for this group. |
651 |
""" |
""" |
652 |
|
|
653 |
ClassGroup.__init__(self, label) |
ClassGroup.__init__(self, label, props, group) |
|
self.SetProperties(prop) |
|
654 |
|
|
655 |
def __copy__(self): |
def __copy__(self): |
656 |
return ClassGroupDefault(self.GetProperties(), self.GetLabel()) |
return ClassGroupDefault(self.GetProperties(), self.GetLabel()) |
657 |
|
|
658 |
def __deepcopy__(self, memo): |
def __deepcopy__(self, memo): |
659 |
return ClassGroupDefault(copy.copy(self.GetProperties()), |
return ClassGroupDefault(label = self.GetLabel(), group = self) |
|
copy.copy(self.GetLabel())) |
|
660 |
|
|
661 |
def Matches(self, value): |
def Matches(self, value): |
662 |
return True |
return True |
663 |
|
|
|
def GetProperties(self): |
|
|
"""Return the Properties associated with this Group.""" |
|
|
return self.prop |
|
|
|
|
|
def SetProperties(self, prop): |
|
|
"""Set the properties associated with this Group. |
|
|
|
|
|
prop -- a ClassGroupProperties object. if prop is None, |
|
|
a default set of properties is created. |
|
|
""" |
|
|
|
|
|
if prop is None: prop = ClassGroupProperties() |
|
|
assert isinstance(prop, ClassGroupProperties) |
|
|
self.prop = prop |
|
|
|
|
664 |
def GetDisplayText(self): |
def GetDisplayText(self): |
665 |
label = self.GetLabel() |
label = self.GetLabel() |
666 |
|
|
667 |
if label != "": return label |
if label != "": return label |
668 |
|
|
669 |
return "DEFAULT" |
return _("DEFAULT") |
670 |
|
|
671 |
def __eq__(self, other): |
def __eq__(self, other): |
672 |
return isinstance(other, ClassGroupDefault) \ |
return ClassGroup.__eq__(self, other) \ |
673 |
|
and isinstance(other, ClassGroupDefault) \ |
674 |
and self.GetProperties() == other.GetProperties() |
and self.GetProperties() == other.GetProperties() |
675 |
|
|
|
def __ne__(self, other): |
|
|
return not self.__eq__(other) |
|
|
|
|
676 |
class ClassGroupRange(ClassGroup): |
class ClassGroupRange(ClassGroup): |
677 |
"""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 |
678 |
set of properties.""" |
set of properties.""" |
679 |
|
|
680 |
def __init__(self, min = 0, max = 1, prop = None, label = ""): |
def __init__(self, min = 0, max = 1, props = None, label = "", group=None): |
681 |
"""Constructor. |
"""Constructor. |
682 |
|
|
683 |
The minumum value must be strictly less than the maximum. |
The minumum value must be strictly less than the maximum. |
692 |
label -- a label for this group. |
label -- a label for this group. |
693 |
""" |
""" |
694 |
|
|
695 |
ClassGroup.__init__(self, label) |
ClassGroup.__init__(self, label, props, group) |
696 |
|
|
697 |
self.min = self.max = 0 |
self.__min = self.__max = 0 |
|
self.prop = None |
|
698 |
|
|
699 |
self.SetRange(min, max) |
self.SetRange(min, max) |
|
self.SetProperties(prop) |
|
700 |
|
|
701 |
def __copy__(self): |
def __copy__(self): |
702 |
return ClassGroupRange(self.GetMin(), |
return ClassGroupRange(self.GetMin(), |
707 |
def __deepcopy__(self, memo): |
def __deepcopy__(self, memo): |
708 |
return ClassGroupRange(copy.copy(self.GetMin()), |
return ClassGroupRange(copy.copy(self.GetMin()), |
709 |
copy.copy(self.GetMax()), |
copy.copy(self.GetMax()), |
710 |
copy.copy(self.GetProperties()), |
group = self) |
|
copy.copy(self.GetLabel())) |
|
711 |
|
|
712 |
def GetMin(self): |
def GetMin(self): |
713 |
"""Return the range's minimum value.""" |
"""Return the range's minimum value.""" |
714 |
return self.min |
return self.__min |
715 |
|
|
716 |
def SetMin(self, min): |
def SetMin(self, min): |
717 |
"""Set the range's minimum value. |
"""Set the range's minimum value. |
720 |
maximum value. Use SetRange() to change both min and max values. |
maximum value. Use SetRange() to change both min and max values. |
721 |
""" |
""" |
722 |
|
|
723 |
self.SetRange(min, self.max) |
self.SetRange(min, self.__max) |
724 |
|
|
725 |
def GetMax(self): |
def GetMax(self): |
726 |
"""Return the range's maximum value.""" |
"""Return the range's maximum value.""" |
727 |
return self.max |
return self.__max |
728 |
|
|
729 |
def SetMax(self, max): |
def SetMax(self, max): |
730 |
"""Set the range's maximum value. |
"""Set the range's maximum value. |
732 |
max -- the new maximum. Note that this must be greater than the current |
max -- the new maximum. Note that this must be greater than the current |
733 |
minimum value. Use SetRange() to change both min and max values. |
minimum value. Use SetRange() to change both min and max values. |
734 |
""" |
""" |
735 |
self.SetRange(self.min, max) |
self.SetRange(self.__min, max) |
736 |
|
|
737 |
def SetRange(self, min, max): |
def SetRange(self, min, max): |
738 |
"""Set a new range. |
"""Set a new range. |
746 |
if min >= max: |
if min >= max: |
747 |
raise ValueError(_("ClassGroupRange: %i(min) >= %i(max)!") % |
raise ValueError(_("ClassGroupRange: %i(min) >= %i(max)!") % |
748 |
(min, max)) |
(min, max)) |
749 |
self.min = min |
self.__min = min |
750 |
self.max = max |
self.__max = max |
751 |
|
|
752 |
def GetRange(self): |
def GetRange(self): |
753 |
"""Return the range as a tuple (min, max)""" |
"""Return the range as a tuple (min, max)""" |
754 |
return (self.min, self.max) |
return (self.__min, self.__max) |
755 |
|
|
756 |
def Matches(self, value): |
def Matches(self, value): |
757 |
"""Determine if the given value lies with the current range. |
"""Determine if the given value lies with the current range. |
759 |
The following check is used: min <= value < max. |
The following check is used: min <= value < max. |
760 |
""" |
""" |
761 |
|
|
762 |
return self.min <= value < self.max |
return self.__min <= value < self.__max |
|
|
|
|
def GetProperties(self): |
|
|
"""Return the Properties associated with this Group.""" |
|
|
return self.prop |
|
|
|
|
|
def SetProperties(self, prop): |
|
|
"""Set the properties associated with this Group. |
|
|
|
|
|
prop -- a ClassGroupProperties object. if prop is None, |
|
|
a default set of properties is created. |
|
|
""" |
|
|
if prop is None: prop = ClassGroupProperties() |
|
|
assert isinstance(prop, ClassGroupProperties) |
|
|
self.prop = prop |
|
763 |
|
|
764 |
def GetDisplayText(self): |
def GetDisplayText(self): |
765 |
label = self.GetLabel() |
label = self.GetLabel() |
769 |
return _("%s - %s") % (self.GetMin(), self.GetMax()) |
return _("%s - %s") % (self.GetMin(), self.GetMax()) |
770 |
|
|
771 |
def __eq__(self, other): |
def __eq__(self, other): |
772 |
return isinstance(other, ClassGroupRange) \ |
return ClassGroup.__eq__(self, other) \ |
773 |
and self.GetProperties() == other.GetProperties() \ |
and isinstance(other, ClassGroupRange) \ |
774 |
and self.GetRange() == other.GetRange() |
and self.__min == other.__min \ |
775 |
|
and self.__max == other.__max |
|
def __ne__(self, other): |
|
|
return not self.__eq__(other) |
|
776 |
|
|
777 |
class ClassGroupMap(ClassGroup): |
class ClassGroupMap(ClassGroup): |
778 |
"""Currently, this class is not used.""" |
"""Currently, this class is not used.""" |