Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse(self, e):
c = QtCore.QPointF(*map(self.parseUnit, (e.attrib.get('cx', 0),
e.attrib.get('cy', 0))))
r = self.parseUnit(e.attrib.get('r', 0))
self.addEllipse(c, r, r)
anchor = Typed(QPointF, factory=lambda: QPointF(0.5, 0.0))
sp = QPainterPath()
sp.moveTo(cur)
sp.lineTo(point)
next_angle = sp.angleAtPercent(1)
# Direction of last move
angle = blade_path.angleAtPercent(1)
# If not continuous it needs corrected with an arc
if isnan(angle) or isnan(next_angle):
return
if abs(angle - next_angle) > self.config.cutoff:
r = self.config.offset
a = radians(next_angle)
dx, dy = r*cos(a), -r*sin(a)
po = QPointF(cur.x()+dx, cur.y()+dy)
c = offset_path.currentPosition()
dx, dy = po.x()-cur.x()+c.x()-cur.x(), po.y()-cur.y()+c.y()-cur.y()
c1 = QPointF(cur.x()+dx, cur.y()+dy)
offset_path.quadTo(c1, po)
# This works for small offsets < 0.5 mm
def updatePixmap(self, rect):
""" Update the pixmap for the current transition.
This method sets a radial clipping region on the output pixmap
and draws in the relevant portion of the ending pixamp.
"""
x = rect.x()
y = rect.y()
rx = rect.width()
ry = rect.height()
path = QPainterPath()
path.addEllipse(QPointF(x, y), float(rx), float(ry))
painter = QPainter(self.outPixmap())
painter.setClipPath(path)
painter.drawPixmap(QPoint(0, 0), self.endPixmap())
def set_parent_anchor(self, anchor):
""" Set the parent anchor location on the underlying widget.
"""
self.widget.setParentAnchor(QPointF(*anchor))
#: this is effectively the resolution the software supplies
step_size = self.step_size
#: Time to wait between each step so we don't get
#: way ahead of the cutter and fill up it's buffer
step_time = self.step_time
#: Total length
total_length = float(job.model.length())
#: How far we went already
total_moved = 0
#: Previous point
_p = QtCore.QPointF(0, 0)
self.status = "Job length: {}".format(total_length)
update = 0
#: For each path
for path in model.toSubpathPolygons():
#: And then each point within the path
#: this is a polygon
for i, p in enumerate(path):
#: TODO: If the device does not support streaming
#: the path interpolation should be skipped entirely
#: Make a subpath
Parameters
----------
model: QPainterPath
The path to process
Returns
-------
generator: A list or generator object that yields each command
to invoke on the device and the distance moved. In the format
(distance, cmd, args, kwargs)
"""
config = self.config
# Previous point
_p = QtCore.QPointF(self.origin[0], self.origin[1])
# Do a final translation since Qt's y axis is reversed from svg's
# It should now be a bbox of (x=0, y=0, width, height)
# this creates a copy
model = model * QtGui.QTransform.fromScale(1, -1)
# Determine if interpolation should be used
skip_interpolation = (self.connection.always_spools or config.spooled
or not config.interpolate)
# speed = distance/seconds
# So distance/speed = seconds to wait
step_size = config.step_size
if not skip_interpolation and step_size <= 0:
raise ValueError("Cannot have a step size <= 0!")
try:
paths = []
path = QtGui.QPainterPath()
i = 0
while i < self.elementCount():
e = self.elementAt(i)
if e.type == ElementType.MoveToElement:
if not path.isEmpty():
paths.append(path)
path = QtGui.QPainterPath(QtCore.QPointF(e.x, e.y))
elif e.type == ElementType.LineToElement:
path.lineTo(QtCore.QPointF(e.x, e.y))
elif e.type == ElementType.CurveToElement:
e1, e2 = self.elementAt(i+1), self.elementAt(i+2)
path.cubicTo(QtCore.QPointF(e.x, e.y),
QtCore.QPointF(e1.x, e1.y),
QtCore.QPointF(e2.x, e2.y))
i += 2
else:
raise ValueError("Invalid element type %s" % (e.type,))
i += 1
if not path.isEmpty():
paths.append(path)
return paths
AnchorParent = 0
#: Anchor to mouse
AnchorCursor = 1
class ViewState(Atom):
""" A private class used to manage the state of a popup view.
"""
#: The anchor location on the view. The default anchors
#: the top center of the view to the center of the parent.
anchor = Typed(QPointF, factory=lambda: QPointF(0.5, 0.0))
#: The anchor location on the parent. The default anchors
#: the top center of the view to the center of the parent.
parent_anchor = Typed(QPointF, factory=lambda: QPointF(0.5, 0.5))
#: Anchor to parent or cursor
anchor_mode = Int(0) # AnchorParent
#: The size of the arrow for the view.
arrow_size = Int(0)
#: The edge location of the arrow for the view.
arrow_edge = Int(0) # LeftEdge
#: The position of the arrow for the view.
arrow_position = Float(0.5)
#: The offset of the view wrt to the anchor.
offset = Typed(QPoint, factory=lambda: QPoint(0, 0))