本文整理汇总了Python中PyQt4.QtGui.QGraphicsEllipseItem.setPen方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsEllipseItem.setPen方法的具体用法?Python QGraphicsEllipseItem.setPen怎么用?Python QGraphicsEllipseItem.setPen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsEllipseItem
的用法示例。
在下文中一共展示了QGraphicsEllipseItem.setPen方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: iLabel
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
def iLabel(node, *args, **kargs):
#code for making specialized faces for intermediates mostly cribbed from the ete2 website example (though not interactive):
# http://pythonhosted.org/ete2/tutorial/tutorial_drawing.html#creating-your-custom-interactive-item-faces
my_label = node.name
ellipse = QGraphicsEllipseItem(0,0,fontSize*2,fontSize*2) #I think the first two are coords of center; second pair is major/minor axis
ellipse.setPen(QPen(QColor( 'black' )))
ellipse.setBrush(QBrush(QColor( 'white' )))
text = QGraphicsSimpleTextItem(my_label)
text.setParentItem(ellipse)
text.setBrush(QBrush(QColor("black")))
font = QFont("Arial",fontSize*.9,weight=80)
font.setLetterSpacing(1, 2) #add 2 pixels between letters for legibility
text.setFont(font)
#Center text according to masterItem size
tw = text.boundingRect().width()
th = text.boundingRect().height()
center = ellipse.boundingRect().center()
text.setPos(center.x()+1-tw/2, center.y()-th/2) #since the last letter has an extra 2 pixels after it from the spacing command, adjust center to compensate
return ellipse
示例2: _finish_select_area
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
def _finish_select_area(self):
self.unregister_handler(self.home_map_scene,
QEvent.GraphicsSceneMouseRelease)
self.unregister_handler(self.home_map_scene,
QEvent.KeyRelease)
item = None
for id,it in self.current_op_stat['items'].items() :
print "%d,%s" % (id,HMItem.repr(it))
p = it.polygon().first()
item = None
self.current_op = ''
self.current_op_stat = None
el_it = QGraphicsEllipseItem(p.x()-2,p.y()-2,4,4)
HMItem.module(el_it,self.__class__.__name__)
HMItem.type(el_it,HMItem.ARTIFACT)
HMItem.level(el_it, -1)
el_it.setPen(QPen(Qt.blue,
1,
Qt.SolidLine,
Qt.RoundCap,
Qt.RoundJoin))
el_it.setBrush(QBrush(Qt.blue))
el_it.setZValue(1)
self.home_map_scene.addItem(el_it)
示例3: constructPieChart
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
def constructPieChart(self, distrib, numbs):
pie = QGraphicsItemGroup()
totArc = 0
for j, num, dist in reversed(zip(range(len(numbs)), numbs, distrib)):
arc = QGraphicsEllipseItem(-self.pieWidth/2, -self.pieWidth/2, self.pieWidth, self.pieHeight)
arc.setPen(QPen(QColor(0, 0, 0), 1, Qt.SolidLine))
arc.setBrush(QBrush(self.discPalette[j]))
arc.setToolTip("%s: %.3f" % (self.attributes[self.selectedAttributes[j]][0], num) + (" (%2.1f%%)" % (dist/self.barHeight*100) if self.normalize else ""))
arc.setStartAngle(totArc)
arc.setSpanAngle(dist * 2880 / self.barHeight)
pie.addToGroup(arc)
totArc += dist * 2880 / self.barHeight
return pie
示例4: SingleJoystickView
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
class SingleJoystickView(QGraphicsView):
def __init__(self, *args):
QGraphicsView.__init__(self, *args)
self.outerD = 125
self.innerD = 25
self.innerRange = 50
self.inputRange = 256
self.thresh = 3
self.worker = JoystickThread()
self.worker.valueUpdated.connect(self.moveJoystick)
self.worker.start()
self.move(30, 100)
self.setContentsMargins(0, 0, 0, 0)
self.setMaximumHeight(140)
self.setMaximumWidth(140)
self.adjustSize()
self.scene = QGraphicsScene(self)
self.outerCircle = QGraphicsEllipseItem(0, 0, self.outerD, self.outerD)
self.outerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.outerCircle.setBrush(Qt.gray)
self.innerCircle = QGraphicsEllipseItem(self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2, self.innerD, self.innerD)
self.innerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle.setBrush(Qt.lightGray)
self.scene.addItem(self.outerCircle)
self.scene.addItem(self.innerCircle)
self.setScene(self.scene)
self.setStyleSheet('background-color:transparent;color:red')
self.currentX = 0
self.currentY = 0
def moveJoystick(self, x, y):
x2 = x * self.innerRange / self.inputRange - self.innerRange / 2
y2 = y * self.innerRange / self.inputRange - self.innerRange / 2
if -self.thresh <= x2 <= self.thresh:
x2 = 0
if -self.thresh <= y2 <= self.thresh:
y2 = 0
self.tl = QTimeLine(10)
self.tl.setFrameRange(0, 10)
self.a = QGraphicsItemAnimation()
self.a.setItem(self.innerCircle)
self.a.setTimeLine(self.tl)
self.a.setPosAt(0, QPointF(self.currentX, self.currentY))
self.a.setTranslationAt(1, x2, y2)
self.currentX = x2
self.currentY = y2
self.tl.start()
print 'x:%d y:%d' % (x2, y2)
示例5: _update_add_area
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
def _update_add_area(self,event):
p = event.scenePos()
self.current_op_stat['points'].append(p)
el_it = QGraphicsEllipseItem(p.x()-2,p.y()-2,4,4)
HMItem.module(el_it,self.__class__.__name__)
HMItem.type(el_it,HMItem.OUTLINE_POINT)
HMItem.level(el_it, -1)
el_it.setPen(QPen(Qt.black,
1,
Qt.SolidLine,
Qt.RoundCap,
Qt.RoundJoin))
el_it.setBrush(QBrush(Qt.Dense4Pattern))
el_it.setZValue(1)
self.home_map_scene.addItem(el_it)
示例6: Joystick
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
class Joystick(Button):
def __init__(self, outer, inner, filename=None, width=None, height=None, x=0, y=0, pixmap=None, group=None, pos=None, size=None, padding=None):
Button.__init__(self, filename, width, height, x, y, pixmap, group, pos, size, padding)
self.outer = outer
self.inner = inner
self.innerRange = 48
self.inputRange = 256
self.thresh = 5
self.outerCircle = QGraphicsEllipseItem(self.getX(), self.getY(), self.outer, self.outer)
self.outerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.outerCircle.setBrush(Qt.gray)
self.innerCircle = QGraphicsEllipseItem(self.getX() + self.outer / 2 - self.inner / 2, self.getY() + self.outer / 2 - self.inner / 2, self.inner, self.inner)
self.innerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle.setBrush(Qt.lightGray)
self.currentX = 0
self.currentY = 0
self.items = [self.outerCircle, self.innerCircle]
def getItems(self):
return self.items
def setScene(self, scene):
self.scene = scene
for item in self.items :
self.scene.addItem(item)
def update(self,x,y,z):
# y = y - sqrt(x + y) if x > 0 else y
# x = x - sqrt(x + y) if y > 0 else x
x2 = x * self.innerRange / self.inputRange - self.innerRange / 2
y2 = y * self.innerRange / self.inputRange - self.innerRange / 2
x2 = x2 - sqrt(abs(y2)) if x2 >= 0 else x2 + sqrt(abs(y2))
y2 = y2 - sqrt(abs(x2)) if y2 >= 0 else y2 + sqrt(abs(x2))
if self.inputRange / 2 - self.thresh <= x <= self.inputRange / 2 + self.thresh:
x2 = 0
if self.inputRange / 2 - self.thresh <= y <= self.inputRange / 2 + self.thresh:
y2 = 0
self.tl = QTimeLine(10)
self.tl.setFrameRange(0, 10)
self.a = QGraphicsItemAnimation()
self.a.setItem(self.innerCircle)
self.a.setTimeLine(self.tl)
self.a.setPosAt(0, QPointF(self.currentX, self.currentY))
self.a.setTranslationAt(1, x2, y2)
if z:
self.innerCircle.setPen(QPen(QColor(Qt.white), 1, Qt.SolidLine))
self.innerCircle.setBrush(QColor(200, 225, 3))
else:
self.innerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle.setBrush(Qt.lightGray)
self.currentX = x2
self.currentY = y2
self.tl.start()
示例7: CircleCurve
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
class CircleCurve(OWCurve):
"""
Displays a circle on the plot
:param pen: The pen used to draw the outline of the circle
:type pen: QPen
:param brush: The brush used to paint the inside of the circle
:type brush: QBrush
:param xCenter: The x coordinate of the circle's center
:type xCenter: float
:param yCenter: The y coordinate of the circle's center
:type yCenter: float
:param radius: The circle's radius
:type radius: float
"""
def __init__(self, pen=QPen(Qt.black), brush=QBrush(Qt.NoBrush), xCenter=0.0, yCenter=0.0, radius=1.0):
OWCurve.__init__(self)
self._item = QGraphicsEllipseItem(self)
self.center = xCenter, yCenter
self.radius = radius
self._rect = QRectF(xCenter - radius, yCenter - radius, 2 * radius, 2 * radius)
self.set_pen(pen)
self.set_brush(brush)
def update_properties(self):
self._item.setRect(self.graph_transform().mapRect(self.data_rect()))
self._item.setPen(self.pen())
self._item.setBrush(self.brush())
def data_rect(self):
x, y = self.center
r = self.radius
return QRectF(x - r, y - r, 2 * r, 2 * r)
示例8: item
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
def item(self):
if self.item_ is None:
num_pts = len(self.pts_)
if num_pts == 1:
# draw a point
item = QGraphicsEllipseItem(self.pts_[0][0]-self.radius_,
self.pts_[0][1]-self.radius_,
2*self.radius_,
2*self.radius_)
item.setBrush(self.qcolor)
elif num_pts == 2:
item = QGraphicsLineItem(self.pts_[0][0], self.pts_[0][1],
self.pts_[1][0], self.pts_[1][1])
else:
poly = QPolygonF()
for p in self.pts_:
poly.append(QPointF(p[0],p[1]))
item = QGraphicsPolygonItem(poly)
item.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
item.setPen(self.qcolor)
item.setEnabled(True)
item.setActive(True)
self.item_ = item
return self.item_
示例9: __init__
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
def __init__(self, world):
QGraphicsPolygonItem.__init__(self)
#############################
### Build graph
#############################
graph = pydot.Dot()
graph.set_node_defaults(color = 'red', fontcolor = 'red', label = '\<orphan\>')
graph.set('overlap', 'prism')
# build adjacency graph from world
for area in world.areas:
# create node for each room
node = pydot.Node(area.id)
node.set( 'label', area.name )
if area == world.player.currentArea:
node.set( 'color', 'blue' )
node.set( 'fontcolor', 'blue' )
else:
node.set( 'color', 'black' )
node.set( 'fontcolor', 'black' )
graph.add_node(node)
# link to adjacent rooms
for feature in area.features:
for action in feature.actions:
finalEvent = None
for event in action.events:
if type(event) == events.PlayerMoveEvent:
finalEvent = pydot.Edge( src=area.id, dst=event.properties['destination'] )
if finalEvent is not None:
graph.add_edge( finalEvent )
################################
### Generate SVG from graph
################################
ps = graph.create_svg(prog='neato')
#########################################
### Build graphics items from SVG
#########################################
# build xml tree
ns = {'svg': 'http://www.w3.org/2000/svg'}
doc = ET.fromstring(ps)
# grab the root node properties
rootNode = doc.xpath('/svg:svg/svg:g[1]', namespaces=ns)[0]
polygon = rootNode.xpath('./svg:polygon', namespaces=ns)[0]
pointStr = polygon.xpath('./@points', namespaces=ns)[0]
penColor = QString(polygon.xpath('./@stroke', namespaces=ns)[0])
fillColor = QString(polygon.xpath('./@fill', namespaces=ns)[0])
# parse root polygon path
path = QPolygonF()
for pair in pointStr.split(' '):
dims = pair.split(',')
point = QPointF( float(dims[0]), float(dims[1]) )
path.append(point)
self.setPolygon(path)
# fill in root node colors
if QColor.isValidColor(penColor):
self.setPen( QColor(penColor) )
if QColor.isValidColor(fillColor):
self.setBrush( QColor(fillColor) )
# build each graph node
for xmlNode in rootNode.xpath('./svg:g', namespaces=ns):
group = QGraphicsRectItem(self)
group.setPen( Qt.transparent )
group.setBrush( Qt.transparent )
if xmlNode.attrib['class'] == 'node':
# find the area object
name = xmlNode.xpath('./svg:title', namespaces=ns)[0].text
group.setData( 0, QString(world.areas[world.areaLookup[name]].id) )
# get the ellipse info
ellipseNode = xmlNode.xpath('./svg:ellipse', namespaces=ns)[0]
elProps = { k: float(ellipseNode.attrib[k]) for k in ['cx', 'cy', 'rx', 'ry']}
rect = QRectF( elProps['cx']-elProps['rx'], elProps['cy']-elProps['ry'], 2*elProps['rx'], 2*elProps['ry'])
penColor = QString(ellipseNode.attrib['stroke'])
ellipseItem = QGraphicsEllipseItem(rect, group)
if QColor.isValidColor(penColor):
ellipseItem.setPen( QColor(penColor) )
# get the text info
textNode = xmlNode.xpath('./svg:text', namespaces=ns)[0]
text = textNode.text
textItem = QGraphicsTextItem(text, group)
#.........这里部分代码省略.........
示例10: AxisScene
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
class AxisScene(QGraphicsScene):
def __init__(self, parent = None):
super(AxisScene, self).__init__(parent)
self.guidePen = QPen(QColor("blue"),1)
self.dot = QGraphicsEllipseItem(-10, -10, 20, 20)
self.dot.setPos(QPointF(0,0))
self.dot.setPen(QPen(QColor("red"), 4))
self.dot.setBrush(QColor("black"))
self.lastPos = {}
self.lastPos['x'] = 0
self.lastPos['y'] = 0
self.grid = False
self.gridPen = QPen(QColor("blue"), 2)
self.pathItem = QGraphicsPathItem()
self.pathItem.setPen(QPen(QColor("red"), 1, Qt.DotLine))
self.path = None
self.xAxis = "Select Axis..."
self.yAxis = self.xAxis
self.addItem(self.dot)
def setXAxisName(self, x):
self.xAxis = "Axis " + str(x)
self.invalidate()
def setYAxisName(self, y):
self.yAxis = "Axis " + str(y)
self.invalidate()
def pathToggled(self, toggled):
if toggled:
self.path = QPainterPath()
self.path.moveTo(0,0)
self.pathItem.setPath(self.path)
self.addItem(self.pathItem)
else:
if self.path != None:
self.removeItem(self.pathItem)
self.path = None
self.invalidate()
def gridToggled(self, toggled):
self.grid = toggled
self.invalidate()
def updateDotX(self, x):
self.lastPos['x'] = x * (self.sceneRect().width() / 2)
self.update(self.lastPos['x'], self.lastPos['y'])
def updateDotY(self, y):
self.lastPos['y'] = y * (self.sceneRect().height() / 2)
self.update(self.lastPos['x'], self.lastPos['y'])
def update(self, x, y):
if self.path != None:
self.path.lineTo(x, y)
self.pathItem.setPath(self.path)
self.dot.setPos(self.lastPos['x'], self.lastPos['y'])
self.invalidate()
def drawBackground(self, painter, rect):
if self.grid:
painter.setClipRect(rect)
painter.setPen(self.gridPen)
def drawForeground(self, painter, rect):
painter.setClipRect(rect)
painter.setPen(self.gridPen)
r = self.sceneRect()
if self.grid:
painter.drawLine(r.center().x(), r.top(), r.center().x(), r.bottom())
painter.drawLine(r.left(), r.center().y(), r.right(), r.center().y())
painter.setPen(QPen(QColor("red"), 1))
painter.drawText(QRectF(r.left(), r.center().y(), 80, 80), self.xAxis)
painter.drawText(QRectF(r.center().x()+5, r.top(), 80, 80), self.yAxis)
if self.path != None:
painter.setPen(QPen(QColor("red"), 1))
painter.drawLine(QPointF(self.lastPos['x'], r.top()), QPointF(self.lastPos['x'], r.bottom()))
painter.drawLine(QPointF(r.left(), self.lastPos['y']), QPointF(r.right(), self.lastPos['y']))
示例11: TaskGraphicsItem
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
class TaskGraphicsItem (QGraphicsEllipseItem):
def __init__(self, rect=None):
super(TaskGraphicsItem, self).__init__()
if rect is not None:
self.setRect(rect)
self.setPen(QPen(Qt.NoPen))
# Setup the text item
self.textItem = QGraphicsTextItem()
self.textItem.setParentItem(self)
self.textItem.rotate(-90)
self.textItem.setDefaultTextColor(QColor(255, 255, 255))
# The dimensions to reach via a LERP.
self.startPos = QPointF(0, 0)
self.endPos = QPointF(0, 0)
self.startDiameter = 1
self.endDiameter = 1
self.centerMark = QGraphicsEllipseItem()
self.centerMark.setBrush(QBrush(Qt.white))
self.centerMark.setPen(QPen(Qt.NoPen))
self.centerMark.setParentItem(self)
self.pid = -1
# To determine if it is associated with an active process.
self.used = False
def mousePressEvent(self, event):
print "Clicked On Ellipse at: ", self.rect().topLeft()
def set_pid(self, pid):
self.pid = pid
def set_name(self, str_name):
self.textItem.setPlainText(str_name)
def update_name_pos(self):
rect = self.boundingRect()
text_rect = self.textItem.boundingRect()
# Center text (on the x-axis) and offset (on the y-axis) so it doesn't overlap the ellipse item.
x_text = rect.x() + rect.width()/2 - text_rect.height()/2
y_text = rect.y() + 100 + text_rect.width() + rect.height()
self.textItem.setPos(x_text, y_text)
# Time step is in seconds.
def update(self, time_step):
diameter = self.rect().width() + self.lerp_rate(self.startDiameter, self.endDiameter, time_step)
if diameter <= 1:
diameter = 1
pos = self.rect().topLeft()
x = pos.x() + self.lerp_rate(self.startPos.x(), self.endPos.x(), time_step)
y = pos.y() + self.lerp_rate(self.startPos.y(), self.endPos.y(), time_step)
self.setRect(QRectF(x, y, diameter, diameter))
self.update_name_pos()
self.update_center_mark()
def update_center_mark(self):
scale = self.scene().views()[0].currentScale
hwidth = self.rect().width() / 2.0
diam = 2.0 / scale
# Only mark center for large enough items.
if hwidth * 0.2 > diam:
self.centerMark.setVisible(True)
hdiam = diam / 2.0
pos = self.rect().topLeft()
x = pos.x() - hdiam + hwidth
y = pos.y() - hdiam + hwidth
self.centerMark.setRect(QRectF(x, y, diam, diam))
else:
self.centerMark.setVisible(False)
# Return the linear interpolation rate. Reach start to end at a rate of 'growth rate'
@staticmethod
def lerp_rate(start, end, time_step):
return (end - start) * time_step
示例12: DualJoystickView
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
class DualJoystickView(QGraphicsView):
def __init__(self, *args):
QGraphicsView.__init__(self, *args)
self.outerD = 125
self.innerD = 35
self.innerRange = 48
self.inputRange = 256
self.thresh = 3
self.padding = 40
self.worker = QSixAxisThread()
self.worker.valueUpdated.connect(self.moveJoysticks)
self.worker.start()
self.move(2, 100)
self.setContentsMargins(0, 0, 0, 0)
self.setMaximumHeight(180)
self.setMaximumWidth(420)
self.setMinimumHeight(140)
self.setMinimumWidth(300)
self.adjustSize()
self.scene = QGraphicsScene(self)
self.outerCircle1 = QGraphicsEllipseItem(0, 0, self.outerD, self.outerD)
self.outerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.outerCircle1.setBrush(Qt.gray)
self.innerCircle1 = QGraphicsEllipseItem(self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2, self.innerD, self.innerD)
self.innerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle1.setBrush(Qt.lightGray)
self.scene.addItem(self.outerCircle1)
self.scene.addItem(self.innerCircle1)
self.outerCircle2 = QGraphicsEllipseItem(self.outerD + self.padding, 0, self.outerD, self.outerD)
self.outerCircle2.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.outerCircle2.setBrush(Qt.gray)
self.innerCircle2 = QGraphicsEllipseItem(self.outerD + self.padding + self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2, self.innerD, self.innerD)
self.innerCircle2.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle2.setBrush(Qt.lightGray)
self.scene.addItem(self.outerCircle2)
self.scene.addItem(self.innerCircle2)
self.setScene(self.scene)
self.setStyleSheet('background-color:transparent;')
self.currentX = 0
self.currentY = 0
self.currentA = 0
self.currentZ = 0
self.test = QGraphicsItem(self.outerCircle2)
def moveJoysticks(self, x, y, a, z, l3, r3):
x2 = x * self.innerRange / self.inputRange - self.innerRange / 2
y2 = y * self.innerRange / self.inputRange - self.innerRange / 2
a2 = a * self.innerRange / self.inputRange - self.innerRange / 2
z2 = z * self.innerRange / self.inputRange - self.innerRange / 2
if -self.thresh <= x2 <= self.thresh:
x2 = 0
if -self.thresh <= y2 <= self.thresh:
y2 = 0
if -self.thresh <= a2 <= self.thresh:
a2 = 0
if -self.thresh <= z2 <= self.thresh:
z2 = 0
self.tl = QTimeLine(10)
self.tl.setFrameRange(0, 10)
self.a = QGraphicsItemAnimation()
self.a.setItem(self.innerCircle1)
self.a.setTimeLine(self.tl)
self.a.setPosAt(0, QPointF(self.currentX, self.currentY))
self.a.setTranslationAt(1, x2, y2)
if l3:
self.innerCircle1.setPen(QPen(QColor(Qt.white), 1, Qt.SolidLine))
self.innerCircle1.setBrush(QColor(200, 225, 3))
else:
self.innerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle1.setBrush(Qt.lightGray)
if r3:
self.innerCircle2.setPen(QPen(QColor(Qt.white), 1, Qt.SolidLine))
self.innerCircle2.setBrush(QColor(200, 225, 3))
else:
self.innerCircle2.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle2.setBrush(Qt.lightGray)
self.b = QGraphicsItemAnimation()
self.b.setItem(self.innerCircle2)
self.b.setTimeLine(self.tl)
self.b.setPosAt(0, QPointF(self.currentA, self.currentZ))
self.b.setTranslationAt(1, a2, z2)
self.currentX = x2
self.currentY = y2
self.currentA = a2
self.currentZ = z2
self.tl.start()
示例13: SixAxisView
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPen [as 别名]
class SixAxisView(QGraphicsView):
def __init__(self, *args):
QGraphicsView.__init__(self, *args)
self.move(20, 240)
self.outerD = 125
self.innerD = 35
self.innerRange = 48
self.inputRange = 256
self.thresh = 3
self.padding = 40
self.marginTop = 10
self.worker = QSixAxisThread()
self.worker.valueUpdated.connect(self.moveJoysticks)
self.worker.start()
self.setContentsMargins(0, 0, 0, 0)
self.setMaximumHeight(180)
self.setMaximumWidth(420)
self.setMinimumHeight(240)
self.setMinimumWidth(300)
self.adjustSize()
self.scene = QGraphicsScene(self)
self.outerCircle1 = QGraphicsEllipseItem(0, self.marginTop, self.outerD, self.outerD)
self.outerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.outerCircle1.setBrush(Qt.gray)
self.innerCircle1 = QGraphicsEllipseItem(self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2 + self.marginTop, self.innerD, self.innerD)
self.innerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle1.setBrush(Qt.lightGray)
self.scene.addItem(self.outerCircle1)
self.scene.addItem(self.innerCircle1)
self.outerCircle2 = QGraphicsEllipseItem(self.outerD + self.padding, self.marginTop, self.outerD, self.outerD)
self.outerCircle2.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.outerCircle2.setBrush(Qt.gray)
self.innerCircle2 = QGraphicsEllipseItem(self.outerD + self.padding + self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2 + self.marginTop, self.innerD, self.innerD)
self.innerCircle2.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle2.setBrush(Qt.lightGray)
self.scene.addItem(self.outerCircle2)
self.scene.addItem(self.innerCircle2)
self.setScene(self.scene)
self.setStyleSheet('background-color:transparent; border-width: 0px; border: 0px;')
self.currentX = 0
self.currentY = 0
self.currentA = 0
self.currentZ = 0
self.psBtn = QPixmap(os.getcwd() + '/../icons/bt_PS.png')
self.psBtn = self.psBtn.scaled(50, 50, Qt.KeepAspectRatio)
self.psItem = QGraphicsPixmapItem(self.psBtn)
self.psItem.setOffset(QPointF(self.outerD - 4, 0))
self.effect = QGraphicsDropShadowEffect()
self.effect.setOffset(0, 0)
self.effect.setBlurRadius(20)
self.effect.setColor(Qt.green)
self.psItem.setGraphicsEffect(self.effect)
self.scene.addItem(self.psItem)
self.tl2 = QTimeLine(10000)
self.tl2.setFrameRange(0, 10000)
self.c = QGraphicsItemAnimation()
self.c.setItem(self.psItem)
self.c.setTimeLine(self.tl2)
self.tl2.connect(self.tl2, SIGNAL('frameChanged(int)'), self.updateEffect)
self.effectd = 3
self.tl2.start()
def updateEffect(self):
if self.effect.blurRadius() > 50:
self.effectd = -3
elif self.effect.blurRadius() < 5:
self.effectd = 3
self.effect.setBlurRadius(self.effect.blurRadius() + self.effectd)
def update(self, *args, **kwargs):
return QGraphicsView.update(self, *args, **kwargs)
def moveJoysticks(self, x, y, a, z, l3, r3):
x2 = x * self.innerRange / self.inputRange - self.innerRange / 2
y2 = y * self.innerRange / self.inputRange - self.innerRange / 2
a2 = a * self.innerRange / self.inputRange - self.innerRange / 2
z2 = z * self.innerRange / self.inputRange - self.innerRange / 2
if -self.thresh <= x2 <= self.thresh:
x2 = 0
if -self.thresh <= y2 <= self.thresh:
y2 = 0
if -self.thresh <= a2 <= self.thresh:
a2 = 0
if -self.thresh <= z2 <= self.thresh:
z2 = 0
self.tl = QTimeLine(10)
self.tl.setFrameRange(0, 10)
self.a = QGraphicsItemAnimation()
self.a.setItem(self.innerCircle1)
self.a.setTimeLine(self.tl)
self.a.setPosAt(0, QPointF(self.currentX, self.currentY))
self.a.setTranslationAt(1, x2, y2)
if l3:
self.innerCircle1.setPen(QPen(QColor(Qt.white), 1, Qt.SolidLine))
self.innerCircle1.setBrush(QColor(200, 225, 3))
else:
self.innerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
self.innerCircle1.setBrush(Qt.lightGray)
if r3:
#.........这里部分代码省略.........