Beispiel #1
0
    def on_render(\
        self, window, widget, background_area, cell_area, expose_area, flags):
        # Drawing context
        cr         = window.cairo_create()
        gdkcontext = Gdk.CairoContext(cr)
        gdkcontext.set_antialias(cairo.ANTIALIAS_NONE)
        # Coordinates of the origin point
        x_align = self.get_property("xalign")
        y_align = self.get_property("yalign")
        rect_x  = cell_area.x
        rect_y  = cell_area.y + int((cell_area.height - 16) * y_align)
        colours = { "online": "#0FDD28", "busy": "#E81110", "offline": "#777"}
        if self.status:
            color = colours[self.status]
            # Draw circle
            radius = 7
            my_color = Gdk.color_parse(color)
            gdkcontext.set_source_color(my_color)
            gdkcontext.arc(rect_x,rect_y+8,radius,90,180)
            gdkcontext.fill()

            # Outer line
            gdkcontext.set_source_rgba(0, 0, 0, 0.20)
            gdkcontext.set_line_width(1.0)
            gdkcontext.arc(rect_x,rect_y+8,radius,90,180)
            gdkcontext.stroke()
Beispiel #2
0
    def _new_dot_surface(self, color='#000000', image=None, color_image=None):
        ''' generate a dot of a color color '''
        self._dot_cache = {}
        if color_image is not None:
            if color_image + 10000 in self._dot_cache:
                return self._dot_cache[color_image + 10000]
            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                os.path.join(self._path, self._CPATHS[color_image]),
                self._svg_width, self._svg_height)
        elif image is not None:
            if image in self._dot_cache:
                return self._dot_cache[image]
            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                os.path.join(self._path, self._PATHS[image]),
                self._svg_width, self._svg_height)
        else:
            if color in self._dot_cache:
                return self._dot_cache[color]
            self._stroke = color
            self._fill = color
            self._svg_width = self._dot_size
            self._svg_height = self._dot_size

            i = self._colors.index(color)
            pixbuf = svg_str_to_pixbuf(
                self._header() + \
                    self._circle(self._dot_size / 2., self._dot_size / 2.,
                                 self._dot_size / 2.) + \
                    self._footer())
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                     self._svg_width, self._svg_height)
        context = cairo.Context(surface)
        context = Gdk.CairoContext(context)
        context.set_source_pixbuf(pixbuf, 0, 0)
        context.rectangle(0, 0, self._svg_width, self._svg_height)
        context.fill()
        if color_image is not None:
            self._dot_cache[color_image + 10000] = surface
        elif image is not None:
            self._dot_cache[image] = surface
        else:
            self._dot_cache[color] = surface
        return surface