Beispiel #1
0
    def draw_zoom_target(self, widget, cairo_context):
        """ Perform the drawings by user.

        Args:
            widget (:class:`~Gtk.DrawingArea`): The widget where to draw the scribbles.
            cairo_context (:class:`~cairo.Context`): The canvas on which to render the drawings
        """
        ww, wh = widget.get_allocated_width(), widget.get_allocated_height()

        if self.zoom_selecting and self.zoom_points:
            xmin, xmax = sorted(p[0] * ww for p in self.zoom_points)
            ymin, ymax = sorted(p[1] * wh for p in self.zoom_points)

            rect = Gdk.Rectangle()
            rect.x = xmin
            rect.width = xmax - xmin
            rect.y = ymin
            rect.height = ymax - ymin

            cairo_context.set_line_width(3)
            cairo_context.set_line_cap(cairo.LINE_CAP_SQUARE)
            Gdk.cairo_rectangle(cairo_context, rect)
            cairo_context.set_source_rgba(.1, .1, 1, .4)
            cairo_context.stroke()

            Gdk.cairo_rectangle(cairo_context, rect)
            cairo_context.set_source_rgba(.5, .5, 1, .2)
            cairo_context.fill()
Beispiel #2
0
    def do_draw(self, ctx):
        square = Gdk.Rectangle()
        square.x = 0
        square.y = 0
        square.width = Gdk.Screen.width()
        square.height = Gdk.Screen.height()
        color = Gdk.color_parse("white")
        Gdk.cairo_set_source_color(ctx, color)
        Gdk.cairo_rectangle(ctx, square)
        ctx.fill()

        self.draw_images(ctx, self.current_images)

        if self._face:
            self.draw_face(self._face)

        if not self.finished:
            if not self._id:
                def enable_click():
                    self._id = self.connect('button-press-event',
                                            self.check_option)
                    if self._face:
                        self._face = None
                        self.queue_draw()

                GObject.timeout_add(1500, enable_click)
Beispiel #3
0
    def do_draw(self, contexto):
        rect = self.get_allocation()
        w, h = (rect.width, rect.height)

        # Relleno de la barra
        ww = w - self.borde * 2
        hh = h - self.borde * 2
        Gdk.cairo_set_source_color(contexto, Gdk.Color(0, 0, 0))
        rect = Gdk.Rectangle()
        rect.x, rect.y, rect.width, rect.height = (
            self.borde, self.borde, ww, hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        # Relleno de la barra segun progreso
        Gdk.cairo_set_source_color(contexto, Gdk.Color(23000, 41000, 12000))
        rect = Gdk.Rectangle()

        ximage = int(self.ajuste.get_value() * ww / 100)
        rect.x, rect.y, rect.width, rect.height = (self.borde, self.borde,
            ximage, hh)

        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        return True
Beispiel #4
0
    def invalidate_new_wire(self, event):
        scaled_x, scaled_y = self.to_svg_coordinates(event.x, event.y)

        # Determine minimum point and maximum point
        min_x = min(scaled_x, self.new_wire_start.x)
        min_y = min(scaled_y, self.new_wire_start.y)

        max_x = max(scaled_x, self.new_wire_start.x)
        max_y = max(scaled_y, self.new_wire_start.y)

        scaled_min_x, scaled_min_y = self.to_window_coordinates(min_x, min_y)
        scaled_max_x, scaled_max_y = self.to_window_coordinates(max_x, max_y)

        update_rect = Gdk.Rectangle()
        update_rect.x = scaled_min_x - 50
        update_rect.y = scaled_min_y - 50
        update_rect.width = (scaled_max_x - scaled_min_x) + 100
        update_rect.height = (scaled_max_y - scaled_min_y) + 100

        # paint to the surface where we store our state
        cairo_ctx = cairo.Context(self.new_wire_surface)

        # Clear previous contents
        cairo_ctx.set_source_rgba(1, 1, 1, 1)
        cairo_ctx.set_operator(cairo.OPERATOR_CLEAR)

        Gdk.cairo_rectangle(cairo_ctx, update_rect)
        cairo_ctx.fill()

        self.get_window().invalidate_rect(update_rect, False)
Beispiel #5
0
    def do_draw(self, contexto):
        """
        Dibuja el estado de la barra de progreso.
        """

        rect = self.get_allocation()
        w, h = (rect.width, rect.height)

        # Fondo
        #Gdk.cairo_set_source_color(contexto, G.BLANCO)
        #contexto.paint()

        # Relleno de la barra
        ww = w - self.borde * 2
        hh = h - self.borde * 2
        Gdk.cairo_set_source_color(contexto, get_color("NEGRO"))
        rect = Gdk.Rectangle()
        rect.x, rect.y, rect.width, rect.height = (
            self.borde, self.borde, ww, hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        # Relleno de la barra segun progreso
        Gdk.cairo_set_source_color(contexto, get_color("NARANJA"))
        rect = Gdk.Rectangle()

        ximage = int(self.ajuste.get_value() * ww / 100)
        rect.x, rect.y, rect.width, rect.height = (self.borde, self.borde,
            ximage, hh)

        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        return True
Beispiel #6
0
    def do_draw(self, contexto):
        rect = self.get_allocation()
        w, h = (rect.width, rect.height)

        # Relleno de la barra
        ww = w - self.borde * 2
        hh = h - self.borde * 2
        Gdk.cairo_set_source_color(contexto, Gdk.Color(0, 0, 0))
        rect = Gdk.Rectangle()
        rect.x, rect.y, rect.width, rect.height = (self.borde, self.borde, ww,
                                                   hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        # Relleno de la barra segun progreso
        Gdk.cairo_set_source_color(contexto, Gdk.Color(23000, 41000, 12000))
        rect = Gdk.Rectangle()

        ximage = int(self.ajuste.get_value() * ww / 100)
        rect.x, rect.y, rect.width, rect.height = (self.borde, self.borde,
                                                   ximage, hh)

        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        return True
Beispiel #7
0
    def draw_brush(self, widget, x, y, size):
        rect = self.brush_size(x, y, size)
        context = cairo.Context(self.surface)
        context.set_source_rgba(
                                self.color.red, 
                                self.color.green, 
                                self.color.blue, 1)

        Gdk.cairo_rectangle(context, rect)
        context.fill()

        widget.get_window().invalidate_rect(rect, False)
    def draw_brush(self, widget, x, y, size):
        rect = self.brush_size(x, y, size)
        context = cairo.Context(self.surface)
        context.set_source_rgba(
                                self.color.red, 
                                self.color.green, 
                                self.color.blue, 1)

        Gdk.cairo_rectangle(context, rect)
        context.fill()

        widget.get_window().invalidate_rect(rect, False)
Beispiel #9
0
    def draw_brush(self, widget, x, y):
        update_rect = Gdk.Rectangle()
        update_rect.x = x - 3
        update_rect.y = y - 3
        update_rect.width = 6
        update_rect.height = 6

        # paint to the surface where we store our state
        cairo_ctx = cairo.Context(self.surface)

        Gdk.cairo_rectangle(cairo_ctx, update_rect)
        cairo_ctx.fill()

        widget.get_window().invalidate_rect(update_rect, False)
Beispiel #10
0
    def draw_brush(self, widget, x, y):
        update_rect = Gdk.Rectangle()
        update_rect.x = x - 3
        update_rect.y = y - 3
        update_rect.width = 6
        update_rect.height = 6

        # paint to the surface where we store our state
        cairo_ctx = cairo.Context(self.surface)

        Gdk.cairo_rectangle(cairo_ctx, update_rect)
        cairo_ctx.fill()

        widget.get_window().invalidate_rect(update_rect, False)
Beispiel #11
0
    def draw_pixel(self, widget, x, y):
        if self._app.draw_state:
            # Create the "pixel" only if not running animatiion
            update_rect = Gdk.Rectangle()
            update_rect.x = x
            update_rect.y = y
            update_rect.width = 1
            update_rect.height = 1

            cairo_ctx = cairo.Context(self._surface)

            Gdk.cairo_rectangle(cairo_ctx, update_rect)
            cairo_ctx.set_source_rgb(1, 1, 1)
            cairo_ctx.fill()
            widget.get_window().invalidate_rect(update_rect, False)
Beispiel #12
0
    def new_image(self, widget):
        """ Start a new sketch by clearing the canvas.
        """

        update_rect = Gdk.Rectangle()
        update_rect.x = 0
        update_rect.y = 0
        update_rect.width = self.width
        update_rect.height = self.height

        # paint to the surface where we store our state
        cairo_ctx = cairo.Context(self.surface)
        cairo_ctx.set_source_rgb(*bgcolor)
        Gdk.cairo_rectangle(cairo_ctx, update_rect)
        cairo_ctx.fill()

        widget.get_window().invalidate_rect(update_rect, False)
    def do_draw(self, contexto):
        """
        Dibuja el estado de la barra de progreso.
        """

        rect = self.get_allocation()
        w, h = (rect.width, rect.height)

        # Fondo
        Gdk.cairo_set_source_color(contexto, get_color("BLANCO"))
        contexto.paint()

        # Relleno de la barra
        ww = w - self.borde * 2
        hh = h / 5

        Gdk.cairo_set_source_color(contexto, get_color("NEGRO"))
        rect = Gdk.Rectangle()

        rect.x, rect.y, rect.width, rect.height = (self.borde, h / 5 * 2, ww,
                                                   hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        # Relleno de la barra segun progreso
        Gdk.cairo_set_source_color(contexto, get_color("NARANJA"))
        rect = Gdk.Rectangle()

        ximage = int(self.ajuste.get_value() * ww / 100)
        rect.x, rect.y, rect.width, rect.height = (self.borde, h / 5 * 2,
                                                   ximage, hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        # La Imagen
        imgw, imgh = (self.pixbuf.get_width(), self.pixbuf.get_height())
        imgx = ximage - imgw / 2
        imgy = float(self.get_allocation().height / 2 - imgh / 2)
        Gdk.cairo_set_source_pixbuf(contexto, self.pixbuf, imgx, imgy)
        contexto.paint()

        return True
Beispiel #14
0
    def do_draw(self, contexto):
        """
        Dibuja el estado de la barra de progreso.
        """

        rect = self.get_allocation()
        w, h = (rect.width, rect.height)

        # Fondo
        Gdk.cairo_set_source_color(contexto, get_color("BLANCO"))
        contexto.paint()

        # Relleno de la barra
        ww = w - self.borde * 2
        hh = h / 5

        Gdk.cairo_set_source_color(contexto, get_color("NEGRO"))
        rect = Gdk.Rectangle()

        rect.x, rect.y, rect.width, rect.height = (
            self.borde, h / 5 * 2, ww, hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        # Relleno de la barra segun progreso
        Gdk.cairo_set_source_color(contexto, get_color("NARANJA"))
        rect = Gdk.Rectangle()

        ximage = int(self.ajuste.get_value() * ww / 100)
        rect.x, rect.y, rect.width, rect.height = (
            self.borde, h / 5 * 2, ximage, hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        # La Imagen
        imgw, imgh = (self.pixbuf.get_width(), self.pixbuf.get_height())
        imgx = (ximage - imgw / 2) + self.borde
        imgy = float(self.get_allocation().height / 2 - imgh / 2)
        Gdk.cairo_set_source_pixbuf(contexto, self.pixbuf, imgx, imgy)
        contexto.paint()

        return True
Beispiel #15
0
    def erase_point(self, widget, x, y, rectshape=True):
        """ Erase a point (=square/circle) on the screen.
        """
        
        update_rect = Gdk.Rectangle()
        update_rect.x = x - erase_left
        update_rect.y = y - erase_left
        update_rect.width = erase_width
        update_rect.height = erase_width

        # paint to the surface where we store our state
        cairo_ctx = cairo.Context(self.surface)
        if rectshape:
            cairo_ctx.set_source_rgb(*bgcolor)
            Gdk.cairo_rectangle(cairo_ctx, update_rect)
            cairo_ctx.fill()
        else:
            self.cairo_circle(cairo_ctx, x, y, bgcolor, erase_width)

        widget.get_window().invalidate_rect(update_rect, False)
Beispiel #16
0
    def draw_point(self, widget, x, y, rectshape=True):
        """ Draw a point (=square/circle) on the screen.
        """
        
        update_rect = Gdk.Rectangle()
        update_rect.x = x - rect_left
        update_rect.y = y - rect_left
        update_rect.width = pysketch.pen_size
        update_rect.height = pysketch.pen_size

        # paint to the surface where we store our state
        cairo_ctx = cairo.Context(self.surface)
        if rectshape:
            cairo_ctx.set_source_rgb(*fgcolor)
            Gdk.cairo_rectangle(cairo_ctx, update_rect)
            cairo_ctx.fill()
        else:
            self.cairo_circle(cairo_ctx, x, y, fgcolor, pysketch.pen_size)

        widget.get_window().invalidate_rect(update_rect, False)
Beispiel #17
0
    def on_life_update(self, update_step):

        widget = self._app.builder.get_object('life')
        allocation = widget.get_allocation()
        surface = widget.get_window().create_similar_surface(
            cairo.CONTENT_COLOR,
            allocation.width,
            allocation.height)

        draw_rect = Gdk.Rectangle()
        draw_rect.x = 0
        draw_rect.y = 0
        draw_rect.width = self._app.board.width()
        draw_rect.height = self._app.board.height()

        for row in range(self._app.board.height()):
            for col in range(self._app.board.width()):
                    if self._app.board.alive(row, col):
                        update_rect = Gdk.Rectangle()
                        update_rect.x = row
                        update_rect.y = col
                        update_rect.width = 1
                        update_rect.height = 1

                        cairo_ctx = cairo.Context(surface)

                        Gdk.cairo_rectangle(cairo_ctx, update_rect)
                        cairo_ctx.set_source_rgb(0, 0, 1)
                        cairo_ctx.fill()

            # Allow GUI updates
            while Gtk.events_pending():
                Gtk.main_iteration_do(False)

        # Set new surface
        self._surface = surface
        widget.get_window().invalidate_rect(draw_rect, False)

        self._status.push(1, "Life Step %i" % update_step)
Beispiel #18
0
    def draw_rect(self, cr, begin, end, dashed=False):
        rect = self.view.get_iter_location(begin)
        rect.x, rect.y = self.view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect.x, rect.y)

        rect_end = self.view.get_iter_location(end)
        rect_end.x, rect_end.y = self.view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect_end.x, rect_end.y)
        rect.width = rect_end.x - rect.x

        rect.width -= 1
        rect.height -= 1
        col = self.view.get_style_context().get_color(Gtk.StateFlags.INSENSITIVE)
        col.alpha = 0.7
        Gdk.cairo_set_source_rgba(cr, col)
        cr.set_line_width(1.0)
        if dashed:
            cr.set_dash([2], 0)
        Gdk.cairo_rectangle(cr, rect)
        if dashed:
            cr.stroke()
        else:
            cr.stroke_preserve()
            col.alpha = 0.1
            Gdk.cairo_set_source_rgba(cr, col)
            cr.fill()
Beispiel #19
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()