def do_draw(self, cr): context = self.get_style_context() context.save() state = self.get_state_flags() if (state & Gtk.StateFlags.NORMAL) == 0: state = Gtk.StateFlags.PRELIGHT context.set_state(state) a = self.get_allocation() x = 0 y = 0 width = a.width height = a.height border = context.get_border(Gtk.StateFlags.PRELIGHT) if self.arrow_type == Gtk.ArrowType.LEFT: width += 2 * border.right elif self.arrow_type == Gtk.ArrowType.RIGHT: x -= border.left width += border.left Gtk.render_background(context, cr, x, y, width, height) Gtk.render_frame(context, cr, x, y, width, height) context.restore() for child in self: self.propagate_draw(child, cr) return
def draw_style_common(context, cr, x, y, width, height): margin = context.get_margin(context.get_state()) border = context.get_border(context.get_state()) padding = context.get_padding(context.get_state()) min_width = context.get_property('min-width', context.get_state()) min_height = context.get_property('min-height', context.get_state()) x += margin.left y += margin.top width -= margin.left + margin.right height -= margin.top + margin.bottom width = max(width, min_width) height = max(height, min_height) Gtk.render_background(context, cr, x, y, width, height) Gtk.render_frame(context, cr, x, y, width, height) contents_x = x + border.left + padding.left contents_y = y + border.top + padding.top contents_width = (width - border.left - border.right - padding.left - padding.right) contents_height = (height - border.top - border.bottom - padding.top - padding.bottom) return contents_x, contents_y, contents_width, contents_height
def _render_progress(self, context, cr, progress, cell_area, ypad, is_rtl): percent = progress * 0.01 # per the spec, the progressbar should be the width of the action # button action_btn = self.get_button_by_name(CellButtonIDs.ACTION) x, _, w, h = action_btn.allocation # shift the bar to the top edge y = cell_area.y + ypad context.save() context.add_class("trough") Gtk.render_background(context, cr, x, y, w, h) Gtk.render_frame(context, cr, x, y, w, h) context.restore() bar_size = w * percent context.save() context.add_class("progressbar") if (bar_size > 0): if is_rtl: x += (w - bar_size) Gtk.render_activity(context, cr, x, y, bar_size, h) context.restore()
def do_draw(self, context, background_area, cell_area, start, end, state): GtkSource.GutterRendererPixbuf.do_draw(self, context, background_area, cell_area, start, end, state) if self.is_action: if Gtk.get_minor_version() < 20: style_context = get_style(None, "GtkButton.flat.image-button") style_context.add_class(Gtk.STYLE_CLASS_BUTTON) style_context.add_class(Gtk.STYLE_CLASS_FLAT) else: # TODO: Fix padding and min-height in CSS and use # draw_style_common style_context = get_style(None, "button.flat.image-button") style_context.set_state(renderer_to_gtk_state(state)) x = background_area.x + 1 y = background_area.y + 1 width = background_area.width - 2 height = background_area.height - 2 Gtk.render_background(style_context, context, x, y, width, height) Gtk.render_frame(style_context, context, x, y, width, height) pixbuf = self.props.pixbuf pix_width, pix_height = pixbuf.props.width, pixbuf.props.height Gtk.render_icon(style_context, context, pixbuf, x + (width - pix_width) // 2, y + (height - pix_height) // 2) self.draw_chunks(context, background_area, cell_area, start, end, state)
def do_draw_bg(self, cr, drawstate): """ Renders the Gtk theme background """ style = drawstate.style style.save() style.add_class(Gtk.STYLE_CLASS_CELL) Gtk.render_background(style, cr, 0, 0, *drawstate.size) style.restore()
def render(self, context, cr, layout): if not self.visible: return x, y, width, height = self.allocation context.save() context.add_class("cellrenderer-button") if self.has_focus: context.set_state(self.state | Gtk.StateFlags.FOCUSED) else: context.set_state(self.state) # render background and focal frame if has-focus context.save() context.add_class(Gtk.STYLE_CLASS_BUTTON) Gtk.render_background(context, cr, x, y, width, height) context.restore() if self.has_focus: Gtk.render_focus(context, cr, x + 3, y + 3, width - 6, height - 6) # position and render layout markup context.save() context.add_class(Gtk.STYLE_CLASS_BUTTON) layout.set_markup(self.markup_variants[self.current_variant], -1) layout_width = layout.get_pixel_extents()[1].width x = x + (width - layout_width) / 2 y += self.ypad Gtk.render_layout(context, cr, x, y, layout) context.restore() context.restore()
def draw_style_common(context, cr, x, y, width, height): margin = context.get_margin(context.get_state()) border = context.get_border(context.get_state()) padding = context.get_padding(context.get_state()) min_width = context.get_property('min-width', context.get_state()) min_height = context.get_property('min-height', context.get_state()) x += margin.left y += margin.top width -= margin.left + margin.right height -= margin.top + margin.bottom width = max(width, min_width) height = max(height, min_height) Gtk.render_background(context, cr, x, y, width, height) Gtk.render_frame(context, cr, x, y, width, height) contents_x = x + border.left + padding.left contents_y = y + border.top + padding.top contents_width = ( width - border.left - border.right - padding.left - padding.right) contents_height = ( height - border.top - border.bottom - padding.top - padding.bottom) return contents_x, contents_y, contents_width, contents_height
def _render_progress(self, context, cr, progress, cell_area, ypad, is_rtl): percent = progress * 0.01 # per the spec, the progressbar should be the width of the action button action_btn = self.get_button_by_name(CellButtonIDs.ACTION) x, _, w, h = action_btn.allocation # shift the bar to the top edge y = cell_area.y + ypad context.save() context.add_class("trough") Gtk.render_background(context, cr, x, y, w, h) Gtk.render_frame(context, cr, x, y, w, h) context.restore () bar_size = w * percent context.save () context.add_class ("progressbar") if (bar_size > 0): if is_rtl: x += (w - bar_size) Gtk.render_activity(context, cr, x, y, bar_size, h) context.restore () return
def on_canvas_draw(self, canvas, cr, width, height): # We proxy the style of the top-level; if we wanted to style the # GtkClutterEmbed widget directly we'd need a custom CSS style # provider and a style class style = self.get_toplevel().get_style_context() Gtk.render_background(style, cr, 0, 0, width, height) return True
def render(self, context, cr, layout): if not self.visible: return x, y, width, height = self.allocation context.save() context.add_class("cellrenderer-button") if self.has_focus: context.set_state(self.state | Gtk.StateFlags.FOCUSED) else: context.set_state(self.state) # render background and focal frame if has-focus context.save() context.add_class(Gtk.STYLE_CLASS_BUTTON) Gtk.render_background(context, cr, x, y, width, height) context.restore() if self.has_focus: Gtk.render_focus(context, cr, x+3, y+3, width-6, height-6) # position and render layout markup context.save() context.add_class(Gtk.STYLE_CLASS_BUTTON) layout.set_markup(self.markup_variants[self.current_variant], -1) layout_width = layout.get_pixel_extents()[1].width x = x + (width - layout_width)/2 y += self.ypad Gtk.render_layout(context, cr, x, y, layout) context.restore() context.restore() return
def _highlight_current_cell(cr, background_area, cell_area, flags): """Draws a 'highlighting' background for the cell. Look depends on the active theme. """ # Use drawing code/CSS for Entry (reason being that it looks best here) dummy_widget = Gtk.Entry() style_context = dummy_widget.get_style_context() style_context.save() # Make it less prominent state = Gtk.StateFlags.INSENSITIVE | Gtk.StateFlags.BACKDROP style_context.set_state(state) color = style_context.get_border_color(state) add_css(dummy_widget, "* { border-color: rgba(%d, %d, %d, 0.3); }" % ( color.red * 255, color.green * 255, color.blue * 255)) ba = background_area ca = cell_area # Draw over the left and right border so we don't see the rounded corners # and borders. Use height for the overshoot as rounded corners + border # should never be larger than the height.. # Ideally we would draw over the whole background but the cell area only # redraws the cell_area so we get leftover artifacts if we draw # above/below. draw_area = (ba.x - ca.height, ca.y, ba.width + ca.height * 2, ca.height) cr.save() cr.new_path() cr.rectangle(ba.x, ca.y, ba.width, ca.height) cr.clip() Gtk.render_background(style_context, cr, *draw_area) Gtk.render_frame(style_context, cr, *draw_area) cr.restore() style_context.restore()
def _cache_bg_for_state(self, state): a = self.get_allocation() # tmp surface on which we render the button bg as per the gtk # theme engine _surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height) cr = cairo.Context(_surf) context = self.get_style_context() context.save() context.set_state(state) Gtk.render_background(context, cr, -5, -5, a.width + 10, a.height + 10) Gtk.render_frame(context, cr, -5, -5, a.width + 10, a.height + 10) del cr # new surface which will be cached which surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height) cr = cairo.Context(surf) # gradient for masking lin = cairo.LinearGradient(0, 0, 0, a.height) lin.add_color_stop_rgba(0.0, 1, 1, 1, 0.1) lin.add_color_stop_rgba(0.25, 1, 1, 1, 0.7) lin.add_color_stop_rgba(0.5, 1, 1, 1, 1.0) lin.add_color_stop_rgba(0.75, 1, 1, 1, 0.7) lin.add_color_stop_rgba(1.0, 1, 1, 1, 0.1) cr.set_source_surface(_surf, 0, 0) cr.mask(lin) del cr # cache the resulting surf... self._bg_cache[state] = surf
def do_draw(self, context, background_area, cell_area, start, end, state): GtkSource.GutterRendererPixbuf.do_draw( self, context, background_area, cell_area, start, end, state) if self.is_action: if Gtk.get_minor_version() < 20: style_context = get_style(None, "GtkButton.flat.image-button") style_context.add_class(Gtk.STYLE_CLASS_BUTTON) style_context.add_class(Gtk.STYLE_CLASS_FLAT) else: # TODO: Fix padding and min-height in CSS and use # draw_style_common style_context = get_style(None, "button.flat.image-button") style_context.set_state(renderer_to_gtk_state(state)) x = background_area.x + 1 y = background_area.y + 1 width = background_area.width - 2 height = background_area.height - 2 Gtk.render_background(style_context, context, x, y, width, height) Gtk.render_frame(style_context, context, x, y, width, height) pixbuf = self.props.pixbuf pix_width, pix_height = pixbuf.props.width, pixbuf.props.height Gtk.render_icon( style_context, context, pixbuf, x + (width - pix_width) // 2, y + (height - pix_height) // 2) self.draw_chunks( context, background_area, cell_area, start, end, state)
def draw_bg(self, cr, alpha): style = self.get_style_context() w, h = self.get_allocated_width(), self.get_allocated_height() cr.push_group() Gtk.render_background(style, cr, 0, 0, w, h) cr.pop_group_to_source() cr.paint_with_alpha(alpha)
def do_draw(self, cr): if self.use_shade: tv = Gtk.TextView() tv_context = tv.get_style_context() width = self.get_allocated_width() height = self.get_allocated_height() Gtk.render_background(tv_context, cr, 0, 0, width, height) self.get_child().draw(cr)
def do_draw(self, cr): """Render a background that fits the allocated space.""" allocation = self.get_allocation() context = self.get_style_context() Gtk.render_background(context, cr, 0, 0, allocation.width, allocation.height) EventIcon.do_draw(self, cr)
def drawing_area_draw(self, widget, cairo_t): context = widget.get_style_context() Gtk.render_background(context, cairo_t, 0, 0, widget.get_allocated_width(), widget.get_allocated_height()) Gtk.render_frame(context, cairo_t, 0, 0, widget.get_allocated_width(), widget.get_allocated_height())
def draw(canvas, cairocontext, width, height): Gtk.render_background( self.get_toplevel().get_style_context(), cairocontext, 0, 0, width, height ) return True
def do_draw(self, cr): '''Gtk widget implementation method''' allocation = self.get_allocation() context = self.get_style_context() Gtk.render_background(context, cr, 0, 0, allocation.width, allocation.height) EventIcon.do_draw(self, cr)
def paint(self, cr, a, context, xo, yo): if self.is_nopaint: return cr.save() x, y = 0, 0 w, h = a.width, a.height arrow_width = 12 # theme['arrow-width'] if isinstance(self, PathPart): _a = self.get_allocation() self.shape.layout(cr, _a.x - xo + 1, _a.y - yo, w, h, 3, arrow_width) cr.clip() else: Gtk.render_background(context, cr, a.x - xo - 10, a.y - yo, a.width + 10, a.height) cr.translate(a.x - xo, a.y - yo) if self.shape.name.find('Arrow') != -1: # draw arrow head cr.move_to(w - arrow_width / 2, 2) cr.line_to(w + 5, h / 2) cr.line_to(w - arrow_width / 2, h - 2) # fetch the line color and stroke rgba = context.get_border_color(Gtk.StateFlags.NORMAL) cr.set_source_rgb(rgba.red, rgba.green, rgba.blue) cr.set_line_width(1) cr.stroke() # render the layout e = self.layout.get_pixel_extents()[1] lw, lh = e.width, e.height pw, ph = a.width, a.height x = min(self.xpadding, (pw - lw) / 2) y = (ph - lh) / 2 # layout area Gtk.render_layout(context, cr, int(x), int(y), self.layout) # paint the focus frame if need be if isinstance(self, PathPart) and self.has_focus(): # layout area x, w, h = x - 2, lw + 4, lh + 1 Gtk.render_focus(context, cr, x, y, w, h) cr.restore()
def paint(self, cr, a, context, xo, yo): if self.is_nopaint: return cr.save() x, y = 0, 0 w, h = a.width, a.height arrow_width = 12#theme['arrow-width'] if isinstance(self, PathPart): _a = self.get_allocation() self.shape.layout(cr, _a.x-xo+1, _a.y-yo, w, h, 3, arrow_width) cr.clip() else: Gtk.render_background(context, cr, a.x-xo-10, a.y-yo, a.width+10, a.height) cr.translate(a.x-xo, a.y-yo) if self.shape.name.find('Arrow') != -1: # draw arrow head cr.move_to(w-arrow_width/2, 2) cr.line_to(w+5, h/2) cr.line_to(w-arrow_width/2, h-2) # fetch the line color and stroke rgba = context.get_border_color(Gtk.StateFlags.NORMAL) cr.set_source_rgb(rgba.red, rgba.green, rgba.blue) cr.set_line_width(1) cr.stroke() # render the layout e = self.layout.get_pixel_extents()[1] lw, lh = e.width, e.height pw, ph = a.width, a.height x = min(self.xpadding, (pw-lw)/2) y = (ph-lh)/2 # layout area Gtk.render_layout(context, cr, int(x), int(y), self.layout) # paint the focus frame if need be if isinstance(self, PathPart) and self.has_focus(): # layout area x, w, h = x-2, lw+4, lh+1 Gtk.render_focus(context, cr, x, y, w, h) cr.restore() return
def redraw_rect(self, widget, cairo_ctx): style_ctx = widget.get_style_context() (w, h) = (widget.get_allocated_width(), widget.get_allocated_height()) Gtk.render_background(style_ctx, cairo_ctx, 0, 0, w - 1, h - 1) xc = w // 2 yc = h // 2 # Consider using gtk_render_arrow def triangle(points): cairo_ctx.move_to(*points[0]) cairo_ctx.line_to(*points[1]) cairo_ctx.line_to(*points[2]) cairo_ctx.line_to(*points[0]) cairo_ctx.fill() cairo_ctx.stroke() th = 8 tw = 6 # Triangle pointing left points = [(1, yc), (1 + th, yc - tw), (1 + th, yc + tw)] triangle(points) # pointing right points = [(w - 2, yc), (w - 2 - th, yc - tw), (w - 2 - th, yc + tw)] triangle(points) # pointing up points = [(xc, 1), (xc - tw, th), (xc + tw, th)] triangle(points) # pointing down points = [(xc, h - 2), (xc - tw, h - 2 - th), (xc + tw, h - 2 - th)] triangle(points) pango_ctx = widget.get_pango_context() layout = Pango.Layout(pango_ctx) try: drawtext = self.text except AttributeError: print("fourway has no text") return while True: layout.set_text(drawtext, len(drawtext)) (text_width, text_height) = layout.get_pixel_size() # truncate text if it's too long if text_width < (w - th * 2) or len(drawtext) < 3: break drawtext = drawtext[:-1] Gtk.render_layout(style_ctx, cairo_ctx, xc - text_width // 2, yc - text_height // 2, layout)
def on_draw(self, widget, cr, data): context = widget.get_style_context() width = widget.get_allocated_width() height = widget.get_allocated_height() Gtk.render_background(context, cr, 0, 0, width, height) r, g, b, a = data['color'] cr.set_source_rgba(r, g, b, a) cr.rectangle(0, 0, width, height) cr.fill()
def on_draw(self, area, cr, obxColor): contexto = area.get_style_context() ancho = area.get_allocated_width() alto = area.get_allocated_height() Gtk.render_background(contexto, cr, 0, 0, ancho, alto) r, g, b, a = obxColor["color"] cr.set_source_rgba(r, g, b, a) cr.rectangle(0, 0, ancho, alto) cr.fill()
def on_draw(self, widget, cr, data): context = widget.get_style_context() width = widget.get_allocated_width() height = widget.get_allocated_height() Gtk.render_background(context, cr, 0, 0, width, height) r,g,b,a = data['color'] cr.set_source_rgba(r,g,b,a) cr.rectangle(0, 0, width, height) cr.fill()
def render_header(self, cr, a, border_radius, assets): context = self.get_style_context() Gtk.render_background(context, cr, 0, 0, a.width, a.height) cr.save() lin = cairo.LinearGradient(0, 0, 0, a.height) lin.add_color_stop_rgba(0, 1,1,1, 0.5) lin.add_color_stop_rgba(1, 1,1,1, 0.0) cr.set_source(lin) cr.rectangle(0, 0, a.width, a.height) cr.fill() # gridline color context.save() context.add_class("grid-lines") bc = context.get_border_color(self.get_state_flags()) Gdk.cairo_set_source_rgba(cr, bc) context.restore() cr.move_to(0, a.height-0.5) cr.rel_line_to(a.width, 0) cr.set_line_width(1) cr.stroke() cr.restore() if hasattr(self, "more"): # set the arrow fill color context = self.more.get_style_context() cr.save() bg = context.get_background_color(self.get_state_flags()) Gdk.cairo_set_source_rgba(cr, bg) # the arrow shape stuff ta = self.more.get_allocation() cr.move_to(ta.x-a.x-StockEms.MEDIUM, 0) cr.rel_line_to(ta.width+StockEms.MEDIUM, 0) cr.rel_line_to(0, a.height) cr.rel_line_to(-(ta.width+StockEms.MEDIUM), 0) cr.rel_line_to(StockEms.MEDIUM, -(a.height)*0.5) cr.close_path() cr.clip_preserve() cr.fill_preserve() bc = context.get_border_color(self.get_state_flags()) Gdk.cairo_set_source_rgba(cr, bc) cr.stroke() cr.restore() # paint the containers children for child in self: self.propagate_draw(child, cr) return
def draw_event(self, da, cairo_ctx): """Handle redraws.""" style_ctx = da.get_style_context() width = da.get_allocated_width() height = da.get_allocated_height() Gtk.render_background(style_ctx, cairo_ctx, 0, 0, width, height) if self.__kyes is not None: for n in range(self.__kyes): Gdk.cairo_set_source_pixbuf(cairo_ctx, self.__kyeimg, n * 20, 0) cairo_ctx.paint()
def onWindowDraw(self, widget, cr): if self.usecustomcolor: borderColor = Gdk.RGBA() borderColor.parse(self.custombordercolor) Gdk.cairo_set_source_rgba(cr, borderColor) cr.paint() else: style = widget.get_style_context() req = widget.get_preferred_size()[0] Gtk.render_background(style, cr, 0, 0, req.width, req.height) Gtk.render_frame(style, cr, 0, 0, req.width, req.height) return False
def on_draw(self, widget, cr): rect = self.get_allocation() Gtk.render_background(self.get_style_context(), cr, 0, 0, rect.width, rect.height) cr.save() self._draw_graph(cr, rect) cr.restore() self.drag_action.draw(cr) return False
def area_on_draw(self, widget, cr, data): context = widget.get_style_context() width = widget.get_allocated_width() height = widget.get_allocated_height() Gtk.render_background(context, cr, 0, 0, width, height) frame = data['frame'] widget_label = data['widget_label'] r,g,b,a = self.update_text_color_by_frame(frame, widget_label) cr.set_source_rgba(r,g,b,a) cr.rectangle(0, 0, width, height) cr.fill()
def draw(self, widget, cr, data = None): width = self.get_allocated_width() height = self.get_allocated_height() context = self.get_style_context() Gtk.render_background(context, cr, 0, 0, width, height) if self.state == 'spinner': cr.set_source_rgba(1, 1, 1, 0.5) i = -20 + (self.spinner_state % 20) while i < height: cr.rectangle(0, i, 10, 10) cr.fill() i += 20 return True
def _on_canvas_draw(self, canvas, cr, width, height): self._context.save() self._context.add_class('button') state = self._context.get_state() if self._crossing: state |= Gtk.StateFlags.PRELIGHT self._context.set_state(state) Gtk.render_background(self._context, cr, 0, 0, width, height) Gtk.render_frame(self._context, cr, 0, 0, width, height) self._context.restore() return True
def _on_goal_draw(self, widget, cr): context = widget.get_style_context() width = widget.get_allocated_width() height = widget.get_allocated_height() Gtk.render_background(context, cr, 0, 0, width, height) xc, yc = width / 2.0, height / 2.0 radius = min(height, width) / 2.0 angle1 = angle2 = -(math.pi / 2.0) ratio = self._word_goal_ratio_accomplished fg_color = context.get_color(context.get_state()) bg_color = Gdk.RGBA() has_color, bg_color = context.lookup_color('theme_bg_color') has_color, completion_color = context.lookup_color( 'theme_selected_bg_color') # Add a faded circle first cr.move_to(xc, yc) fg_color.alpha = 0.1 Gdk.cairo_set_source_rgba(cr, fg_color) cr.arc(xc, yc, radius, 0, 2 * math.pi) cr.fill() # Add the goal completion circle if ratio > 0: if ratio >= 1: ratio = 1 has_color, completion_color = context.lookup_color( 'success_color') completion_color.alpha = 0.7 angle2 = (ratio * math.pi * 2.0) - (math.pi / 2.0) cr.move_to(xc, yc) Gdk.cairo_set_source_rgba(cr, completion_color) cr.arc(xc, yc, radius, angle1, angle2) cr.fill() # Add an inner circle of bg color cr.move_to(xc, yc) bg_color.alpha = 1.0 if ratio >= 1: bg_color.alpha = 0.8 Gdk.cairo_set_source_rgba(cr, bg_color) cr.arc(xc, yc, radius - 16, 0, 2 * math.pi) cr.fill() return False
def draw(self, widget, cr, data = None): width = self.get_allocated_width() height = self.get_allocated_height() context = self.get_style_context() Gtk.render_background(context, cr, 0, 0, width, height) if self.opacity > 0: cr.set_source_rgba(0.86, 0.86, 0.86, self.opacity) i = 0 while i < width: cr.rectangle(i, 0, 9, 9) cr.fill() i += 18 else: pass return False
def on_draw(self, widget, cr): rect = self.get_allocation() Gtk.render_background(self.get_style_context(), cr, 0, 0, rect.width, rect.height) cr.save() cr.translate(0.5 * rect.width, 0.5 * rect.height) cr.scale(self.zoom_ratio, self.zoom_ratio) cr.translate(-self.x, -self.y) self.graph.draw(cr, highlight_items=self.highlight) cr.restore() self.drag_action.draw(cr) return False
def on_floating_bar_draw(self, widget, cairo_t): """Draw the floating statusbar""" context = widget.get_style_context() context.save() context.set_state(widget.get_state_flags()) Gtk.render_background(context, cairo_t, 0, 0, widget.get_allocated_width(), widget.get_allocated_height()) Gtk.render_frame(context, cairo_t, 0, 0, widget.get_allocated_width(), widget.get_allocated_height()) context.restore() return False
def do_draw(self, cr): Gtk.render_background(self.get_style_context(), cr, 0, 0, self.get_allocated_width(), self.get_allocated_height()) Gtk.render_frame(self.get_style_context(), cr, 0, 0, self.get_allocated_width(), self.get_allocated_height()) cr.set_antialias(cairo.ANTIALIAS_NONE) cr.set_line_width(1) cr.set_line_join(cairo.LINE_JOIN_BEVEL) cr.set_line_cap(cairo.LINE_CAP_BUTT) style = self.get_style_context() r, g, b, a = style.get_color(style.get_state()) font_height = icebar.util.get_height(self) height = self.get_allocated_height() cr.translate(0, (height - font_height) // 2 + 1) cr.set_source_rgba(r, g, b, a / 6) h = font_height - 1 for n in range(self.cores + 1): y = int(n / self.cores * h) cr.move_to(0, y) cr.line_to(self.get_allocated_width(), y) cr.stroke() def draw_graph(f): i = enumerate(map(lambda y: int((1 - f(y)) * h), self.samples)) py = 0 for x, y in i: if py - y > 1: cr.line_to(x - 1, y + 1) if py - y < -1: cr.line_to(x - 1, y - 1) cr.line_to(x, y) py = y cr.stroke() cr.set_source_rgba((r + 1) / 2, (g + 0) / 2, (b + 0) / 2, a / 2) draw_graph(lambda a: a.iowait) cr.set_source_rgba(r, g, b, a / 2) draw_graph(lambda a: a.system) cr.set_source_rgba(r, g, b, a) draw_graph(lambda a: a.user)
def do_render(self, drawable, widget, background_area, cell_area, flags): if flags & Gtk.CellRendererState.SELECTED: state = Gtk.StateFlags.SELECTED else: state = Gtk.StateFlags.NORMAL context = widget.get_style_context() context.set_state(state) Gtk.render_background(context, drawable, cell_area.x, cell_area.y, cell_area.width, cell_area.height) Gtk.render_focus(context, drawable, cell_area.x, cell_area.y, cell_area.width, cell_area.height) Gtk.CellRendererText.do_render(self, drawable, widget, background_area, cell_area, flags)
def do_render(self, ctx, widget, bg_area, cell_area, flags): style_ctx = widget.get_style_context() style_ctx.save() style_ctx.add_class('star') if self.props.show_star == 1: style_ctx.set_state(Gtk.StateFlags.SELECTED) else: style_ctx.set_state(Gtk.StateFlags.NORMAL) y = cell_area.y + ((cell_area.height - self._icon_height) / 2) x = cell_area.x + ((cell_area.width - self._icon_width) / 2) Gtk.render_background( style_ctx, ctx, x, y, self._icon_width, self._icon_height) style_ctx.restore()
def do_draw(self, cr): context = self.get_style_context() if self.get_app_paintable(): cr.set_operator(cairo.OPERATOR_SOURCE) cr.set_source_rgba(0, 0, 0, 0) cr.paint() context.save() context.add_class(Gtk.STYLE_CLASS_RUBBERBAND) Gtk.render_background(context, cr, 0, 0, self.get_allocated_width(), self.get_allocated_height()) Gtk.render_frame(context, cr, 0, 0, self.get_allocated_width(), self.get_allocated_height()) context.restore() return True
def _on_draw(self, widget, cr): # always paint psuedo parts first a = self.get_allocation() context = self.get_style_context() context.save() context.add_class("button") self._paint_psuedo_parts(cr, context, a.x, a.y) # paint a frame around the entire pathbar width = self.get_parts_width() Gtk.render_background(context, cr, 1, 1, width - 2, a.height - 2) self._paint_widget_parts(cr, context, a.x, a.y) Gtk.render_frame(context, cr, 0, 0, width, a.height) context.restore() return True
def _on_draw(self, widget, cr): # always paint psuedo parts first a = self.get_allocation() context = self.get_style_context() context.save() context.add_class("button") self._paint_psuedo_parts(cr, context, a.x, a.y) # paint a frame around the entire pathbar width = self.get_parts_width() Gtk.render_background(context, cr, 1, 1, width-2, a.height-2) self._paint_widget_parts(cr, context, a.x, a.y) Gtk.render_frame(context, cr, 0, 0, width, a.height) context.restore() return True
def do_draw_node(self, cr, sc, alloc, dock_renderers, children, border_width, editable): sc.save() sc.add_class(Gtk.STYLE_CLASS_BUTTON) Gtk.render_background(sc, cr, alloc.x, alloc.y, alloc.width, alloc.height) Gtk.render_frame(sc, cr, alloc.x, alloc.y, alloc.width, alloc.height) sc.restore() y_offset = 0 for child in sorted(children, key=lambda child: int(child.get_name().replace("switch_",""))): child_alloc = child.get_allocation() _, mw = child.get_preferred_width() _, mh = child.get_preferred_height() self.switch_height = mh child_alloc.x = border_width + 2*RaspiRenderer.HEADER_BORDER_WIDTH \ + 2*RaspiRenderer.HEADER_PIN_SIZE \ + 2*RaspiRenderer.HEADER_BORDER_PADDING \ + 2*RaspiRenderer.HEADER_BORDER_WIDTH \ + RaspiRenderer.HEADER_PIN_SPACING \ + RaspiRenderer.HEADER_SWITCH_DISTANCE child_alloc.y = border_width + y_offset child_alloc.width = mw child_alloc.height = mh child.size_allocate(child_alloc) child.show() self.emit("child-redraw", child) y_offset += mh y_offset = border_width+mh/3 x_offset = border_width + 2*RaspiRenderer.HEADER_BORDER_WIDTH \ + 2*RaspiRenderer.HEADER_PIN_SIZE \ + 2*RaspiRenderer.HEADER_BORDER_PADDING \ + 2*RaspiRenderer.HEADER_BORDER_WIDTH \ + RaspiRenderer.HEADER_PIN_SPACING \ + RaspiRenderer.HEADER_SWITCH_DISTANCE for dock in sorted(dock_renderers, key=lambda dr: int(dr.get_dock().get_name().replace("GPIO ",""))): dock.draw_dock(cr, sc, alloc.x-border_width, alloc.y+y_offset, alloc.width) y_offset += mh self.draw_header(cr, sc, alloc, border_width)
def do_draw(self, cr): allocation = self.get_allocation() if self.background is None: # Use default window background Gtk.render_background(self.get_style_context(), cr, self.border_width, self.border_width, allocation.width - (2 * self.border_width), allocation.height - (2 * self.border_width) ) header_al = self.children[0].get_allocation() # Border cr.set_source_rgba(*self.color) cr.move_to(0, self.border_width / 2.0) cr.line_to(0, allocation.height) cr.line_to(allocation.width, allocation.height) cr.line_to(allocation.width, self.border_width / 2.0) cr.set_line_width(self.border_width * 2) # Half of border is rendered outside of widget cr.stroke() # Background if not self.background is None: # Use set background color cr.set_source_rgba(*self.background) cr.rectangle(self.border_width, self.border_width, allocation.width - (2 * self.border_width), allocation.height - (2 * self.border_width) ) cr.fill() # Header cr.set_source_rgba(*self.color) cr.rectangle(self.border_width / 2.0, 0, allocation.width - self.border_width, header_al.height + (2 * self.border_width)) cr.fill() for c in self.children: if not c is None: self.propagate_draw(c, cr)
def do_draw(self, context, background_area, cell_area, start, end, state): GtkSource.GutterRendererPixbuf.do_draw( self, context, background_area, cell_area, start, end, state) if self.is_action: # TODO: Fix padding and min-height in CSS and use # draw_style_common style_context = get_style(None, "button.flat.image-button") style_context.set_state(renderer_to_gtk_state(state)) x = background_area.x + 1 y = background_area.y + 1 width = background_area.width - 2 height = background_area.height - 2 Gtk.render_background(style_context, context, x, y, width, height) Gtk.render_frame(style_context, context, x, y, width, height) pixbuf = self.props.pixbuf pix_width, pix_height = pixbuf.props.width, pixbuf.props.height xalign, yalign = self.get_alignment() align_mode = self.get_alignment_mode() if align_mode == GtkSource.GutterRendererAlignmentMode.CELL: icon_x = x + (width - pix_width) // 2 icon_y = y + (height - pix_height) // 2 else: line_iter = start if align_mode == ALIGN_MODE_FIRST else end textview = self.get_view() loc = textview.get_iter_location(line_iter) line_x, line_y = textview.buffer_to_window_coords( self.get_window_type(), loc.x, loc.y) icon_x = cell_area.x + (cell_area.width - pix_width) * xalign icon_y = line_y + (loc.height - pix_height) * yalign Gtk.render_icon(style_context, context, pixbuf, icon_x, icon_y) self.draw_chunks( context, background_area, cell_area, start, end, state)
def _cache_bg_for_state(self, state): a = self.get_allocation() # tmp surface on which we render the button bg as per the gtk # theme engine _surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height) cr = cairo.Context(_surf) context = self.get_style_context() context.save() context.set_state(state) Gtk.render_background(context, cr, -5, -5, a.width+10, a.height+10) Gtk.render_frame(context, cr, -5, -5, a.width+10, a.height+10) del cr # new surface which will be cached which surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height) cr = cairo.Context(surf) # gradient for masking lin = cairo.LinearGradient(0, 0, 0, a.height) lin.add_color_stop_rgba(0.0, 1,1,1, 0.1) lin.add_color_stop_rgba(0.25, 1,1,1, 0.7) lin.add_color_stop_rgba(0.5, 1,1,1, 1.0) lin.add_color_stop_rgba(0.75, 1,1,1, 0.7) lin.add_color_stop_rgba(1.0, 1,1,1, 0.1) cr.set_source_surface(_surf, 0, 0) cr.mask(lin) del cr # cache the resulting surf... self._bg_cache[state] = surf return
def do_draw(self, cr): ''' Draws everything! ''' if self._obsolete_offset: self._compute_offset() drawstate = ImageView.DrawState(self) # Renders the BG. Not sure if it works style = self.get_style_context() Gtk.render_background(style, cr, 0, 0, *drawstate.size) cr.save() # Apply the zooooooom cr.scale(drawstate.magnification, drawstate.magnification) # Translate the offset cr.translate(*drawstate.translation) # Rotate the radians cr.rotate(drawstate.rad_rotation) # Flip the... thing if drawstate.is_flipped: cr.scale(-1 if drawstate.hflip else 1, -1 if drawstate.vflip else 1) # Yes, this supports multiple frames! # No, we don't use that feature... not yet. for a_frame in self._frames: cr.save() try: cr.translate(*a_frame.origin) a_frame.draw(cr, drawstate) except Exception: raise cr.restore() cr.restore() Gtk.render_frame(style, cr, 0, 0, *drawstate.size)
def do_render(self, cr, treeview, background_area, cell_area, flags): context = Gtk.Widget.get_style_context(treeview) Gtk.render_background(context, cr, cell_area.x, cell_area.y, cell_area.x + cell_area.width, cell_area.y + cell_area.height ) scaled = self.icon.scale_simple( self.size, self.size, GdkPixbuf.InterpType.BILINEAR ) surf = Gdk.cairo_surface_create_from_pixbuf(scaled, 1) if self.has_colors: cr.set_source_surface(surf, cell_area.x, cell_area.y) cr.rectangle(cell_area.x, cell_area.y, self.size, self.size) else: color_flags = Gtk.StateFlags.NORMAL if (flags & Gtk.CellRendererState.SELECTED) != 0: color_flags = Gtk.StateFlags.SELECTED Gdk.cairo_set_source_rgba(cr, context.get_color(color_flags)) cr.mask_surface(surf, cell_area.x, cell_area.y) cr.fill()
def do_draw(self, cr): allocation = self.get_allocation() if allocation.width >= allocation.height: context = Gtk.Widget.get_style_context(self) Gtk.render_background(context, cr, 0, 0, allocation.width, allocation.height) if self.pb is None: # No icon set return scaled = self.pb.scale_simple( allocation.height, allocation.height, GdkPixbuf.InterpType.BILINEAR ) surf = Gdk.cairo_surface_create_from_pixbuf(scaled, 1) if self.has_colors: cr.set_source_surface(surf, 1.0, 1.0) #allocation.height, allocation.height) cr.rectangle(0, 0, allocation.height, allocation.height) else: Gdk.cairo_set_source_rgba(cr, context.get_color(Gtk.StateFlags.NORMAL)) cr.mask_surface(surf, 0, 0) cr.fill()