def __createAnimations(self): """ 创建动画 """ self.aniGroup = QParallelAnimationGroup(self) self.__deltaX_list = [13, 5, -3, -11, -13] self.__aniWidget_list = [ self.songNameCard, self.songerLabel, self.albumLabel, self.yearLabel, self.durationLabel, ] self.__ani_list = [ QPropertyAnimation(widget, b"geometry") for widget in self.__aniWidget_list ] for ani in self.__ani_list: ani.setDuration(400) ani.setEasingCurve(QEasingCurve.OutQuad) self.aniGroup.addAnimation(ani) # 记录下移动目标位置 self.__getAniTargetX_list()
def _create_flash_animation(self): if FLASH_COUNT.value <= 0 or \ FLASH_DURATION.value <= 0: return None minibuff_input = self.minibuffer.input() anim = QPropertyAnimation(minibuff_input, b"background_color") base = minibuff_input.property(b"background_color") flash_color = QColor(FLASH_COLOR.value) anim.setDuration(int(FLASH_DURATION.value * 1000)) step = 1. / (FLASH_COUNT.value * 2) pos = step colors = itertools.cycle((flash_color, base)) anim.setStartValue(base) while pos < 1: anim.setKeyValueAt(pos, next(colors)) pos += step anim.setEndValue(base) return anim
def slide_bar(self): width = self.ui.left_side_menu.width() if width == 70: newWidth = 220 self.ui.convert_slide_btn.setStyleSheet("padding-left:0;") self.ui.history_slide_btn.setStyleSheet("padding-left:0;") else: newWidth = 70 self.ui.convert_slide_btn.setStyleSheet("padding-left:110;") self.ui.history_slide_btn.setStyleSheet("padding-left:110;") self.animation = QPropertyAnimation(self.ui.left_side_menu, b"minimumWidth") self.animation.setDuration(200) self.animation.setStartValue(width) self.animation.setEndValue(newWidth) self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart) self.animation.start()
def setAnimation(self, aniWidget_list: list, deltaX_list: list): """ 设置小部件的动画 Parameters ---------- aniWidget_list : 需要设置动画的小部件列表\n deltaX_list : 和aniWidget_list相对应的动画位置偏移量列表 """ self.__checkIsLengthEqual(aniWidget_list, deltaX_list) self.__aniWidget_list = aniWidget_list self.__deltaX_list = deltaX_list # 清空动画组的内容 self.ani_list.clear() self.aniGroup.clear() self.__ani_list = [QPropertyAnimation( widget, b'geometry') for widget in self.__aniWidget_list] # 初始化动画 for ani in self.__ani_list: ani.setDuration(400) ani.setEasingCurve(QEasingCurve.OutQuad) self.aniGroup.addAnimation(ani) self.getAniTargetX_list()
def set_fadeout(self, wait_for_sec=7): opc = QGraphicsOpacityEffect(self) self.opc = opc self.setGraphicsEffect(opc) cue = QSequentialAnimationGroup() self.cue = cue cue.addPause(wait_for_sec * 1000) # Fade-out anim = QPropertyAnimation(opc, b"opacity") self.anim = anim anim.setDuration(3000) anim.setStartValue(1) anim.setEndValue(0) anim.setEasingCurve(QEasingCurve.InExpo) cue.addAnimation(anim) cue.finished.connect(self.deleteLater) cue.start(QAbstractAnimation.DeleteWhenStopped)
def animationDash(self): if self.enable: multBy = 1 / 1.4 self.pbHome.setText('') self.pbAgenda.setText('') else: multBy = 1.4 self.pbHome.setText('Home') self.pbAgenda.setText('Agenda') widthStart = self.frMenu.width() self.animSideBar = QPropertyAnimation(self.frMenu, b"minimumWidth") self.animSideBar.setDuration(200) self.animSideBar.setStartValue(widthStart) self.animSideBar.setEndValue(widthStart * multBy) self.animSideBar.start() self.enable = not self.enable
def goOn(self): self.anim = QPropertyAnimation(self.mascot, b"pos") self.mascotFlip.hide() self.mascotGif.start() self.mascot.show() path = QPainterPath() path.moveTo(-70, 410) for i in range(self.step): path.quadTo( QPointF( self.xRange / self.step * i - 70 + (self.xRange / self.step / 2), 410), QPointF((self.xRange / self.step) * i - 70 + (self.xRange / self.step), 430)) vals = [p / 100 for p in range(0, 101)] self.anim.setDuration(self.duration) for i in vals: self.anim.setKeyValueAt(i, path.pointAtPercent(i)) self.anim.start() self.anim.finished.connect(self.goFlip)
def regularsize_me(self): """ Collapse this attribute and hide it's content Returns ------- None """ if self.active: self.store_current_content() self.animation = QPropertyAnimation(self, b"minimumSize") self.animation.setDuration(200) self.animation.setEndValue(QSize(100, self.height())) self.animation.start() self.ui.nodata_content.hide() self.clear_domain() self.clear_nodata() self.ui.place_holder.show() self.active = False
def toggleWindow(self): self.animation = QPropertyAnimation(self.ui.app_list, b"maximumHeight") self.animation.setDuration(250) try: self.animation.finished.disconnect() except TypeError: pass if self.ui.app_list.maximumHeight() == 0: self.animation.setStartValue(0) self.animation.setEndValue( self.ui.app_list_layout.sizeHint().height()) self.animation.finished.connect(self.onGroupExpanded) else: self.ui.app_list_layout.setSizeConstraint( QLayout.SetDefaultConstraint) self.animation.setStartValue( self.ui.app_list_layout.sizeHint().height()) self.animation.setEndValue(0) self.animation.finished.connect(self.onGroupCollapsed) self.animation.start()
def Mostrar (self, label, imagen, nombre, posicionX=650): imagen = QPixmap.fromImage(imagen) # Escalar imagen a 640x480 si el ancho es mayor a 640 o el alto mayor a 480 if imagen.width() > 640 or imagen.height() > 480: imagen = imagen.scaled(640, 480, Qt.KeepAspectRatio, Qt.SmoothTransformation) if imagen.width() < 640 or imagen.height() < 480: imagen = imagen.scaled(640, 480, Qt.KeepAspectRatio, Qt.SmoothTransformation) # Mostrar imagen label.setPixmap(imagen) # Animación (al finalizar la animación se muestra en la barra de estado el nombre y la extensión de la imagen # y se desbloquean los botones). self.animacionMostar = QPropertyAnimation(label, b"geometry") self.animacionMostar.finished.connect(lambda: (self.parent.statusBar.showMessage(nombre), self.bloquearBotones(True))) self.animacionMostar.setDuration(200) self.animacionMostar.setStartValue(QRect(posicionX, 0, 640, 480)) self.animacionMostar.setEndValue(QRect(0, 0, 640, 480)) self.animacionMostar.start(QAbstractAnimation.DeleteWhenStopped)
def _big_geometry(self): w = 30 h = 30 x = self.right - w y = self.bottom - h big_w = 300 big_h = 300 big_x = self.right - big_w big_y = self.bottom - big_h if (self.x() < x) and (self.y() < y): return self.animation = QPropertyAnimation(self, b"geometry") self.animation.setDuration(250) self.animation.setStartValue(QRect(x, y, w, h)) self.animation.setEndValue(QRect(big_x, big_y, big_w, big_h)) self.animation.start() self.setFixedSize(big_w, big_h)
def __init__(self, _container, _fadeWidget): super(StackedWidgetFadeInAnimator, self).__init__(_container) self.m_decorator = StackedWidgetFadeInDecorator(_container, _fadeWidget=_fadeWidget) self.m_animation = QPropertyAnimation(self.m_decorator, b"opacity") _container.installEventFilter(self) self.m_animation.setDuration(200) self.m_decorator.hide() def finished(): self.setAnimatedStopped() if self.m_animation.direction() == QPropertyAnimation.Forward: _container.setCurrentWidget(_fadeWidget) self.m_decorator.hide() self.m_animation.finished.connect(finished)
def hideDecorator(self): hideEffect = self.m_decorator.graphicsEffect() if hideEffect == None: hideEffect = QGraphicsOpacityEffect(self.m_decorator) self.m_decorator.setGraphicsEffect(hideEffect) hideEffect.setOpacity(1) hideAnimation = QPropertyAnimation(hideEffect, b"opacity", self.m_decorator) hideAnimation.setDuration(400) hideAnimation.setStartValue(1) hideAnimation.setEndValue(0) def finished(): self.m_decorator.hide() hideEffect.setOpacity(1) hideAnimation.finished.connect(finished) hideAnimation.start(QAbstractAnimation.DeleteWhenStopped)
def setup_yd(self): if self.biaotipos == 1: self.biaotipos = 2 self.kuang.hide() self.edit2.hide() self.pushButton_18.hide() self.edit.hide() self.edit22.show() self.yuan2.show() self.pushButton_19.show() self.edit_suiji_size.show() self.yuan3.show() self.edit_suiji_num.show() animation = QPropertyAnimation(self) animation.setTargetObject(self.biaoti_one) animation.setPropertyName(b"pos") animation.setStartValue(QPoint(375, 75)) animation.setEndValue((QPoint(615, 75))) animation.setDuration(300) animation.start()
def setPaths(pix, anime, node): pos = node.pix.pos() sync = random.randint(73,173) * 100 ## very arbitrary path = QPropertyAnimation(node, b'pos') path.setDuration(sync) waypts = pathLoader(anime) if not waypts: return ## offset for origin pt - setOrigin wasn't working pt = getOffset(node.pix) path.setStartValue(waypts.pointAtPercent(0.0)-pt) for i in range(1, 99): path.setKeyValueAt(i/100.0, waypts.pointAtPercent(i/100.0)-pt) path.setEndValue(waypts.pointAtPercent(1.0)-pt) path.setLoopCount(-1) return path
def Home(self): self.items = [] for i in range(len(self.names['home'])): item = QPushButton(self) item.setText(self.names['home'][i]) item.setGeometry(395, 350, 120, 80) item.setStyleSheet( "QPushButton:hover{background-color:rgb(241, 90, 36);border:5px solid rgb(0, 97, 157);}\n" "QPushButton{color:white;background-color: rgb(50, 50, 50);border:5px solid rgb(255, 255, 255);}QPushButton:pressed{color:white;background-color: rgb(50, 50, 50);border:5px solid rgb(255, 255, 255);}\n" "") self.font.setPointSize(15) item.setFont(self.font) self.items.append(item) exec("""item.clicked.connect(partial(self.IND,i=%i))""" % (i)) self.rootState = QState() self.tiledState = QState(self.rootState) self.centeredState = QState(self.rootState) for i, item in enumerate(self.items): self.tiledState.assignProperty( item, 'pos', QPointF(((i % 6) * 5.3) * 30, ((i // 6) * 5.3) * 30)) self.centeredState.assignProperty(item, 'pos', QPointF()) self.states = QStateMachine() self.states.addState(self.rootState) self.states.setInitialState(self.rootState) self.rootState.setInitialState(self.centeredState) self.group = QParallelAnimationGroup() for i, item in enumerate(self.items): anim = QPropertyAnimation(item, b'pos') anim.setStartValue(QPoint(400, 300)) anim.setDuration(750 + i * 25) anim.setEasingCurve(QEasingCurve.InOutBack) self.group.addAnimation(anim) for u in self.items: trans = self.rootState.addTransition(u.clicked, self.tiledState) trans.addAnimation(self.group) self.states.start()
def resizeLayout(self): if len(self.widgets) == 0: return gpw_width = self.fixed_width gpw_height = self.fixed_height bar_width = self.verticalScrollBar().width() # 一列数量 col_count = max( int((self.center_widget.width() - self.item_spacing_h - bar_width) / (gpw_width + self.item_spacing_h)), 1) if col_count > len(self.widgets): col_count = len(self.widgets) # 行数 row_count = max(int((len(self.widgets) + col_count - 1) / col_count), 1) total_height = row_count * ( gpw_height + self.item_spacing_v) + self.item_spacing_v * 2 self.center_widget.setMinimumHeight(total_height) self.center_widget.resize(self.center_widget.width(), total_height) total_left = (self.center_widget.width() - col_count * (gpw_width + self.item_spacing_h)) / 2 total_top = self.item_spacing_v cur_row = 0 cur_col = 0 for widget in self.widgets: pos = QPoint( total_left + cur_col * (gpw_width + self.item_spacing_h), total_top + cur_row * (gpw_height + self.item_spacing_v)) ani = QPropertyAnimation(widget, b"pos", self) ani.setStartValue(widget.pos()) ani.setEndValue(pos) ani.setDuration(300) ani.setEasingCurve(QEasingCurve.OutQuad) ani.finished.connect(ani.deleteLater) ani.start() cur_col += 1 if cur_col >= col_count: cur_col = 0 cur_row += 1
def getDetailInfo(self): """点击后进行动画效果的: 显示某歌曲的详细信息。""" self.shortInfo.hide() self.detailInfo.show() self.showDetail = QPropertyAnimation(self, b"geometry") x = self.pos().x() y = self.pos().y() self.showDetail.setStartValue(QRect(x, y, self.width(), self.height())) # 获取顶层父窗口的长度。 self.showDetail.setEndValue(QRect(0, self.grandparent.header.height()+3, self.grandparent.width(), self.grandparent.mainContent.height())) self.showDetail.setDuration(300) self.showDetail.setEasingCurve(QEasingCurve.InBack) self.showDetail.start(QAbstractAnimation.DeleteWhenStopped) # 将该组件显示在最前,默认会嵌入到父组件里面。 self.raise_() self.setDetailInfo()
def toggleMenu(self, maxWidth, enable): if enable: # GET WIDTH width = self.ui.side_frame.width() maxExtend = maxWidth standard = 70 # SET MAX WIDTH if width == 70: widthExtended = maxExtend else: widthExtended = standard # ANIMATION self.animation = QPropertyAnimation(self.ui.side_frame, b"minimumWidth") self.animation.setDuration(400) self.animation.setStartValue(width) self.animation.setEndValue(widthExtended) self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart) self.animation.start()
def toggleMenu(self, maxWidth, enable): if enable: width = self.ui.frame_left_menu.width() maxExtend = maxWidth standard = 100 if width == 100: widthExtended = maxExtend self.ui.Btn_page_2.setText("Волатильность") self.ui.Btn_page_3.setText("Простая стратегия") else: widthExtended = standard self.ui.Btn_page_2.setText("Вола-\nтильность") self.ui.Btn_page_3.setText("Простая\nстратегия") self.animation = QPropertyAnimation(self.ui.frame_left_menu, b"minimumWidth") self.animation.setDuration(300) self.animation.setStartValue(width) self.animation.setEndValue(widthExtended) self.animation.start()
def toggleMenu(self, maxWidth, enable): if enable: # получаем значение Width width = self.frame_left_menu.width() maxExtend = maxWidth standart = 50 # задаем макс значание width if width == 50: widthExtend = maxExtend else: widthExtend = standart # анимация self.animation = QPropertyAnimation(self.frame_left_menu, b'minimumWidth') self.animation.setDuration(200) self.animation.setStartValue(width) self.animation.setEndValue(widthExtend) self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart) self.animation.start()
def __init__(self, child_widget: QWidget, play_on_show=True, duration_ms=1000, start_color=QColor(50, 190, 25, 255), *args, **kwargs): super().__init__(*args, **kwargs) main_layout = QHBoxLayout() self.setLayout(main_layout) main_layout.addWidget(child_widget) main_layout.setContentsMargins(0, 0, 0, 0) main_layout.setSpacing(0) self._animation = QPropertyAnimation(self, b'color') self._animation.setDuration(duration_ms) self._animation.setStartValue(start_color) self._animation.setEndValue(self.palette().color( self.backgroundRole())) self._animation.setEasingCurve(QEasingCurve.OutInBack) self.play_on_show = play_on_show
def showHideMirrorAfterNotification(self): try: self.showMainTimer.stop() if self.isMirrorAwake: startValue = 0 endValue = 1 else: startValue = 1 endValue = 0 self.mainFourEffect = QGraphicsOpacityEffect() self.mainFourFrame.setGraphicsEffect(self.mainFourEffect) self.showHideMirrorAnimation = QPropertyAnimation( self.mainFourEffect, b"opacity") self.showHideMirrorAnimation.setDuration(2000) self.showHideMirrorAnimation.setStartValue(startValue) self.showHideMirrorAnimation.setEndValue(endValue) self.showHideMirrorAnimation.start() except Exception as e: print(e)
def mousePressEvent(self, mouseEvent: QMouseEvent): closestNode = self.playerNode.closest(mouseEvent.pos() - self.paintOffset) direction = closestNode.row - self.playerNode.row, closestNode.column - self.playerNode.column crawlNode = self.playerNode.crawl(direction) self.animation = QPropertyAnimation(self, b'player') if len(crawlNode.links) > 2: self.animation.setEasingCurve(QEasingCurve.OutBack) else: self.animation.setEasingCurve(QEasingCurve.OutBounce) self.animation.setStartValue(self.player) self.animation.setEndValue(crawlNode.point) self.animation.setDuration(400) self.animation.start() self.playerNode = crawlNode if self.playerNode == self.finishNode: QMessageBox.information(self, self.tr("Victory!"), self.tr("You won :)"), QMessageBox.Ok) self.initMaze()
def move_move(self, move): if move not in self.board.legal_moves: return False self.board.push(move) x_from, y_from = self._get_coordinate(move.from_square) x_to, y_to = self._get_coordinate(move.to_square) self.refresh_board() label = self.pieces[move.to_square] self.anim = QPropertyAnimation(label, b"pos") self.anim.setDuration(400) self.anim.setStartValue(QPoint(x_from, y_from)) self.anim.setEndValue(QPoint(x_to, y_to)) self.anim.setEasingCurve(QEasingCurve.InOutQuart) self.anim.start() # self.anim.finished.connect(self.notify_listener) self.move_memory = [] return True
def __init__(self, parent, closable=False): super().__init__(parent=parent) self.setupUi(self) self.setWindowTitle('Set Master Password') self.setModal(True) # bool of whether the entered passswords are correct self.requirements_passed = closable # creating messageBox self.messageBox = MessageBox(parent=self) self.messageBox.setWindowTitle(self.windowTitle()) # creating animation self.buttonAnim = QPropertyAnimation(self.pushButton, b'geometry') # assigning event handlers self.pushButton.clicked.connect(self.pushButtonClicked) self.buttonAnim.finished.connect(self.buttonAnimFinished)
def search(self, host_type): if host_type: self.HostListWindow_Out.setStartValue( QRect(0 - self.width(), 0, self.width(), self.height())) self.HostListWindow_Out.setEndValue( QRect(0, 0, self.width(), self.height())) self.HostList_Out.setStartValue( QtCore.QRect(0, 0, self.width(), self.height())) self.HostList_Out.setEndValue( QRect(self.width(), 0, self.width(), self.height())) self.HostListWindow_Out.start() self.HostList_Out.start() else: self.HostList.pushButton_2.setText('返回') self.HostList.outani = QPropertyAnimation(self.HostList.lineEdit, b"geometry") self.HostList.outani.setStartValue( QtCore.QRect(self.HostList.width() + 40, 10, 200, 38)) self.HostList.outani.setDuration(300) # 1s self.HostList.outani.setEndValue(QRect(12, 10, 200, 38)) self.HostList.outani.start()
def createWidgets(self): """ 创建小部件 """ icon_path = { 'normal': r'resource\images\createPlaylistPanel\stateToolTip_closeBt_normal_14_14.png', 'hover': r'resource\images\createPlaylistPanel\stateToolTip_closeBt_hover_14_14.png', 'pressed': r'resource\images\createPlaylistPanel\stateToolTip_closeBt_hover_14_14.png' } self.closeButton = ThreeStateButton(icon_path, self, (14, 14)) self.titleLabel = QLabel(self.title, self) self.contentLabel = QLabel(self.content, self) self.rotateTimer = QTimer(self) self.closeTimer = QTimer(self) self.animation = QPropertyAnimation(self, b'windowOpacity') self.busyImage = QPixmap( r'resource\images\createPlaylistPanel\running_22_22.png') self.doneImage = QPixmap( r'resource\images\createPlaylistPanel\complete_20_20.png')
def getShortInfo(self): """返回到原来的缩略图信息。""" self.showShort = QPropertyAnimation(self, b"geometry") x = self.pos().x() y = self.pos().y() self.showShort.setStartValue( QRect(0, self.grandparent.header.height(), self.grandparent.width(), self.grandparent.mainContent.height())) self.showShort.setEndValue( QRect(0, self.grandparent.height() - 64 - self.parent.height(), self.grandparent.navigation.width(), 64)) self.showShort.setDuration(300) self.showShort.setEasingCurve(QEasingCurve.InBack) self.showShort.start(QAbstractAnimation.DeleteWhenStopped) self.raise_()
def animate(self, item): panel = self.centralWidget() self.list = item.tableWidget() self.row = item.row() # create a cell widget to get the right position in the table self.cellWidget = QWidget() self.cellWidget.setMaximumHeight(0) self.list.setCellWidget(self.row, 1, self.cellWidget) pos = self.cellWidget.mapTo(panel, QPoint(0, 0)) self.editor.setParent(panel) self.editor.move(pos) self.editor.resize(self.cellWidget.size()) self.editor.show() self.animation = QPropertyAnimation(self.editor, "geometry".encode("utf-8")) self.animation.setDuration(300) self.animation.setStartValue(QRect(pos.x(), pos.y(), self.cellWidget.size().width(), self.cellWidget.size().height())) self.animation.setEndValue(QRect(0, 0, panel.size().width(), panel.size().height())) self.animation.start()