[Rdkit-devel] [PATCH 02/17] derive specialized Canvas classes from CanvasBase
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
|
From: Gianluca S. <gi...@gm...> - 2011-03-19 09:44:35
|
---
rdkit/Chem/Draw/aggCanvas.py | 177 ++++++++++++++++++----------------
rdkit/Chem/Draw/cairoCanvas.py | 210 ++++++++++++++++++++--------------------
rdkit/Chem/Draw/spingCanvas.py | 146 +++++++++++++++------------
3 files changed, 282 insertions(+), 251 deletions(-)
diff --git a/rdkit/Chem/Draw/aggCanvas.py b/rdkit/Chem/Draw/aggCanvas.py
index 6709f19..dc18451 100644
--- a/rdkit/Chem/Draw/aggCanvas.py
+++ b/rdkit/Chem/Draw/aggCanvas.py
@@ -14,6 +14,9 @@ import math
from rdkit import RDConfig
import os
+from aggdraw import Draw
+from canvasbase import CanvasBase
+
faceMap={'sans':os.path.join(RDConfig.RDCodeDir,'Chem','Draw','FreeSans.ttf')}
#faceMap={'sans':os.path.join(os.path.dirname(__file__),'FreeSans.ttf')}
@@ -21,94 +24,104 @@ def convertColor(color):
color = (int(color[0]*255),int(color[1]*255),int(color[2]*255))
return color
-def _getLinePoints(p1,p2,dash):
- x1,y1=p1
- x2,y2=p2
- dx = x2-x1
- dy = y2-y1
- lineLen = math.sqrt(dx*dx+dy*dy)
- theta = math.atan2(dy,dx)
- cosT = math.cos(theta)
- sinT = math.sin(theta)
-
- pos = (x1,y1)
- pts = [pos]
- dist = 0
- currDash = 0
- while dist < lineLen:
- currL = dash[currDash%len(dash)]
- if(dist+currL > lineLen): currL = lineLen-dist
- endP = (pos[0] + currL*cosT, pos[1] + currL*sinT)
- pts.append(endP)
- pos = endP
- dist += currL
- currDash += 1
- return pts
+class Canvas(CanvasBase):
-def _doLine(canvas,p1,p2,pen,**kwargs):
- if kwargs.get('dashes',(0,0)) == (0,0):
- canvas.line((p1[0],p1[1],p2[0],p2[1]),pen)
- else:
- # the antialiasing makes the dashes appear too small
- dash = [x*4 for x in kwargs['dashes']]
- pts = _getLinePoints(p1,p2,dash)
+ def __init__(self, img):
+ self.image = Draw(img)
+ self.image.setantialias(True)
+ self.size = self.image.size
+
+ def _getLinePoints(self, p1, p2, dash):
+ x1,y1=p1
+ x2,y2=p2
+ dx = x2-x1
+ dy = y2-y1
+ lineLen = math.sqrt(dx*dx+dy*dy)
+ theta = math.atan2(dy,dx)
+ cosT = math.cos(theta)
+ sinT = math.sin(theta)
+ pos = (x1,y1)
+ pts = [pos]
+ dist = 0
currDash = 0
- dashOn = True
- while currDash<(len(pts)-1):
- if dashOn:
- p1 = pts[currDash]
- p2 = pts[currDash+1]
- canvas.line((p1[0],p1[1],p2[0],p2[1]),pen)
- currDash+=1
- dashOn = not dashOn
+ while dist < lineLen:
+ currL = dash[currDash%len(dash)]
+ if(dist+currL > lineLen): currL = lineLen-dist
+ endP = (pos[0] + currL*cosT, pos[1] + currL*sinT)
+ pts.append(endP)
+ pos = endP
+ dist += currL
+ currDash += 1
+ return pts
-def addCanvasLine(canvas,p1,p2,color=(0,0,0),color2=None,**kwargs):
- if color2 and color2!=color:
- mp = (p1[0]+p2[0])/2.,(p1[1]+p2[1])/2.
- color = convertColor(color)
- _doLine(canvas,p1,mp,Pen(color,kwargs.get('linewidth',1)),**kwargs)
- color2 = convertColor(color2)
- _doLine(canvas,mp,p2,Pen(color2,kwargs.get('linewidth',1)),**kwargs)
- else:
- color = convertColor(color)
- _doLine(canvas,p1,p2,Pen(color,kwargs.get('linewidth',1)),**kwargs)
+ def _doLine(self, p1, p2, pen, **kwargs):
+ if kwargs.get('dashes',(0,0)) == (0,0):
+ self.image.line((p1[0],p1[1],p2[0],p2[1]),pen)
+ else:
+ # the antialiasing makes the dashes appear too small
+ dash = [x*4 for x in kwargs['dashes']]
+ pts = _getLinePoints(p1,p2,dash)
-def addCanvasText(canvas,text,pos,font,color=(0,0,0),**kwargs):
- color = convertColor(color)
- font = Font(color,faceMap[font.face],size=font.size)
- w,h=canvas.textsize(text,font)
- bw,bh=w*1.1,h*1.1
- dPos = pos[0]-bw/2.,pos[1]-bh/2.
- bgColor=kwargs.get('bgColor',(1,1,1))
- bgColor = convertColor(bgColor)
- canvas.rectangle((dPos[0],dPos[1],dPos[0]+bw,dPos[1]+bh),
- None,Brush(bgColor))
- dPos = pos[0]-w/2.,pos[1]-h/2.
- canvas.text(dPos,text,font)
+ currDash = 0
+ dashOn = True
+ while currDash<(len(pts)-1):
+ if dashOn:
+ p1 = pts[currDash]
+ p2 = pts[currDash+1]
+ self.image.line((p1[0],p1[1],p2[0],p2[1]),pen)
+ currDash+=1
+ dashOn = not dashOn
-def addCanvasPolygon(canvas,ps,color=(0,0,0),fill=True,stroke=False,**kwargs):
- if not fill and not stroke: return
- dps = []
- for p in ps:
- dps.extend(p)
- color = convertColor(color)
- brush=None
- pen=None
- if fill:
- brush = Brush(color)
- if stroke:
- pen = Pen(color)
- canvas.polygon(dps,pen,brush)
+ def addCanvasLine(self, p1, p2, color=(0,0,0), color2=None, **kwargs):
+ if color2 and color2!=color:
+ mp = (p1[0]+p2[0])/2.,(p1[1]+p2[1])/2.
+ color = convertColor(color)
+ self._doLine(p1,mp,Pen(color,kwargs.get('linewidth',1)),**kwargs)
+ color2 = convertColor(color2)
+ self._doLine(mp,p2,Pen(color2,kwargs.get('linewidth',1)),**kwargs)
+ else:
+ color = convertColor(color)
+ self._doLine(p1,p2,Pen(color,kwargs.get('linewidth',1)),**kwargs)
+
+ def addCanvasText(self,text,pos,font,color=(0,0,0),**kwargs):
+ color = convertColor(color)
+ font = Font(color,faceMap[font.face],size=font.size)
+ w,h=self.image.textsize(text,font)
+ bw,bh=w*1.1,h*1.1
+ dPos = pos[0]-bw/2.,pos[1]-bh/2.
+ bgColor=kwargs.get('bgColor',(1,1,1))
+ bgColor = convertColor(bgColor)
+ self.image.rectangle((dPos[0],dPos[1],dPos[0]+bw,dPos[1]+bh),
+ None,Brush(bgColor))
+ dPos = pos[0]-w/2.,pos[1]-h/2.
+ self.image.text(dPos,text,font)
+
+ def addCanvasPolygon(self,ps,color=(0,0,0),fill=True,stroke=False,**kwargs):
+ if not fill and not stroke: return
+ dps = []
+ for p in ps:
+ dps.extend(p)
+ color = convertColor(color)
+ brush=None
+ pen=None
+ if fill:
+ brush = Brush(color)
+ if stroke:
+ pen = Pen(color)
+ self.image.polygon(dps,pen,brush)
+
+ def addCanvasDashedWedge(self,p1,p2,p3,dash=(2,2),color=(0,0,0),
+ color2=None,**kwargs):
+ pen = Pen(color,kwargs.get('linewidth',1))
+ dash = (3,3)
+ pts1 = self._getLinePoints(p1,p2,dash)
+ pts2 = self._getLinePoints(p1,p3,dash)
-def addCanvasDashedWedge(canvas,p1,p2,p3,dash=(2,2),color=(0,0,0),
- color2=None,**kwargs):
- pen = Pen(color,kwargs.get('linewidth',1))
- dash = (3,3)
- pts1 = _getLinePoints(p1,p2,dash)
- pts2 = _getLinePoints(p1,p3,dash)
+ if len(pts2)<len(pts1): pts2,pts1=pts1,pts2
- if len(pts2)<len(pts1): pts2,pts1=pts1,pts2
+ for i in range(len(pts1)):
+ self.image.line((pts1[i][0],pts1[i][1],pts2[i][0],pts2[i][1]),pen)
- for i in range(len(pts1)):
- canvas.line((pts1[i][0],pts1[i][1],pts2[i][0],pts2[i][1]),pen)
+ def flush(self):
+ self.image.flush()
diff --git a/rdkit/Chem/Draw/cairoCanvas.py b/rdkit/Chem/Draw/cairoCanvas.py
index c1284ae..71f1166 100644
--- a/rdkit/Chem/Draw/cairoCanvas.py
+++ b/rdkit/Chem/Draw/cairoCanvas.py
@@ -15,11 +15,13 @@ import rdkit.RDConfig
import os
import array
+from canvasbase import CanvasBase
+
#missing up to now
#faceMap={'sans':os.path.join(
# rdkit.RDConfig.RDCodeDir,'Chem','Draw','FreeSans.ttf')}
-class Canvas(object):
+class Canvas(CanvasBase):
def __init__(self,
image=None, # PIL image
size=None,
@@ -94,109 +96,109 @@ class Canvas(object):
return buffer
-def _getLinePoints(p1,p2,dash):
- x1,y1=p1
- x2,y2=p2
- dx = x2-x1
- dy = y2-y1
- lineLen = math.sqrt(dx*dx+dy*dy)
- theta = math.atan2(dy,dx)
- cosT = math.cos(theta)
- sinT = math.sin(theta)
-
- pos = (x1,y1)
- pts = [pos]
- dist = 0
- currDash = 0
- while dist < lineLen:
- currL = dash[currDash%len(dash)]
- if(dist+currL > lineLen): currL = lineLen-dist
- endP = (pos[0] + currL*cosT, pos[1] + currL*sinT)
- pts.append(endP)
- pos = endP
- dist += currL
- currDash += 1
- return pts
-
-def _doLine(canvas,p1,p2,**kwargs):
- if kwargs.get('dashes',(0,0)) == (0,0):
- canvas.ctx.move_to(p1[0],p1[1])
- canvas.ctx.line_to(p2[0],p2[1])
- else:
- # the antialiasing makes the dashes appear too small
- dash = [x*4 for x in kwargs['dashes']]
- pts = _getLinePoints(p1,p2,dash)
+ def _getLinePoints(self, p1, p2, dash):
+ x1,y1 = p1
+ x2,y2 = p2
+ dx = x2-x1
+ dy = y2-y1
+ lineLen = math.sqrt(dx*dx+dy*dy)
+ theta = math.atan2(dy,dx)
+ cosT = math.cos(theta)
+ sinT = math.sin(theta)
+ pos = (x1,y1)
+ pts = [pos]
+ dist = 0
currDash = 0
- dashOn = True
- while currDash<(len(pts)-1):
- if dashOn:
- p1 = pts[currDash]
- p2 = pts[currDash+1]
- canvas.ctx.move_to(p1[0],p1[1])
- canvas.ctx.line_to(p2[0],p2[1])
- currDash+=1
- dashOn = not dashOn
-
-def addCanvasLine(canvas,p1,p2,color=(0,0,0),color2=None,**kwargs):
- canvas.ctx.set_line_width(kwargs.get('linewidth',1))
- if color2 and color2!=color:
- mp = (p1[0]+p2[0])/2.,(p1[1]+p2[1])/2.
- canvas.ctx.set_source_rgb(*color)
- _doLine(canvas,p1,mp,**kwargs)
- canvas.ctx.stroke()
- canvas.ctx.set_source_rgb(*color2)
- _doLine(canvas,mp,p2,**kwargs)
- canvas.ctx.stroke()
- else:
- canvas.ctx.set_source_rgb(*color)
- _doLine(canvas,p1,p2,**kwargs)
- canvas.ctx.stroke()
-
-def addCanvasText(canvas,text,pos,font,color=(0,0,0),**kwargs):
- canvas.ctx.select_font_face("Georgia",
- cairo.FONT_SLANT_NORMAL,
- cairo.FONT_WEIGHT_BOLD)
- canvas.ctx.set_font_size(font.size)
- w,h=canvas.ctx.text_extents(text)[2:4]
- bw,bh=w*1.8,h*1.4
- dPos = pos[0]-bw/2.,pos[1]-bh/2.
- bgColor=kwargs.get('bgColor',(1,1,1))
- canvas.ctx.set_source_rgb(*bgColor)
- canvas.ctx.rectangle(dPos[0],dPos[1],bw,bh)
- canvas.ctx.fill()
- dPos = pos[0]-w/2.,pos[1]+h/2.
- canvas.ctx.set_source_rgb(*color)
- canvas.ctx.move_to(*dPos)
- canvas.ctx.show_text(text)
-
-def addCanvasPolygon(canvas,ps,color=(0,0,0),fill=True,stroke=False,**kwargs):
- if not fill and not stroke: return
- dps = []
- canvas.ctx.set_source_rgb(*color)
- canvas.ctx.move_to(ps[0][0],ps[0][1])
- for p in ps[1:]:
- canvas.ctx.line_to(p[0],p[1])
- canvas.ctx.close_path()
- if stroke:
- if fill:
- canvas.ctx.stroke_preserve()
+ while dist < lineLen:
+ currL = dash[currDash%len(dash)]
+ if(dist+currL > lineLen): currL = lineLen-dist
+ endP = (pos[0] + currL*cosT, pos[1] + currL*sinT)
+ pts.append(endP)
+ pos = endP
+ dist += currL
+ currDash += 1
+ return pts
+
+ def _doLine(self, p1, p2, **kwargs):
+ if kwargs.get('dashes',(0,0)) == (0,0):
+ self.ctx.move_to(p1[0],p1[1])
+ self.ctx.line_to(p2[0],p2[1])
else:
- canvas.ctx.stroke()
- if fill:
- canvas.ctx.fill()
-
-def addCanvasDashedWedge(canvas,p1,p2,p3,dash=(2,2),color=(0,0,0),
- color2=None,**kwargs):
- canvas.ctx.set_line_width(kwargs.get('linewidth',1))
- canvas.ctx.set_source_rgb(*color)
- dash = (3,3)
- pts1 = _getLinePoints(p1,p2,dash)
- pts2 = _getLinePoints(p1,p3,dash)
-
- if len(pts2)<len(pts1): pts2,pts1=pts1,pts2
-
- for i in range(len(pts1)):
- canvas.ctx.move_to(pts1[i][0],pts1[i][1])
- canvas.ctx.line_to(pts2[i][0],pts2[i][1])
- canvas.ctx.stroke()
+ # the antialiasing makes the dashes appear too small
+ dash = [x*4 for x in kwargs['dashes']]
+ pts = _getLinePoints(p1,p2,dash)
+
+ currDash = 0
+ dashOn = True
+ while currDash<(len(pts)-1):
+ if dashOn:
+ p1 = pts[currDash]
+ p2 = pts[currDash+1]
+ self.ctx.move_to(p1[0],p1[1])
+ self.ctx.line_to(p2[0],p2[1])
+ currDash+=1
+ dashOn = not dashOn
+
+ def addCanvasLine(self,p1,p2,color=(0,0,0),color2=None,**kwargs):
+ self.ctx.set_line_width(kwargs.get('linewidth',1))
+ if color2 and color2!=color:
+ mp = (p1[0]+p2[0])/2.,(p1[1]+p2[1])/2.
+ self.ctx.set_source_rgb(*color)
+ self._doLine(p1,mp,**kwargs)
+ self.ctx.stroke()
+ self.ctx.set_source_rgb(*color2)
+ self._doLine(mp,p2,**kwargs)
+ self.ctx.stroke()
+ else:
+ self.ctx.set_source_rgb(*color)
+ self._doLine(p1,p2,**kwargs)
+ self.ctx.stroke()
+
+ def addCanvasText(self,text,pos,font,color=(0,0,0),**kwargs):
+ self.ctx.select_font_face("Georgia",
+ cairo.FONT_SLANT_NORMAL,
+ cairo.FONT_WEIGHT_BOLD)
+ self.ctx.set_font_size(font.size)
+ w,h=self.ctx.text_extents(text)[2:4]
+ bw,bh=w*1.8,h*1.4
+ dPos = pos[0]-bw/2.,pos[1]-bh/2.
+ bgColor=kwargs.get('bgColor',(1,1,1))
+ self.ctx.set_source_rgb(*bgColor)
+ self.ctx.rectangle(dPos[0],dPos[1],bw,bh)
+ self.ctx.fill()
+ dPos = pos[0]-w/2.,pos[1]+h/2.
+ self.ctx.set_source_rgb(*color)
+ self.ctx.move_to(*dPos)
+ self.ctx.show_text(text)
+
+ def addCanvasPolygon(self,ps,color=(0,0,0),fill=True,stroke=False,**kwargs):
+ if not fill and not stroke: return
+ dps = []
+ self.ctx.set_source_rgb(*color)
+ self.ctx.move_to(ps[0][0],ps[0][1])
+ for p in ps[1:]:
+ self.ctx.line_to(p[0],p[1])
+ self.ctx.close_path()
+ if stroke:
+ if fill:
+ self.ctx.stroke_preserve()
+ else:
+ self.ctx.stroke()
+ if fill:
+ self.ctx.fill()
+
+ def addCanvasDashedWedge(self,p1,p2,p3,dash=(2,2),color=(0,0,0),
+ color2=None,**kwargs):
+ self.ctx.set_line_width(kwargs.get('linewidth',1))
+ self.ctx.set_source_rgb(*color)
+ dash = (3,3)
+ pts1 = self._getLinePoints(p1,p2,dash)
+ pts2 = self._getLinePoints(p1,p3,dash)
+
+ if len(pts2)<len(pts1): pts2,pts1=pts1,pts2
+
+ for i in range(len(pts1)):
+ self.ctx.move_to(pts1[i][0],pts1[i][1])
+ self.ctx.line_to(pts2[i][0],pts2[i][1])
+ self.ctx.stroke()
diff --git a/rdkit/Chem/Draw/spingCanvas.py b/rdkit/Chem/Draw/spingCanvas.py
index 9ed697a..98bbe3d 100644
--- a/rdkit/Chem/Draw/spingCanvas.py
+++ b/rdkit/Chem/Draw/spingCanvas.py
@@ -9,8 +9,12 @@
# of the RDKit source tree.
#
from rdkit.sping import pid
+
import math
+from rdkit.sping.PIL.pidPIL import PILCanvas
+from canvasbase import CanvasBase
+
faceMap={'sans':'helvetica'}
def convertColor(color):
@@ -41,70 +45,82 @@ def _getLinePoints(p1,p2,dash):
currDash += 1
return pts
-def addCanvasLine(canvas,p1,p2,color=(0,0,0),color2=None,**kwargs):
- if color2 and color2!=color:
- mp = (p1[0]+p2[0])/2.,(p1[1]+p2[1])/2.
- color = convertColor(color)
- canvas.drawLine(p1[0],p1[1],mp[0],mp[1],
- color=color,
- width=int(kwargs.get('linewidth',1)),
- dash=kwargs.get('dash',None))
- color2 = convertColor(color2)
- canvas.drawLine(mp[0],mp[1],p2[0],p2[1],
- color=color2,
- width=int(kwargs.get('linewidth',1)),
- dash=kwargs.get('dash',None))
- else:
+
+class Canvas(CanvasBase):
+
+ def __init__(self, size, name):
+ self.canvas = PILCanvas(size=size, name=name)
+ self._image = self.canvas._image
+ self.size = self._image.size
+
+ def addCanvasLine(self, p1,p2,color=(0,0,0),color2=None,**kwargs):
+ if color2 and color2!=color:
+ mp = (p1[0]+p2[0])/2.,(p1[1]+p2[1])/2.
+ color = convertColor(color)
+ self.canvas.drawLine(p1[0],p1[1],mp[0],mp[1],
+ color=color,
+ width=int(kwargs.get('linewidth',1)),
+ dash=kwargs.get('dash',None))
+ color2 = convertColor(color2)
+ self.canvas.drawLine(mp[0],mp[1],p2[0],p2[1],
+ color=color2,
+ width=int(kwargs.get('linewidth',1)),
+ dash=kwargs.get('dash',None))
+ else:
+ color = convertColor(color)
+ width=kwargs.get('linewidth',1)
+ self.canvas.drawLine(p1[0],p1[1],p2[0],p2[1],
+ color=color,
+ width=int(width),
+ dash=kwargs.get('dash',None))
+
+ def addCanvasText(self, text,pos,font,color=(0,0,0),**kwargs):
+ font = pid.Font(face=faceMap[font.face],size=font.size)
+ txtWidth,txtHeight=self.canvas.stringBox(text,font)
+ labelP = pos[0]-txtWidth/2,pos[1]+txtHeight/2
+ xPad = kwargs.get('xPadding',0)
+ yPad = kwargs.get('yPadding',0)
+ x1 = pos[0]-txtWidth/2 - xPad
+ y1 = pos[1]+txtHeight/2 + yPad
+ x2 = pos[0]+txtWidth/2 + xPad
+ y2 = pos[1]-txtHeight/2 - yPad
+ bgColor=kwargs.get('bgColor',(1,1,1))
+ bgColor = convertColor(bgColor)
+ self.canvas.drawRect(x1,y1,x2,y2,
+ edgeColor=pid.transparent,
+ edgeWidth=0,fillColor=bgColor)
color = convertColor(color)
- width=kwargs.get('linewidth',1)
- canvas.drawLine(p1[0],p1[1],p2[0],p2[1],
- color=color,
- width=int(width),
- dash=kwargs.get('dash',None))
-
-def addCanvasText(canvas,text,pos,font,color=(0,0,0),**kwargs):
- font = pid.Font(face=faceMap[font.face],size=font.size)
- txtWidth,txtHeight=canvas.stringBox(text,font)
- labelP = pos[0]-txtWidth/2,pos[1]+txtHeight/2
- xPad = kwargs.get('xPadding',0)
- yPad = kwargs.get('yPadding',0)
- x1 = pos[0]-txtWidth/2 - xPad
- y1 = pos[1]+txtHeight/2 + yPad
- x2 = pos[0]+txtWidth/2 + xPad
- y2 = pos[1]-txtHeight/2 - yPad
- bgColor=kwargs.get('bgColor',(1,1,1))
- bgColor = convertColor(bgColor)
- canvas.drawRect(x1,y1,x2,y2,
- edgeColor=pid.transparent,
- edgeWidth=0,fillColor=bgColor)
- color = convertColor(color)
- canvas.drawString(text,labelP[0],labelP[1],font,color=color)
-
-def addCanvasPolygon(canvas,ps,color=(0,0,0),fill=True,stroke=False,**kwargs):
- if not fill and not stroke: return
- color = convertColor(color)
- if not stroke:
- edgeWidth=0
+ self.canvas.drawString(text,labelP[0],labelP[1],font,color=color)
+
+ def addCanvasPolygon(self, ps,color=(0,0,0),fill=True,stroke=False,**kwargs):
+ if not fill and not stroke: return
+ edgeWidth=kwargs.get('lineWidth',0)
edgeColor=pid.transparent
- else:
- edgeWidth=kwargs.get('lineWidth',1)
- edgeColor=color
- if not fill:
- fillColor = pid.transparent
- else:
- fillColor = color
- canvas.drawPolygon(ps,edgeColor=edgeColor,edgeWidth=int(edgeWidth),fillColor=fillColor,
- closed=1)
-
-def addCanvasDashedWedge(canvas,p1,p2,p3,dash=(2,2),color=(0,0,0),
- color2=None,**kwargs):
- color = convertColor(color)
- dash = (4,4)
- pts1 = _getLinePoints(p1,p2,dash)
- pts2 = _getLinePoints(p1,p3,dash)
-
- if len(pts2)<len(pts1): pts2,pts1=pts1,pts2
-
- for i in range(len(pts1)):
- canvas.drawLine(pts1[i][0],pts1[i][1],pts2[i][0],pts2[i][1],
- color=color,width=1)
+ color = convertColor(color)
+ if not stroke:
+ edgeWidth=0
+ edgeColor=pid.transparent
+ else:
+ edgeWidth=kwargs.get('lineWidth',1)
+ edgeColor=color
+ if not fill:
+ fillColor = pid.transparent
+ else:
+ fillColor = color
+ self.canvas.drawPolygon(ps,edgeColor=edgeColor,edgeWidth=int(edgeWidth),fillColor=fillColor,closed=1)
+
+ def addCanvasDashedWedge(self,p1,p2,p3,dash=(2,2),color=(0,0,0),
+ color2=None,**kwargs):
+ color = convertColor(color)
+ dash = (4,4)
+ pts1 = _getLinePoints(p1,p2,dash)
+ pts2 = _getLinePoints(p1,p3,dash)
+
+ if len(pts2)<len(pts1): pts2,pts1=pts1,pts2
+
+ for i in range(len(pts1)):
+ self.canvas.drawLine(pts1[i][0],pts1[i][1],pts2[i][0],pts2[i][1],
+ color=color,width=1)
+
+ def flush(self):
+ self.canvas.flush()
--
1.7.4
|