def do_render(self, cr, widget, background_area, cell_area, flags): # GTK 3 layout = widget.create_pango_layout(self.text) a, rect = layout.get_pixel_extents() context = widget.get_style_context() image_y = int(0.5 * (cell_area.height - self.image.get_height())) gtk.render_icon(context, cr, self.image, cell_area.x, cell_area.y) text_y = int(0.5 * (cell_area.height - (rect.y + rect.height))) gtk.render_layout(context, cr, cell_area.x + CELL_TEXT_INDENT, cell_area.y + text_y, layout)
def do_render_gtk3(self, cr, widget, background_area, cell_area, flags): x_offset, y_offset, width, height = self.do_get_size(widget, cell_area) # Center the label y_offset = cell_area.height / 2 - height / 2 # Draws label context = widget.get_style_context() gtk.render_layout(context, cr, cell_area.x + x_offset, cell_area.y + y_offset, self._label_layout) if not self._details_callback: return gtk.render_line(context, cr, cell_area.x, cell_area.y, cell_area.x + cell_area.width, cell_area.y + cell_area.height - 1)
def do_render(self, cr, widget, background_area, cell_area, flags): if not self.visible: return state = gtk.StateFlags.NORMAL if self.clicking and flags & gtk.CELL_RENDERER_SELECTED: state = gtk.StateFlags.ACTIVE elif not self.sensitive: state = gtk.StateFlags.INSENSITIVE context = widget.get_style_context() context.save() context.add_class('button') context.set_state(state) xpad, ypad = self.get_padding() x = cell_area.x + xpad y = cell_area.y + ypad w = cell_area.width - 2 * xpad h = cell_area.height - 2 * ypad gtk.render_background(context, cr, x, y, w, h) gtk.render_frame(context, cr, x, y, w, h) padding = context.get_padding(state) layout = widget.create_pango_layout(self.text) layout.set_width((w - padding.left - padding.right) * pango.SCALE) layout.set_ellipsize(pango.ELLIPSIZE_END) layout.set_wrap(pango.WRAP_CHAR) lw, lh = layout.get_size() # Can not use get_pixel_extents lw /= pango.SCALE lh /= pango.SCALE if w < lw: x = x + padding.left else: x = x + padding.left + 0.5 * (w - padding.left - padding.right - lw) y = y + padding.top + 0.5 * (h - padding.top - padding.bottom - lh) gtk.render_layout(context, cr, x, y, layout) context.restore()
def do_render(self, cr, widget, background_area, cell_area, flags): if not self.visible: return button_width = self.button_width() state = self.get_state(widget, flags) context = widget.get_style_context() context.save() context.add_class('button') xpad, ypad = self.get_padding() x = cell_area.x + xpad y = cell_area.y + ypad w = cell_area.width - 2 * xpad h = cell_area.height - 2 * ypad padding = context.get_padding(state) layout = widget.create_pango_layout(self.size) lwidth = w - button_width - padding.left - padding.right if lwidth < 0: lwidth = 0 layout.set_width(lwidth * pango.SCALE) layout.set_ellipsize(pango.ELLIPSIZE_END) layout.set_wrap(pango.WRAP_CHAR) layout.set_alignment(pango.ALIGN_RIGHT) if lwidth > 0: lw, lh = layout.get_size() # Can not use get_pixel_extents lw /= pango.SCALE lh /= pango.SCALE lx = x + padding.left if self.buttons and self.buttons[0] == 'open': pxbf_width = self.images['open'][2] lx += pxbf_width + 2 * BUTTON_BORDER + BUTTON_SPACING ly = y + padding.top + 0.5 * (h - padding.top - padding.bottom - lh) gtk.render_layout(context, cr, lx, ly, layout) for index, button_name in enumerate(self.buttons): pxbf_sens, pxbf_insens, pxbf_width, pxbf_height = \ self.images[button_name] if (not self.editable and button_name in {'select', 'clear'} or not self.size and button_name in {'open', 'save'}): pixbuf = pxbf_insens else: pixbuf = pxbf_sens if index == 0 and button_name == 'open': x_offset = 0 else: x_offset = (w - button_width + (pxbf_width + (2 * BUTTON_BORDER) + BUTTON_SPACING) * index) if x_offset < 0: continue bx = cell_area.x + x_offset by = cell_area.y bw = pxbf_width + (2 * BUTTON_BORDER) gtk.render_background(context, cr, bx, by, bw, h) gtk.render_frame(context, cr, bx, by, bw, h) gtk.gdk.cairo_set_source_pixbuf(cr, pixbuf, bx + BUTTON_BORDER, by + (h - pxbf_height) / 2) cr.paint() context.restore()
def do_render(self, cr, widget, background_area, cell_area, flags): if not self.visible: return button_width = self.button_width() state = self.get_state(widget, flags) context = widget.get_style_context() context.save() context.add_class('button') xpad, ypad = self.get_padding() x = cell_area.x + xpad y = cell_area.y + ypad w = cell_area.width - 2 * xpad h = cell_area.height - 2 * ypad padding = context.get_padding(state) layout = widget.create_pango_layout(self.size) lwidth = (min(w / 2, w - button_width) - padding.left - padding.right) if lwidth < 0: lwidth = 0 layout.set_width(lwidth * pango.SCALE) layout.set_ellipsize(pango.ELLIPSIZE_END) layout.set_wrap(pango.WRAP_CHAR) if lwidth > 0: lw, lh = layout.get_size() # Can not use get_pixel_extents lw /= pango.SCALE lh /= pango.SCALE lx = x + padding.left ly = y + padding.top + 0.5 * (h - padding.top - padding.bottom - lh) gtk.render_layout(context, cr, lx, ly, layout) for index, button_name in enumerate(self.buttons): pxbf_sens, pxbf_insens, pxbf_width, pxbf_height = \ self.images[button_name] state = gtk.StateFlags.NORMAL if (self.clicking == button_name and flags & gtk.CELL_RENDERER_SELECTED): state = gtk.StateFlags.ACTIVE if (not self.editable and button_name in {'select', 'clear'} or not self.size and button_name in {'open', 'save'}): state = gtk.StateFlags.INSENSITIVE pixbuf = pxbf_insens else: pixbuf = pxbf_sens x_offset = (w - button_width + (pxbf_width + (2 * BUTTON_BORDER) + BUTTON_SPACING) * index) if x_offset < 0: continue bx = cell_area.x + x_offset by = cell_area.y bw = pxbf_width + (2 * BUTTON_BORDER) gtk.render_background(context, cr, bx, by, bw, h) gtk.render_frame(context, cr, bx, by, bw, h) gtk.gdk.cairo_set_source_pixbuf(cr, pixbuf, bx + BUTTON_BORDER, by + (h - pxbf_height) / 2) cr.paint() context.restore()