Python gi.repository.Gdk.cairo_set_source_pixbuf() Examples

The following are 11 code examples of gi.repository.Gdk.cairo_set_source_pixbuf(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gdk , or try the search function .
Example #1
Source File: abstract_canvas_tool.py    From drawing with GNU General Public License v3.0 6 votes vote down vote up
def temp_preview(self, is_selection, local_dx, local_dy):
		"""Part of the previewing methods shared by all canvas tools."""
		cairo_context = self.get_context()
		pixbuf = self.get_image().temp_pixbuf
		if is_selection:
			cairo_context.set_source_surface(self.get_surface(), 0, 0)
			cairo_context.paint()
			x = self.get_selection().selection_x + local_dx
			y = self.get_selection().selection_y + local_dy
			Gdk.cairo_set_source_pixbuf(cairo_context, pixbuf, x, y)
			cairo_context.paint()
		else:
			cairo_context.set_operator(cairo.Operator.CLEAR)
			cairo_context.paint()
			cairo_context.set_operator(cairo.Operator.OVER)
			Gdk.cairo_set_source_pixbuf(cairo_context, pixbuf, 0, 0)
			cairo_context.paint()
		self.get_image().update()

	############################################################################ 
Example #2
Source File: gif_backend.py    From pympress with GNU General Public License v2.0 5 votes vote down vote up
def draw(self, widget, ctx):
        """ Simple resized drawing: get the pixbuf, set the transform, draw the image.
        """
        if self.iter is None:
            return False

        try:
            ctx.transform(self.transform)
            Gdk.cairo_set_source_pixbuf(ctx, self.iter.get_pixbuf(), 0, 0)
            ctx.paint()
        except cairo.Error:
            logger.error(_('Cairo can not draw gif'), exc_info = True) 
Example #3
Source File: pointer.py    From pympress with GNU General Public License v2.0 5 votes vote down vote up
def render_pointer(self, cairo_context, ww, wh):
        """ Draw the laser pointer on screen.

        Args:
            cairo_context (:class:`~cairo.Context`): The canvas on which to render the pointer
            ww (`int`): The widget width
            wh (`int`): The widget height
        """
        if self.show_pointer:
            x = ww * self.pointer_pos[0] - self.pointer.get_width() / 2
            y = wh * self.pointer_pos[1] - self.pointer.get_height() / 2
            Gdk.cairo_set_source_pixbuf(cairo_context, self.pointer, x, y)
            cairo_context.paint() 
Example #4
Source File: xdot.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
def draw(self, cr, highlight=False):
        pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.path)
        sx = float(self.w)/float(pixbuf.get_width())
        sy = float(self.h)/float(pixbuf.get_height())
        cr.save()
        cr.translate(self.x0, self.y0 - self.h)
        cr.scale(sx, sy)
        Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0)
        cr.paint()
        cr.restore() 
Example #5
Source File: weatherwidget.py    From my-weather-indicator with MIT License 5 votes vote down vote up
def get_surface_from_pixbuf(pixbuf):
    surface = cairo.ImageSurface(
        cairo.FORMAT_ARGB32, pixbuf.get_width(), pixbuf.get_height())
    micairo = cairo.Context(surface)
    micairo.save()
    Gdk.cairo_set_source_pixbuf(micairo, pixbuf, 0, 0)
    micairo.paint()
    micairo.restore()
    return surface 
Example #6
Source File: weatherwidget.py    From my-weather-indicator with MIT License 5 votes vote down vote up
def get_surface_from_file(filename):
    if os.path.exists(filename):
        pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
        if pixbuf:
            surface = cairo.ImageSurface(
                cairo.FORMAT_ARGB32, pixbuf.get_width(), pixbuf.get_height())
            context = cairo.Context(surface)
            Gdk.cairo_set_source_pixbuf(context, pixbuf, 0, 0)
            context.paint()
            return surface
    return None 
Example #7
Source File: image.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
def do_draw_page(self, op, print_ctx, page_num):
		# TODO if it's too big for one page ?
		cairo_context = print_ctx.get_cairo_context()
		Gdk.cairo_set_source_pixbuf(cairo_context, self.main_pixbuf, 0, 0)
		cairo_context.paint() 
Example #8
Source File: image.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
def do_begin_print(self, op, print_ctx):
		op.set_n_pages(1)
		cairo_context = print_ctx.get_cairo_context()
		Gdk.cairo_set_source_pixbuf(cairo_context, self.main_pixbuf, 0, 0)
		cairo_context.paint()

	############################################################################
################################################################################ 
Example #9
Source File: selection_manager.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
def show_selection_on_surface(self, cairo_context, with_scroll, tool_dx, tool_dy):
		if self.selection_pixbuf is None:
			raise NoSelectionPixbufException()
		if with_scroll:
			x = self.selection_x - self.image.scroll_x + tool_dx
			y = self.selection_y - self.image.scroll_y + tool_dy
		else:
			x = self.selection_x + tool_dx
			y = self.selection_y + tool_dy
		Gdk.cairo_set_source_pixbuf(cairo_context, self.selection_pixbuf, x, y)
		cairo_context.paint() 
Example #10
Source File: libcairodoc.py    From gprime with GNU General Public License v2.0 4 votes vote down vote up
def draw(self, cr, layout, width, dpi_x, dpi_y):
        from gi.repository import Gtk, Gdk
        img_width = self._width * dpi_x / 2.54
        img_height = self._height * dpi_y / 2.54

        if self._style == 'right':
            l_margin = width - img_width
        elif self._style == 'center':
            l_margin = (width - img_width) / 2.0
        else:
            l_margin = 0

        # load the image and get its extents
        pixbuf = resize_to_buffer(self._filename, [img_width, img_height],
                                  self._crop)
        pixbuf_width = pixbuf.get_width()
        pixbuf_height = pixbuf.get_height()

        # calculate the scale to fit image into the set extents
        scale = min(img_width / pixbuf_width, img_height / pixbuf_height)

        # draw the image
        cr.save()
        cr.translate(l_margin, 0)
        cr.scale(scale, scale)
        Gdk.cairo_set_source_pixbuf(cr, pixbuf,
                              (img_width / scale - pixbuf_width) / 2,
                              (img_height / scale - pixbuf_height) / 2)
        cr.rectangle(0 , 0, img_width / scale, img_height / scale)
        ##gcr.set_source_pixbuf(pixbuf,
                              ##(img_width - pixbuf_width) / 2,
                              ##(img_height - pixbuf_height) / 2)
        ##cr.rectangle(0 , 0, img_width, img_height)
        ##cr.scale(scale, scale)
        cr.fill()
        cr.restore()

        if DEBUG:
            cr.set_line_width(0.1)
            cr.set_source_rgb(1.0, 0, 0)
            cr.rectangle(l_margin, 0, img_width, img_height)
            cr.stroke()

        return (img_height) 
Example #11
Source File: tool_paint.py    From drawing with GNU General Public License v3.0 4 votes vote down vote up
def _op_replace(self, operation):
		"""Algorithmically less ugly than `_op_fill`, but doesn't handle (semi-)
		transparent colors correctly, even outside of the targeted area."""
		# FIXME
		if operation['path'] is None:
			return
		surf = self.get_surface()
		cairo_context = cairo.Context(surf)
		rgba = operation['rgba']
		old_rgba = operation['old_rgba']
		cairo_context.set_source_rgba(255, 255, 255, 1.0)
		cairo_context.append_path(operation['path'])
		cairo_context.set_operator(cairo.Operator.DEST_IN)
		cairo_context.fill_preserve()

		self.get_image().temp_pixbuf = Gdk.pixbuf_get_from_surface(surf, 0, 0, \
		                                    surf.get_width(), surf.get_height())

		tolerance = 10 # XXX
		i = -1 * tolerance
		while i < tolerance:
			red = max(0, old_rgba[0]+i)
			green = max(0, old_rgba[1]+i)
			blue = max(0, old_rgba[2]+i)
			red = int( min(255, red) )
			green = int( min(255, green) )
			blue = int( min(255, blue) )
			self._replace_temp_with_alpha(red, green, blue)
			i = i+1
		self.restore_pixbuf()
		cairo_context2 = self.get_context()

		cairo_context2.append_path(operation['path'])
		cairo_context2.set_operator(cairo.Operator.CLEAR)
		cairo_context2.set_source_rgba(255, 255, 255, 1.0)
		cairo_context2.fill()
		cairo_context2.set_operator(cairo.Operator.OVER)

		Gdk.cairo_set_source_pixbuf(cairo_context2, \
		                                     self.get_image().temp_pixbuf, 0, 0)
		cairo_context2.append_path(operation['path'])
		cairo_context2.paint()
		self.non_destructive_show_modif()
		cairo_context2.set_operator(cairo.Operator.DEST_OVER)
		cairo_context2.set_source_rgba(rgba.red, rgba.green, rgba.blue, rgba.alpha)
		cairo_context2.paint()