本文整理汇总了Python中PyQt4.QtCore.QTimeLine.start方法的典型用法代码示例。如果您正苦于以下问题:Python QTimeLine.start方法的具体用法?Python QTimeLine.start怎么用?Python QTimeLine.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QTimeLine
的用法示例。
在下文中一共展示了QTimeLine.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FaderWidget
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class FaderWidget(QWidget):
def __init__(self, old_widget, new_widget):
QWidget.__init__(self, new_widget)
self.old_pixmap = QPixmap(new_widget.size())
old_widget.render(self.old_pixmap)
self.pixmap_opacity = 1.0
self.timeline = QTimeLine()
self.timeline.valueChanged.connect(self.animate)
self.timeline.finished.connect(self.close)
self.timeline.setDuration(500)
self.timeline.start()
self.resize(new_widget.size())
self.show()
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
painter.setOpacity(self.pixmap_opacity)
painter.drawPixmap(0, 0, self.old_pixmap)
painter.end()
def animate(self, value):
self.pixmap_opacity = 1.0 - value
self.repaint()
示例2: Meterbar
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class Meterbar(Button):
def __init__(self, max=255, 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.max = max
self.outer = QGraphicsRectItem(x,y,width,max + 2)
self.outer.setPen(QPen(QColor(Qt.black), 1, Qt.SolidLine))
self.outer.setBrush(Qt.green)
# self.outer.hide()
self.inner = QGraphicsRectItem(x + 1,y + 1,width - 2,max)
self.inner.setPen(QPen(QColor(Qt.green), 1, Qt.SolidLine))
self.inner.setBrush(Qt.blue)
self.items = [self.outer, self.inner]
self.current = 255
self.effect = QGraphicsDropShadowEffect()
self.effect.setOffset(0, 0)
self.effect.setBlurRadius(0)
self.effect.setColor(Qt.green)
self.item = self.outer
self.addEffect('shadow', self.effect, True)
self.addAnimation('glow', Glow(15, 300, self, maxRadius=80, minRadius=5))
# self.test(10)
def test(self, x):
self.tl = QTimeLine(10000)
self.tl.setFrameRange(0, 10000)
self.a = QGraphicsItemAnimation()
self.a.setItem(self.inner)
self.a.setTimeLine(self.tl)
# self.a.setPosAt(0, QPointF(self.getX(), self.current))
# self.a.setTranslationAt(1, self.getX(), self.getY() + self.max - x + 1)
self.a.setScaleAt(0, 1, 1)
self.a.setScaleAt(1, 1, 0.1)
self.current = x
self.tl.start()
def update(self, x):
x2 = 1 - (float(x) * 1.0 / float(self.max))
# print x
# return
self.tl = QTimeLine(10)
self.tl.setFrameRange(0, 10)
self.a = QGraphicsItemAnimation()
self.a.setItem(self.inner)
self.a.setTimeLine(self.tl)
# self.a.setPosAt(0, QPointF(self.getX(), self.current))
# self.a.setTranslationAt(1, self.getX(), self.getY() + self.max - x + 1)
self.a.setScaleAt(0, 1, self.current)
self.a.setScaleAt(1, 1, x2)
self.current = x
self.tl.start()
if x > 3 :
self.play('glow')
def setScene(self, scene):
self.scene = scene
for item in self.items :
self.scene.addItem(item)
示例3: FaceButtonsView
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class FaceButtonsView(QGraphicsView):
def __init__(self, *args):
QGraphicsView.__init__(self, *args)
self.move(170, 90)
self.btnSize = 40
self.padding = 5
self.setMaximumHeight(self.btnSize * 4)
self.setMaximumWidth(self.btnSize * 4)
self.setMinimumHeight(self.btnSize * 4)
self.setMinimumWidth(self.btnSize * 4)
self.adjustSize()
self.setStyleSheet('background-color:transparent; border-width: 0px; border: 0px;')
self.scene = QGraphicsScene(self)
self.psButtons = QPixmap(os.getcwd() + '/../icons/PS3_Buttons.png')
self.triangle = self.psButtons.copy(0, 0, 220, 225)
self.triangle = self.triangle.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio)
self.square = self.psButtons.copy(220, 0, 220, 225)
self.square = self.square.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio)
self.circle = self.psButtons.copy(440, 0, 220, 225)
self.circle = self.circle.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio)
self.cross = self.psButtons.copy(660, 0, 220, 225)
self.cross = self.cross.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio)
self.triangleItem = QGraphicsPixmapItem(self.triangle)
self.triangleItem.setOffset(QPointF(self.btnSize + self.padding, 0))
self.scene.addItem(self.triangleItem)
self.squareItem = QGraphicsPixmapItem(self.square)
self.squareItem.setOffset(QPointF(0, self.btnSize + self.padding))
self.scene.addItem(self.squareItem)
self.circleItem = QGraphicsPixmapItem(self.circle)
self.circleItem.setOffset(QPointF(self.btnSize * 2 + self.padding * 2, self.btnSize + self.padding))
self.scene.addItem(self.circleItem)
self.crossItem = QGraphicsPixmapItem(self.cross)
self.crossItem.setOffset(QPointF(self.btnSize + self.padding, self.btnSize * 2 + self.padding * 2))
self.scene.addItem(self.crossItem)
self.effect = QGraphicsDropShadowEffect()
self.effect.setOffset(0, 0)
self.effect.setBlurRadius(20)
self.effect.setColor(Qt.green)
self.triangleItem.setGraphicsEffect(self.effect)
self.setScene(self.scene)
self.tl2 = QTimeLine(10000)
self.tl2.setFrameRange(0, 10000)
self.t = QGraphicsItemAnimation()
self.t.setItem(self.triangleItem)
self.t.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)
示例4: DpadView
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class DpadView(QGraphicsView):
def __init__(self, *args):
QGraphicsView.__init__(self, *args)
self.move(2, 90)
self.btnSize = 75
self.padding = -35
self.setMaximumHeight(self.btnSize * 2 + 20)
self.setMaximumWidth(self.btnSize * 2 + 20)
self.setMinimumHeight(self.btnSize * 2 + 20)
self.setMinimumWidth(self.btnSize * 2 + 20)
self.adjustSize()
self.setStyleSheet('background-color:transparent; border-width: 0px; border: 0px;')
self.scene = QGraphicsScene(self)
self.left = QPixmap(os.getcwd() + '/../icons/left.png')
self.left = self.left.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio)
self.right = QPixmap(os.getcwd() + '/../icons/right.png')
self.right = self.right.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio)
self.up = QPixmap(os.getcwd() + '/../icons/up.png')
self.up = self.up.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio)
self.down = QPixmap(os.getcwd() + '/../icons/down.png')
self.down = self.down.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio)
self.leftItem = QGraphicsPixmapItem(self.left)
self.leftItem.setOffset(QPointF(0, self.btnSize + self.padding))
self.scene.addItem(self.leftItem)
self.rightItem = QGraphicsPixmapItem(self.right)
self.rightItem.setOffset(QPointF(self.btnSize * 2 + self.padding * 2, self.btnSize + self.padding))
self.scene.addItem(self.rightItem)
self.upItem = QGraphicsPixmapItem(self.up)
self.upItem.setOffset(QPointF(self.btnSize + self.padding, 0))
self.scene.addItem(self.upItem)
self.downItem = QGraphicsPixmapItem(self.down)
self.downItem.setOffset(QPointF(self.btnSize + self.padding, self.btnSize * 2 + self.padding * 2))
self.scene.addItem(self.downItem)
self.effect = QGraphicsDropShadowEffect()
self.effect.setOffset(0, 0)
self.effect.setBlurRadius(20)
self.effect.setColor(Qt.green)
self.downItem.setGraphicsEffect(self.effect)
self.setScene(self.scene)
self.tl2 = QTimeLine(10000)
self.tl2.setFrameRange(0, 10000)
self.t = QGraphicsItemAnimation()
self.t.setItem(self.downItem)
self.t.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)
示例5: Joystick
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [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()
示例6: SingleJoystickView
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [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)
示例7: __init__
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class Animation:
def __init__(self, duration, component):
self.tl = QTimeLine(duration)
self.tl.setFrameRange(0, duration)
self.component = component
self.t = QGraphicsItemAnimation()
self.t.setItem(self.component.item)
self.t.setTimeLine(self.tl)
self.tl.connect(self.tl, SIGNAL('frameChanged(int)'), self.update)
self.tl.connect(self.tl, SIGNAL('finished()'), self.finished)
def start(self):
self.tl.stop()
self.tl.start()
def update(self):
pass
def finished(self):
pass
示例8: AnimatedGraphicsSvgItem
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class AnimatedGraphicsSvgItem(QGraphicsSvgItem):
def __init__(self, file, parent = None):
QGraphicsSvgItem.__init__(self, file, parent)
self.animation = QGraphicsItemAnimation()
self.animation.setItem(self)
self.timeline = QTimeLine(300)
self.animation.setTimeLine(self.timeline)
def setMatrix(self, matrix):
self.matrix = matrix
QGraphicsSvgItem.setMatrix(self, matrix)
def show(self):
self.scale(0.0, 0.0)
self.animation.setPosAt(0.0, QPointF(self.matrix.dx()+self.boundingRect().width()/8, self.matrix.dy()+self.boundingRect().height()/8))
self.animation.setPosAt(1.0, QPointF(self.matrix.dx(), self.matrix.dy()))
self.animation.setScaleAt(0.0, 0.25, 0.25)
self.animation.setScaleAt(1.0, 0.5, 0.5)
self.timeline.start()
QGraphicsSvgItem.show(self)
示例9: RotatingIcon
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class RotatingIcon(QLabel):
def __init__(self,resource,parent=None,steps=20,width=15,height=15):
QLabel.__init__(self,parent)
self._resource=resource
self._steps=steps
self._width=width
self._height=height
self._progressTimeLine = QTimeLine(1000, self)
self._progressTimeLine.setFrameRange(0, self._steps)
self._progressTimeLine.setLoopCount(0)
self.connect(self._progressTimeLine, SIGNAL("frameChanged(int)"), self.setProgress)
self._renderPixmaps()
self.setProgress(0)
def _renderPixmaps(self):
self._pixmaps=[]
for i in range(self._steps+1):
angle = int(i * 360.0 / self._steps)
pixmap = QPixmap(self._resource)
# if problem with loading png
if pixmap.size().width()==0:
self._pixmaps=None
return
rotate_matrix = QMatrix()
rotate_matrix.rotate(angle)
pixmap_rotated = pixmap.transformed(rotate_matrix)
pixmap_moved = QPixmap(pixmap.size())
pixmap_moved.fill(Qt.transparent)
painter = QPainter()
painter.begin(pixmap_moved)
painter.drawPixmap((pixmap_moved.width() - pixmap_rotated.width()) / 2.0, (pixmap_moved.height() - pixmap_rotated.height()) / 2.0, pixmap_rotated)
painter.end()
self._pixmaps+=[pixmap_moved.scaled(self._width, self._height)]
def setProgress(self, progress):
if self._pixmaps!=None:
self.setPixmap(self._pixmaps[progress])
def start(self):
self.setProgress(0)
self._progressTimeLine.start()
def stop(self):
self._progressTimeLine.stop()
示例10: StackFader
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class StackFader(QWidget):
"""
A widget that creates smooth transitions in a QStackedWidget.
"""
def __init__(self, stackedWidget):
QWidget.__init__(self, stackedWidget)
self.curIndex = None
self.timeline = QTimeLine()
self.timeline.setDuration(333)
self.timeline.finished.connect(self.hide)
self.timeline.valueChanged.connect(self.animate)
stackedWidget.currentChanged.connect(self.start)
self.hide()
def start(self, index):
if self.curIndex is not None:
stack = self.parent()
old, new = stack.widget(self.curIndex), stack.widget(index)
if old and new:
self.old_pixmap = QPixmap(new.size())
old.render(self.old_pixmap)
self.pixmap_opacity = 1.0
self.resize(new.size())
self.timeline.start()
self.raise_()
self.show()
self.curIndex = index
def paintEvent(self, ev):
painter = QPainter()
painter.begin(self)
painter.setOpacity(self.pixmap_opacity)
painter.drawPixmap(0, 0, self.old_pixmap)
painter.end()
def animate(self, value):
self.pixmap_opacity = 1.0 - value
self.repaint()
示例11: TransitionWidget
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class TransitionWidget(QWidget):
"""
This class implements a transition effect between two pixmaps.
Starts the transition with the method `start` and emit the signal finished()
when the transition is done.
"""
def __init__(self, parent):
QWidget.__init__(self, parent)
self._timeline = QTimeLine(400, self)
self._blending_factor = 0.0
self.connect(self._timeline, SIGNAL("valueChanged(qreal)"),
self._triggerRepaint)
self.connect(self._timeline, SIGNAL("finished()"), SIGNAL("finished()"))
def start(self, prev_pixmap, next_pixmap):
self._prev_pixmap = prev_pixmap
self._next_pixmap = next_pixmap
self._timeline.start()
def stop(self):
self._timeline.stop()
def _triggerRepaint(self, value):
self._blending_factor = value
self.update()
def paintEvent(self, event):
QWidget.paintEvent(self, event)
if self._timeline.state() == QTimeLine.NotRunning: # nothing to do
return
p = QPainter(self)
p.setRenderHint(QPainter.SmoothPixmapTransform, True)
p.drawPixmap(QPoint(0, 0), self._prev_pixmap)
p.setOpacity(self._blending_factor)
p.drawPixmap(QPoint(0, 0), self._next_pixmap)
示例12: HookBox0
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class HookBox0 (QGraphicsItem):
def __init__(self, parent=None, scene=None):
QGraphicsItem.__init__ (self)
self.helper = None
self.parent = parent
self.setFlags (QGraphicsItem.ItemIsSelectable)
self.setAcceptsHoverEvents (True)
self.pen_color = QPen (Qt.black, 2)
self.socket_id = None
self.hookType = None
self.hookName = ''
# init Hook Animation Tweening
self.timeline = QTimeLine (200)
self.timeline.setFrameRange (0, 100)
self.anim = QGraphicsItemAnimation ()
self.anim.setItem (self)
self.anim.setTimeLine (self.timeline)
self.parent.helper.connect (self.timeline, SIGNAL("finished()"), self.moveFurtherUp)
self.anim_active = False
def setTextfield (self):
tx = 8
self._text_item = GText (self.hookName, self)
self._text_item.setDefaultTextColor (Qt.black)
self._text_item.setEnabled (False)
if self.hookType=='out' :
tx=-50
tmp0 = QTextBlockFormat ()
tmp0.setAlignment (Qt.AlignRight)
tmp = QTextCursor ()
tmp.setBlockFormat (tmp0)
self._text_item.setTextCursor (tmp)
self._text_item.setPos (QPointF (tx, -5))
self._text_item.setFont (QFont ("Geneva", 8, QFont.AllLowercase, False))
self._text_item.setTextWidth (65)
def boundingRect (self): return QRectF (0, 0, 12, 12)
def shape (self):
path = QPainterPath ()
path.addRect (2, 2, 10, 10)
return path
def paint (self, painter, option, unused_widget):
painter.setBrush (QBrush (Qt.white))
painter.setPen (self.pen_color)
painter.drawEllipse (1, 1, 8 ,8)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def moveDown (self):
self.anim_active = True
self.up_flag=False
self.timeline.stop ()
self.hook_height = (self.pos_in_list-2)*10
self.anim.setPosAt (0, QPointF (self.x(), self.hook_height))
self.hook_height += 10
self.anim.setPosAt (1, QPointF (self.x(), self.hook_height))
self.timeline.start ()
self.update ()
def moveUp (self):
if self.anim_active == False:
if (self.parent.getHookPos(self)+1) < self.pos_in_list: # this check is to prevent the hooks with unchanged position from moving up.
self.anim_active = True
self.up_flag=True
self.timeline.stop ()
self.pos_in_list -= 1
self.hook_height = float(self.y())
self.anim.setPosAt (0, QPointF (self.x(), self.hook_height))
self.hook_height -= 10
self.anim.setPosAt (1, QPointF (self.x(), self.hook_height))
self.timeline.start ()
self.update ()
# this method double-checks whether the hook needs to move up again as a result
# of receiving other asynchronous "delete link" SIGNALs while moving up.
def moveFurtherUp (self):
#.........这里部分代码省略.........
示例13: ParallaxSlide
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
class ParallaxSlide(QGraphicsView):
def __init__(self):
QGraphicsView.__init__(self)
self.ofs = 0
self.factor = 1
self.scene = QGraphicsScene()
self.background = None
self.icons = []
self.iconTimeLine = QTimeLine()
self.backgroundTimeLine = QTimeLine()
self.setScene(self.scene)
self.background = self.scene.addPixmap(QPixmap(":/background.jpg"))
self.background.setZValue(0.0)
self.background.setPos(0, 0)
for i in range(7):
str = QString(":/icon%1.png").arg(i+1)
icon = self.scene.addPixmap(QPixmap(str))
icon.setPos(320+i*64, 400)
icon.setZValue(1.0)
self.icons.append(icon)
self.setFixedSize(320, 480)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.connect(self.iconTimeLine, SIGNAL("frameChanged(int)"), self, SLOT("moveIcons(int)"))
self.iconTimeLine.setCurveShape(QTimeLine.EaseInOutCurve)
self.connect(self.backgroundTimeLine, SIGNAL("frameChanged(int)"), self, SLOT("moveBackground(int)"))
self.connect(self.backgroundTimeLine, SIGNAL("finished()"), self, SLOT("adjustParameters()"))
self.backgroundTimeLine.setCurveShape(QTimeLine.EaseInOutCurve)
self.controls = Ui_ControlsForm()
toolWidget = QWidget(self)
toolWidget.setWindowFlags(Qt.Tool | Qt.WindowTitleHint)
self.controls.setupUi(toolWidget)
toolWidget.show()
self.connect(self.controls.speedSlider, SIGNAL("valueChanged(int)"),
self, SLOT("adjustParameters()"))
self.connect(self.controls.normalButton, SIGNAL("clicked()"),
self, SLOT("adjustParameters()"))
self.connect(self.controls.parallaxButton, SIGNAL("clicked()"),
self, SLOT("adjustParameters()"))
self.connect(self.controls.leftButton, SIGNAL("clicked()"),
self, SLOT("slideLeft()"))
self.connect(self.controls.rightButton, SIGNAL("clicked()"),
self, SLOT("slideRight()"))
self.slideBy(-320)
self.adjustParameters()
@pyqtSignature("")
def slideLeft(self):
if self.iconTimeLine.state() != QTimeLine.NotRunning:
return
if self.ofs > -640:
self.slideBy(-320)
@pyqtSignature("")
def slideRight(self):
if self.iconTimeLine.state() != QTimeLine.NotRunning:
return
if self.ofs < 0:
self.slideBy(320)
@pyqtSignature("int")
def slideBy(self, dx):
iconStart = self.ofs
iconEnd = self.ofs + dx
self.iconTimeLine.setFrameRange(iconStart, iconEnd)
self.iconTimeLine.start()
backgroundStart = -320 - int((-320 - iconStart)/self.factor)
backgroundEnd = -320 - int((-320 - iconEnd)/self.factor)
self.backgroundTimeLine.setFrameRange(backgroundStart, backgroundEnd)
self.backgroundTimeLine.start()
self.ofs = iconEnd
@pyqtSignature("bool")
def setParallaxEnabled(self, p):
if p:
self.factor = 2
self.setWindowTitle("Sliding - Parallax mode")
else:
self.factor = 1
self.setWindowTitle("Sliding - Normal mode")
#.........这里部分代码省略.........
示例14: CanvasProps
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
#.........这里部分代码省略.........
level = 120
else:
level = 100
painter.setBrush (QBrush (fillColor.dark (level)))
#painter.drawRoundRect (QRect (0, 0, 80, 34+self.height), 20)
painter.drawRect (QRect (0, 20, 120, 30+9*self._canvas_height))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def addProp (self, prop_name, prop_value):
i = len (self.props_list)
self.props_list.append (QGraphicsTextItem (prop_name + ' : ', self))
self.props_textItem_value_list.append (CustomFloatingText (prop_value, self))
# (1) adding the prop's name.
self.props_list[i].setPos (QPointF (7, 35+i*10))
self.props_list[i].setDefaultTextColor (QColor (Qt.white).light (255))
self.props_list[i].setFont (QFont ("Helvetica", 9, QFont.StyleItalic, False))
self.props_list[i].setTextWidth (55)
self.props_list[i].setToolTip (self.props_list[i].toPlainText ())
# (2) adding the prop's value.
self.props_textItem_value_list[i].setTextInteractionFlags (Qt.TextEditable)
self.props_textItem_value_list[i].setPos (QPointF (55, 35+i*10))
self.props_textItem_value_list[i].setDefaultTextColor (QColor (Qt.white).light (255))
self.props_textItem_value_list[i].setFont (QFont ("Helvetica", 9, QFont.StyleNormal, False))
self.props_textItem_value_list[i].setTextWidth (55)
receiver = lambda value: self.parent.listenToChangedPropsValues (prop_name, value)
self.helper.connect (self.props_textItem_value_list[i], SIGNAL ("textChanged(QString)"), receiver)
def getProps (self):
tmp_list = []
l = len (self.props_list)
for i in range (0, l):
tmp_list[i] = [self.props_list[i].toPlainText(), self.props_textItem_value_list[i].toPlainText()]
return tmp_list
def setTitle (self, title): self._nodename.setPlainText (title)
def setCanvasHeightInUnits (self, ch): self._canvas_height = ch
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def moveDown (self, canvas_height_in_units):
self.anim_active = True
self.upwards_flag = False
self.canvas_height = canvas_height_in_units
self.timeline.stop ()
self.anim.setPosAt (0, QPointF(0, 1+(self.canvas_height+1)*self.FACTOR))
self.anim.setPosAt (1, QPointF(0, 1+(self.canvas_height+2)*self.FACTOR))
self.timeline.start ()
self.update ()
def moveUp (self, canvas_height_in_units):
if self.anim_active == False:
self.anim_active = True
self.upwards_flag = True
self.canvas_height = canvas_height_in_units
self.timeline.stop ()
self.anim.setPosAt (0, QPointF(0, 1+(self.canvas_height+1)*self.FACTOR))
self.anim.setPosAt (1, QPointF(0, 1+(self.canvas_height) *self.FACTOR))
self.timeline.start ()
self.update ()
# this method double-checks whether the canvas needs to be further up as a
# result of receiving other asynchronous "delete link" SIGNALs while moving up.
def moveFurtherUp (self):
self.anim_active = False
if self.upwards_flag==True:
if self.parent.getMaxLen() < self.canvas_height:
self.moveUp (self.canvas_height-1)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def hoverEnterEvent (self, e):
self._nodename.setToolTip (self._nodename.toPlainText ())
QGraphicsItem.hoverEnterEvent (self, e)
'''
示例15: ProgressDialog
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import start [as 别名]
#.........这里部分代码省略.........
def publishComplete(self, exitCode, exitStatus):
self.progressBar_.setValue(self.progressBar_.maximum())
self._timeline.stop()
if self._cancelled:
self.reject()
self._cancelled = True
publishSuccess = (0 == exitCode and QProcess.NormalExit == exitStatus)
output_exists = self.__findOutput()
self.viewButton_.setEnabled(publishSuccess and \
output_exists)
if not publishSuccess:
self.progressLabel_.setText("Publishing failed, see script output"
" for more details")
else:
self.progressLabel_.setText("Publishing completed")
def __findOutput(self):
output_exists = os.path.exists(unicode(self._outFile))
if not output_exists:
output_exists = self.__findInSubdir()
if not(output_exists) and ('Dita' in self._publisher.__str__()) :
output_exists = self.__findInLog()
if not(output_exists) and ('Docbook' in self._publisher.__str__()) :
output_exists = self.__findInPI()
return output_exists
def __findInLog(self):
log = self.outputTextEdit_.toPlainText()
src_filename = os.path.basename(self._publisher.attrs()['srcUri'])
dst_filename = src_filename.split('.')[0] + "." + self._publisher.attrs()['extension']
re_str = '\[xslt\] Processing.*?' + src_filename + ' to (?P<outputFilename>.*?' + dst_filename + ')'
output_re = re.compile(re_str)
output_filename = ''
if None != output_re.search(log):
output_filename = output_re.search(log).group("outputFilename")
if not output_filename:
return False
real_dst_dir = os.path.dirname(unicode(output_filename))
dst_filename = os.path.join(real_dst_dir, os.path.basename(self._outFile))
os.rename(output_filename, dst_filename)
output_exists = os.path.exists(dst_filename)
if output_exists:
self._outFile = dst_filename
self._parent.setOutputFilePath(self._outFile)
return True
return False
def __findInPI(self):
src_uri = self._publisher.attrs()['srcUri']
grove = Grove.buildGroveFromFile(src_uri)
xpath_value = XpathExpr("//self::processing-instruction('dbhtml')").eval(grove.document())
dbhtml_pi = xpath_value.getNodeSet().firstNode()
str_ = unicode(dbhtml_pi.asGrovePi().data())
filename_re = re.compile('filename="(?P<filename>.*?\n?.*?)"')
dir_re = re.compile('dir="(?P<dir>.*?\n?.*?)"')
if None != filename_re.search(str_):
filename_ = filename_re.search(str_).group("filename")
if None != dir_re.search(str_):
dir_ = dir_re.search(str_).group("dir")
out_dir = os.path.dirname(self._outFile)
combined_output_filename = os.path.join(out_dir, dir_, filename_)
output_exists = os.path.exists(combined_output_filename)
if output_exists:
self._outFile = combined_output_filename
self._parent.setOutputFilePath(self._outFile)
return True
return False
def __findInSubdir(self):
output_filename = unicode(self._outFile)
filename_ = os.path.basename(output_filename)
dir_ = os.path.dirname(output_filename)
folder_name = os.path.basename(dir_)
output_filename = os.path.join(dir_, folder_name, filename_)
output_exists = os.path.exists(output_filename)
if output_exists:
self._outFile = output_filename
self._parent.setOutputFilePath(self._outFile)
return True
return False
def on_viewButton__clicked(self, released=True):
if not released:
return
self._plugin.launchViewer(os.path.abspath(self._outFile))
def publish(self, dsi, outFile):
if not self._publisher:
self.updatePublisherOutput("Script is not found")
self.publishComplete(1, QProcess.Crashed)
return self.exec_()
self._outFile = outFile
self.show()
try:
self.progressBar_.setValue(self.progressBar_.minimum() + 1)
self._publisher.publish(self, dsi, outFile)
self._timeline.start()
except PublishException, pe:
self.updatePublisherOutput(pe.getErrorString())
return self.exec_()