Bug with PowerRail resize fixed
authorlbessard
Sun, 07 Sep 2008 19:21:39 +0200
changeset 254 27abdcf9a460
parent 253 d9391572655f
child 255 068935254b28
Bug with PowerRail resize fixed
graphics/LD_Objects.py
--- a/graphics/LD_Objects.py	Sun Sep 07 15:29:12 2008 +0200
+++ b/graphics/LD_Objects.py	Sun Sep 07 19:21:39 2008 +0200
@@ -269,9 +269,14 @@
     def OnLeftDown(self, event, dc, scaling):
         self.RealConnectors = []
         height = self.Size[1] - self.Extensions[0] - self.Extensions[1]
-        for connector in self.Connectors:
-            position = connector.GetRelPosition()
-            self.RealConnectors.append(float(position.y - self.Extensions[0])/float(max(1, height)))
+        if height > 0:
+            for connector in self.Connectors:
+                position = connector.GetRelPosition()
+                self.RealConnectors.append(max(0., min(float(position.y - self.Extensions[0]) / float(height), 1.)))
+        elif len(self.Connectors) > 1:
+            self.RealConnectors = map(lambda x : x * 1 / (len(self.Connectors) - 1), xrange(len(self.Connectors)))
+        else:
+            self.RealConnectors = [0.5]
         Graphic_Element.OnLeftDown(self, event, dc, scaling)
     
     # Method called when a LeftUp event have been generated
@@ -315,7 +320,10 @@
     
     def Resize(self, x, y, width, height):
         self.Move(x, y)
-        self.SetSize(LD_POWERRAIL_WIDTH, height)
+        if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
+            self.SetSize(width, height)
+        else:
+            self.SetSize(LD_POWERRAIL_WIDTH, height)
 
     # Refreshes the powerrail state according to move defined and handle selected
     def ProcessDragging(self, movex, movey, centered, scaling):