def on_system_paint(self, ev): bitmap = self.bitmap painter = Painter(self.bitmap) border = self.border_width() width = self.window_width() height = self.window_height() caption_color = SteelBlue if self.active() else LightSteelBlue border_color = 0xaaffffff & caption_color if self.attr() & WND_TRANSPARENT: painter.clear() else: painter.fill_rect(self.margin_left(), self.margin_top(), self.width(), self.height(), White) if self.attr() & WND_FRAME: rc = Rect(0, 0, self.window_width() - 1, self.window_height() - 1) max_alpha = 40 if self.active() else 20 dalpha = max_alpha / DEFAULT_BORDER_WIDTH for i in xrange(DEFAULT_BORDER_WIDTH - 1): painter.set_pen_color(i * dalpha << 24) painter.draw_rect(rc) rc.adjust(1, 1, -1, -1) painter.set_pen_color(caption_color) painter.draw_rect(rc) if self.attr() & WND_CAPTION: # fill caption caption_color &= 0xddffffff caption_rc = Rect(border, border, width - 2 * border, self.caption_height()) painter.fill_rect(rc, caption_color) # draw title painter.set_pen_color(White) rc = caption_rc.translated(10, 0) painter.draw_text(rc, Painter.AlignLeft | Painter.AlignVCenter, self.title_) # draw close/maximize/minimize painter.save() painter.set_pen_color(DarkWhite) painter.set_render_hint(Painter.Antialiasing) # close painter.set_pen_width(2) rc = Rect(self.close_rect()) painter.draw_line(rc.top_left(), rc.bottom_right()) painter.draw_line(rc.top_right(), rc.bottom_left()) # maximize painter.draw_rect(Rect(self.maximize_rect())) # minimize rc = Rect(self.minimize_rect()) painter.draw_line(rc.bottom_left(), rc.bottom_right()) painter.restore()
class MathFrac(MultiItem): """Container for inline maths""" def __init__(self, num = None, denom = None): MultiItem.__init__(self) self.style = 'math-var', 1 if num: if not denom: denom = MathNumber('1') self.appendItem(num) self.appendItem(denom) def resizePDF(self, pdf, x = 0, y = 0): if len(self.items) < 2 or not self.items[0] or not self.items[1]: raise Exception('MathFrac must have two items.') self.rect = Rect(x,y,x,y) dx = pdf.get_string_width(' ') * self.style[1] self.margins.set(dx, 0.0) setFontPDF(pdf, self.style, self.styles) lineHeight = pdf.font_size_pt / pdf.k numerator = self.items[0] if hasattr(numerator,'style'): setFontPDF(pdf, numerator.style, self.styles) numerator.resizePDF(pdf,x + dx, y - lineHeight * 0.5) denominator = self.items[1] if hasattr(denominator,'style'): setFontPDF(pdf, denominator.style, self.styles) denominator.resizePDF(pdf, x + dx, numerator.rect.y1()) if numerator.rect.width() > denominator.rect.width(): denominator.rect.alignXCenter(numerator.rect) else: numerator.rect.alignXCenter(denominator.rect) self.rect.unite(numerator.rect) self.rect.unite(denominator.rect) self.rect.adjust(rect.Point(0,0),rect.Point(dx,0)) def cellPDF(self, pdf, r = None): MultiItem.cellPDF(self, pdf, r) y = self.items[0].rect.y1() pdf.set_line_width(0.2) if r: x_shift = r.x0() y_shift = r.y0() else: x_shift = 0.0 y_shift = 0.0 pdf.line(self.rect.x0() - x_shift, y - y_shift, self.rect.x1() - x_shift, y - y_shift)