Esempio n. 1
0
 def on_draw(self, widget, cr, layout):
     a = widget.get_allocation()
     # paint the current animation frame
     x = (a.width - self.h_stride) * 0.5
     y = (a.height - self.v_stride) * 0.5
     Gdk.cairo_set_source_pixbuf(cr, self.frame, x, y)
     cr.paint()
     if self.transaction_count <= 0: return
     # paint a bubble with the transaction count
     layout.set_markup('<small>%i</small>' % self.transaction_count, -1)
     # determine bubble size
     extents = layout.get_pixel_extents()[1]
     width = extents.width + (2 * self.BUBBLE_XPADDING)
     height = extents.height + (2 * self.BUBBLE_YPADDING)
     # now render the bubble and layout
     context = self.get_style_context()
     x += self.h_stride + self.BUBBLE_XPADDING
     y += (self.v_stride - height) / 2
     rounded_rect(cr, x, y, width, height, self.BUBBLE_BORDER_RADIUS)
     cr.set_source_rgba(0,0,0,0.2)
     cr.fill()
     Gtk.render_layout(context, cr,
                       x + self.BUBBLE_XPADDING,
                       y + self.BUBBLE_YPADDING,
                       layout)
     return
    def on_draw(self, widget, cr, *args, **kwargs):
        cr.save()
        if self.is_animating():
            # translate to the center, then set the rotation
            a = widget.get_allocation()
            cr.translate(a.width * 0.5, a.height * 0.5)
            cr.rotate(self.rotation)
            # pass on the translation details
            kwargs['xo'] = -(a.width * 0.5)
            kwargs['yo'] = -(a.height * 0.5)

        # do icon drawing
        SymbolicIcon.on_draw(self, widget, cr, *args, **kwargs)
        cr.restore()

        if not self.is_animating() or not self.transaction_count:
            return

        # paint transactions bubble

        # get the layout extents and calc the bubble size
        ex = self.layout.get_pixel_extents()[1]
        x = ((a.width - self.icon.get_width()) / 2 +
            self.icon.get_width() - ex.width + 2)
        y = ((a.height - self.icon.get_height()) / 2 +
            self.icon.get_height() - ex.height + 2)
        w = ex.width + 2 * self.BUBBLE_XPADDING
        h = ex.height + 2 * self.BUBBLE_YPADDING

        border_radius = w / 3
        if border_radius > self.BUBBLE_MAX_BORDER_RADIUS:
            border_radius = self.BUBBLE_MAX_BORDER_RADIUS

        # paint background
        context = widget.get_style_context()
        context.save()
        color = context.get_background_color(Gtk.StateFlags.SELECTED)
        rounded_rect(cr, x + 1, y + 1, w - 2, h - 2, border_radius)
        Gdk.cairo_set_source_rgba(cr, color)
        cr.fill()
        context.restore()

        # paint outline
        rounded_rect(cr, x + 1.5, y + 1.5, w - 3, h - 3, border_radius - 1)
        cr.set_source_rgb(1, 1, 1)
        cr.set_line_width(1)
        cr.stroke()

        # paint layout
        cr.save()
        cr.translate(x + (w - ex.width) * 0.5, y + (h - ex.height) * 0.5)
        cr.move_to(0, 1)
        PangoCairo.layout_path(cr, self.layout)
        cr.set_source_rgba(0, 0, 0, 0.6)
        cr.fill()
        Gtk.render_layout(context, cr, 0, 0, self.layout)
        cr.restore()
Esempio n. 3
0
    def render_grid(self, cr):
        context = self.get_style_context()
        context.save()
        context.add_class("grid-lines")
        bg = context.get_border_color(self.get_state_flags())
        context.restore()

        cr.save()
        a = self.get_allocation()
        rounded_rect(cr, 0, 0, a.width, a.height-1, Frame.BORDER_RADIUS)
        cr.clip()

        Gdk.cairo_set_source_rgba(cr, bg)
        cr.set_line_width(1)

        cell_w = a.width / self.n_columns
        cell_h = self.get_cell_size()[1]

        for i in range(self.n_columns):
            for j in range(self.n_rows):
                # paint checker if need be
                #~ if not (i + j%2)%2:
                    #~ cr.save()
                    #~ cr.set_source_rgba(0.976470588, 0.956862745, 0.960784314, 0.85) #F9F4F5
                    #~ cr.rectangle(i*cell_w, j*cell_h, cell_w, cell_h)
                    #~ cr.fill()
                    #~ cr.restore()

                # paint rows
                if not j: continue
                cr.move_to(0, j*cell_h + 0.5)
                cr.rel_line_to(a.width-1, 0)
                cr.stroke()

            # paint columns
            if not i: continue
            cr.move_to(i*cell_w + 0.5, 0)
            cr.rel_line_to(0, a.height-1)
            cr.stroke()

        cr.restore()
        return
Esempio n. 4
0
 def on_draw(self, widget, cr, layout):
     a = widget.get_allocation()
     # paint the current animation frame
     x = (a.width - self.h_stride) * 0.5
     y = (a.height - self.v_stride) * 0.5
     Gdk.cairo_set_source_pixbuf(cr, self.frame, x, y)
     cr.paint()
     if self.transaction_count <= 0: return
     # paint a bubble with the transaction count
     layout.set_markup('<small>%i</small>' % self.transaction_count, -1)
     # determine bubble size
     extents = layout.get_pixel_extents()[1]
     width = extents.width + (2 * self.BUBBLE_XPADDING)
     height = extents.height + (2 * self.BUBBLE_YPADDING)
     # now render the bubble and layout
     context = self.get_style_context()
     x += self.h_stride + self.BUBBLE_XPADDING
     y += (self.v_stride - height) / 2
     rounded_rect(cr, x, y, width, height, self.BUBBLE_BORDER_RADIUS)
     cr.set_source_rgba(0, 0, 0, 0.2)
     cr.fill()
     Gtk.render_layout(context, cr, x + self.BUBBLE_XPADDING,
                       y + self.BUBBLE_YPADDING, layout)
     return
Esempio n. 5
0
    def render_frame(self, cr, a, border_radius, assets):
        # we cache as much of the drawing as possible
        # store a copy of the rendered frame surface, so we only have to
        # do a full redraw if the widget dimensions change
        if self._frame_surface_cache is None:
            surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height)
            _cr = cairo.Context(surf)

            at = self.ASSET_TAG

            width = a.width
            height = a.height
            cnr_slice = assets["corner-slice"]

            # paint north-west corner
            _cr.set_source_surface(assets["%s-nw" % at], 0, 0)
            _cr.paint()

            # paint north length
            _cr.save()
            _cr.set_source(assets["%s-n" % at])
            _cr.rectangle(cnr_slice, 0, width - 2 * cnr_slice, cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # paint north-east corner
            _cr.set_source_surface(assets["%s-ne" % at],
                                   width - cnr_slice, 0)
            _cr.paint()

            # paint east length
            _cr.save()
            _cr.translate(width - cnr_slice, cnr_slice)
            _cr.set_source(assets["%s-e" % at])
            _cr.rectangle(0, 0, cnr_slice, height - 2 * cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # paint south-east corner
            _cr.set_source_surface(assets["%s-se" % at],
                                   width - cnr_slice,
                                   height - cnr_slice)
            _cr.paint()

            # paint south length
            _cr.save()
            _cr.translate(cnr_slice, height - cnr_slice)
            _cr.set_source(assets["%s-s" % at])
            _cr.rectangle(0, 0, width - 2 * cnr_slice, cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # paint south-west corner
            _cr.set_source_surface(assets["%s-sw" % at],
                                   0, height - cnr_slice)
            _cr.paint()

            # paint west length
            _cr.save()
            _cr.translate(0, cnr_slice)
            _cr.set_source(assets["%s-w" % at])
            _cr.rectangle(0, 0, cnr_slice, height - 2 * cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # fill interior
            rounded_rect(_cr, 3, 2, a.width - 6, a.height - 6, border_radius)
            context = self.get_style_context()
            bg = context.get_background_color(self.get_state_flags())

            Gdk.cairo_set_source_rgba(_cr, bg)
            _cr.fill_preserve()

            lin = cairo.LinearGradient(0, 0, 0, max(300, a.height))
            lin.add_color_stop_rgba(0, 1, 1, 1, 0.02)
            lin.add_color_stop_rgba(1, 0, 0, 0, 0.06)
            _cr.set_source(lin)
            _cr.fill()

            self._frame_surface_cache = surf
            del _cr

        # paint the cached surface and apply a rounded rect clip to
        # child draw ops
        A = self.get_allocation()
        xo, yo = a.x - A.x, a.y - A.y

        cr.set_source_surface(self._frame_surface_cache, xo, yo)
        cr.paint()
    def render_frame(self, cr, a, border_radius, assets):
        # we cache as much of the drawing as possible
        # store a copy of the rendered frame surface, so we only have to
        # do a full redraw if the widget dimensions change
        if self._frame_surface_cache is None:
            surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height)
            _cr = cairo.Context(surf)

            at = self.ASSET_TAG

            width = a.width
            height = a.height
            cnr_slice = assets["corner-slice"]

            # paint north-west corner
            _cr.set_source_surface(assets["%s-nw" % at], 0, 0)
            _cr.paint()

            # paint north length
            _cr.save()
            _cr.set_source(assets["%s-n" % at])
            _cr.rectangle(cnr_slice, 0, width - 2 * cnr_slice, cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # paint north-east corner
            _cr.set_source_surface(assets["%s-ne" % at], width - cnr_slice, 0)
            _cr.paint()

            # paint east length
            _cr.save()
            _cr.translate(width - cnr_slice, cnr_slice)
            _cr.set_source(assets["%s-e" % at])
            _cr.rectangle(0, 0, cnr_slice, height - 2 * cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # paint south-east corner
            _cr.set_source_surface(assets["%s-se" % at], width - cnr_slice,
                                   height - cnr_slice)
            _cr.paint()

            # paint south length
            _cr.save()
            _cr.translate(cnr_slice, height - cnr_slice)
            _cr.set_source(assets["%s-s" % at])
            _cr.rectangle(0, 0, width - 2 * cnr_slice, cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # paint south-west corner
            _cr.set_source_surface(assets["%s-sw" % at], 0, height - cnr_slice)
            _cr.paint()

            # paint west length
            _cr.save()
            _cr.translate(0, cnr_slice)
            _cr.set_source(assets["%s-w" % at])
            _cr.rectangle(0, 0, cnr_slice, height - 2 * cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # fill interior
            rounded_rect(_cr, 3, 2, a.width - 6, a.height - 6, border_radius)
            context = self.get_style_context()
            bg = context.get_background_color(self.get_state_flags())

            Gdk.cairo_set_source_rgba(_cr, bg)
            _cr.fill_preserve()

            lin = cairo.LinearGradient(0, 0, 0, max(300, a.height))
            lin.add_color_stop_rgba(0, 1, 1, 1, 0.02)
            lin.add_color_stop_rgba(1, 0, 0, 0, 0.06)
            _cr.set_source(lin)
            _cr.fill()

            self._frame_surface_cache = surf
            del _cr

        # paint the cached surface and apply a rounded rect clip to
        # child draw ops
        A = self.get_allocation()
        xo, yo = a.x - A.x, a.y - A.y

        cr.set_source_surface(self._frame_surface_cache, xo, yo)
        cr.paint()
Esempio n. 7
0
    def do_draw(self, cr):
        # ensure that we pause the exhibits carousel if the window goes
        # into the background
        self._init_pause_handling_if_needed()

        # hide the next/prev buttons if needed
        if len(self.exhibits) == 1:
            self.nextprev_hbox.hide()
        else:
            self.nextprev_hbox.show()

        # do the actual drawing
        cr.save()

        a = self.get_allocation()

        cr.set_source_rgb(1, 1, 1)
        cr.paint()

        # workaround a really odd bug in the offscreen window of the
        # webkit view that leaves a 8px white border around the rendered
        # image
        OFFSET = -8
        if self.old_image is not None:
            #x = (a.width - self.old_image.get_width()) / 2
            x = OFFSET
            y = OFFSET
            Gdk.cairo_set_source_pixbuf(cr, self.old_image, x, y)
            cr.paint()

        if self.image is not None:
            #x = (a.width - self.image.get_width()) / 2
            x = OFFSET
            y = OFFSET
            Gdk.cairo_set_source_pixbuf(cr, self.image, x, y)
            cr.paint_with_alpha(self.alpha)

        if self.has_focus():
            # paint a focal border/frame
            context = self.get_style_context()
            context.save()
            context.add_class(Gtk.STYLE_CLASS_HIGHLIGHT)
            highlight = context.get_background_color(self.get_state_flags())
            context.restore()

            rounded_rect(cr, 1, 1, a.width - 2, a.height - 3, 5)
            Gdk.cairo_set_source_rgba(cr, highlight)
            cr.set_line_width(6)
            cr.stroke()

        # paint dropshadows last
        #~ cr.rectangle(0, 0, a.width, self.DROPSHADOW_HEIGHT)
        #~ cr.clip()
        #~ cr.set_source(assets["n"])
        #~ cr.paint()
        #~ cr.reset_clip()

        cr.rectangle(0, a.height - self.DROPSHADOW_HEIGHT,
                     a.width, self.DROPSHADOW_HEIGHT)
        cr.clip()
        cr.save()
        cr.translate(0, a.height - self.DROPSHADOW_HEIGHT)
        cr.set_source(_asset_cache["s"])
        cr.paint()
        cr.restore()

        cr.set_line_width(1)
        cr.move_to(-0.5, a.height - 0.5)
        cr.rel_line_to(a.width + 1, 0)
        cr.set_source_rgba(1, 1, 1, 0.75)
        cr.stroke()

        cr.restore()

        for child in self:
            self.propagate_draw(child, cr)
    def do_draw(self, cr):
        # ensure that we pause the exhibits carousel if the window goes
        # into the background
        self._init_pause_handling_if_needed()

        # hide the next/prev buttons if needed
        if len(self.exhibits) == 1:
            self.nextprev_hbox.hide()
        else:
            self.nextprev_hbox.show()

        # do the actual drawing
        cr.save()

        a = self.get_allocation()

        cr.set_source_rgb(1, 1, 1)
        cr.paint()

        # workaround a really odd bug in the offscreen window of the
        # webkit view that leaves a 8px white border around the rendered
        # image
        OFFSET = -8
        if self.old_image is not None:
            #x = (a.width - self.old_image.get_width()) / 2
            x = OFFSET
            y = OFFSET
            Gdk.cairo_set_source_pixbuf(cr, self.old_image, x, y)
            cr.paint()

        if self.image is not None:
            #x = (a.width - self.image.get_width()) / 2
            x = OFFSET
            y = OFFSET
            Gdk.cairo_set_source_pixbuf(cr, self.image, x, y)
            cr.paint_with_alpha(self.alpha)

        if self.has_focus():
            # paint a focal border/frame
            context = self.get_style_context()
            context.save()
            context.add_class(Gtk.STYLE_CLASS_HIGHLIGHT)
            highlight = context.get_background_color(self.get_state_flags())
            context.restore()

            rounded_rect(cr, 1, 1, a.width - 2, a.height - 3, 5)
            Gdk.cairo_set_source_rgba(cr, highlight)
            cr.set_line_width(6)
            cr.stroke()

        # paint dropshadows last
        #~ cr.rectangle(0, 0, a.width, self.DROPSHADOW_HEIGHT)
        #~ cr.clip()
        #~ cr.set_source(assets["n"])
        #~ cr.paint()
        #~ cr.reset_clip()

        cr.rectangle(0, a.height - self.DROPSHADOW_HEIGHT, a.width,
                     self.DROPSHADOW_HEIGHT)
        cr.clip()
        cr.save()
        cr.translate(0, a.height - self.DROPSHADOW_HEIGHT)
        cr.set_source(_asset_cache["s"])
        cr.paint()
        cr.restore()

        cr.set_line_width(1)
        cr.move_to(-0.5, a.height - 0.5)
        cr.rel_line_to(a.width + 1, 0)
        cr.set_source_rgba(1, 1, 1, 0.75)
        cr.stroke()

        cr.restore()

        for child in self:
            self.propagate_draw(child, cr)