def frame_on_expose(self, evt): log.warn("expose! %s", self) context = self.context cr = context.cr if False: context.fill((255, 0, 255)) context.text(0, 10, self.window.get_property("WM_NAME")[0], (255, 255, 255)) # fred: why do I have to set y=10? # dunk: because its specifying the baseline of the text not the top else: g = self.frame.get_geometry() log.warn(str((g, dir(g)))) cairo.cairo_set_antialias(cr, cairo.CAIRO_ANTIALIAS_NONE) cairo.cairo_set_line_width(cr, 1) cairo.cairo_set_source_rgb(cr, 0.8, 0.0, 0.0) cairo.cairo_rectangle(cr, 0, 0, g["width"] - 1, g["height"] - 1) cairo.cairo_fill_preserve(cr) cairo.cairo_set_source_rgb(cr, 1.0, 1.0, 1.0) cairo.cairo_stroke(cr) context.text( self.style["border"] + 1, self.style["border"] + 1 + context.default_font_size, self.window.get_property("WM_NAME")[0], (255, 255, 255), ) # TODO should the client know its own connection? self.window.connection.flush()
def fillrect(self, x, y, width, height, color): if False: pat = cairo.cairo_pattern_create_linear (0.0, 0.0, width, 0.0) cairo.cairo_pattern_add_color_stop_rgba (pat, 0.0, 1.0, 0.0, 0.0, 1.0) cairo.cairo_pattern_add_color_stop_rgba (pat, width/3, 0.1, 0.0, 0.0, 1.0) cairo.cairo_pattern_add_color_stop_rgba (pat, width, 0.0, 0.0, 0.0, 1.0) cairo.cairo_rectangle(self.cr, x, y, width, height) cairo.cairo_set_source(self.cr, pat) cairo.cairo_fill(self.cr) cairo.cairo_pattern_destroy(pat) else: cairo.cairo_set_source_rgb(self.cr, color[0], color[1], color[2]) cairo.cairo_rectangle(self.cr, x, y, width, height) cairo.cairo_fill(self.cr) self.connection.flush()
def text(self, x, y, string, color=(0.0, 0.0, 0.0), font=None, bold=False, align=None, font_size=None): cairo.cairo_set_source_rgb(self.cr, color[0], color[1], color[2]) if font is None: font = self.default_font if font_size is None: font_size = self.default_font_size if bold: weight = cairo.CAIRO_FONT_WEIGHT_BOLD else: weight = cairo.CAIRO_FONT_WEIGHT_NORMAL cairo.cairo_select_font_face(self.cr, font, cairo.CAIRO_FONT_SLANT_NORMAL, weight) cairo.cairo_set_font_size(self.cr, font_size) if align and align != 'left': #typedef struct { # double x_bearing; # double y_bearing; # double width; # double height; # double x_advance; # double y_advance; #} cairo.cairo_text_extents_t; extents = cairo.cairo_text_extents_t() cairo.cairo_text_extents(self.cr, string, byref(extents)) if align == "right": x -= extents.x_advance cairo.cairo_move_to(self.cr, x, y) cairo.cairo_show_text(self.cr, string) self.connection.flush()
def fill(self, color=(0.0, 0.0, 0.0)): cairo.cairo_set_source_rgb(self.cr, *color) cairo.cairo_paint(self.cr) self.connection.flush()