Hi.
I'm trying to create a turntable viewer and in need of some guidance
please. In this view, I want to be able to click and hold left mouse button
then drag left/right to turn the turntable, which are image sequences.
My questions:
- Is there other way I should approach this? The mouse move event triggers
too fast and when I try to print out new image names they appear too
rapidly.
- How can I detect if I am moving mouse left or right?
- The pixmap doesn't seem to repaint even if I explicitly tells it to.
Appreciate any help. Thank you!
--
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/d0541c00-46a5-42da-9cef-36e66ae76813%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
# -*- coding: utf-8 -*-
import sys
from os.path import dirname, realpath, join
from PySide.QtGui import (QApplication, QVBoxLayout, QLabel, QPixmap,
QWidget)
from PySide import QtCore
class PlayTurntable(QWidget):
def __init__(self, images, parent=None):
super(PlayTurntable, self).__init__(parent)
self.label = QLabel()
self.label.setFixedWidth(300)
self.label.setFixedHeight(200)
layout = QVBoxLayout()
layout.addWidget(self.label)
self.setLayout(layout)
self.images = images
self.image_index = 0
self.pic = QPixmap(self.images[self.image_index])
self.label.setPixmap(self.pic.scaled(300, 200, QtCore.Qt.KeepAspectRatio))
self.installEventFilter(self)
def eventFilter(self, obj, event):
if event.type() == event.MouseMove:
if event.buttons() == QtCore.Qt.LeftButton:
self.increase_pic()
event.accept()
return True
return True
def increase_pic(self):
self.image_index += 1
if self.image_index >= len(self.images):
self.image_index = 0
self.pic.load(self.images[self.image_index])
self.label.setPixmap(
self.pic.scaled(300, 200, QtCore.Qt.KeepAspectRatio))
self.label.repaint()
if __name__=='__main__':
current_path = dirname(realpath(__file__))
images = ['turn1.jpg', 'turn2.jpg', 'turn3.jpg', 'turn4.jpg']
for index, value in enumerate(images):
images[index] = join(current_path, value)
app = QApplication(sys.argv)
PT = PlayTurntable(images)
PT.show()
sys.exit(app.exec_())