def __init__(self, stickMan, keyReceiver): self.m_stickMan = stickMan self.m_keyReceiver = keyReceiver # Create animation group to be used for all transitions. self.m_animationGroup = QtCore.QParallelAnimationGroup() stickManNodeCount = self.m_stickMan.nodeCount() self._pas = [] for i in range(stickManNodeCount): pa = QtCore.QPropertyAnimation(self.m_stickMan.node(i), 'pos') self._pas.append(pa) self.m_animationGroup.addAnimation(pa) # Set up intial state graph. self.m_machine = QtCore.QStateMachine() self.m_machine.addDefaultAnimation(self.m_animationGroup) self.m_alive = QtCore.QState(self.m_machine) self.m_alive.setObjectName('alive') # Make it blink when lightning strikes before entering dead animation. lightningBlink = QtCore.QState(self.m_machine) lightningBlink.assignProperty(self.m_stickMan.scene(), 'backgroundBrush', QtCore.Qt.white) lightningBlink.assignProperty(self.m_stickMan, 'penColor', QtCore.Qt.black) lightningBlink.assignProperty(self.m_stickMan, 'fillColor', QtCore.Qt.white) lightningBlink.assignProperty(self.m_stickMan, 'isDead', True) timer = QtCore.QTimer(lightningBlink) timer.setSingleShot(True) timer.setInterval(100) lightningBlink.entered.connect(timer.start) lightningBlink.exited.connect(timer.stop) self.m_dead = QtCore.QState(self.m_machine) self.m_dead.assignProperty(self.m_stickMan.scene(), 'backgroundBrush', QtCore.Qt.black) self.m_dead.assignProperty(self.m_stickMan, 'penColor', QtCore.Qt.white) self.m_dead.assignProperty(self.m_stickMan, 'fillColor', QtCore.Qt.black) self.m_dead.setObjectName('dead') # Idle state (sets no properties). self.m_idle = QtCore.QState(self.m_alive) self.m_idle.setObjectName('idle') self.m_alive.setInitialState(self.m_idle) # Lightning strikes at random. self.m_alive.addTransition(LightningStrikesTransition(lightningBlink)) lightningBlink.addTransition(timer.timeout, self.m_dead) self.m_machine.setInitialState(self.m_alive)
def __init__(self, parent=None): """ Inizializza il componente""" QStackedWidget.__init__(self, parent) self.__m_vertical = False self.__m_speed = 500 self.__m_animationtype = QEasingCurve.OutQuint #QEasingCurve.OutBack self.__m_now = 0 self.__m_next = 0 self.__m_pnow = QPoint(0, 0) self.__m_active = False self.__direction = self.__SLIDE_TYPE.RIGHT2LEFT self.__animgroup = QtCore.QParallelAnimationGroup() self.__animgroup.finished.connect(self.__animationDone) self.__animnext = QPropertyAnimation(None, "pos") self.__animnow = QPropertyAnimation(None, "pos") #self.setMinimumSize(300, 300) self.setStyleSheet("background-color: rgb(184, 184, 184);")
def doAnim_slideTiltFade(self, to_widget, doTilting=False, isBecomeVisible=False, duration=400): self.anim_group = QtCore.QParallelAnimationGroup() self.doAnim_slide(to_widget, duration=duration, doStart=False) self.anim_group.addAnimation(self.anim_slide) if doTilting: isTilted = abs(self.rotation()) > 1.0 self.doAanim_tilt(isTilted, duration=duration, doStart=False) self.anim_group.addAnimation(self.anim_tilt) if isBecomeVisible: self.doAanim_fade(isBecomeVisible, duration=duration, doStart=False) self.anim_group.addAnimation(self.anim_fade) self.anim_group.start()
def __init__(self, app_admin, workspace, parent): super(QDockWidget, self).__init__(parent) self.workspace = workspace self.app_admin = app_admin self._sections = None self._animation = QtCore.QParallelAnimationGroup() self._animation.finished.connect( self.animation_finished ) self._title_widget = QWidget() self._dock_widget = self.get_dock_widget() self._dock_widget.setMouseTracking(True) self._current_tree_widget = None # hack for removing the dock title bar self.setTitleBarWidget(self._title_widget) self.setWidget(self._dock_widget) self.setFeatures(QDockWidget.NoDockWidgetFeatures) self.app_admin.sections_changed_signal.connect(self.update_sections) self.update_sections()
# Ui. view = View(scene) view.setWindowTitle("Animated Tiles") view.setViewportUpdateMode(QtGui.QGraphicsView.BoundingRectViewportUpdate) view.setBackgroundBrush(QtGui.QBrush(bgPix)) view.setCacheMode(QtGui.QGraphicsView.CacheBackground) view.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) view.show() states = QtCore.QStateMachine() states.addState(rootState) states.setInitialState(rootState) rootState.setInitialState(centeredState) group = QtCore.QParallelAnimationGroup() for i, item in enumerate(items): anim = QtCore.QPropertyAnimation(item, 'pos') anim.setDuration(750 + i * 25) anim.setEasingCurve(QtCore.QEasingCurve.InOutBack) group.addAnimation(anim) trans = rootState.addTransition(ellipseButton.pressed, ellipseState) trans.addAnimation(group) trans = rootState.addTransition(figure8Button.pressed, figure8State) trans.addAnimation(group) trans = rootState.addTransition(randomButton.pressed, randomState) trans.addAnimation(group)
def startanimation(parent=None): import sys app = QtGui.QApplication(sys.argv) button1 = QGraphicsRectWidget() button2 = QGraphicsRectWidget() button3 = QGraphicsRectWidget() button4 = QGraphicsRectWidget() button2.setZValue(1) button3.setZValue(2) button4.setZValue(3) scene = QtGui.QGraphicsScene(0, 0, SCREENSIZE, SCREENSIZE,parent=parent) scene.setBackgroundBrush(QtCore.Qt.black) scene.addItem(button1) scene.addItem(button2) scene.addItem(button3) scene.addItem(button4) window = QtGui.QGraphicsView(scene,parent=parent) window.setFrameStyle(0) window.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) window.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) window.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) machine = QtCore.QStateMachine() group = QtCore.QState() timer = QtCore.QTimer() timer.setInterval(1250) timer.setSingleShot(True) group.entered.connect(timer.start) state1 = createGeometryState(button1, QtCore.QRect(BLOCKSIZE*2, 0, BLOCKSIZE, BLOCKSIZE), button2, QtCore.QRect(BLOCKSIZE*3, 0, BLOCKSIZE, BLOCKSIZE), button3, QtCore.QRect(SCREENSIZE-BLOCKSIZE*2, 0, BLOCKSIZE, BLOCKSIZE), button4, QtCore.QRect(SCREENSIZE-BLOCKSIZE, 0, BLOCKSIZE, BLOCKSIZE), group) state2 = createGeometryState(button1, QtCore.QRect(SCREENSIZE-BLOCKSIZE,BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE), button2, QtCore.QRect(SCREENSIZE-BLOCKSIZE, BLOCKSIZE*3, BLOCKSIZE, BLOCKSIZE), button3, QtCore.QRect(SCREENSIZE-BLOCKSIZE, SCREENSIZE-BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE), button4, QtCore.QRect(SCREENSIZE-BLOCKSIZE, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), group) state3 = createGeometryState(button1, QtCore.QRect(BLOCKSIZE*3, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), button2, QtCore.QRect(BLOCKSIZE*2, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), button3, QtCore.QRect(BLOCKSIZE, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), button4, QtCore.QRect(0, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), group) state4 = createGeometryState(button1, QtCore.QRect(0, BLOCKSIZE*3, BLOCKSIZE, BLOCKSIZE), button2, QtCore.QRect(0, BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE), button3, QtCore.QRect(0, BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), button4, QtCore.QRect(0, 0, BLOCKSIZE, BLOCKSIZE), group) state5 = createGeometryState(button1, QtCore.QRect( BLOCKSIZE*2,BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE), button2, QtCore.QRect(BLOCKSIZE*3, BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE), button3, QtCore.QRect(BLOCKSIZE*2, BLOCKSIZE*3, BLOCKSIZE, BLOCKSIZE), button4, QtCore.QRect(BLOCKSIZE*3, BLOCKSIZE*3, BLOCKSIZE, BLOCKSIZE), group) state6 = createGeometryState(button1, QtCore.QRect(BLOCKSIZE, BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), button2, QtCore.QRect(SCREENSIZE-2*BLOCKSIZE, BLOCKSIZE, BLOCKSIZE,BLOCKSIZE), button3, QtCore.QRect(BLOCKSIZE, SCREENSIZE-2*BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), button4, QtCore.QRect(SCREENSIZE-2*BLOCKSIZE, SCREENSIZE-2*BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), group) state7 = createGeometryState(button1, QtCore.QRect(0, 0, BLOCKSIZE, BLOCKSIZE), button2, QtCore.QRect(SCREENSIZE-BLOCKSIZE, 0, BLOCKSIZE, BLOCKSIZE), button3, QtCore.QRect(0, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), button4, QtCore.QRect(SCREENSIZE-BLOCKSIZE, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), group) group.setInitialState(state1) animationGroup = QtCore.QParallelAnimationGroup() anim = QtCore.QPropertyAnimation(button4, 'geometry') anim.setDuration(1000) anim.setEasingCurve(QtCore.QEasingCurve.OutElastic) animationGroup.addAnimation(anim) subGroup = QtCore.QSequentialAnimationGroup(animationGroup) subGroup.addPause(100) anim = QtCore.QPropertyAnimation(button3, 'geometry') anim.setDuration(1000) anim.setEasingCurve(QtCore.QEasingCurve.OutElastic) subGroup.addAnimation(anim) subGroup = QtCore.QSequentialAnimationGroup(animationGroup) subGroup.addPause(150) anim = QtCore.QPropertyAnimation(button2, 'geometry') anim.setDuration(1000) anim.setEasingCurve(QtCore.QEasingCurve.OutElastic) subGroup.addAnimation(anim) subGroup = QtCore.QSequentialAnimationGroup(animationGroup) subGroup.addPause(200) anim = QtCore.QPropertyAnimation(button1, 'geometry') anim.setDuration(1000) anim.setEasingCurve(QtCore.QEasingCurve.OutElastic) subGroup.addAnimation(anim) stateSwitcher = StateSwitcher(machine) group.addTransition(timer.timeout, stateSwitcher) stateSwitcher.addState(state1, animationGroup) stateSwitcher.addState(state2, animationGroup) stateSwitcher.addState(state3, animationGroup) stateSwitcher.addState(state4, animationGroup) stateSwitcher.addState(state5, animationGroup) stateSwitcher.addState(state6, animationGroup) stateSwitcher.addState(state7, animationGroup) machine.addState(group) machine.setInitialState(group) machine.start() window.resize(SCREENSIZE, SCREENSIZE) window.show() sys.exit(app.exec_())
def __init__(self, action, gui_context, parent): QtGui.QLabel.__init__(self, parent) AbstractActionWidget.__init__(self, action, gui_context) self.setObjectName('ActionButton') self.setMouseTracking(True) # This property holds if this button reacts to mouse events. self.interactive = False # This property is used to store the original position of this label # so it can be visually reset when the user leaves before the ongoing # animation has finished. self.originalPosition = None # This property holds the state of the selection animation. Since this # animation is only created inside startSelectionAnimation() (to avoid # the increasing amount of performAction() invocations), this variable is # used to continuously store the state of that animation. self.selectionAnimationState = QtCore.QAbstractAnimation.Stopped self.setMaximumHeight(160) opacityEffect = QtGui.QGraphicsOpacityEffect(parent=self) opacityEffect.setOpacity(1.0) self.setGraphicsEffect(opacityEffect) # Bounce animation # hoverAnimationPart1 = QtCore.QPropertyAnimation(self, 'pos') hoverAnimationPart1.setObjectName('hoverAnimationPart1') hoverAnimationPart1.setDuration(500) hoverAnimationPart1.setEasingCurve(QtCore.QEasingCurve.Linear) hoverAnimationPart2 = QtCore.QPropertyAnimation(self, 'pos') hoverAnimationPart2.setObjectName('hoverAnimationPart2') hoverAnimationPart2.setDuration(1500) hoverAnimationPart2.setEasingCurve(QtCore.QEasingCurve.OutElastic) hoverAnimation = QtCore.QSequentialAnimationGroup(parent=self) hoverAnimation.setObjectName('hoverAnimation') hoverAnimation.setLoopCount(-1) # Infinite hoverAnimation.addAnimation(hoverAnimationPart1) hoverAnimation.addAnimation(hoverAnimationPart2) #################### # Selection animation # selectionAnimationPart1 = QtCore.QPropertyAnimation(self, 'pos') selectionAnimationPart1.setObjectName('selectionAnimationPart1') selectionAnimationPart1.setDuration(200) selectionAnimationPart1.setEasingCurve(QtCore.QEasingCurve.Linear) selectionAnimationPart2 = QtCore.QPropertyAnimation(self, 'size') selectionAnimationPart2.setObjectName('selectionAnimationPart2') selectionAnimationPart2.setDuration(200) selectionAnimationPart2.setEasingCurve(QtCore.QEasingCurve.OutCubic) selectionAnimationPart3 = QtCore.QPropertyAnimation( self.graphicsEffect(), 'opacity') selectionAnimationPart3.setObjectName('selectionAnimationPart3') selectionAnimationPart3.setDuration(200) selectionAnimationPart3.setEasingCurve(QtCore.QEasingCurve.Linear) selectionAnimation = QtCore.QParallelAnimationGroup(parent=self) selectionAnimation.setObjectName('selectionAnimation') selectionAnimation.addAnimation(selectionAnimationPart1) selectionAnimation.addAnimation(selectionAnimationPart2) selectionAnimation.addAnimation(selectionAnimationPart3) # Not working when clicking the white area underneath the ActionButton image. #selectionAnimation.finished.connect(self.resetLayout) #selectionAnimation.finished.connect(self.performAction) selectionAnimation.stateChanged.connect( self.updateSelectionAnimationState)
def __init__(self, machine, title, msg, icon, time=3000, parent=None): QtGui.QWidget.__init__(self, parent) self.machine = machine self.time = time if ostools.isWin32(): self.setWindowFlags(QtCore.Qt.ToolTip) else: self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.X11BypassWindowManagerHint | QtCore.Qt.ToolTip) self.m_animation = QtCore.QParallelAnimationGroup() anim = QtCore.QPropertyAnimation(self) anim.setTargetObject(self) self.m_animation.addAnimation(anim) anim.setEasingCurve(QtCore.QEasingCurve.OutBounce) anim.setDuration(1000) self.connect(anim, QtCore.SIGNAL('finished()'), self, QtCore.SLOT('reverseTrigger()')) self.m_animation.setDirection(QtCore.QAnimationGroup.Forward) self.title = QtGui.QLabel(title, self) self.msg = QtGui.QLabel(msg, self) self.content = msg if icon: self.icon = QtGui.QLabel("") self.icon.setPixmap(QtGui.QPixmap(icon).scaledToWidth(30)) else: self.icon = QtGui.QLabel("") self.icon.setPixmap(QtGui.QPixmap(30, 30)) self.icon.pixmap().fill(QtGui.QColor(0, 0, 0, 0)) layout_0 = QtGui.QVBoxLayout() layout_0.setMargin(0) layout_0.setContentsMargins(0, 0, 0, 0) if self.icon: layout_1 = QtGui.QGridLayout() layout_1.addWidget(self.icon, 0, 0, 1, 1) layout_1.addWidget(self.title, 0, 1, 1, 7) layout_1.setAlignment(self.msg, QtCore.Qt.AlignTop) layout_0.addLayout(layout_1) else: layout_0.addWidget(self.title) layout_0.addWidget(self.msg) self.setMaximumWidth(self.parent().theme["toasts/width"]) self.msg.setMaximumWidth(self.parent().theme["toasts/width"]) self.title.setMinimumHeight( self.parent().theme["toasts/title/minimumheight"]) self.setLayout(layout_0) self.setGeometry(0, 0, self.parent().theme["toasts/width"], self.parent().theme["toasts/height"]) self.setStyleSheet(self.parent().theme["toasts/style"]) self.title.setStyleSheet(self.parent().theme["toasts/title/style"]) if self.icon: self.icon.setStyleSheet(self.parent().theme["toasts/icon/style"]) self.msg.setStyleSheet(self.parent().theme["toasts/content/style"]) self.layout().setSpacing(0) self.msg.setText( PesterToast.wrapText(self.msg.font(), unicode(self.msg.text()), self.parent().theme["toasts/width"], self.parent().theme["toasts/content/style"])) p = QtGui.QApplication.desktop().availableGeometry(self).bottomRight() o = QtGui.QApplication.desktop().screenGeometry(self).bottomRight() anim.setStartValue(p.y() - o.y()) anim.setEndValue(100) self.connect(anim, QtCore.SIGNAL('valueChanged(QVariant)'), self, QtCore.SLOT('updateBottomLeftAnimation(QVariant)')) self.byebye = False