def addCanvasText(self, text, pos, font, color=(0, 0, 0), **kwargs): text = re.sub(r'\<.+?\>', '', text) font = pid.Font(face=faceMap[font.face], size=font.size) txtWidth, txtHeight = self.canvas.stringBox(text, font) bw, bh = txtWidth + txtHeight * 0.4, txtHeight * 1.4 offset = txtWidth * pos[2] labelP = pos[0] - txtWidth / 2 + offset, pos[1] + txtHeight / 2 color = convertColor(color) self.canvas.drawString(text, labelP[0], labelP[1], font, color=color) return (bw, bh, offset)
class VisOpts(object): circRad = 10 minCircRad = 4 maxCircRad = 16 circColor = piddle.Color(0.6,0.6,0.9) terminalEmptyColor = piddle.Color(.8,.8,.2) terminalOnColor = piddle.Color(0.8,0.8,0.8) terminalOffColor = piddle.Color(0.2,0.2,0.2) outlineColor = piddle.transparent lineColor = piddle.Color(0,0,0) lineWidth = 2 horizOffset = 10 vertOffset = 50 labelFont = piddle.Font(face='helvetica',size=10) highlightColor = piddle.Color(1.,1.,.4) highlightWidth = 2
def _drawRotatedString(self, lines, x, y, font=None, color=None, angle=0): import math # [kbj] Hack since the default system font may not be able to rotate. if font is None: font = sping_pid.Font(face='helvetica') self._setWXfont(font) ascent = self.fontAscent(font) height = self.fontHeight(font) rad = angle * math.pi / 180. s = math.sin(rad) c = math.cos(rad) dx = s * height dy = c * height lx = x - dx ly = y - c * ascent for i in range(0, len(lines)): self.dc.DrawRotatedText(lines[i], lx + i * dx, ly + i * dy, angle)
def addCanvasText(self, text, pos, font, color=(0, 0, 0), **kwargs): text = re.sub(r'\<.+?\>', '', text) 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) self.canvas.drawString(text, labelP[0], labelP[1], font, color=color)