def __init__(self, parent): """ Create property animations, sets the opacity to zero initially. """ super().__init__() if isinstance(parent, QtGui.QGraphicsItem): # create opacity effect self.effect = QtGui.QGraphicsOpacityEffect() self.effect.setOpacity(0) parent.setGraphicsEffect(self.effect) self.fade = QtCore.QPropertyAnimation(self.effect, 'opacity') elif isinstance(parent, QtGui.QWidget): parent.setWindowOpacity(0) self.fade = QtCore.QPropertyAnimation(parent, 'windowOpacity') else: raise RuntimeError( 'Type of parameter must be QtGui.QGraphicsItem or QtGui.QWidget.' ) # set start and stop value self.fade.setStartValue(0) self.fade.setEndValue(1) self.fade.finished.connect(self.finished) self.forward = True
def _animateExpand(self, value): opacityAnim = qc.QPropertyAnimation(self.main_widgetProxy, "opacity") opacityAnim.setStartValue(int(not (value))) opacityAnim.setEndValue(int(value)) opacityAnim.setDuration(200) opacityAnimCurve = qc.QEasingCurve() if value: opacityAnimCurve.setType(qc.QEasingCurve.InQuad) else: opacityAnimCurve.setType(qc.QEasingCurve.OutQuad) ##### size_anim = qc.QPropertyAnimation(self, "geometry") geometry = self.geometry() width = geometry.width() x, y, _, _ = geometry.getCoords() size_start = qc.QRect(x, y, width, int(not (value) * 200)) size_end = qc.QRect(x, y, width, int(value) * 200) size_anim.setStartValue(size_start) size_anim.setEndValue(size_end) size_anim.setDuration(150) size_animCurve = qc.QEasingCurve() if value: size_animCurve.setType(qc.QEasingCurve.InQuad) else: size_animCurve.setType(qc.QEasingCurve.OutQuad) size_anim.setEasingCurve(size_animCurve) self._animation = qc.QSequentialAnimationGroup() if value: self.main_widgetProxy.setOpacity(0.05) self._animation.addAnimation(size_anim) self._animation.addAnimation(opacityAnim) else: self.main_widgetProxy.setOpacity(1) self._animation.addAnimation(opacityAnim) self._animation.addAnimation(size_anim) size_anim.valueChanged.connect(self._forceResize) self._animation.finished.connect(self._animation.clear) if not value: self._animation.finished.connect(self.deleteWidgetUI) self._animation.start(qc.QAbstractAnimation.DeleteWhenStopped)
def _animateExpand(self, widget, value): Proxy = self.opacity_wdt opacity_anim = qc.QPropertyAnimation(Proxy, "opacity") opacity_anim.setStartValue(not(value)) opacity_anim.setEndValue(value) opacity_anim.setDuration(200) opacity_anim_curve = qc.QEasingCurve() if value is True: opacity_anim_curve.setType(qc.QEasingCurve.InQuad) else: opacity_anim_curve.setType(qc.QEasingCurve.OutQuad) opacity_anim.setEasingCurve(opacity_anim_curve) size_anim = qc.QPropertyAnimation(widget, "geometry") geometry = widget.geometry() height = geometry.height() x, y, _, _ = geometry.getCoords() size_start = qc.QRect(x, y, int(not(value)) * 225, height) size_end = qc.QRect(x, y, value * 225, height ) size_anim.setStartValue(size_start) size_anim.setEndValue(size_end) size_anim.setDuration(250) size_anim_curve = qc.QEasingCurve() if value: size_anim_curve.setType(qc.QEasingCurve.InSine) else: size_anim_curve.setType(qc.QEasingCurve.OutCubic) size_anim.setEasingCurve(size_anim_curve) self._animation = qc.QSequentialAnimationGroup() if value: Proxy.setOpacity(0) self._animation.addAnimation(size_anim) self._animation.addAnimation(opacity_anim) self.turnAroundLabel.setEnabled(True) else: Proxy.setOpacity(1) self._animation.addAnimation(opacity_anim) self._animation.addAnimation(size_anim) self.turnAroundLabel.setEnabled(False) size_anim.valueChanged.connect(self._forceResize) self._animation.finished.connect(self._animation.clear) self._animation.start(qc.QAbstractAnimation.DeleteWhenStopped)
def __init__(self, scene): ''' Initialize the game ''' self.scene = scene scene.scene_left.connect(self.quit_scene) self.rocket = Rocket() self.width = self.scene.sceneRect().width() self.height = self.scene.sceneRect().height() self.screen_bottom = self.height - self.rocket.boundingRect().height() scene.addItem(self.rocket) # Compute random land points random.seed() p1 = QPointF(0.0, random.uniform(0.0, self.height)) p2 = QPointF(random.uniform(0.0, self.width / 4.0), random.uniform(0.0, self.height)) p3 = QPointF(random.uniform(p2.x(), 2 * self.width / 3.0), self.height) p4 = QPointF(p3.x() + 40.0, self.height) p5 = QPointF(self.width, random.uniform(0.0, self.height)) path = QPainterPath(p1) slope = (p2.y() - p1.y()) / (p2.x() - p1.x()) sign = 3 for point in range(int((p2.x() - p1.x()) / 5)): sign = -sign x = p1.x() + point * 5 path.lineTo(x, slope * x + sign) path.lineTo(p2) path.lineTo(p3) path.lineTo(p4) path.lineTo(p5) scene.addPath(path) # Initialize the music try: self.music = phonon.Phonon.createPlayer( phonon.Phonon.MusicCategory, phonon.Phonon.MediaSource(':/lander.mp3')) except NameError: LOG.warning('Could not initialise phonon') # Initialize the animation for the translation of the rocket self.animation = QtCore.QPropertyAnimation(self.rocket, "position") self.rocket_position = None # Initialize the animation for the rotation of the rocket self.rotation = QtCore.QPropertyAnimation(self.rocket, "angle") # Catch the key events to add user interaction: self.scene.keyPressEvent = lambda x: self.key(x) # updateCurrentTime is called by Qt when time changes self.animation.updateCurrentTime = lambda x: self.time_progress(x) # Connect signal sent at end of animation self.animation.finished.connect(self.animation_finished)
def __init__(self, device=None): super().__init__() if device is None: import GazeDevice self.gazeTracker = GazeDevice.getGazeDevice() else: self.gazeTracker = device self.setStyleSheet("background-color: #ddd;") self.movementTime = 750 self.pointCaptureDelay = 500 self.pointCaptureDuration = 1000 self.started = False self.eyes = EyeballWidget(self) self.target = TargetWidget(parent=self) self.target.hide() self.eyeTimer = QtCore.QTimer() self.eyeTimer.setSingleShot(False) self.eyeTimer.timeout.connect(self.moveEyes) self.gazeTimer = QtCore.QTimer() self.gazeTimer.setSingleShot(False) self.gazeTimer.timeout.connect(self.trackGazeWithTarget) self.pointLabels = [] self.showCalibratedLabels() self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) self.showFullScreen() self.centerChildAt(self.eyes) self.animation = QtCore.QPropertyAnimation(self.target, 'pos') self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuad) self.pulseAnimation = QtCore.QPropertyAnimation(self.target, 'scale') self.pulseAnimation.setStartValue(1.0) self.pulseAnimation.setKeyValueAt(0.5, 1.0 / 3.0) self.pulseAnimation.setEndValue(1.0) self.pulseAnimation.setEasingCurve(QtCore.QEasingCurve.InOutQuad) self.pulseAnimation.setLoopCount(-1) self.gazeTracker.eyesAppeared.connect(self.setEyesGood) self.gazeTracker.eyesDisappeared.connect(self.setEyesBad) self.eyeTimer.start(1000 / 30) self.gazeTimer.start(1000 / 30) self.gazeTracker.startPolling() self.points = None
def __init__(self, parent): super(SegmentationTabDropWidget, self).__init__(parent) self.setAcceptDrops(True) self._animation_increase = QtCore.QPropertyAnimation( self, 'maximumWidth') self._animation_increase.setStartValue(1) self._animation_increase.setEndValue(100) self._animation_decrease = QtCore.QPropertyAnimation( self, 'maximumWidth') self._animation_decrease.setStartValue(100) self._animation_decrease.setEndValue(1) self._animation_decrease.finished.connect(self._animationFinished) self._tabWidget = None
def _animateExpand(self, value): opacity_anim = QtCore.QPropertyAnimation(self.main_widget_proxy, "opacity") opacity_anim.setStartValue(not (value)) opacity_anim.setEndValue(value) opacity_anim.setDuration(200) opacity_anim_curve = QtCore.QEasingCurve() if value: opacity_anim_curve.setType(QtCore.QEasingCurve.InQuad) else: opacity_anim_curve.setType(QtCore.QEasingCurve.OutQuad) opacity_anim.setEasingCurve(opacity_anim_curve) size_anim = QtCore.QPropertyAnimation(self, 'geometry') geometry = self.geometry() width = geometry.width() x, y, _, _ = geometry.getCoords() size_start = QtCore.QRect(x, y, width, int(not (value)) * 150) size_end = QtCore.QRect(x, y, width, value * 150) size_anim.setStartValue(size_start) size_anim.setEndValue(size_end) size_anim.setDuration(300) size_anim_curve = QtCore.QEasingCurve() if value: size_anim_curve.setType(QtCore.QEasingCurve.InQuad) else: size_anim_curve.setType(QtCore.QEasingCurve.OutQuad) size_anim.setEasingCurve(size_anim_curve) self._animation = QtCore.QSequentialAnimationGroup() if value: self.main_widget_proxy.setOpacity(1) self._animation.addAnimation(size_anim) self._animation.addAnimation(opacity_anim) else: self.main_widget_proxy.setOpacity(0) self._animation.addAnimation(opacity_anim) self._animation.addAnimation(size_anim) size_anim.valueChanged.connect(self._forceResize) self._animation.finished.connect(self._animation.clear) if not value: size_anim.finished.connect(self.deleteWidget) size_anim.start(QtCore.QAbstractAnimation.DeleteWhenStopped)
def _create_content_items(self): x_pos = Style.component_margin # scene width - margins text_width = self.scene().width() - 2 * Style.component_margin # create panorama items text for i, text in enumerate(self.tabs.itervalues()): tmp = QtGui.QGraphicsTextItem() tmp.setFont(Style.body_font) tmp.setAcceptHoverEvents(False) tmp.setPlainText(text) tmp.setTextWidth(text_width) tmp.setDefaultTextColor(Style.ui_text_color) # place content below header tmp.setPos(x_pos, (Style.component_margin * 4 + Style.body_text_size + Style.header_text_size)) # calculate the position for the next item x_pos = x_pos + text_width + Style.component_margin anim = QtCore.QPropertyAnimation(tmp, 'pos') anim.setDuration(Style.animation_time) anim.setPropertyName('pos') anim.setEasingCurve(QtCore.QEasingCurve.OutCirc) self.content_animation_group.addAnimation(anim) self.content_animations.append(anim) self.content_items.append(tmp) self.scene().addItem(tmp)
def __init__(self, scene, tabs=None, parent=None): super(PanoramaView, self).__init__(scene, parent) self.tabs = tabs or {} self.header_items = [] self.header_animations = [] self.content_items = [] self.content_animations = [] self.current_index = 0 self.mouse_x_position = 0 self.prev_x_position = 0 # set blackish background self.setStyleSheet(Style.background_style) # create opacity animator self.opacity_animator = QtCore.QPropertyAnimation() self.opacity_animator.setDuration(Style.animation_time) self.opacity_animator.setPropertyName("opacity") self.opacity_animator.setEasingCurve(QtCore.QEasingCurve.Linear) self.opacity_animator.setStartValue(0.3) self.opacity_animator.setEndValue(1.0) # create animation groups self.content_animation_group = QtCore.QParallelAnimationGroup() self.header_animation_group = QtCore.QParallelAnimationGroup() # create the rest of the ui self._create_top_bar() self._create_metro_tab_bar() self._create_content_items()
def _create_metro_tab_bar(self): x_pos = Style.component_margin # create panorama header items for i, text in enumerate(self.tabs.iterkeys()): text_item = QtGui.QGraphicsTextItem() text_item.setAcceptHoverEvents(False) text_item.setPlainText(text) text_item.setFont(Style.header_font) text_item.adjustSize() text_item.setDefaultTextColor(Style.ui_text_color) # place header below header text text_item.setPos( x_pos, (Style.component_margin * 2 + Style.body_text_size)) # calculate position for the next item. ComponentMargin + item width + ComponentMargin x_pos = x_pos + text_item.textWidth() + Style.component_margin anim = QtCore.QPropertyAnimation(text_item, 'pos') anim.setDuration(Style.animation_time) anim.setPropertyName('pos') anim.setEasingCurve(QtCore.QEasingCurve.OutCirc) self.header_animation_group.addAnimation(anim) self.header_animations.append(anim) # remove highlight from all items except the current one if i > 0: text_item.setOpacity(0.3) self.header_items.append(text_item) self.scene().addItem(text_item)
def __init__(self, model, parent=None): QtGui.QMainWindow.__init__(self, parent) self.model = model self.ui = Ui_MainWindowView() self.ui.setupUi(self) MainWindowView.MaxRecentFiles = len( self.ui.menu_recent_files.actions()) MainWindowView.MaxBookmarkFiles = \ len(self.ui.menu_recent_bookmarks.actions()) self.ui.menu_recent_files.menuAction().setVisible(False) self.global_shortcuts = self._define_global_shortcuts() self.create_connections() self.centralize_window() self.update_recent_file_actions() self.model.load_progress.connect( self.ui.statusbar.set_progressbar_value) self.vertical_anim = QtCore.QPropertyAnimation( self.ui.qscroll_area_viewer.verticalScrollBar(), "sliderPosition")
def __init__(self, parent=None): super(SegmentationTabWidget, self).__init__(parent) tb = SegmentationTabBar(self) tb.tabReorderRequested.connect(self.repositionTab) self.setTabBar(tb) self.setAcceptDrops(True) self._animation_increase = QtCore.QPropertyAnimation( self, 'maximumWidth') self._animation_increase.setStartValue(1) self._animation_increase.setEndValue(TABWIDGET_TARGET_SIZE) self._animation_decrease = QtCore.QPropertyAnimation( self, 'maximumWidth') self._animation_decrease.setStartValue(TABWIDGET_TARGET_SIZE) self._animation_decrease.setEndValue(1) self._animation_decrease.finished.connect(self._animationFinished)
def leaveEvent(self, event): if self._unfocusedOpacity == 1.0: return self.animation = animation = QtCore.QPropertyAnimation(self, 'windowOpacity') animation.setDuration(250) animation.setStartValue(self.windowOpacity()) animation.setEndValue(self._unfocusedOpacity) animation.valueChanged.connect(self.animate) animation.start()
def slide_in_animation(self): """Run the slide-in animation.""" self.start_anim = QtCore.QPropertyAnimation(self, 'geometry') self.start_anim.setDuration(150) height = self.menu_bar.parent().geometry().height() - 46 self.start_anim.setStartValue(QtCore.QRect(-250, 46, 0, height)) self.start_anim.setEndValue(QtCore.QRect(0, 46, 250, height)) self.start_anim.start() self.menu_bar.show_menu_btn.setChecked(True)
def slide_out_animation(self): """Run the slide-out animation.""" self.end_anim = QtCore.QPropertyAnimation(self, 'geometry') self.end_anim.setDuration(150) self.end_anim.setStartValue(self.geometry()) height = self.menu_bar.parent().geometry().height() self.end_anim.setEndValue(QtCore.QRect(-250, 46, 0, height)) self.end_anim.finished.connect(self.hide) self.end_anim.start() self.menu_bar.show_menu_btn.setChecked(False)
def _start_animation(self): """Execute the start animation. Slides the dialog into the screen from the left side. """ self.start_anim = QtCore.QPropertyAnimation(self, 'geometry') self.start_anim.setDuration(self._animation_speed) self.start_anim.setStartValue(self._get_start_geometry()) self.start_anim.setEndValue(self._get_display_geometry()) self.start_anim.start()
def _end_animation(self): """Execute the end animation. Slides the dialog out to the right. """ self.end_anim = QtCore.QPropertyAnimation(self, 'geometry') self.end_anim.setDuration(self._animation_speed) self.end_anim.setStartValue(self.geometry()) self.end_anim.setEndValue(self._get_end_geometry()) self.end_anim.finished.connect(self.close) self.end_anim.start()
def showImage(self): pixmap = QtGui.QPixmap(self._art.image.scaled(500, 500, QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.SmoothTransformation)) self._pixmapWrapper.graphicsItem.setPixmap(pixmap) anim = QtCore.QPropertyAnimation(self) anim.setPropertyName("opacity") anim.setTargetObject(self._pixmapWrapper) anim.setDuration(750) anim.setStartValue(0.0) anim.setEndValue(1.0) anim.setEasingCurve(QtCore.QEasingCurve.InOutBack) anim.start() self.startTimer(3000)
def setGeometry(self, rect): print('setGeometry', rect, self.widget().objectName()) self.trg_rect = rect if (self.anim is None): self.anim = QtCore.QPropertyAnimation(self.widget(), "geometry") self.anim.setStartValue(self.cur_rect) self.anim.setEndValue(self.trg_rect) self.anim.setDuration(self.anim_duration) self.anim.setEasingCurve(self.anim_curve) self.anim.finished.connect(self.on_anim_finished) self.anim.start() else: self.anim.setEndValue(self.trg_rect)
def toggled(self, model, wrapper, checkbox, parent): global view, __doc__ new_value = wrapper.toggle_checked() new_list = model.checked() print '='*20, 'New List', '='*20 print '\n'.join(x.name for x in new_list) view.setWindowTitle('%s (%d)' % (__doc__, len(new_list))) if new_value: pa = QtCore.QSequentialAnimationGroup(parent) anim = QtCore.QPropertyAnimation(checkbox, 'scale') anim.setDuration(700) anim.setStartValue(10) anim.setEndValue(1) anim.setEasingCurve(QtCore.QEasingCurve.OutSine) pa.addAnimation(anim) anim = QtCore.QPropertyAnimation(parent, 'rotation', parent) anim.setDuration(100) anim.setStartValue(-180) anim.setEndValue(0) pa.addAnimation(anim) pa.start(QtCore.QAbstractAnimation.DeleteWhenStopped)
def fade(target, duration, propertyName='opacity', start=0, end=1, easingCurve=QtCore.QEasingCurve.OutCirc): """Get animation to fade in the image :param target: Target property of animation(QGraphicsOpacityEffect) :param duration: Time spent on animation :param propertyName: Name of the property changed :param start: Start value of the effect :param end: End value of the effect :param easingCurve: Type of animation curve """ an = QtCore.QPropertyAnimation(target, propertyName) an.setDuration(duration) an.setStartValue(start) an.setEndValue(end) an.setEasingCurve(easingCurve) return an
def receiveData(json_str): global rootObject data = json.loads(json_str) print 'Received data:', data if len(data) == 2 and data[0] == 'setRotation': animation = QtCore.QPropertyAnimation(rootObject, 'rotation', rootObject) animation.setDuration(3000) animation.setEasingCurve(QtCore.QEasingCurve.InOutElastic) # eh immer: animation.setStartValue(rootObject.property('rotation')) animation.setEndValue(data[1]) animation.start(QtCore.QAbstractAnimation.DeleteWhenStopped) #rootObject.setProperty('rotation', data[1]) else: sendData({'Hello': 'from PySide', 'itsNow': int(time.time())})
def _state_fired(self): if not self._state: anim = QtCore.QPropertyAnimation(self.control, "count") anim.setDuration(1000) anim.setStartValue(1) anim.setEndValue(32) anim.setLoopCount(-1) QtCore.QObject.connect(anim, QtCore.SIGNAL("finished()"), anim, QtCore.SLOT("deleteLater()")) anim.start() self._animation = anim else: self._animation.stop() self.control.set_count(0) self._state = not self._state
def _camera_lyt_anim(self, value): Proxy = self.opacityCamera_wdt opacity_anim = qc.QPropertyAnimation(Proxy, "opacity") opacity_anim.setStartValue(float(value)) opacity_anim.setEndValue(float(not(value))) opacity_anim.setDuration(5000) opacity_anim_curve = qc.QEasingCurve() if value: #Proxy.setOpacity(float(0)) opacity_anim_curve.setType(qc.QEasingCurve.InQuad) opacity_anim.setEasingCurve(opacity_anim_curve) opacity_anim.start(qc.QAbstractAnimation.DeleteWhenStopped) else: #Proxy.setOpacity(float(1)) opacity_anim_curve.setType(qc.QEasingCurve.OutQuad) opacity_anim.setEasingCurve(opacity_anim_curve) opacity_anim.start(qc.QAbstractAnimation.DeleteWhenStopped)
def update(self): '''Animate the view to match sorting and filtering requests''' logger.debug('updating view') self.deletedTaskWidgets = [ tw for tw in self.taskWidgets if tw.task.index == -2 ] taskWidgetsHeight = len(self.taskWidgets) * ( TaskWidget.TASKWIDGETHEIGHT * TaskWidget.TASKWIDGETSPACING) self.taskContainer.resize( self.scrollArea.width() - 20, max(taskWidgetsHeight, self.scrollArea.height())) self.animGroup = QtCore.QParallelAnimationGroup() animGroupForDeletedWidget = QtCore.QParallelAnimationGroup() animGroupForDeletedWidget.finished.connect(self.deleteTaskWidget) for taskWidget in self.taskWidgets: moveAnimation = QtCore.QPropertyAnimation(taskWidget, 'pos') moveAnimation.setDuration(1000) moveAnimation.setStartValue(taskWidget.pos()) moveAnimation.setEndValue(taskWidget.getNewPosition()) if taskWidget.task.index == -2: # DELETED WIDGET moveAnimation.setEasingCurve(QtCore.QEasingCurve.InCubic) animGroupForDeletedWidget.addAnimation(moveAnimation) else: moveAnimation.setEasingCurve(QtCore.QEasingCurve.OutCubic) self.animGroup.addAnimation(moveAnimation) taskWidget.update() # GO self.animGroup.start() # OVERLAP ANIMNATION FOR DELETED WIDGETS IN CASE OF RAPID TASK DELETION if animGroupForDeletedWidget.animationCount(): self.animGroupsDeleted.append(animGroupForDeletedWidget) animGroupForDeletedWidget.start() logger.debug('finished updating view')
def addWidgetSizeAnim(self, widget, onoff): self.size_anim = QtCore.QPropertyAnimation(widget, 'geometry') geometry = widget.geometry() width = geometry.width() x, y, _, _ = geometry.getCoords() print x, y size_start = QtCore.QRect(x, y, width, int(not (onoff)) * 20) size_end = QtCore.QRect(x, y, width, onoff * 20) self.size_anim.setStartValue(size_start) self.size_anim.setEndValue(size_end) self.size_anim.setDuration(200) size_anim_curve = QtCore.QEasingCurve() if onoff: size_anim_curve.setType(QtCore.QEasingCurve.InQuad) else: size_anim_curve.setType(QtCore.QEasingCurve.OutQuad) self.size_anim.setEasingCurve(size_anim_curve) self.size_anim.valueChanged.connect(self.forceResize) self.size_anim.start(QtCore.QAbstractAnimation.DeleteWhenStopped)
def showSelectionInPuzzleView(self, selectedItems, deselectedItems): selectionChanged = False # update the selected cells: for itemRange in selectedItems: index = itemRange.topLeft() index = index.sibling(index.row(), 0) # iterate the ranges in this row while True: if (index == QtCore.QModelIndex()): break if (not index.isValid()): break item = self.constraintModel.getItem(index) if (isinstance(item, (ConstraintProxyItem, CellProxyItem, ReferencedCellProxyItem, GridProxyItem, ConstraintGroupProxyItem))): #self.selectedCells |= item.getCells() selectionChanged = True self.selectedItems.add(item) # check whether or not to calculate the next index if (index.row() + 1 < itemRange.bottomRight().row()): index = index.sibling(index.row() + 1, 0) else: break # remove the de-selected cells: for itemRange in deselectedItems: index = itemRange.topLeft() index = index.sibling(index.row(), 0) # iterate the ranges in this row while True: if (index == QtCore.QModelIndex()): break if (not index.isValid()): break item = self.constraintModel.getItem(index) if (item in self.selectedItems): self.selectedItems.remove(item) selectionChanged = True # check whether or not to calculate the next index if (index.row() + 1 < itemRange.bottomRight().row()): index = index.sibling(index.row() + 1, 0) else: break if (selectionChanged): # first copy the reference to the current state to the previous state self.trans1, self.trans2 = self.trans2, self.trans1 self.previousSelectionState, self.currentSelectionState = self.currentSelectionState, self.previousSelectionState selectedCells = set() for item in self.selectedItems: selectedCells |= item.getCells() group = QtCore.QParallelAnimationGroup() for cell in self.puzzlePieceProxies: #it = self.puzzlePieces[cell] it = self.puzzlePieceProxies[cell] animation = QtCore.QPropertyAnimation(it, "backgroundColor") animation.setDuration(200) animation.setEasingCurve(QtCore.QEasingCurve.InOutQuad) group.addAnimation(animation) if cell in selectedCells: self.currentSelectionState.assignProperty( it, "backgroundColor", QtGui.QColor(255, 0, 0, 100)) else: self.currentSelectionState.assignProperty( it, "backgroundColor", QtGui.QColor(255, 0, 0, 0)) for anim in self.trans1.animations(): self.trans1.removeAnimation(anim) self.trans1.addAnimation(group) self.showNextSelectionState.emit()
state3.assignProperty(p4, 'pos', QtCore.QPointF(5 + 64 + 5, 5)) state3.assignProperty(p5, 'pos', QtCore.QPointF(5 + 64 + 5, 5 + 64 + 5)) state3.assignProperty(p6, 'pos', QtCore.QPointF(5 + 64 + 5, 5 + (64 + 5) + 64)) state3.assignProperty(widget, 'geometry', QtCore.QRectF(138, 5, 400 - 138, 200)) state3.assignProperty(box, 'geometry', QtCore.QRect(5, 205, 400, 90)) state3.assignProperty(p1, 'opacity', 1.0) state3.assignProperty(p2, 'opacity', 1.0) state3.assignProperty(p3, 'opacity', 1.0) state3.assignProperty(p4, 'opacity', 1.0) state3.assignProperty(p5, 'opacity', 1.0) state3.assignProperty(p6, 'opacity', 1.0) t1 = state1.addTransition(button.clicked, state2) animation1SubGroup = QtCore.QSequentialAnimationGroup() animation1SubGroup.addPause(250) animation1SubGroup.addAnimation(QtCore.QPropertyAnimation(box, 'geometry', state1)) t1.addAnimation(animation1SubGroup) t1.addAnimation(QtCore.QPropertyAnimation(widget, 'geometry', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p1, 'pos', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p2, 'pos', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p3, 'pos', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p4, 'pos', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p5, 'pos', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p6, 'pos', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p1, 'rotation', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p2, 'rotation', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p3, 'rotation', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p4, 'rotation', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p5, 'rotation', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p6, 'rotation', state1)) t1.addAnimation(QtCore.QPropertyAnimation(p1, 'opacity', state1))
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) trans = rootState.addTransition(tiledButton.pressed, tiledState) trans.addAnimation(group)
def createAnimations(objects, machine): for obj in objects: animation = QtCore.QPropertyAnimation(obj, 'geometry', obj) machine.addDefaultAnimation(animation)