Animated Gif Widget triggered during mouse Hover Over

685 views
Skip to first unread message

Antonio Govela

unread,
Sep 9, 2015, 12:36:17 AM9/9/15
to Python Programming for Autodesk Maya
Hi, I'm still trying to wrap my head around events and trying to start an animated gif 'splashed' on a widget.
I can manage to detect when the mouse hovers in and out to display a start and stop  but I can't seem to find how to trigger the movie.start() action.


I mashed up bits of code form other sites to display a window with an animated gif.

Any clues would be helpful...
here's the code (any animated gif should work)



from PySide import QtGui, QtCore
import PySide.QtCore as qc
import PySide.QtGui  as qg

from PySide.QtCore import Signal,Slot

import sys, time
from PySide.QtCore import Qt, QTimer
from PySide.QtGui import *


import sys
from PySide.QtCore import *
from PySide.QtGui import *


class Window(QtGui.QWidget):
class MovieSplashScreen(QSplashScreen):

def __init__(self, movie, parent = None):
movie.jumpToFrame(0)
pixmap = QPixmap(movie.frameRect().size())
QSplashScreen.__init__(self, pixmap)
self.movie = movie
self.movie.frameChanged.connect(self.repaint)
def showEvent(self, event):
self.movie.start()
def hideEvent(self, event):
self.movie.stop()
def paintEvent(self, event):
painter = QPainter(self)
pixmap = self.movie.currentPixmap()
self.setMask(pixmap.mask())
painter.drawPixmap(0, 0, pixmap)
def sizeHint(self):
return self.movie.scaledSize()
class animWidget(QtGui.QWidget):
mStart = Signal()
mStop = Signal()
zeros = 0
def __init__(self,parent=None):
QtGui.QWidget.__init__(self)
self._last_index = QtCore.QPersistentModelIndex()
self.installEventFilter(self)
def eventFilter(self, widget, event):
if event.type() == QtCore.QEvent.MouseMove:
print "Starting..."
self.mStart.emit()
self.startMovie()
self.emit(SIGNAL("mStart"))
 
elif event.type() == QtCore.QEvent.Leave:
print "Pausing"
self.mStop.emit()
return QtGui.QTableWidget.eventFilter(self, widget, event)
def startMovie(self,*args):
print "xxx"
#self.start()

def __init__(self, rows, columns):
QtGui.QWidget.__init__(self)
self.anim = self.animWidget(self)
self.anim.setMouseTracking(True)
self.animLayout = QtGui.QHBoxLayout()
self.anim.setLayout (self.animLayout)
layout = QtGui.QVBoxLayout(self)
movie = qg.QMovie("d:/cutebunny.gif")
self.movie = movie
splash = MovieSplashScreen(movie)
self.animGif = qg.QLabel(self)
self.animGif.setMovie(movie)
#self.movie.start()
self.animLayout.addWidget(self.animGif)
layout.addWidget(self.anim)
#self.movie.connect(SIGNAL("START"), self.startMovie)
#self.movie.connect(SIGNAL("mSTART"), self.startMovie)

        
        
  
     
        
        
        


if __name__ == '__main__':

    import sys
    #app = QtGui.QApplication(sys.argv)
    window = Window(6, 3)
    window.setGeometry(500, 300, 350, 250)
    window.show()
    
    
    #sys.exit(app.exec_())





animGif.py
Message has been deleted

Antonio Govela

unread,
Sep 9, 2015, 1:30:39 AM9/9/15
to Python Programming for Autodesk Maya
I cleaned up the code a bit...I just realized since I hadn't restarted maya for a while, the code was not working because I moved a class around.
Still stuck though.

Thanks!


code:




from PySide import QtGui
from PySide import QtCore
import PySide.QtCore as qc
import PySide.QtGui  as qg
from PySide.QtCore import *
from PySide.QtGui import *


class MovieSplashScreen(QSplashScreen):

def __init__(self, movie, parent = None):
movie.jumpToFrame(0)
pixmap = QPixmap(movie.frameRect().size())
QSplashScreen.__init__(self, pixmap)
self.movie = movie
self.movie.frameChanged.connect(self.repaint)
def showEvent(self, event):
self.movie.start()
def hideEvent(self, event):
self.movie.stop()
def paintEvent(self, event):
painter = QPainter(self)
pixmap = self.movie.currentPixmap()
self.setMask(pixmap.mask())
painter.drawPixmap(0, 0, pixmap)
def sizeHint(self):
return self.movie.scaledSize()


class Window(QtGui.QWidget):
class animWidget(QtGui.QWidget):
mStart = Signal()
mStop = Signal()
START = Signal ()
zeros = 0
def __init__(self,parent=None):
QtGui.QWidget.__init__(self)
self._last_index = QtCore.QPersistentModelIndex()
self.installEventFilter(self)
def eventFilter(self, widget, event):
if event.type() == QtCore.QEvent.MouseMove:
print "Starting..."
#self.mStart.emit()
#self.startMovie()
self.START.emit()
self.emit(SIGNAL("mStart"))
self.emit(SIGNAL("START"))
elif event.type() == QtCore.QEvent.Leave:
print "Pausing"
self.mStop.emit()
return QtGui.QTableWidget.eventFilter(self, widget, event)
def startMovie(self,*args):
print "zzz"
#self.start()

def __init__(self, rows, columns):
QtGui.QWidget.__init__(self)
self.anim = self.animWidget(self)
self.anim.setMouseTracking(True)
self.animLayout = QtGui.QHBoxLayout()
self.anim.setLayout (self.animLayout)
layout = QtGui.QVBoxLayout(self)
movie = qg.QMovie("d:/cutebunny.gif")
self.movie = movie
splash = MovieSplashScreen(movie)
self.animGif = qg.QLabel(self)
self.animGif.setMovie(movie)
#self.movie.start()
self.animLayout.addWidget(self.animGif)
layout.addWidget(self.anim)
#self.anim.connect(SIGNAL("START"), self.startMovieX)
#self.anim.connect(SIGNAL("mSTART"), self.startMovieX)
def startMovieX(self,*args):
print "xxx"
#self.movie.start()
if __name__ == '__main__':

    import sys
    #app = QtGui.QApplication(sys.argv)
    window = Window(6, 3)
    window.setGeometry(500, 300, 350, 250)
    window.show()
    
    
    #sys.exit(app.exec_())

Justin Israel

unread,
Sep 9, 2015, 5:35:05 PM9/9/15
to Python Programming for Autodesk Maya
Can you please just use a pastebin? This code is hard to read. I'm also having trouble following some of the usages in here... such as the persistent model index, and calling to the QTableWidget eventFilter, randomly.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d164c8e5-96c0-4974-806c-5307342f8b86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonio Govela

unread,
Sep 9, 2015, 6:17:02 PM9/9/15
to Python Programming for Autodesk Maya
Sorry.. it was late and was getting kinda lost. So I managed to clean the code and actually trigger an animated gif widget using events. <ultiple widgets can be added with classes and respond independently to the 'hover over and leave' mouse tracking.
 
Here's the code: http://pastebin.com/C43HwDgi fully functional...

My question would then be: is using the event filter better than trying to use signals or vice versa, and how can this be done using signals to trigger events like start, stop and reset.

Thanks!

Antonio

 

Kurian O.S

unread,
Sep 9, 2015, 6:28:03 PM9/9/15
to python_in...@googlegroups.com
http://pyqt.sourceforge.net/Docs/PyQt4/qmovie.html#started did you check the default signals from QMovie ?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
--:: Kurian ::--

Justin Israel

unread,
Sep 9, 2015, 6:59:06 PM9/9/15
to python_in...@googlegroups.com
Thanks for doing the pastebin. Much better.

Wouldn't the event trigger at each pixel move, and call start? Also, you don't need to install an event filter if you are installing it on itself. It would be the same as just reimplementing event() on that class. 



Antonio Govela

unread,
Sep 9, 2015, 7:10:05 PM9/9/15
to Python Programming for Autodesk Maya
The MouseMove event seems to  trigger the movie.start only once. so even if the event keeps triggering with a slight mouse move (which it does) the gif plays through and loops, which is the functionality I was looking for. 
I'm looking into your suggestion about reimplementing event() on the class....


Thanks!


pdw...@gmail.com

unread,
Mar 9, 2020, 8:26:51 PM3/9/20
to Python Programming for Autodesk Maya
Thanks for posting this - I used it and it works perfectly for my needs.
Reply all
Reply to author
Forward
0 new messages