[PyQt] qthread an pil

Krzysztof k4chim at gmail.com
Tue Dec 9 12:01:17 GMT 2008


Hi,
I can't get why code below doesn't work properly in thread.
actionThread is class which inherrits from QThread. I start this
thread with start method. When quantize method is invoked for
imageOryg, my gui freezes. When I tested this code with simple:
while(True):
       print "text"
instead of quantize, everything was fine, my gui didn't freeze. What
can be the reason? Thx in advance.

Regards,
Krzychu


        self.graphAction = GAct
        self.thAction = actionThread(self.transformImageAndQLoad)
        ...
        self.thAction.start()

   def transformImageAndQLoad(self):
        self.graphAction.transform()

===============================================

class GQuantizeAction(GTransformAction):
        def __init__(self, im, factor):
                GTransformAction.__init__(self)
#               self.imageOryg = im
                self.imageOryg = Image.open("test.jpg")
                self.factor = factor
        def quantize(self):
                self.imageTransform = self.imageOryg.quantize(self.factor)
                self.imageTransform = self.imageTransform.convert("RGB")
        def transform(self):
                self.quantize()

=============================================
class actionThread(QtCore.QThread):
    def __init__(self, act, parent = None):
        QtCore.QThread.__init__(self, parent)
        self.action = act
    def run(self):
        self.action()


More information about the PyQt mailing list