Created
November 2, 2012 10:28
-
-
Save Svenito/4000025 to your computer and use it in GitHub Desktop.
Python class to play an animated gif using PyQt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImagePlayer(QWidget): | |
def __init__(self, filename, title, parent=None): | |
QWidget.__init__(self, parent) | |
# Load the file into a QMovie | |
self.movie = QMovie(filename, QByteArray(), self) | |
size = self.movie.scaledSize() | |
self.setGeometry(200, 200, size.width(), size.height()) | |
self.setWindowTitle(title) | |
self.movie_screen = QLabel() | |
# Make label fit the gif | |
self.movie_screen.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) | |
self.movie_screen.setAlignment(Qt.AlignCenter) | |
# Create the layout | |
main_layout = QVBoxLayout() | |
main_layout.addWidget(self.movie_screen) | |
self.setLayout(main_layout) | |
# Add the QMovie object to the label | |
self.movie.setCacheMode(QMovie.CacheAll) | |
self.movie.setSpeed(100) | |
self.movie_screen.setMovie(self.movie) | |
self.movie.start() |
When i use this class like this:
if __name__ == "__main__": gif = "dotGreen.gif" app = QApplication(sys.argv) player = ImagePlayer(gif, "was") player.show() sys.exit(app.exec_())
The Animation stops after one loop.
try this: self.movie.loopCount(-1)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When i use this class like this:
The Animation stops after one loop.