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:
@@ -11,7 +11,6 @@
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
from __future__ import division
|
||||
import math
|
||||
|
||||
import wx
|
||||
@@ -79,28 +78,28 @@ LINE_ALIGNMENT_NONE = 0
|
||||
# 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:
|
||||
@@ -112,7 +111,7 @@ def FormatText(dc, text, width, height, formatMode):
|
||||
|
||||
if end_word:
|
||||
word_list.append(word)
|
||||
word=""
|
||||
word = ""
|
||||
end_word = False
|
||||
if new_line:
|
||||
word_list.append(None)
|
||||
@@ -120,23 +119,23 @@ def FormatText(dc, text, width, height, formatMode):
|
||||
|
||||
# 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)
|
||||
@@ -155,7 +154,7 @@ def GetCentredTextExtent(dc, text_list, xpos = 0, ypos = 0, width = 0, height =
|
||||
max_width = 0
|
||||
for line in text_list:
|
||||
current_width, char_height = dc.GetTextExtent(line)
|
||||
if current_width>max_width:
|
||||
if current_width > max_width:
|
||||
max_width = current_width
|
||||
|
||||
return max_width, len(text_list) * char_height
|
||||
@@ -176,31 +175,31 @@ def CentreText(dc, text_list, xpos, ypos, width, height, formatMode):
|
||||
for line in text_list:
|
||||
current_width, char_height = dc.GetTextExtent(line.GetText())
|
||||
widths.append(current_width)
|
||||
if current_width>max_width:
|
||||
if current_width > max_width:
|
||||
max_width = current_width
|
||||
|
||||
max_height = len(text_list) * char_height
|
||||
|
||||
if formatMode & FORMAT_CENTRE_VERT:
|
||||
if max_height<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
|
||||
@@ -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())
|
||||
@@ -232,14 +231,14 @@ def DrawFormattedText(dc, text_list, xpos, ypos, width, height, formatMode):
|
||||
|
||||
|
||||
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)
|
||||
|
||||
@@ -253,19 +252,19 @@ def CheckLineIntersection(x1, y1, x2, y2, x3, y3, x4, y4):
|
||||
k_line = 1.0
|
||||
|
||||
# Check for parallel lines
|
||||
if denominator_term<0.005 and denominator_term>-0.005:
|
||||
line_constant=-1.0
|
||||
if denominator_term < 0.005 and denominator_term > -0.005:
|
||||
line_constant = -1.0
|
||||
else:
|
||||
line_constant = float(numerator_term) / denominator_term
|
||||
|
||||
# Check for intersection
|
||||
if line_constant<1.0 and line_constant>0.0:
|
||||
if line_constant < 1.0 and line_constant > 0.0:
|
||||
# Now must check that other line hits
|
||||
if (y4 - y3)<0.005 and (y4 - y3)>-0.005:
|
||||
if (y4 - y3) < 0.005 and (y4 - y3) > -0.005:
|
||||
k_line = (x1 - x3 + line_constant * (x2 - x1)) / (x4 - x3)
|
||||
else:
|
||||
k_line = (y1 - y3 + line_constant * (y2 - y1)) / (y4 - y3)
|
||||
if k_line >= 0 and k_line<1:
|
||||
if k_line >= 0 and k_line < 1:
|
||||
length_ratio = line_constant
|
||||
else:
|
||||
k_line = 1
|
||||
@@ -285,13 +284,13 @@ def FindEndForPolyline(xvec, yvec, x1, y1, x2, y2):
|
||||
lastx = xvec[i]
|
||||
lasty = yvec[i]
|
||||
|
||||
if line_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
|
||||
@@ -312,7 +311,7 @@ def PolylineHitTest(xvec, yvec, x1, y1, x2, y2):
|
||||
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
|
||||
@@ -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]
|
||||
@@ -340,40 +339,40 @@ def GraphicsStraightenLine(point1, point2):
|
||||
|
||||
def GetPointOnLine(x1, y1, x2, y2, length):
|
||||
l = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
|
||||
if l<0.01:
|
||||
if l < 0.01:
|
||||
l = 0.01
|
||||
|
||||
i_bar = (x2 - x1) / l
|
||||
j_bar = (y2 - y1) / l
|
||||
|
||||
return -length * i_bar + x2,-length * j_bar + y2
|
||||
return -length * i_bar + x2, -length * j_bar + y2
|
||||
|
||||
|
||||
|
||||
def GetArrowPoints(x1, y1, x2, y2, length, width):
|
||||
l = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
|
||||
|
||||
if l<0.01:
|
||||
if l < 0.01:
|
||||
l = 0.01
|
||||
|
||||
i_bar = (x2 - x1) / l
|
||||
j_bar = (y2 - y1) / l
|
||||
|
||||
x3=-length * i_bar + x2
|
||||
y3=-length * j_bar + y2
|
||||
x3 = -length * i_bar + x2
|
||||
y3 = -length * j_bar + y2
|
||||
|
||||
return x2, y2, width*-j_bar + x3, width * i_bar + y3,-width*-j_bar + x3,-width * i_bar + y3
|
||||
return x2, y2, width * -j_bar + x3, width * i_bar + y3, -width * -j_bar + x3, -width * i_bar + y3
|
||||
|
||||
|
||||
|
||||
def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3):
|
||||
a1 = width1 / 2
|
||||
b1 = height1 / 2
|
||||
a1 = width1 / 2.0
|
||||
b1 = height1 / 2.0
|
||||
|
||||
# Check that x2 != x3
|
||||
if abs(x2 - x3)<0.05:
|
||||
if abs(x2 - x3) < 0.05:
|
||||
x4 = x2
|
||||
if y3>y2:
|
||||
if y3 > y2:
|
||||
y4 = y1 - math.sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1))))
|
||||
else:
|
||||
y4 = y1 + math.sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1))))
|
||||
@@ -387,16 +386,16 @@ def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3):
|
||||
E = (A + B)
|
||||
F = (C - (2 * A * x1) - (2 * B * x2))
|
||||
G = ((A * x1 * x1) + (B * x2 * x2) - (C * x2) + D - 1)
|
||||
H = ((y3 - y2) / (x2 - x2))
|
||||
H = (float(y3 - y2) / (x2 - x2))
|
||||
K = ((F * F) - (4 * E * G))
|
||||
|
||||
if K >= 0:
|
||||
# In this case the line intersects the ellipse, so calculate intersection
|
||||
if x2 >= x1:
|
||||
ellipse1_x = ((F*-1) + math.sqrt(K)) / (2 * E)
|
||||
ellipse1_x = ((F * -1) + math.sqrt(K)) / (2 * E)
|
||||
ellipse1_y = ((H * (ellipse1_x - x2)) + y2)
|
||||
else:
|
||||
ellipse1_x = (((F*-1) - math.sqrt(K)) / (2 * E))
|
||||
ellipse1_x = (((F * -1) - math.sqrt(K)) / (2 * E))
|
||||
ellipse1_y = ((H * (ellipse1_x - x2)) + y2)
|
||||
else:
|
||||
# in this case, arc does not intersect ellipse, so just draw arc
|
||||
|
Reference in New Issue
Block a user