本文整理汇总了Python中PySide.QtGui.QPainterPath.addEllipse方法的典型用法代码示例。如果您正苦于以下问题:Python QPainterPath.addEllipse方法的具体用法?Python QPainterPath.addEllipse怎么用?Python QPainterPath.addEllipse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainterPath
的用法示例。
在下文中一共展示了QPainterPath.addEllipse方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_shape
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def set_shape(self, width, height):
''' Define the bouding rectangle of the JOIN symbol '''
circ = min(width, height)
path = QPainterPath()
path.addEllipse(0, 0, circ, circ)
self.setPath(path)
super(Join, self).set_shape(width, height)
示例2: setupPaint
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def setupPaint(self):
"""Offscreen rather than onscreen redraw (few changes)."""
path = QPainterPath()
if self.data.isInput:
path.addEllipse(
self.pinW / 2, self.pinW / 2, self.bodyW, self.bodyW)
else:
path.addRect(
3 * self.pinW / 2 + 1, self.pinW / 2, self.bodyW, self.bodyW)
path.addPath(self.pinPath)
self.setPath(path)
self.name.setVisible(self.showName)
self.name.setText(self.data.name)
br = self.mapToScene(self.boundingRect())
w = self.boundingRect().width()
h = self.boundingRect().height()
realX = min([i.x() for i in br])
realY = min([i.y() for i in br])
self.name.setPos(self.mapFromScene(
realX, realY + (w if self.rotation() % 180 else h) + 1))
self.value.setText(
str(int(self.data.value)) if self.data.value is not None else 'E')
self.value.setPos(self.mapFromScene(realX + w / 3, realY + h / 3))
self.value.setBrush(QColor('green' if self.data.value else 'red'))
self.update() # Force onscreen redraw after changes.
示例3: animate
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def animate(self, shapes):
self.start_signal.emit()
time.sleep(self.start_delay)
self.running = True
self.ended = False
max_radius = []
original_clips = []
centers = []
animating_radius = []
inc_rate = []
for s in shapes:
# Setting max of width or height as radius, ergo "circular" reveal,
# not "oval" reveal
target = max(s.width, s.height)
max_radius.append(target)
# Starting from the zero reaching the max
animating_radius.append(0)
# Getting the original masks; Used in case of cancelation
original_clips.append(s.clip)
# Center of the shape, considering margin
centers.append(QPoint((s.width / 2) + s.margin_start, (s.height / 2) + s.margin_top))
# Calculating the increase rate using the good ol' formula
inc_rate.append((target / self.fps) * (1000 / self.duration))
while self.running or self.paused:
if self.canceled:
for i, s in enumerate(shapes):
s.clip = original_clips[i]
self.cancel_signal.emit()
return
elif self.ended:
self.end_signal.emit()
return
elif self.paused:
# Handling the pause
self.pause_signal.emit()
while not self.paused:
pass
self.resume_signal.emit()
else:
# Setting FPS from the animator
time.sleep(1 / self.fps)
completed = False
for i, s in enumerate(shapes):
if animating_radius[i] < max_radius[i]:
path = QPainterPath()
path.addEllipse(centers[i], animating_radius[i], animating_radius[i])
s.clip = path
s.update()
QApplication.processEvents()
animating_radius[i] += inc_rate[i]
else:
completed = True
# No need to check on every iteration, duration is same so
# all objects are gonna end at the same time
if completed:
self.end_signal.emit()
self.started = False
self.ended = True
return
示例4: __init__
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def __init__(self, pos, edge):
''' Set the original control point - with color, shape '''
path = QPainterPath()
path.addEllipse(pos.x() - 5, pos.y() - 5, 10, 10)
super(Controlpoint, self).__init__(path, parent=edge)
self.setPen(QColor(50, 100, 120, 200))
self.setBrush(QColor(200, 200, 210, 120))
self.setFlags(QGraphicsItem.ItemIsSelectable |
QGraphicsItem.ItemIsMovable)
self.edge = edge
self.hide()
示例5: fillEllipse
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def fillEllipse(
self,
painter,
x,
y,
size,
brush,
):
path = QPainterPath()
path.addEllipse(x, y, size, size)
painter.fillPath(path, brush)
示例6: __init__
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def __init__(self, parent):
super(QNEOutputPort, self).__init__(parent)
self.parent = parent
self.setPen(self.parent.pen())
self.setBrush(self.parent.brush())
radius_ = parent.radius_
path = QPainterPath()
path.addEllipse(0, -radius_, 2*radius_, 2*radius_)
self.setPath(path)
示例7: setCanConnect
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def setCanConnect(self, hasInput, hasOutput):
self.hasInput_ = hasInput
self.hasOutput_ = hasOutput
if self.hasOutput_:
self.outputPort.setVisible(True)
else:
self.outputPort.setVisible(False)
path = QPainterPath()
if self.hasInput_:
path.addEllipse(0, -self.radius_, 2*self.radius_, 2*self.radius_)
else:
pass
self.setPath(path)
示例8: __init__
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def __init__(self, parent):
super(QNEPort, self).__init__(parent)
self.label = QGraphicsTextItem(self)
self.radius_ = 4
self.margin = 3
path = QPainterPath()
path.addEllipse(-self.radius_, -self.radius_, 2*self.radius_, 2*self.radius_);
self.setPath(path)
self.setPen(QPen(Qt.darkRed))
self.setBrush(Qt.red)
self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges)
self.m_portFlags = 0
self.isOutput_ = False
self.m_block = None
self.m_connections = []
示例9: updateLeader
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def updateLeader(self):
"""
TOWRITE
"""
arrowStyle = Closed # int # TODO: Make this customizable
arrowStyleAngle = 15.0 # qreal # TODO: Make this customizable
arrowStyleLength = 1.0 # qreal # TODO: Make this customizable
self.lineStyleAngle = 45.0 # qreal # TODO: Make this customizable
self.lineStyleLength = 1.0 # qreal # TODO: Make this customizable
lyne = self.line() # QLineF
angle = lyne.angle() # qreal
ap0 = lyne.p1() # QPointF
lp0 = lyne.p2() # QPointF
# Arrow
lynePerp = QLineF(lyne.pointAt(arrowStyleLength / lyne.length()), lp0)
lynePerp.setAngle(angle + 90)
lyne1 = QLineF(ap0, lp0)
lyne2 = QLineF(ap0, lp0)
lyne1.setAngle(angle + arrowStyleAngle)
lyne2.setAngle(angle - arrowStyleAngle)
# ap1 = QPointF()
# ap2 = QPointF()
_, ap1 = lynePerp.intersect(lyne1)
_, ap2 = lynePerp.intersect(lyne2)
# Math Diagram
# .(ap1) .(lp1)
# /| /|
# / | / |
# / | / |
# / | / |
# / | / |
# / | / |
# / | / |
# / | / |
# /+(aSA) | /+(lSA) |
# (ap0)./__(aSL)__|__________(lp0)./__(lSL)__|
# \ -(aSA) | \ -(lSA) |
# \ | \ |
# \ | \ |
# \ | \ |
# \ | \ |
# \ | \ |
# \ | \ |
# \ | \ |
# \ | \ |
# \| \|
# .(ap2) .(lp2)
if arrowStyle == Open:
arrowStylePath = QPainterPath()
arrowStylePath.moveTo(ap1)
arrowStylePath.lineTo(ap0)
arrowStylePath.lineTo(ap2)
arrowStylePath.lineTo(ap0)
arrowStylePath.lineTo(ap1)
elif arrowStyle == Closed:
arrowStylePath = QPainterPath()
arrowStylePath.moveTo(ap1)
arrowStylePath.lineTo(ap0)
arrowStylePath.lineTo(ap2)
arrowStylePath.lineTo(ap1)
elif arrowStyle == Dot:
arrowStylePath = QPainterPath()
arrowStylePath.addEllipse(ap0, arrowStyleLength, arrowStyleLength)
elif arrowStyle == Box:
arrowStylePath = QPainterPath()
side = QLineF(ap1, ap2).length() # qreal
ar0 = QRectF(0, 0, side, side)
ar0.moveCenter(ap0)
arrowStylePath.addRect(ar0)
elif arrowStyle == Tick:
pass #TODO/PORT# Is this supposed to be empty?
lineStylePath = QPainterPath()
lineStylePath.moveTo(ap0)
lineStylePath.lineTo(lp0)
示例10: animate
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def animate(self, shapes):
self.start_signal.emit()
time.sleep(self.start_delay)
self.running = True
self.ended = False
target_radius = []
original_clips = []
centers = []
animating_radius = []
rate_of_change = []
for s in shapes:
if self.target.startswith("show"):
# Setting max of width or height as radius, ergo "circular" reveal,
# not "oval" reveal
target = max(s.width, s.height)
# Starting from the zero reaching the max
animating_radius.append(0)
rate_of_change.append((target / self.fps) * (1000 / self.duration))
elif self.target.startswith("hide"):
# You know why...
target = 0
# Starting from the max reaching the 0
animating_radius.append(max(s.width, s.height))
rate_of_change.append(((target - max(s.width, s.height)) / self.fps) * (1000 / self.duration))
else:
raise ValueError("Target should be either 'reveal' or 'hide'")
target_radius.append(target)
# Getting the original masks; Used in case of cancelation
original_clips.append(s.clip)
# Center of the shape, considering margin
centers.append(QPoint((s.width / 2) + s.margin_left, (s.height / 2) + s.margin_top))
# Calculating the increase rate using the good ol' formula
while self.running or self.paused:
if self.canceled and not self.paused:
for i, s in enumerate(shapes):
s.clip = original_clips[i]
self.cancel_signal.emit()
return
elif self.ended:
self.end_signal.emit()
return
elif self.paused:
# Handling the pause
self.pause_signal.emit()
while self.paused:
# If you want the current state, pause the
# animation and then cancel it
print("paused")
if self.canceled:
print("canceled")
self.ended = True
self.started = False
self.cancel_signal.emit()
return
self.resume_signal.emit()
else:
# Setting FPS from the animator
time.sleep(1 / self.fps)
completed = False
for i, s in enumerate(shapes):
if rate_of_change[i] > 0:
if not animating_radius[i] < target_radius[i]:
completed = True
else:
if not animating_radius[i] > target_radius[i]:
completed = True
if not completed:
animating_radius[i] += rate_of_change[i]
path = QPainterPath()
if self.target.endswith("circle"):
path.addEllipse(
QPointF((s.width / 2) + s.margin_left,
(s.height / 2) + s.margin_top),
animating_radius[i] / 2,
animating_radius[i] / 2
)
else:
path.addEllipse(
QPointF((s.width / 2) + s.margin_left,
(s.height / 2) + s.margin_top),
animating_radius[i],
animating_radius[i]
)
s.clip = path
s.update()
QApplication.processEvents()
# No need to check on every iteration, duration is same so
# all objects are gonna end at the same time
if completed:
self.end_signal.emit()
self.started = False
self.ended = True
return
示例11: handleAtPos
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
def handleAtPos(self, pos):
"""Is there an interactive handle where the mouse is?"""
if not self.complete:
path = QPainterPath()
path.addEllipse(self.data['points'][-1], self.radius, self.radius)
return path.contains(pos)
示例12: PlugItem
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import addEllipse [as 别名]
class PlugItem(QGraphicsPathItem):
"""Graphical wrapper around the engine Plug class."""
bodyW = 30
"""The width of the body of plugs."""
pinW = 10
"""The width of the pin part of plugs."""
def __init__(self, plug):
super(PlugItem, self).__init__()
self.data = plug
"""The real info. The class PlugItem is just a graphical container
around it. data is saved / loaded to / from file.
"""
self.showName = False
"""Is the name of the item shown on screen?"""
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
self.setAcceptsHoverEvents(True)
self.setPen(QPen(QBrush(QColor(QColor('black'))), 2))
# This path is needed at each mouse over event, to check if
# the mouse is over a pin. We save it as an instance field,
# rather than recreate it at each event.
self.pinPath = QPainterPath()
if self.data.isInput:
self.pinPath.addEllipse(
self.bodyW + self.pinW / 2, self.bodyW / 2,
self.pinW, self.pinW)
else:
self.pinPath.addEllipse(
self.pinW / 2, self.bodyW / 2, self.pinW, self.pinW)
f = QFont('Times', 12, 75)
# Name and value text labels.
self.name = QGraphicsSimpleTextItem(self)
# that won't rotate when the PlugItem is rotated by the user.
self.name.setFlag(QGraphicsItem.ItemIgnoresTransformations)
self.name.setText(self.data.name)
self.name.setFont(f)
self.value = QGraphicsSimpleTextItem(self)
self.value.setFlag(QGraphicsItem.ItemIgnoresTransformations)
# Or else value would get the clicks, instead of the PlugItem.
self.value.setFlag(QGraphicsItem.ItemStacksBehindParent)
self.value.setFont(f)
self.setupPaint()
def handleAtPos(self, pos):
"""Is there an interactive handle where the mouse is?
Also return the Plug under this handle.
"""
return self.data if self.pinPath.contains(pos) else None
def itemChange(self, change, value):
"""Warning view it will soon have to correct pos."""
if change == QGraphicsItem.ItemPositionHasChanged:
# Restart till we stop moving.
self.scene().views()[0].timer.start()
return QGraphicsItem.itemChange(self, change, value)
def setAndUpdate(self):
"""Change the undelying plug's value, and force updates items."""
self.data.set(not self.data.value)
for i in self.scene().items():
if isinstance(i, PlugItem) or isinstance(i, WireItem):
i.setupPaint()
def setNameVisibility(self, isVisible):
"""Shows/Hide the item name in the graphical view."""
self.showName = isVisible
self.setupPaint()
def setupPaint(self):
"""Offscreen rather than onscreen redraw (few changes)."""
path = QPainterPath()
if self.data.isInput:
path.addEllipse(
self.pinW / 2, self.pinW / 2, self.bodyW, self.bodyW)
else:
path.addRect(
3 * self.pinW / 2 + 1, self.pinW / 2, self.bodyW, self.bodyW)
path.addPath(self.pinPath)
self.setPath(path)
self.name.setVisible(self.showName)
self.name.setText(self.data.name)
br = self.mapToScene(self.boundingRect())
w = self.boundingRect().width()
h = self.boundingRect().height()
realX = min([i.x() for i in br])
realY = min([i.y() for i in br])
self.name.setPos(self.mapFromScene(
realX, realY + (w if self.rotation() % 180 else h) + 1))
self.value.setText(
str(int(self.data.value)) if self.data.value is not None else 'E')
self.value.setPos(self.mapFromScene(realX + w / 3, realY + h / 3))
self.value.setBrush(QColor('green' if self.data.value else 'red'))
self.update() # Force onscreen redraw after changes.