Example #1
0
    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
Example #2
0
 def do_draw_fg(self, cr, drawstate):
     """ Renders the Gtk theme frame """
     style = drawstate.style
     style.save()
     style.add_class(Gtk.STYLE_CLASS_CELL)
     Gtk.render_frame(style, cr, 0, 0, *drawstate.size)
     style.restore()
Example #3
0
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
Example #4
0
    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)
Example #5
0
    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 do_draw(self, cr):
        # Fall trough to the container expose handler.
        # (Leaving out the window expose handler which redraws everything)
        Gtk.Window.do_draw(self, cr)

        if self._invoker is not None and self._invoker.has_rectangle_gap():
            invoker = self._invoker.get_rect()
            palette = self.get_rect()
            gap = _calculate_gap(palette, invoker)
        else:
            gap = False

        allocation = self.get_allocation()
        context = self.get_style_context()
        context.add_class("palette")
        if gap:
            cr.save()
            cr.set_source_rgb(0, 0, 0)
            cr.rectangle(0, 0, allocation.width, allocation.height)
            cr.set_line_width(4)
            cr.stroke()
            cr.restore()
            Gtk.render_frame_gap(
                context, cr, 0, 0, allocation.width, allocation.height, gap[0], gap[1], gap[1] + gap[2]
            )
        else:
            Gtk.render_frame(context, cr, 0, 0, allocation.width, allocation.height)
        return False
Example #7
0
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()
Example #8
0
    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())
Example #9
0
 def do_render(self, cr, widget, bg_area, cell_area, flags):
     context = widget.get_style_context()
     context.save()
     context.add_class(Gtk.STYLE_CLASS_BUTTON)
     self.layout.set_markup("Install")
     (x, y, w, h) = self.do_get_size(widget, cell_area)
     h -= 4
     # Gtk.render_background(context, cr, x, y, w, h)
     Gtk.render_frame(context, cr, x, y, w-2, h+4)
     Gtk.render_layout(context, cr, x + 10, y, self.layout)
     context.restore()
Example #10
0
    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
Example #11
0
 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
Example #12
0
    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
Example #13
0
    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)
Example #14
0
    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)
Example #15
0
    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
Example #16
0
	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)
Example #17
0
    def do_render(self, cr, widget, background_area, cell_area, flags):
        context = widget.get_style_context()

        context.save()
        context.add_class("clocks-digital-renderer")
        context.add_class(self.css_class)

        cr.save()
        Gdk.cairo_rectangle(cr, cell_area)
        cr.clip()

        # draw background
        if self.props.pixbuf:
            Gtk.CellRendererPixbuf.do_render(self, cr, widget, background_area, cell_area, flags)
        else:
            Gtk.render_frame(context, cr, cell_area.x, cell_area.y, cell_area.width, cell_area.height)
            Gtk.render_background(context, cr, cell_area.x, cell_area.y, cell_area.width, cell_area.height)

        cr.translate(cell_area.x, cell_area.y)

        # for now the space around the digital clock is hardcoded and
        # relative to the image width (not the width of the cell which
        # may be larger in case of long city names).
        # We need to know the width to create the pango layouts
        if self.props.pixbuf:
            pixbuf_margin = (cell_area.width - self.props.pixbuf.get_width()) // 2
        else:
            pixbuf_margin = 0
        margin = 12 + pixbuf_margin
        padding = 12
        w = cell_area.width - 2 * margin

        # create the layouts so that we can measure them
        layout = widget.create_pango_layout("")
        layout.set_markup(
            "<span size='xx-large'><b>%s</b></span>" % self.text, -1)
        layout.set_width(w * Pango.SCALE)
        layout.set_alignment(Pango.Alignment.CENTER)
        text_w, text_h = layout.get_pixel_size()

        if self.subtext:
            layout_subtext = widget.create_pango_layout("")
            layout_subtext.set_markup(
                "<span size='medium'>%s</span>" % self.subtext, -1)
            layout_subtext.set_width(w * Pango.SCALE)
            layout_subtext.set_alignment(Pango.Alignment.CENTER)
            subtext_w, subtext_h = layout_subtext.get_pixel_size()
            subtext_pad = 6
            # We just assume the first line is the longest
            line = layout_subtext.get_line(0)
            ink_rect, log_rect = line.get_pixel_extents()
            subtext_w = log_rect.width
        else:
            subtext_w, subtext_h, subtext_pad = 0, 0, 0

        # measure the actual height and coordinates (xpad is ignored for now)
        h = 2 * padding + text_h + subtext_h + subtext_pad
        x = margin
        y = (cell_area.height - h) / 2

        context.add_class("inner")

        # draw inner rectangle background
        Gtk.render_frame(context, cr, x, y, w, h)
        Gtk.render_background(context, cr, x, y, w, h)

        # draw text
        Gtk.render_layout(context, cr, x, y + padding, layout)
        if self.subtext:
            Gtk.render_layout(context, cr, x, y + padding + text_h + subtext_pad,
                              layout_subtext)

        context.restore()

        # draw the overlayed checkbox
        if self.toggle_visible:
            context.save()
            context.add_class(Gtk.STYLE_CLASS_CHECK)

            xpad, ypad = self.get_padding()
            direction = widget.get_direction()
            if direction == Gtk.TextDirection.RTL:
                x_offset = xpad
            else:
                x_offset = cell_area.width - self.icon_size - xpad

            check_x = x_offset
            check_y = cell_area.height - self.icon_size - ypad

            if self.active:
                context.set_state(Gtk.StateFlags.ACTIVE)

            Gtk.render_check(context, cr, check_x, check_y, self.icon_size, self.icon_size)

            context.restore()

        cr.restore()
Example #18
0
	def do_draw(self, cr):
		w, h = self.get_allocated_width(), self.get_allocated_height()		
		if self.square:
			hpadding = self.padding + self.mark_width / 2
			vpadding = self.padding + self.mark_height / 2
		else:
			hpadding, vpadding = self.padding, self.padding
		
		t, l = vpadding, hpadding
		r, b = w - hpadding, h - vpadding
				
		hrange = self.get_hrange()
		if hrange:
			lx, ux = hrange.get_lower(), hrange.get_upper()
			vx = hrange.get_value()
			x = (r - l - 1) * (vx / (ux - lx) - lx) + l
		else:
			x = w / 2
			
		vrange = self.get_vrange()
		if vrange:
			ly, uy = vrange.get_lower(), vrange.get_upper()
			vy = vrange.get_value()
			y = (b - t - 1) * (vy / (uy - ly) - ly) + l
		else:
			y = h / 2
		
		style = self.get_style_context()
		
		style.add_class(Gtk.STYLE_CLASS_ENTRY)
		Gtk.render_background(style, cr, 0, 0, w, h)
		cr.save()
		border = style.get_border(style.get_state())
		radius = style.get_property(Gtk.STYLE_PROPERTY_BORDER_RADIUS,
		                            Gtk.StateFlags.NORMAL)
		color = style.get_color(style.get_state())
		cr.arc(border.left + radius,
		       border.top + radius, radius, math.pi, math.pi * 1.5)
		cr.arc(w - border.right - radius -1,
		       border.top + radius, radius, math.pi * 1.5, math.pi * 2)
		cr.arc(w - border.right - radius -1,
		       h -border.bottom - radius -1, radius, 0, math.pi / 2)
		cr.arc(border.left + radius,
		       h - border.bottom - radius - 1, radius, math.pi / 2, math.pi)
		cr.clip()
		
		cr.set_source_rgba(color.red, color.green, color.blue, color.alpha)
		x, y = round(x), round(y)
		
		if self.square:
			ml, mt = x - self.mark_width / 2, y - self.mark_height / 2
			mr, mb = ml + self.mark_width, mt + self.mark_height
			ml, mt, mr, mb = round(ml), round(mt), round(mr), round(mb)
			
			cr.set_line_width(1)
			cr.set_dash([3, 7], x + y)
			cr.move_to(ml, 0); cr.line_to(ml, h); cr.stroke()
			cr.move_to(mr, 0); cr.line_to(mr, h); cr.stroke()
			cr.move_to(0, mt); cr.line_to(w, mt); cr.stroke()
			cr.move_to(0, mb); cr.line_to(w, mb); cr.stroke()
			
			cr.set_dash([], 0)
			cr.rectangle(ml, mt, self.mark_width, self.mark_height)
			cr.stroke()
		
		else:
			cr.set_line_width(1)
			cr.set_dash([3, 7], x + y)
			cr.move_to(x, 0); cr.line_to(x, h); cr.stroke()
			cr.move_to(0, y); cr.line_to(w, y); cr.stroke()
			
			cr.save()
			cr.translate(x, y)
			cr.scale(self.mark_width * 3, self.mark_height * 3)
			cr.arc(0, 0, 1, 0, 2 * math.pi)
			cr.restore()
			cr.stroke()
			
			cr.set_dash([], 0)
			
			cr.save()
			cr.translate(x, y)
			cr.scale(self.mark_width / 2, self.mark_height / 2)
			cr.arc(0, 0, 1, 0, 2 * math.pi)
			cr.restore()
			cr.fill()
			
		cr.restore()
		Gtk.render_frame(style, cr, 0, 0, w, h)
Example #19
0
    def do_render(self, cr, widget, background_area, cell_area, flags):
        context = widget.get_style_context()
        context.save()
        context.add_class("sugar-icon-cell")

        pointer_inside = self._point_in_cell_renderer(widget)

        # The context will have prelight state if the mouse pointer is
        # in the entire row, but we want that state if the pointer is
        # in this cell only:
        if flags & Gtk.CellRendererState.PRELIT:
            if pointer_inside:
                if self._active_state:
                    context.set_state(Gtk.StateFlags.ACTIVE)
            else:
                context.set_state(Gtk.StateFlags.NORMAL)

        Gtk.render_background(context, cr, background_area.x,
                              background_area.y, background_area.width,
                              background_area.height)

        Gtk.render_frame(context, cr, background_area.x, background_area.y,
                         background_area.width, background_area.height)

        if self._xo_color is not None:
            stroke_color = self._xo_color.get_stroke_color()
            fill_color = self._xo_color.get_fill_color()
            prelit_fill_color = None
            prelit_stroke_color = None
        else:
            stroke_color = self._stroke_color
            fill_color = self._fill_color
            prelit_fill_color = self._prelit_fill_color
            prelit_stroke_color = self._prelit_stroke_color

        has_prelit_colors = None not in [
            prelit_fill_color, prelit_stroke_color
        ]

        if flags & Gtk.CellRendererState.PRELIT and has_prelit_colors and \
                pointer_inside:

            self._buffer.fill_color = prelit_fill_color
            self._buffer.stroke_color = prelit_stroke_color
        else:
            self._buffer.fill_color = fill_color
            self._buffer.stroke_color = stroke_color

        surface = self._buffer.get_surface()
        if surface is None:
            return

        xoffset, yoffset, width_, height_ = self.do_get_size(widget, cell_area)

        x = cell_area.x + xoffset
        y = cell_area.y + yoffset

        cr.set_source_surface(surface, math.floor(x), math.floor(y))
        cr.rectangle(cell_area.x, cell_area.y, cell_area.width,
                     cell_area.height)
        cr.clip()
        cr.paint()
Example #20
0
    def do_draw(self, context):
        view = self.source_view
        if not view or not view.get_realized():
            return

        self.buttons = []

        width = self.get_allocated_width()
        height = self.get_allocated_height()

        style_context = self.get_style_context()
        Gtk.render_background(style_context, context, 0, 0, width, height)

        buf = view.get_buffer()

        context.save()
        context.set_line_width(1.0)

        # Get our linked view's visible offset, get our vertical offset
        # against our view (e.g., for info bars at the top of the view)
        # and translate our context to match.
        view_y_start = view.get_visible_rect().y
        view_y_offset = view.translate_coordinates(self, 0, 0)[1]
        gutter_y_translate = view_y_offset - view_y_start
        context.translate(0, gutter_y_translate)

        button_x = 1
        button_width = width - 2

        for chunk in self.get_chunk_range(view_y_start, view_y_start + height):

            change_type, start_line, end_line, *_unused = chunk

            rect_y = view.get_y_for_line_num(start_line)
            rect_height = max(
                0, view.get_y_for_line_num(end_line) - rect_y - 1)

            # Draw our rectangle outside x bounds, so we don't get
            # vertical lines. Fill first, over-fill with a highlight
            # if in the focused chunk, and then stroke the border.
            context.rectangle(-0.5, rect_y + 0.5, width + 1, rect_height)
            if start_line != end_line:
                context.set_source_rgba(*self.fill_colors[change_type])
                context.fill_preserve()
                if view.current_chunk_check(chunk):
                    highlight = self.fill_colors['current-chunk-highlight']
                    context.set_source_rgba(*highlight)
                    context.fill_preserve()
            context.set_source_rgba(*self.line_colors[change_type])
            context.stroke()

            # Button rendering and tracking
            action = self._classify_change_actions(chunk)
            if action is None:
                continue

            it = buf.get_iter_at_line(start_line)
            button_y, button_height = view.get_line_yrange(it)
            button_y += 1
            button_height -= 2

            button_style_context = get_style(None, 'button.flat.image-button')
            if chunk == self.pointer_chunk:
                button_style_context.set_state(Gtk.StateFlags.PRELIGHT)

            Gtk.render_background(
                button_style_context, context, button_x, button_y,
                button_width, button_height)
            Gtk.render_frame(
                button_style_context, context, button_x, button_y,
                button_width, button_height)

            # TODO: Ideally we'd do this in a pre-render step of some
            # kind, but I'm having trouble figuring out what that would
            # look like.
            self.buttons.append(
                (
                    button_x,
                    button_y + gutter_y_translate,
                    button_x + button_width,
                    button_y + gutter_y_translate + button_height,
                    chunk,
                )
            )

            pixbuf = self.action_map.get(action)
            icon_x = button_x + (button_width - pixbuf.props.width) // 2
            icon_y = button_y + (button_height - pixbuf.props.height) // 2
            Gtk.render_icon(
                button_style_context, context, pixbuf, icon_x, icon_y)

        context.restore()
Example #21
0
    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.EllipsizeMode.END)
        layout.set_wrap(Pango.WrapMode.CHAR)
        layout.set_alignment(Pango.Alignment.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)

            Gdk.cairo_set_source_pixbuf(cr, pixbuf, bx + BUTTON_BORDER,
                                        by + (h - pxbf_height) / 2)
            cr.paint()
        context.restore()
Example #22
0
 def do_draw(self, cr):
     context = self.get_style_context() 
     allocation = self.get_allocation() 
     Gtk.render_frame(context, cr, 0, 0, 
                      allocation.width, allocation.height) 
Example #23
0
    def do_draw(self, cr):
        cr.save()

        window = self.get_window()
        w = window.get_width()
        h = window.get_height()

        points_per_set = (len(self.data_array) / self.num_sets)
        pixels_per_point = (float(w) /
                            (float((points_per_set - 1) or 1)))

        widget = self
        ctx = widget.get_style_context()

        # This draws the light gray backing rectangle
        Gtk.render_background(ctx, cr, 0, 0, w - 1, h - 1)

        # This draws the marker ticks
        max_ticks = 4
        for index in range(1, max_ticks):
            Gtk.render_line(ctx, cr, 1,
                            (h / max_ticks) * index,
                            w - 2,
                            (h / max_ticks) * index)

        # Foreground-color graphics context
        # This draws the black border
        Gtk.render_frame(ctx, cr, 0, 0, w - 1, h - 1)

        # Draw the actual sparkline
        def get_y(dataset, index):
            baseline_y = h

            n = dataset * points_per_set
            if self.reversed:
                n += (points_per_set - index - 1)
            else:
                n += index

            val = self.data_array[n]
            return baseline_y - ((h - 1) * val)

        cr.set_line_width(2)

        for dataset in range(0, self.num_sets):
            if len(self.rgb) == (self.num_sets * 3):
                cr.set_source_rgb(self.rgb[(dataset * 3)],
                                        self.rgb[(dataset * 3) + 1],
                                        self.rgb[(dataset * 1) + 2])
            points = []
            for index in range(0, points_per_set):
                x = index * pixels_per_point
                y = get_y(dataset, index)

                points.append((int(x), int(y)))


            if self.num_sets == 1:
                pass

            draw_line(cr, 0, 0, w, h, points)
            if self.filled:
                # Fixes a fully filled graph from having an oddly
                # tapered in end (bug 560913). Need to figure out
                # what's really going on.
                points = [(0, h)] + points
                draw_fill(cr, 0, 0, w, h, points, taper=True)

        cr.restore()

        return 0
Example #24
0
    def do_draw(self, context):
        if not self._setup:
            return

        context.set_line_width(1.0)
        allocation = self.get_allocation()
        style = self.get_style_context()

        pix_start = [t.get_visible_rect().y for t in self.views]
        y_offset = [t.translate_coordinates(self, 0, 0)[1] for t in self.views]

        clip_height = max(t.get_visible_rect().height for t in self.views) + 2
        Gtk.render_frame(style, context, 0, 0, allocation.width, clip_height)
        context.rectangle(0, -1, allocation.width, clip_height)
        context.clip()

        height = allocation.height
        visible = [self.views[0].get_line_num_for_y(pix_start[0]),
                   self.views[0].get_line_num_for_y(pix_start[0] + height),
                   self.views[1].get_line_num_for_y(pix_start[1]),
                   self.views[1].get_line_num_for_y(pix_start[1] + height)]

        wtotal = allocation.width
        # For bezier control points
        x_steps = [-0.5, (1. / 3) * wtotal, (2. / 3) * wtotal, wtotal + 0.5]
        # Rounded rectangle corner radius for culled changes display
        radius = self.line_height // 3
        q_rad = math.pi / 2

        left, right = self.view_indices
        view_offset_line = lambda v, l: (self.views[v].get_y_for_line_num(l) -
                                         pix_start[v] + y_offset[v])
        for c in self.filediff.linediffer.pair_changes(left, right, visible):
            # f and t are short for "from" and "to"
            f0, f1 = [view_offset_line(0, l) for l in c[1:3]]
            t0, t1 = [view_offset_line(1, l) for l in c[3:5]]

            # If either endpoint is completely off-screen, we cull for clarity
            if (t0 < 0 and t1 < 0) or (t0 > height and t1 > height):
                if f0 == f1:
                    continue
                context.arc(x_steps[0], f0 - 0.5 + radius, radius, -q_rad, 0)
                context.arc(x_steps[0], f1 - 0.5 - radius, radius, 0, q_rad)
                context.close_path()
            elif (f0 < 0 and f1 < 0) or (f0 > height and f1 > height):
                if t0 == t1:
                    continue
                context.arc_negative(x_steps[3], t0 - 0.5 + radius, radius,
                                     -q_rad, q_rad * 2)
                context.arc_negative(x_steps[3], t1 - 0.5 - radius, radius,
                                     q_rad * 2, q_rad)
                context.close_path()
            else:
                context.move_to(x_steps[0], f0 - 0.5)
                context.curve_to(x_steps[1], f0 - 0.5,
                                 x_steps[2], t0 - 0.5,
                                 x_steps[3], t0 - 0.5)
                context.line_to(x_steps[3], t1 - 0.5)
                context.curve_to(x_steps[2], t1 - 0.5,
                                 x_steps[1], f1 - 0.5,
                                 x_steps[0], f1 - 0.5)
                context.close_path()

            context.set_source_rgba(*self.fill_colors[c[0]])
            context.fill_preserve()

            chunk_idx = self.filediff.linediffer.locate_chunk(left, c[1])[0]
            if chunk_idx == self.filediff.cursor.chunk:
                highlight = self.fill_colors['current-chunk-highlight']
                context.set_source_rgba(*highlight)
                context.fill_preserve()

            context.set_source_rgba(*self.line_colors[c[0]])
            context.stroke()
Example #25
0
    def do_draw(self, context):
        view = self.source_view
        if not view or not view.get_realized():
            return

        self.buttons = []

        width = self.get_allocated_width()
        height = self.get_allocated_height()

        style_context = self.get_style_context()
        Gtk.render_background(style_context, context, 0, 0, width, height)

        buf = view.get_buffer()

        context.save()
        context.set_line_width(1.0)

        # Get our linked view's visible offset, get our vertical offset
        # against our view (e.g., for info bars at the top of the view)
        # and translate our context to match.
        view_y_start = view.get_visible_rect().y
        view_y_offset = view.translate_coordinates(self, 0, 0)[1]
        gutter_y_translate = view_y_offset - view_y_start
        context.translate(0, gutter_y_translate)

        button_x = 1
        button_width = width - 2

        for chunk in self.get_chunk_range(view_y_start, view_y_start + height):

            change_type, start_line, end_line, *_unused = chunk

            rect_y = view.get_y_for_line_num(start_line)
            rect_height = max(0,
                              view.get_y_for_line_num(end_line) - rect_y - 1)

            # Draw our rectangle outside x bounds, so we don't get
            # vertical lines. Fill first, over-fill with a highlight
            # if in the focused chunk, and then stroke the border.
            context.rectangle(-0.5, rect_y + 0.5, width + 1, rect_height)
            if start_line != end_line:
                context.set_source_rgba(*self.fill_colors[change_type])
                context.fill_preserve()
                if view.current_chunk_check(chunk):
                    highlight = self.fill_colors['current-chunk-highlight']
                    context.set_source_rgba(*highlight)
                    context.fill_preserve()
            context.set_source_rgba(*self.line_colors[change_type])
            context.stroke()

            # Button rendering and tracking
            action = self._classify_change_actions(chunk)
            if action is None:
                continue

            it = buf.get_iter_at_line(start_line)
            button_y, button_height = view.get_line_yrange(it)
            button_y += 1
            button_height -= 2

            button_style_context = get_style(None, 'button.flat.image-button')
            if chunk == self.pointer_chunk:
                button_style_context.set_state(Gtk.StateFlags.PRELIGHT)

            Gtk.render_background(button_style_context, context, button_x,
                                  button_y, button_width, button_height)
            Gtk.render_frame(button_style_context, context, button_x, button_y,
                             button_width, button_height)

            # TODO: Ideally we'd do this in a pre-render step of some
            # kind, but I'm having trouble figuring out what that would
            # look like.
            self.buttons.append((
                button_x,
                button_y + gutter_y_translate,
                button_x + button_width,
                button_y + gutter_y_translate + button_height,
                chunk,
            ))

            pixbuf = self.action_map.get(action)
            icon_x = button_x + (button_width - pixbuf.props.width) // 2
            icon_y = button_y + (button_height - pixbuf.props.height) // 2
            Gtk.render_icon(button_style_context, context, pixbuf, icon_x,
                            icon_y)

        context.restore()
Example #26
0
    def draw(self, context):
        alloc = self.get_allocation()
        width = alloc.width
        height = alloc.height

        #------------------------------------------------------ Paint side ruler
        context.move_to(alloc.x + line, alloc.y + line)
        context.rel_line_to(0, height - line * 2 - curve)
        context.rel_curve_to(0, curve, 0, curve, curve, curve)
        context.rel_line_to(width - line * 2 - curve, 0)

        sc = self.get_style_context()
        bool1, dark_prelight = sc.lookup_color("p_dark_prelight")
        bool1, fg_prelight = sc.lookup_color("p_fg_prelight")
        bool1, bg_prelight = sc.lookup_color("p_bg_prelight")

        context.set_line_width(line)
        context.set_line_cap(cairo.LINE_CAP_ROUND)
        state = self.state == Gtk.StateType.NORMAL and Gtk.StateType.PRELIGHT or self.state
        context.set_source_rgba(dark_prelight.red, dark_prelight.green,
                                dark_prelight.blue, dark_prelight.alpha)
        context.stroke()

        #------------------------------------------------ Paint horizontal marks
        for x, title in self.xmarks:
            context.set_source_rgba(fg_prelight.red, fg_prelight.green,
                                    fg_prelight.blue, fg_prelight.alpha)
            context.set_font_size(12)
            x, y = self.prcToPix(x, 1)
            context.move_to(x + line / 2., y - line / 2.)
            context.rotate(-math.pi / 2)
            context.show_text(title)
            context.rotate(math.pi / 2)

            context.set_source_rgba(bg_prelight.red, bg_prelight.green,
                                    bg_prelight.blue, bg_prelight.alpha)
            context.move_to(x - line / 2., y)
            context.rel_curve_to(6, 0, 6, line, 6, line)
            context.rel_curve_to(0, -line, 6, -line, 6, -line)
            context.close_path()
            context.fill()

        #-------------------------------------------------- Paint vertical marks
        for y, title in self.ymarks:
            context.set_source_rgba(fg_prelight.red, fg_prelight.green,
                                    fg_prelight.blue, fg_prelight.alpha)
            context.set_font_size(12)
            x, y = self.prcToPix(0, y)
            context.move_to(x + line / 2., y + line / 2.)
            context.show_text(title)

            context.set_source_rgba(bg_prelight.red, bg_prelight.green,
                                    bg_prelight.blue, bg_prelight.alpha)
            context.move_to(x, y - line / 2.)
            context.rel_curve_to(0, 6, -line, 6, -line, 6)
            context.rel_curve_to(line, 0, line, 6, line, 6)
            context.close_path()
            context.fill()

        #----------------------------------------------------------- Paint spots
        context.set_line_width(dotSmall * lineprc)
        for x, y, type, name, text in self.spots.values():
            context.set_source_rgb(*self.typeColors[type][0])
            if self.hovered and name == self.hovered[3]:
                continue

            x, y = self.prcToPix(x, y)
            context.arc(x, y, dotSmall / (1 + lineprc) / 2., 0, 2 * math.pi)
            context.fill_preserve()
            context.set_source_rgb(*self.typeColors[type][1])
            context.stroke()

        #--------------------------------------------------- Paint hovered spots
        context.set_line_width(dotLarge * lineprc)
        if self.hovered:
            x, y, type, name, text = self.hovered
            x, y = self.prcToPix(x, y)
            if not self.pressed:
                context.set_source_rgb(*self.typeColors[type][0])
            else:
                context.set_source_rgb(*self.typeColors[type][1])
            context.arc(x, y, dotLarge / (1 + lineprc) / 2., 0, 2 * math.pi)
            context.fill_preserve()
            context.set_source_rgb(*self.typeColors[type][1])
            context.stroke()

            x, y, width, height = self.getTextBounds(self.hovered)

            sc = self.get_style_context()
            sc.save()
            sc.add_class(Gtk.STYLE_CLASS_NOTEBOOK)
            Gtk.render_background(sc, context, int(x - hpadding),
                                  int(y - vpadding),
                                  ceil(width + hpadding * 2),
                                  ceil(height + vpadding * 2))
            Gtk.render_frame(sc, context, int(x - hpadding), int(y - vpadding),
                             ceil(width + hpadding * 2),
                             ceil(height + vpadding * 2))
            sc.restore()

            context.move_to(x, y)
            context.set_source_rgba(fg_prelight.red, fg_prelight.green,
                                    fg_prelight.blue, fg_prelight.alpha)
            PangoCairo.show_layout(context, self.create_pango_layout(text))
Example #27
0
    def do_draw(self, cr):
        cr.save()

        window = self.get_window()
        w = window.get_width()
        h = window.get_height()

        points_per_set = (len(self.data_array) / self.num_sets)
        pixels_per_point = (float(w) /
                            (float((points_per_set - 1) or 1)))

        widget = self
        ctx = widget.get_style_context()

        # This draws the light gray backing rectangle
        Gtk.render_background(ctx, cr, 0, 0, w - 1, h - 1)

        # This draws the marker ticks
        max_ticks = 4
        for index in range(1, max_ticks):
            Gtk.render_line(ctx, cr, 1,
                            (h / max_ticks) * index,
                            w - 2,
                            (h / max_ticks) * index)

        # Foreground-color graphics context
        # This draws the black border
        Gtk.render_frame(ctx, cr, 0, 0, w - 1, h - 1)

        # Draw the actual sparkline
        def get_y(dataset, index):
            baseline_y = h

            n = dataset * points_per_set
            if self.reversed:
                n += (points_per_set - index - 1)
            else:
                n += index

            val = self.data_array[n]
            return baseline_y - ((h - 1) * val)

        cr.set_line_width(2)

        for dataset in range(0, self.num_sets):
            if len(self.rgb) == (self.num_sets * 3):
                cr.set_source_rgb(self.rgb[(dataset * 3)],
                                        self.rgb[(dataset * 3) + 1],
                                        self.rgb[(dataset * 1) + 2])
            points = []
            for index in range(0, points_per_set):
                x = index * pixels_per_point
                y = get_y(dataset, index)

                points.append((int(x), int(y)))


            if self.num_sets == 1:
                pass

            draw_line(cr, 0, 0, w, h, points)
            if self.filled:
                # Fixes a fully filled graph from having an oddly
                # tapered in end (bug 560913). Need to figure out
                # what's really going on.
                points = [(0, h)] + points
                draw_fill(cr, 0, 0, w, h, points, taper=True)

        cr.restore()

        return 0
Example #28
0
    def draw (self, context):
        alloc = self.get_allocation()
        width = alloc.width
        height = alloc.height

        #------------------------------------------------------ Paint side ruler
        context.move_to(alloc.x+line, alloc.y+line)
        context.rel_line_to(0, height-line*2-curve)
        context.rel_curve_to(0, curve,  0, curve,  curve, curve)
        context.rel_line_to(width-line*2-curve, 0)

        sc = self.get_style_context()
        bool1, dark_prelight = sc.lookup_color("p_dark_prelight")
        bool1, fg_prelight = sc.lookup_color("p_fg_prelight")
        bool1, bg_prelight = sc.lookup_color("p_bg_prelight")

        context.set_line_width(line)
        context.set_line_cap(cairo.LINE_CAP_ROUND)
        state = self.state == Gtk.StateType.NORMAL and Gtk.StateType.PRELIGHT or self.state
        context.set_source_rgba(dark_prelight.red, dark_prelight.green, dark_prelight.blue, dark_prelight.alpha)
        context.stroke()

        #------------------------------------------------ Paint horizontal marks
        for x, title in self.xmarks:
            context.set_source_rgba(fg_prelight.red, fg_prelight.green, fg_prelight.blue, fg_prelight.alpha)
            context.set_font_size(12)
            x, y = self.prcToPix (x, 1)
            context.move_to (x+line/2., y-line/2.)
            context.rotate(-math.pi/2)
            context.show_text(title)
            context.rotate(math.pi/2)

            context.set_source_rgba(bg_prelight.red, bg_prelight.green, bg_prelight.blue, bg_prelight.alpha)
            context.move_to (x-line/2., y)
            context.rel_curve_to (6, 0,  6, line,  6, line)
            context.rel_curve_to (0, -line,  6, -line,  6, -line)
            context.close_path()
            context.fill()

        #-------------------------------------------------- Paint vertical marks
        for y, title in self.ymarks:
            context.set_source_rgba(fg_prelight.red, fg_prelight.green, fg_prelight.blue, fg_prelight.alpha)
            context.set_font_size(12)
            x, y = self.prcToPix (0, y)
            context.move_to (x+line/2., y+line/2.)
            context.show_text(title)

            context.set_source_rgba(bg_prelight.red, bg_prelight.green, bg_prelight.blue, bg_prelight.alpha)
            context.move_to (x, y-line/2.)
            context.rel_curve_to (0, 6,  -line, 6,  -line, 6)
            context.rel_curve_to (line, 0,  line, 6,  line, 6)
            context.close_path()
            context.fill()

        #----------------------------------------------------------- Paint spots
        context.set_line_width(dotSmall*lineprc)
        for x, y, type, name, text in self.spots.values():
            context.set_source_rgb(*self.typeColors[type][0])
            if self.hovered and name == self.hovered[3]:
                continue

            x, y = self.prcToPix (x, y)
            context.arc(x, y, dotSmall/(1+lineprc)/2., 0, 2 * math.pi)
            context.fill_preserve()
            context.set_source_rgb(*self.typeColors[type][1])
            context.stroke()

        #--------------------------------------------------- Paint hovered spots
        context.set_line_width(dotLarge*lineprc)
        if self.hovered:
            x, y, type, name, text = self.hovered
            x, y = self.prcToPix (x, y)
            if not self.pressed:
                context.set_source_rgb(*self.typeColors[type][0])
            else:
                context.set_source_rgb(*self.typeColors[type][1])
            context.arc(x, y, dotLarge/(1+lineprc)/2., 0, 2 * math.pi)
            context.fill_preserve()
            context.set_source_rgb(*self.typeColors[type][1])
            context.stroke()

            x, y, width, height = self.getTextBounds(self.hovered)

            sc = self.get_style_context()
            sc.save()
            sc.add_class(Gtk.STYLE_CLASS_NOTEBOOK)
            Gtk.render_background(sc, context, int(x-hpadding), int(y-vpadding), ceil(width+hpadding*2), ceil(height+vpadding*2))
            Gtk.render_frame(sc, context, int(x-hpadding), int(y-vpadding), ceil(width+hpadding*2), ceil(height+vpadding*2))
            sc.restore()

            context.move_to(x, y)
            context.set_source_rgba(fg_prelight.red, fg_prelight.green, fg_prelight.blue, fg_prelight.alpha)
            PangoCairo.show_layout(context, self.create_pango_layout(text))
Example #29
0
    def do_render(self, cr, widget, background_area, cell_area, flags):
        context = widget.get_style_context()
        context.save()
        context.add_class("sugar-icon-cell")

        pointer_inside = self._point_in_cell_renderer(widget)

        # The context will have prelight state if the mouse pointer is
        # in the entire row, but we want that state if the pointer is
        # in this cell only:
        if flags & Gtk.CellRendererState.PRELIT:
            if pointer_inside:
                if self._active_state:
                    context.set_state(Gtk.StateFlags.ACTIVE)
            else:
                context.set_state(Gtk.StateFlags.NORMAL)

        Gtk.render_background(
            context, cr, background_area.x, background_area.y,
            background_area.width, background_area.height)

        Gtk.render_frame(context, cr, background_area.x, background_area.y,
                         background_area.width, background_area.height)

        if self._xo_color is not None:
            stroke_color = self._xo_color.get_stroke_color()
            fill_color = self._xo_color.get_fill_color()
            prelit_fill_color = None
            prelit_stroke_color = None
        else:
            stroke_color = self._stroke_color
            fill_color = self._fill_color
            prelit_fill_color = self._prelit_fill_color
            prelit_stroke_color = self._prelit_stroke_color

        has_prelit_colors = None not in [prelit_fill_color,
                                         prelit_stroke_color]

        if flags & Gtk.CellRendererState.PRELIT and has_prelit_colors and \
                pointer_inside:

            self._buffer.fill_color = prelit_fill_color
            self._buffer.stroke_color = prelit_stroke_color
        else:
            self._buffer.fill_color = fill_color
            self._buffer.stroke_color = stroke_color

        surface = self._buffer.get_surface()
        if surface is None:
            return

        xoffset, yoffset, width_, height_ = self.do_get_size(widget, cell_area)

        x = cell_area.x + xoffset
        y = cell_area.y + yoffset

        cr.set_source_surface(surface, math.floor(x), math.floor(y))
        cr.rectangle(cell_area.x, cell_area.y, cell_area.width,
                     cell_area.height)
        cr.clip()
        cr.paint()
Example #30
0
 def onWindowDraw(self, widget, cr):
     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