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_())





-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/a189b4f6-176f-42b7-aa9a-699dfe4e1ebb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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_())

Reply via email to