def draw(self, cr): x = self.x y = self.y background_colour = self.background_colour background_colour[3] *= self.opacity cr.set_source_rgba(*background_colour) rounded_rectangle(cr, x, y, self.width, self.height, 5, 5) cr.fill() cr.save() cr.set_operator(cairo.OPERATOR_SOURCE) rounded_rectangle(cr, x, y, self.width, self.height, 5, 5) border_colour = self.border_colour border_colour[3] *= self.opacity cr.set_source_rgba(*border_colour) cr.set_line_width(self.border_width) cr.stroke() cr.restore() if self._thumbnail is not None: cr.set_source_surface(self._thumbnail, x + self.inner_space, y + self.inner_space) cr.rectangle(x + self.inner_space, y + self.inner_space, 40, 40) cr.fill() text_space_left = x + self.image_size + self.inner_space * 2 else: text_space_left = x + self.inner_space * 2 pg = pangocairo.CairoContext(cr) pgl = pg.create_layout() pgl.set_font_description(self.title_font) pgl.set_markup(self.title) cr.move_to(text_space_left, y + self.inner_space) title_colour = self.title_colour title_colour[3] *= self.opacity cr.set_source_rgba(*title_colour) pg.show_layout(pgl) if self.caption is not None: pgl = pgl.copy() pgl.set_font_description(self.caption_font) pgl.set_markup(self.caption) cr.move_to(text_space_left, y + self.height - pgl.get_pixel_size()[1] - self.inner_space) caption_colour = self.caption_colour caption_colour[3] *= self.opacity cr.set_source_rgba(*caption_colour) pg.show_layout(pgl)
def draw_window(self, widget, event, type="key"): c = widget.window.cairo_create() #Make the window transparent width = widget.get_allocation().width height = widget.get_allocation().height c.set_source_rgba(0.0, 0.0, 0.0, 0.0) c.set_operator(cairo.OPERATOR_SOURCE) c.paint() c.set_operator(cairo.OPERATOR_OVER) self.pg = pangocairo.CairoContext(c) self.pgl = self.pg.create_layout() self.pgl.set_width(gtk.gdk.screen_get_default().get_width() * pango.SCALE) pgfont = pango.FontDescription("sans 28") pgfont.set_family("Droid Sans") self.pgl.set_font_description(pgfont) text = markup_escape_text(self._searchbox.get_text()) self.pgl.set_markup('<span letter_spacing="-1000">%s</span>' % text) cursor_pos = _char_offset_to_byte_offset(self._searchbox.get_position(), text) #sort out selected text try: selected = self._searchbox.get_selection_bounds() selected_1_pos = self.pgl.get_cursor_pos(_char_offset_to_byte_offset(selected[0], text))[0] selected_2_pos = self.pgl.get_cursor_pos(_char_offset_to_byte_offset(selected[1], text))[0] except IndexError: selected_1_pos = None (pglw, pglh) = self.pgl.get_pixel_size() print pglw, pglh width = max(120, pglw + 80) height = max(120, pglh + 80) widget.resize(width, height) pglx = (width / 2) - (pglw / 2) pgly = (height / 2) - (pglh / 2) print pglx, pgly c.set_source_rgba(0.0, 0.0, 0.0, 0.7) rounded_rectangle(c, 20, 20, width - 40, height - 40, 10, 10) c.fill() rounded_rectangle(c, 20, 20, width - 40, height - 40, 10, 10) c.set_source_rgba(0.2, 0.2, 0.2, 0.7) c.stroke() if selected_1_pos is not None: c.set_source_rgba(1, 1, 1, 0.1) selected_w = (selected_2_pos[0] - selected_1_pos[0]) / pango.SCALE rounded_rectangle(c, selected_1_pos[0] / pango.SCALE + pglx - 5, selected_1_pos[1] / pango.SCALE + pgly - 5, selected_w + 10, selected_1_pos[3] / pango.SCALE + 10, 5, 5) c.fill() c.set_source_rgb(1, 1, 1) c.move_to(pglx, pgly) self.pg.update_layout(self.pgl) self.pg.show_layout(self.pgl) # Draw the cursor if len(text) and cursor_pos != len(text): cursor_pos = self.pgl.get_cursor_pos(cursor_pos)[0] c.set_source_rgba(1, 1, 1, 0.7) c.rectangle(cursor_pos[0] / pango.SCALE + pglx, cursor_pos[1] / pango.SCALE + pgly, 1, cursor_pos[3] / pango.SCALE) c.fill()