def _animation_expand(self, value): size_animation = qc.QPropertyAnimation(self, 'geometry') opacity_anim = qc.QPropertyAnimation(self.main_widget_proxy, 'opacity') # Animation Opacity opacity_anim.setStartValue(not (value)) opacity_anim.setEndValue(value) opacity_anim.setDuration(200) opacity_anim_curve = qc.QEasingCurve() if value: opacity_anim_curve.setType(qc.QEasingCurve.InQuad) else: opacity_anim_curve.setType(qc.QEasingCurve.OutQuad) opacity_anim.setEasingCurve(opacity_anim_curve) # def size of the geometry geometry = self.geometry() width = geometry.width() x, y, _, _ = geometry.getCoords() size_start = qc.QRect(x, y, width, int(not (value)) * 150) size_end = qc.QRect(x, y, width, int(value) * 150) # Animation for geometry size_animation.setStartValue(size_start) size_animation.setEndValue(size_end) size_animation.setDuration(300) anim_curve = qc.QEasingCurve() if value: anim_curve.setType(qc.QEasingCurve.InQuad) else: anim_curve.setType(qc.QEasingCurve.OutQuad) size_animation.setEasingCurve(anim_curve) # Animation sequence self._animation = qc.QSequentialAnimationGroup() if value: self.main_widget_proxy.setOpacity(0) self._animation.addAnimation(size_animation) self._animation.addAnimation(opacity_anim) self._animation.finished.connect(self._animation.clear) else: self.main_widget_proxy.setOpacity(1) self._animation.addAnimation(opacity_anim) self._animation.addAnimation(size_animation) self._animation.finished.connect(self._animation.clear) self._animation.finished.connect(self.delete_widget) size_animation.valueChanged.connect(self._force_resize) self._animation.start(qc.QAbstractAnimation.DeleteWhenStopped)
def _animateExpand(self, value): opacity_anim = qc.QPropertyAnimation(self.main_widget_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(self, "geometry") geometry = self.geometry() width = geometry.width() x, y, _, _ = geometry.getCoords() size_start = qc.QRect(x, y, width, int(not(value)) * 150) size_end = qc.QRect(x, y, width, value * 150) size_anim.setStartValue(size_start) size_anim.setEndValue(size_end) size_anim.setDuration(300) size_anim_curve = qc.QEasingCurve() if value: size_anim_curve.setType(qc.QEasingCurve.InQuad) else: size_anim_curve.setType(qc.QEasingCurve.OutQuad) size_anim.setEasingCurve(size_anim_curve) self._animation = qc.QSequentialAnimationGroup() if value: self.main_widget_proxy.setOpacity(0) self._animation.addAnimation(size_anim) self._animation.addAnimation(opacity_anim) else: self.main_widget_proxy.setOpacity(1) 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: self._animation.finished.connect(self.deleteWidget) self._animation.start(qc.QAbstractAnimation.DeleteWhenStopped)
def uiAddWidgetSizeAnim(widget, onoff, size, size_offset=0): size_anim = None try: print widget size_anim = QtCore.QPropertyAnimation(widget, 'geometry') except: pm.warning('Failed to create QPropertyAnimation ') geometry = widget.geometry() width = geometry.width() x, y, _, _ = geometry.getCoords() size_start = QtCore.QRect(x, y, width, int(not (onoff)) * size + size_offset) size_end = QtCore.QRect(x, y, width, onoff * size + size_offset) size_anim.setStartValue(size_start) size_anim.setEndValue(size_end) 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) size_anim.setEasingCurve(size_anim_curve) return size_anim
def __init__(self, parent=None): super(QtGui.QWidget, self).__init__(parent) self.m_iconSize = QtCore.QSize(64, 64) self.m_scene = QtGui.QGraphicsScene() self.m_ui = Ui_Form() self.m_ui.setupUi(self) self.m_ui.easingCurvePicker.setIconSize(self.m_iconSize) self.m_ui.easingCurvePicker.setMinimumHeight(self.m_iconSize.height() + 50) self.m_ui.buttonGroup.setId(self.m_ui.lineRadio, 0) self.m_ui.buttonGroup.setId(self.m_ui.circleRadio, 1) dummy = QtCore.QEasingCurve() self.m_ui.periodSpinBox.setValue(dummy.period()) self.m_ui.amplitudeSpinBox.setValue(dummy.amplitude()) self.m_ui.overshootSpinBox.setValue(dummy.overshoot()) self.m_ui.easingCurvePicker.currentRowChanged.connect( self.curveChanged) self.m_ui.buttonGroup.buttonClicked[int].connect(self.pathChanged) self.m_ui.periodSpinBox.valueChanged.connect(self.periodChanged) self.m_ui.amplitudeSpinBox.valueChanged.connect(self.amplitudeChanged) self.m_ui.overshootSpinBox.valueChanged.connect(self.overshootChanged) self.createCurveIcons() pix = QtGui.QPixmap(':/images/qt-logo.png') self.m_item = PixmapItem(pix) self.m_scene.addItem(self.m_item.pixmap_item) self.m_ui.graphicsView.setScene(self.m_scene) self.m_anim = Animation(self.m_item, 'pos') self.m_anim.setEasingCurve(QtCore.QEasingCurve.OutBounce) self.m_ui.easingCurvePicker.setCurrentRow( int(QtCore.QEasingCurve.OutBounce)) self.startAnimation()
def createCurveIcons(self): pix = QtGui.QPixmap(self.m_iconSize) painter = QtGui.QPainter() gradient = QtGui.QLinearGradient(0, 0, 0, self.m_iconSize.height()) gradient.setColorAt(0.0, QtGui.QColor(240, 240, 240)) gradient.setColorAt(1.0, QtGui.QColor(224, 224, 224)) brush = QtGui.QBrush(gradient) # The original C++ code uses undocumented calls to get the names of the # different curve types. We do the Python equivalant (but without # cheating). curve_types = [(n, c) for n, c in QtCore.QEasingCurve.__dict__.items() if isinstance(c, QtCore.QEasingCurve.Type) and c != QtCore.QEasingCurve.Custom] curve_types.sort(key=lambda ct: ct[1]) painter.begin(pix) for curve_name, curve_type in curve_types: painter.fillRect( QtCore.QRect(QtCore.QPoint(0, 0), self.m_iconSize), brush) curve = QtCore.QEasingCurve(curve_type) painter.setPen(QtGui.QColor(0, 0, 255, 64)) xAxis = self.m_iconSize.height() / 1.5 yAxis = self.m_iconSize.width() / 3.0 painter.drawLine(0, xAxis, self.m_iconSize.width(), xAxis) painter.drawLine(yAxis, 0, yAxis, self.m_iconSize.height()) curveScale = self.m_iconSize.height() / 2.0 painter.setPen(QtCore.Qt.NoPen) # Start point. painter.setBrush(QtCore.Qt.red) start = QtCore.QPoint( yAxis, xAxis - curveScale * curve.valueForProgress(0)) painter.drawRect(start.x() - 1, start.y() - 1, 3, 3) # End point. painter.setBrush(QtCore.Qt.blue) end = QtCore.QPoint(yAxis + curveScale, xAxis - curveScale * curve.valueForProgress(1)) painter.drawRect(end.x() - 1, end.y() - 1, 3, 3) curvePath = QtGui.QPainterPath() curvePath.moveTo(QtCore.QPointF(start)) t = 0.0 while t <= 1.0: to = QtCore.QPointF( yAxis + curveScale * t, xAxis - curveScale * curve.valueForProgress(t)) curvePath.lineTo(to) t += 1.0 / curveScale painter.setRenderHint(QtGui.QPainter.Antialiasing, True) painter.strokePath(curvePath, QtGui.QColor(32, 32, 32)) painter.setRenderHint(QtGui.QPainter.Antialiasing, False) item = QtGui.QListWidgetItem() item.setIcon(QtGui.QIcon(pix)) item.setText(curve_name) self.m_ui.easingCurvePicker.addItem(item) painter.end()
def _animate(self, direction, move_direction, start, stop, duration, just_resize=False, dont_animate=False): # Stop all running animations for timeline in (self.__sceneX, self.__sceneY, self.__sceneF): timeline.stop() # Re-initialize Timelines self._initializeTimeLines() # Use given duration time or use the default one duration = duration if duration > 0 else self._duration # Set last used animations with given values self.__last_stop = stop self.__last_start = start self.__last_move_direction = move_direction self.__last_direction = direction # Set X coordinate timeline settings self.__sceneX.setDirection(move_direction) self.__sceneX.setEasingCurve(QtCore.QEasingCurve(self._animation)) self.__sceneX.setDuration(duration) self.__sceneX.setUpdateInterval(20) # Set Y coordinate timeline settings self.__sceneY.setDirection(move_direction) self.__sceneY.setEasingCurve(QtCore.QEasingCurve(self._animation)) self.__sceneY.setDuration(duration) self.__sceneY.setUpdateInterval(20) # Update duration for overlay fade effect self.__sceneF.setDuration(self.__overlay_duration) # Get current sizes p_width = self.__parent.width() p_height = self.__parent.height() width = self.width() height = self.height() # Calculate new positions for given points limits = { TOPLEFT: [0, 0], TOPCENTER: [p_width / 2 - width / 2, 0], TOPRIGHT: [p_width - width, 0], MIDLEFT: [0, p_height / 2 - height / 2], MIDCENTER: [p_width / 2 - width / 2, p_height / 2 - height / 2], MIDRIGHT: [p_width - width, p_height / 2 - height / 2], BOTLEFT: [0, p_height - height], BOTCENTER: [p_width / 2 - width / 2, p_height - height], BOTRIGHT: [p_width - width, p_height - height], CURRENT: [self.x(), self.y()] } # Get start and stop positions # I used deepcopy in case of selecting same positions for start and stop start_pos = copy.deepcopy(limits[start]) stop_pos = copy.deepcopy(limits[stop]) # Poor developer's debug mechanism. # print start_pos, stop_pos, width, height # Update start and stop positions for given direction if direction == IN: self.show() if start in (TOPLEFT, MIDLEFT, BOTLEFT): start_pos[0] -= width elif start in (TOPRIGHT, MIDRIGHT, BOTRIGHT): start_pos[0] += width elif start == TOPCENTER: start_pos[1] -= height elif start == BOTCENTER: start_pos[1] += height elif direction == OUT: if stop in (TOPLEFT, MIDLEFT, BOTLEFT): stop_pos[0] -= width elif stop in (TOPRIGHT, MIDRIGHT, BOTRIGHT): stop_pos[0] += width elif stop == TOPCENTER: stop_pos[1] -= height elif stop == BOTCENTER: stop_pos[1] += height # Move the widget to calculated start position self.move(start_pos[0], start_pos[1]) # Set calculated start and stop positions self.__sceneX.setFrameRange(start_pos[0], stop_pos[0]) self.__sceneX.frameChanged.connect(lambda x: self.move(x, self.y())) self.__sceneY.setFrameRange(start_pos[1], stop_pos[1]) self.__sceneY.frameChanged.connect(lambda y: self.move(self.x(), y)) # Run predefined callback functions for given direction self.runCallBacks(direction) self._disable_parent() # Hide widget when direction is OUT self.__sceneX.finished.connect( lambda: self.setHidden(direction == OUT)) # Run finish callbacks self.__sceneX.finished.connect(lambda: self.runCallBacks(FINISHED)) # Show/hide overlay if overlay enabled if self.__overlay_enabled: self.__overlay.show() self.__sceneX.finished.connect( lambda: self.__overlay.setHidden(direction == OUT)) else: self.__overlay.hide() if dont_animate: self.__overlay.setHidden(direction == OUT) self.setHidden(direction == OUT) self.runCallBacks(FINISHED) else: # Start the animation ! if self.__sceneX.state() == QtCore.QTimeLine.NotRunning: self.__sceneX.start() self.__sceneY.start() if not just_resize: # The animation will just work for repositioning the widget, # so we dont need overlay fade animation self.__sceneF.start() # Return the X coordinate timeline obj to use as reference for next animation return self.__sceneX
def easing_curve_fn(easing_curve_type): easing_curve = QtCore.QEasingCurve(easing_curve_type) def ease(i): return easing_curve.valueForProgress(i) return ease
break return rgb(r, g, b) class DisplayBase(QtCore.QObject): def __init__(self): super(DisplayBase, self).__init__() def identity(x): return x EASING_FN = [ np.vectorize(QtCore.QEasingCurve(i).valueForProgress, doc = 'QEasingCurve({})'.format(i), otypes=[np.float32]) for i in range(0, 41) ] def choice_fn(options): weights, choices = zip(*options) sum_weights = sum(weights) probabilities = [ w / sum_weights for w in weights ] #print('choice_fn', choices, probabilities) def choose(): return np.random.choice(choices, p=probabilities) return choose