[Thuban-devel] an oopsie?

Jan-Oliver Wagner jan at intevation.de
Mon Dec 27 15:01:50 CET 2004


On Fri, Dec 24, 2004 at 01:56:18AM -0500, Russell Nelson wrote:
> Hmmmmm.  Thuban/Model/map.py says this:
> 
>     def Layers(self):
>         """Return the list of layers contained in the map.
> 
>         The list does not include the label layer"""
>         return self.layers
> 
> and yet later does this in BoundingBox:
> 
>         for layer in self.layers:
>             if layer is self.label_layer:
>                 continue
> 
> I can't see how both of those can be correct.  If the first is wrong,
> there might be a bug hiding.  If the second is wrong, it's just a few
> wasted cycles.

I think it is the second.
Attached is a patch that primarily adds/extends doc strings
and removes the above mentioned lines as well as adds LabelLayer
to the TreeInfo output.

Bernhard Herzog: OK to commit?
If so, OK to backport to 1_0?

Best

	Jan
-- 
Jan-Oliver Wagner               http://intevation.de/~jan/

Intevation GmbH                      http://intevation.de/
FreeGIS                                http://freegis.org/
-------------- next part --------------
Index: Thuban/Model/map.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/map.py,v
retrieving revision 1.18
diff -u -3 -p -r1.18 map.py
--- Thuban/Model/map.py	10 Jul 2003 14:53:15 -0000	1.18
+++ Thuban/Model/map.py	27 Dec 2004 13:58:37 -0000
@@ -21,7 +21,9 @@ from label import LabelLayer
 
 class Map(TitledObject, Modifiable):
 
-    """Represent a map. A map is simply a list of layers.
+    """Represent a map. A map is a list of layers. Additionally
+    there is a special label layer containing all labels that
+    are defined for the map.
 
     Map objects send the following message types:
 
@@ -50,10 +52,14 @@ class Map(TitledObject, Modifiable):
         self.projection = projection
 
     def Destroy(self):
-        # call Modifiable.Destroy first since it will call
-        # Publisher.Destroy which removes all subscriptions. Otherwise
-        # clearing the layers results in messages to be sent which can
-        # cause problems.
+        """Destroys the map object with all layers including
+        the label layer.
+
+        Calls Modifiable.Destroy first since it will call
+        Publisher.Destroy which removes all subscriptions. Otherwise
+        clearing the layers results in messages to be sent which can
+        cause problems.
+        """
         Modifiable.Destroy(self)
         self.ClearLayers()
         self.label_layer.Unsubscribe(CHANGED, self.forward, MAP_LAYERS_CHANGED)
@@ -67,7 +73,9 @@ class Map(TitledObject, Modifiable):
         self.changed(MAP_LAYERS_ADDED, self)
 
     def RemoveLayer(self, layer):
-        """Remove layer from the map."""
+        """Remove layer from the map.
+        This can not be applied for the label layer of the map.
+        """
         self.unsubscribe_layer_channels(layer)
         self.layers.remove(layer)
         self.changed(MAP_LAYERS_CHANGED, self)
@@ -84,7 +92,9 @@ class Map(TitledObject, Modifiable):
         return 1
 
     def ClearLayers(self):
-        """Delete all layers."""
+        """Delete all layers and also remove all labels from the
+        label layer.
+        """
         for layer in self.layers:
             self.unsubscribe_layer_channels(layer)
             layer.Destroy()
@@ -110,15 +120,18 @@ class Map(TitledObject, Modifiable):
     def Layers(self):
         """Return the list of layers contained in the map.
 
-        The list does not include the label layer"""
+        The list does not include the label layer which
+        can be retrieved by a separate method."""
         return self.layers
 
     def HasLayers(self):
-        """Return true if the map has at least one shape layer"""
+        """Return true if the map has at least one layer other
+        than the label layer."""
         return len(self.layers) > 0
 
     def MoveLayerToTop(self, layer):
-        """Put the layer on top of the layer stack.
+        """Put the layer on top of the layer stack. This can not
+        be applied to the label layer.
 
         If the layer is already at the top do nothing. If the stacking
         order has been changed, issue a MAP_LAYERS_CHANGED message.
@@ -130,9 +143,9 @@ class Map(TitledObject, Modifiable):
             self.changed(MAP_LAYERS_CHANGED, self)
             self.changed(MAP_STACKING_CHANGED, self)
 
-        
     def RaiseLayer(self, layer):
-        """Swap the layer with the one above it.
+        """Swap the layer with the one above it. This does
+        not apply to the label layer.
 
         If the layer is already at the top do nothing. If the stacking
         order has been changed, issue a MAP_LAYERS_CHANGED message.
@@ -145,7 +158,8 @@ class Map(TitledObject, Modifiable):
             self.changed(MAP_STACKING_CHANGED, self)
 
     def LowerLayer(self, layer):
-        """Swap the layer with the one below it.
+        """Swap the layer with the one below it. This does
+        not apply to the label layer.
 
         If the layer is already at the bottom do nothing. If the
         stacking order has been changed, issue a MAP_LAYERS_CHANGED message.
@@ -158,7 +172,8 @@ class Map(TitledObject, Modifiable):
             self.changed(MAP_STACKING_CHANGED, self)
 
     def MoveLayerToBottom(self, layer):
-        """Put the layer at the bottom of the stack.
+        """Put the layer at the bottom of the stack. This does
+        not apply to the label layer.
 
         If the layer is already at the bottom do nothing. If the
         stacking order has been changed, issue a MAP_LAYERS_CHANGED message.
@@ -172,8 +187,11 @@ class Map(TitledObject, Modifiable):
 
     def BoundingBox(self):
         """Return the bounding box of the map in Lat/Lon coordinates.
+        The label layer is not considered for the computation of the
+        bounding box.
 
-        Return None if there are no layers or no layer contains any shapes.
+        Return None if there are no layers (except the label layer) or
+        no layer contains any shapes.
         """
         if not self.layers:
             return None
@@ -182,8 +200,6 @@ class Map(TitledObject, Modifiable):
         urx = []
         ury = []
         for layer in self.layers:
-            if layer is self.label_layer:
-                continue
             # the layer's bbox may be None if it doesn't have any shapes
             bbox = layer.LatLongBoundingBox()
             if bbox is not None:
@@ -201,8 +217,11 @@ class Map(TitledObject, Modifiable):
 
     def ProjectedBoundingBox(self):
         """Return the bounding box of the map in projected coordinates.
+        The label layer is not considered for the computation of the
+        bounding box.
 
-        Return None if there are no layers or no layer contains any shapes.
+        Return None if there are no layers (except the label layer) or
+        no layer contains any shapes.
         """
         # This simply returns the rectangle given by the projected
         # corners of the non-projected bbox.
@@ -212,6 +231,7 @@ class Map(TitledObject, Modifiable):
         return bbox
 
     def GetProjection(self):
+        """Return the projection of the map."""
         return self.projection
 
     def SetProjection(self, projection):
@@ -246,6 +266,9 @@ class Map(TitledObject, Modifiable):
         self.label_layer.UnsetModified()
 
     def TreeInfo(self):
+        """Return a tuple of (title, tupel) describing the contents
+        of the object in a tree-structure.
+        """
         items = []
         if self.BoundingBox() != None:
             items.append(_("Extent (lat-lon): (%g, %g, %g, %g)")
@@ -260,6 +283,6 @@ class Map(TitledObject, Modifiable):
         layers = self.layers[:]
         layers.reverse()
         items.extend(layers)
+        items.append(self.label_layer)
 
         return (_("Map: %s") % self.title, items)
-
Index: Thuban/Model/label.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/label.py,v
retrieving revision 1.2
diff -u -3 -p -r1.2 label.py
--- Thuban/Model/label.py	30 Jul 2002 14:15:39 -0000	1.2
+++ Thuban/Model/label.py	27 Dec 2004 13:58:37 -0000
@@ -7,6 +7,8 @@
 
 __version__ = "$Revision: 1.2 $"
 
+from Thuban import _
+
 from messages import CHANGED
 
 from base import TitledObject, Modifiable
@@ -20,7 +22,13 @@ ALIGN_BASELINE = "baseline"
 
 class Label:
 
+    """This class repesents a single label that is
+    defined by its coordinate, the text as well
+    as vertical and horizontal alignment concerning
+    the coordinate."""
+
     def __init__(self, x, y, text, halign, valign):
+        """Initialize the label with the given parameters."""
         self.x = x
         self.y = y
         self.text = text
@@ -30,23 +38,49 @@ class Label:
 
 class LabelLayer(TitledObject, Modifiable):
 
+    """This represent a layer holding a number of labels."""
+
     def __init__(self, title):
+        """Initialize the LabeleLayer with an empty
+        list of labels and set the title to "title".
+        """
         TitledObject.__init__(self, title)
         Modifiable.__init__(self)
         self.labels = []
 
     def Labels(self):
+        """Return a list of all labels."""
         return self.labels
 
-    def AddLabel(self, x, y, text, halign = "left", valign="center"):
+    def AddLabel(self, x, y, text, halign = ALIGN_LEFT,
+                 valign = ALIGN_CENTER):
+        """Add a label at position (x,y) with contents "text".
+
+        This will emit a CHANGED signal.
+        """
         self.labels.append(Label(x, y, text, halign, valign))
         self.changed(CHANGED)
 
     def RemoveLabel(self, index):
+        """Remove the label specified by index.
+
+        This will emit a CHANGED signal.
+        """
         del self.labels[index]
         self.changed(CHANGED)
 
     def ClearLabels(self):
-        """Remove all labels"""
+        """Remove all labels.
+
+        This will emit a CHANGED signal.
+        """
         del self.labels[:]
         self.changed(CHANGED)
+
+    def TreeInfo(self):
+        """Return a tuple of (title, tupel) describing the contents
+        of the object in a tree-structure.
+        """
+        items = []
+        items.append(_("Number of labels: %d") % len(self.labels))
+        return (_("Label Layer: %s") % self.title, items)


More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)