From: Robin Dunn Date: Fri, 18 Jun 2004 16:32:03 +0000 (+0000) Subject: Patch from Pierre Hjälm. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a2df8090e8f9f53ce5211f7037c632f792fed9be Patch from Pierre Hjälm. """ It removes "from __future__ import division", fixes a couple of bugs and adds a lot of whitespace. Since I also removed an instance of [::-1] for list reversing, I think this ought to work on older pythons (I have not tested though). """ git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27884 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/wxPython/wx/lib/ogl/__init__.py b/wxPython/wx/lib/ogl/__init__.py index c295f49323..42da15c237 100644 --- a/wxPython/wx/lib/ogl/__init__.py +++ b/wxPython/wx/lib/ogl/__init__.py @@ -14,7 +14,7 @@ from _composit import * # Set things up for documenting with epydoc. The __docfilter__ will -# prevent some things from beign documented, and anything in __all__ +# prevent some things from being documented, and anything in __all__ # will appear to actually exist in this module. import wx._core as _wx __docfilter__ = _wx.__DocFilter(globals()) diff --git a/wxPython/wx/lib/ogl/_basic.py b/wxPython/wx/lib/ogl/_basic.py index 250e8f9422..e0d5c7307f 100644 --- a/wxPython/wx/lib/ogl/_basic.py +++ b/wxPython/wx/lib/ogl/_basic.py @@ -11,8 +11,6 @@ # Licence: wxWindows license #---------------------------------------------------------------------------- -from __future__ import division - import wx import math @@ -254,7 +252,7 @@ class Shape(ShapeEvtHandler): self._shadowBrush = wx.BLACK_BRUSH self._textMarginX = 5 self._textMarginY = 5 - self._regionName="0" + self._regionName = "0" self._centreResize = True self._maintainAspectRatio = False self._highlighted = False @@ -431,8 +429,8 @@ class Shape(ShapeEvtHandler): def ClearText(self, regionId = 0): """Clear the text from the specified text region.""" if regionId == 0: - self._text="" - if regionIdlen(self._regions): + if i > len(self._regions): return region = self._regions[i] @@ -595,7 +593,7 @@ class Shape(ShapeEvtHandler): def SetFont(self, the_font, regionId = 0): """Set the font for the specified text region.""" self._font = the_font - if regionId-1: + if id > -1: return self, id for child in self._children: @@ -696,7 +694,7 @@ class Shape(ShapeEvtHandler): if actualImage: return actualImage, regionId - return None,-1 + return None, -1 # Finds all region names for this image (composite or simple). def FindRegionNames(self): @@ -782,8 +780,8 @@ class Shape(ShapeEvtHandler): minX, minY = self.GetBoundingBoxMin() maxX, maxY = self.GetBoundingBoxMax() - topLeftX = xp - maxX / 2 - 2 - topLeftY = yp - maxY / 2 - 2 + topLeftX = xp - maxX / 2.0 - 2 + topLeftY = yp - maxY / 2.0 - 2 penWidth = 0 if self._pen: @@ -794,7 +792,7 @@ class Shape(ShapeEvtHandler): dc.DrawRectangle(topLeftX - penWidth, topLeftY - penWidth, maxX + penWidth * 2 + 4, maxY + penWidth * 2 + 4) - def EraseLinks(self, dc, attachment=-1, recurse = False): + def EraseLinks(self, dc, attachment = -1, recurse = False): """Erase links attached to this shape, but do not repair damage caused to other shapes. """ @@ -802,20 +800,20 @@ class Shape(ShapeEvtHandler): return for line in self._lines: - if attachment==-1 or (line.GetTo() == self and line.GetAttachmentTo() == attachment or line.GetFrom() == self and line.GetAttachmentFrom() == attachment): + if attachment == -1 or (line.GetTo() == self and line.GetAttachmentTo() == attachment or line.GetFrom() == self and line.GetAttachmentFrom() == attachment): line.GetEventHandler().OnErase(dc) if recurse: for child in self._children: child.EraseLinks(dc, attachment, recurse) - def DrawLinks(self, dc, attachment=-1, recurse = False): + def DrawLinks(self, dc, attachment = -1, recurse = False): """Draws any lines linked to this shape.""" if not self._visible: return for line in self._lines: - if attachment==-1 or (line.GetTo() == self and line.GetAttachmentTo() == attachment or line.GetFrom() == self and line.GetAttachmentFrom() == attachment): + if attachment == -1 or (line.GetTo() == self and line.GetAttachmentTo() == attachment or line.GetFrom() == self and line.GetAttachmentFrom() == attachment): line.GetEventHandler().Draw(dc) if recurse: @@ -878,8 +876,8 @@ class Shape(ShapeEvtHandler): # it to another position in the list del newOrdering[newOrdering.index(to_move)] - old_x=-99999.9 - old_y=-99999.9 + old_x = -99999.9 + old_y = -99999.9 found = False @@ -1048,7 +1046,7 @@ class Shape(ShapeEvtHandler): hit = self._parent.HitTest(x, y) if hit: attachment, dist = hit - self._parent.GetEventHandler().OnEndDragLeft(x, y, keys, attachment) + self._parent.GetEventHandler().OnEndDragLeft(x, y, keys, attachment) return dc = wx.ClientDC(self.GetCanvas()) @@ -1088,14 +1086,13 @@ class Shape(ShapeEvtHandler): return def OnDrawOutline(self, dc, x, y, w, h): - points = [[x - w / 2, y - h / 2], - [x + w / 2, y - h / 2], - [x + w / 2, y + h / 2], - [x - w / 2, y + h / 2], - [x - w / 2, y - h / 2], + points = [[x - w / 2.0, y - h / 2.0], + [x + w / 2.0, y - h / 2.0], + [x + w / 2.0, y + h / 2.0], + [x - w / 2.0, y + h / 2.0], + [x - w / 2.0, y - h / 2.0], ] - #dc.DrawLines([[round(x), round(y)] for x, y in points]) dc.DrawLines(points) def Attach(self, can): @@ -1197,18 +1194,18 @@ class Shape(ShapeEvtHandler): if width == 0: scaleX = 1.0 else: - scaleX = long(w) / width + scaleX = float(w) / width if height == 0: scaleY = 1.0 else: - scaleY = long(h) / height + scaleY = float(h) / height for point in self._attachmentPoints: point._x = point._x * scaleX point._y = point._y * scaleY # Add line FROM this object - def AddLine(self, line, other, attachFrom = 0, attachTo = 0, positionFrom=-1, positionTo=-1): + def AddLine(self, line, other, attachFrom = 0, attachTo = 0, positionFrom = -1, positionTo = -1): """Add a line between this shape and the given other shape, at the specified attachment points. @@ -1216,7 +1213,7 @@ class Shape(ShapeEvtHandler): so that the line will be drawn at a particular point on its attachment point. """ - if positionFrom==-1: + if positionFrom == -1: if not line in self._lines: self._lines.append(line) else: @@ -1225,12 +1222,12 @@ class Shape(ShapeEvtHandler): self._lines.remove(line) except ValueError: pass - if positionFrommaxN: + if point._id > maxN: maxN = point._id return maxN + 1 @@ -1492,10 +1489,10 @@ class Shape(ShapeEvtHandler): else: # Assume is rectangular w, h = self.GetBoundingBoxMax() - top = self._ypos + h / 2 - bottom = self._ypos - h / 2 - left = self._xpos - w / 2 - right = self._xpos + w / 2 + top = self._ypos + h / 2.0 + bottom = self._ypos - h / 2.0 + left = self._xpos - w / 2.0 + right = self._xpos + w / 2.0 # wtf? line and line.IsEnd(self) @@ -1583,7 +1580,7 @@ class Shape(ShapeEvtHandler): isHorizontal = RoughlyEqual(pt1[1], pt2[1]) if isHorizontal: - if pt1[0]>pt2[0]: + if pt1[0] > pt2[0]: firstPoint = pt2 secondPoint = pt1 else: @@ -1594,21 +1591,21 @@ class Shape(ShapeEvtHandler): if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE: # Align line according to the next handle along point = line.GetNextControlPoint(self) - if point[0]secondPoint[0]: + elif point[0] > secondPoint[0]: x = secondPoint[0] else: x = point[0] else: - x = firstPoint[0] + (nth + 1) * (secondPoint[0] - firstPoint[0]) / (noArcs + 1) + x = firstPoint[0] + (nth + 1) * (secondPoint[0] - firstPoint[0]) / (noArcs + 1.0) else: - x = (secondPoint[0] - firstPoint[0]) / 2 # Midpoint + x = (secondPoint[0] - firstPoint[0]) / 2.0 # Midpoint y = pt1[1] else: assert RoughlyEqual(pt1[0], pt2[0]) - if pt1[1]>pt2[1]: + if pt1[1] > pt2[1]: firstPoint = pt2 secondPoint = pt1 else: @@ -1619,16 +1616,16 @@ class Shape(ShapeEvtHandler): if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE: # Align line according to the next handle along point = line.GetNextControlPoint(self) - if point[1]secondPoint[1]: + elif point[1] > secondPoint[1]: y = secondPoint[1] else: y = point[1] else: - y = firstPoint[1] + (nth + 1) * (secondPoint[1] - firstPoint[1]) / (noArcs + 1) + y = firstPoint[1] + (nth + 1) * (secondPoint[1] - firstPoint[1]) / (noArcs + 1.0) else: - y = (secondPoint[1] - firstPoint[1]) / 2 # Midpoint + y = (secondPoint[1] - firstPoint[1]) / 2.0 # Midpoint x = pt1[0] return x, y @@ -1676,8 +1673,8 @@ class Shape(ShapeEvtHandler): neck.x = self.GetX() neck.y = root.y - self._branchNeckLength - shoulder1.x = root.x - totalBranchLength / 2 - shoulder2.x = root.x + totalBranchLength / 2 + shoulder1.x = root.x - totalBranchLength / 2.0 + shoulder2.x = root.x + totalBranchLength / 2.0 shoulder1.y = neck.y shoulder2.y = neck.y @@ -1688,14 +1685,14 @@ class Shape(ShapeEvtHandler): shoulder1.x = neck.x shoulder2.x = neck.x - shoulder1.y = neck.y - totalBranchLength / 2 - shoulder1.y = neck.y + totalBranchLength / 2 + shoulder1.y = neck.y - totalBranchLength / 2.0 + shoulder1.y = neck.y + totalBranchLength / 2.0 elif physicalAttachment == 2: neck.x = self.GetX() neck.y = root.y + self._branchNeckLength - shoulder1.x = root.x - totalBranchLength / 2 - shoulder2.x = root.x + totalBranchLength / 2 + shoulder1.x = root.x - totalBranchLength / 2.0 + shoulder2.x = root.x + totalBranchLength / 2.0 shoulder1.y = neck.y shoulder2.y = neck.y @@ -1706,8 +1703,8 @@ class Shape(ShapeEvtHandler): shoulder1.x = neck.x shoulder2.x = neck.x - shoulder1.y = neck.y - totalBranchLength / 2 - shoulder2.y = neck.y + totalBranchLength / 2 + shoulder1.y = neck.y - totalBranchLength / 2.0 + shoulder2.y = neck.y + totalBranchLength / 2.0 else: raise "Unrecognised attachment point in GetBranchingAttachmentInfo" return root, neck, shoulder1, shoulder2 @@ -1769,15 +1766,15 @@ class Shape(ShapeEvtHandler): # Assume that we have attachment points 0 to 3: top, right, bottom, left if physicalAttachment == 0: root.x = self.GetX() - root.y = self.GetY() - height / 2 + root.y = self.GetY() - height / 2.0 elif physicalAttachment == 1: - root.x = self.GetX() + width / 2 + root.x = self.GetX() + width / 2.0 root.y = self.GetY() elif physicalAttachment == 2: root.x = self.GetX() - root.y = self.GetY() + height / 2 + root.y = self.GetY() + height / 2.0 elif physicalAttachment == 3: - root.x = self.GetX() - width / 2 + root.x = self.GetX() - width / 2.0 root.y = self.GetY() else: raise "Unrecognised attachment point in GetBranchingAttachmentRoot" @@ -1802,7 +1799,7 @@ class Shape(ShapeEvtHandler): # Draw neck dc.DrawLine(root, neck) - if count>1: + if count > 1: # Draw shoulder-to-shoulder line dc.DrawLine(shoulder1, shoulder2) # Draw all the little branches @@ -1810,9 +1807,9 @@ class Shape(ShapeEvtHandler): pt, stemPt = self.GetBranchingAttachmentPoint(attachment, i) dc.DrawLine(stemPt, pt) - if self.GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB and count>1: - blobSize = 6 - dc.DrawEllipse(stemPt.x - blobSize / 2, stemPt.y - blobSize / 2, blobSize, blobSize) + if self.GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB and count > 1: + blobSize = 6.0 + dc.DrawEllipse(stemPt.x - blobSize / 2.0, stemPt.y - blobSize / 2.0, blobSize, blobSize) def OnDrawBranches(self, dc, erase = False): if self._attachmentMode != ATTACHMENT_MODE_BRANCHING: @@ -1841,17 +1838,17 @@ class Shape(ShapeEvtHandler): """ if RoughlyEqual(self.GetRotation(), 0): i = physicalAttachment - elif RoughlyEqual(self.GetRotation(), math.pi / 2): + elif RoughlyEqual(self.GetRotation(), math.pi / 2.0): i = physicalAttachment - 1 elif RoughlyEqual(self.GetRotation(), math.pi): i = physicalAttachment - 2 - elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2): + elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2.0): i = physicalAttachment - 3 else: # Can't handle -- assume the same return physicalAttachment - if i<0: + if i < 0: i += 4 return i @@ -1862,16 +1859,16 @@ class Shape(ShapeEvtHandler): """ if RoughlyEqual(self.GetRotation(), 0): i = logicalAttachment - elif RoughlyEqual(self.GetRotation(), math.pi / 2): + elif RoughlyEqual(self.GetRotation(), math.pi / 2.0): i = logicalAttachment + 1 elif RoughlyEqual(self.GetRotation(), math.pi): i = logicalAttachment + 2 - elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2): + elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2.0): i = logicalAttachment + 3 else: return logicalAttachment - if i>3: + if i > 3: i -= 4 return i @@ -1879,9 +1876,9 @@ class Shape(ShapeEvtHandler): def Rotate(self, x, y, theta): """Rotate about the given axis by the given amount in radians.""" self._rotation = theta - if self._rotation<0: + if self._rotation < 0: self._rotation += 2 * math.pi - elif self._rotation>2 * math.pi: + elif self._rotation > 2 * math.pi: self._rotation -= 2 * math.pi def GetBackgroundPen(self): @@ -2128,14 +2125,14 @@ class Shape(ShapeEvtHandler): newX1 = pt._controlPointDragStartX newX2 = newX1 + pt._controlPointDragStartWidth elif pt._type == CONTROL_POINT_DIAGONAL and (keys & KEY_SHIFT or self.GetMaintainAspectRatio()): - newH = (newX2 - newX1) * (pt._controlPointDragStartHeight / pt._controlPointDragStartWidth) - if self.GetY()>pt._controlPointDragStartY: + newH = (newX2 - newX1) * (float(pt._controlPointDragStartHeight) / pt._controlPointDragStartWidth) + if self.GetY() > pt._controlPointDragStartY: newY2 = newY1 + newH else: newY1 = newY2 - newH - newWidth = newX2 - newX1 - newHeight = newY2 - newY1 + newWidth = float(newX2 - newX1) + newHeight = float(newY2 - newY1) if pt._type == CONTROL_POINT_VERTICAL and self.GetMaintainAspectRatio(): newWidth = bound_x * (newHeight / bound_y) @@ -2143,8 +2140,8 @@ class Shape(ShapeEvtHandler): if pt._type == CONTROL_POINT_HORIZONTAL and self.GetMaintainAspectRatio(): newHeight = bound_y * (newWidth / bound_x) - pt._controlPointDragPosX = newX1 + newWidth / 2 - pt._controlPointDragPosY = newY1 + newHeight / 2 + pt._controlPointDragPosX = newX1 + newWidth / 2.0 + pt._controlPointDragPosY = newY1 + newHeight / 2.0 if self.GetFixedWidth(): newWidth = bound_x @@ -2168,20 +2165,20 @@ class Shape(ShapeEvtHandler): # Choose the 'opposite corner' of the object as the stationary # point in case this is non-centring resizing. - if pt.GetX()pt._controlPointDragStartY: + newH = (newX2 - newX1) * (float(pt._controlPointDragStartHeight) / pt._controlPointDragStartWidth) + if pt.GetY() > pt._controlPointDragStartY: newY2 = newY1 + newH else: newY1 = newY2 - newH - newWidth = newX2 - newX1 - newHeight = newY2 - newY1 + newWidth = float(newX2 - newX1) + newHeight = float(newY2 - newY1) if pt._type == CONTROL_POINT_VERTICAL and self.GetMaintainAspectRatio(): newWidth = bound_x * (newHeight / bound_y) @@ -2246,8 +2243,8 @@ class Shape(ShapeEvtHandler): if pt._type == CONTROL_POINT_HORIZONTAL and self.GetMaintainAspectRatio(): newHeight = bound_y * (newWidth / bound_x) - pt._controlPointDragPosX = newX1 + newWidth / 2 - pt._controlPointDragPosY = newY1 + newHeight / 2 + pt._controlPointDragPosX = newX1 + newWidth / 2.0 + pt._controlPointDragPosY = newY1 + newHeight / 2.0 if self.GetFixedWidth(): newWidth = bound_x @@ -2285,7 +2282,7 @@ class Shape(ShapeEvtHandler): # Recursively redraw links if we have a composite if len(self.GetChildren()): - self.DrawLinks(dc,-1, True) + self.DrawLinks(dc, -1, True) width, height = self.GetBoundingBoxMax() self.GetEventHandler().OnEndSize(width, height) @@ -2310,8 +2307,8 @@ class RectangleShape(Shape): self.SetDefaultRegionSize() def OnDraw(self, dc): - x1 = self._xpos - self._width / 2 - y1 = self._ypos - self._height / 2 + x1 = self._xpos - self._width / 2.0 + y1 = self._ypos - self._height / 2.0 if self._shadowMode != SHADOW_NONE: if self._shadowBrush: @@ -2440,19 +2437,19 @@ class PolygonShape(Shape): def CalculateBoundingBox(self): # Calculate bounding box at construction (and presumably resize) time left = 10000 - right=-10000 + right = -10000 top = 10000 - bottom=-10000 + bottom = -10000 for point in self._points: - if point.xright: + if point.x > right: right = point.x - if point.ybottom: + if point.y > bottom: bottom = point.y self._boundWidth = right - left @@ -2466,26 +2463,26 @@ class PolygonShape(Shape): box. """ left = 10000 - right=-10000 + right = -10000 top = 10000 - bottom=-10000 + bottom = -10000 for point in self._points: - if point.xright: + if point.x > right: right = point.x - if point.ybottom: + if point.y > bottom: bottom = point.y bwidth = right - left bheight = bottom - top - newCentreX = left + bwidth / 2 - newCentreY = top + bheight / 2 + newCentreX = left + bwidth / 2.0 + newCentreY = top + bheight / 2.0 for point in self._points: point.x -= newCentreX @@ -2529,7 +2526,7 @@ class PolygonShape(Shape): if e: xp, yp = e l = math.sqrt((xp - x) * (xp - x) + (yp - y) * (yp - y)) - if l= len(self._points) - 1: @@ -2596,7 +2593,7 @@ class PolygonShape(Shape): def DeletePolygonPoint(self, pos): """Delete the given control point.""" - if posy1 and point.y>0: + if y2 > y1 and point.y > 0: return point.x + self._xpos, point.y + self._ypos - elif y2maxN: + if point._id > maxN: maxN = point._id return maxN + 1 def GetAttachmentPosition(self, attachment, nth = 0, no_arcs = 1, line = None): - if self._attachmentMode == ATTACHMENT_MODE_EDGE and self._points and attachment= 0 and attachment= 0 and attachment < len(self._points): return True for point in self._attachmentPoints: @@ -2840,8 +2837,8 @@ class EllipseShape(Shape): if self._shadowBrush: dc.SetBrush(self._shadowBrush) dc.SetPen(TransparentPen) - dc.DrawEllipse(self._xpos - self.GetWidth() / 2 + self._shadowOffsetX, - self._ypos - self.GetHeight() / 2 + self._shadowOffsetY, + dc.DrawEllipse(self._xpos - self.GetWidth() / 2.0 + self._shadowOffsetX, + self._ypos - self.GetHeight() / 2.0 + self._shadowOffsetY, self.GetWidth(), self.GetHeight()) if self._pen: @@ -2851,7 +2848,7 @@ class EllipseShape(Shape): dc.SetPen(self._pen) if self._brush: dc.SetBrush(self._brush) - dc.DrawEllipse(self._xpos - self.GetWidth() / 2, self._ypos - self.GetHeight() / 2, self.GetWidth(), self.GetHeight()) + dc.DrawEllipse(self._xpos - self.GetWidth() / 2.0, self._ypos - self.GetHeight() / 2.0, self.GetWidth(), self.GetHeight()) def SetSize(self, x, y, recursive = True): self.SetAttachmentSize(x, y) @@ -2869,16 +2866,16 @@ class EllipseShape(Shape): return Shape.GetAttachmentPosition(self, attachment, nth, no_arcs, line) if self._attachmentMode != ATTACHMENT_MODE_NONE: - top = self._ypos + self._height / 2 - bottom = self._ypos - self._height / 2 - left = self._xpos - self._width / 2 - right = self._xpos + self._width / 2 + top = self._ypos + self._height / 2.0 + bottom = self._ypos - self._height / 2.0 + left = self._xpos - self._width / 2.0 + right = self._xpos + self._width / 2.0 physicalAttachment = self.LogicalToPhysicalAttachment(attachment) if physicalAttachment == 0: if self._spaceAttachments: - x = left + (nth + 1) * self._width / (no_arcs + 1) + x = left + (nth + 1) * self._width / (no_arcs + 1.0) else: x = self._xpos y = top @@ -2891,13 +2888,13 @@ class EllipseShape(Shape): elif physicalAttachment == 1: x = right if self._spaceAttachments: - y = bottom + (nth + 1) * self._height / (no_arcs + 1) + y = bottom + (nth + 1) * self._height / (no_arcs + 1.0) else: y = self._ypos return DrawArcToEllipse(self._xpos, self._ypos, self._width, self._height, self._xpos + self._width + 500, y, self._xpos, y) elif physicalAttachment == 2: if self._spaceAttachments: - x = left + (nth + 1) * self._width / (no_arcs + 1) + x = left + (nth + 1) * self._width / (no_arcs + 1.0) else: x = self._xpos y = bottom @@ -2905,7 +2902,7 @@ class EllipseShape(Shape): elif physicalAttachment == 3: x = left if self._spaceAttachments: - y = bottom + (nth + 1) * self._height / (no_arcs + 1) + y = bottom + (nth + 1) * self._height / (no_arcs + 1.0) else: y = self._ypos return DrawArcToEllipse(self._xpos, self._ypos, self._width, self._height, self._xpos - self._width - 500, y, self._xpos, y) @@ -2923,7 +2920,7 @@ class CircleShape(EllipseShape): self.SetMaintainAspectRatio(True) def GetPerimeterPoint(self, x1, y1, x2, y2): - return FindEndForCircle(self._width / 2, self._xpos, self._ypos, x2, y2) + return FindEndForCircle(self._width / 2.0, self._xpos, self._ypos, x2, y2) @@ -2966,7 +2963,7 @@ class ShapeRegion(object): new_line = ShapeTextLine(line.GetX(), line.GetY(), line.GetText()) self._formattedText.append(new_line) else: - self._regionText="" + self._regionText = "" self._font = NormalFont self._minHeight = 5.0 self._minWidth = 5.0 @@ -2975,12 +2972,12 @@ class ShapeRegion(object): self._x = 0.0 self._y = 0.0 - self._regionProportionX=-1.0 - self._regionProportionY=-1.0 + self._regionProportionX = -1.0 + self._regionProportionY = -1.0 self._formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT - self._regionName="" - self._textColour="BLACK" - self._penColour="BLACK" + self._regionName = "" + self._textColour = "BLACK" + self._penColour = "BLACK" self._penStyle = wx.SOLID self._actualColourObject = wx.TheColourDatabase.Find("BLACK") self._actualPenObject = None diff --git a/wxPython/wx/lib/ogl/_bmpshape.py b/wxPython/wx/lib/ogl/_bmpshape.py index 8a12d85a04..c239aab6dd 100644 --- a/wxPython/wx/lib/ogl/_bmpshape.py +++ b/wxPython/wx/lib/ogl/_bmpshape.py @@ -11,8 +11,6 @@ # Licence: wxWindows license #---------------------------------------------------------------------------- -from __future__ import division - from _basic import RectangleShape @@ -20,14 +18,14 @@ class BitmapShape(RectangleShape): """Draws a bitmap (non-resizable).""" def __init__(self): RectangleShape.__init__(self, 100, 50) - self._filename="" + self._filename = "" def OnDraw(self, dc): if not self._bitmap.Ok(): return - x = self._xpos-self._bitmap.GetWidth() / 2 - y = self._ypos-self._bitmap.GetHeight() / 2 + x = self._xpos - self._bitmap.GetWidth() / 2.0 + y = self._ypos - self._bitmap.GetHeight() / 2.0 dc.DrawBitmap(self._bitmap, x, y, True) def SetSize(self, w, h, recursive = True): diff --git a/wxPython/wx/lib/ogl/_canvas.py b/wxPython/wx/lib/ogl/_canvas.py index 105cfa22ab..a3e2f11898 100644 --- a/wxPython/wx/lib/ogl/_canvas.py +++ b/wxPython/wx/lib/ogl/_canvas.py @@ -11,8 +11,6 @@ # Licence: wxWindows license #---------------------------------------------------------------------------- -from __future__ import division - import wx from _lines import LineShape from _composit import * @@ -31,13 +29,13 @@ def WhollyContains(contains, contained): w1, h1 = contains.GetBoundingBoxMax() w2, h2 = contained.GetBoundingBoxMax() - left1 = xp1-w1 / 2.0 - top1 = yp1-h1 / 2.0 + left1 = xp1 - w1 / 2.0 + top1 = yp1 - h1 / 2.0 right1 = xp1 + w1 / 2.0 bottom1 = yp1 + h1 / 2.0 - left2 = xp2-w2 / 2.0 - top2 = yp2-h2 / 2.0 + left2 = xp2 - w2 / 2.0 + top2 = yp2 - h2 / 2.0 right2 = xp2 + w2 / 2.0 bottom2 = yp2 + h2 / 2.0 @@ -46,7 +44,7 @@ def WhollyContains(contains, contained): class ShapeCanvas(wx.ScrolledWindow): - def __init__(self, parent = None, id=-1, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.BORDER, name="ShapeCanvas"): + def __init__(self, parent = None, id = -1, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.BORDER, name = "ShapeCanvas"): wx.ScrolledWindow.__init__(self, parent, id, pos, size, style, name) self._shapeDiagram = None @@ -95,8 +93,8 @@ class ShapeCanvas(wx.ScrolledWindow): # If we're very close to the position we started dragging # from, this may not be an intentional drag at all. if dragging: - dx = abs(dc.LogicalToDeviceX(x-self._firstDragX)) - dy = abs(dc.LogicalToDeviceY(y-self._firstDragY)) + dx = abs(dc.LogicalToDeviceX(x - self._firstDragX)) + dy = abs(dc.LogicalToDeviceY(y - self._firstDragY)) if self._checkTolerance and (dx <= self.GetDiagram().GetMouseTolerance()) and (dy <= self.GetDiagram().GetMouseTolerance()): return # If we've ignored the tolerance once, then ALWAYS ignore @@ -270,7 +268,9 @@ class ShapeCanvas(wx.ScrolledWindow): # the other objects # (b) to find the control points FIRST if they exist - for object in self.GetDiagram().GetShapeList()[::-1]: + rl = self.GetDiagram().GetShapeList()[:] + rl.reverse() + for object in rl: # First pass for lines, which might be inside a container, so we # want lines to take priority over containers. This first loop # could fail if we clickout side a line, so then we'll @@ -288,12 +288,12 @@ class ShapeCanvas(wx.ScrolledWindow): # to specify the nearest point to the centre of the line # as our hit criterion, to give the user some room for # manouevre. - if dist= a-marg + return b <= a + marg and b >= a - marg def Evaluate(self): """Evaluate this constraint and return TRUE if anything changed.""" @@ -177,21 +175,21 @@ class Constraint(object): # Check if within the constraining object... if totalObjectHeight + (n + 1) * self._ySpacing <= minHeight: - spacingY = (minHeight-totalObjectHeight) / (n + 1) - startY = y-minHeight / 2 + spacingY = (minHeight - totalObjectHeight) / (n + 1.0) + startY = y - minHeight / 2.0 else: # Otherwise, use default spacing spacingY = self._ySpacing - startY = y-(totalObjectHeight + (n + 1) * spacingY) / 2 + startY = y - (totalObjectHeight + (n + 1) * spacingY) / 2.0 # Now position the objects changed = False for constrainedObject in self._constrainedObjects: width2, height2 = constrainedObject.GetBoundingBoxMax() - startY += spacingY + height2 / 2 + startY += spacingY + height2 / 2.0 if not self.Equals(startY, constrainedObject.GetY()): constrainedObject.Move(dc, constrainedObject.GetX(), startY, False) changed = True - startY += height2 / 2 + startY += height2 / 2.0 return changed elif self._constraintType == CONSTRAINT_CENTRED_HORIZONTALLY: n = len(self._constrainedObjects) @@ -201,22 +199,22 @@ class Constraint(object): totalObjectWidth += width2 # Check if within the constraining object... - if totalObjectWidth + (n + 1) * self._xSpacingmaxX: - maxX = child.GetX() + w / 2 - if child.GetX()-w / 2maxY: - maxY = child.GetY() + h / 2 - if child.GetY()-h / 2 maxX: + maxX = child.GetX() + w / 2.0 + if child.GetX() - w / 2.0 < minX: + minX = child.GetX() - w / 2.0 + if child.GetY() + h / 2.0 > maxY: + maxY = child.GetY() + h / 2.0 + if child.GetY() - h / 2.0 < minY: + minY = child.GetY() - h / 2.0 + + self._width = maxX - minX + self._height = maxY - minY + self._xpos = self._width / 2.0 + minX + self._ypos = self._height / 2.0 + minY def Recompute(self): """Recomputes any constraints associated with the object. If FALSE is @@ -661,7 +659,7 @@ class CompositeShape(RectangleShape): """ noIterations = 0 changed = True - while changed and noIterations<500: + while changed and noIterations < 500: changed = self.Constrain() noIterations += 1 @@ -783,17 +781,17 @@ class DivisionControlPoint(ControlPoint): divisionParent = division.GetParent() # Need to check it's within the bounds of the parent composite - x1 = divisionParent.GetX()-divisionParent.GetWidth() / 2 - y1 = divisionParent.GetY()-divisionParent.GetHeight() / 2 - x2 = divisionParent.GetX() + divisionParent.GetWidth() / 2 - y2 = divisionParent.GetY() + divisionParent.GetHeight() / 2 + x1 = divisionParent.GetX() - divisionParent.GetWidth() / 2.0 + y1 = divisionParent.GetY() - divisionParent.GetHeight() / 2.0 + x2 = divisionParent.GetX() + divisionParent.GetWidth() / 2.0 + y2 = divisionParent.GetY() + divisionParent.GetHeight() / 2.0 # Need to check it has not made the division zero or negative # width / height - dx1 = division.GetX()-division.GetWidth() / 2 - dy1 = division.GetY()-division.GetHeight() / 2 - dx2 = division.GetX() + division.GetWidth() / 2 - dy2 = division.GetY() + division.GetHeight() / 2 + dx1 = division.GetX() - division.GetWidth() / 2.0 + dy1 = division.GetY() - division.GetHeight() / 2.0 + dx2 = division.GetX() + division.GetWidth() / 2.0 + dy2 = division.GetY() + division.GetHeight() / 2.0 success = True if division.GetHandleSide() == DIVISION_SIDE_LEFT: @@ -895,10 +893,10 @@ class DivisionShape(CompositeShape): self._handleSide = DIVISION_SIDE_NONE self._leftSidePen = wx.BLACK_PEN self._topSidePen = wx.BLACK_PEN - self._leftSideColour="BLACK" - self._topSideColour="BLACK" - self._leftSideStyle="Solid" - self._topSideStyle="Solid" + self._leftSideColour = "BLACK" + self._topSideColour = "BLACK" + self._leftSideStyle = "Solid" + self._topSideStyle = "Solid" self.ClearRegions() def SetLeftSide(self, shape): @@ -994,13 +992,13 @@ class DivisionShape(CompositeShape): dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetBackgroundMode(wx.TRANSPARENT) - x1 = self.GetX()-self.GetWidth() / 2 - y1 = self.GetY()-self.GetHeight() / 2 - x2 = self.GetX() + self.GetWidth() / 2 - y2 = self.GetY() + self.GetHeight() / 2 + x1 = self.GetX() - self.GetWidth() / 2.0 + y1 = self.GetY() - self.GetHeight() / 2.0 + x2 = self.GetX() + self.GetWidth() / 2.0 + y2 = self.GetY() + self.GetHeight() / 2.0 # Should subtract 1 pixel if drawing under Windows - if sys.platform[:3]=="win": + if sys.platform[:3] == "win": y2 -= 1 if self._leftSide: @@ -1020,8 +1018,8 @@ class DivisionShape(CompositeShape): CompositeShape.OnDrawContents(self, dc) def OnMovePre(self, dc, x, y, oldx, oldy, display = True): - diffX = x-oldx - diffY = y-oldy + diffX = x - oldx + diffY = y - oldy for object in self._children: object.Erase(dc) object.Move(dc, object.GetX() + diffX, object.GetY() + diffY, display) @@ -1100,8 +1098,8 @@ class DivisionShape(CompositeShape): vertically (direction is wxVERTICAL). """ # Calculate existing top-left, bottom-right - x1 = self.GetX()-self.GetWidth() / 2 - y1 = self.GetY()-self.GetHeight() / 2 + x1 = self.GetX() - self.GetWidth() / 2.0 + y1 = self.GetY() - self.GetHeight() / 2.0 compositeParent = self.GetParent() oldWidth = self.GetWidth() @@ -1117,9 +1115,9 @@ class DivisionShape(CompositeShape): # line through it. # Break existing piece into two. newXPos1 = self.GetX() - newYPos1 = y1 + self.GetHeight() / 4 + newYPos1 = y1 + self.GetHeight() / 4.0 newXPos2 = self.GetX() - newYPos2 = y1 + 3 * self.GetHeight() / 4 + newYPos2 = y1 + 3 * self.GetHeight() / 4.0 newDivision = compositeParent.OnCreateDivision() newDivision.Show(True) @@ -1153,18 +1151,18 @@ class DivisionShape(CompositeShape): self._handleSide = DIVISION_SIDE_BOTTOM newDivision.SetHandleSide(DIVISION_SIDE_TOP) - self.SetSize(oldWidth, oldHeight / 2) + self.SetSize(oldWidth, oldHeight / 2.0) self.Move(dc, newXPos1, newYPos1) - newDivision.SetSize(oldWidth, oldHeight / 2) + newDivision.SetSize(oldWidth, oldHeight / 2.0) newDivision.Move(dc, newXPos2, newYPos2) else: # Dividing horizontally means notionally putting a vertical line # through it. # Break existing piece into two. - newXPos1 = x1 + self.GetWidth() / 4 + newXPos1 = x1 + self.GetWidth() / 4.0 newYPos1 = self.GetY() - newXPos2 = x1 + 3 * self.GetWidth() / 4 + newXPos2 = x1 + 3 * self.GetWidth() / 4.0 newYPos2 = self.GetY() newDivision = compositeParent.OnCreateDivision() newDivision.Show(True) @@ -1189,10 +1187,10 @@ class DivisionShape(CompositeShape): self._handleSide = DIVISION_SIDE_RIGHT newDivision.SetHandleSide(DIVISION_SIDE_LEFT) - self.SetSize(oldWidth / 2, oldHeight) + self.SetSize(oldWidth / 2.0, oldHeight) self.Move(dc, newXPos1, newYPos1) - newDivision.SetSize(oldWidth / 2, oldHeight) + newDivision.SetSize(oldWidth / 2.0, oldHeight) newDivision.Move(dc, newXPos2, newYPos2) if compositeParent.Selected(): @@ -1212,16 +1210,16 @@ class DivisionShape(CompositeShape): direction = 0 if self._handleSide == DIVISION_SIDE_LEFT: - x=-maxX / 2 + x = -maxX / 2.0 direction = CONTROL_POINT_HORIZONTAL elif self._handleSide == DIVISION_SIDE_TOP: - y=-maxY / 2 + y = -maxY / 2.0 direction = CONTROL_POINT_VERTICAL elif self._handleSide == DIVISION_SIDE_RIGHT: - x = maxX / 2 + x = maxX / 2.0 direction = CONTROL_POINT_HORIZONTAL elif self._handleSide == DIVISION_SIDE_BOTTOM: - y = maxY / 2 + y = maxY / 2.0 direction = CONTROL_POINT_VERTICAL if self._handleSide != DIVISION_SIDE_NONE: @@ -1241,20 +1239,20 @@ class DivisionShape(CompositeShape): node = self._controlPoints[0] if self._handleSide == DIVISION_SIDE_LEFT and node: - node._xoffset=-maxX / 2 + node._xoffset = -maxX / 2.0 node._yoffset = 0.0 if self._handleSide == DIVISION_SIDE_TOP and node: node._xoffset = 0.0 - node._yoffset=-maxY / 2 + node._yoffset = -maxY / 2.0 if self._handleSide == DIVISION_SIDE_RIGHT and node: - node._xoffset = maxX / 2 + node._xoffset = maxX / 2.0 node._yoffset = 0.0 if self._handleSide == DIVISION_SIDE_BOTTOM and node: node._xoffset = 0.0 - node._yoffset = maxY / 2 + node._yoffset = maxY / 2.0 def AdjustLeft(self, left, test): """Adjust a side. @@ -1262,7 +1260,7 @@ class DivisionShape(CompositeShape): Returns FALSE if it's not physically possible to adjust it to this point. """ - x2 = self.GetX() + self.GetWidth() / 2 + x2 = self.GetX() + self.GetWidth() / 2.0 if left >= x2: return False @@ -1270,8 +1268,8 @@ class DivisionShape(CompositeShape): if test: return True - newW = x2-left - newX = left + newW / 2 + newW = x2 - left + newX = left + newW / 2.0 self.SetSize(newW, self.GetHeight()) dc = wx.ClientDC(self.GetCanvas()) @@ -1286,7 +1284,7 @@ class DivisionShape(CompositeShape): Returns FALSE if it's not physically possible to adjust it to this point. """ - y2 = self.GetY() + self.GetHeight() / 2 + y2 = self.GetY() + self.GetHeight() / 2.0 if top >= y2: return False @@ -1294,8 +1292,8 @@ class DivisionShape(CompositeShape): if test: return True - newH = y2-top - newY = top + newH / 2 + newH = y2 - top + newY = top + newH / 2.0 self.SetSize(self.GetWidth(), newH) dc = wx.ClientDC(self.GetCanvas()) @@ -1310,7 +1308,7 @@ class DivisionShape(CompositeShape): Returns FALSE if it's not physically possible to adjust it to this point. """ - x1 = self.GetX()-self.GetWidth() / 2 + x1 = self.GetX() - self.GetWidth() / 2.0 if right <= x1: return False @@ -1318,8 +1316,8 @@ class DivisionShape(CompositeShape): if test: return True - newW = right-x1 - newX = x1 + newW / 2 + newW = right - x1 + newX = x1 + newW / 2.0 self.SetSize(newW, self.GetHeight()) dc = wx.ClientDC(self.GetCanvas()) @@ -1334,7 +1332,7 @@ class DivisionShape(CompositeShape): Returns FALSE if it's not physically possible to adjust it to this point. """ - y1 = self.GetY()-self.GetHeight() / 2 + y1 = self.GetY() - self.GetHeight() / 2.0 if bottom <= y1: return False @@ -1342,8 +1340,8 @@ class DivisionShape(CompositeShape): if test: return True - newH = bottom-y1 - newY = y1 + newH / 2 + newH = bottom - y1 + newY = y1 + newH / 2.0 self.SetSize(self.GetWidth(), newH) dc = wx.ClientDC(self.GetCanvas()) @@ -1422,8 +1420,8 @@ class DivisionShape(CompositeShape): dc = wx.ClientDC(self.GetCanvas()) self.GetCanvas().PrepareDC(dc) - mouse_x = dc.LogicalToDeviceX(x-x1 * unit_x) - mouse_y = dc.LogicalToDeviceY(y-y1 * unit_y) + mouse_x = dc.LogicalToDeviceX(x - x1 * unit_x) + mouse_y = dc.LogicalToDeviceY(y - y1 * unit_y) self._canvas.PopupMenu(menu, (mouse_x, mouse_y)) diff --git a/wxPython/wx/lib/ogl/_diagram.py b/wxPython/wx/lib/ogl/_diagram.py index 95ef272206..a89bda3e95 100644 --- a/wxPython/wx/lib/ogl/_diagram.py +++ b/wxPython/wx/lib/ogl/_diagram.py @@ -11,8 +11,6 @@ # Licence: wxWindows license #---------------------------------------------------------------------------- -from __future__ import division - import wx DEFAULT_MOUSE_TOLERANCE = 3 diff --git a/wxPython/wx/lib/ogl/_divided.py b/wxPython/wx/lib/ogl/_divided.py index 9d5822229c..7ea907d9ab 100644 --- a/wxPython/wx/lib/ogl/_divided.py +++ b/wxPython/wx/lib/ogl/_divided.py @@ -11,8 +11,6 @@ # Licence: wxWindows license #---------------------------------------------------------------------------- -from __future__ import division - import sys import wx @@ -37,9 +35,9 @@ class DividedShapeControlPoint(ControlPoint): dc.SetBrush(wx.TRANSPARENT_BRUSH) dividedObject = self._shape - x1 = dividedObject.GetX()-dividedObject.GetWidth() / 2 + x1 = dividedObject.GetX() - dividedObject.GetWidth() / 2.0 y1 = y - x2 = dividedObject.GetX() + dividedObject.GetWidth() / 2 + x2 = dividedObject.GetX() + dividedObject.GetWidth() / 2.0 y2 = y dc.DrawLine(x1, y1, x2, y2) @@ -55,9 +53,9 @@ class DividedShapeControlPoint(ControlPoint): dividedObject = self._shape - x1 = dividedObject.GetX()-dividedObject.GetWidth() / 2 + x1 = dividedObject.GetX() - dividedObject.GetWidth() / 2.0 y1 = y - x2 = dividedObject.GetX() + dividedObject.GetWidth() / 2 + x2 = dividedObject.GetX() + dividedObject.GetWidth() / 2.0 y2 = y dc.DrawLine(x1, y1, x2, y2) @@ -82,8 +80,8 @@ class DividedShapeControlPoint(ControlPoint): # Find the old top and bottom of this region, # and calculate the new proportion for this region # if legal. - currentY = dividedObject.GetY()-dividedObject.GetHeight() / 2 - maxY = dividedObject.GetY() + dividedObject.GetHeight() / 2 + currentY = dividedObject.GetY() - dividedObject.GetHeight() / 2.0 + maxY = dividedObject.GetY() + dividedObject.GetHeight() / 2.0 # Save values theRegionTop = 0 @@ -98,7 +96,7 @@ class DividedShapeControlPoint(ControlPoint): if region == thisRegion: thisRegionTop = currentY - if i + 1right: + elif point.x > right: x = right else: x = point.x else: - x = left + (nth + 1) * self._width / (no_arcs + 1) + x = left + (nth + 1) * self._width / (no_arcs + 1.0) else: x = self._xpos elif attachment == n + 1: @@ -278,22 +276,22 @@ class DividedShape(RectangleShape): if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE: # Align line according to the next handle along point = line.GetNextControlPoint(self) - if point.xright: + elif point.x > right: x = right else: x = point.x else: - x = left + (nth + 1) * self._width / (no_arcs + 1) + x = left + (nth + 1) * self._width / (no_arcs + 1.0) else: x = self._xpos else: # Left or right - isLeft = not attachment<(n + 1) + isLeft = not attachment < (n + 1) if isLeft: - i = totalNumberAttachments-attachment-1 + i = totalNumberAttachments - attachment - 1 else: - i = attachment-1 + i = attachment - 1 region = self.GetRegions()[i] if region: @@ -303,8 +301,8 @@ class DividedShape(RectangleShape): x = right # Calculate top and bottom of region - top = self._ypos + region._y-region._height / 2 - bottom = self._ypos + region._y + region._height / 2 + top = self._ypos + region._y - region._height / 2.0 + bottom = self._ypos + region._y + region._height / 2.0 # Assuming we can trust the absolute size and # position of these regions @@ -312,14 +310,14 @@ class DividedShape(RectangleShape): if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE: # Align line according to the next handle along point = line.GetNextControlPoint(self) - if point.ytop: + elif point.y > top: y = top else: y = point.y else: - y = top + (nth + 1) * region._height / (no_arcs + 1) + y = top + (nth + 1) * region._height / (no_arcs + 1.0) else: y = self._ypos + region._y else: @@ -331,9 +329,9 @@ class DividedShape(RectangleShape): # plus one on the top and one on the bottom. n = len(self.GetRegions()) * 2 + 2 - maxN = n-1 + maxN = n - 1 for point in self._attachmentPoints: - if point._id>maxN: + if point._id > maxN: maxN = point._id return maxN + 1 @@ -350,8 +348,8 @@ class DividedShape(RectangleShape): self.MakeMandatoryControlPoints() def MakeMandatoryControlPoints(self): - currentY = self.GetY()-self._height / 2 - maxY = self.GetY() + self._height / 2 + currentY = self.GetY() - self._height / 2.0 + maxY = self.GetY() + self._height / 2.0 for i, region in enumerate(self.GetRegions()): proportion = region._regionProportionY @@ -360,7 +358,7 @@ class DividedShape(RectangleShape): actualY = min(maxY, y) if region != self.GetRegions()[-1]: - controlPoint = DividedShapeControlPoint(self._canvas, self, i, CONTROL_POINT_SIZE, 0, actualY-self.GetY(), 0) + controlPoint = DividedShapeControlPoint(self._canvas, self, i, CONTROL_POINT_SIZE, 0, actualY - self.GetY(), 0) self._canvas.AddShape(controlPoint) self._controlPoints.append(controlPoint) @@ -368,14 +366,14 @@ class DividedShape(RectangleShape): def ResetControlPoints(self): # May only have the region handles, (n - 1) of them - if len(self._controlPoints)>len(self.GetRegions())-1: + if len(self._controlPoints) > len(self.GetRegions()) - 1: RectangleShape.ResetControlPoints(self) self.ResetMandatoryControlPoints() def ResetMandatoryControlPoints(self): - currentY = self.GetY()-self._height / 2 - maxY = self.GetY() + self._height / 2 + currentY = self.GetY() - self._height / 2.0 + maxY = self.GetY() + self._height / 2.0 i = 0 for controlPoint in self._controlPoints: @@ -387,7 +385,7 @@ class DividedShape(RectangleShape): actualY = min(maxY, y) controlPoint._xoffset = 0 - controlPoint._yoffset = actualY-self.GetY() + controlPoint._yoffset = actualY - self.GetY() currentY = actualY diff --git a/wxPython/wx/lib/ogl/_lines.py b/wxPython/wx/lib/ogl/_lines.py index 65978c484f..66e891cf7e 100644 --- a/wxPython/wx/lib/ogl/_lines.py +++ b/wxPython/wx/lib/ogl/_lines.py @@ -11,8 +11,6 @@ # Licence: wxWindows license #---------------------------------------------------------------------------- -from __future__ import division - import sys import math @@ -21,10 +19,10 @@ from _oglmisc import * # Line alignment flags # Vertical by default -LINE_ALIGNMENT_HORIZ= 1 -LINE_ALIGNMENT_VERT= 0 -LINE_ALIGNMENT_TO_NEXT_HANDLE= 2 -LINE_ALIGNMENT_NONE= 0 +LINE_ALIGNMENT_HORIZ = 1 +LINE_ALIGNMENT_VERT = 0 +LINE_ALIGNMENT_TO_NEXT_HANDLE = 2 +LINE_ALIGNMENT_NONE = 0 @@ -53,7 +51,7 @@ class LineControlPoint(ControlPoint): class ArrowHead(object): - def __init__(self, type = 0, end = 0, size = 0.0, dist = 0.0, name="",mf = None, arrowId=-1): + def __init__(self, type = 0, end = 0, size = 0.0, dist = 0.0, name = "", mf = None, arrowId = -1): if isinstance(type, ArrowHead): pass else: @@ -67,7 +65,7 @@ class ArrowHead(object): self._arrowName = name self._metaFile = mf self._id = arrowId - if self._id==-1: + if self._id == -1: self._id = wx.NewId() def _GetType(self): @@ -98,7 +96,7 @@ class ArrowHead(object): if oldWidth == 0: return - scale = size / oldWidth + scale = float(size) / oldWidth if scale != 1: self._metaFile.Scale(scale, scale) @@ -139,8 +137,8 @@ class LabelShape(RectangleShape): if self._lineShape and not self._lineShape.GetDrawHandles(): return - x1 = self._xpos-self._width / 2 - y1 = self._ypos-self._height / 2 + x1 = self._xpos - self._width / 2.0 + y1 = self._ypos - self._height / 2.0 if self._pen: if self._pen.GetWidth() == 0: @@ -149,7 +147,7 @@ class LabelShape(RectangleShape): dc.SetPen(self._pen) dc.SetBrush(wx.TRANSPARENT_BRUSH) - if self._cornerRadius>0: + if self._cornerRadius > 0: dc.DrawRoundedRectangle(x1, y1, self._width, self._height, self._cornerRadius) else: dc.DrawRectangle(x1, y1, self._width, self._height) @@ -296,7 +294,7 @@ class LineShape(Shape): self._lineControlPoints = [] for _ in range(n): - point = wx.RealPoint(-999,-999) + point = wx.RealPoint(-999, -999) self._lineControlPoints.append(point) def InsertLineControlPoint(self, dc = None): @@ -307,15 +305,15 @@ class LineShape(Shape): last_point = self._lineControlPoints[-1] second_last_point = self._lineControlPoints[-2] - line_x = (last_point[0] + second_last_point[0]) / 2 - line_y = (last_point[1] + second_last_point[1]) / 2 + 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) self._lineControlPoints.insert(len(self._lineControlPoints), point) def DeleteLineControlPoint(self): """Delete an arbitary point on the line.""" - if len(self._lineControlPoints)<3: + if len(self._lineControlPoints) < 3: return False del self._lineControlPoints[-2] @@ -333,21 +331,21 @@ class LineShape(Shape): # and the last. for point in self._lineControlPoints[1:]: - if point[0]==-999: - if first_point[0]rLeft and xrTop and y rLeft and x < rRight and y > rTop and y < rBottom: inLabelRegion = True break - for i in range(len(self._lineControlPoints)-1): + for i in range(len(self._lineControlPoints) - 1): point1 = self._lineControlPoints[i] point2 = self._lineControlPoints[i + 1] # For inaccurate mousing allow 8 pixel corridor extra = 4 - dx = point2[0]-point1[0] - dy = point2[1]-point1[1] + dx = point2[0] - point1[0] + dy = point2[1] - point1[1] seg_len = math.sqrt(dx * dx + dy * dy) if dy == 0 or dx == 0: return False - distance_from_seg = seg_len * ((x-point1[0]) * dy-(y-point1[1]) * dx) / (dy * dy + dx * dx) - distance_from_prev = seg_len * ((y-point1[1]) * dy + (x-point1[0]) * dx) / (dy * dy + dx * dx) + distance_from_seg = seg_len * float((x - point1[0]) * dy - (y - point1[1]) * dx) / (dy * dy + dx * dx) + distance_from_prev = seg_len * float((y - point1[1]) * dy + (x - point1[0]) * dx) / (dy * dy + dx * dx) - if abs(distance_from_seg)= 0 and distance_from_prev <= seg_len or inLabelRegion: + if abs(distance_from_seg) < extra and distance_from_prev >= 0 and distance_from_prev <= seg_len or inLabelRegion: return 0, distance_from_seg return False @@ -612,7 +610,7 @@ class LineShape(Shape): # will be on the line. realOffset = XOffset if proportionalOffset: - totalLength = math.sqrt((second_line_point[0]-first_line_point[0]) * (second_line_point[0]-first_line_point[0]) + (second_line_point[1]-first_line_point[1]) * (second_line_point[1]-first_line_point[1])) + totalLength = math.sqrt((second_line_point[0] - first_line_point[0]) * (second_line_point[0] - first_line_point[0]) + (second_line_point[1] - first_line_point[1]) * (second_line_point[1] - first_line_point[1])) realOffset = XOffset * totalLength positionOnLineX, positionOnLineY = GetPointOnLine(second_line_point[0], second_line_point[1], first_line_point[0], first_line_point[1], realOffset) @@ -624,7 +622,7 @@ class LineShape(Shape): # will be on the line. realOffset = XOffset if proportionalOffset: - totalLength = math.sqrt((second_last_line_point[0]-last_line_point[0]) * (second_last_line_point[0]-last_line_point[0]) + (second_last_line_point[1]-last_line_point[1]) * (second_last_line_point[1]-last_line_point[1])); + totalLength = math.sqrt((second_last_line_point[0] - last_line_point[0]) * (second_last_line_point[0] - last_line_point[0]) + (second_last_line_point[1] - last_line_point[1]) * (second_last_line_point[1] - last_line_point[1])); realOffset = XOffset * totalLength positionOnLineX, positionOnLineY = GetPointOnLine(second_last_line_point[0], second_last_line_point[1], last_line_point[0], last_line_point[1], realOffset) @@ -633,14 +631,14 @@ class LineShape(Shape): startPositionY = second_last_line_point[1] elif ap == ARROW_POSITION_MIDDLE: # Choose a point half way between the last and penultimate points - x = (last_line_point[0] + second_last_line_point[0]) / 2 - y = (last_line_point[1] + second_last_line_point[1]) / 2 + x = (last_line_point[0] + second_last_line_point[0]) / 2.0 + y = (last_line_point[1] + second_last_line_point[1]) / 2.0 # If we're using a proportional offset, calculate just where this # will be on the line. realOffset = XOffset if proportionalOffset: - totalLength = math.sqrt((second_last_line_point[0]-x) * (second_last_line_point[0]-x) + (second_last_line_point[1]-y) * (second_last_line_point[1]-y)); + totalLength = math.sqrt((second_last_line_point[0] - x) * (second_last_line_point[0] - x) + (second_last_line_point[1] - y) * (second_last_line_point[1] - y)); realOffset = XOffset * totalLength positionOnLineX, positionOnLineY = GetPointOnLine(second_last_line_point[0], second_last_line_point[1], x, y, realOffset) @@ -663,25 +661,25 @@ class LineShape(Shape): # Where theta = math.tan(-1) of (y3-y1) / (x3-x1) x1 = startPositionX y1 = startPositionY - x3 = positionOnLineX - y3 = positionOnLineY - d=-arrow.GetYOffset() # Negate so +offset is above line + x3 = float(positionOnLineX) + y3 = float(positionOnLineY) + d = -arrow.GetYOffset() # Negate so +offset is above line if x3 == x1: - theta = math.pi / 2 + theta = math.pi / 2.0 else: - theta = math.atan((y3-y1) / (x3-x1)) + theta = math.atan((y3 - y1) / (x3 - x1)) - x4 = x3-d * math.sin(theta) + x4 = x3 - d * math.sin(theta) y4 = y3 + d * math.cos(theta) - deltaX = x4-positionOnLineX - deltaY = y4-positionOnLineY + deltaX = x4 - positionOnLineX + deltaY = y4 - positionOnLineY at = arrow._GetType() if at == ARROW_ARROW: arrowLength = arrow.GetSize() - arrowWidth = arrowLength / 3 + arrowWidth = arrowLength / 3.0 tip_x, tip_y, side1_x, side1_y, side2_x, side2_y = GetArrowPoints(startPositionX + deltaX, startPositionY + deltaY, positionOnLineX + deltaX, positionOnLineY + deltaY, arrowLength, arrowWidth) @@ -699,9 +697,9 @@ class LineShape(Shape): diameter = arrow.GetSize() x, y = GetPointOnLine(startPositionX + deltaX, startPositionY + deltaY, positionOnLineX + deltaX, positionOnLineY + deltaY, - diameter / 2) - x1 = x-diameter / 2 - y1 = y-diameter / 2 + diameter / 2.0) + x1 = x - diameter / 2.0 + y1 = y - diameter / 2.0 dc.SetPen(self._pen) if arrow._GetType() == ARROW_HOLLOW_CIRCLE: dc.SetBrush(self.GetBackgroundBrush()) @@ -724,7 +722,7 @@ class LineShape(Shape): # x, y = GetPointOnLine(startPositionX, startPositionY, positionOnLineX, positionOnLineY, - arrow.GetMetaFile()._width / 2) + arrow.GetMetaFile()._width / 2.0) # Calculate theta for rotating the metafile. # # | @@ -738,21 +736,21 @@ class LineShape(Shape): theta = 0.0 x1 = startPositionX y1 = startPositionY - x2 = positionOnLineX - y2 = positionOnLineY + x2 = float(positionOnLineX) + y2 = float(positionOnLineY) if x1 == x2 and y1 == y2: theta = 0.0 - elif x1 == x2 and y1>y2: - theta = 3.0 * math.pi / 2 - elif x1 == x2 and y2>y1: - theta = math.pi / 2 - elif x2>x1 and y2 >= y1: - theta = math.atan((y2-y1) / (x2-x1)) - elif x2x1 and y2 y2: + theta = 3.0 * math.pi / 2.0 + elif x1 == x2 and y2 > y1: + theta = math.pi / 2.0 + elif x2 > x1 and y2 >= y1: + theta = math.atan((y2 - y1) / (x2 - x1)) + elif x2 < x1: + theta = math.pi + math.atan((y2 - y1) / (x2 - x1)) + elif x2 > x1 and y2 < y1: + theta = 2 * math.pi + math.atan((y2 - y1) / (x2 - x1)) else: raise "Unknown arrowhead rotation case" @@ -766,7 +764,7 @@ class LineShape(Shape): minX, minY, maxX, maxY = arrow.GetMetaFile().GetBounds() # Make erasing rectangle slightly bigger or you get droppings extraPixels = 4 - dc.DrawRectangle(deltaX + x + minX-extraPixels / 2, deltaY + y + minY-extraPixels / 2, maxX-minX + extraPixels, maxY-minY + extraPixels) + dc.DrawRectangle(deltaX + x + minX - extraPixels / 2.0, deltaY + y + minY - extraPixels / 2.0, maxX - minX + extraPixels, maxY - minY + extraPixels) else: arrow.GetMetaFile().Draw(dc, x + deltaX, y + deltaY) @@ -795,8 +793,8 @@ class LineShape(Shape): # Drawing over the line only seems to work if the line has a thickness # of 1. - if old_pen and old_pen.GetWidth()>1: - dc.DrawRectangle(self._xpos-bound_x / 2-2, self._ypos-bound_y / 2-2, + if old_pen and old_pen.GetWidth() > 1: + dc.DrawRectangle(self._xpos - bound_x / 2.0 - 2, self._ypos - bound_y / 2.0 - 2, bound_x + 4, bound_y + 4) else: self._erasing = True @@ -811,19 +809,19 @@ class LineShape(Shape): def GetBoundingBoxMin(self): x1, y1 = 10000, 10000 - x2, y2=-10000,-10000 + x2, y2 = -10000, -10000 for point in self._lineControlPoints: - if point[0]x2: + if point[0] > x2: x2 = point[0] - if point[1]>y2: + if point[1] > y2: y2 = point[1] - return x2-x1, y2-y1 + return x2 - x1, y2 - y1 # For a node image of interest, finds the position of this arc # amongst all the arcs which are attached to THIS SIDE of the node image, @@ -834,7 +832,7 @@ class LineShape(Shape): Specify whether incoming or outgoing lines are being considered with incoming. """ - n=-1 + n = -1 num = 0 if image == self._to: @@ -884,8 +882,8 @@ class LineShape(Shape): self.SetBrush(None) def OnMovePre(self, dc, x, y, old_x, old_y, display = True): - x_offset = x-old_x - y_offset = y-old_y + x_offset = x - old_x + y_offset = y - old_y if self._lineControlPoints and not (x_offset == 0 and y_offset == 0): for point in self._lineControlPoints: @@ -897,7 +895,7 @@ class LineShape(Shape): if self._labelObjects[i]: self._labelObjects[i].Erase(dc) xp, yp = self.GetLabelPosition(i) - if i2: + if len(self._lineControlPoints) > 2: self.Initialise() # Do each end - nothing in the middle. User has to move other points @@ -930,8 +928,8 @@ class LineShape(Shape): self.SetEnds(end_x, end_y, other_end_x, other_end_y) # Try to move control points with the arc - x_offset = self._xpos-oldX - y_offset = self._ypos-oldY + x_offset = self._xpos - oldX + y_offset = self._ypos - oldY # Only move control points if it's a self link. And only works # if attachment mode is ON @@ -957,7 +955,7 @@ class LineShape(Shape): second_point = self._lineControlPoints[1] second_last_point = self._lineControlPoints[-2] - if len(self._lineControlPoints)>2: + if len(self._lineControlPoints) > 2: if self._from.GetAttachmentMode() != ATTACHMENT_MODE_NONE: nth, no_arcs = self.FindNth(self._from, False) # Not incoming end_x, end_y = self._from.GetAttachmentPosition(self._attachmentFrom, nth, no_arcs, self) @@ -1015,7 +1013,7 @@ class LineShape(Shape): else: dc.DrawLines(points) - if sys.platform[:3]=="win": + if sys.platform[:3] == "win": # For some reason, last point isn't drawn under Windows pt = points[-1] dc.DrawPoint(pt.x, pt.y) @@ -1256,7 +1254,7 @@ class LineShape(Shape): return True - def AddArrow(self, type, end = ARROW_POSITION_END, size = 10.0, xOffset = 0.0, name="",mf = None, arrowId=-1): + def AddArrow(self, type, end = ARROW_POSITION_END, size = 10.0, xOffset = 0.0, name = "", mf = None, arrowId = -1): """Add an arrow (or annotation) to the line. type may currently be one of: @@ -1326,7 +1324,7 @@ class LineShape(Shape): return True i1 = i2 = 0 - while i10: + if minWidth > 0: minWidth = minWidth * 1.4 else: minWidth = 20.0 @@ -1438,13 +1436,13 @@ class LineShape(Shape): startX, startY, endX, endY = self.GetEnds() # Find distances from centre, start and end. The smallest wins - centreDistance = math.sqrt((x-self._xpos) * (x-self._xpos) + (y-self._ypos) * (y-self._ypos)) - startDistance = math.sqrt((x-startX) * (x-startX) + (y-startY) * (y-startY)) - endDistance = math.sqrt((x-endX) * (x-endX) + (y-endY) * (y-endY)) + centreDistance = math.sqrt((x - self._xpos) * (x - self._xpos) + (y - self._ypos) * (y - self._ypos)) + startDistance = math.sqrt((x - startX) * (x - startX) + (y - startY) * (y - startY)) + endDistance = math.sqrt((x - endX) * (x - endX) + (y - endY) * (y - endY)) - if centreDistance0: + if len(buffer) > 0: string_list.append(buffer) - buffer="" + buffer = "" else: if len(buffer): - buffer+=" " + buffer += " " buffer += s x, y = dc.GetTextExtent(buffer) # Don't fit within the bounding box if we're fitting # shape to contents - if (x>width) and not (formatMode & FORMAT_SIZE_TO_CONTENTS): + if (x > width) and not (formatMode & FORMAT_SIZE_TO_CONTENTS): # Deal with first word being wider than box if len(oldBuffer): string_list.append(oldBuffer) @@ -155,7 +154,7 @@ def GetCentredTextExtent(dc, text_list, xpos = 0, ypos = 0, width = 0, height = max_width = 0 for line in text_list: current_width, char_height = dc.GetTextExtent(line) - if current_width>max_width: + if current_width > max_width: max_width = current_width return max_width, len(text_list) * char_height @@ -176,31 +175,31 @@ def CentreText(dc, text_list, xpos, ypos, width, height, formatMode): for line in text_list: current_width, char_height = dc.GetTextExtent(line.GetText()) widths.append(current_width) - if current_width>max_width: + if current_width > max_width: max_width = current_width max_height = len(text_list) * char_height if formatMode & FORMAT_CENTRE_VERT: - if max_height(val2 - tol) and \ - val2<(val1 + tol) and val2>(val1 - tol) + return val1 < (val2 + tol) and val1 > (val2 - tol) and \ + val2 < (val1 + tol) and val2 > (val1 - tol) def FindEndForBox(width, height, x1, y1, x2, y2): - xvec = [x1 - width / 2, x1 - width / 2, x1 + width / 2, x1 + width / 2, x1 - width / 2] - yvec = [y1 - height / 2, y1 + height / 2, y1 + height / 2, y1 - height / 2, y1 - height / 2] + xvec = [x1 - width / 2.0, x1 - width / 2.0, x1 + width / 2.0, x1 + width / 2.0, x1 - width / 2.0] + yvec = [y1 - height / 2.0, y1 + height / 2.0, y1 + height / 2.0, y1 - height / 2.0, y1 - height / 2.0] return FindEndForPolyline(xvec, yvec, x2, y2, x1, y1) @@ -253,19 +252,19 @@ def CheckLineIntersection(x1, y1, x2, y2, x3, y3, x4, y4): k_line = 1.0 # Check for parallel lines - if denominator_term<0.005 and denominator_term>-0.005: - line_constant=-1.0 + if denominator_term < 0.005 and denominator_term > -0.005: + line_constant = -1.0 else: line_constant = float(numerator_term) / denominator_term # Check for intersection - if line_constant<1.0 and line_constant>0.0: + if line_constant < 1.0 and line_constant > 0.0: # Now must check that other line hits - if (y4 - y3)<0.005 and (y4 - y3)>-0.005: + if (y4 - y3) < 0.005 and (y4 - y3) > -0.005: k_line = (x1 - x3 + line_constant * (x2 - x1)) / (x4 - x3) else: k_line = (y1 - y3 + line_constant * (y2 - y1)) / (y4 - y3) - if k_line >= 0 and k_line<1: + if k_line >= 0 and k_line < 1: length_ratio = line_constant else: k_line = 1 @@ -285,13 +284,13 @@ def FindEndForPolyline(xvec, yvec, x1, y1, x2, y2): lastx = xvec[i] lasty = yvec[i] - if line_ratio1: + elif abs(float(dy) / dx) > 1: point2[0] = point1[0] else: point2[1] = point1[0] @@ -340,40 +339,40 @@ def GraphicsStraightenLine(point1, point2): def GetPointOnLine(x1, y1, x2, y2, length): l = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) - if l<0.01: + if l < 0.01: l = 0.01 i_bar = (x2 - x1) / l j_bar = (y2 - y1) / l - return -length * i_bar + x2,-length * j_bar + y2 + return -length * i_bar + x2, -length * j_bar + y2 def GetArrowPoints(x1, y1, x2, y2, length, width): l = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) - if l<0.01: + if l < 0.01: l = 0.01 i_bar = (x2 - x1) / l j_bar = (y2 - y1) / l - x3=-length * i_bar + x2 - y3=-length * j_bar + y2 + x3 = -length * i_bar + x2 + y3 = -length * j_bar + y2 - return x2, y2, width*-j_bar + x3, width * i_bar + y3,-width*-j_bar + x3,-width * i_bar + y3 + return x2, y2, width * -j_bar + x3, width * i_bar + y3, -width * -j_bar + x3, -width * i_bar + y3 def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3): - a1 = width1 / 2 - b1 = height1 / 2 + a1 = width1 / 2.0 + b1 = height1 / 2.0 # Check that x2 != x3 - if abs(x2 - x3)<0.05: + if abs(x2 - x3) < 0.05: x4 = x2 - if y3>y2: + if y3 > y2: y4 = y1 - math.sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1)))) else: y4 = y1 + math.sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1)))) @@ -387,16 +386,16 @@ def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3): E = (A + B) F = (C - (2 * A * x1) - (2 * B * x2)) G = ((A * x1 * x1) + (B * x2 * x2) - (C * x2) + D - 1) - H = ((y3 - y2) / (x2 - x2)) + H = (float(y3 - y2) / (x2 - x2)) K = ((F * F) - (4 * E * G)) if K >= 0: # In this case the line intersects the ellipse, so calculate intersection if x2 >= x1: - ellipse1_x = ((F*-1) + math.sqrt(K)) / (2 * E) + ellipse1_x = ((F * -1) + math.sqrt(K)) / (2 * E) ellipse1_y = ((H * (ellipse1_x - x2)) + y2) else: - ellipse1_x = (((F*-1) - math.sqrt(K)) / (2 * E)) + ellipse1_x = (((F * -1) - math.sqrt(K)) / (2 * E)) ellipse1_y = ((H * (ellipse1_x - x2)) + y2) else: # in this case, arc does not intersect ellipse, so just draw arc