def draw(self, cr): w_size = utils.text_size(cr, "W")[1] + 6 if self.tokens_count == 0: return px, py = self.get_position() text_width = 0 all = self.removed_tokens + self.tokens + self.new_tokens if all: text_width = max(utils.text_size(cr, t)[0] for t in all) + 5 size_y = len(all) * w_size self.size = (text_width, size_y) self.visual_position = (px + 10, py - size_y / 2) top = py - size_y / 2 + 2 y = top if self.removed_tokens: cr.set_source_rgba(0.2, 0.2, 0.2, 0.7) cr.rectangle(px + 10, y + 4, text_width + 6, w_size * len(self.removed_tokens)) cr.fill() y += w_size * len(self.removed_tokens) if self.tokens: cr.set_source_rgba(0.2, 0.45, 0, 0.7) cr.rectangle(px + 10, y + 4, text_width + 6, w_size * len(self.tokens)) cr.fill() y += w_size * len(self.tokens) if self.new_tokens: cr.set_source_rgba(0.2,0.7,0,0.7) cr.rectangle(px + 10, y + 4, text_width + 6, w_size * len(self.new_tokens)) cr.fill() y += w_size * len(self.new_tokens) y = top cr.set_source_rgb(1.0,1.0,1.0) for t in all: y += w_size cr.move_to(px + 15, y) cr.show_text(t) if self.new_tokens: cr.set_source_rgb(0.2,0.6,0) else: cr.set_source_rgb(0.2,0.45,0) cr.new_sub_path() cr.arc(px, py, 8, 0, 2 * math.pi) cr.fill() cr.set_line_width(0.5) cr.new_sub_path() cr.arc(px, py, 8, 0, 2 * math.pi) cr.set_source_rgb(0,0,0) cr.stroke() drawing.draw_centered_text(cr, px, py, str(self.tokens_count))
def draw_text(cr, px, py, text, align_x, align_y, padding_left=0, padding_top=0, padding_right=0, padding_bottom=0, background_color=None, border_color=None, border_width=1, radius=None): if isinstance(text, str) or isinstance(text, unicode): lines = text.replace("\t", " ").split("\n") else: lines = text sizes = [utils.text_size(cr, text)[0] for text in lines] tx = max(sizes) w_height = utils.text_size(cr, "W")[1] + 2 count = len(lines) x = px - tx * align_x y = py + w_height * count * align_y sx = tx + padding_left + padding_right sy = w_height * count + padding_top + padding_bottom if background_color is not None: cr.save() cr.set_source_rgba(*background_color) if radius: rounded_rectangle(cr, x - padding_left, y - padding_top - w_height * count, sx, sy, radius) else: cr.rectangle(x - padding_left, y - padding_top - w_height * count, sx, sy) cr.fill() cr.restore() if border_color is not None: cr.save() cr.set_source_rgba(*border_color) cr.set_line_width(border_width) if radius: rounded_rectangle(cr, x - padding_left, y - padding_top - w_height * count, sx, sy, radius) else: cr.rectangle(x - padding_left, y - padding_top - w_height * count, sx, sy) cr.stroke() cr.restore() for i in xrange(count): j = count - i - 1 cr.move_to(px - sizes[j] * align_x, y - i * w_height) cr.show_text(lines[j]) return (sx, sy)
def draw_label(cr, x, y, text, symbol, text_color, background_color): tw = 0 th = 0 for txt in text: tx, ty = utils.text_size(cr, txt, 8) th += ty tw = tw if tw > tx else tx cr.set_line_width(2) rounded_rectangle(cr, x, y, tw + 40, th + len(text) * 10, 10) cr.set_source_rgba(background_color[0], background_color[1], background_color[2], 0.9) cr.fill() rounded_rectangle(cr, x, y, tw + 40, th + len(text) * 10, 10) cr.set_source_rgb(*background_color) cr.stroke() cr.set_source_rgb(*text_color) th = -5 for txt in text: tx, ty = utils.text_size(cr, txt, 8) th += ty + 10 cr.move_to(x + 25, y + th) cr.show_text(txt) cr.fill() if symbol == "lookingglass": cr.new_sub_path() cr.arc(x + 12, y + 7, 4, 0, 2 * math.pi) cr.move_to(x + 16, y + 11) cr.rel_line_to(5, 5) cr.stroke() elif symbol == "arrow": cr.set_line_width(1) cr.move_to(x + 8, y + 5) cr.rel_line_to(4, 4) cr.rel_line_to(-4, 4) cr.close_path() cr.stroke() cr.move_to(x + 13, y + 4) cr.rel_line_to(5, 5) cr.rel_line_to(-5, 5) cr.fill() rounded_rectangle(cr, x + 5, y + 2, 15, 14, 3) cr.stroke() elif symbol == "tick": cr.set_line_width(2) cr.move_to(x + 5, y + 10) cr.rel_line_to(4, 3) cr.rel_line_to(9, -10) cr.stroke()
def get_size(self, cr): if not self.texts: return tx = max(utils.text_size(cr, t)[0] for t in self.texts) tx += 20 ty = 13 * len(self.texts) + 4 return (tx, ty)
def draw_text(cr, px, py, text, align_x, align_y, padding_left=0, padding_top=0, padding_right=0, padding_bottom=0, background_color=None, border_color=None, border_width=1, radius=None): if isinstance(text, str) or isinstance(text, unicode): lines = text.replace("\t", " ").split("\n") else: lines = text sizes = [ utils.text_size(cr, text)[0] for text in lines ] tx = max(sizes) w_height = utils.text_size(cr, "W")[1] + 2 count = len(lines) x = px - tx * align_x y = py + w_height * count * align_y sx = tx + padding_left + padding_right sy = w_height * count + padding_top + padding_bottom if background_color is not None: cr.save() cr.set_source_rgba(*background_color) if radius: rounded_rectangle(cr, x - padding_left, y - padding_top - w_height * count, sx, sy, radius) else: cr.rectangle(x - padding_left, y - padding_top - w_height * count, sx, sy) cr.fill() cr.restore() if border_color is not None: cr.save() cr.set_source_rgba(*border_color) cr.set_line_width(border_width) if radius: rounded_rectangle(cr, x - padding_left, y - padding_top - w_height * count, sx, sy, radius) else: cr.rectangle(x - padding_left, y - padding_top - w_height * count, sx, sy) cr.stroke() cr.restore() for i in xrange(count): j = count - i - 1 cr.move_to(px - sizes[j] * align_x, y - i * w_height) cr.show_text(lines[j]) return (sx, sy)
def draw(self, cr): px, py = self.get_position() w_size = utils.text_size(cr, "W")[1] cr.set_source_rgba(0.4, 0.4, 0.4, 0.8) cr.move_to(px - 3, py - w_size) cr.rel_line_to(8, 0) cr.rel_line_to(-3, w_size) cr.rel_line_to(3, w_size) cr.rel_line_to(-8, 0) cr.rel_line_to(0, -2 * w_size) cr.fill() """
def draw(self, cr): px, py = self.get_position() w_size = utils.text_size(cr, "W")[1] cr.set_source_rgba(0.4, 0.4, 0.4,0.8) cr.move_to(px - 3, py - w_size) cr.rel_line_to(8, 0) cr.rel_line_to(-3, w_size) cr.rel_line_to(3, w_size) cr.rel_line_to(-8, 0) cr.rel_line_to(0, -2 * w_size) cr.fill() """
def draw_text(cr, px, py, text, align_x, align_y, padding_x=0, padding_y=0, background_color=None, border_color=None, radius=None): lines = text.strip().replace("\t", " ").split("\n") sizes = [ utils.text_size(cr, text)[0] for text in lines ] tx = max(sizes) w_height = utils.text_size(cr, "W")[1] + 2 count = len(lines) x = px - tx * align_x y = py + w_height * count * align_y sx = tx + padding_x * 2 sy = w_height * count + padding_y * 2 if background_color is not None: cr.save() cr.set_source_rgba(*background_color) if radius: rounded_rectangle(cr, x - padding_x, y - padding_y - sy, sx, sy, radius) else: cr.rectangle(x - padding_x, y - padding_y - w_height * count, sx, sy) cr.fill() cr.restore() if border_color is not None: cr.save() cr.set_source_rgba(*border_color) if radius: rounded_rectangle(cr, x - padding_x, y - padding_y - sy, sx, sy, radius) else: cr.rectangle(x - padding_x, y - padding_y - w_height * count, sx, sy) cr.stroke() cr.restore() for i in xrange(count): j = count - i - 1 cr.move_to(px - sizes[j] * align_x, y - i * w_height) cr.show_text(lines[j]) return (sx, sy)
def draw(self, cr): w_size = utils.text_size(cr, "W")[1] + 6 if self.tokens_count == 0: return px, py = self.get_position() text_width = 0 all = self.removed_tokens + self.tokens + self.new_tokens if all: text_width = max(utils.text_size(cr, t)[0] for t in all) + 5 size_y = len(all) * w_size self.size = (text_width, size_y) self.visual_position = (px + 10, py - size_y / 2) top = py - size_y / 2 + 2 y = top if self.removed_tokens: cr.set_source_rgba(0.2, 0.2, 0.2, 0.7) cr.rectangle(px + 10, y + 4, text_width + 6, w_size * len(self.removed_tokens)) cr.fill() y += w_size * len(self.removed_tokens) if self.tokens: cr.set_source_rgba(0.2, 0.45, 0, 0.7) cr.rectangle(px + 10, y + 4, text_width + 6, w_size * len(self.tokens)) cr.fill() y += w_size * len(self.tokens) if self.new_tokens: cr.set_source_rgba(0.2, 0.7, 0, 0.7) cr.rectangle(px + 10, y + 4, text_width + 6, w_size * len(self.new_tokens)) cr.fill() y += w_size * len(self.new_tokens) y = top cr.set_source_rgb(1.0, 1.0, 1.0) for t in all: y += w_size cr.move_to(px + 15, y) cr.show_text(t) if self.new_tokens: cr.set_source_rgb(0.2, 0.6, 0) else: cr.set_source_rgb(0.2, 0.45, 0) cr.new_sub_path() cr.arc(px, py, 8, 0, 2 * math.pi) cr.fill() cr.set_line_width(0.5) cr.new_sub_path() cr.arc(px, py, 8, 0, 2 * math.pi) cr.set_source_rgb(0, 0, 0) cr.stroke() drawing.draw_centered_text(cr, px, py, str(self.tokens_count))