]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/ogl/_lines.py
frame should call skip on child focus event to give owner a chance
[wxWidgets.git] / wxPython / wx / lib / ogl / _lines.py
index dde563634dae09da0c86612590594c371553db78..fdee0ed6b5f400eb6b83058272cdea0d02a95a9a 100644 (file)
@@ -14,7 +14,7 @@
 import sys
 import math
 
 import sys
 import math
 
-from _basic import Shape, ShapeRegion, ControlPoint, RectangleShape
+from _basic import Shape, ShapeRegion, ShapeTextLine, ControlPoint, RectangleShape
 from _oglmisc import *
 
 # Line alignment flags
 from _oglmisc import *
 
 # Line alignment flags
@@ -131,7 +131,7 @@ class LabelShape(RectangleShape):
         RectangleShape.__init__(self, w, h)
         self._lineShape = parent
         self._shapeRegion = region
         RectangleShape.__init__(self, w, h)
         self._lineShape = parent
         self._shapeRegion = region
-        self.SetPen(wx.ThePenList.FindOrCreatePen(wx.Colour(0, 0, 0), 1, wx.DOT))
+        self.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1, wx.DOT))
 
     def OnDraw(self, dc):
         if self._lineShape and not self._lineShape.GetDrawHandles():
 
     def OnDraw(self, dc):
         if self._lineShape and not self._lineShape.GetDrawHandles():
@@ -220,7 +220,6 @@ class LineShape(Shape):
 
     def __del__(self):
         if self._lineControlPoints:
 
     def __del__(self):
         if self._lineControlPoints:
-            self.ClearPointList(self._lineControlPoints)
             self._lineControlPoints = []
         for i in range(3):
             if self._labelObjects[i]:
             self._lineControlPoints = []
         for i in range(3):
             if self._labelObjects[i]:
@@ -289,29 +288,32 @@ class LineShape(Shape):
 
     def MakeLineControlPoints(self, n):
         """Make a given number of control points (minimum of two)."""
 
     def MakeLineControlPoints(self, n):
         """Make a given number of control points (minimum of two)."""
-        if self._lineControlPoints:
-            self.ClearPointList(self._lineControlPoints)
         self._lineControlPoints = []
         
         for _ in range(n):
             point = wx.RealPoint(-999, -999)
             self._lineControlPoints.append(point)
 
         self._lineControlPoints = []
         
         for _ in range(n):
             point = wx.RealPoint(-999, -999)
             self._lineControlPoints.append(point)
 
+        # pi: added _initialised to keep track of when we have set
+        # the middle points to something other than (-999, -999)
         self._initialised = False
         
         self._initialised = False
         
-    def InsertLineControlPoint(self, dc = None):
-        """Insert a control point at an arbitrary position."""
+    def InsertLineControlPoint(self, dc = None, point = None):
+        """Insert a control point at an optional given position."""
         if dc:
             self.Erase(dc)
 
         if dc:
             self.Erase(dc)
 
-        last_point = self._lineControlPoints[-1]
-        second_last_point = self._lineControlPoints[-2]
+        if point:
+            line_x, line_y = point
+        else:
+            last_point = self._lineControlPoints[-1]
+            second_last_point = self._lineControlPoints[-2]
 
 
-        line_x = (last_point[0] + second_last_point[0]) / 2.0
-        line_y = (last_point[1] + second_last_point[1]) / 2.0
+            line_x = (last_point[0] + second_last_point[0]) / 2.0
+            line_y = (last_point[1] + second_last_point[1]) / 2.0
 
         point = wx.RealPoint(line_x, line_y)
 
         point = wx.RealPoint(line_x, line_y)
-        self._lineControlPoints.insert(len(self._lineControlPoints), point)
+        self._lineControlPoints.insert(len(self._lineControlPoints)-1, point)
 
     def DeleteLineControlPoint(self):
         """Delete an arbitary point on the line."""
 
     def DeleteLineControlPoint(self):
         """Delete an arbitary point on the line."""
@@ -506,7 +508,7 @@ class LineShape(Shape):
         first_point = self._lineControlPoints[0]
         last_point = self._lineControlPoints[-1]
 
         first_point = self._lineControlPoints[0]
         last_point = self._lineControlPoints[-1]
 
-        return (first_point[0], first_point[1]), (last_point[0], last_point[1])
+        return first_point[0], first_point[1], last_point[0], last_point[1]
 
     def SetAttachments(self, from_attach, to_attach):
         """Specify which object attachment points should be used at each end
 
     def SetAttachments(self, from_attach, to_attach):
         """Specify which object attachment points should be used at each end
@@ -913,6 +915,14 @@ class LineShape(Shape):
 
         oldX, oldY = self._xpos, self._ypos
 
 
         oldX, oldY = self._xpos, self._ypos
 
+        # pi: The first time we go through FindLineEndPoints we can't
+        # use the middle points (since they don't have sane values),
+        # so we just do what we do for a normal line. Then we call
+        # Initialise to set the middle points, and then FindLineEndPoints
+        # again, but this time (and from now on) we use the middle
+        # points to calculate the end points.
+        # This was buggy in the C++ version too.
+        
         self.SetEnds(end_x, end_y, other_end_x, other_end_y)
 
         if len(self._lineControlPoints) > 2:
         self.SetEnds(end_x, end_y, other_end_x, other_end_y)
 
         if len(self._lineControlPoints) > 2:
@@ -949,7 +959,9 @@ class LineShape(Shape):
         # manually if necessary.
         second_point = self._lineControlPoints[1]
         second_last_point = self._lineControlPoints[-2]
         # manually if necessary.
         second_point = self._lineControlPoints[1]
         second_last_point = self._lineControlPoints[-2]
-        
+
+        # pi: If we have a segmented line and this is the first time,
+        # do this as a straight line.
         if len(self._lineControlPoints) > 2 and self._initialised:
             if self._from.GetAttachmentMode() != ATTACHMENT_MODE_NONE:
                 nth, no_arcs = self.FindNth(self._from, False) # Not incoming
         if len(self._lineControlPoints) > 2 and self._initialised:
             if self._from.GetAttachmentMode() != ATTACHMENT_MODE_NONE:
                 nth, no_arcs = self.FindNth(self._from, False) # Not incoming
@@ -1015,7 +1027,7 @@ class LineShape(Shape):
         # Problem with pen - if not a solid pen, does strange things
         # to the arrowhead. So make (get) a new pen that's solid.
         if self._pen and self._pen.GetStyle() != wx.SOLID:
         # Problem with pen - if not a solid pen, does strange things
         # to the arrowhead. So make (get) a new pen that's solid.
         if self._pen and self._pen.GetStyle() != wx.SOLID:
-            solid_pen = wx.ThePenList.FindOrCreatePen(self._pen.GetColour(), 1, wx.SOLID)
+            solid_pen = wx.Pen(self._pen.GetColour(), 1, wx.SOLID)
             if solid_pen:
                 dc.SetPen(solid_pen)
 
             if solid_pen:
                 dc.SetPen(solid_pen)
 
@@ -1366,7 +1378,7 @@ class LineShape(Shape):
         """
         for arrow in self._arcArrows:
             if (position == -1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
         """
         for arrow in self._arcArrows:
             if (position == -1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
-                return arow
+                return arrow
 
         return None
 
 
         return None
 
@@ -1502,12 +1514,7 @@ class LineShape(Shape):
         labelShape._shapeRegion.SetSize(labelShape.GetWidth(), labelShape.GetHeight())
 
         # Find position in line's region list
         labelShape._shapeRegion.SetSize(labelShape.GetWidth(), labelShape.GetHeight())
 
         # Find position in line's region list
-        i = 0
-        for region in self.GetRegions():
-            if labelShape._shapeRegion == region:
-                self.GetRegions().remove(region)
-            else:
-                i += 1
+        i = self._regions.index(labelShape._shapeRegion)
                 
         xx, yy = self.GetLabelPosition(i)
         # Set the region's offset, relative to the default position for
                 
         xx, yy = self.GetLabelPosition(i)
         # Set the region's offset, relative to the default position for