# -*- encoding: utf-8 -*- import Image import ImageDraw import ImageFont import math import addons ROUNDED = 30 BGCOLOR = (228,233,237) TITLECOLOR = (150,70,70) FONT = addons.get_module_resource('process', 'report/sb.ttf') BOXSIZE = (160,120) size = 800,600 class draw(object): def _rounding_box(self, x, y, width, height, title=None, bgcolor=BGCOLOR): d = ImageDraw.Draw(self.img) DR = ROUNDED/2 d.polygon( (x+DR,y,x+width-DR,y,x+width,y+DR,x+width,y+height-DR,x+width-DR,y+height,x+DR,y+height,x,y+height-DR,x,y+DR), fill=bgcolor) d.pieslice((x,y,x+ROUNDED,y+ROUNDED),180,270,fill=bgcolor) d.pieslice((x+width-ROUNDED,y,x+width,y+ROUNDED),270,0,fill=title and TITLECOLOR or bgcolor) d.pieslice((x+width-ROUNDED,y+height-ROUNDED,x+width,y+height),0,90,fill=bgcolor) d.pieslice((x,y+height-ROUNDED,x+ROUNDED,y+height),90,180,fill=bgcolor) if title: d.polygon( (x+width/5, y, x+width-DR, y, x+width, y+DR, x+width, y+20, x+width/5+15, y+20), fill=TITLECOLOR) self.draw_text(x+width/5+13, y+4, 10, title, (255,255,255), width*4/5-14) def node(self, x, y, width, height, title=None, start_color=BGCOLOR): self._rounding_box(x,y,BOXSIZE[0]-16,BOXSIZE[1], bgcolor=start_color) self._rounding_box(x+12,y,BOXSIZE[0]-16,BOXSIZE[1], bgcolor=(255,255,255)) self._rounding_box(x+16,y,BOXSIZE[0]-16,BOXSIZE[1], title) def angle(self, arrow): if not arrow[1]-arrow[3]: angle = 180 else: angle = math.atan(-(arrow[2]-arrow[0]) / (arrow[1]-arrow[3])) * 180 / math.pi angle = 270 - angle if arrow[3]