def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # arrow specific bits x = self.x y = self.y s2 = s/2 s3 = s/3 s5 = s/5 s24 = s/24 g.add(shapes.Polygon( points = [ x,y+11*s24, x,y+13*s24, x+18.75*s24, y+13*s24, x+2*s3, y+2*s3, x+s, y+s2, x+2*s3, y+s3, x+18.75*s24, y+11*s24, ], fillColor = self.fillColor, strokeColor = self.strokeColor, strokeWidth = self.strokeWidth) ) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # tickbox specific bits box = shapes.Rect(self.x + 1, self.y + 1, s - 2, s - 2, fillColor=self.fillColor, strokeColor=self.strokeColor, strokeWidth=2) g.add(box) tickLine = shapes.PolyLine(points=[ self.x + (s * 0.15), self.y + (s * 0.35), self.x + (s * 0.35), self.y + (s * 0.15), self.x + (s * 0.35), self.y + (s * 0.15), self.x + (s * 0.85), self.y + (s * 0.85) ], fillColor=self.tickColor, strokeColor=self.tickColor, strokeWidth=self.tickwidth) g.add(tickLine) return g
def draw_side(x, y, attach_height, hole_dist_x, fieldnum, fliph = 1, colorout = green, colorin = green): f = box.drawField(x, y, BOX_WIDTH/2, fieldnum, fliph, colorout) attach_width = 12 insert_length = fliph * 10 insert_width = 15 margin_hole = 5 l1 = box._draw_line(x, y, x, y + MATERIAL_THICKNESS, colorout) l2 = box._draw_line(x, y + MATERIAL_THICKNESS, x - insert_length, y + MATERIAL_THICKNESS, colorout) l3 = box._draw_line(x - insert_length, y + MATERIAL_THICKNESS, x - insert_length, y + MATERIAL_THICKNESS + insert_width, colorout) l4 = box._draw_line(x, y + MATERIAL_THICKNESS + insert_width, x - insert_length, y + MATERIAL_THICKNESS + insert_width, colorout) l5 = box._draw_line(x, y + MATERIAL_THICKNESS + insert_width, x, y + attach_height - attach_width/2, colorout) b = box._draw_polyline([ x, y + attach_height - attach_width/2, x - (hole_dist_x + margin_hole) * fliph, y + attach_height - attach_width/2 , x - (hole_dist_x + margin_hole) * fliph, y + attach_height + attach_width/2 , x, y + attach_height + attach_width/2], colorout) l6 = box._draw_line(x, y + attach_height + attach_width/2, x, BOX_WIDTH + y - MATERIAL_THICKNESS - insert_width , colorout) l7 = box._draw_line(x, y + BOX_WIDTH - MATERIAL_THICKNESS - insert_width, x - insert_length, y + BOX_WIDTH - MATERIAL_THICKNESS - insert_width, colorout) l8 = box._draw_line(x - insert_length, y + BOX_WIDTH - MATERIAL_THICKNESS - insert_width, x - insert_length, y + BOX_WIDTH - MATERIAL_THICKNESS , colorout) l9 = box._draw_line(x, y + BOX_WIDTH - MATERIAL_THICKNESS, x - insert_length, y + BOX_WIDTH - MATERIAL_THICKNESS, colorout) l10 = box._draw_line(x, y + BOX_WIDTH - MATERIAL_THICKNESS, x, y + BOX_WIDTH, colorout) if fliph == 1: p = box._draw_circle(x - hole_dist_x * fliph, y + attach_height, RADIUS, colorin) else: p = box._draw_circle(x - hole_dist_x * fliph, y + attach_height, RADIUS, colorin) # p = box._draw_circle(x - (SCREEN_X + SCREEN_TO_SCREW1X - MATERIAL_THICKNESS)*fliph, y + attach_height, RADIUS, colorin) return shapes.Group(f, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, p, b)
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() x = self.x y = self.y s2 = s/2 s3 = s/3 s5 = s/5 g.add(shapes.Polygon(points = [ x,y+s3, x,y+2*s3, x+s2,y+2*s3, x+s2,y+4*s5, x+s,y+s2, x+s2,y+s5, x+s2,y+s3, ], fillColor = self.fillColor, strokeColor = self.strokeColor, strokeWidth = self.strokeWidth, ) ) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # crossbox specific bits box = shapes.Rect(self.x+1, self.y+1, s-2, s-2, fillColor = self.fillColor, strokeColor = self.strokeColor, strokeWidth=2) g.add(box) crossLine1 = shapes.Line(self.x+(s*0.15), self.y+(s*0.15), self.x+(s*0.85), self.y+(s*0.85), fillColor = self.crossColor, strokeColor = self.crossColor, strokeWidth = self.crosswidth) g.add(crossLine1) crossLine2 = shapes.Line(self.x+(s*0.15), self.y+(s*0.85), self.x+(s*0.85) ,self.y+(s*0.15), fillColor = self.crossColor, strokeColor = self.crossColor, strokeWidth = self.crosswidth) g.add(crossLine2) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() ig = self.innerGap x = self.x + self.dx y = self.y + self.dy hsize = 0.5 * self.size if not ig: L = [(x - hsize, y, x + hsize, y), (x, y - hsize, x, y + hsize)] else: if isStr(ig): ig = asUnicode(ig) if ig.endswith(u'%'): gs = hsize * float(ig[:-1]) / 100.0 else: gs = float(ig) * 0.5 else: gs = ig * 0.5 L = [(x - hsize, y, x - gs, y), (x + gs, y, x + hsize, y), (x, y - hsize, x, y - gs), (x, y + gs, x, y + hsize)] P = shapes.Path(strokeWidth=self.strokeWidth, strokeColor=self.strokeColor) for x0, y0, x1, y1 in L: P.moveTo(x0, y0) P.lineTo(x1, y1) g.add(P) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # SmileyFace specific bits g.add( shapes.Circle(cx=self.x + (s / 2), cy=self.y + (s / 2), r=s / 2, fillColor=self.fillColor, strokeColor=self.strokeColor, strokeWidth=max(s / 38., self.strokeWidth))) for i in (1, 2): g.add( shapes.Ellipse(self.x + (s / 3) * i, self.y + (s / 3) * 2, s / 30, s / 10, fillColor=self.strokeColor, strokeColor=self.strokeColor, strokeWidth=max(s / 38., self.strokeWidth))) # calculate a pointslist for the mouth # THIS IS A HACK! - don't use if there is a 'shapes.Arc' centerx = self.x + (s / 2) centery = self.y + (s / 2) radius = s / 3 yradius = radius xradius = radius startangledegrees = 200 endangledegrees = 340 degreedelta = 1 pointslist = [] a = pointslist.append from math import sin, cos, pi degreestoradians = pi / 180.0 radiansdelta = degreedelta * degreestoradians startangle = startangledegrees * degreestoradians endangle = endangledegrees * degreestoradians while endangle < startangle: endangle = endangle + 2 * pi angle = startangle while angle < endangle: x = centerx + cos(angle) * radius y = centery + sin(angle) * yradius a(x) a(y) angle = angle + radiansdelta # make the mouth smile = shapes.PolyLine(pointslist, fillColor=self.strokeColor, strokeColor=self.strokeColor, strokeWidth=max(s / 38., self.strokeWidth)) g.add(smile) return g
def draw(self): s = self.size # abbreviate as we will use this a lot g = shapes.Group() g.transform = [1, 0, 0, 1, self.x, self.y] # background g.add( shapes.Circle(s * 0.5, s * 0.5, s * 0.5, fillColor=self.skinColor)) # left eye g.add( shapes.Circle(s * 0.35, s * 0.65, s * 0.1, fillColor=colors.white)) g.add( shapes.Circle(s * 0.35, s * 0.65, s * 0.05, fillColor=self.eyeColor)) # right eye g.add( shapes.Circle(s * 0.65, s * 0.65, s * 0.1, fillColor=colors.white)) g.add( shapes.Circle(s * 0.65, s * 0.65, s * 0.05, fillColor=self.eyeColor)) # nose g.add( shapes.Polygon( points=[s * 0.5, s * 0.6, s * 0.4, s * 0.3, s * 0.6, s * 0.3], fillColor=None)) # mouth if self.mood == 'happy': offset = -0.05 elif self.mood == 'sad': offset = +0.05 else: offset = 0 g.add( shapes.Polygon( points=[ s * 0.3, s * 0.2, #left of mouth s * 0.7, s * 0.2, #right of mouth s * 0.6, s * (0.2 + offset), # the bit going up or down s * 0.4, s * (0.2 + offset) # the bit going up or down ], fillColor=colors.pink, strokeColor=colors.red, strokeWidth=s * 0.03)) return g
def draw(self): """ returns a group of shapes """ g = shapes.Group() #overall border and fill if self.borderStrokeColor or self.fillColor: # adds border and filling color rect = shapes.Rect(self.x, self.y, self.width, self.height) rect.fillColor = self.fillColor rect.strokeColor = self.borderStrokeColor rect.strokeWidth = self.borderStrokeWidth g.add(rect) #special case - for an empty table we want to avoid divide-by-zero data = self.preProcessData(self.data) rows = len(self.data) cols = len(self.data[0]) #print "(rows,cols)=(%s, %s)"%(rows,cols) row_step = self.height / float(rows) col_step = self.width / float(cols) #print "(row_step,col_step)=(%s, %s)"%(row_step,col_step) # draw the grid if self.horizontalDividerStrokeColor: for i in range(rows): # make horizontal lines x1 = self.x x2 = self.x + self.width y = self.y + row_step*i #print 'line (%s, %s), (%s, %s)'%(x1, y, x2, y) line = shapes.Line(x1, y, x2, y) line.strokeDashArray = self.dividerDashArray line.strokeWidth = self.horizontalDividerStrokeWidth line.strokeColor = self.horizontalDividerStrokeColor g.add(line) if self.verticalDividerStrokeColor: for i in range(cols): # make vertical lines x = self.x+col_step*i y1 = self.y y2 = self.y + self.height #print 'line (%s, %s), (%s, %s)'%(x, y1, x, y2) line = shapes.Line(x, y1, x, y2) line.strokeDashArray = self.dividerDashArray line.strokeWidth = self.verticalDividerStrokeWidth line.strokeColor = self.verticalDividerStrokeColor g.add(line) # since we plot data from down up, we reverse the list self.data.reverse() for (j, row) in enumerate(self.data): y = self.y + j*row_step + 0.5*row_step - 0.5 * self.fontSize for (i, datum) in enumerate(row): if datum: x = self.x + i*col_step + 0.5*col_step s = shapes.String(x, y, str(datum), textAnchor=self.textAnchor) s.fontName = self.fontName s.fontSize = self.fontSize s.fillColor = self.fontColor g.add(s) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # floppy disk specific bits diskBody = shapes.Rect(x=self.x, y=self.y+(s/100), width=s, height=s-(s/100), fillColor = self.diskColor, strokeColor = None, strokeWidth=0) g.add(diskBody) label = shapes.Rect(x=self.x+(s*0.1), y=(self.y+s)-(s*0.5), width=s*0.8, height=s*0.48, fillColor = colors.whitesmoke, strokeColor = None, strokeWidth=0) g.add(label) labelsplash = shapes.Rect(x=self.x+(s*0.1), y=(self.y+s)-(s*0.1), width=s*0.8, height=s*0.08, fillColor = colors.royalblue, strokeColor = None, strokeWidth=0) g.add(labelsplash) line1 = shapes.Line(x1=self.x+(s*0.15), y1=self.y+(0.6*s), x2=self.x+(s*0.85), y2=self.y+(0.6*s), fillColor = colors.black, strokeColor = colors.black, strokeWidth=0) g.add(line1) line2 = shapes.Line(x1=self.x+(s*0.15), y1=self.y+(0.7*s), x2=self.x+(s*0.85), y2=self.y+(0.7*s), fillColor = colors.black, strokeColor = colors.black, strokeWidth=0) g.add(line2) line3 = shapes.Line(x1=self.x+(s*0.15), y1=self.y+(0.8*s), x2=self.x+(s*0.85), y2=self.y+(0.8*s), fillColor = colors.black, strokeColor = colors.black, strokeWidth=0) g.add(line3) metalcover = shapes.Rect(x=self.x+(s*0.2), y=(self.y), width=s*0.5, height=s*0.35, fillColor = colors.silver, strokeColor = None, strokeWidth=0) g.add(metalcover) coverslot = shapes.Rect(x=self.x+(s*0.28), y=(self.y)+(s*0.035), width=s*0.12, height=s*0.28, fillColor = self.diskColor, strokeColor = None, strokeWidth=0) g.add(coverslot) return g
def draw(self): # general widget bits w = float(self.length) h = float(self.height) # print self.label,w,h # Set minimum size if abs(w)<self.wmin: xmid = self.x+0.5*w w = w/abs(w) * self.wmin self.x = xmid-0.5*w g = shapes.Group() if abs(w)>self.wNoTail: # arrow specific bits body = shapes.Rect(x=self.x, y=self.y-self.aspectRatio*h/2, width=2*(w/3), height=self.aspectRatio*h, fillColor=self.fillColor, strokeColor=self.strokeColor, strokeWidth=self.strokeWidth) g.add(body) head = shapes.Polygon( points=[self.x+w, self.y, self.x+2*(w/3), self.y+h/2, self.x+2*(w/3), self.y-h/2, self.x+w, self.y], fillColor=self.fillColor, strokeColor=self.strokeColor, strokeWidth=self.strokeWidth) g.add(head) else: head = shapes.Polygon( points=[self.x+w, self.y, self.x, self.y+h/2, self.x, self.y-h/2, self.x+w, self.y], fillColor=self.fillColor, strokeColor=self.strokeColor, strokeWidth=self.strokeWidth) g.add(head) if self.label: b = g.getBounds() s = Label() s.setText(self.label) s.setOrigin(self.x+0.5*w+self.labeldx, self.y-h/2+b[3]-b[1]+self.labeldy) s.boxAnchor = self.boxAnchor s.textAnchor = self.textAnchor s.fontName = 'Helvetica' s.fontSize = self.fontSize s.angle = self.labelAngle g.add(s) return g
def process(self): attrs = dict(self.getAttributeValues()) string = shapes.String(attrs.pop('x'), attrs.pop('y'), attrs.pop('text')) angle = attrs.pop('angle', 0) for name, value in attrs.items(): setattr(string, name, value) group = shapes.Group(string) group.translate(0, 0) group.rotate(angle) self.parent.parent.drawing.add(group)
def draw(self): g = shapes.Group() (x1, y1, x2, y2) = self.getBounds() r = shapes.Rect(x=x1, y=y1, width=x2 - x1, height=y2 - y1, fillColor=self.fillColor, strokeColor=self.strokeColor) g.add(r) for elem in self.contents: g.add(elem) return g
def testGroup(self): g = shapes.Group() g.add(shapes.Rect(0, 0, 10, 10)) g.add(shapes.Rect(50, 50, 10, 10)) assert g.getBounds() == (0, 0, 60, 60) g.translate(40, 40) assert g.getBounds() == (40, 40, 100, 100) g.translate(-40, -40) g.rotate(90) #approx bounds needed, trig functions create an error of 3e-15 assert list(map(int, g.getBounds())) == [-60, 0, 0, 60]
def draw(self): g = shapes.Group() for attr, info in filter(lambda x: x[1]["visible"], self.render_info.items()): if hasattr(self, attr): val = getattr(self, attr) if val is not None: fs = info["font_size"] * self.baseheight rel = info["offset_relative"] y = self.y if rel == "self": x = self.x elif rel == "edge" and self.parent: x = self.x - (self.x - self.parent.x) * 0.5 dx = info["x_offset"] * fs dy = info["y_offset"] * fs label = shapes.String(x + dx, y + dy, info["format"] % val, fontName=info["font"], fontSize=fs, fillColor=info["font_color"], textAnchor=info["text_anchor"]) g.add(label) if self.parent: pl = shapes.PolyLine([ self.x, self.y, self.parent.x, self.y, self.parent.x, self.parent.y ], strokeWidth=max(self.calc_strokewidth(), 1.0), strokeColor=self.stroke_color, fillColor=None) g.add(pl) ## thicken strongly supported branches if self.thicken: pl = shapes.PolyLine( [ self.x, self.y, self.parent.x - self.parent.calc_strokewidth() / 2.0, self.y ], strokeWidth=max(self.calc_strokewidth(), 1.0) * 4, strokeColor=self.stroke_color, fillColor=None) g.add(pl) for d in self.drawables: g.add(d) return g
def process(self): attrs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) angle = attrs.pop('angle', 0) x, y = attrs.pop('dx'), attrs.pop('dy') self.drawing = shapes.Drawing(attrs.pop('dwidth'), attrs.pop('dheight')) self.context = chart = self.createChart(attrs) self.processSubDirectives() group = shapes.Group(chart) group.translate(0, 0) group.rotate(angle) self.drawing.add(group) manager = attr.getManager(self, interfaces.ICanvasManager) self.drawing.drawOn(manager.canvas, x, y)
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() ew = self.strokeWidth ae = s * 0.125 #(ae = 'an eighth') # danger sign specific bits ew = self.strokeWidth ae = s * 0.125 #(ae = 'an eighth') outerTriangle = shapes.Polygon(points=[ self.x, self.y, self.x + s, self.y, self.x + (s / 2), self.y + s ], fillColor=None, strokeColor=self.strokeColor, strokeWidth=0) g.add(outerTriangle) innerTriangle = shapes.Polygon(points=[ self.x + (s / 50), self.y + (s / 75), (self.x + s) - (s / 50), self.y + (s / 75), self.x + (s / 2), (self.y + s) - (s / 50) ], fillColor=self.fillColor, strokeColor=None, strokeWidth=0) g.add(innerTriangle) exmark = shapes.Polygon(points=[ ((self.x + s / 2) - ew / 2), self.y + ae * 2.5, ((self.x + s / 2) + ew / 2), self.y + ae * 2.5, ((self.x + s / 2) + ((ew / 2)) + (ew / 6)), self.y + ae * 5.5, ((self.x + s / 2) - ((ew / 2)) - (ew / 6)), self.y + ae * 5.5 ], fillColor=self.strokeColor, strokeColor=None) g.add(exmark) exdot = shapes.Polygon(points=[ ((self.x + s / 2) - ew / 2), self.y + ae, ((self.x + s / 2) + ew / 2), self.y + ae, ((self.x + s / 2) + ew / 2), self.y + ae * 2, ((self.x + s / 2) - ew / 2), self.y + ae * 2 ], fillColor=self.strokeColor, strokeColor=None) g.add(exdot) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # Triangle specific bits ae = s * 0.125 #(ae = 'an eighth') triangle = shapes.Polygon( points=[self.x, self.y, self.x + s, self.y, self.x, self.y + s], fillColor=self.fillColor, strokeColor=self.strokeColor, strokeWidth=s / 50.) g.add(triangle) return g
def _draw_width_by_height_side(self, x0, y0, color=blue): g = shapes.Group() g.add( self._draw_horizontal_line(x0, y0, self._notch_length['w'], self._num_notches['w'], self._thickness, self._cut_width / 2.0, True, True, color)) g.add( self._draw_horizontal_line(x0, y0 + self._size['h'] - self._thickness, self._notch_length['w'], self._num_notches['w'], self._thickness, self._cut_width / 2.0, False, True, color)) return g
def _draw_horizontal_line(self, x0, y0, notch_width, notch_count, notch_height, cut_width, flip, smallside, color): x = x0 y = y0 g = shapes.Group() for step in range(0, int(notch_count)): y = y0 if (((step % 2) == 0) ^ flip) else y0 + notch_height if step == 0: # start first edge in the right place if smallside: l = self._draw_line(x + notch_height, y, x + notch_width + cut_width, y, color) l.strokeWidth = self.strokeWidth g.add(l) else: l = self._draw_line(x, y, x + notch_width + cut_width, y, color) l.strokeWidth = self.strokeWidth g.add(l) elif step == (notch_count - 1): # shorter last edge l = self._draw_line(x - cut_width, y, x + notch_width - notch_height, y, color) l.strokeWidth = self.strokeWidth g.add(l) elif step % 2 == 0: l = self._draw_line(x - cut_width, y, x + notch_width + cut_width, y, color) l.strokeWidth = self.strokeWidth g.add(l) else: l = self._draw_line(x + cut_width, y, x + notch_width - cut_width, y, color) l.strokeWidth = self.strokeWidth g.add(l) if step < (notch_count - 1): if step % 2 == 0: l = self._draw_line(x + notch_width + cut_width, y0 + notch_height, x + notch_width + cut_width, y0, color) l.strokeWidth = self.strokeWidth g.add(l) else: l = self._draw_line(x + notch_width - cut_width, y0 + notch_height, x + notch_width - cut_width, y0, color) l.strokeWidth = self.strokeWidth g.add(l) x = x + notch_width return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # no-entry-sign specific bits if self.strokeColor: g.add(shapes.Circle(cx = (self.x+(s/2)), cy = (self.y+(s/2)), r = s/2, fillColor = None, strokeColor = self.strokeColor, strokeWidth=1)) if self.fillColor: g.add(shapes.Circle(cx = (self.x+(s/2)), cy =(self.y+(s/2)), r = ((s/2)-(s/50)), fillColor = self.fillColor, strokeColor = None, strokeWidth=0)) innerBarColor = self.innerBarColor if innerBarColor: g.add(shapes.Rect(self.x+(s*0.1), self.y+(s*0.4), width=s*0.8, height=s*0.2, fillColor = innerBarColor, strokeColor = innerBarColor, strokeLineCap = 1, strokeWidth = 0)) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # stop-sign specific bits athird = s / 3 outerOctagon = shapes.Polygon(points=[ self.x + athird, self.y, self.x, self.y + athird, self.x, self.y + (athird * 2), self.x + athird, self.y + s, self.x + (athird * 2), self.y + s, self.x + s, self.y + (athird * 2), self.x + s, self.y + athird, self.x + (athird * 2), self.y ], strokeColor=self.strokeColor, fillColor=None, strokeWidth=1) g.add(outerOctagon) innerOctagon = shapes.Polygon(points=[ self.x + athird + (s / 75), self.y + (s / 75), self.x + (s / 75), self.y + athird + (s / 75), self.x + (s / 75), self.y + (athird * 2) - (s / 75), self.x + athird + (s / 75), self.y + s - (s / 75), self.x + (athird * 2) - (s / 75), (self.y + s) - (s / 75), (self.x + s) - (s / 75), self.y + (athird * 2) - (s / 75), (self.x + s) - (s / 75), self.y + athird + (s / 75), self.x + (athird * 2) - (s / 75), self.y + (s / 75) ], strokeColor=None, fillColor=self.fillColor, strokeWidth=0) g.add(innerOctagon) if self.stopColor: g.add( shapes.String(self.x + (s * 0.5), self.y + (s * 0.4), 'STOP', fillColor=self.stopColor, textAnchor='middle', fontSize=s / 3, fontName="Helvetica-Bold")) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() strokeColor = self.strokeColor # not=allowed specific bits outerCircle = shapes.Circle(cx=(self.x + (s / 2)), cy=(self.y + (s / 2)), r=(s / 2) - (s / 10), fillColor=self.fillColor, strokeColor=strokeColor, strokeWidth=s / 10.) g.add(outerCircle) centerx = self.x + s centery = self.y + (s / 2) - (s / 6) radius = s - (s / 6) yradius = radius / 2 xradius = radius / 2 startangledegrees = 100 endangledegrees = -80 degreedelta = 90 pointslist = [] a = pointslist.append from math import sin, cos, pi degreestoradians = pi / 180.0 radiansdelta = degreedelta * degreestoradians startangle = startangledegrees * degreestoradians endangle = endangledegrees * degreestoradians while endangle < startangle: endangle = endangle + 2 * pi angle = startangle while angle < endangle: x = centerx + cos(angle) * radius y = centery + sin(angle) * yradius a(x) a(y) angle = angle + radiansdelta crossbar = shapes.PolyLine(pointslist, fillColor=strokeColor, strokeColor=strokeColor, strokeWidth=s / 10.) g.add(crossbar) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # Octagon specific bits athird = s / 3 octagon = shapes.Polygon(points=[ self.x + athird, self.y, self.x, self.y + athird, self.x, self.y + (athird * 2), self.x + athird, self.y + s, self.x + (athird * 2), self.y + s, self.x + s, self.y + (athird * 2), self.x + s, self.y + athird, self.x + (athird * 2), self.y ], strokeColor=self.strokeColor, fillColor=self.fillColor, strokeWidth=10) g.add(octagon) return g
def draw(self): # general widget bits w = float(self.length) h = float(self.height) g = shapes.Group() block = shapes.Rect(x=self.x, y=self.y-h/2, width=self.length, height=h, fillColor=self.fillColor, strokeColor=self.strokeColor, strokeWidth=self.strokeWidth) g.add(block) point = shapes.Polygon( points=[self.x+w, self.y-h/2, self.x+w+signum(w)*h/4, self.y, self.x+w, self.y+h/2, self.x+w, self.y-h/2], fillColor=self.fillColor, strokeColor=self.strokeColor, strokeWidth=self.strokeWidth) g.add(point) return g
def drawString(self, s, x,y, font=None, color=None, angle=0, **kwargs): # set color... if color: if color == transparent: return elif self.defaultLineColor == transparent: return else: color = self.defaultLineColor color = colorToRL(color) if font is None: font = self.defaultFont txt = shapes.String(0,0,s,fillColor=color) txt.fontName=self._findPostScriptFontName(font) txt.fontSize=font.size g=shapes.Group(txt) g.translate(x,self.fixY(y)) g.rotate(angle) self.drawing.add(g) return
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # arrow specific bits body = shapes.Rect(x=self.x, y=(self.y+(s/2))-(s/24), width=9*(s/10), height=(s/12), fillColor = self.fillColor, strokeColor = None, strokeWidth=0) g.add(body) head = shapes.Polygon(points = [self.x+(2.5*(s/3)), (self.y+(s/2)), self.x+(4*(s/6)), self.y+4*(s/6), self.x+s, self.y+(s/2), self.x+(4*(s/6)), self.y+2*(s/6)], fillColor = self.fillColor, strokeColor = None, strokeWidth=0) g.add(head) return g
def draw_address(label, width, height, address): assert address.state, address assert address.zip, address # The order is flipped, because we're painting from bottom to top. # The Some of the lines get .upper(), because that's what the USPS likes. lines = [ ('%s %s %s' % (address.city, address.state, address.zip)).upper(), address.street2.upper(), address.street1.upper(), address.name2, address.name, ] group = shapes.Group() x, y = 0, 0 for line in lines: if not line: continue shape = shapes.String(x, y, line, textAnchor="start") _, _, _, y = shape.getBounds() # Some extra spacing between the lines, to make it easier to read y += 3 group.add(shape) _, _, lx, ly = label.getBounds() _, _, gx, gy = group.getBounds() # Make sure the label fits in a sticker assert gx <= lx, (address, gx, lx) assert gy <= ly, (address, gy, ly) # Move the content to the center of the sticker dx = (lx - gx) / 2 dy = (ly - gy) / 2 group.translate(dx, dy) label.add(group)
def draw(self): """Just return a group""" return shapes.Group(self.faceOne, self.faceTwo)
def draw(self): return shapes.Group(self.leftCircle, self.rightCircle)