Exemplo n.º 1
1
    def addMovementAnimation(self, animGroup):
#        print(">>MoveAnim")
        for phIdx in self.photoIdxsToMove:
            item = self.photosInGrid[phIdx]
            anim = QPropertyAnimation(item.pixmap, "pos")
            anim.setDuration(self.moveDuration - item.gridCol * self.moveModifier)
            anim.setEasingCurve(QEasingCurve.Linear)
            startCoords = self.getCellTLCoords(item.gridRow, item.gridCol)
            endCoords = self.getCellTLCoords(item.gridRow, item.gridCol + self.columnMovementDist)
            anim.setStartValue(startCoords)
            anim.setEndValue(endCoords)
            animGroup.addAnimation(anim)
Exemplo n.º 2
0
    def start(self):
        height = self.height()
        width = self.width()
        for i in range(self._ball_numbers):
            self._seq_animations.append(QSequentialAnimationGroup(self))
            # 增加间隔
            self._seq_animations[i].addPause(self.duration_pause * i)
            # 第一段
            par_animation1 = QParallelAnimationGroup(self)
            ra = RoundAnimation(self._balls[i], b'pos', self)
            ra.setEasingCurve(self.ec)
            ra.setDuration(self.duration)
            ra.setStartValue(QPoint(2 * self.ball_radius, 2 * self.ball_radius))
            ra.setEndValue(QPoint(width - 2 * self.ball_radius, height - 2 * self.ball_radius))
            par_animation1.addAnimation(ra)
            pa = QPropertyAnimation(self._balls[i], b'_style', self)
            pa.setEasingCurve(self.ec)
            pa.setDuration(self.duration)
            pa.setStartValue(0)
            pa.setKeyValueAt(0.5, 255)
            pa.setEndValue(0)
            par_animation1.addAnimation(pa)
            self._seq_animations[i].addAnimation(par_animation1)
            # 增加间隔
            self._seq_animations[i].addPause(self.duration_pause * (self._ball_numbers - i - 1))

        for seq in self._seq_animations:
            seq.setLoopCount(-1)
            seq.start(QAbstractAnimation.DeleteWhenStopped)
Exemplo n.º 3
0
 def goBack(self):
     back = QPropertyAnimation(
         self, bytes("pos", 'utf-8'),
         self)  # 这边最后一个parent必须指定,或者将back定义为成员变量,否则动画无法生效(猜测直接被销毁了)
     back.setEndValue(self.home_pos)
     back.setEasingCurve(QEasingCurve.OutBounce)
     back.start(QAbstractAnimation.DeleteWhenStopped)
Exemplo n.º 4
0
class MoveSymbol(QUndoCommand):
    ''' Undo/Redo command for moving symbols '''
    def __init__(self, symbol_id, old_pos, new_pos, animate=False):
        super(MoveSymbol, self).__init__()
        self.setText('Move symbol')
        self.symbol = symbol_id
        self.old_pos = old_pos
        self.new_pos = new_pos
        if animate:
            self.animation = QPropertyAnimation(self.symbol, "position")
            self.animation.setDuration(500)
            self.animation.setStartValue(self.old_pos)
            self.animation.setEndValue(self.new_pos)
            self.animation.setEasingCurve(QEasingCurve.OutCirc)

    def undo(self):
        ''' Undo a symbol move '''
        self.symbol.position = self.old_pos
        try:
            self.symbol.decisionParent.updateConnectionPointPosition()
        except AttributeError:
            pass

    def redo(self):
        ''' Apply a symbol move '''
        try:
            self.animation.start()
        except AttributeError:
            self.symbol.position = self.new_pos
        try:
            self.symbol.decisionParent.updateConnectionPointPosition()
        except AttributeError:
            pass
Exemplo n.º 5
0
def load_animation2(window: object,
                    property_name: bytes = b'windowOpacity') -> None:
    animation = QPropertyAnimation()
    animation.setTargetObject(window)  # 设置动画目标对象

    # 设置动画属性
    # 注意:字节类型
    # pos---位置动画---QPoint
    # size---大小动画---QSize
    # geometry----位置+大小动画----QRect
    # windowOpacity---窗口的透明度(0.0是透明的    1.0是不透明)---好像只适合顶层窗口
    animation.setPropertyName(property_name)

    # animation.setStartValue(QPoint(0, 0))  # 设置开始位置---按钮的左上角位置
    # animation.setEndValue(QPoint(300, 300))  # 设置结束位置
    # animation.setStartValue(QSize(0, 0))  # 设置开始大小
    # animation.setEndValue(QSize(300, 300))  # 设置结束大小
    # animation.setStartValue(QRect(0, 0,100,100))  # 设置开始位置和大小
    # animation.setEndValue(QRect(100,100,300, 300))  # 设置结束位置和大小

    # 参数1 0.0到1.0  0.0表示开始点,1.0表示结束点
    # 在动画的中间插入透明度0.2
    animation.setStartValue(0.2)  # 设置开始不透明
    animation.setKeyValueAt(0.2, 0.4)  # 在动画的某时间点插入一个值
    animation.setKeyValueAt(0.4, 0.6)
    animation.setKeyValueAt(1, 1)  # 在动画的结束点是不透明的
    # 0透明, 1不透明
    # animation.setEndValue(1)  # 设置结束透明度
    animation.setEndValue(TRANSPARENT)  # 设置结束透明度

    animation.setDirection(3000)  # 设置动画单次时长---单位毫秒

    animation.setEasingCurve(QEasingCurve.InQuad)  # 设置动画的节奏
    animation.start()  # 动画开始---非阻塞
Exemplo n.º 6
0
def bobble(pix):
    node = Node(pix)
    pos = node.pix.pos()
    node.pix.setOriginPt()

    sync = random.randint(4, 9) * 400
    up = random.randint(5, 12)
    left = random.randint(5, 9)

    if random.randint(0, 1): up = up * -1
    if random.randint(0, 1): left = left * -1

    bobble = QPropertyAnimation(node, b'pos')
    bobble.setDuration(sync)

    bobble.setStartValue(pos)
    bobble.setKeyValueAt(0.25, pos + QPointF(-left, -up * 1.75))
    bobble.setKeyValueAt(0.35, pos + QPointF(-left * 1.35, 0))
    bobble.setKeyValueAt(0.45, pos + QPointF(0, up * 1.65))
    bobble.setKeyValueAt(0.55, pos + QPointF(left * 1.35, 0))
    bobble.setKeyValueAt(0.65, pos + QPointF(left, -up * 1.75))
    bobble.setEndValue(pos)

    bobble.setLoopCount(-1)
    bobble.setEasingCurve(QEasingCurve.InOutCubic)

    return bobble
Exemplo n.º 7
0
class DummyButton(QPushButton):
    def __init__(self, value, max, parent=None):
        super().__init__(str(value), parent)
        self.setFont(QFont("Consolas", 16, 3))
        self.setFixedSize(100, 50)
        self.done = False
        self.index = value
        self.max = max
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)
        self.fade_anim = QPropertyAnimation(self.effect, b"opacity")
        self.effect.setOpacity(1)
        self.fade_anim.setDuration(150)
        self.fade_anim.setStartValue(0)
        self.fade_anim.setEndValue(1)
        self.fade_anim.setEasingCurve(QEasingCurve.InQuad)
        self.fade_anim.finished.connect(self.finish)

    def finish(self):
        self.done = True

    def moveEvent(self, event):
        super().moveEvent(event)
        if self.pos().y() < 110 + self.max * 50 and not self.done:
            self.fade_anim.start()
Exemplo n.º 8
0
class MoreActionsMenu(AeroMenu):
    """ 更多操作圆角菜单,actionFlag用来指示动作的类型,actionFlag=1有四个动作,actionFlag=0有三个动作 """

    def __init__(self, parent=None, actionFlag=1):
        super().__init__(parent=parent)
        self.actionFlag = actionFlag
        # 创建动作和动画
        self.createActions()
        self.animation = QPropertyAnimation(self, b"geometry")
        # 初始化界面
        self.initWidget()

    def initWidget(self):
        """ 初始化小部件 """
        self.setObjectName("moreActionsMenu")
        self.animation.setDuration(300)
        self.animation.setEasingCurve(QEasingCurve.OutQuad)

    def createActions(self):
        """ 创建动作"""
        self.savePlayListAct = QAction(
            QIcon("app\\resource\\images\\menu\\保存为播放列表.png"), "保存为播放列表", self
        )
        self.clearPlayListAct = QAction(
            QIcon("app\\resource\\images\\menu\\清空正在播放_16_16.png"), '清空"正在播放"', self
        )
        if self.actionFlag:
            self.showPlayListAct = QAction(
                QIcon("app\\resource\\images\\menu\\显示正在播放列表.png"), "显示正在播放列表", self
            )
            self.fillScreenAct = QAction(
                QIcon("app\\resource\\images\\menu\\转到全屏.png"), "转到全屏", self
            )
            self.action_list = [
                self.showPlayListAct,
                self.fillScreenAct,
                self.savePlayListAct,
                self.clearPlayListAct,
            ]
            self.actionNum = 4
        else:
            self.showSongerCover = QAction("显示歌手封面", self)
            self.action_list = [
                self.savePlayListAct,
                self.showSongerCover,
                self.clearPlayListAct,
            ]
            self.actionNum = 3
        self.addActions(self.action_list)

    def exec(self, pos):
        """ 重写exec_() """
        height = self.actionNum * 38
        width = [188, 206][self.actionFlag]
        self.animation.setStartValue(QRect(pos.x(), pos.y(), 1, height))
        self.animation.setEndValue(QRect(pos.x(), pos.y(), width, height))
        # 开始动画
        self.animation.start()
        super().exec(pos)
Exemplo n.º 9
0
 def slide_in_animation(self):
     self.on_display = True
     ani_in = QPropertyAnimation(self, b'pos', self)
     ani_in.setDuration(self.ani_duration)
     ani_in.setStartValue(QPoint(self.x, self.y + self.h))
     ani_in.setEndValue(QPoint(self.x, self.y + self.margin_bottom))
     ani_in.setEasingCurve(QEasingCurve.InOutQuad)
     ani_in.start()
Exemplo n.º 10
0
class NavigationMenu(NavigationWidget):
    """ 导航菜单 """

    def __init__(self, parent=None):
        super().__init__(parent)
        # 是否削减设置按钮底部空白标志位
        self.__isShowBottomSpacing = False
        self.__ani = QPropertyAnimation(self, b"geometry")
        # 才叫你窗口效果
        self.windowEffect = WindowEffect()
        self.__initWidget()

    def __initWidget(self):
        """ 初始化小部件 """
        self.resize(60, 800)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setWindowFlags(Qt.NoDropShadowWindowHint | Qt.Popup)
        # self.hWnd = HWND(int(self.winId()))
        self.windowEffect.setAcrylicEffect(self.winId(), "F2F2F299", False)

    def resizeEvent(self, e):
        """ 调整小部件尺寸 """
        super().resizeEvent(e)
        self.settingButton.move(
            0, self.height() - 62 - 10 - self.__isShowBottomSpacing * 115
        )
        self.searchLineEdit.resize(self.width() - 30, self.searchLineEdit.height())

    def aniShow(self):
        """ 动画显示 """
        super().show()
        self.__ani.setStartValue(QRect(self.x(), self.y(), 60, self.height()))
        self.__ani.setEndValue(QRect(self.x(), self.y(), 400, self.height()))
        self.__ani.setDuration(85)
        self.__ani.start()
        self.__ani.setEasingCurve(QEasingCurve.InOutQuad)

    def aniHide(self):
        """ 动画隐藏 """
        self.__ani.setStartValue(QRect(self.x(), self.y(), 400, self.height()))
        self.__ani.setEndValue(QRect(self.x(), self.y(), 60, self.height()))
        self.__ani.finished.connect(self.__hideAniFinishedSlot)
        self.__ani.setDuration(85)
        self.__ani.start()

    def __hideAniFinishedSlot(self):
        """ 隐藏窗体的动画结束 """
        super().hide()
        self.resize(60, self.height())
        self.__ani.disconnect()

    def setBottomSpacingVisible(self, isBottomSpacingVisible: bool):
        """ 是否削减设置按钮底部空白 """
        self.__isShowBottomSpacing = isBottomSpacingVisible

    @property
    def isShowBottomSpacing(self):
        return self.__isShowBottomSpacing
Exemplo n.º 11
0
    def slideInWidget(self, widget, direction=Automatic):
        if self.indexOf(widget) == -1 or widget is self.currentWidget():
            return

        if self._active:
            return

        self._active = True

        prev_widget = self.currentWidget()
        next_widget = widget

        if direction == self.Automatic:
            if self.indexOf(prev_widget) < self.indexOf(next_widget):
                direction = self.BottomToTop if self.verticalMode else self.RightToLeft
            else:
                direction = self.TopToBottom if self.verticalMode else self.LeftToRight

        width = self.frameRect().width()
        height = self.frameRect().height()

        # the following is important, to ensure that the new widget has correct geometry information when sliding in the first time
        next_widget.setGeometry(0, 0, width, height)

        if direction in (self.TopToBottom, self.BottomToTop):
            offset = QPoint(
                0, height if direction == self.TopToBottom else -height)
        elif direction in (self.LeftToRight, self.RightToLeft):
            offset = QPoint(width if direction == self.LeftToRight else -width,
                            0)

        # re-position the next widget outside of the display area
        prev_widget_position = prev_widget.pos()
        next_widget_position = next_widget.pos()

        next_widget.move(next_widget_position - offset)
        next_widget.show()
        next_widget.raise_()

        prev_widget_animation = QPropertyAnimation(prev_widget, "pos")
        prev_widget_animation.setDuration(self.animationDuration)
        prev_widget_animation.setEasingCurve(
            QEasingCurve(self.animationEasingCurve))
        prev_widget_animation.setStartValue(prev_widget_position)
        prev_widget_animation.setEndValue(prev_widget_position + offset)

        next_widget_animation = QPropertyAnimation(next_widget, "pos")
        next_widget_animation.setDuration(self.animationDuration)
        next_widget_animation.setEasingCurve(
            QEasingCurve(self.animationEasingCurve))
        next_widget_animation.setStartValue(next_widget_position - offset)
        next_widget_animation.setEndValue(next_widget_position)

        self._animation_group.clear()
        self._animation_group.addAnimation(prev_widget_animation)
        self._animation_group.addAnimation(next_widget_animation)
        self._animation_group.start()
Exemplo n.º 12
0
 def shake_screen(self) -> None:
     a = QPropertyAnimation(self._stack, b'pos')
     a.setEasingCurve(QEasingCurve.InOutSine)
     a.setDuration(500)
     for step, offset in enumerate([0, 1, -2, 2, -1, 0]):
         a.setKeyValueAt(step * 0.2,
                         self._stack.pos() + QPoint(offset * 40, 0))
     a.start(QPropertyAnimation.DeleteWhenStopped)
     self._shakeanim = a
Exemplo n.º 13
0
class SwitchPrivate(QObject):
    def __init__(self, q, parent=None, isOn=False):
        self.isOn = isOn
        QObject.__init__(self, parent=parent)
        self.mPointer = q
        if self.isOn:
            self.mPosition = 1.0
        else:
            self.mPosition = 0.0

        self.mGradient = QLinearGradient()
        self.mGradient.setSpread(QGradient.PadSpread)

        self.animation = QPropertyAnimation(self)
        self.animation.setTargetObject(self)
        self.animation.setPropertyName(b'position')
        self.animation.setStartValue(0.0)
        self.animation.setEndValue(1.0)
        self.animation.setDuration(200)
        self.animation.setEasingCurve(QEasingCurve.InOutExpo)

        self.animation.finished.connect(self.mPointer.update)

    @pyqtProperty(float)
    def position(self):
        return self.mPosition

    @position.setter
    def position(self, value):
        self.mPosition = value
        self.mPointer.update()

    def draw(self, painter):
        r = self.mPointer.rect()
        margin = r.height() / 10

        painter.setPen(Qt.NoPen)

        self.background_color = QColor(118, 118, 118)
        painter.setBrush(self.background_color)
        painter.drawRoundedRect(r, r.height() / 2, r.height() / 2)

        self.mGradient = QColor(35, 35, 35)

        painter.setBrush(self.mGradient)

        x = r.height() / 2.0 + self.mPosition * (r.width() - r.height())
        painter.drawEllipse(QPointF(x,
                                    r.height() / 2),
                            r.height() / 2 - margin,
                            r.height() / 2 - margin)

    @pyqtSlot(bool, name='animate')
    def animate(self, checked):
        self.animation.setDirection(QPropertyAnimation.Forward if checked else
                                    QPropertyAnimation.Backward)
        self.animation.start()
Exemplo n.º 14
0
def splash_open_init(pane):
    animation = QPropertyAnimation(pane)
    animation.setTargetObject(pane)
    animation.setPropertyName(b"pos")
    animation.setStartValue(pane.pos())
    animation.setEndValue(QPoint(0, 0))
    animation.setEasingCurve(QEasingCurve.OutBounce)
    animation.setDuration(500)
    animation.start(QAbstractAnimation.DeleteWhenStopped)
Exemplo n.º 15
0
class MoreActionsMenu(QMenu):
    """ 更多操作菜单 """
    def __init__(self, parent=None):
        super().__init__(parent)
        # 添加动画
        self.animation = QPropertyAnimation(self, b"geometry")
        # 创建窗口效果实例
        self.windowEffect = WindowEffect()
        self.__initWidget()

    def __initWidget(self):
        """ 初始化小部件 """
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Popup
                            | Qt.NoDropShadowWindowHint)
        self.setObjectName("albumInterfaceMoreActionMenu")
        self.animation.setDuration(300)
        self.animation.setEasingCurve(QEasingCurve.OutQuad)
        # 设置层叠样式
        self.__setQss()

    def event(self, e: QEvent):
        if e.type() == QEvent.WinIdChange:
            # self.hWnd = HWND(int(self.winId()))
            self.windowEffect.addShadowEffect(self.winId())
        return QMenu.event(self, e)

    def __setQss(self):
        """ 设置层叠样式 """
        with open("app\\resource\\css\\menu.qss", encoding="utf-8") as f:
            self.setStyleSheet(f.read())

    def setActionNum(self, actionNum):
        """ 设置动作的个数 """
        self.clear()
        self.actionNum = actionNum
        self.action_list = []
        self.deleteAct = QAction("删除", self)
        self.action_list.append(self.deleteAct)
        if actionNum >= 2:
            self.editInfoAct = QAction("编辑信息", self)
            self.action_list.append(self.editInfoAct)
            if actionNum == 3:
                self.pinToStartMenuAct = QAction('固定到"开始"菜单', self)
                self.action_list.append(self.pinToStartMenuAct)
        self.addActions(self.action_list[::-1])
        self.currentWidth = [120, 120, 168][self.actionNum - 1]
        self.currentHeight = self.actionNum * 38 + 10

    def exec(self, pos):
        """ 显示菜单 """
        self.animation.setStartValue(
            QRect(pos.x(), pos.y(), 1, self.currentHeight))
        self.animation.setEndValue(
            QRect(pos.x(), pos.y(), self.currentWidth, self.currentHeight))
        # 开始动画
        self.animation.start()
        super().exec(pos)
Exemplo n.º 16
0
def splash_exit_init(pane, pane1):
    animation = QPropertyAnimation(pane)
    animation.setTargetObject(pane)
    animation.setPropertyName(b"pos")
    animation.setEndValue(QPoint(0, pane1.width()))
    animation.setStartValue(QPoint(0, 0))
    animation.setEasingCurve(QEasingCurve.InBounce)
    animation.setDuration(500)
    animation.start(QAbstractAnimation.DeleteWhenStopped)
Exemplo n.º 17
0
 def zoom2(self):
     animation = QPropertyAnimation(self, b"geometry", parent=self.parent())
     animation.setDuration(200)
     animation.setStartValue(
         QRect(self.x(),
               self.y() + 10, self.width(), self.height()))
     animation.setEndValue(
         QRect(self.x(), self.y(), self.width(), self.height()))
     animation.setEasingCurve(QEasingCurve.OutBounce)
     animation.start()
Exemplo n.º 18
0
 def fadeOut(self):
     g = QGraphicsOpacityEffect(self)
     self.errorWidget.setGraphicsEffect(g)
     a = QPropertyAnimation(g, self.animationProp, self)
     a.setDuration(350)
     a.setStartValue(1)
     a.setEndValue(0)
     a.setEasingCurve(QEasingCurve.OutBack)
     a.finished.connect(lambda: self.errorWidget.setVisible(False))
     a.start(QPropertyAnimation.DeleteWhenStopped)
Exemplo n.º 19
0
class AngleButton(QPushButton):
    pressed = pyqtSignal(int)

    def __init__(self, value, parent=None):
        super().__init__(str(value), parent)
        self.setFont(QFont("Consolas", 16, 3))
        self.setFixedSize(100, 50)
        self.index = value
        self.activated = False
        self.clicked.connect(lambda: self.pressed.emit(self.index))
        self.activate(False)
        self.setup_fade()

    def moveEvent(self, event):
        super().moveEvent(event)
        if self.pos().y() < 55 and not self.faded:
            self.faded = True
            self.fade_anim.start()

    def activate(self, active):
        if active:
            self.setStyleSheet("""
                AngleButton {background-color: lime}
                AngleButton:pressed {
                    background-color: cyan
                }
            """)
            self.activated = True
        else:
            self.setStyleSheet("""
                AngleButton {background-color: none}
                AngleButton:pressed {
                    background-color: cyan
                }
            """)
            self.activated = False

    def disable(self, state):
        if state:
            self.setEnabled(False)
        else:
            self.setEnabled(True)
            self.activate(self.activated)
            self.setup_fade()

    def setup_fade(self):
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)
        self.effect.setOpacity(1)
        self.fade_anim = QPropertyAnimation(self.effect, b"opacity")
        self.fade_anim.setDuration(80)
        self.fade_anim.setStartValue(1)
        self.fade_anim.setEndValue(0)
        self.fade_anim.setEasingCurve(QEasingCurve.OutQuad)
        self.faded = False
Exemplo n.º 20
0
 def __setAnimation(self,
                    ani: QPropertyAnimation,
                    startValue,
                    endValue,
                    duration,
                    easingCurve=QEasingCurve.Linear):
     """ 初始化动画 """
     ani.setEasingCurve(easingCurve)
     ani.setStartValue(startValue)
     ani.setEndValue(endValue)
     ani.setDuration(duration)
Exemplo n.º 21
0
 def fadeIn(self):
     g = QGraphicsOpacityEffect(self)
     self.errorWidget.setGraphicsEffect(g)
     a = QPropertyAnimation(g, self.animationProp, self)
     a.setDuration(350)
     a.setStartValue(0)
     a.setEndValue(1)
     a.setEasingCurve(QEasingCurve.InBack)
     #a.valueChanged.connect(lambda:self.errorWidget.show())
     self.errorWidget.show()
     a.start()
Exemplo n.º 22
0
 def showEvent(self, e):
     """ 淡入 """
     opacityEffect = QGraphicsOpacityEffect(self)
     self.setGraphicsEffect(opacityEffect)
     opacityAni = QPropertyAnimation(opacityEffect, b'opacity', self)
     opacityAni.setStartValue(0)
     opacityAni.setEndValue(1)
     opacityAni.setDuration(200)
     opacityAni.setEasingCurve(QEasingCurve.InSine)
     opacityAni.finished.connect(opacityEffect.deleteLater)
     opacityAni.start()
     super().showEvent(e)
Exemplo n.º 23
0
class ChessBoardMenu(QMenu):
    """ 棋盘右击菜单 """
    def __init__(self, parent):
        super().__init__('', parent)
        self.windowEffect = WindowEffect()
        self.animation = QPropertyAnimation(self, b'geometry')
        # 创建动作
        self.restartGameAct = QAction(
            Icon(':/images/chess_board_interface/重新开始.png'),
            self.tr('Restart'), self)
        self.settingAct = QAction(
            Icon(':/images/chess_board_interface/设置.png'), self.tr('Settings'),
            self)
        self.action_list = [self.restartGameAct, self.settingAct]
        self.addActions(self.action_list)
        self.__initWidget()

    def __initWidget(self):
        """ 初始化小部件 """
        self.animation.setDuration(300)
        self.animation.setEasingCurve(QEasingCurve.OutQuad)
        self.setWindowFlags(self.windowFlags() | Qt.NoDropShadowWindowHint)
        self.windowEffect.addShadowEffect(self.winId())
        self.__setQss()

    def event(self, e: QEvent):
        if e.type() == QEvent.WinIdChange:
            self.windowEffect.addShadowEffect(self.winId())
        return QMenu.event(self, e)

    def exec_(self, pos):
        w = max(self.fontMetrics().width(i.text())
                for i in self.actions()) + 70
        actionNum = len(self.action_list)

        # 每个item的高度为38px,10为上下的内边距和
        h = actionNum * 38 + 10

        # 设置动画
        self.animation.setStartValue(QRect(pos.x(), pos.y(), 1, h))
        self.animation.setEndValue(QRect(pos.x(), pos.y(), w, h))
        self.setStyle(QApplication.style())

        # 开始动画
        self.animation.start()
        super().exec_(pos)

    def __setQss(self):
        """ 设置层叠样式 """
        f = QFile(':/qss/menu.qss')
        f.open(QFile.ReadOnly)
        self.setStyleSheet(str(f.readAll(), encoding='utf-8'))
        f.close()
Exemplo n.º 24
0
class SidemenuView(object):
    def __init__(self, layout):
        self.widget_side_menu = QtWidgets.QWidget()
        layout.addWidget(self.widget_side_menu)
        self.setupUi(self.widget_side_menu)

    def setupUi(self, widget_side_menu):
        widget_side_menu.setObjectName("widget_side_menu")
        widget_side_menu.resize(94, 791)
        self.horizontalLayout = QtWidgets.QHBoxLayout(widget_side_menu)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.frame_side_menu = QtWidgets.QFrame(widget_side_menu)
        self.frame_side_menu.setMinimumSize(QtCore.QSize(70, 0))
        self.frame_side_menu.setMaximumSize(QtCore.QSize(70, 16777215))
        self.frame_side_menu.setAutoFillBackground(False)
        self.frame_side_menu.setStyleSheet(
            "background-color: rgb(80, 74, 64);")
        self.frame_side_menu.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.frame_side_menu.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_side_menu.setLineWidth(1)
        self.frame_side_menu.setObjectName("frame_side_menu")
        self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.frame_side_menu)
        self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_4.setSpacing(0)
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        self.horizontalLayout.addWidget(self.frame_side_menu)

        self.retranslateUi(widget_side_menu)
        QtCore.QMetaObject.connectSlotsByName(widget_side_menu)

    def retranslateUi(self, widget_side_menu):
        _translate = QtCore.QCoreApplication.translate
        widget_side_menu.setWindowTitle(_translate("widget_side_menu", "Form"))

    def extend(self, button_names):
        self.change_width(200)
        #ToDo enable fields with ButtonNames and show them next to the Button in an extra function

    def minimize(self):
        self.change_width(70)
        #ToDo hide visibility of ButtonNames in an extra function

    def change_width(self, end_width):
        width = self.frame_side_menu.width()
        self.animation = QPropertyAnimation(self.frame_side_menu,
                                            b"minimumWidth")
        self.animation.setDuration(300)
        self.animation.setStartValue(width)
        self.animation.setEndValue(end_width)
        self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart)
        self.animation.start()
Exemplo n.º 25
0
 def slide_in_animation(self):
     # pre-actions
     self.on_display = True
     self.search_line.slide_in_actions()
     self.search_body.slide_in_actions()
     # animations
     slide_in = QPropertyAnimation(self, b'pos', self)
     slide_in.setDuration(self.slide_duration)
     slide_in.setStartValue(QPoint(self.x, -self.h))
     slide_in.setEndValue(QPoint(self.x, self.y))
     slide_in.setEasingCurve(QEasingCurve.OutBounce)
     slide_in.start()
Exemplo n.º 26
0
 def move_to_pos(self, x: float, y: float):
     # move node to one pos with animation.
     # call by organize thread in athreads.
     move = QPropertyAnimation(self.pos_manager, b'pos', self.pos_manager)
     move.setDuration(600)
     move.setStartValue(self.pos())
     move.setEndValue(QPointF(x, y))
     move.setEasingCurve(QEasingCurve.OutQuart)
     # also update the edges that connect with.
     move.valueChanged.connect(self.node.update_connect_edges)
     move.start()
     self.is_modified()
Exemplo n.º 27
0
class CircleObstruction(QColorThemedGraphicsObject):
    """
    Useful for notifications, I...guess?
    """
    def get_thickness(self):
        return self._thickness

    def set_thickness(self, c):
        self._thickness = c
        self.update()

    thickness = pyqtProperty(float, get_thickness, set_thickness)

    def __init__(self, sz, thickness, parent=None):
        super(CircleObstruction, self).__init__(parent)
        self._sz = sz
        self._thickness = thickness
        self._color = Qt.blue

    def boundingRect(self):
        return QRectF(-self._thickness, -self._thickness,
                      self._sz + 2 * self._thickness,
                      self._sz + 2 * self._thickness)

    def paint(self, painter, option, widget):
        # painter.setPen(QPen(self._color,
        #                     self._thickness))
        painter.setBrush(self._color)
        painter.setPen(Qt.NoPen)
        painter.drawEllipse(
            QRectF(
                self._sz / 2.0 - self._thickness,
                self._sz / 2.0 - self._thickness,
                2 * self._thickness,
                2 * self._thickness,
            ))

    def show_anim(self):
        self.anim = QPropertyAnimation(self, "thickness")
        self.anim.setDuration(2000)
        self.anim.setStartValue(self.get_thickness())
        self.anim.setEndValue(50.0)
        self.anim.setEasingCurve(QEasingCurve.OutElastic)
        self.anim.start()

    def hide_anim(self):
        self.anim = QPropertyAnimation(self, "thickness")
        self.anim.setDuration(500)
        self.anim.setStartValue(self.get_thickness())
        self.anim.setEndValue(0.0)
        self.anim.setEasingCurve(QEasingCurve.InBack)
        self.anim.start()
Exemplo n.º 28
0
 def update_second(self):
     t = int(time.time())
     now = datetime.now()
     second = now.second
     self.year = now.year
     self.month = now.month
     self.day = now.day
     pa = QPropertyAnimation(self, b'_second', self)
     pa.setEasingCurve(QEasingCurve.OutBounce)
     pa.setDuration(1000)
     pa.setStartValue(QPoint(t, second * self.frequency))
     pa.setEndValue(QPoint(t, (second + 1) * self.frequency))
     pa.start()
Exemplo n.º 29
0
 def timerEvent(self, *args, **kwargs):
     self.currentTime += 1
     if self.currentTime >= self.timeout:
         self.timerMB.stop()
         self.timerMB.quit()
         a = QPropertyAnimation(self,
                                "windowOpacity".encode())  #also  b"opacity"
         a.setDuration(350)
         a.setStartValue(1)
         a.setEndValue(0)
         a.setEasingCurve(QEasingCurve.OutQuad)  #QEasingCurve::OutBack
         a.start()
         self.done(0)
Exemplo n.º 30
0
 def closeEvent(self, e):
     """ 淡出 """
     self.widget.setGraphicsEffect(None)
     opacityEffect = QGraphicsOpacityEffect(self)
     self.setGraphicsEffect(opacityEffect)
     opacityAni = QPropertyAnimation(opacityEffect, b'opacity', self)
     opacityAni.setStartValue(1)
     opacityAni.setEndValue(0)
     opacityAni.setDuration(100)
     opacityAni.setEasingCurve(QEasingCurve.OutCubic)
     opacityAni.finished.connect(self.deleteLater)
     opacityAni.start()
     e.ignore()
Exemplo n.º 31
0
 def slide_out_animation(self):
     # pre-actions
     self.on_display = False
     self.search_line.slide_out_actions()
     self.search_body.slide_out_actions()
     self.recover()
     # animation
     slide_out = QPropertyAnimation(self, b'pos', self)
     slide_out.setDuration(self.slide_duration)
     slide_out.setStartValue(QPoint(self.x, self.y))
     slide_out.setEndValue(QPoint(self.x, -self.h))
     slide_out.setEasingCurve(QEasingCurve.OutCubic)
     slide_out.start()
Exemplo n.º 32
0
    def __init__(self):
        super(Robot, self).__init__()

        self.setFlag(self.ItemHasNoContents)

        self.torsoItem = RobotTorso(self)
        self.headItem = RobotHead(self.torsoItem)
        self.upperLeftArmItem = RobotLimb(self.torsoItem)
        self.lowerLeftArmItem = RobotLimb(self.upperLeftArmItem)
        self.upperRightArmItem = RobotLimb(self.torsoItem)
        self.lowerRightArmItem = RobotLimb(self.upperRightArmItem)
        self.upperRightLegItem = RobotLimb(self.torsoItem)
        self.lowerRightLegItem = RobotLimb(self.upperRightLegItem)
        self.upperLeftLegItem = RobotLimb(self.torsoItem)
        self.lowerLeftLegItem = RobotLimb(self.upperLeftLegItem)

        settings = (
            #    Item                       Position        Rotation  Scale
            #                                x     y    start    end
            (self.headItem, 0, -18, 20, -20, 1.1),
            (self.upperLeftArmItem, -15, -10, 190, 180, 0),
            (self.lowerLeftArmItem, 30, 0, 50, 10, 0),
            (self.upperRightArmItem, 15, -10, 300, 310, 0),
            (self.lowerRightArmItem, 30, 0, 0, -70, 0),
            (self.upperRightLegItem, 10, 32, 40, 120, 0),
            (self.lowerRightLegItem, 30, 0, 10, 50, 0),
            (self.upperLeftLegItem, -10, 32, 150, 80, 0),
            (self.lowerLeftLegItem, 30, 0, 70, 10, 0),
            (self.torsoItem, 0, 0, 5, -20, 0),
        )

        animation = QParallelAnimationGroup(self)
        for item, pos_x, pos_y, start_rot, end_rot, scale in settings:
            item.setPos(pos_x, pos_y)

            rot_animation = QPropertyAnimation(item, b"rotation")
            rot_animation.setStartValue(start_rot)
            rot_animation.setEndValue(end_rot)
            rot_animation.setEasingCurve(QEasingCurve.SineCurve)
            rot_animation.setDuration(2000)
            animation.addAnimation(rot_animation)

            if scale > 0:
                scale_animation = QPropertyAnimation(item, b"scale")
                scale_animation.setEndValue(scale)
                scale_animation.setEasingCurve(QEasingCurve.SineCurve)
                scale_animation.setDuration(2000)
                animation.addAnimation(scale_animation)

        animation.setLoopCount(-1)
        animation.start()
Exemplo n.º 33
0
    def __init__(self):
        super(Robot, self).__init__()

        self.setFlag(self.ItemHasNoContents)

        self.torsoItem = RobotTorso(self)
        self.headItem = RobotHead(self.torsoItem)
        self.upperLeftArmItem = RobotLimb(self.torsoItem)
        self.lowerLeftArmItem = RobotLimb(self.upperLeftArmItem)
        self.upperRightArmItem = RobotLimb(self.torsoItem)
        self.lowerRightArmItem = RobotLimb(self.upperRightArmItem)
        self.upperRightLegItem = RobotLimb(self.torsoItem)
        self.lowerRightLegItem = RobotLimb(self.upperRightLegItem)
        self.upperLeftLegItem = RobotLimb(self.torsoItem)
        self.lowerLeftLegItem = RobotLimb(self.upperLeftLegItem)

        settings = (
            #    Item                       Position        Rotation  Scale
            #                                x     y    start    end
            (self.headItem, 0, -18, 20, -20, 1.1),
            (self.upperLeftArmItem, -15, -10, 190, 180, 0),
            (self.lowerLeftArmItem, 30, 0, 50, 10, 0),
            (self.upperRightArmItem, 15, -10, 300, 310, 0),
            (self.lowerRightArmItem, 30, 0, 0, -70, 0),
            (self.upperRightLegItem, 10, 32, 40, 120, 0),
            (self.lowerRightLegItem, 30, 0, 10, 50, 0),
            (self.upperLeftLegItem, -10, 32, 150, 80, 0),
            (self.lowerLeftLegItem, 30, 0, 70, 10, 0),
            (self.torsoItem, 0, 0, 5, -20, 0),
        )

        animation = QParallelAnimationGroup(self)
        for item, pos_x, pos_y, start_rot, end_rot, scale in settings:
            item.setPos(pos_x, pos_y)

            rot_animation = QPropertyAnimation(item, b"rotation")
            rot_animation.setStartValue(start_rot)
            rot_animation.setEndValue(end_rot)
            rot_animation.setEasingCurve(QEasingCurve.SineCurve)
            rot_animation.setDuration(2000)
            animation.addAnimation(rot_animation)

            if scale > 0:
                scale_animation = QPropertyAnimation(item, b"scale")
                scale_animation.setEndValue(scale)
                scale_animation.setEasingCurve(QEasingCurve.SineCurve)
                scale_animation.setDuration(2000)
                animation.addAnimation(scale_animation)

        animation.setLoopCount(-1)
        animation.start()
Exemplo n.º 34
0
class CircleObstruction(QColorThemedGraphicsObject):
    """
    Useful for notifications, I...guess?
    """
    def get_thickness(self):
        return self._thickness
    def set_thickness(self,c):
        self._thickness = c
        self.update()
    thickness = pyqtProperty(float, get_thickness, set_thickness)
    def __init__(self, sz, thickness, parent=None):
        super(CircleObstruction, self).__init__(parent)
        self._sz = sz
        self._thickness = thickness
        self._color = Qt.blue
    def boundingRect(self):
        return QRectF(-self._thickness,
                      -self._thickness,
                      self._sz + 2*self._thickness,
                      self._sz + 2*self._thickness)

    def paint(self, painter, option, widget):
        # painter.setPen(QPen(self._color,
        #                     self._thickness))
        painter.setBrush(self._color)
        painter.setPen(Qt.NoPen)
        painter.drawEllipse(QRectF(
            self._sz/2.0 - self._thickness,
            self._sz/2.0 - self._thickness,
            2*self._thickness,
            2*self._thickness,
        ))
    def show_anim(self):
        self.anim = QPropertyAnimation(self, "thickness")
        self.anim.setDuration(2000)
        self.anim.setStartValue(self.get_thickness())
        self.anim.setEndValue(50.0)
        self.anim.setEasingCurve(QEasingCurve.OutElastic)
        self.anim.start()
    def hide_anim(self):
        self.anim = QPropertyAnimation(self, "thickness")
        self.anim.setDuration(500)
        self.anim.setStartValue(self.get_thickness())
        self.anim.setEndValue(0.0)
        self.anim.setEasingCurve(QEasingCurve.InBack)
        self.anim.start()
Exemplo n.º 35
0
    def addRemovalAnimation(self, animGroup):
#        print(">>RemoveAnim")
        for phIdx in self.photoIdxsToRemove:
            item = self.photosInGrid[phIdx]
            anim = QPropertyAnimation(item.pixmap, "scale")
            anim.setDuration(self.shrinkDuration)
            anim.setEasingCurve(QEasingCurve.Linear)
            anim.setStartValue(1.0)
            anim.setEndValue(0.0)
            animGroup.addAnimation(anim)
            anim = QPropertyAnimation(item.pixmap, "pos")
            anim.setDuration(self.shrinkDuration)
            anim.setEasingCurve(QEasingCurve.Linear)
            startCoords = self.getCellTLCoords(item.gridRow, item.gridCol)
            endCoords = QPointF(startCoords.x()+self.cellSize.width()*item.xFactor, startCoords.y() + item.pixmap.pixmapSize.height() / 2)
            anim.setStartValue(startCoords)
            anim.setEndValue(endCoords)
            animGroup.addAnimation(anim)
Exemplo n.º 36
0
    def addInsertionAnimation(self, animGroup):
        # Animation for added
#        print(">>>InsAnim")
        for ph in self.picItemsToAdd:
            # Set pixmap start location
            newPixmap = ph[0].pixmap
            row = ph[1]
            col = ph[2]
            xFact = ph[0].xFactor
            endCoords = self.getCellTLCoords(row, col)
            startCoords = QPointF(endCoords.x()-self.cellSize.width()*xFact, endCoords.y())
            newPixmap.pixmap_item.setPos(startCoords)
            newPixmap.pixmap_item.setVisible(True)
            # Animate in
            anim = QPropertyAnimation(newPixmap, "pos")
            anim.setDuration(self.insertDuration)
            anim.setStartValue(startCoords)
            anim.setEasingCurve(QEasingCurve.Linear)
            anim.setEndValue(endCoords)
            animGroup.addAnimation(anim)
Exemplo n.º 37
0
class ScreensharingToolbox(base_class, ui_class):
    exposedPixels = 3

    def __init__(self, parent):
        super(ScreensharingToolbox, self).__init__(parent)
        with Resources.directory:
            self.setupUi()
        parent.installEventFilter(self)
        self.animation = QPropertyAnimation(self, 'pos')
        self.animation.setDuration(250)
        self.animation.setDirection(QPropertyAnimation.Forward)
        self.animation.setEasingCurve(QEasingCurve.Linear)  # or OutCirc with 300ms
        self.retract_timer = QTimer(self)
        self.retract_timer.setInterval(3000)
        self.retract_timer.setSingleShot(True)
        self.retract_timer.timeout.connect(self.retract)
        self.resize(self.size().expandedTo(self.toolbox_layout.minimumSize()))

    def setupUi(self):
        super(ScreensharingToolbox, self).setupUi(self)

        # fix the SVG icons, as the generated code loads them as pixmaps, losing their ability to scale -Dan
        scale_icon = QIcon()
        scale_icon.addFile(Resources.get('icons/scale.svg'), mode=QIcon.Normal, state=QIcon.Off)
        viewonly_icon = QIcon()
        viewonly_icon.addFile(Resources.get('icons/viewonly.svg'), mode=QIcon.Normal, state=QIcon.Off)
        screenshot_icon = QIcon()
        screenshot_icon.addFile(Resources.get('icons/screenshot.svg'), mode=QIcon.Normal, state=QIcon.Off)
        fullscreen_icon = QIcon()
        fullscreen_icon.addFile(Resources.get('icons/fullscreen.svg'), mode=QIcon.Normal, state=QIcon.Off)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Normal, state=QIcon.On)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Active, state=QIcon.On)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Disabled, state=QIcon.On)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Selected, state=QIcon.On)
        minimize_icon = QIcon()
        minimize_icon.addFile(Resources.get('icons/minimize.svg'), mode=QIcon.Normal, state=QIcon.Off)
        minimize_icon.addFile(Resources.get('icons/minimize-active.svg'), mode=QIcon.Active, state=QIcon.Off)
        close_icon = QIcon()
        close_icon.addFile(Resources.get('icons/close.svg'), mode=QIcon.Normal, state=QIcon.Off)
        close_icon.addFile(Resources.get('icons/close-active.svg'), mode=QIcon.Active, state=QIcon.Off)

        self.scale_action.setIcon(scale_icon)
        self.viewonly_action.setIcon(viewonly_icon)
        self.screenshot_action.setIcon(screenshot_icon)
        self.fullscreen_action.setIcon(fullscreen_icon)
        self.minimize_action.setIcon(minimize_icon)
        self.close_action.setIcon(close_icon)

        self.scale_button.setIcon(scale_icon)
        self.viewonly_button.setIcon(viewonly_icon)
        self.screenshot_button.setIcon(screenshot_icon)
        self.fullscreen_button.setIcon(fullscreen_icon)
        self.minimize_button.setIcon(minimize_icon)
        self.close_button.setIcon(close_icon)

        self.scale_button.setDefaultAction(self.scale_action)
        self.viewonly_button.setDefaultAction(self.viewonly_action)
        self.screenshot_button.setDefaultAction(self.screenshot_action)
        self.fullscreen_button.setDefaultAction(self.fullscreen_action)
        self.minimize_button.setDefaultAction(self.minimize_action)
        self.close_button.setDefaultAction(self.close_action)

        self.color_depth_button.clear()
        self.color_depth_button.addItem('Default Color Depth', ServerDefault)
        self.color_depth_button.addItem('TrueColor (24 bits)', TrueColor)
        self.color_depth_button.addItem('HighColor (16 bits)', HighColor)
        self.color_depth_button.addItem('LowColor (8 bits)', LowColor)

    def eventFilter(self, watched, event):
        if watched is self.parent() and event.type() == QEvent.Resize:
            new_x = (watched.width() - self.width()) / 2
            self.move(new_x, self.y())
            self.animation.setStartValue(QPoint(new_x, -self.height() + self.exposedPixels))
            self.animation.setEndValue(QPoint(new_x, 0))
        return False

    def enterEvent(self, event):
        super(ScreensharingToolbox, self).enterEvent(event)
        self.retract_timer.stop()
        self.expose()

    def leaveEvent(self, event):
        super(ScreensharingToolbox, self).leaveEvent(event)
        self.retract_timer.start()

    def paintEvent(self, event):  # make the widget style aware
        option = QStyleOption()
        option.initFrom(self)
        painter = QStylePainter(self)
        painter.drawPrimitive(QStyle.PE_Widget, option)

    def expose(self):
        if self.animation.state() == QPropertyAnimation.Running and self.animation.direction() == QPropertyAnimation.Forward:
            return
        elif self.animation.state() == QPropertyAnimation.Stopped and self.pos() == self.animation.endValue():
            return
        self.animation.setDirection(QPropertyAnimation.Forward)
        self.animation.start()

    def retract(self):
        if self.animation.state() == QPropertyAnimation.Running and self.animation.direction() == QPropertyAnimation.Backward:
            return
        elif self.animation.state() == QPropertyAnimation.Stopped and self.pos() == self.animation.startValue():
            return
        self.animation.setDirection(QPropertyAnimation.Backward)
        self.animation.start()
Exemplo n.º 38
0
    view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
    view.setBackgroundBrush(QBrush(bgPix))
    view.setCacheMode(QGraphicsView.CacheBackground)
    view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
    view.show()

    states = QStateMachine()
    states.addState(rootState)
    states.setInitialState(rootState)
    rootState.setInitialState(centeredState)

    group = QParallelAnimationGroup()
    for i, item in enumerate(items):
        anim = QPropertyAnimation(item, b'pos')
        anim.setDuration(750 + i * 25)
        anim.setEasingCurve(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)

    trans = rootState.addTransition(centeredButton.pressed, centeredState)
Exemplo n.º 39
0
class CoffeeFundWindow(QWidget):
    signal_back = pyqtSignal()
    signal_coffee = pyqtSignal()
    signal_account = pyqtSignal()

    def __init__(self, parent=None):
        super().__init__()

        self.cards = {}  # type: Dict[GuiCards, QWidget]
        """
            Python's GC will clean up QPropertyAnimations as soon as it leaves the button handler,
             therefore they will appear not to work. Use members to store the animations.
            see http://stackoverflow.com/a/6953965
        """
        self.slide_in_animation = None
        self.slide_out_animation = None
        self.animation_group = None
        self.setObjectName("coffeeFundWindow")

        """
            Store the position and size of visible/hidden cards for the animation sequences
        """
        self.hidden_geometry = None
        self.visible_geometry = None

        layout = QStackedLayout()
        layout.setStackingMode(QStackedLayout.StackAll)

        card_remove = RemoveCard()
        self.cards[GuiCards.RemoveCard] = card_remove
        layout.addWidget(card_remove)

        card_choose_action = ChooseActionCard()
        self.cards[GuiCards.ChooseAction] = card_choose_action
        layout.addWidget(card_choose_action)

        card_account = AccountCard()
        self.cards[GuiCards.AccountInfo] = card_account
        layout.addWidget(card_account)

        # keep this as last initialized card, the last card will be shown on startup!
        card_start = StartCard()
        self.cards[GuiCards.Start] = card_start
        layout.addWidget(card_start)

        self.setLayout(layout)
        self.setWindowTitle("Kaffeekasse")

        layout.setCurrentWidget(card_start)
        self.active_card = None

        card_choose_action.button_account.clicked.connect(self.signal_account)
        card_choose_action.button_coffee.clicked.connect(self.signal_coffee)
        card_account.button_back.clicked.connect(self.signal_back)

    def set_card_hidden(self, card: QWidget):
        card.setGeometry(self.hidden_geometry)

    def show_start(self):
        self.show_card(GuiCards.Start)

    def show_account(self, name, value):
        self.cards[GuiCards.AccountInfo].set_user_name(name)
        self.cards[GuiCards.AccountInfo].set_balance(value)
        self.show_card(GuiCards.AccountInfo)

    def show_choose_action(self, name: str):
        self.cards[GuiCards.ChooseAction].set_user_name(name)
        self.show_card(GuiCards.ChooseAction)

    def show_remove(self):
        self.show_card(GuiCards.RemoveCard)

    def show_card(self, card_id: GuiCards):
        if self.active_card is None:
            self.active_card = self.cards[GuiCards.Start]

        if self.active_card == self.cards[card_id]:
            return

        if self.visible_geometry is None or self.hidden_geometry is None:
            self.visible_geometry = self.active_card.geometry()  # type: QRect
            self.hidden_geometry = QRect(self.visible_geometry.x(), self.visible_geometry.height() * 1.5,
                                         self.visible_geometry.width(), self.visible_geometry.height())
        for key in self.cards.keys():
            if key != self.active_card:
                self.set_card_hidden(self.cards[key])

        card_to_show = self.cards[card_id]
        self.start_card_switch(card_to_show)
        self.active_card = self.cards[card_id]
        self.layout().setCurrentWidget(self.active_card)

    def start_card_switch(self, card_to_show):
        self.slide_out_animation = QPropertyAnimation(self.active_card, "geometry")
        self.slide_out_animation.setDuration(ANIMATION_DURATION)
        self.slide_out_animation.setEasingCurve(QEasingCurve.OutCubic)
        self.slide_out_animation.setStartValue(self.visible_geometry)
        self.slide_out_animation.setEndValue(self.hidden_geometry)
        self.set_card_hidden(card_to_show)
        self.slide_in_animation = QPropertyAnimation(card_to_show, "geometry")
        self.slide_in_animation.setDuration(ANIMATION_DURATION)
        self.slide_in_animation.setEasingCurve(QEasingCurve.InCubic)
        self.slide_in_animation.setStartValue(self.hidden_geometry)
        self.slide_in_animation.setEndValue(self.visible_geometry)
        self.animation_group = QParallelAnimationGroup()
        self.animation_group.addAnimation(self.slide_out_animation)
        self.animation_group.addAnimation(self.slide_in_animation)
        self.animation_group.start()
Exemplo n.º 40
0
from PyQt5.QtCore import QPropertyAnimation, QEasingCurve


animation = QPropertyAnimation()
animation.setTargetObject()
animation.setStartValue(0)
animation.setEndValue(1000)
animation.setDuration(1000)
animation.setEasingCurve(QEasingCurve.InOutQuad)

animation.start()
Exemplo n.º 41
0
    def __init__(self, size, parent=None):
        super(PadNavigator, self).__init__(parent)

        self.form = Ui_Form()

        splash = SplashItem()
        splash.setZValue(1)

        pad = FlippablePad(size)
        flipRotation = QGraphicsRotation(pad)
        xRotation = QGraphicsRotation(pad)
        yRotation = QGraphicsRotation(pad)
        flipRotation.setAxis(Qt.YAxis)
        xRotation.setAxis(Qt.YAxis)
        yRotation.setAxis(Qt.XAxis)
        pad.setTransformations([flipRotation, xRotation, yRotation])

        backItem = QGraphicsProxyWidget(pad)
        widget = QWidget()
        self.form.setupUi(widget)
        self.form.hostName.setFocus()
        backItem.setWidget(widget)
        backItem.setVisible(False)
        backItem.setFocus()
        backItem.setCacheMode(QGraphicsItem.ItemCoordinateCache)
        r = backItem.rect()
        backItem.setTransform(QTransform().rotate(180, Qt.YAxis).translate(-r.width()/2, -r.height()/2))

        selectionItem = RoundRectItem(QRectF(-60, -60, 120, 120),
                QColor(Qt.gray), pad)
        selectionItem.setZValue(0.5)

        smoothSplashMove = QPropertyAnimation(splash, b'y')
        smoothSplashOpacity = QPropertyAnimation(splash, b'opacity')
        smoothSplashMove.setEasingCurve(QEasingCurve.InQuad)
        smoothSplashMove.setDuration(250)
        smoothSplashOpacity.setDuration(250)

        smoothXSelection = QPropertyAnimation(selectionItem, b'x')
        smoothYSelection = QPropertyAnimation(selectionItem, b'y')
        smoothXRotation = QPropertyAnimation(xRotation, b'angle')
        smoothYRotation = QPropertyAnimation(yRotation, b'angle')
        smoothXSelection.setDuration(125)
        smoothYSelection.setDuration(125)
        smoothXRotation.setDuration(125)
        smoothYRotation.setDuration(125)
        smoothXSelection.setEasingCurve(QEasingCurve.InOutQuad)
        smoothYSelection.setEasingCurve(QEasingCurve.InOutQuad)
        smoothXRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothYRotation.setEasingCurve(QEasingCurve.InOutQuad)

        smoothFlipRotation = QPropertyAnimation(flipRotation, b'angle')
        smoothFlipScale = QPropertyAnimation(pad, b'scale')
        smoothFlipXRotation = QPropertyAnimation(xRotation, b'angle')
        smoothFlipYRotation = QPropertyAnimation(yRotation, b'angle')
        flipAnimation = QParallelAnimationGroup(self)
        smoothFlipScale.setDuration(500)
        smoothFlipRotation.setDuration(500)
        smoothFlipXRotation.setDuration(500)
        smoothFlipYRotation.setDuration(500)
        smoothFlipScale.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipXRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipYRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipScale.setKeyValueAt(0, 1.0)
        smoothFlipScale.setKeyValueAt(0.5, 0.7)
        smoothFlipScale.setKeyValueAt(1, 1.0)
        flipAnimation.addAnimation(smoothFlipRotation)
        flipAnimation.addAnimation(smoothFlipScale)
        flipAnimation.addAnimation(smoothFlipXRotation)
        flipAnimation.addAnimation(smoothFlipYRotation)

        setVariablesSequence = QSequentialAnimationGroup()
        setFillAnimation = QPropertyAnimation(pad, b'fill')
        setBackItemVisibleAnimation = QPropertyAnimation(backItem, b'visible')
        setSelectionItemVisibleAnimation = QPropertyAnimation(selectionItem, b'visible')
        setFillAnimation.setDuration(0)
        setBackItemVisibleAnimation.setDuration(0)
        setSelectionItemVisibleAnimation.setDuration(0)
        setVariablesSequence.addPause(250)
        setVariablesSequence.addAnimation(setBackItemVisibleAnimation)
        setVariablesSequence.addAnimation(setSelectionItemVisibleAnimation)
        setVariablesSequence.addAnimation(setFillAnimation)
        flipAnimation.addAnimation(setVariablesSequence)

        stateMachine = QStateMachine(self)
        splashState = QState(stateMachine)
        frontState = QState(stateMachine)
        historyState = QHistoryState(frontState)
        backState = QState(stateMachine)

        frontState.assignProperty(pad, "fill", False)
        frontState.assignProperty(splash, "opacity", 0.0)
        frontState.assignProperty(backItem, "visible", False)
        frontState.assignProperty(flipRotation, "angle", 0.0)
        frontState.assignProperty(selectionItem, "visible", True)

        backState.assignProperty(pad, "fill", True)
        backState.assignProperty(backItem, "visible", True)
        backState.assignProperty(xRotation, "angle", 0.0)
        backState.assignProperty(yRotation, "angle", 0.0)
        backState.assignProperty(flipRotation, "angle", 180.0)
        backState.assignProperty(selectionItem, "visible", False)

        stateMachine.addDefaultAnimation(smoothXRotation)
        stateMachine.addDefaultAnimation(smoothYRotation)
        stateMachine.addDefaultAnimation(smoothXSelection)
        stateMachine.addDefaultAnimation(smoothYSelection)
        stateMachine.setInitialState(splashState)

        anyKeyTransition = QEventTransition(self, QEvent.KeyPress, splashState)
        anyKeyTransition.setTargetState(frontState)
        anyKeyTransition.addAnimation(smoothSplashMove)
        anyKeyTransition.addAnimation(smoothSplashOpacity)

        enterTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Enter, backState)
        returnTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Return, backState)
        backEnterTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Enter, frontState)
        backReturnTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Return, frontState)
        enterTransition.setTargetState(historyState)
        returnTransition.setTargetState(historyState)
        backEnterTransition.setTargetState(backState)
        backReturnTransition.setTargetState(backState)
        enterTransition.addAnimation(flipAnimation)
        returnTransition.addAnimation(flipAnimation)
        backEnterTransition.addAnimation(flipAnimation)
        backReturnTransition.addAnimation(flipAnimation)

        columns = size.width()
        rows = size.height()
        stateGrid = []
        for y in range(rows):
            stateGrid.append([QState(frontState) for _ in range(columns)])

        frontState.setInitialState(stateGrid[0][0])
        selectionItem.setPos(pad.iconAt(0, 0).pos())

        for y in range(rows):
            for x in range(columns):
                state = stateGrid[y][x]

                rightTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Right, state)
                leftTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Left, state)
                downTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Down, state)
                upTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Up, state)

                rightTransition.setTargetState(stateGrid[y][(x + 1) % columns])
                leftTransition.setTargetState(stateGrid[y][((x - 1) + columns) % columns])
                downTransition.setTargetState(stateGrid[(y + 1) % rows][x])
                upTransition.setTargetState(stateGrid[((y - 1) + rows) % rows][x])

                icon = pad.iconAt(x, y)
                state.assignProperty(xRotation, "angle", -icon.x() / 6.0)
                state.assignProperty(yRotation, "angle", icon.y() / 6.0)
                state.assignProperty(selectionItem, "x", icon.x())
                state.assignProperty(selectionItem, "y", icon.y())
                frontState.assignProperty(icon, "visible", True)
                backState.assignProperty(icon, "visible", False)

                setIconVisibleAnimation = QPropertyAnimation(icon, b'visible')
                setIconVisibleAnimation.setDuration(0)
                setVariablesSequence.addAnimation(setIconVisibleAnimation)

        scene = QGraphicsScene(self)
        scene.setBackgroundBrush(QBrush(QPixmap(":/images/blue_angle_swirl.jpg")))
        scene.setItemIndexMethod(QGraphicsScene.NoIndex)
        scene.addItem(pad)
        scene.setSceneRect(scene.itemsBoundingRect())
        self.setScene(scene)

        sbr = splash.boundingRect()
        splash.setPos(-sbr.width() / 2, scene.sceneRect().top() - 2)
        frontState.assignProperty(splash, "y", splash.y() - 100.0)
        scene.addItem(splash)

        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setMinimumSize(50, 50)
        self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
        self.setCacheMode(QGraphicsView.CacheBackground)
        self.setRenderHints(QPainter.Antialiasing |
                QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing)

        if QGLFormat.hasOpenGL():
            self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))

        stateMachine.start()
Exemplo n.º 42
0
class NS_Animate(object):
    def __init__(self, scene, x_max, y_max, back_color):

        scene = QGraphicsScene(0, 0, x_max, y_max)
        scene.setBackgroundBrush(back_color)

        color = [Qt.green, Qt.lightGray, Qt.darkYellow, QtGui.QColor.fromRgb(255, 85, 0)]
        self.anim_butt = [ QGraphicsRectWidget(color[j]) for j in range(4) ]
        for j in range(4):
            scene.addItem(self.anim_butt[j])

        self.window = QGraphicsView(scene)
        self.window.setFrameStyle(0)
        self.window.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        self.window.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.window.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        self.machine = QStateMachine()

        self.group = QState()
        self.timer = QTimer()
        self.timer.setInterval(1250)
        self.timer.setSingleShot(True)
        self.group.entered.connect(self.timer.start)

        # set states positions
        anim_state_rects = [ [QRect(x_max*xp/6, y_max*yp/4, 8, 8) for xp in range(4)] for yp in range(4) ]
        self.states = [ self.createGeometryState(
                                self.anim_butt[0], anim_state_rects[0][j], self.anim_butt[1], anim_state_rects[1][j],
                                self.anim_butt[2], anim_state_rects[2][j], self.anim_butt[3], anim_state_rects[3][j],
                                self.group
                            ) for j in range(4) ]

        self.group.setInitialState(self.states[0])


        self.animationGroup = QParallelAnimationGroup()
        self.anim = QPropertyAnimation(self.anim_butt[3], 'geometry')
        self.anim.setDuration(1250)
        self.anim.setEasingCurve(QEasingCurve.InBack)
        self.animationGroup.addAnimation(self.anim)

        self.subGroup = QSequentialAnimationGroup(self.animationGroup)
        self.subGroup.addPause(100)
        self.anim = QPropertyAnimation(self.anim_butt[2], 'geometry')
        self.anim.setDuration(1000)
        self.anim.setEasingCurve(QEasingCurve.OutElastic)
        self.subGroup.addAnimation(self.anim)

        self.subGroup = QSequentialAnimationGroup(self.animationGroup)
        self.subGroup.addPause(500)
        self.anim = QPropertyAnimation(self.anim_butt[1], 'geometry')
        self.anim.setDuration(500)
        self.anim.setEasingCurve(QEasingCurve.OutElastic)
        self.subGroup.addAnimation(self.anim)

        self.subGroup = QSequentialAnimationGroup(self.animationGroup)
        self.subGroup.addPause(750)
        self.anim = QPropertyAnimation(self.anim_butt[0], 'geometry')
        self.anim.setDuration(250)
        self.anim.setEasingCurve(QEasingCurve.OutElastic)
        self.subGroup.addAnimation(self.anim)

        self.stateSwitcher = StateSwitcher(self.machine)
        self.group.addTransition(self.timer.timeout, self.stateSwitcher)
        for j in range(4):
            self.stateSwitcher.addState(self.states[j], self.animationGroup)

        self.machine.addState(self.group)
        self.machine.setInitialState(self.group)
        self.machine.start()

    #
    def createGeometryState(self, w1, rect1, w2, rect2, w3, rect3, w4, rect4, parent):
        result = QState(parent)

        result.assignProperty(w1, 'geometry', rect1)
        result.assignProperty(w1, 'geometry', rect1)
        result.assignProperty(w2, 'geometry', rect2)
        result.assignProperty(w3, 'geometry', rect3)
        result.assignProperty(w4, 'geometry', rect4)

        return result
Exemplo n.º 43
0
            QRect(150, 150, 50, 50), group)

    state6 = createGeometryState(button1, QRect(50, 50, 50, 50), button2,
            QRect(200, 50, 50, 50), button3, QRect(50, 200, 50, 50), button4,
            QRect(200, 200, 50, 50), group)

    state7 = createGeometryState(button1, QRect(0, 0, 50, 50), button2,
            QRect(250, 0, 50, 50), button3, QRect(0, 250, 50, 50), button4,
            QRect(250, 250, 50, 50), group)

    group.setInitialState(state1)

    animationGroup = QParallelAnimationGroup()
    anim = QPropertyAnimation(button4, 'geometry')
    anim.setDuration(1000)
    anim.setEasingCurve(QEasingCurve.OutElastic)
    animationGroup.addAnimation(anim)

    subGroup = QSequentialAnimationGroup(animationGroup)
    subGroup.addPause(100)
    anim = QPropertyAnimation(button3, 'geometry')
    anim.setDuration(1000)
    anim.setEasingCurve(QEasingCurve.OutElastic)
    subGroup.addAnimation(anim)

    subGroup = QSequentialAnimationGroup(animationGroup)
    subGroup.addPause(150)
    anim = QPropertyAnimation(button2, 'geometry')
    anim.setDuration(1000)
    anim.setEasingCurve(QEasingCurve.OutElastic)
    subGroup.addAnimation(anim)