class LaueImage(QtGui.QWidget): def __init__(self, parent, _name): QtGui.QWidget.__init__(self, parent) self.name=os.path.split(_name)[1] self.fullImg=Image.open(_name) self.VRGB_BezierParams=[[], [], [], []] initParams=[[(0, 0), (1, 1)], [(0, 0), (1, 1)], [(0, 0), (1, 1)], [(0, 0), (1, 1)]] self.transfer=ImageTransfer() self.resizeImg(self.size()) self.setTransferCurves(initParams) sp=self.sizePolicy() #sp.setHeightForWidth(True) sp.setHorizontalPolicy(QtGui.QSizePolicy.Expanding) sp.setVerticalPolicy(QtGui.QSizePolicy.Expanding) self.setSizePolicy(sp) def resizeEvent(self, e): #QtGui.QWidget.resizeEvent(self, e) self.resizeImg(e.size()) def resizeImg(self, size): s=QtCore.QSize(self.fullImg.width, self.fullImg.height) s.scale(size, QtCore.Qt.KeepAspectRatio) print 'Size',self.width(), self.height() , s.width(), s.height() self.scaledImg=self.fullImg.resize((s.width(), s.height())) mode=None if self.scaledImg.mode=='RGB': mode=1 elif self.scaledImg.mode=='F': mode=0 if mode!=None: self.transfer.setData(s.width(), s.height(), mode, self.scaledImg.tostring()) def paintEvent(self, e): p=QtGui.QPainter(self) s=self.transfer.qImg().size() x=(self.width()-s.width())/2 y=(self.height()-s.height())/2 p.drawImage(x, y, self.transfer.qImg()) def setTransferCurves(self, newParams): curvesChanged=False for i, pa in enumerate(zip(newParams, self.VRGB_BezierParams)): pn,po=pa if pn!=po: self.VRGB_BezierParams[i]=pn curvesChanged=True if curvesChanged: for i in range(4): c=BezierCurve(*zip(*self.VRGB_BezierParams[i])) p1=c.x[1:] p2=reduce(lambda x, y:x+y, c.D) self.transfer.setTransferCurve(i, p1, p2) self.update()