当前位置: 首页>>代码示例>>Python>>正文


Python QTimeLine.setDuration方法代码示例

本文整理汇总了Python中PyQt4.QtCore.QTimeLine.setDuration方法的典型用法代码示例。如果您正苦于以下问题:Python QTimeLine.setDuration方法的具体用法?Python QTimeLine.setDuration怎么用?Python QTimeLine.setDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtCore.QTimeLine的用法示例。


在下文中一共展示了QTimeLine.setDuration方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FaderWidget

# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import setDuration [as 别名]
class FaderWidget(QWidget):

    def __init__(self, old_widget, new_widget):
        QWidget.__init__(self, new_widget)

        self.old_pixmap = QPixmap(new_widget.size())
        old_widget.render(self.old_pixmap)
        self.pixmap_opacity = 1.0

        self.timeline = QTimeLine()
        self.timeline.valueChanged.connect(self.animate)
        self.timeline.finished.connect(self.close)
        self.timeline.setDuration(500)
        self.timeline.start()

        self.resize(new_widget.size())
        self.show()

    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setOpacity(self.pixmap_opacity)
        painter.drawPixmap(0, 0, self.old_pixmap)
        painter.end()

    def animate(self, value):
        self.pixmap_opacity = 1.0 - value
        self.repaint()
开发者ID:beefsack,项目名称:ninja-ide,代码行数:30,代码来源:ui_tools.py

示例2: TimedProgressBar

# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import setDuration [as 别名]
class TimedProgressBar(QProgressBar):
    """A QProgressBar showing a certain time elapse."""
    hideOnTimeout = True
    def __init__(self, parent=None):
        super(TimedProgressBar, self).__init__(parent, minimum=0, maximum=100)
        self._timeline = QTimeLine(updateInterval=100, frameChanged=self.setValue)
        self._timeline.setFrameRange(0, 100)
        self._hideTimer = QTimer(timeout=self._done, singleShot=True, interval=3000)
    
    def start(self, total, elapsed=0.0):
        """Starts showing progress.
        
        total is the number of seconds (maybe float) the timeline will last,
        elapsed (defaulting to 0) is the value to start with.
        
        """
        self._hideTimer.stop()
        self._timeline.stop()
        self._timeline.setDuration(total * 1000)
        self._timeline.setCurrentTime(elapsed * 1000)
        self.setValue(self._timeline.currentFrame())
        self._timeline.resume()
        if self.hideOnTimeout:
            self.show()
        
    def stop(self, showFinished=True):
        """Ends the progress display.
        
        If showFinished is True (the default), 100% is shown for a few
        seconds and then the progress is reset.
        The progressbar is hidden if the hideOnTimeout attribute is True.
        
        """
        self._hideTimer.stop()
        self._timeline.stop()
        if showFinished:
            self.setValue(100)
            self._hideTimer.start()
        else:
            self._done()

    def _done(self):
        if self.hideOnTimeout:
            self.hide()
        self.reset()
开发者ID:EdwardBetts,项目名称:frescobaldi,代码行数:47,代码来源:progressbar.py

示例3: StackFader

# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import setDuration [as 别名]
class StackFader(QWidget):
    """
    A widget that creates smooth transitions in a QStackedWidget.
    """
    def __init__(self, stackedWidget):
        QWidget.__init__(self, stackedWidget)
        self.curIndex = None
        self.timeline = QTimeLine()
        self.timeline.setDuration(333)
        self.timeline.finished.connect(self.hide)
        self.timeline.valueChanged.connect(self.animate)
        stackedWidget.currentChanged.connect(self.start)
        self.hide()
    
    def start(self, index):
        if self.curIndex is not None:
            stack = self.parent()
            old, new = stack.widget(self.curIndex), stack.widget(index)
            if old and new:
                self.old_pixmap = QPixmap(new.size())
                old.render(self.old_pixmap)
                self.pixmap_opacity = 1.0
                self.resize(new.size())
                self.timeline.start()
                self.raise_()
                self.show()
        self.curIndex = index
        
    def paintEvent(self, ev):
        painter = QPainter()
        painter.begin(self)
        painter.setOpacity(self.pixmap_opacity)
        painter.drawPixmap(0, 0, self.old_pixmap)
        painter.end()
        
    def animate(self, value):
        self.pixmap_opacity = 1.0 - value
        self.repaint()
开发者ID:Alwnikrotikz,项目名称:lilykde,代码行数:40,代码来源:widgets.py

示例4: ParallaxSlide

# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import setDuration [as 别名]

#.........这里部分代码省略.........
        self.iconTimeLine.setCurveShape(QTimeLine.EaseInOutCurve)
    
        self.connect(self.backgroundTimeLine, SIGNAL("frameChanged(int)"), self, SLOT("moveBackground(int)"))
        self.connect(self.backgroundTimeLine, SIGNAL("finished()"), self, SLOT("adjustParameters()"))
        self.backgroundTimeLine.setCurveShape(QTimeLine.EaseInOutCurve)
        
        self.controls = Ui_ControlsForm()
        
        toolWidget = QWidget(self)
        toolWidget.setWindowFlags(Qt.Tool | Qt.WindowTitleHint)
        self.controls.setupUi(toolWidget)
        toolWidget.show()
    
        self.connect(self.controls.speedSlider, SIGNAL("valueChanged(int)"),
                     self, SLOT("adjustParameters()"))
        self.connect(self.controls.normalButton, SIGNAL("clicked()"),
                     self, SLOT("adjustParameters()"))
        self.connect(self.controls.parallaxButton, SIGNAL("clicked()"),
                     self, SLOT("adjustParameters()"))
        self.connect(self.controls.leftButton, SIGNAL("clicked()"),
                     self, SLOT("slideLeft()"))
        self.connect(self.controls.rightButton, SIGNAL("clicked()"),
                     self, SLOT("slideRight()"))
    
        self.slideBy(-320)
        self.adjustParameters()
    
    @pyqtSignature("")
    def slideLeft(self):
    
        if self.iconTimeLine.state() != QTimeLine.NotRunning:
            return
        
        if self.ofs > -640:
            self.slideBy(-320)
    
    @pyqtSignature("")
    def slideRight(self):
    
        if self.iconTimeLine.state() != QTimeLine.NotRunning:
            return
        
        if self.ofs < 0:
            self.slideBy(320)
    
    @pyqtSignature("int")
    def slideBy(self, dx):
    
        iconStart = self.ofs
        iconEnd = self.ofs + dx
        self.iconTimeLine.setFrameRange(iconStart, iconEnd)
        self.iconTimeLine.start()
        
        backgroundStart = -320 - int((-320 - iconStart)/self.factor)
        backgroundEnd = -320 - int((-320 - iconEnd)/self.factor)
        self.backgroundTimeLine.setFrameRange(backgroundStart, backgroundEnd)
        self.backgroundTimeLine.start()
        
        self.ofs = iconEnd
    
    @pyqtSignature("bool")
    def setParallaxEnabled(self, p):
    
        if p:
            self.factor = 2
            self.setWindowTitle("Sliding - Parallax mode")
        else:
            self.factor = 1
            self.setWindowTitle("Sliding - Normal mode")
    
    def keyPressEvent(self, event):
    
        if event.key() == Qt.Key_Left:
            self.slideLeft()

        if event.key() == Qt.Key_Right:
            self.slideRight()
    
    @pyqtSignature("int")
    def moveIcons(self, x):
    
        i = 0
        for icon in self.icons:
            icon.setPos(320 + x+i*64, icon.pos().y())
            i += 1
    
    @pyqtSignature("int")
    def moveBackground(self, x):
    
        self.background.setPos(x, self.background.pos().y())
    
    @pyqtSignature("")
    def adjustParameters(self):
    
        speed = self.controls.speedSlider.value()
        self.iconTimeLine.setDuration(1200 - speed*10)
        self.backgroundTimeLine.setDuration(1200 - speed*10)
        self.setParallaxEnabled(self.controls.parallaxButton.isChecked())
        self.controls.leftButton.setEnabled(self.ofs > -640)
        self.controls.rightButton.setEnabled(self.ofs < 0)
开发者ID:Tarzanello,项目名称:graphics-dojo-qt5,代码行数:104,代码来源:parallaxslide.py

示例5: ViewMain

# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import setDuration [as 别名]
class ViewMain(QMainWindow):
    """This Class Provides the Graphical Interface for Game"""

    # Use Constants To Avoid Magic Numbers
    
    # Declare stack widget names
    MAIN_PAGE = 0
    SETTINGS_PAGE = 1
    GAME_PAGE = 2
    INSTRUCTIONS_PAGE = 3
    CREDITS_PAGE = 4
    STORY_PAGE = 5
    SCORE_PAGE = 6

    finished = pyqtSignal()
    
    def __init__(self, parent=None):
        """Initialize the abstracted class instance"""
        super(ViewMain, self).__init__(parent)

        # Init Data Members
        self.gui  = Gui(self)
        self.game = None
        self.connectGui()

        self.gameWasLoaded = False
        self.useLoadWorkaround = True

        # Dictionary of Graphics Objects
        self.graphicsObjects = {}
        
        # Overlays
        self.overlays = {}
        
        self.currStackIndex = self.MAIN_PAGE
        self.gui.soundManager.playCurrMusic()
        #self.gui.soundManager.setVolume(0)
        
        # Timer initialization and setup for normal popups
        self.popupTimelineStart = QTimeLine(200)
        self.popupTimelineStart.setFrameRange(0,100)
        self.popupTimelineEnd = QTimeLine(200)
        self.popupTimelineEnd.setFrameRange(0,100)
        self.popupTimelineWait = QTimeLine()
        self.popupTimelineWait.setFrameRange(0,100)
        self.popupClue = False
        self.popupStory = False
        
        # Initialization and setup for animated popups
        self.popupAnimationOpen = QPropertyAnimation(self.gui.popup,"geometry")
        self.popupAnimationOpen.setDuration(200)
        self.popupAnimationOpen.setStartValue(QRect(0, 591, 0, 0))
        self.popupAnimationOpen.setEndValue(QRect(25, 25, 750, 450))
        self.popupAnimationClose = QPropertyAnimation(self.gui.popup,"geometry")
        self.popupAnimationClose.setDuration(200)
        self.popupAnimationClose.setStartValue(QRect(25, 25, 750, 450))
        self.popupAnimationClose.setEndValue(QRect(0, 591, 0, 0))
        self.popupAnimationWait = QTimeLine()
        
        self.toMain = False
        #self.gui.personView.centerOn(0,0)
        self.gui.mapView.centerOn(0,0)
        
########################################
### Signals and slots connected here ###
########################################

        # Connections for normal popups
        self.popupTimelineStart.frameChanged.connect(self.drawPopup)
        self.popupTimelineStart.finished.connect(self.popupWait)
        self.popupTimelineEnd.frameChanged.connect(self.erasePopup)   
        self.popupTimelineWait.finished.connect(self.enableErasePopup) 
        self.popupTimelineEnd.finished.connect(self.writeClue)
        
        # Connections for animated popups
        self.popupAnimationOpen.finished.connect(self.popupAnimationWait.start)
        self.popupAnimationWait.finished.connect(self.popupAnimationClose.start)
        self.popupAnimationClose.finished.connect(self.popupAnimationCleanup)
        self.finished.connect(self.writeStory)
    
    def connectGui(self):
        """Connect signals for Gui"""
        self.gui.actionQuit.triggered.connect(self.close)
        self.gui.quitButton.released.connect(self.close)
        self.gui.settingsButton.released.connect(self.setSettings)
        self.gui.actionSettings.triggered.connect(self.setSettings)
        self.gui.loadButton.released.connect(self.loadFileDialog)
        self.gui.actionSave_Game.triggered.connect(self.saveFileDialog)
        self.gui.doneButton.released.connect(self.goBack)
        self.gui.startButton.released.connect(self.enterName)
        self.gui.actionMain_Menu.triggered.connect(self.setMain)
        self.gui.actionHelp.triggered.connect(self.setInstructions)
        self.gui.instrButton.released.connect(self.setInstructions)
        self.gui.doneButton2.released.connect(self.goBack)
        self.gui.doneButton3.released.connect(self.goBack)
        self.gui.doneButtonScore.released.connect(self.scoreButton)
        self.gui.actionCredits.triggered.connect(self.setCredits)
        self.gui.latLongCheck.stateChanged.connect(self.latLong)
        self.gui.colorCheck.stateChanged.connect(self.colorize)
        self.gui.legendCheck.stateChanged.connect(self.legend)
#.........这里部分代码省略.........
开发者ID:hackerj,项目名称:Treasure-Hunting-Game,代码行数:103,代码来源:ViewMain.py

示例6: QPageWidget

# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import setDuration [as 别名]
class QPageWidget(QScrollArea):
    """ The QPageWidget provides a stack widget with animated page transitions. """

    def __init__(self, parent = None, direction = "ltr", rtf = False):
        """ Creates a new QPageWidget on given parent object. 

        parent: QWidget parent
        direction: "ltr" -> Left To Right
                   "ttb" -> Top To Bottom
        rtf: Return to first, if its True it flips to the first page 
             when next page requested at the last page
        """
        # First initialize, QPageWidget is based on QScrollArea
        QScrollArea.__init__(self, parent)

        # Properties for QScrollArea
        self.setFrameShape(QFrame.NoFrame)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setWidgetResizable(True)

        # Main widget, which stores all Pages in it
        self.widget = QWidget(self)

        # Layout based on QBoxLayout which supports Vertical or Horizontal layout
        if direction == "ltr":
            self.layout = QBoxLayout(QBoxLayout.LeftToRight, self.widget)
            self.__scrollBar = self.horizontalScrollBar()
            self.__base_value = self.width
        else:
            self.layout = QBoxLayout(QBoxLayout.TopToBottom, self.widget)
            self.__scrollBar = self.verticalScrollBar()
            self.__base_value = self.height
        self.layout.setSpacing(0)
        self.layout.setMargin(0)

        # Return to first
        self.__return_to_first = rtf

        # TMP_PAGE, its using as last page in stack
        # A workaround for a QScrollArea bug
        self.__tmp_page = Page(QWidget(self.widget))
        self.__pages = [self.__tmp_page]
        self.__current = 0
        self.__last = 0

        # Set main widget
        self.setWidget(self.widget)

        # Animation TimeLine
        self.__timeline = QTimeLine()
        self.__timeline.setUpdateInterval(2)

        # Updates scrollbar position when frame changed
        self.__timeline.frameChanged.connect(lambda x: self.__scrollBar.setValue(x))

        # End of the animation
        self.__timeline.finished.connect(self._animateFinished)

        # Initialize animation
        self.setAnimation()
        self.setDuration()

    def _animateFinished(self):
        """ Its called by TimeLine when animation finished.

        It first runs the outMethod of last Page and then the inMethod of current Page
        Finally tt gives the focus to the current page and fixes the scrollBar
        """

        # Disable other widgets
        for page in self.__pages:
            if not page == self.__pages[self.__current]:
                page.widget.setEnabled(False)

        # Run last page's outMethod if exists
        if self.__pages[self.__last].outMethod:
            self.__pages[self.__last].outMethod()

        # Run new page's inMethod if exists
        if self.__pages[self.__current].inMethod:
            self.__pages[self.__current].inMethod()

        # Give focus to the current Page
        self.__pages[self.__current].widget.setFocus()

        # Update scrollbar position for current page
        self.__scrollBar.setValue(self.__current * self.__base_value())

        # Emit currentChanged SIGNAL
        self.emit(SIGNAL("currentChanged()"))

    def event(self, event):
        """ Overrides the main event handler to catch resize events """
        # Catch Resize event
        if event.type() == QEvent.Resize:
            # Update each page size limits to mainwidget's new size
            for page in self.__pages:
                page.widget.setMinimumSize(self.size())
                page.widget.setMaximumSize(self.size())
#.........这里部分代码省略.........
开发者ID:Pardus-Linux,项目名称:pds,代码行数:103,代码来源:qpagewidget.py


注:本文中的PyQt4.QtCore.QTimeLine.setDuration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。