PEATDB/Labbook.py
def draw_file_tooltip(self, row, col):
        """Draw a tooltip for image and file previews"""
        import os
        h=self.height
        x1,y1,x2,y2 = self.getCellCoords(row,col)
        w=x2-x1
        absrow = self.get_AbsoluteRow(row)
        text = self.model.getValueAt(absrow,col)
        if text == '' or text == None:
            return

        #actual blob data is stored in parent db blob attr
        cell = self.model.getCellRecord(absrow,col)
        key = cell['filename']
        rec = self.DB.blobs[key]
        myblob = rec.blob

        if myblob != None:
            f = myblob.open("r")
            filename = f.name
        else:
            filename=None

        extension = text.split('.')[-1]
        if extension in ['jpg','jpeg','tiff','tif','gif','ps','png','ico']:
            extension = 'img'
        if extension in ['gz','bz','jar']:
            extension = 'zip'
        if not self.fileicons.has_key(extension):
            extension = 'other'

        #Check if its an image and try to make thumbnail.. needs PIL
        if extension == 'img' and filename != None:
            self.pic = self.get_image_thumb(filename)
            isthumb=1
        #if can't get thumb, just create icon for the file type
        if self.pic == None:
            import File_images
            func = getattr(File_images, self.fileicons[extension])
            self.pic = func()
            isthumb=0

        imgobj = self.create_image(x1+w/1.5,y2+2, image=self.pic, anchor='nw')
        if isthumb == 1:
            box = self.bbox(imgobj)
            xa=box[0]-1
            ya=box[1]-1
            xb=box[2]+1
            yb=box[3]+1
            self.create_rectangle(xa,ya,xb,yb,tag='tooltip',fill='black')
            self.lift(imgobj)

        #now draw text
        import tkFont
        sfont = tkFont.Font (family='Arial', size=12, weight='bold')
        obj=self.create_text(x1+w/1.5,y2,text=text,
                                anchor='sw',
                                font=sfont,tag='tooltip')
        box = self.bbox(obj)
        x1=box[0]
        y1=box[1]
        x2=box[2]+1
        y2=box[3]+1
        self.create_rectangle(x1+1,y1+1,x2+1,y2+1,tag='tooltip',fill='black')
        self.create_rectangle(x1,y1,x2,y2,tag='tooltip',fill='lightyellow')
        self.lift(obj)
        return
Draw a tooltip for image and file previews
Draw a tooltip for image and file previews
Draw a tooltip for image and file previews
def draw_file_tooltip(self, row, col):
        import os
        h=self.height
        x1,y1,x2,y2 = self.getCellCoords(row,col)
        w=x2-x1
        absrow = self.get_AbsoluteRow(row)
        text = self.model.getValueAt(absrow,col)
        if text == '' or text == None:
            return
        cell = self.model.getCellRecord(absrow,col)
        key = cell['filename']
        rec = self.DB.blobs[key]
        myblob = rec.blob
        if myblob != None:
            f = myblob.open("r")
            filename = f.name
        else:
            filename=None
        extension = text.split('.')[-1]
        if extension in ['jpg','jpeg','tiff','tif','gif','ps','png','ico']:
            extension = 'img'
        if extension in ['gz','bz','jar']:
            extension = 'zip'
        if not self.fileicons.has_key(extension):
            extension = 'other'
        if extension == 'img' and filename != None:
            self.pic = self.get_image_thumb(filename)
            isthumb=1
        if self.pic == None:
            import File_images
            func = getattr(File_images, self.fileicons[extension])
            self.pic = func()
            isthumb=0
        imgobj = self.create_image(x1+w/1.5,y2+2, image=self.pic, anchor='nw')
        if isthumb == 1:
            box = self.bbox(imgobj)
            xa=box[0]-1
            ya=box[1]-1
            xb=box[2]+1
            yb=box[3]+1
            self.create_rectangle(xa,ya,xb,yb,tag='tooltip',fill='black')
            self.lift(imgobj)
        import tkFont
        sfont = tkFont.Font (family='Arial', size=12, weight='bold')
        obj=self.create_text(x1+w/1.5,y2,text=text,
                                anchor='sw',
                                font=sfont,tag='tooltip')
        box = self.bbox(obj)
        x1=box[0]
        y1=box[1]
        x2=box[2]+1
        y2=box[3]+1
        self.create_rectangle(x1+1,y1+1,x2+1,y2+1,tag='tooltip',fill='black')
        self.create_rectangle(x1,y1,x2,y2,tag='tooltip',fill='lightyellow')
        self.lift(obj)
        return
def draw_file_tooltip ( self , row , col ) : import os h = self . height x1 , y1 , x2 , y2 = self . getCellCoords ( row , col ) w = x2 - x1 absrow = self . get_AbsoluteRow ( row ) text = self . model . getValueAt ( absrow , col ) if text == '' or text == None : return cell = self . model . getCellRecord ( absrow , col ) key = cell [ 'filename' ] rec = self . DB . blobs [ key ] myblob = rec . blob if myblob != None : f = myblob . open ( "r" ) filename = f . name else : filename = None extension = text . split ( '.' ) [ - 1 ] if extension in [ 'jpg' , 'jpeg' , 'tiff' , 'tif' , 'gif' , 'ps' , 'png' , 'ico' ] : extension = 'img' if extension in [ 'gz' , 'bz' , 'jar' ] : extension = 'zip' if not self . fileicons . has_key ( extension ) : extension = 'other' if extension == 'img' and filename != None : self . pic = self . get_image_thumb ( filename ) isthumb = 1 if self . pic == None : import File_images func = getattr ( File_images , self . fileicons [ extension ] ) self . pic = func ( ) isthumb = 0 imgobj = self . create_image ( x1 + w / 1.5 , y2 + 2 , image = self . pic , anchor = 'nw' ) if isthumb == 1 : box = self . bbox ( imgobj ) xa = box [ 0 ] - 1 ya = box [ 1 ] - 1 xb = box [ 2 ] + 1 yb = box [ 3 ] + 1 self . create_rectangle ( xa , ya , xb , yb , tag = 'tooltip' , fill = 'black' ) self . lift ( imgobj ) import tkFont sfont = tkFont . Font ( family = 'Arial' , size = 12 , weight = 'bold' ) obj = self . create_text ( x1 + w / 1.5 , y2 , text = text , anchor = 'sw' , font = sfont , tag = 'tooltip' ) box = self . bbox ( obj ) x1 = box [ 0 ] y1 = box [ 1 ] x2 = box [ 2 ] + 1 y2 = box [ 3 ] + 1 self . create_rectangle ( x1 + 1 , y1 + 1 , x2 + 1 , y2 + 1 , tag = 'tooltip' , fill = 'black' ) self . create_rectangle ( x1 , y1 , x2 , y2 , tag = 'tooltip' , fill = 'lightyellow' ) self . lift ( obj ) return
Draw a tooltip for image and file previews
Draw a tooltip for image and file previews
"""Draw a tooltip for image and file previews""" #actual blob data is stored in parent db blob attr #Check if its an image and try to make thumbnail.. needs PIL #if can't get thumb, just create icon for the file type #now draw text
self
row
col