X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b2f6eb0606be607c176121ad4ae272e3112f44eb..25b3661bd4cb44304418b93c0dee1d0dfb99765c:/wxPython/wx/lib/ogl/_composit.py diff --git a/wxPython/wx/lib/ogl/_composit.py b/wxPython/wx/lib/ogl/_composit.py index dbc20e6291..812b7539a1 100644 --- a/wxPython/wx/lib/ogl/_composit.py +++ b/wxPython/wx/lib/ogl/_composit.py @@ -11,8 +11,6 @@ # Licence: wxWindows license #---------------------------------------------------------------------------- -from __future__ import division - import sys import wx @@ -135,10 +133,10 @@ class Constraint(object): self._ySpacing = 0.0 self._constraintType = type - self._constraintingObject = constraining + self._constrainingObject = constraining self._constraintId = 0 - self._constraintName="noname" + self._constraintName = "noname" self._constrainedObjects = constrained[:] @@ -156,17 +154,17 @@ class Constraint(object): """ 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.""" - maxWidth, maxHeight = self._constraintingObject.GetBoundingBoxMax() - minWidth, minHeight = self._constraintingObject.GetBoundingBoxMin() - x = self._constraintingObject.GetX() - y = self._constraintingObject.GetY() + maxWidth, maxHeight = self._constrainingObject.GetBoundingBoxMax() + minWidth, minHeight = self._constrainingObject.GetBoundingBoxMin() + x = self._constrainingObject.GetX() + y = self._constrainingObject.GetY() - dc = wx.ClientDC(self._constraintingObject.GetCanvas()) - self._constraintingObject.GetCanvas().PrepareDC(dc) + dc = wx.ClientDC(self._constrainingObject.GetCanvas()) + self._constrainingObject.GetCanvas().PrepareDC(dc) if self._constraintType == CONSTRAINT_CENTRED_VERTICALLY: n = len(self._constrainedObjects) @@ -177,21 +175,21 @@ class Constraint(object): # Check if within the constraining object... if totalObjectHeight + (n + 1) * self._ySpacing <= minHeight: - spacingY = (minHeight-totalObjectHeight) / (n + 1) - startY = y-minHeight / 2 + spacingY = (minHeight - totalObjectHeight) / (n + 1.0) + startY = y - minHeight / 2.0 else: # Otherwise, use default spacing spacingY = self._ySpacing - startY = y-(totalObjectHeight + (n + 1) * spacingY) / 2 + startY = y - (totalObjectHeight + (n + 1) * spacingY) / 2.0 # Now position the objects changed = False for constrainedObject in self._constrainedObjects: width2, height2 = constrainedObject.GetBoundingBoxMax() - startY += spacingY + height2 / 2 + startY += spacingY + height2 / 2.0 if not self.Equals(startY, constrainedObject.GetY()): constrainedObject.Move(dc, constrainedObject.GetX(), startY, False) changed = True - startY += height2 / 2 + startY += height2 / 2.0 return changed elif self._constraintType == CONSTRAINT_CENTRED_HORIZONTALLY: n = len(self._constrainedObjects) @@ -201,22 +199,22 @@ class Constraint(object): totalObjectWidth += width2 # Check if within the constraining object... - if totalObjectWidth + (n + 1) * self._xSpacingmaxX: - maxX = child.GetX() + w / 2 - if child.GetX()-w / 2maxY: - maxY = child.GetY() + h / 2 - if child.GetY()-h / 2 maxX: + maxX = child.GetX() + w / 2.0 + if child.GetX() - w / 2.0 < minX: + minX = child.GetX() - w / 2.0 + if child.GetY() + h / 2.0 > maxY: + maxY = child.GetY() + h / 2.0 + if child.GetY() - h / 2.0 < minY: + minY = child.GetY() - h / 2.0 + + self._width = maxX - minX + self._height = maxY - minY + self._xpos = self._width / 2.0 + minX + self._ypos = self._height / 2.0 + minY def Recompute(self): """Recomputes any constraints associated with the object. If FALSE is @@ -661,7 +661,7 @@ class CompositeShape(RectangleShape): """ noIterations = 0 changed = True - while changed and noIterations<500: + while changed and noIterations < 500: changed = self.Constrain() noIterations += 1 @@ -783,17 +783,17 @@ class DivisionControlPoint(ControlPoint): divisionParent = division.GetParent() # Need to check it's within the bounds of the parent composite - x1 = divisionParent.GetX()-divisionParent.GetWidth() / 2 - y1 = divisionParent.GetY()-divisionParent.GetHeight() / 2 - x2 = divisionParent.GetX() + divisionParent.GetWidth() / 2 - y2 = divisionParent.GetY() + divisionParent.GetHeight() / 2 + x1 = divisionParent.GetX() - divisionParent.GetWidth() / 2.0 + y1 = divisionParent.GetY() - divisionParent.GetHeight() / 2.0 + x2 = divisionParent.GetX() + divisionParent.GetWidth() / 2.0 + y2 = divisionParent.GetY() + divisionParent.GetHeight() / 2.0 # Need to check it has not made the division zero or negative # width / height - dx1 = division.GetX()-division.GetWidth() / 2 - dy1 = division.GetY()-division.GetHeight() / 2 - dx2 = division.GetX() + division.GetWidth() / 2 - dy2 = division.GetY() + division.GetHeight() / 2 + dx1 = division.GetX() - division.GetWidth() / 2.0 + dy1 = division.GetY() - division.GetHeight() / 2.0 + dx2 = division.GetX() + division.GetWidth() / 2.0 + dy2 = division.GetY() + division.GetHeight() / 2.0 success = True if division.GetHandleSide() == DIVISION_SIDE_LEFT: @@ -895,10 +895,10 @@ class DivisionShape(CompositeShape): self._handleSide = DIVISION_SIDE_NONE self._leftSidePen = wx.BLACK_PEN self._topSidePen = wx.BLACK_PEN - self._leftSideColour="BLACK" - self._topSideColour="BLACK" - self._leftSideStyle="Solid" - self._topSideStyle="Solid" + self._leftSideColour = "BLACK" + self._topSideColour = "BLACK" + self._leftSideStyle = "Solid" + self._topSideStyle = "Solid" self.ClearRegions() def SetLeftSide(self, shape): @@ -994,13 +994,13 @@ class DivisionShape(CompositeShape): dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetBackgroundMode(wx.TRANSPARENT) - x1 = self.GetX()-self.GetWidth() / 2 - y1 = self.GetY()-self.GetHeight() / 2 - x2 = self.GetX() + self.GetWidth() / 2 - y2 = self.GetY() + self.GetHeight() / 2 + x1 = self.GetX() - self.GetWidth() / 2.0 + y1 = self.GetY() - self.GetHeight() / 2.0 + x2 = self.GetX() + self.GetWidth() / 2.0 + y2 = self.GetY() + self.GetHeight() / 2.0 # Should subtract 1 pixel if drawing under Windows - if sys.platform[:3]=="win": + if sys.platform[:3] == "win": y2 -= 1 if self._leftSide: @@ -1020,8 +1020,8 @@ class DivisionShape(CompositeShape): CompositeShape.OnDrawContents(self, dc) def OnMovePre(self, dc, x, y, oldx, oldy, display = True): - diffX = x-oldx - diffY = y-oldy + diffX = x - oldx + diffY = y - oldy for object in self._children: object.Erase(dc) object.Move(dc, object.GetX() + diffX, object.GetY() + diffY, display) @@ -1100,8 +1100,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 +1117,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 +1153,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 +1189,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 +1212,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 +1241,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 +1262,7 @@ class DivisionShape(CompositeShape): Returns FALSE if it's not physically possible to adjust it to this point. """ - x2 = self.GetX() + self.GetWidth() / 2 + x2 = self.GetX() + self.GetWidth() / 2.0 if left >= x2: return False @@ -1270,8 +1270,8 @@ class DivisionShape(CompositeShape): if test: return True - newW = x2-left - newX = left + newW / 2 + newW = x2 - left + newX = left + newW / 2.0 self.SetSize(newW, self.GetHeight()) dc = wx.ClientDC(self.GetCanvas()) @@ -1286,7 +1286,7 @@ class DivisionShape(CompositeShape): Returns FALSE if it's not physically possible to adjust it to this point. """ - y2 = self.GetY() + self.GetHeight() / 2 + y2 = self.GetY() + self.GetHeight() / 2.0 if top >= y2: return False @@ -1294,8 +1294,8 @@ class DivisionShape(CompositeShape): if test: return True - newH = y2-top - newY = top + newH / 2 + newH = y2 - top + newY = top + newH / 2.0 self.SetSize(self.GetWidth(), newH) dc = wx.ClientDC(self.GetCanvas()) @@ -1310,7 +1310,7 @@ class DivisionShape(CompositeShape): Returns FALSE if it's not physically possible to adjust it to this point. """ - x1 = self.GetX()-self.GetWidth() / 2 + x1 = self.GetX() - self.GetWidth() / 2.0 if right <= x1: return False @@ -1318,8 +1318,8 @@ class DivisionShape(CompositeShape): if test: return True - newW = right-x1 - newX = x1 + newW / 2 + newW = right - x1 + newX = x1 + newW / 2.0 self.SetSize(newW, self.GetHeight()) dc = wx.ClientDC(self.GetCanvas()) @@ -1334,7 +1334,7 @@ class DivisionShape(CompositeShape): Returns FALSE if it's not physically possible to adjust it to this point. """ - y1 = self.GetY()-self.GetHeight() / 2 + y1 = self.GetY() - self.GetHeight() / 2.0 if bottom <= y1: return False @@ -1342,8 +1342,8 @@ class DivisionShape(CompositeShape): if test: return True - newH = bottom-y1 - newY = y1 + newH / 2 + newH = bottom - y1 + newY = y1 + newH / 2.0 self.SetSize(self.GetWidth(), newH) dc = wx.ClientDC(self.GetCanvas()) @@ -1422,8 +1422,8 @@ class DivisionShape(CompositeShape): dc = wx.ClientDC(self.GetCanvas()) self.GetCanvas().PrepareDC(dc) - mouse_x = dc.LogicalToDeviceX(x-x1 * unit_x) - mouse_y = dc.LogicalToDeviceY(y-y1 * unit_y) + mouse_x = dc.LogicalToDeviceX(x - x1 * unit_x) + mouse_y = dc.LogicalToDeviceY(y - y1 * unit_y) self._canvas.PopupMenu(menu, (mouse_x, mouse_y))