# 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())
# Licence: wxWindows license
#----------------------------------------------------------------------------
-from __future__ import division
-
import wx
import math
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
def ClearText(self, regionId = 0):
"""Clear the text from the specified text region."""
if regionId == 0:
- self._text=""
- if regionId<len(self._regions):
+ self._text = ""
+ if regionId < len(self._regions):
self._regions[regionId].ClearText()
def ClearRegions(self):
the given point and target.
"""
width, height = self.GetBoundingBoxMax()
- if abs(width)<4:
+ if abs(width) < 4:
width = 4.0
- if abs(height)<4:
+ if abs(height) < 4:
height = 4.0
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
if e:
xp, yp = e
l = math.sqrt(((xp - x) * (xp - x)) + (yp - y) * (yp - y))
- if l<nearest:
+ if l < nearest:
nearest = l
nearest_attachment = i
if not self._regions:
return
- if i>len(self._regions):
+ if i > len(self._regions):
return
region = self._regions[i]
def SetFont(self, the_font, regionId = 0):
"""Set the font for the specified text region."""
self._font = the_font
- if regionId<len(self._regions):
+ if regionId < len(self._regions):
self._regions[regionId].SetFont(the_font)
def GetFont(self, regionId = 0):
FORMAT_CENTRE_VERT
Vertical centring.
"""
- if regionId<len(self._regions):
+ if regionId < len(self._regions):
self._regions[regionId].SetFormatMode(mode)
def GetFormatMode(self, regionId = 0):
self._textColour = wx.TheColourDatabase.Find(the_colour)
self._textColourName = the_colour
- if regionId<len(self._regions):
+ if regionId < len(self._regions):
self._regions[regionId].SetColour(the_colour)
def GetTextColour(self, regionId = 0):
The name for a region is unique within the scope of the whole
composite, whereas a region id is unique only for a single image.
"""
- if regionId<len(self._regions):
+ if regionId < len(self._regions):
self._regions[regionId].SetName(name)
def GetRegionName(self, regionId = 0):
for the given region name.
"""
id = self.GetRegionId(name)
- if id>-1:
+ if id > -1:
return self, id
for child in self._children:
if actualImage:
return actualImage, regionId
- return None,-1
+ return None, -1
# Finds all region names for this image (composite or simple).
def FindRegionNames(self):
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:
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.
"""
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:
# 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
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())
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):
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.
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:
self._lines.remove(line)
except ValueError:
pass
- if positionFrom<len(self._lines):
+ if positionFrom < len(self._lines):
self._lines.insert(positionFrom, line)
else:
self._lines.append(line)
- if positionTo==-1:
+ if positionTo == -1:
if not other in other._lines:
other._lines.append(line)
else:
other._lines.remove(line)
except ValueError:
pass
- if positionTo<len(other._lines):
+ if positionTo < len(other._lines):
other._lines.insert(positionTo, line)
else:
other._lines.append(line)
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)
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
else:
maxN = 3
for point in self._attachmentPoints:
- if point._id>maxN:
+ if point._id > maxN:
maxN = point._id
return maxN + 1
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)
isHorizontal = RoughlyEqual(pt1[1], pt2[1])
if isHorizontal:
- if pt1[0]>pt2[0]:
+ if pt1[0] > pt2[0]:
firstPoint = pt2
secondPoint = pt1
else:
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]<firstPoint[0]:
+ if point[0] < firstPoint[0]:
x = firstPoint[0]
- elif 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:
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]<firstPoint[1]:
+ if point[1] < firstPoint[1]:
y = firstPoint[1]
- elif 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
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
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
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
# 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"
# 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
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:
"""
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
"""
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
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):
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)
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
# 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
+ if pt.GetX() < self.GetX():
+ 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
+ if pt.GetY() < self.GetY():
+ 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
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)
- if pt.GetY()>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)
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
# 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)
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:
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.x<left:
+ if point.x < left:
left = point.x
- if point.x>right:
+ if point.x > right:
right = point.x
- if point.y<top:
+ if point.y < top:
top = point.y
- if point.y>bottom:
+ if point.y > bottom:
bottom = point.y
self._boundWidth = right - left
box.
"""
left = 10000
- right=-10000
+ right = -10000
top = 10000
- bottom=-10000
+ bottom = -10000
for point in self._points:
- if point.x<left:
+ if point.x < left:
left = point.x
- if point.x>right:
+ if point.x > right:
right = point.x
- if point.y<top:
+ if point.y < top:
top = point.y
- if point.y>bottom:
+ 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
if e:
xp, yp = e
l = math.sqrt((xp - x) * (xp - x) + (yp - y) * (yp - y))
- if l<nearest:
+ if l < nearest:
nearest = l
nearest_attachment = i
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
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:
def DeletePolygonPoint(self, pos):
"""Delete the given control point."""
- if pos<len(self._points):
+ if pos < len(self._points):
del self._points[pos]
self.UpdateOriginalPoints()
if self._selected:
# a heuristic...
for point in self._points:
if point.x == 0:
- if y2>y1 and point.y>0:
+ if y2 > y1 and point.y > 0:
return point.x + self._xpos, point.y + self._ypos
- elif y2<y1 and point.y<0:
+ elif y2 < y1 and point.y < 0:
return point.x + self._xpos, point.y + self._ypos
xpoints = []
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:
def GetNumberOfAttachments(self):
maxN = max(len(self._points) - 1, 0)
for point in self._attachmentPoints:
- if point._id>maxN:
+ 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<len(self._points):
+ if self._attachmentMode == ATTACHMENT_MODE_EDGE and self._points and attachment < len(self._points):
point = self._points[0]
return point.x + self._xpos, point.y + self._ypos
return Shape.GetAttachmentPosition(self, attachment, nth, no_arcs, line)
if not self._points:
return False
- if attachment >= 0 and attachment<len(self._points):
+ if attachment >= 0 and attachment < len(self._points):
return True
for point in self._attachmentPoints:
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:
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)
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
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
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)
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)
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
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
# Licence: wxWindows license
#----------------------------------------------------------------------------
-from __future__ import division
-
from _basic import 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):
# Licence: wxWindows license
#----------------------------------------------------------------------------
-from __future__ import division
-
import wx
from _lines import LineShape
from _composit import *
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
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
# 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
# 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
# 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<nearest:
+ if dist < nearest:
nearest = dist
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.
# Licence: wxWindows license
#----------------------------------------------------------------------------
-from __future__ import division
-
import sys
import wx
self._constraintingObject = constraining
self._constraintId = 0
- self._constraintName="noname"
+ self._constraintName = "noname"
self._constrainedObjects = constrained[:]
"""
marg = 0.5
- return b <= a + marg and b >= a-marg
+ return b <= a + marg and b >= a - marg
def Evaluate(self):
"""Evaluate this constraint and return TRUE if anything changed."""
# 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)
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)
# 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)
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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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:
Shape.OnDrawContents(self, dc)
def OnMovePre(self, dc, x, y, old_x, old_y, display = True):
- diffX = x-old_x
- diffY = y-old_y
+ diffX = x - old_x
+ diffY = y - old_y
for object in self._children:
object.Erase(dc)
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
for object in self._children:
# Scale the position first
- newX = (object.GetX()-self.GetX()) * xScale + self.GetX()
- newY = (object.GetY()-self.GetY()) * yScale + self.GetY()
+ newX = (object.GetX() - self.GetX()) * xScale + self.GetX()
+ newY = (object.GetY() - self.GetY()) * yScale + self.GetY()
object.Show(False)
object.Move(dc, newX, newY)
object.Show(True)
"""Calculates the size and position of the composite based on
child sizes and positions.
"""
- maxX=-999999.9
- maxY=-999999.9
+ maxX = -999999.9
+ maxY = -999999.9
minX = 999999.9
minY = 999999.9
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
-
- self._width = maxX-minX
- self._height = maxY-minY
- self._xpos = self._width / 2 + minX
- self._ypos = self._height / 2 + minY
+ 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.0 + minX
+ self._ypos = self._height / 2.0 + minY
def Recompute(self):
"""Recomputes any constraints associated with the object. If FALSE is
"""
noIterations = 0
changed = True
- while changed and noIterations<500:
+ while changed and noIterations < 500:
changed = self.Constrain()
noIterations += 1
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:
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):
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:
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)
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()
# 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)
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)
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():
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:
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.
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
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())
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
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())
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
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())
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
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())
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))
# Licence: wxWindows license
#----------------------------------------------------------------------------
-from __future__ import division
-
import wx
DEFAULT_MOUSE_TOLERANCE = 3
# Licence: wxWindows license
#----------------------------------------------------------------------------
-from __future__ import division
-
import sys
import wx
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)
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)
# 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
if region == thisRegion:
thisRegionTop = currentY
- if i + 1<len(dividedObject.GetRegions()):
+ if i + 1 < len(dividedObject.GetRegions()):
nextRegion = dividedObject.GetRegions()[i + 1]
if region == nextRegion:
nextRegionBottom = actualY
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)
- self._yoffset = y-dividedObject.GetY()
+ self._yoffset = y - dividedObject.GetY()
# Now reformat text
for i, region in enumerate(dividedObject.GetRegions()):
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)
# For efficiency, don't do this under X - doesn't make
# any visible difference for our purposes.
- if sys.platform[:3]=="win":
+ if sys.platform[:3] == "win":
dc.SetTextBackground(self._brush.GetColour())
if self.GetDisableLabel():
dc.SetFont(region.GetFont())
dc.SetTextForeground(region.GetActualColourObject())
- if region._regionProportionY<0:
+ if region._regionProportionY < 0:
proportion = defaultProportion
else:
proportion = region._regionProportionY
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)
+ DrawFormattedText(dc, region._formattedText, centreX, centreY, self._width - 2 * xMargin, actualY - currentY - 2 * yMargin, region._formatMode)
if y <= maxY and region != self.GetRegions()[-1]:
regionPen = region.GetActualPen()
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:
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)
+ region.SetPosition(0, centreY - self._ypos)
currentY = actualY
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:
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.x<left:
+ if point.x < left:
x = left
- elif point.x>right:
+ 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:
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.x<left:
+ if point.x < left:
x = left
- elif point.x>right:
+ 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:
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
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.y<bottom:
+ if point.y < bottom:
y = bottom
- elif point.y>top:
+ 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:
# 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
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
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)
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:
actualY = min(maxY, y)
controlPoint._xoffset = 0
- controlPoint._yoffset = actualY-self.GetY()
+ controlPoint._yoffset = actualY - self.GetY()
currentY = actualY
# Licence: wxWindows license
#----------------------------------------------------------------------------
-from __future__ import division
-
import sys
import math
# 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
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:
self._arrowName = name
self._metaFile = mf
self._id = arrowId
- if self._id==-1:
+ if self._id == -1:
self._id = wx.NewId()
def _GetType(self):
if oldWidth == 0:
return
- scale = size / oldWidth
+ scale = float(size) / oldWidth
if scale != 1:
self._metaFile.Scale(scale, scale)
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:
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)
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):
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]
# and the last.
for point in self._lineControlPoints[1:]:
- if point[0]==-999:
- if first_point[0]<last_point[0]:
+ if point[0] == -999:
+ if first_point[0] < last_point[0]:
x1 = first_point[0]
x2 = last_point[0]
else:
x2 = first_point[0]
x1 = last_point[0]
- if first_point[1]<last_point[1]:
+ if first_point[1] < last_point[1]:
y1 = first_point[1]
y2 = last_point[1]
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
w, h = 100, 50
region.SetSize(w, h)
- string_list = FormatText(dc, s, w-5, h-5, region.GetFormatMode())
+ string_list = FormatText(dc, s, w - 5, h - 5, region.GetFormatMode())
for s in string_list:
line = ShapeTextLine(0.0, 0.0, s)
region.GetFormattedText().append(line)
if actualW != w or actualH != h:
xx, yy = self.GetLabelPosition(i)
self.EraseRegion(dc, region, xx, yy)
- if len(self._labelObjects)<i:
+ if len(self._labelObjects) < i:
self._labelObjects[i].Select(False, dc)
self._labelObjects[i].Erase(dc)
self._labelObjects[i].SetSize(actualW, actualH)
region.SetSize(actualW, actualH)
- if len(self._labelObjects)<i:
+ if len(self._labelObjects) < i:
self._labelObjects[i].Select(True, dc)
self._labelObjects[i].Draw(dc)
# 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)
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.
"""
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]
+ point = self._lineControlPoints[half_way - 1]
next_point = self._lineControlPoints[half_way]
- dx = next_point[0]-point[0]
- dy = next_point[1]-point[1]
+ 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:
def Straighten(self, dc = None):
"""Straighten verticals and horizontals."""
- if len(self._lineControlPoints)<3:
+ if len(self._lineControlPoints) < 3:
return
if dc:
GraphicsStraightenLine(self._lineControlPoints[-1], self._lineControlPoints[-2])
- for i in range(len(self._lineControlPoints)-2):
+ for i in range(len(self._lineControlPoints) - 2):
GraphicsStraightenLine(self._lineControlPoints[i], self._lineControlPoints[i + 1])
if dc:
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):
xp, yp = self.GetLabelPosition(i)
# Offset region from default label position
cx, cy = region.GetPosition()
- cw, ch = region.GetSize()
+ cw, ch = region.GetSize()
cx += xp
cy += yp
- rLeft = cx-cw / 2
- rTop = cy-ch / 2
- rRight = cx + cw / 2
- rBottom = cy + ch / 2
- if x>rLeft and x<rRight and y>rTop and y<rBottom:
+ 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
- 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)<extra and distance_from_prev >= 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
# 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)
# 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)
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)
# 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)
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())
#
x, y = GetPointOnLine(startPositionX, startPositionY,
positionOnLineX, positionOnLineY,
- arrow.GetMetaFile()._width / 2)
+ arrow.GetMetaFile()._width / 2.0)
# Calculate theta for rotating the metafile.
#
# |
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 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))
+ elif x1 == x2 and y1 > 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"
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)
# 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
def GetBoundingBoxMin(self):
x1, y1 = 10000, 10000
- x2, y2=-10000,-10000
+ x2, y2 = -10000, -10000
for point in self._lineControlPoints:
- if point[0]<x1:
+ if point[0] < x1:
x1 = point[0]
- if point[1]<y1:
+ if point[1] < y1:
y1 = point[1]
- 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,
Specify whether incoming or outgoing lines are being considered
with incoming.
"""
- n=-1
+ n = -1
num = 0
if image == self._to:
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:
if self._labelObjects[i]:
self._labelObjects[i].Erase(dc)
xp, yp = self.GetLabelPosition(i)
- if i<len(self._regions):
+ if i < len(self._regions):
xr, yr = self._regions[i].GetPosition()
else:
xr, yr = 0, 0
if not self._from or not self._to:
return
- if len(self._lineControlPoints)>2:
+ if len(self._lineControlPoints) > 2:
self.Initialise()
# Do each end - nothing in the middle. User has to move other points
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
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)
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)
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:
return True
i1 = i2 = 0
- while i1<len(referenceList) and i2<len(self._arcArrows):
+ while i1 < len(referenceList) and i2 < len(self._arcArrows):
refArrow = referenceList[i1]
currArrow = self._arcArrows[i2]
# Check if we're at the correct position in the
# reference list
if targetName == refArrow.GetName():
- if i2<len(self._arcArrows):
+ if i2 < len(self._arcArrows):
self._arcArrows.insert(i2, arrow)
else:
self._arcArrows.append(arrow)
"""Delete the arrows at the specified position, or at any position
if position is -1.
"""
- if end==-1:
+ if end == -1:
self._arcArrows = []
return
if position is -1, matches any position.
"""
for arrow in self._arcArrows:
- if (position==-1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
+ if (position == -1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
return arow
return None
if position is -1, matches any position.
"""
for arrow in self._arcArrows:
- if (position==-1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
+ if (position == -1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
self._arcArrows.remove(arrow)
return True
return False
# We have ABSOLUTE minimum now. So
# scale it to give it reasonable aesthetics
# when drawing with line.
- if minWidth>0:
+ if minWidth > 0:
minWidth = minWidth * 1.4
else:
minWidth = 20.0
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 centreDistance<startDistance and centreDistance<endDistance:
+ if centreDistance < startDistance and centreDistance < endDistance:
return ARROW_POSITION_MIDDLE
- elif startDistance<endDistance:
+ elif startDistance < endDistance:
return ARROW_POSITION_START
else:
return ARROW_POSITION_END
if self._to == shape:
# Must be END of line, so we want (n - 1)th control point.
# But indexing ends at n-1, so subtract 2.
- nn = n-2
+ nn = n - 2
else:
nn = 1
- if nn<len(self._lineControlPoints):
+ if nn < len(self._lineControlPoints):
return self._lineControlPoints[nn]
return None
xx, yy = self.GetLabelPosition(i)
# Set the region's offset, relative to the default position for
# each region.
- labelShape._shapeRegion.SetPosition(x-xx, y-yy)
+ labelShape._shapeRegion.SetPosition(x - xx, y - yy)
labelShape.SetX(x)
labelShape.SetY(y)
# Licence: wxWindows license
#----------------------------------------------------------------------------
-from __future__ import division
import math
import wx
# Interpret %n and 10 or 13 as a new line.
def FormatText(dc, text, width, height, formatMode):
i = 0
- word=""
+ word = ""
word_list = []
end_word = False
new_line = False
- while i<len(text):
- if text[i]=="%":
+ while i < len(text):
+ if text[i] == "%":
i += 1
if i == len(text):
- word+="%"
+ word += "%"
else:
- if text[i]=="n":
+ if text[i] == "n":
new_line = True
end_word = True
i += 1
else:
- word+="%"+text[i]
+ word += "%" + text[i]
i += 1
elif text[i] in ["\012","\015"]:
new_line = True
end_word = True
i += 1
- elif text[i]==" ":
+ elif text[i] == " ":
end_word = True
i += 1
else:
if end_word:
word_list.append(word)
- word=""
+ word = ""
end_word = False
if new_line:
word_list.append(None)
# Now, make a list of strings which can fit in the box
string_list = []
- buffer=""
+ buffer = ""
for s in word_list:
oldBuffer = buffer
if s is None:
# FORCE NEW LINE
- if len(buffer)>0:
+ 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)
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
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<height:
- yoffset = ypos - height / 2 + (height - max_height) / 2
+ if max_height < height:
+ 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
xOffset = 0.0
for i, line in enumerate(text_list):
- if formatMode & FORMAT_CENTRE_HORIZ and widths[i]<width:
- x = (width - widths[i]) / 2 + xoffset
+ if formatMode & FORMAT_CENTRE_HORIZ and widths[i] < width:
+ x = (width - widths[i]) / 2.0 + xoffset
else:
x = xoffset
y = i * char_height + yoffset
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())
def RoughlyEqual(val1, val2, tol = 0.00001):
- return val1<(val2 + tol) and val1>(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)
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
lastx = xvec[i]
lasty = yvec[i]
- if line_ratio<min_ratio:
+ if line_ratio < min_ratio:
min_ratio = line_ratio
# Do last (implicit) line if last and first doubles are not identical
if not (xvec[0] == lastx and yvec[0] == lasty):
line_ratio, other_ratio = CheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[0], yvec[0])
- if line_ratio<min_ratio:
+ if line_ratio < min_ratio:
min_ratio = line_ratio
return x1 + (x2 - x1) * min_ratio, y1 + (y2 - y1) * min_ratio
lastx = xvec[i]
lasty = yvec[i]
- if line_ratio<min_ratio:
+ if line_ratio < min_ratio:
min_ratio = line_ratio
# Do last (implicit) line if last and first doubles are not identical
if dx == 0:
return
- elif abs(dy / dx)>1:
+ elif abs(float(dy) / dx) > 1:
point2[0] = point1[0]
else:
point2[1] = point1[0]
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))))
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