Skip to content

Commit

Permalink
Pen, DrawLines and others take integers, fix a TypeError on Python 3.10+
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Nov 17, 2021
1 parent 5a328ff commit faade5b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions printrun/gui/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def drawgrid(self, dc, gc):
xscale = float(self.width - 1) / (self.xbars - 1)
for x in range(self.xbars + 1):
x = x * xscale
dc.DrawLine(x, 0, x, self.height)
dc.DrawLine(int(x), 0, int(x), self.height)

# draw horizontal bars
spacing = self._calculate_spacing() # spacing between bars, in degrees
Expand All @@ -159,7 +159,7 @@ def drawgrid(self, dc, gc):
# y_pos = y*(float(self.height)/self.ybars)
degrees = y * spacing
y_pos = self._y_pos(degrees)
dc.DrawLine(0, y_pos, self.width, y_pos)
dc.DrawLine(0, int(y_pos), self.width, int(y_pos))
label = str(y * spacing)
label_y = y_pos - font.GetPointSize() / 2
self.layoutText(label, 1, label_y, gc)
Expand Down Expand Up @@ -219,7 +219,7 @@ def drawtemperature(self, dc, gc, temperature_list,
for temperature in temperature_list:
y_pos = self._y_pos(temperature)
if x_pos > 0: # One need 2 points to draw a line.
dc.DrawLine(lastxvalue, lastyvalue, x_pos, y_pos)
dc.DrawLine(int(lastxvalue), int(lastyvalue), int(x_pos), int(y_pos))

lastxvalue = x_pos
x_pos += x_add
Expand Down Expand Up @@ -291,7 +291,7 @@ def layoutRectY(self, rc):

def layoutText(self, text, x, y, gc):
ext = gc.GetTextExtent(text)
rc = self.layoutRect(wx.Rect(x, y, *ext))
rc = self.layoutRect(wx.Rect(int(x), int(y), int(ext[0]), int(ext[1])))
# print('layoutText', text, rc.TopLeft)
return rc

Expand Down
2 changes: 1 addition & 1 deletion printrun/gui/xybuttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def mouseOverKeypad(self, mpos):
return None

def drawPartialPie(self, gc, center, r1, r2, angle1, angle2):
p1 = wx.Point(center.x + r1 * math.cos(angle1), center.y + r1 * math.sin(angle1))
p1 = wx.Point(int(center.x + r1 * math.cos(angle1)), int(center.y + r1 * math.sin(angle1)))

path = gc.CreatePath()
path.MoveToPoint(p1.x, p1.y)
Expand Down
24 changes: 12 additions & 12 deletions printrun/gviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def __init__(self, parent, size = (200, 200), build_dimensions = [200, 200, 100,
self.filament_width = extrusion_width # set it to 0 to disable scaling lines with zoom
self.update_basescale()
self.scale = self.basescale
penwidth = max(1.0, self.filament_width * ((self.scale[0] + self.scale[1]) / 2.0))
penwidth = max(1, int(self.filament_width * ((self.scale[0] + self.scale[1]) / 2.0)))
self.translate = [0.0, 0.0]
self.mainpen = wx.Pen(wx.Colour(0, 0, 0), penwidth)
self.arcpen = wx.Pen(wx.Colour(255, 0, 0), penwidth)
Expand Down Expand Up @@ -292,17 +292,17 @@ def zoom(self, x, y, factor):

self.translate = [x - (x - self.translate[0]) * factor,
y - (y - self.translate[1]) * factor]
penwidth = max(1.0, self.filament_width * ((self.scale[0] + self.scale[1]) / 2.0))
penwidth = max(1, int(self.filament_width * ((self.scale[0] + self.scale[1]) / 2.0)))
for pen in self.penslist:
pen.SetWidth(penwidth)
self.dirty = True
wx.CallAfter(self.Refresh)

def _line_scaler(self, x):
return (self.scale[0] * x[0],
self.scale[1] * x[1],
self.scale[0] * x[2],
self.scale[1] * x[3],)
return (int(self.scale[0] * x[0]),
int(self.scale[1] * x[1]),
int(self.scale[0] * x[2]),
int(self.scale[1] * x[3]),)

def _arc_scaler(self, x):
return (self.scale[0] * x[0],
Expand All @@ -326,7 +326,7 @@ def _drawarcs(self, dc, arcs, pens):
def repaint_everything(self):
width = self.scale[0] * self.build_dimensions[0]
height = self.scale[1] * self.build_dimensions[1]
self.blitmap = wx.Bitmap(width + 1, height + 1, -1)
self.blitmap = wx.Bitmap(int(width) + 1, int(height) + 1, -1)
dc = wx.MemoryDC()
dc.SelectObject(self.blitmap)
dc.SetBackground(wx.Brush((250, 250, 200)))
Expand All @@ -336,19 +336,19 @@ def repaint_everything(self):
if grid_unit > 0:
for x in range(int(self.build_dimensions[0] / grid_unit) + 1):
draw_x = self.scale[0] * x * grid_unit
dc.DrawLine(draw_x, 0, draw_x, height)
dc.DrawLine(int(draw_x), 0, int(draw_x), int(height))
for y in range(int(self.build_dimensions[1] / grid_unit) + 1):
draw_y = self.scale[1] * (self.build_dimensions[1] - y * grid_unit)
dc.DrawLine(0, draw_y, width, draw_y)
dc.DrawLine(0, int(draw_y), int(width), int(draw_y))
dc.SetPen(wx.Pen(wx.Colour(0, 0, 0)))

if not self.showall:
# Draw layer gauge
dc.SetBrush(wx.Brush((43, 144, 255)))
dc.DrawRectangle(width - 15, 0, 15, height)
dc.DrawRectangle(int(width) - 15, 0, 15, int(height))
dc.SetBrush(wx.Brush((0, 255, 0)))
if self.layers:
dc.DrawRectangle(width - 14, (1.0 - (1.0 * (self.layerindex + 1)) / len(self.layers)) * height, 13, height - 1)
dc.DrawRectangle(int(width) - 14, int((1.0 - (1.0 * (self.layerindex + 1)) / len(self.layers)) * height), 13, int(height) - 1)

if self.showall:
for i in range(len(self.layersz)):
Expand Down Expand Up @@ -410,7 +410,7 @@ def paint(self, event):
dc = wx.PaintDC(self)
dc.SetBackground(wx.Brush(self.bgcolor))
dc.Clear()
dc.DrawBitmap(self.blitmap, self.translate[0], self.translate[1])
dc.DrawBitmap(self.blitmap, int(self.translate[0]), int(self.translate[1]))
if self.paint_overlay:
self.paint_overlay(dc)

Expand Down

0 comments on commit faade5b

Please sign in to comment.