Example #1
0
 def slotActionOpenFile(self):
     #print 'openfile!'
     fileName = unicode(QtGui.QFileDialog.getOpenFileName(self,'Open Image',' ','FITS Files (*.fits *.fit *.fts);;HDR Images (*.exr);;Images (*.tiff *.tif *.png *.jpeg *.jpg *.bmp *.dib *.jpe *.pbm *.pgm *.ppm *.sr *.ras *.jp2);;All (*)'))
     #print fileName 
     
     #Open FITS image file
     #http://www.stsci.edu/resources/software_hardware/pyfits/
     #http://www.stsci.edu/resources/software_hardware/pyfits/Download
     if fileName.lower().endswith('.fits') or fileName.lower().endswith('.fit') or fileName.lower().endswith('.fts') :
         #print 'opening fits file'
         global impreview
         impreview=ImagePreviewWidget(fileName)
         impreview.show()
Example #2
0
class ImageTableModel(QtCore.QAbstractTableModel):

    def __init__(self, images,colormap):
        QtCore.QAbstractTableModel.__init__(self)
        self.images = images
        self.fields = ['IMAGETYP', 'FILTER', 'EXPTIME', 'CCD-TEMP', 'XBINNING', 'YBINNING', 'DATE-OBS']
        self.cols=1
        self.margin=0  
        self.noprevthumb=QPixmap.fromImage(QImage(":/images/nopreview.png"))         
   
    def rowCount(self, parent):
        return  ((len(self.images)-1)/self.cols)+1

    def columnCount(self, parent):
        return self.cols

    def data(self, index, role):     
        #print role
        if role == Qt.SizeHintRole:
            return QSize(max(384,384+self.margin/self.cols-1), 125)
        n=index.column()+index.row()*self.cols   
        if role == Qt.DisplayRole:
            if n < len(self.images):
                displayString = os.path.basename(self.images[n]) + '\n'
                hdulist = pyfits.open(self.images[n])
                for s in self.fields:
                    try:
                        displayString = displayString + s + ' = ' +str(hdulist[0].header[s])
                        displayString = displayString + '\n'
                    except KeyError:
                        pass
                return displayString

        elif role == Qt.DecorationRole:
            if n < len(self.images):
                if self.images[n] in thumbs :
                    return QPixmap.fromImage(thumbs[self.images[n]])
                else :
                    return self.noprevthumb
                    
        elif role ==Qt.AccessibleTextRole:    
            return os.path.abspath(self.images[n])

    def viewResized(self, width, height):      
        self.emit(SIGNAL("layoutAboutToBeChanged()"))
        self.cols=max(width/384,1)
        self.margin=max(width-self.cols*384,0)
        self.emit(SIGNAL("layoutChanged()"))
        
    def sort(self, field):
        self.sortingField=field
        self.images.sort(key=self.cmp)
        self.emit(SIGNAL("layoutChanged()"))
        
    def cmp(self, image):
        hdulist = pyfits.open(image)
        prihdr = hdulist[0].header
        if self.sortingField in prihdr.ascardlist().keys():
            return prihdr[self.sortingField]
        else:
            return 'ZZZZZZZZZZZZZZ'+image
            
    def doubleClick(self,i):
        self.w=ImagePreviewWidget(self.data(i,role=Qt.AccessibleTextRole))
        self.w.show()
        print 'click',self.data(i,role=Qt.AccessibleTextRole)
Example #3
0
 def doubleClick(self,i):
     self.w=ImagePreviewWidget(self.data(i,role=Qt.AccessibleTextRole))
     self.w.show()
     print 'click',self.data(i,role=Qt.AccessibleTextRole)