Re: [Maya-Python] A turntable player

2018-06-27 Thread Panupat Chongstitwattana
Figured another one out thanks to Stackoverflow. https://stackoverflow.com/questions/43454882/paint-over-qlabel-with-pyqt My paintEvent was done on QWidget, which was behind QLabel. Once the QLabel got stylesheet'd it covered up my image I suppose. So paintEvent needed to be implemented on the

Re: [Maya-Python] A turntable player

2018-06-26 Thread Panupat Chongstitwattana
Ran into a problem. When I set qdarkstyle, the images no longer showed up. Neither load_stylesheet nor load_stylesheet_pyside worked. environ['QT_API'] = 'pyside' app = QApplication(sys.argv) app.setStyleSheet(qdarkstyle.load_stylesheet()) SCRUB = ScrubbaleImageSequenceWidget(images) # SCRUB =

Re: [Maya-Python] A turntable player

2018-06-26 Thread Justin Israel
QPixmapCache is a good candidate if you want to preload your images. There is already a global cache that gets used anyways when you load QPixmaps from files. You can insert them ahead of time if you want: https://doc-snapshots.qt.io/qtforpython/PySide2/QtGui/QPixmapCache.html When you load your

Re: [Maya-Python] A turntable player

2018-06-26 Thread Panupat Chongstitwattana
By the way I went with QPainter because it's the only way I could find how to control opacity. Is opacity possible if I use QPixmap? -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and

Re: [Maya-Python] A turntable player

2018-06-26 Thread Panupat Chongstitwattana
Thank you everyone for your help. Learned a lot from this simple widget. My current working code. If there's any room for adjustment please let me know :) Been thinking that it would be great to pre-load image sequences in advance. Maybe create pixmap for each of them and store in a list? #

Re: [Maya-Python] A turntable player

2018-06-26 Thread Justin Israel
You have two options two choose from, but you are actually currently doing a mixture of both. 1) use a QPainter(self) (as per your example) and paint the icon manually, from your stored self.pic. If you do this, you need to not set the pixmap onto the QLabel, otherwise you will get the paint

Re: [Maya-Python] A turntable player

2018-06-26 Thread Panupat Chongstitwattana
I see. Thank you again Justin. Moving to another functionality. I want to add a default icon with lowered opacity when calling without passing images attribute. It is hard-coded right now. if not images or not isinstance(images, list): self.disable = True self.images =

Re: [Maya-Python] A turntable player

2018-06-25 Thread Justin Israel
self.pic.scaled() returns a new scalled QPixmap instance. So calling it the way you doing is having no actual effect. You aren't doing anything with the return value. That is why you have to pass a new scaled QPixmap into the QLabel, which retains the aspect ratio. Justin On Tue, Jun 26, 2018

Re: [Maya-Python] A turntable player

2018-06-25 Thread Panupat Chongstitwattana
Thank you Justin. Wow so by setting minimal size it allows going smaller. I wouldn't have suspected that. By the way is it OK to call setPixmap over and over like I did in resizeEvent? It seems a bit redundant. def resizeEvent(self, event): self.label.setPixmap(

Re: [Maya-Python] A turntable player

2018-06-25 Thread Panupat Chongstitwattana
That works. Thanks Justin. At the moment I do setPixmap repeatedly on resizeEvent. Is that normal? I tried self.pic.scaled and self.label.repaint but those 2 don't seem to have any effect. Not working def resizeEvent(self, event): self.pic.scaled(self.label.width(), self.label.height(),

Re: [Maya-Python] A turntable player

2018-06-25 Thread Justin Israel
On Tue, Jun 26, 2018, 12:39 AM Panupat Chongstitwattana wrote: > Question on Pixmap resizing. > > I tried switching from fixed size to allow resizing. > This is what I have at the moment and what happens is that I can increase > my widget size, > but it won't let me decrease. How should I

Re: [Maya-Python] A turntable player

2018-06-25 Thread Justin Israel
On Tue, Jun 26, 2018, 12:32 AM Panupat Chongstitwattana wrote: > Thank you for your suggestion Justin. Did you mean the mouseMoveEvent > method? Made some adjustments and is working as intended. > Yep, that was what I meant. In a previous example you had alot of repeat checking of the event

Re: [Maya-Python] A turntable player

2018-06-25 Thread Panupat Chongstitwattana
Question on Pixmap resizing. I tried switching from fixed size to allow resizing. This is what I have at the moment and what happens is that I can increase my widget size, but it won't let me decrease. How should I approach this? in __init__ self.pic = QPixmap(self.images[self.image_index]) #

Re: [Maya-Python] A turntable player

2018-06-25 Thread Panupat Chongstitwattana
Thank you for your suggestion Justin. Did you mean the mouseMoveEvent method? Made some adjustments and is working as intended. def mouseMoveEvent(self, event): if not self.tracking: return distance = self.mouse_start - event.x() if distance >= self.mouse_threshold:

Re: [Maya-Python] A turntable player

2018-06-25 Thread Justin Israel
One last tip about the event handlers. It might be good for you to make use of if/elif instead of comparing extra cases that will never be true since another event is going to match. It's just wasteful comparisons. Justin On Mon, Jun 25, 2018, 7:30 PM Marcus Ottosson wrote: > Sometimes. In the

Re: [Maya-Python] A turntable player

2018-06-25 Thread Marcus Ottosson
Sometimes. In the case of closeEvent, calling it would close the GUI I think so you’d probably want your code to run first. In general, it depends on whether you want something done before or after the superclass implementation. In your case, someone overriding your mouseMoveEvent would have to

Re: [Maya-Python] A turntable player

2018-06-25 Thread Panupat Chongstitwattana
I see. Does it matter if you call super first thing or last thing in the method override? On Monday, June 25, 2018 at 2:14:36 PM UTC+7, Marcus Ottosson wrote: > > You are most welcome. > > in what instances would you want, or need, to do that? > > If you’re inheriting from a class that already

Re: [Maya-Python] A turntable player

2018-06-25 Thread Marcus Ottosson
You are most welcome. in what instances would you want, or need, to do that? If you’re inheriting from a class that already subclasses those, it’d be useful for when you want to add to the original behavior. Otherwise you’d be replacing it. For example, anyone inheriting from the class you’re

Re: [Maya-Python] A turntable player

2018-06-25 Thread Panupat Chongstitwattana
Thank you Marcus. Here's the updated methods and it's working as intended. def mousePressEvent(self, event): if event.button() == QtCore.Qt.LeftButton: self.mouse_start = event.x() self.tracking = True def mouseReleaseEvent(self, event): if event.button() ==

Re: [Maya-Python] A turntable player

2018-06-25 Thread Marcus Ottosson
Using an event filter is a little heavy handed for what you’re trying to achieve, I think. The problem with it is that every event, including draw events, passes through your event filter waiting for it to either block the event - return True - or pass it through - return False. And the number of

Re: [Maya-Python] A turntable player

2018-06-25 Thread Panupat Chongstitwattana
Got it working now with more returns added to the eventFilter. def eventFilter(self, obj, event): if event.type() == event.MouseButtonPress: if event.button() == QtCore.Qt.LeftButton: self.mouse_start = event.x() self.tracking = True event.accept()

Re: [Maya-Python] A turntable player

2018-06-24 Thread Panupat Chongstitwattana
Thank you for your suggestion Marcus. I added MouseButtonPress and MouseButtonRelease event based on your suggestion and it almost work. I cannot get the image to repaint. It prints out the image name correctly however. I way to get the repaint working is to remove return True (line 51) from