(self, icon_name, size=None)
return icon
draw default icons, return icon drawing
draw default icons, return icon drawing
draw default icons return icon drawing
def create_icon(self, icon_name, size=None):
        '''
        draw default icons, return icon drawing
        '''
        if not HAVE_PIL:
            return None
            
        if not size:
            size = self.size
            
        if icon_name in ['roomba', 'stuck', 'cancelled']:
            icon = self.base_icon.copy().resize(size,Image.ANTIALIAS)
        else:
            icon = Image.new('RGBA', size, transparent)
        draw_icon = ImageDraw.Draw(icon)
        if icon_name in ['stuck', 'cancelled']:
            draw_icon.pieslice([(5,5),(icon.size[0]-5,icon.size[1]-5)],
                175, 185, fill="red", outline="red")

        if icon_name == "roomba":
            draw_icon.pieslice([(5,5),(icon.size[0]-5,icon.size[1]-5)],
                355, 5, fill="red", outline="red")
        elif icon_name == "cancelled":
            if self.fnt is not None:
                draw_icon.text((4,-4), "X", font=self.fnt, fill=(255,0,0,255))
        elif icon_name == "stuck":
            draw_icon.polygon([(
                icon.size[0]//2,icon.size[1]), (0, 0), (0,icon.size[1])],
                fill = 'red')
            if self.fnt is not None:
                draw_icon.text((4,-4), "!", font=self.fnt,
                    fill=(255,255,255,255))
        elif icon_name == "bin full":
            draw_icon.rectangle([
                icon.size[0]-10, icon.size[1]-10,
                icon.size[0]+10, icon.size[1]+10],
                fill = "grey")
            if self.fnt is not None:
                draw_icon.text((4,-4), "F", font=self.fnt,
                    fill=(255,255,255,255))
        elif icon_name == "tank low":
            draw_icon.rectangle([
                icon.size[0]-10, icon.size[1]-10,
                icon.size[0]+10, icon.size[1]+10],
                fill = "blue")
            if self.fnt is not None:
                draw_icon.text((4,-4), "L", font=self.fnt,
                    fill=(255,255,255,255))
        elif icon_name == "battery":
            draw_icon.rectangle([icon.size[0]-10, icon.size[1]-10,
                icon.size[0]+10,icon.size[1]+10], fill = "orange")
            if self.fnt is not None:
                draw_icon.text((4,-4), "B", font=self.fnt,
                    fill=(255,255,255,255))
        elif icon_name == "home":
            draw_icon.rectangle([0,0,32,32], fill="red", outline="black")
            if self.fnt is not None:
                draw_icon.text((4,-4), "D", font=self.fnt,
                    fill=(255,255,255,255))
        else:
            return None
        #rotate icon 180 degrees
        icon = icon.rotate(180-self.angle, expand=False)
        return icon
def create_icon ( self , icon_name , size = None ) : if not HAVE_PIL : return None if not size : size = self . size if icon_name in [ 'roomba' , 'stuck' , 'cancelled' ] : icon = self . base_icon . copy ( ) . resize ( size , Image . ANTIALIAS ) else : icon = Image . new ( 'RGBA' , size , transparent ) draw_icon = ImageDraw . Draw ( icon ) if icon_name in [ 'stuck' , 'cancelled' ] : draw_icon . pieslice ( [ ( 5 , 5 ) , ( icon . size [ 0 ] - 5 , icon . size [ 1 ] - 5 ) ] , 175 , 185 , fill = "red" , outline = "red" ) if icon_name == "roomba" : draw_icon . pieslice ( [ ( 5 , 5 ) , ( icon . size [ 0 ] - 5 , icon . size [ 1 ] - 5 ) ] , 355 , 5 , fill = "red" , outline = "red" ) elif icon_name == "cancelled" : if self . fnt is not None : draw_icon . text ( ( 4 , - 4 ) , "X" , font = self . fnt , fill = ( 255 , 0 , 0 , 255 ) ) elif icon_name == "stuck" : draw_icon . polygon ( [ ( icon . size [ 0 ] // 2 , icon . size [ 1 ] ) , ( 0 , 0 ) , ( 0 , icon . size [ 1 ] ) ] , fill = 'red' ) if self . fnt is not None : draw_icon . text ( ( 4 , - 4 ) , "!" , font = self . fnt , fill = ( 255 , 255 , 255 , 255 ) ) elif icon_name == "bin full" : draw_icon . rectangle ( [ icon . size [ 0 ] - 10 , icon . size [ 1 ] - 10 , icon . size [ 0 ] + 10 , icon . size [ 1 ] + 10 ] , fill = "grey" ) if self . fnt is not None : draw_icon . text ( ( 4 , - 4 ) , "F" , font = self . fnt , fill = ( 255 , 255 , 255 , 255 ) ) elif icon_name == "tank low" : draw_icon . rectangle ( [ icon . size [ 0 ] - 10 , icon . size [ 1 ] - 10 , icon . size [ 0 ] + 10 , icon . size [ 1 ] + 10 ] , fill = "blue" ) if self . fnt is not None : draw_icon . text ( ( 4 , - 4 ) , "L" , font = self . fnt , fill = ( 255 , 255 , 255 , 255 ) ) elif icon_name == "battery" : draw_icon . rectangle ( [ icon . size [ 0 ] - 10 , icon . size [ 1 ] - 10 , icon . size [ 0 ] + 10 , icon . size [ 1 ] + 10 ] , fill = "orange" ) if self . fnt is not None : draw_icon . text ( ( 4 , - 4 ) , "B" , font = self . fnt , fill = ( 255 , 255 , 255 , 255 ) ) elif icon_name == "home" : draw_icon . rectangle ( [ 0 , 0 , 32 , 32 ] , fill = "red" , outline = "black" ) if self . fnt is not None : draw_icon . text ( ( 4 , - 4 ) , "D" , font = self . fnt , fill = ( 255 , 255 , 255 , 255 ) ) else : return None #rotate icon 180 degrees icon = icon . rotate ( 180 - self . angle , expand = False ) return icon