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
This commit is contained in:
Robin Dunn
2004-06-18 16:32:03 +00:00
parent bc55323bc3
commit a2df8090e8
9 changed files with 489 additions and 503 deletions

View File

@@ -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())

View File

@@ -11,8 +11,6 @@
# Licence: wxWindows license
#----------------------------------------------------------------------------
from __future__ import division
import wx
import math
@@ -464,10 +462,10 @@ class Shape(ShapeEvtHandler):
width += 4 # Allowance for inaccurate mousing
height += 4
left = self._xpos - (width / 2)
top = self._ypos - (height / 2)
right = self._xpos + (width / 2)
bottom = self._ypos + (height / 2)
left = self._xpos - width / 2.0
top = self._ypos - height / 2.0
right = self._xpos + width / 2.0
bottom = self._ypos + height / 2.0
nearest_attachment = 0
@@ -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:
@@ -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,11 +1194,11 @@ 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
@@ -1273,10 +1270,10 @@ class Shape(ShapeEvtHandler):
heightMin = minY + CONTROL_POINT_SIZE + 2
# Offsets from main object
top=-heightMin / 2
bottom = heightMin / 2 + (maxY - minY)
left=-widthMin / 2
right = widthMin / 2 + (maxX - minX)
top = -heightMin / 2.0
bottom = heightMin / 2.0 + (maxY - minY)
left = -widthMin / 2.0
right = widthMin / 2.0 + (maxX - minX)
control = ControlPoint(self._canvas, self, CONTROL_POINT_SIZE, left, top, CONTROL_POINT_DIAGONAL)
self._canvas.AddShape(control)
@@ -1341,10 +1338,10 @@ class Shape(ShapeEvtHandler):
heightMin = minY + CONTROL_POINT_SIZE + 2
# Offsets from main object
top=-heightMin / 2
bottom = heightMin / 2 + (maxY - minY)
left=-widthMin / 2
right = widthMin / 2 + (maxX - minX)
top = -heightMin / 2.0
bottom = heightMin / 2.0 + (maxY - minY)
left = -widthMin / 2.0
right = widthMin / 2.0 + (maxX - minX)
self._controlPoints[0]._xoffset = left
self._controlPoints[0]._yoffset = top
@@ -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)
@@ -1601,9 +1598,9 @@ class Shape(ShapeEvtHandler):
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])
@@ -1626,9 +1623,9 @@ class Shape(ShapeEvtHandler):
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"
@@ -1811,8 +1808,8 @@ class Shape(ShapeEvtHandler):
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)
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,11 +1838,11 @@ 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
@@ -1862,11 +1859,11 @@ 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
@@ -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)
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
@@ -2169,19 +2166,19 @@ class Shape(ShapeEvtHandler):
# Choose the 'opposite corner' of the object as the stationary
# point in case this is non-centring resizing.
if pt.GetX() < self.GetX():
pt._controlPointDragStartX = self.GetX() + bound_x / 2
pt._controlPointDragStartX = self.GetX() + bound_x / 2.0
else:
pt._controlPointDragStartX = self.GetX() - bound_x / 2
pt._controlPointDragStartX = self.GetX() - bound_x / 2.0
if pt.GetY() < self.GetY():
pt._controlPointDragStartY = self.GetY() + bound_y / 2
pt._controlPointDragStartY = self.GetY() + bound_y / 2.0
else:
pt._controlPointDragStartY = self.GetY() - bound_y / 2
pt._controlPointDragStartY = self.GetY() - bound_y / 2.0
if pt._type == CONTROL_POINT_HORIZONTAL:
pt._controlPointDragStartY = self.GetY() - bound_y / 2
pt._controlPointDragStartY = self.GetY() - bound_y / 2.0
elif pt._type == CONTROL_POINT_VERTICAL:
pt._controlPointDragStartX = self.GetX() - bound_x / 2
pt._controlPointDragStartX = self.GetX() - bound_x / 2.0
# We may require the old width and height
pt._controlPointDragStartWidth = bound_x
@@ -2231,14 +2228,14 @@ class Shape(ShapeEvtHandler):
newX1 = pt._controlPointDragStartX
newX2 = newX1 + pt._controlPointDragStartWidth
elif pt._type == CONTROL_POINT_DIAGONAL and (keys & KEYS or self.GetMaintainAspectRatio()):
newH = (newX2 - newX1) * (pt._controlPointDragStartHeight / pt._controlPointDragStartWidth)
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
@@ -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:
@@ -2484,8 +2481,8 @@ class PolygonShape(Shape):
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
@@ -2541,8 +2538,8 @@ class PolygonShape(Shape):
self.SetAttachmentSize(new_width, new_height)
# Multiply all points by proportion of new size to old size
x_proportion = abs(new_width / self._originalWidth)
y_proportion = abs(new_height / self._originalHeight)
x_proportion = abs(float(new_width) / self._originalWidth)
y_proportion = abs(float(new_height) / self._originalHeight)
for i in range(max(len(self._points), len(self._originalPoints))):
self._points[i].x = self._originalPoints[i][0] * x_proportion
@@ -2579,8 +2576,8 @@ class PolygonShape(Shape):
except ValueError:
secondPoint = self._points[0]
x = (secondPoint.x - firstPoint.x) / 2 + firstPoint.x
y = (secondPoint.y - firstPoint.y) / 2 + firstPoint.y
x = (secondPoint.x - firstPoint.x) / 2.0 + firstPoint.x
y = (secondPoint.y - firstPoint.y) / 2.0 + firstPoint.y
point = wx.RealPoint(x, y)
if pos >= len(self._points) - 1:
@@ -2647,8 +2644,8 @@ class PolygonShape(Shape):
def OnDrawOutline(self, dc, x, y, w, h):
dc.SetBrush(wx.TRANSPARENT_BRUSH)
# Multiply all points by proportion of new size to old size
x_proportion = abs(w / self._originalWidth)
y_proportion = abs(h / self._originalHeight)
x_proportion = abs(float(w) / self._originalWidth)
y_proportion = abs(float(h) / self._originalHeight)
intPoints = []
for point in self._originalPoints:
@@ -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)

View File

@@ -11,8 +11,6 @@
# Licence: wxWindows license
#----------------------------------------------------------------------------
from __future__ import division
from _basic import RectangleShape
@@ -26,8 +24,8 @@ class BitmapShape(RectangleShape):
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):

View File

@@ -11,8 +11,6 @@
# Licence: wxWindows license
#----------------------------------------------------------------------------
from __future__ import division
import wx
from _lines import LineShape
from _composit import *
@@ -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
@@ -293,7 +293,7 @@ class ShapeCanvas(wx.ScrolledWindow):
nearest_object = object
nearest_attachment = temp_attachment
for object in self.GetDiagram().GetShapeList()[::-1]:
for object in rl:
# On second pass, only ever consider non-composites or
# divisions. If children want to pass up control to
# the composite, that's up to them.

View File

@@ -11,8 +11,6 @@
# Licence: wxWindows license
#----------------------------------------------------------------------------
from __future__ import division
import sys
import wx
@@ -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._xSpacing<minWidth:
spacingX = (minWidth-totalObjectWidth) / (n + 1)
startX = x-minWidth / 2
if totalObjectWidth + (n + 1) * self._xSpacing <= minWidth:
spacingX = (minWidth - totalObjectWidth) / (n + 1.0)
startX = x - minWidth / 2.0
else: # Otherwise, use default spacing
spacingX = self._xSpacing
startX = x-(totalObjectWidth + (n + 1) * spacingX) / 2
startX = x - (totalObjectWidth + (n + 1) * spacingX) / 2.0
# Now position the objects
changed = False
for constrainedObject in self._constrainedObjects:
width2, height2 = constrainedObject.GetBoundingBoxMax()
startX += spacingX + width2 / 2
startX += spacingX + width2 / 2.0
if not self.Equals(startX, constrainedObject.GetX()):
constrainedObject.Move(dc, startX, constrainedObject.GetY(), False)
changed = True
startX += width2 / 2
startX += width2 / 2.0
return changed
elif self._constraintType == CONSTRAINT_CENTRED_BOTH:
n = len(self._constrainedObjects)
@@ -230,40 +228,40 @@ class Constraint(object):
# Check if within the constraining object...
if totalObjectHeight + (n + 1) * self._xSpacing <= minWidth:
spacingX = (minWidth-totalObjectWidth) / (n + 1)
startX = x-minWidth / 2
spacingX = (minWidth - totalObjectWidth) / (n + 1.0)
startX = x - minWidth / 2.0
else: # Otherwise, use default spacing
spacingX = self._xSpacing
startX = x-(totalObjectWidth + (n + 1) * spacingX) / 2
startX = x - (totalObjectWidth + (n + 1) * spacingX) / 2.0
# 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()
startX += spacingX + width2 / 2
startY += spacingY + height2 / 2
startX += spacingX + width2 / 2.0
startY += spacingY + height2 / 2.0
if not self.Equals(startX, constrainedObject.GetX()) or not self.Equals(startY, constrainedObject.GetY()):
constrainedObject.Move(dc, startX, startY, False)
changed = True
startX += width2 / 2
startY += height2 / 2
startX += width2 / 2.0
startY += height2 / 2.0
return changed
elif self._constraintType == CONSTRAINT_LEFT_OF:
changed = False
for constrainedObject in self._constrainedObjects:
width2, height2 = constrainedObject.GetBoundingBoxMax()
x3 = x-minWidth / 2-width2 / 2-self._xSpacing
x3 = x - minWidth / 2.0 - width2 / 2.0 - self._xSpacing
if not self.Equals(x3, constrainedObject.GetX()):
changed = True
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
@@ -273,7 +271,7 @@ class Constraint(object):
for constrainedObject in self._constrainedObjects:
width2, height2 = constrainedObject.GetBoundingBoxMax()
x3 = x + minWidth / 2 + width2 / 2 + self._xSpacing
x3 = x + minWidth / 2.0 + width2 / 2.0 + self._xSpacing
if not self.Equals(x3, constrainedObject.GetX()):
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
changed = True
@@ -284,7 +282,7 @@ class Constraint(object):
for constrainedObject in self._constrainedObjects:
width2, height2 = constrainedObject.GetBoundingBoxMax()
y3 = y-minHeight / 2-height2 / 2-self._ySpacing
y3 = y - minHeight / 2.0 - height2 / 2.0 - self._ySpacing
if not self.Equals(y3, constrainedObject.GetY()):
changed = True
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
@@ -295,7 +293,7 @@ class Constraint(object):
for constrainedObject in self._constrainedObjects:
width2, height2 = constrainedObject.GetBoundingBoxMax()
y3 = y + minHeight / 2 + height2 / 2 + self._ySpacing
y3 = y + minHeight / 2.0 + height2 / 2.0 + self._ySpacing
if not self.Equals(y3, constrainedObject.GetY()):
changed = True
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
@@ -304,7 +302,7 @@ class Constraint(object):
changed = False
for constrainedObject in self._constrainedObjects:
width2, height2 = constrainedObject.GetBoundingBoxMax()
x3 = x-minWidth / 2 + width2 / 2 + self._xSpacing
x3 = x - minWidth / 2.0 + width2 / 2.0 + self._xSpacing
if not self.Equals(x3, constrainedObject.GetX()):
changed = True
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
@@ -313,7 +311,7 @@ class Constraint(object):
changed = False
for constrainedObject in self._constrainedObjects:
width2, height2 = constrainedObject.GetBoundingBoxMax()
x3 = x + minWidth / 2-width2 / 2-self._xSpacing
x3 = x + minWidth / 2.0 - width2 / 2.0 - self._xSpacing
if not self.Equals(x3, constrainedObject.GetX()):
changed = True
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
@@ -322,7 +320,7 @@ class Constraint(object):
changed = False
for constrainedObject in self._constrainedObjects:
width2, height2 = constrainedObject.GetBoundingBoxMax()
y3 = y-minHeight / 2 + height2 / 2 + self._ySpacing
y3 = y - minHeight / 2.0 + height2 / 2.0 + self._ySpacing
if not self.Equals(y3, constrainedObject.GetY()):
changed = True
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
@@ -331,7 +329,7 @@ class Constraint(object):
changed = False
for constrainedObject in self._constrainedObjects:
width2, height2 = constrainedObject.GetBoundingBoxMax()
y3 = y + minHeight / 2-height2 / 2-self._ySpacing
y3 = y + minHeight / 2.0 - height2 / 2.0 - self._ySpacing
if not self.Equals(y3, constrainedObject.GetY()):
changed = True
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
@@ -339,7 +337,7 @@ class Constraint(object):
elif self._constraintType == CONSTRAINT_MIDALIGNED_LEFT:
changed = False
for constrainedObject in self._constrainedObjects:
x3 = x-minWidth / 2
x3 = x - minWidth / 2.0
if not self.Equals(x3, constrainedObject.GetX()):
changed = True
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
@@ -347,7 +345,7 @@ class Constraint(object):
elif self._constraintType == CONSTRAINT_MIDALIGNED_RIGHT:
changed = False
for constrainedObject in self._constrainedObjects:
x3 = x + minWidth / 2
x3 = x + minWidth / 2.0
if not self.Equals(x3, constrainedObject.GetX()):
changed = True
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
@@ -355,7 +353,7 @@ class Constraint(object):
elif self._constraintType == CONSTRAINT_MIDALIGNED_TOP:
changed = False
for constrainedObject in self._constrainedObjects:
y3 = y-minHeight / 2
y3 = y - minHeight / 2.0
if not self.Equals(y3, constrainedObject.GetY()):
changed = True
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
@@ -363,7 +361,7 @@ class Constraint(object):
elif self._constraintType == CONSTRAINT_MIDALIGNED_BOTTOM:
changed = False
for constrainedObject in self._constrainedObjects:
y3 = y + minHeight / 2
y3 = y + minHeight / 2.0
if not self.Equals(y3, constrainedObject.GetY()):
changed = True
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
@@ -392,8 +390,8 @@ class CompositeShape(RectangleShape):
self._divisions = [] # In case it's a container
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:
@@ -507,8 +505,8 @@ class CompositeShape(RectangleShape):
def SetSize(self, w, h, recursive = True):
self.SetAttachmentSize(w, h)
xScale = w / max(1, self.GetWidth())
yScale = h / max(1, self.GetHeight())
xScale = float(w) / max(1, self.GetWidth())
yScale = float(h) / max(1, self.GetHeight())
self._width = w
self._height = h
@@ -640,19 +638,19 @@ class CompositeShape(RectangleShape):
child.CalculateSize()
w, h = child.GetBoundingBoxMax()
if child.GetX() + w / 2>maxX:
maxX = child.GetX() + w / 2
if child.GetX()-w / 2<minX:
minX = child.GetX()-w / 2
if child.GetY() + h / 2>maxY:
maxY = child.GetY() + h / 2
if child.GetY()-h / 2<minY:
minY = child.GetY()-h / 2
if child.GetX() + w / 2.0 > 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 + minX
self._ypos = self._height / 2 + 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
@@ -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:
@@ -994,10 +992,10 @@ 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":
@@ -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
@@ -1271,7 +1269,7 @@ class DivisionShape(CompositeShape):
return True
newW = x2 - left
newX = left + newW / 2
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
@@ -1295,7 +1293,7 @@ class DivisionShape(CompositeShape):
return True
newH = y2 - top
newY = top + newH / 2
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
@@ -1319,7 +1317,7 @@ class DivisionShape(CompositeShape):
return True
newW = right - x1
newX = x1 + newW / 2
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
@@ -1343,7 +1341,7 @@ class DivisionShape(CompositeShape):
return True
newH = bottom - y1
newY = y1 + newH / 2
newY = y1 + newH / 2.0
self.SetSize(self.GetWidth(), newH)
dc = wx.ClientDC(self.GetCanvas())

View File

@@ -11,8 +11,6 @@
# Licence: wxWindows license
#----------------------------------------------------------------------------
from __future__ import division
import wx
DEFAULT_MOUSE_TOLERANCE = 3

View File

@@ -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
@@ -116,8 +114,8 @@ class DividedShapeControlPoint(ControlPoint):
dividedObject.EraseLinks(dc)
# Now calculate the new proportions of this region and the next region
thisProportion = (y-thisRegionTop) / dividedObject.GetHeight()
nextProportion = (nextRegionBottom-y) / dividedObject.GetHeight()
thisProportion = float(y - thisRegionTop) / dividedObject.GetHeight()
nextProportion = float(nextRegionBottom - y) / dividedObject.GetHeight()
thisRegion.SetProportions(0, thisProportion)
nextRegion.SetProportions(0, nextProportion)
@@ -152,14 +150,14 @@ class DividedShape(RectangleShape):
def OnDrawContents(self, dc):
if self.GetRegions():
defaultProportion = 1 / len(self.GetRegions())
defaultProportion = 1.0 / len(self.GetRegions())
else:
defaultProportion = 0
currentY = self._ypos-self._height / 2
maxY = self._ypos + self._height / 2
defaultProportion = 0.0
currentY = self._ypos - self._height / 2.0
maxY = self._ypos + self._height / 2.0
leftX = self._xpos-self._width / 2
rightX = self._xpos + self._width / 2
leftX = self._xpos - self._width / 2.0
rightX = self._xpos + self._width / 2.0
if self._pen:
dc.SetPen(self._pen)
@@ -192,7 +190,7 @@ class DividedShape(RectangleShape):
actualY = min(maxY, y)
centreX = self._xpos
centreY = currentY + (actualY-currentY) / 2
centreY = currentY + (actualY - currentY) / 2.0
DrawFormattedText(dc, region._formattedText, centreX, centreY, self._width - 2 * xMargin, actualY - currentY - 2 * yMargin, region._formatMode)
@@ -218,11 +216,11 @@ class DividedShape(RectangleShape):
return
if self.GetRegions():
defaultProportion = 1 / len(self.GetRegions())
defaultProportion = 1.0 / len(self.GetRegions())
else:
defaultProportion = 0
currentY = self._ypos-self._height / 2
maxY = self._ypos + self._height / 2
defaultProportion = 0.0
currentY = self._ypos - self._height / 2.0
maxY = self._ypos + self._height / 2.0
for region in self.GetRegions():
if region._regionProportionY <= 0:
@@ -234,7 +232,7 @@ class DividedShape(RectangleShape):
y = currentY + sizeY
actualY = min(maxY, y)
centreY = currentY + (actualY-currentY) / 2
centreY = currentY + (actualY - currentY) / 2.0
region.SetSize(self._width, sizeY)
region.SetPosition(0, centreY - self._ypos)
@@ -250,10 +248,10 @@ class DividedShape(RectangleShape):
n = len(self.GetRegions())
isEnd = line and line.IsEnd(self)
left = self._xpos-self._width / 2
right = self._xpos + self._width / 2
top = self._ypos-self._height / 2
bottom = self._ypos + self._height / 2
left = self._xpos - self._width / 2.0
right = self._xpos + self._width / 2.0
top = self._ypos - self._height / 2.0
bottom = self._ypos + self._height / 2.0
# Zero is top, n + 1 is bottom
if attachment == 0:
@@ -269,7 +267,7 @@ class DividedShape(RectangleShape):
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:
@@ -285,7 +283,7 @@ class DividedShape(RectangleShape):
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
@@ -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
@@ -319,7 +317,7 @@ class DividedShape(RectangleShape):
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:
@@ -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
@@ -374,8 +372,8 @@ class DividedShape(RectangleShape):
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:

View File

@@ -11,8 +11,6 @@
# Licence: wxWindows license
#----------------------------------------------------------------------------
from __future__ import division
import sys
import math
@@ -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:
@@ -307,8 +305,8 @@ 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)
@@ -346,8 +344,8 @@ class LineShape(Shape):
else:
y2 = first_point[1]
y1 = last_point[1]
point[0] = (x2-x1) / 2 + x1
point[1] = (y2-y1) / 2 + y1
point[0] = (x2 - x1) / 2.0 + x1
point[1] = (y2 - y1) / 2.0 + y1
def FormatText(self, dc, s, i):
"""Format a text string according to the region size, adding
@@ -415,7 +413,7 @@ class LineShape(Shape):
# Now draw the text
if region.GetFont():
dc.SetFont(region.GetFont())
dc.DrawRectangle(xp-w / 2, yp-h / 2, w, h)
dc.DrawRectangle(xp - w / 2.0, yp - h / 2.0, w, h)
if self._pen:
dc.SetPen(self._pen)
@@ -440,7 +438,7 @@ class LineShape(Shape):
dc.SetPen(self.GetBackgroundPen())
dc.SetBrush(self.GetBackgroundBrush())
dc.DrawRectangle(xp-w / 2, yp-h / 2, w, h)
dc.DrawRectangle(xp - w / 2.0, yp - h / 2.0, w, h)
def GetLabelPosition(self, position):
"""Get the reference point for a label.
@@ -450,7 +448,7 @@ class LineShape(Shape):
"""
if position == 0:
# Want to take the middle section for the label
half_way = int(len(self._lineControlPoints) / 2)
half_way = int(len(self._lineControlPoints) / 2.0)
# Find middle of this line
point = self._lineControlPoints[half_way - 1]
@@ -459,7 +457,7 @@ class LineShape(Shape):
dx = next_point[0] - point[0]
dy = next_point[1] - point[1]
return point[0] + dx / 2, point[1] + dy / 2
return point[0] + dx / 2.0, point[1] + dy / 2.0
elif position == 1:
return self._lineControlPoints[0][0], self._lineControlPoints[0][1]
elif position == 2:
@@ -501,8 +499,8 @@ class LineShape(Shape):
last_point[0] = x2
last_point[1] = y2
self._xpos = (x1 + x2) / 2
self._ypos = (y1 + y2) / 2
self._xpos = (x1 + x2) / 2.0
self._ypos = (y1 + y2) / 2.0
# Get absolute positions of ends
def GetEnds(self):
@@ -536,10 +534,10 @@ class LineShape(Shape):
cx += xp
cy += yp
rLeft = cx-cw / 2
rTop = cy-ch / 2
rRight = cx + cw / 2
rBottom = cy + ch / 2
rLeft = cx - cw / 2.0
rTop = cy - ch / 2.0
rRight = cx + cw / 2.0
rBottom = cy + ch / 2.0
if x > rLeft and x < rRight and y > rTop and y < rBottom:
inLabelRegion = True
break
@@ -557,8 +555,8 @@ class LineShape(Shape):
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) < extra and distance_from_prev >= 0 and distance_from_prev <= seg_len or inLabelRegion:
return 0, distance_from_seg
@@ -633,8 +631,8 @@ 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.
@@ -663,12 +661,12 @@ class LineShape(Shape):
# Where theta = math.tan(-1) of (y3-y1) / (x3-x1)
x1 = startPositionX
y1 = startPositionY
x3 = positionOnLineX
y3 = positionOnLineY
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))
@@ -681,7 +679,7 @@ class LineShape(Shape):
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,15 +736,15 @@ 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
theta = 3.0 * math.pi / 2.0
elif x1 == x2 and y2 > y1:
theta = math.pi / 2
theta = math.pi / 2.0
elif x2 > x1 and y2 >= y1:
theta = math.atan((y2 - y1) / (x2 - x1))
elif x2 < x1:
@@ -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)
@@ -796,7 +794,7 @@ 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,
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

View File

@@ -11,7 +11,6 @@
# Licence: wxWindows license
#----------------------------------------------------------------------------
from __future__ import division
import math
import wx
@@ -183,16 +182,16 @@ def CentreText(dc, text_list, xpos, ypos, width, height, formatMode):
if formatMode & FORMAT_CENTRE_VERT:
if max_height < height:
yoffset = ypos - height / 2 + (height - max_height) / 2
yoffset = ypos - height / 2.0 + (height - max_height) / 2.0
else:
yoffset = ypos - height / 2
yoffset = ypos - height / 2.0
yOffset = ypos
else:
yoffset = 0.0
yOffset = 0.0
if formatMode & FORMAT_CENTRE_HORIZ:
xoffset = xpos - width / 2
xoffset = xpos - width / 2.0
xOffset = xpos
else:
xoffset = 0.0
@@ -200,7 +199,7 @@ def CentreText(dc, text_list, xpos, ypos, width, height, formatMode):
for i, line in enumerate(text_list):
if formatMode & FORMAT_CENTRE_HORIZ and widths[i] < width:
x = (width - widths[i]) / 2 + xoffset
x = (width - widths[i]) / 2.0 + xoffset
else:
x = xoffset
y = i * char_height + yoffset
@@ -214,15 +213,15 @@ def DrawFormattedText(dc, text_list, xpos, ypos, width, height, formatMode):
if formatMode & FORMAT_CENTRE_HORIZ:
xoffset = xpos
else:
xoffset = xpos - width / 2
xoffset = xpos - width / 2.0
if formatMode & FORMAT_CENTRE_VERT:
yoffset = ypos
else:
yoffset = ypos - height / 2
yoffset = ypos - height / 2.0
# +1 to allow for rounding errors
dc.SetClippingRegion(xpos - width / 2, ypos - height / 2, width + 1, height + 1)
dc.SetClippingRegion(xpos - width / 2.0, ypos - height / 2.0, width + 1, height + 1)
for line in text_list:
dc.DrawText(line.GetText(), xoffset + line.GetX(), yoffset + line.GetY())
@@ -238,8 +237,8 @@ def RoughlyEqual(val1, val2, tol = 0.00001):
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)
@@ -331,7 +330,7 @@ def GraphicsStraightenLine(point1, point2):
if dx == 0:
return
elif abs(dy / dx)>1:
elif abs(float(dy) / dx) > 1:
point2[0] = point1[0]
else:
point2[1] = point1[0]
@@ -367,8 +366,8 @@ def GetArrowPoints(x1, y1, x2, y2, length, width):
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:
@@ -387,7 +386,7 @@ 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: