Better Layout for Processus
bzr revid: fp@tinyerp.com-20080714211932-zgwa7iv6ukzbvr7k
This commit is contained in:
parent
0929bc31f2
commit
b99c3e808f
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 885 B |
Binary file not shown.
After Width: | Height: | Size: 1013 B |
|
@ -1,55 +1,93 @@
|
|||
import Image
|
||||
import ImageDraw
|
||||
import ImageFont
|
||||
import math
|
||||
|
||||
ROUNDED = 30
|
||||
BGCOLOR = (228,233,237)
|
||||
TITLECOLOR = (253,171,44)
|
||||
TITLECOLOR = (150,70,70)
|
||||
FONT = 'sb.ttf'
|
||||
BOXSIZE = (300,140)
|
||||
BOXSIZE = (160,120)
|
||||
|
||||
size = 800,600
|
||||
img = Image.new('RGB',size,'#ffffff')
|
||||
|
||||
class draw(object):
|
||||
def rounding_box(self, x, y, width, height, title=None, bgcolor=BGCOLOR):
|
||||
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)
|
||||
if title:
|
||||
d.polygon( (x+width/3, y, x+width-DR, y, x+width, y+DR, x+width, y+30, x+width/3+30, y+30), fill=TITLECOLOR)
|
||||
self.draw_text(x+width/3+30, y+3, 20, title, (255,255,255), width*2/3-40)
|
||||
|
||||
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 intersect(self, start, stop):
|
||||
x1 = start[0] + BOXSIZE[0]/2
|
||||
y1 = start[1] - (start[1] - stop[1]) * (start[0]-x1) / (start[0] - stop[0])
|
||||
return (x1,y1,stop[0],stop[1])
|
||||
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 arrow(self, start, stop):
|
||||
def angle(self, arrow):
|
||||
if not arrow[1]-arrow[3]:
|
||||
angle = 270
|
||||
else:
|
||||
angle = math.atan(-(arrow[2]-arrow[0]) / (arrow[1]-arrow[3])) * 180 / math.pi
|
||||
angle = 270 - angle
|
||||
return int(angle)
|
||||
|
||||
def arrow(self, arrow):
|
||||
d = ImageDraw.Draw(self.img)
|
||||
start = (start[0]+BOXSIZE[0]/2, start[1]+BOXSIZE[1]/2)
|
||||
stop = (stop[0]+BOXSIZE[0]/2, stop[1]+BOXSIZE[1]/2)
|
||||
arrow = self.intersect(start,stop)
|
||||
d.line(arrow, width=1, fill=(0,0,0))
|
||||
angle = self.angle(arrow)
|
||||
d.pieslice((arrow[2]-14,arrow[3]-14,arrow[2]+14,arrow[3]+14),angle-18,angle+18,fill=(0,0,0))
|
||||
|
||||
d.line(arrow, width=10, fill=(100,0,0))
|
||||
|
||||
def draw_text(self, x, y, size, title, color=(155,255,255), maxlength=None, font_name=FONT):
|
||||
def draw_text(self, x, y, size, title, color=(155,255,255), maxlength=None, font_name=FONT, center=False):
|
||||
d = ImageDraw.Draw(self.img)
|
||||
font = ImageFont.truetype(font_name, size)
|
||||
d.setfont(font)
|
||||
size2 = d.textsize(title)
|
||||
fontsize = min(size, size * maxlength / size2[0])
|
||||
font = ImageFont.truetype(font_name, fontsize)
|
||||
d.setfont(font)
|
||||
if maxlength:
|
||||
fontsize = min(size, size * maxlength / size2[0])
|
||||
font = ImageFont.truetype(font_name, fontsize)
|
||||
d.setfont(font)
|
||||
size = d.textsize(title)
|
||||
if center:
|
||||
x = x-size[0]/2
|
||||
d.text( (x, y+(size2[1]-size[1])/2), title, color)
|
||||
|
||||
def arrow_role(self, node_from, node_to, role='Hello'):
|
||||
d = ImageDraw.Draw(self.img)
|
||||
x = (node_from[0] + node_to[0]) /2
|
||||
y = (node_from[1] + node_to[1]) /2
|
||||
angle = self.angle(node_from+node_to) + 105
|
||||
d.pieslice((x-40,y-40,x+40,y+40),angle-5,angle+5,fill=(100,0,0))
|
||||
d.pieslice((x-6,y-6,x+6,y+6),angle-7,angle+7,fill=(255,255,255))
|
||||
|
||||
print -180 + angle - 90
|
||||
x = x + math.cos(angle * math.pi / 180) * 40
|
||||
y = y + math.sin(angle * math.pi / 180) * 40
|
||||
a,b = x,y
|
||||
angle -= 120
|
||||
|
||||
x = x + math.cos(angle * math.pi / 180) * 20
|
||||
y = y + math.sin(angle * math.pi / 180) * 20
|
||||
|
||||
d.line((a,b,x,y), width=5, fill=(100,0,0))
|
||||
angle += 125
|
||||
d.pieslice((x-30,y-30,x+30,y+30),angle-7,angle+7,fill=(100,0,0))
|
||||
|
||||
x = x + math.cos(angle * math.pi / 180) * 50
|
||||
y = y + math.sin(angle * math.pi / 180) * 50
|
||||
return (x,y)
|
||||
|
||||
def picture(self, x, y, fname):
|
||||
img = Image.open(fname)
|
||||
img2 = img.convert('RGBA')
|
||||
self.img.paste(img2, (max(0,x-img.size[0]/2), max(0,y-img.size[1])), mask=img2)
|
||||
|
||||
def __init__(self, img):
|
||||
self.img = img
|
||||
|
||||
|
@ -57,17 +95,60 @@ class graph(object):
|
|||
def __init__(self, img):
|
||||
self.draw = draw(img)
|
||||
|
||||
def intersect_one(self, start, stop):
|
||||
if start[0] < stop[0]:
|
||||
x1 = start[0] + BOXSIZE[0]/2 + 3
|
||||
else:
|
||||
x1 = start[0] - BOXSIZE[0]/2 - 3
|
||||
y1 = start[1] - (start[1] - stop[1]) * (start[0]-x1) / (start[0] - stop[0])
|
||||
|
||||
if start[1] < stop[1]:
|
||||
y2 = start[1] + BOXSIZE[1]/2 + 3
|
||||
else:
|
||||
y2 = start[1] - BOXSIZE[1]/2 - 3
|
||||
x2 = start[0] - (start[0] - stop[0]) * (start[1]-y2) / (start[1] - stop[1])
|
||||
|
||||
if abs(start[0]-x1)+abs(start[1]-y1)<abs(start[0]-x2)+abs(y2-start[1]):
|
||||
return (x1,y1)
|
||||
return (x2,y2)
|
||||
|
||||
def intersect(self, start, stop):
|
||||
s = self.intersect_one(start,stop)
|
||||
s2 = self.intersect_one(stop,start)
|
||||
return s+s2
|
||||
|
||||
def node(self, x, y, data, start_color=BGCOLOR):
|
||||
self.draw.rounding_box(x-20,y,BOXSIZE[0],BOXSIZE[1], bgcolor=start_color)
|
||||
self.draw.rounding_box(x-4,y,BOXSIZE[0],BOXSIZE[1], bgcolor=(255,255,255))
|
||||
self.draw.rounding_box(x,y,BOXSIZE[0],BOXSIZE[1],data.get('title','Unknown'))
|
||||
self.draw.node(x,y,BOXSIZE[0], BOXSIZE[1], data.get('title','Unknown'), start_color)
|
||||
self.draw.picture(x+35, y+BOXSIZE[1]-5, 'gtk-open.png')
|
||||
self.draw.picture(x+65, y+BOXSIZE[1]-5, 'gtk-print.png')
|
||||
self.draw.picture(x+95, y+BOXSIZE[1]-5, 'gtk-help.png')
|
||||
y = y+25
|
||||
menus = data.get('menu','').split('/')
|
||||
while menus:
|
||||
menu = menus.pop(0)
|
||||
if menu:
|
||||
if menus: menu=menu+' /'
|
||||
self.draw.draw_text(x+23, y, 10, menu, color=(0,0,0), maxlength=BOXSIZE[0] - 25, font_name='ds.ttf')
|
||||
y+=15
|
||||
|
||||
def arrow_role(self, node_from, node_to, role='Hello'):
|
||||
start = (node_from[0]+BOXSIZE[0]/2, node_from[1]+BOXSIZE[1]/2)
|
||||
stop = (node_to[0]+BOXSIZE[0]/2, node_to[1]+BOXSIZE[1]/2)
|
||||
(x,y) = self.draw.arrow_role(start, stop, role)
|
||||
self.draw.picture(x, y-7, 'role.png')
|
||||
self.draw.draw_text(x,y-7, 15, 'Salesman', color=(0,0,0), center=True)
|
||||
|
||||
def arrow(self, node_from, node_to):
|
||||
self.draw.arrow(node_from,node_to)
|
||||
start = (node_from[0]+BOXSIZE[0]/2, node_from[1]+BOXSIZE[1]/2)
|
||||
stop = (node_to[0]+BOXSIZE[0]/2, node_to[1]+BOXSIZE[1]/2)
|
||||
arrow = self.intersect(start,stop)
|
||||
self.draw.arrow(arrow)
|
||||
|
||||
g = graph(img)
|
||||
g.node(50,50,{'title':'SALE AZER ORDER'}, start_color=(200,100,100))
|
||||
g.node(450,150,{'title':'SALE AZER AZE ORDER'})
|
||||
g.arrow((50,50),(450,150))
|
||||
g.node(50,100,{'title':'SALE AZER ORDER', 'menu':'Sales Management/Sales Orders/My Sales Order/My Open Sales Order'}, start_color=(200,100,100))
|
||||
g.node(350,150,{'title':'SALE AZER AZE ORDER', 'menu':'Sales Management/Sales Orders/My Quotations'})
|
||||
g.arrow((50,100),(350,150))
|
||||
|
||||
g.arrow_role((50,100),(350,150))
|
||||
|
||||
img.show()
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Loading…
Reference in New Issue