def __camera_box_expose(self, widget, event):
        cr = widget.window.cairo_create()
        x, y, w, h = widget.allocation
        # draw frame
        with cairo_disable_antialias(cr):
            cr.rectangle(x, y, w, h)
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo("#a2a2a2"))
            cr.stroke()
        # draw background
        cr.rectangle(x + 5, y + 5, w - 10, h - 10)
        cr.set_source_rgb(*color_hex_to_cairo("#333333"))
        cr.fill()

        # draw camera icon
        if hasattr(self, "scanning") and self.scanning:
            draw_pixbuf(cr, self.snapshot_pixbuf,
                        x = x + (CAMERA_BOX_SIZE - self.snapshot_pixbuf.get_width()) / 2,
                        y = y + (CAMERA_BOX_SIZE - self.snapshot_pixbuf.get_height()) / 2)
        else:
            draw_pixbuf(cr, self.camera_pixbuf,
                        x = x + (CAMERA_BOX_SIZE - self.camera_pixbuf.get_width()) / 2,
                        y = y + (CAMERA_BOX_SIZE - self.camera_pixbuf.get_height()) / 2)
            if not Webcam.has_device():
                draw_pixbuf(cr, self.error_pixbuf,
                            x = x + (CAMERA_BOX_SIZE - self.camera_pixbuf.get_width()) / 2 + 12,
                            y = y + (CAMERA_BOX_SIZE - self.camera_pixbuf.get_height()) / 2 + 12)
    def render(self, cr, rect):
        '''
        Render item.
        
        This is IconView interface, you should implement it.
        '''
        if self.pixbuf == None:
            self.create_cache_pixbuf()
        
        wallpaper_x = rect.x + (rect.width - self.wallpaper_width) / 2
        wallpaper_y = rect.y + (rect.height - self.wallpaper_height) / 2
        
        # Draw shadow.
        drop_shadow_padding = 7
        drop_shadow_radious = 7
        draw_shadow(
            cr,
            wallpaper_x,
            wallpaper_y,
            self.wallpaper_width + drop_shadow_padding,
            self.wallpaper_height + drop_shadow_padding,
            drop_shadow_radious,
            app_theme.get_shadow_color("window_shadow")
            )

        outside_shadow_padding = 4
        outside_shadow_radious = 5
        draw_shadow(
            cr,
            wallpaper_x - outside_shadow_padding,
            wallpaper_y - outside_shadow_padding,
            self.wallpaper_width + outside_shadow_padding * 2,
            self.wallpaper_height + outside_shadow_padding * 2,
            outside_shadow_radious,
            app_theme.get_shadow_color("window_shadow")
            )
        
        # Draw wallpaper.
        draw_pixbuf(cr, self.pixbuf, wallpaper_x, wallpaper_y)    
        
        # Draw wallpaper frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(2)
            cr.set_source_rgba(1, 1, 1, 1)
            cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width, self.wallpaper_height)
            cr.stroke()
            
        if self.is_hover:    
            cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width, self.wallpaper_height)
            cr.set_source_rgb(*color_hex_to_cairo(self.hover_stroke_dcolor.get_color()))
            cr.stroke()
        
        if self.is_tick:    
            tick_pixbuf = self.tick_normal_dpixbuf.get_pixbuf()
        else:    
            tick_pixbuf = self.tick_gray_dpixbuf.get_pixbuf()
            
        tick_x = wallpaper_x + self.wallpaper_width - tick_pixbuf.get_width() / 2 
        tick_y = wallpaper_y - tick_pixbuf.get_height() / 2
        draw_pixbuf(cr, tick_pixbuf, tick_x, tick_y)    
    def render_pwd_entry(self, cr, rect):
        render_background(cr, rect)
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(0, 0, 0)
            cr.set_line_width(1)
            cr.rectangle(rect.x, rect.y + 4, rect.width, 22)
            cr.stroke()
        if self.is_select:
            text_color = "#ffffff"
        else:
            text_color = "#000000"
            self.password_buffer.move_to_start()

        self.password_buffer.set_text_color(text_color)
        height = self.password_buffer.get_pixel_size()[1]
        offset = (self.height - height)/2
        if offset < 0 :
            offset = 0
        rect.y += offset  
        if self.entry and self.entry.allocation.width == self.get_column_widths()[1]-4:
            self.entry.calculate()
            rect.x += 2
            rect.width -= 4
            self.password_buffer.set_text_color("#000000")
            self.password_buffer.render(cr, rect, self.entry.im, self.entry.offset_x)
        else:
            self.password_buffer.render(cr, rect)
    def __draw_frame(self, cr, allocation):
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.save()
            cr.set_dash((9, 3))
            cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
            x = self.edit_coord_x
            y = self.edit_coord_y
            w = self.edit_coord_w
            h = self.edit_coord_h
            if x == 0:
                x = 1
            if y == 0:
                y = 1
            if x + w > self.AREA_WIDTH:
                w = self.AREA_WIDTH- x
            if y + h > self.AREA_HEIGHT:
                h = self.AREA_HEIGHT- y
            cr.rectangle(x, y, w, h)
            cr.stroke()

            cr.set_dash((3, 9))
            cr.set_source_rgb(1, 1, 1)
            cr.rectangle(x, y, w, h)
            cr.stroke()
            cr.restore()

            cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
            cr.rectangle(self.drag_point_x, self.drag_point_y, self.DRAG_WIDTH, self.DRAG_WIDTH)
            cr.stroke()
    def render_essid(self, cr, rect):
        self.render_background(cr, rect)
        ssid = self.ssid.replace("&",
                                 "&amp;").replace("<",
                                                  "&lt;").replace(">", "&gt;")
        (text_width, text_height) = get_content_size(ssid)
        if self.active:
            text_color = "#3da1f7"
        else:
            text_color = "#000000"
        draw_text(cr,
                  ssid,
                  rect.x + ALIGN_SPACING,
                  rect.y,
                  rect.width,
                  rect.height,
                  alignment=pango.ALIGN_LEFT,
                  text_color=text_color)

        if self.is_hover:
            with cairo_disable_antialias(cr):
                cr.set_source_rgb(*BORDER_COLOR)
                cr.set_line_width(1)
                #if self.is_last:
                #cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1)
                cr.rectangle(rect.x + 1, rect.y + 1, rect.width,
                             rect.height - 1)
                cr.stroke()
示例#6
0
    def render_signal(self, cr, rect):
        self.render_background(cr, rect)

        if self.security:
            lock_icon = self.lock_pixbuf
            draw_pixbuf(cr, lock_icon.get_pixbuf(), rect.x,
                        rect.y + (rect.height - IMG_WIDTH) / 2)

        if self.strength > 80:
            signal_icon = self.strength_3
        elif self.strength > 60:
            signal_icon = self.strength_2
        elif self.strength > 30:
            signal_icon = self.strength_1
        else:
            signal_icon = self.strength_0

        draw_pixbuf(cr, signal_icon.get_pixbuf(), rect.x + IMG_WIDTH + 5,
                    rect.y + (rect.height - IMG_WIDTH) / 2)
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
            cr.set_line_width(1)
            if self.is_last:
                cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
            cr.rectangle(rect.x, rect.y, rect.width, 1)
            cr.fill()
    def render_wallpaper(self, cr, pixbuf, wallpaper_draw_x, wallpaper_draw_y, reflection=False):    
        cr.set_source_rgba(1, 1, 1, 1)
        cr.rectangle(wallpaper_draw_x - self.wallpaper_frame_size,
                     wallpaper_draw_y - self.wallpaper_frame_size,
                     self.wallpaper_width + self.wallpaper_frame_size * 2,
                     self.wallpaper_height + self.wallpaper_frame_size * 2)
        cr.fill()
        
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo("#A4A7A7"))
            
            cr.rectangle(wallpaper_draw_x - self.wallpaper_frame_size,
                         wallpaper_draw_y - self.wallpaper_frame_size,
                         self.wallpaper_width + self.wallpaper_frame_size * 2 + 1,
                         self.wallpaper_height + self.wallpaper_frame_size * 2 + 1)
            cr.stroke()

            cr.rectangle(wallpaper_draw_x,
                         wallpaper_draw_y,
                         self.wallpaper_width + 1,
                         self.wallpaper_height + 1)
            cr.stroke()
        
        if reflection:
            cr.translate(wallpaper_draw_x - self.wallpaper_frame_size - 1,
                         wallpaper_draw_y + self.wallpaper_height + self.wallpaper_frame_size + 1)
            cr.scale(1, -1)
        
        draw_pixbuf(cr, pixbuf, wallpaper_draw_x, wallpaper_draw_y)
    def render_check(self, cr, rect):
        self.render_background(cr,rect)

        if self.is_hover and self.network_state ==self.NETWORK_DISCONNECT:
            draw_pixbuf(cr, self.check_hover_pixbuf.get_pixbuf(), rect.x + self.H_PADDING, rect.y + (rect.height - IMG_WIDTH)/2)
        elif self.is_hover:
            if self.hover_column == 0 and self.can_disable:
                draw_pixbuf(cr, self.check_disable.get_pixbuf(), rect.x + self.H_PADDING, rect.y + (rect.height - IMG_WIDTH)/2)
            else:
                if self.network_state == self.NETWORK_LOADING:
                    self.draw_loading(cr, rect)
                elif self.network_state == self.NETWORK_CONNECTED:
                    draw_pixbuf(cr, self.check_pixbuf.get_pixbuf(), rect.x + self.H_PADDING, rect.y + (rect.height - IMG_WIDTH)/2)
        else:
            if self.network_state == self.NETWORK_LOADING:
                self.draw_loading(cr, rect)
            elif self.network_state == self.NETWORK_CONNECTED:
                draw_pixbuf(cr, self.check_pixbuf.get_pixbuf(), rect.x + self.H_PADDING, rect.y + (rect.height - IMG_WIDTH)/2)

        #draw outline
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
            cr.set_line_width(1)
            if self.is_last:
                cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1)
            cr.rectangle(rect.x, rect.y, rect.width, 1)
            cr.rectangle(rect.x, rect.y, 1, rect.height)
            cr.fill()
    def select_button_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        if widget.state == gtk.STATE_PRELIGHT:
            with cairo_disable_antialias(cr):
                cr.set_source_rgb(*color_hex_to_cairo(self.bg_color))
                cr.rectangle(rect.x,
                             rect.y,
                             rect.width,
                             rect.height)
                cr.fill()

                cr.set_source_rgb(*color_hex_to_cairo(self.line_color))
                cr.rectangle(rect.x,
                             rect.y,
                             rect.width,
                             rect.height)
                cr.stroke()

        # draw text.
        draw_text(cr, self.label,
                  rect.x, rect.y,
                  rect.width, rect.height,
                  text_size=FONT_SIZE,
                  text_color=self.text_color,
                  alignment=pango.ALIGN_RIGHT
                  )

        return True
示例#10
0
    def __draw_frame(self, cr, allocation):
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.save()
            cr.set_dash((9, 3))
            cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
            x = self.edit_coord_x
            y = self.edit_coord_y
            w = self.edit_coord_w
            h = self.edit_coord_h
            if x == 0:
                x = 1
            if y == 0:
                y = 1
            if x + w > self.AREA_WIDTH:
                w = self.AREA_WIDTH - x
            if y + h > self.AREA_HEIGHT:
                h = self.AREA_HEIGHT - y
            cr.rectangle(x, y, w, h)
            cr.stroke()

            cr.set_dash((3, 9))
            cr.set_source_rgb(1, 1, 1)
            cr.rectangle(x, y, w, h)
            cr.stroke()
            cr.restore()

            cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
            cr.rectangle(self.drag_point_x, self.drag_point_y, self.DRAG_WIDTH,
                         self.DRAG_WIDTH)
            cr.stroke()
示例#11
0
    def render_pwd_entry(self, cr, rect):
        render_background(cr, rect)
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(0, 0, 0)
            cr.set_line_width(1)
            cr.rectangle(rect.x, rect.y + 4, rect.width, 22)
            cr.stroke()
        if self.is_select:
            text_color = "#ffffff"
        else:
            text_color = "#000000"
            self.password_buffer.move_to_start()

        self.password_buffer.set_text_color(text_color)
        height = self.password_buffer.get_pixel_size()[1]
        offset = (self.height - height) / 2
        if offset < 0:
            offset = 0
        rect.y += offset
        if self.entry and self.entry.allocation.width == self.get_column_widths(
        )[1] - 4:
            self.entry.calculate()
            rect.x += 2
            rect.width -= 4
            self.password_buffer.set_text_color("#000000")
            self.password_buffer.render(cr, rect, self.entry.im,
                                        self.entry.offset_x)
        else:
            self.password_buffer.render(cr, rect)
示例#12
0
    def on_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        rect.x += self.padding_x
        rect.width -= self.padding_x * 2

        keyword_span = self.red_span % self.keyword
        from_keyword_span = self.black_span % self.from_keyword
        from_keyword_dict = {
            "keyword": keyword_span,
            "from": from_keyword_span
        }
        self.prompt_text = self.prompt_format_text.format(**from_keyword_dict)
        _width, _height = get_content_size(self.prompt_text)

        draw_text(cr,
                  self.prompt_text,
                  rect.x,
                  rect.y,
                  rect.width,
                  _height,
                  text_color=app_theme.get_color("labelText").get_color())

        # draw dash
        rect.y += _height + self.padding_y
        dash_line_width = 1
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*color_hex_to_cairo("#D6D6D6"))
            cr.set_line_width(dash_line_width)
            cr.set_dash([4.0, 4.0])
            cr.move_to(rect.x, rect.y)
            cr.rel_line_to(rect.width, 0)
            cr.stroke()

        rect.y += self.padding_y + dash_line_width

        _width, _height = get_content_size(self.suggest_title)
        draw_text(cr, self.suggest_title, rect.x, rect.y, rect.width, _height)

        rect.y += _height + self.padding_y
        _width, _height = get_content_size(self.suggest_first_line)
        draw_text(cr,
                  self.suggest_first_line,
                  rect.x,
                  rect.y,
                  rect.width,
                  _height,
                  text_color=app_theme.get_color("labelText").get_color())

        rect.y += _height + self.padding_y
        _width, _height = get_content_size(self.suggest_second_line)
        draw_text(cr,
                  self.suggest_second_line,
                  rect.x,
                  rect.y,
                  rect.width,
                  _height,
                  text_color=app_theme.get_color("labelText").get_color())
        return True
    def render_delete(self, cr, rect):
         
        self.render_background(cr, rect)

        BORDER_COLOR = color_hex_to_cairo("#d2d2d2")
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*BORDER_COLOR)
            cr.set_line_width(1)
 def expose_outline(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     with cairo_disable_antialias(cr):
         cr.set_line_width(1)
         cr.set_source_rgb(*BORDER_COLOR)
         cr.rectangle(rect.x, rect.y, rect.width , rect.height )
         cr.stroke()
示例#15
0
 def draw_frame_border(self, widget, event):
     cr = widget.window.cairo_create()
     with cairo_disable_antialias(cr):
         cr.set_line_width(1)
         x, y, w, h = widget.allocation
         cr.set_source_rgb(*color_hex_to_cairo(TREEVIEW_BORDER_COLOR))
         cr.rectangle(x - 1, y - 1, w + 2, h + 2)
         cr.stroke()
 def treeview_container_expose_cb(self, widget, event, treeview):
     rect = treeview.allocation
     cr = widget.window.cairo_create()
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*color_hex_to_cairo(TREEVIEW_BORDER_COLOR))
         cr.set_line_width(1)
         cr.rectangle(rect.x, rect.y, rect.width+1, rect.height+1)
         cr.stroke()
 def expose_outline(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     with cairo_disable_antialias(cr):
         cr.set_line_width(1)
         cr.set_source_rgb(*BORDER_COLOR)
         cr.rectangle(rect.x, rect.y, rect.width, rect.height)
         cr.stroke()
 def draw_frame_border(self, widget, event):
     cr = widget.window.cairo_create()
     with cairo_disable_antialias(cr):
         cr.set_line_width(1)
         x, y, w, h = widget.allocation
         cr.set_source_rgb(*color_hex_to_cairo(TREEVIEW_BORDER_COLOR))
         cr.rectangle(x-1, y-1, w+2, h+2)
         cr.stroke()
    def render_active(self, cr, rect):
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(0, 0, 0)
            cr.set_line_width(1)
            cr.rectangle(rect.x, rect.y + 4, rect.width, 22)
            cr.stroke()

        draw_text(cr, _("active"), rect.x, rect.y, rect.width, rect.height,
                alignment = pango.ALIGN_LEFT)
示例#20
0
    def render(self, cr, rect):
        '''
        Render item.
        
        This is IconView interface, you should implement it.
        '''
        if self.pixbuf == None:
            self.create_cache_pixbuf()

        wallpaper_x = rect.x + (rect.width - self.wallpaper_width) / 2
        wallpaper_y = rect.y + (rect.height - self.wallpaper_height) / 2

        # Draw shadow.
        drop_shadow_padding = 7
        drop_shadow_radious = 7
        draw_shadow(cr, wallpaper_x, wallpaper_y,
                    self.wallpaper_width + drop_shadow_padding,
                    self.wallpaper_height + drop_shadow_padding,
                    drop_shadow_radious,
                    app_theme.get_shadow_color("window_shadow"))

        outside_shadow_padding = 4
        outside_shadow_radious = 5
        draw_shadow(cr, wallpaper_x - outside_shadow_padding,
                    wallpaper_y - outside_shadow_padding,
                    self.wallpaper_width + outside_shadow_padding * 2,
                    self.wallpaper_height + outside_shadow_padding * 2,
                    outside_shadow_radious,
                    app_theme.get_shadow_color("window_shadow"))

        # Draw wallpaper.
        draw_pixbuf(cr, self.pixbuf, wallpaper_x, wallpaper_y)

        # Draw wallpaper frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(2)
            cr.set_source_rgba(1, 1, 1, 1)
            cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width,
                         self.wallpaper_height)
            cr.stroke()

        if self.is_hover:
            cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width,
                         self.wallpaper_height)
            cr.set_source_rgb(
                *color_hex_to_cairo(self.hover_stroke_dcolor.get_color()))
            cr.stroke()

        if self.is_tick:
            tick_pixbuf = self.tick_normal_dpixbuf.get_pixbuf()
        else:
            tick_pixbuf = self.tick_gray_dpixbuf.get_pixbuf()

        tick_x = wallpaper_x + self.wallpaper_width - tick_pixbuf.get_width(
        ) / 2
        tick_y = wallpaper_y - tick_pixbuf.get_height() / 2
        draw_pixbuf(cr, tick_pixbuf, tick_x, tick_y)
    def render_right(self, cr, rect):
        render_background(cr, rect)

        BORDER_COLOR = color_hex_to_cairo("#d2d2d2")
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*BORDER_COLOR)
            cr.set_line_width(1)
            cr.rectangle(rect.x , rect.y , rect.width , rect.height + 1)
            cr.stroke()
 def render_blank(self, cr, rect):
     render_background(cr, rect)
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
         cr.set_line_width(1)
         if self.is_last:
             cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1)
         cr.rectangle(rect.x, rect.y, rect.width, 1)
         cr.fill()
示例#23
0
 def render_blank(self, cr, rect):
     self.render_background(cr, rect)
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
         cr.set_line_width(1)
         if self.is_last:
             cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
         cr.rectangle(rect.x, rect.y, rect.width, 1)
         cr.fill()
 def render_icon(self, cr, rect):
     if self.icon:
         cr.set_source_pixbuf(self.icon, rect.x, rect.y+self.title_height+self.padding_y)
         cr.paint()
         with cairo_disable_antialias(cr):
             border_color = "#CCCCCC"
             cr.set_source_rgb(*color_hex_to_cairo(border_color))
             cr.set_line_width(1)
             cr.rectangle(rect.x, rect.y+self.title_height+self.padding_y, 48, 48)
             cr.stroke()
 def draw_mask(self, cr, x, y, w, h):
     cr.set_source_rgb(*color_hex_to_cairo(MODULE_BG_COLOR))
     cr.rectangle(x, y, w, h)
     cr.fill()
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*color_hex_to_cairo(TREEVIEW_BORDER_COLOR))
         cr.set_line_width(1)
         cr.move_to(x+w-2, y)
         cr.line_to(x+w-2, y+h)
         cr.stroke()
示例#26
0
    def _render_action(self, cr, rect, text):
        with cairo_disable_antialias(cr):
            cr.rectangle(*rect)
            cr.set_source_rgb(1, 1, 1)
            cr.set_line_width(2)
            cr.stroke_preserve()
            cr.set_source_rgb(*color_hex_to_cairo(ACTION_BUTTON_COLOR_BG))
            cr.fill()

            draw_text(cr, text, rect.x, rect.y, rect.width, rect.height, text_color="#ffffff", alignment=pango.ALIGN_CENTER)
 def render_jumpto(self, cr, rect):
     self.render_background(cr, rect)
     draw_pixbuf(cr, self.jumpto_pixbuf.get_pixbuf(), rect.x , rect.y + (rect.height - IMG_WIDTH)/2)
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
         cr.set_line_width(1)
         if self.is_last:
             cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1)
         cr.rectangle(rect.x, rect.y, rect.width, 1)
         cr.rectangle(rect.x + rect.width -1, rect.y, 1, rect.height)
         cr.fill()
示例#28
0
def draw_range(cr, x, y, width, height, color_name):
    if color_name.startswith("#"):
        color = color_name
    else:
        color = app_theme.get_color(color_name).get_color()
    cairo_color = color_hex_to_cairo(color)
    with cairo_disable_antialias(cr):
        cr.set_line_width(1)
        cr.set_source_rgb(*cairo_color)
        cr.rectangle(x, y, width, height)
        cr.stroke()
def draw_range(cr, x, y, width, height, color_name):
    if color_name.startswith("#"):
        color = color_name
    else:    
        color = app_theme.get_color(color_name).get_color()
    cairo_color = color_hex_to_cairo(color)        
    with cairo_disable_antialias(cr):
        cr.set_line_width(1)
        cr.set_source_rgb(*cairo_color)
        cr.rectangle(x, y, width, height)
        cr.stroke()
示例#30
0
 def __draw_under_line(self, widget):
     '''draw under line'''
     cr = widget.window.cairo_create()
     with utils.cairo_disable_antialias(cr):
         x, y, w, h = widget.allocation
         # #1A70b1
         cr.set_source_rgba(0.1, 0.43, 0.69, 1.0)
         cr.set_line_width(1)
         cr.move_to(x, y+h-3)
         cr.line_to(x+w, y+h-3)
         cr.stroke()
示例#31
0
 def __draw_under_line(self, widget):
     '''draw under line'''
     cr = widget.window.cairo_create()
     with utils.cairo_disable_antialias(cr):
         x, y, w, h = widget.allocation
         # #1A70b1
         cr.set_source_rgba(0.1, 0.43, 0.69, 1.0)
         cr.set_line_width(1)
         cr.move_to(x, y+h-3)
         cr.line_to(x+w, y+h-3)
         cr.stroke()
 def expose_hint_background(self, widget, event):
     bg_color = color_hex_to_cairo(TREEVIEW_BG_COLOR)
     cr = widget.window.cairo_create()
     rect = widget.allocation
     cr.set_source_rgb(*bg_color)
     cr.rectangle(rect.x, rect.y, rect.width, rect.height)
     cr.fill()
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*BORDER_COLOR)
         cr.set_line_width(1)
         cr.rectangle(rect.x, rect.y, rect.width, rect.height - 1)
         cr.stroke()
 def render_info(self, cr ,rect):
     self.render_background(cr, rect)
     (text_width, text_height) = get_content_size(self.info)
     draw_text(cr, self.info, rect.x, rect.y, rect.width, rect.height,
             alignment = pango.ALIGN_LEFT)
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
         cr.set_line_width(1)
         if self.is_last:
             cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1)
         cr.rectangle(rect.x, rect.y, rect.width, 1)
         cr.fill()
def draw_line(cr, start, end, color_name):
    if color_name.startswith("#"):
        color = color_name
    else:    
        color = app_theme.get_color(color_name).get_color()
    cairo_color = color_hex_to_cairo(color)        
    with cairo_disable_antialias(cr):
        cr.set_line_width(1)
        cr.set_source_rgb(*cairo_color)
        cr.move_to(*start)
        cr.line_to(*end)
        cr.stroke()
 def expose_hint_background(self, widget, event):
     bg_color = color_hex_to_cairo(TREEVIEW_BG_COLOR)
     cr = widget.window.cairo_create()
     rect = widget.allocation
     cr.set_source_rgb(*bg_color) 
     cr.rectangle(rect.x, rect.y, rect.width, rect.height)
     cr.fill()
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*BORDER_COLOR)
         cr.set_line_width(1)
         cr.rectangle(rect.x , rect.y, rect.width , rect.height -1)
         cr.stroke()
def draw_line(cr, start, end, color_name):
    if color_name.startswith("#"):
        color = color_name
    else:
        color = app_theme.get_color(color_name).get_color()
    cairo_color = color_hex_to_cairo(color)
    with cairo_disable_antialias(cr):
        cr.set_line_width(1)
        cr.set_source_rgb(*cairo_color)
        cr.move_to(*start)
        cr.rel_line_to(*end)
        cr.stroke()
示例#37
0
 def render_jumpto(self, cr, rect):
     self.render_background(cr, rect)
     draw_pixbuf(cr, self.jumpto_pixbuf.get_pixbuf(), rect.x,
                 rect.y + (rect.height - IMG_WIDTH) / 2)
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
         cr.set_line_width(1)
         if self.is_last:
             cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
         cr.rectangle(rect.x, rect.y, rect.width, 1)
         cr.rectangle(rect.x + rect.width - 1, rect.y, 1, rect.height)
         cr.fill()
    def render(self, cr, rect):
        '''
        Render item.
        
        This is IconView interface, you should implement it.
        '''
        # Init.
        if self.pixbuf == None:
            self.pixbuf = get_optimum_pixbuf_from_file(self.image_path, self.wallpaper_width, self.wallpaper_height)
            
        wallpaper_x = rect.x + (rect.width - self.wallpaper_width) / 2
        wallpaper_y = rect.y + (rect.height - self.wallpaper_height) / 2
        
        # Draw shadow.
        drop_shadow_padding = 7
        drop_shadow_radious = 7
        draw_shadow(
            cr,
            wallpaper_x,
            wallpaper_y,
            self.wallpaper_width + drop_shadow_padding,
            self.wallpaper_height + drop_shadow_padding,
            drop_shadow_radious,
            app_theme.get_shadow_color("window_shadow")
            )

        outside_shadow_padding = 4
        outside_shadow_radious = 5
        draw_shadow(
            cr,
            wallpaper_x - outside_shadow_padding,
            wallpaper_y - outside_shadow_padding,
            self.wallpaper_width + outside_shadow_padding * 2,
            self.wallpaper_height + outside_shadow_padding * 2,
            outside_shadow_radious,
            app_theme.get_shadow_color("window_shadow")
            )
        
        # Draw wallpaper.
        draw_pixbuf(cr, self.pixbuf, wallpaper_x, wallpaper_y)    
        
        # Draw wallpaper frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(2)
            cr.set_source_rgba(1, 1, 1, 1)
            cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width, self.wallpaper_height)
            cr.stroke()
            
        if self.is_hover:    
            cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width, self.wallpaper_height)
            cr.set_source_rgb(*color_hex_to_cairo(self.hover_stroke_dcolor.get_color()))
            cr.stroke()
示例#39
0
 def draw_entry_background(self, cr, rect):
     '''draw background. expose-event callback'''
     with cairo_disable_antialias(cr):
         x, y, w, h = rect.x, rect.y, rect.width, rect.height
         cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
         cr.rectangle(x, y, w, h)
         cr.fill()
         cr.set_source_rgba(0.0, 0.0, 0.0, 1.0)
         if self.background_dash:
             cr.set_dash(self.background_dash)
         cr.set_line_width(1)
         cr.rectangle(x, y, w, h)
         cr.stroke()
示例#40
0
    def expose_completion_window_frame(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_frame_outside_3").get_color_info()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.fill()

            cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_frame_inside_2").get_color_info()))
            cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2)
            cr.fill()
示例#41
0
 def draw_entry_background(self, cr, rect):
     '''draw background. expose-event callback'''
     with cairo_disable_antialias(cr):
         x, y, w, h = rect.x, rect.y, rect.width, rect.height
         cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
         cr.rectangle(x, y, w, h)
         cr.fill()
         cr.set_source_rgba(0.0, 0.0, 0.0, 1.0)
         if self.background_dash:
             cr.set_dash(self.background_dash)
         cr.set_line_width(1)
         cr.rectangle(x, y, w, h)
         cr.stroke()
示例#42
0
    def on_panel_expose_event(self, widget, event):    
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        draw_line(cr, (rect.x, rect.y + 1), (rect.x + rect.width, rect.y + 1), "#c7c7c7")
        draw_line(cr, (rect.x + rect.width, rect.y), (rect.x + rect.width, rect.y + rect.height), "#c7c7c7")
        draw_line(cr, (rect.x, rect.y + rect.height), (rect.x + rect.width, rect.y + rect.height), "#c7c7c7")
        draw_line(cr, (rect.x + 1, rect.y), (rect.x + 1, rect.y + rect.height), "#c7c7c7")
        
        tx = rect.x + self.padding_x        
        ty = rect.y + self.padding_y
        tw = rect.width - self.padding_x * 2
        intro = self.channel_info.get("intro", "").strip()
        intro = utils.xmlescape(intro)
        if intro:
            intro_text = "<b>%s:</b> %s" % ("简介", intro)
            intro_tw, intro_th = get_content_size(intro_text, wrap_width=tw,text_size=9)
            if intro_th > self.line_height * 2:
                intro_th = self.line_height * 2
            cr.save()
            cr.rectangle(tx, ty, intro_tw, intro_th)
            cr.clip()
            draw_text(cr, intro_text, tx, ty, intro_tw, intro_th, text_size=9,
                      text_color="#878787", wrap_width=tw)
            cr.restore()

            with cairo_disable_antialias(cr):
                cr.save()
                cr.move_to(tx, ty + intro_th + self.line_height)
                cr.rel_line_to(tw, 0)
                cr.set_dash([2.0, 2.0])
                cr.stroke()
                cr.restore()
            
        hotsongs =  " / ".join(self.channel_info.get("hot_songs", [])).strip()
        hotsongs = utils.xmlescape(hotsongs)
        hotsongs_text = "<b>%s:</b> %s" % ("热门歌曲", hotsongs)
        if intro:
            new_ty = ty + intro_th + self.line_height * 2
        else:    
            new_ty = ty
            
        hotsongs_tw, hotsongs_th = get_content_size(hotsongs_text, wrap_width=tw,text_size=9)
        if hotsongs_th > self.line_height * 2:
            hotsongs_th = self.line_height * 2
        cr.save()
        cr.rectangle(tx, new_ty, hotsongs_tw, hotsongs_th)
        cr.clip()
        draw_text(cr, hotsongs_text, tx, new_ty, hotsongs_tw, hotsongs_th, text_size=9,
                  text_color="#878787", wrap_width=tw)
        return True
    def __expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Get color info.
        if widget.state == gtk.STATE_NORMAL:
            border = None
            bg = None

        elif widget.state == gtk.STATE_PRELIGHT:
            border = BORDER_COLOR
            bg = BG_COLOR
        elif widget.state == gtk.STATE_ACTIVE:
            border = BORDER_COLOR
            bg = None
        elif widget.state == gtk.STATE_INSENSITIVE:
            pass

        # Draw background.
        if bg:
            cr.set_source_rgb(*BG_COLOR)
            cr.rectangle(x, y, w, h)
            cr.fill()

        # Draw border.
        if border:
            with cairo_disable_antialias(cr):
                cr.set_source_rgb(*border)
                cr.set_line_width(1)
                #if self.is_last:
                #cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1)
                cr.rectangle(x + 1, y + 1, w - 1, h - 1)
                cr.stroke()
            #draw_line(cr, x + 1, y + 1, x + w - 2, y + 1) # top
            #draw_line(cr, x + 2, y + h, x + w - 2, y + h) # bottom
            #draw_line(cr, x + 1, y + 2, x + 1, y + h - 2) # left
            #draw_line(cr, x + w, y + 2, x + w, y + h - 2) # right

        # Draw font.
        draw_text(cr,
                  self.con,
                  x + ALIGN_SPACING,
                  y,
                  w,
                  h,
                  CONTENT_FONT_SIZE,
                  self.text_color,
                  alignment=pango.ALIGN_LEFT)

        return True
示例#44
0
    def on_size_allocate(self, widget, rect):
        x, y, w, h = rect.x, rect.y, rect.width, rect.height
        bitmap = gtk.gdk.Pixmap(None, w, h, 1)
        cr = bitmap.cairo_create()

        cr.set_source_rgb(0.0, 0.0, 0.0)
        cr.set_operator(cairo.OPERATOR_CLEAR)
        cr.paint()
        
        cr.set_operator(cairo.OPERATOR_OVER)
        with cairo_disable_antialias(cr):
            draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, 4)
            cr.fill()
        widget.shape_combine_mask(bitmap, 0, 0)        
    def render_delete(self, cr, rect):
         
        self.render_background(cr, rect)
        if self.delete_hover:
            delete_icon = self.delete_pixbuf_out
            draw_pixbuf(cr, delete_icon.get_pixbuf(), rect.x + self.CHECK_LEFT_PADDING/2, rect.y + (rect.height - IMG_WIDTH)/2)
        else:
            delete_icon = self.delete_pixbuf_out

        BORDER_COLOR = color_hex_to_cairo("#d2d2d2")
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*BORDER_COLOR)
            cr.set_line_width(1)
            draw_line(cr, rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height)
示例#46
0
    def render_active(self, cr, rect):
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(0, 0, 0)
            cr.set_line_width(1)
            cr.rectangle(rect.x, rect.y + 4, rect.width, 22)
            cr.stroke()

        draw_text(cr,
                  _("active"),
                  rect.x,
                  rect.y,
                  rect.width,
                  rect.height,
                  alignment=pango.ALIGN_LEFT)
示例#47
0
    def render(self, cr, rect):
        '''
        Render item.
        
        This is IconView interface, you should implement it.
        '''
        # Init.
        if self.pixbuf == None:
            self.pixbuf = get_optimum_pixbuf_from_file(self.image_path,
                                                       self.wallpaper_width,
                                                       self.wallpaper_height)

        wallpaper_x = rect.x + (rect.width - self.wallpaper_width) / 2
        wallpaper_y = rect.y + (rect.height - self.wallpaper_height) / 2

        # Draw shadow.
        drop_shadow_padding = 7
        drop_shadow_radious = 7
        draw_shadow(cr, wallpaper_x, wallpaper_y,
                    self.wallpaper_width + drop_shadow_padding,
                    self.wallpaper_height + drop_shadow_padding,
                    drop_shadow_radious,
                    app_theme.get_shadow_color("window_shadow"))

        outside_shadow_padding = 4
        outside_shadow_radious = 5
        draw_shadow(cr, wallpaper_x - outside_shadow_padding,
                    wallpaper_y - outside_shadow_padding,
                    self.wallpaper_width + outside_shadow_padding * 2,
                    self.wallpaper_height + outside_shadow_padding * 2,
                    outside_shadow_radious,
                    app_theme.get_shadow_color("window_shadow"))

        # Draw wallpaper.
        draw_pixbuf(cr, self.pixbuf, wallpaper_x, wallpaper_y)

        # Draw wallpaper frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(2)
            cr.set_source_rgba(1, 1, 1, 1)
            cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width,
                         self.wallpaper_height)
            cr.stroke()

        if self.is_hover:
            cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width,
                         self.wallpaper_height)
            cr.set_source_rgb(
                *color_hex_to_cairo(self.hover_stroke_dcolor.get_color()))
            cr.stroke()
 def render_left(self, cr, rect):
     self.render_background(cr, rect)
     if self.is_hover_left:
         icon = self.left_hover
     else:
         icon = self.left
     draw_pixbuf(cr, icon.get_pixbuf(), rect.x + IMG_WIDTH + 5, rect.y + (rect.height - IMG_WIDTH)/2)
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
         cr.set_line_width(1)
         if self.is_last:
             cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1)
         cr.rectangle(rect.x, rect.y, rect.width, 1)
         cr.fill()
    def render_ssid(self, cr, rect):
        self.render_background(cr,rect)
        ssid = self.ssid.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
        (text_width, text_height) = get_content_size(ssid)
        draw_text(cr, ssid, rect.x, rect.y, rect.width, rect.height,
                alignment = pango.ALIGN_LEFT)

        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
            cr.set_line_width(1)
            if self.is_last:
                cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1)
            cr.rectangle(rect.x, rect.y, rect.width, 1)
            cr.fill()
示例#50
0
    def on_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        rect.x += self.padding_x
        rect.width -= self.padding_x * 2

        # Draw title.
        # _width, _height = get_content_size(self.title)
        # draw_text(cr, self.title, rect.x, rect.y, rect.width, _height)
        # rect.y += self.padding_y + _height

        # Draw dashed.
        dash_line_width = 1
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*color_hex_to_cairo("#D6D6D6"))
            cr.set_line_width(dash_line_width)
            cr.set_dash([4.0, 4.0])
            cr.move_to(rect.x, rect.y)
            cr.rel_line_to(rect.width, 0)
            cr.stroke()

        rect.y += self.padding_y + dash_line_width

        # Draw plugin name.
        if self.plugin_info:
            plugin_name = "%s: %s" % (
                _("Name"), utils.xmlescape(self.plugin_info.get("Name", "")))
            _width, _height = get_content_size(plugin_name)
            draw_text(cr, plugin_name, rect.x, rect.y, rect.width, _height)

            rect.y += self.padding_y + _height

            # Draw plugin Authors.
            plugin_authors = plugin_authors = "%s: %s" % (
                _("Author(s)"),
                utils.xmlescape(self.plugin_info.get("Authors", "")))
            _width, _height = get_content_size(plugin_authors)
            draw_text(cr, plugin_authors, rect.x, rect.y, rect.width, _height)

            rect.y += self.padding_y + _height

            # Draw plugin description
            plugin_description = self.plugin_info.get("Description", "")
            _width, _height = get_content_size(plugin_description)
            draw_text(cr, plugin_description, rect.x, rect.y, rect.width,
                      _height)

        return True
    def render(self, cr, rect):
        padding = 10

        # Draw select background.
        if self.is_button_press == True:
            with cairo_disable_antialias(cr):
                cr.set_source_rgb(
                    *color_hex_to_cairo(self.highlight_fill_color))
                cr.rectangle(rect.x + padding, rect.y + padding,
                             rect.width - padding, rect.height - padding)
                cr.fill_preserve()
                cr.set_line_width(1)
                cr.set_source_rgb(
                    *color_hex_to_cairo(self.highlight_stroke_color))
                cr.stroke()

        # Draw device icon.
        draw_pixbuf(
            cr,
            self.pixbuf,
            rect.x + self.icon_size / 2 + 4,
            rect.y + (rect.height - self.icon_size) / 2,
        )

        if self.is_paired:
            draw_pixbuf(
                cr, self.pair_pixbuf.get_pixbuf(), rect.x + self.icon_size +
                self.pair_pixbuf.get_pixbuf().get_width() / 2,
                rect.y + self.icon_size +
                self.pair_pixbuf.get_pixbuf().get_height() / 2)
        if self.is_connected:
            draw_pixbuf(
                cr, self.device_connected_pixbuf.get_pixbuf(), rect.x +
                self.icon_size + self.pair_pixbuf.get_pixbuf().get_width() / 2,
                rect.y + self.pair_pixbuf.get_pixbuf().get_height())

        # Draw device name.
        text_color = "#000000"
        if self.is_button_press == True:
            text_color = "#FFFFFF"
        draw_text(cr,
                  self.name,
                  rect.x + padding,
                  rect.y + self.icon_size + self.__const_padding_y * 2,
                  rect.width - padding,
                  CONTENT_FONT_SIZE,
                  CONTENT_FONT_SIZE,
                  text_color,
                  alignment=pango.ALIGN_CENTER)
示例#52
0
 def render_left(self, cr, rect):
     self.render_background(cr, rect)
     if self.is_hover_left:
         icon = self.left_hover
     else:
         icon = self.left
     draw_pixbuf(cr, icon.get_pixbuf(), rect.x + IMG_WIDTH + 5,
                 rect.y + (rect.height - IMG_WIDTH) / 2)
     with cairo_disable_antialias(cr):
         cr.set_source_rgb(*color_hex_to_cairo(self.border_color))
         cr.set_line_width(1)
         if self.is_last:
             cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
         cr.rectangle(rect.x, rect.y, rect.width, 1)
         cr.fill()
示例#53
0
 def __expose_cb(self, widget, event):
     ''' expose-event callback'''
     cr = widget.window.cairo_create()
     x, y, w, h = widget.allocation
     if widget.get_state() == gtk.STATE_PRELIGHT:
         cr.set_source_rgb(*color_hex_to_cairo("#ddf3ff"))
         cr.rectangle(0, 0, w, self.padding_y)
         cr.fill()
         cr.rectangle(0, h - self.padding_y, w, self.padding_y)
         cr.fill()
         cr.rectangle(0, self.padding_y, self.padding_x,
                      h - 2 * self.padding_y)
         cr.fill()
         cr.rectangle(w - self.padding_x, self.padding_y, self.padding_x,
                      h - 2 * self.padding_y)
         cr.fill()
     else:
         cr.set_source_rgb(1, 1, 1)
         cr.rectangle(0, 0, w, self.padding_y)
         cr.fill()
         cr.rectangle(0, h - self.padding_y, w, self.padding_y)
         cr.fill()
         cr.rectangle(0, self.padding_y, self.padding_x,
                      h - 2 * self.padding_y)
         cr.fill()
         cr.rectangle(w - self.padding_x, self.padding_y, self.padding_x,
                      h - 2 * self.padding_y)
         cr.fill()
     if self.has_frame:
         with cairo_disable_antialias(cr):
             border_color = "#CCCCCC"
             cr.set_source_rgb(*color_hex_to_cairo(border_color))
             cr.set_line_width(1)
             cr.rectangle(self.padding_x, self.padding_y,
                          w - 2 * self.padding_x + 1,
                          h - 2 * self.padding_y + 1)
             cr.stroke()
     if self.pixbuf:
         cr.set_source_pixbuf(self.pixbuf, self.padding_x, self.padding_y)
         cr.paint()
     if self.can_del and widget.get_state() == gtk.STATE_PRELIGHT:
         bg_pixbuf = self.del_bg_pixbuf.get_pixbuf()
         fg_pixbuf = self.del_fg_pixbuf.get_pixbuf()
         cr.set_source_pixbuf(bg_pixbuf, self.bg_offset_x, self.bg_offset_y)
         cr.paint()
         cr.set_source_pixbuf(fg_pixbuf, self.fg_offset_x, self.fg_offset_y)
         cr.paint()
     return True
示例#54
0
    def on_top_hbox_expose(self, widget, event):    
        cr = widget.window.cairo_create()
        rect = widget.allocation

        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgba(*color_hex_to_cairo("#C3C4C5"))
            cr.move_to(rect.x + 1, rect.y + 1)
            cr.rel_line_to(0, rect.height - 1)
            cr.rel_line_to(rect.width - 2, 0)
            cr.rel_line_to(0, -rect.height + 1)
            cr.stroke()
            
        propagate_expose(widget, event)    
        
        return True
    def draw_progress_bar(self, cr, rect):

        # Draw progressbar background.
        bg_height = self.bg_dpixbuf.get_pixbuf().get_height()
        self.bg_cache_pixbuf.scale(self.bg_dpixbuf.get_pixbuf(),
                                   self.progress_width, bg_height)

        bg_y = rect.y + (rect.height - bg_height) / 2
        draw_pixbuf(cr, self.bg_cache_pixbuf.get_cache(),
                    rect.x + self.bg_offset, bg_y)

        # Draw progressbar foreground.
        if self.current_progress_width > 0:
            fg_height = self.fg_dpixbuf.get_pixbuf().get_height()
            # self.fg_cache_pixbuf.scale(self.fg_dpixbuf.get_pixbuf(),
            #                            int(self.current_progress_width),
            #                            fg_height)

            fg_y = rect.y + (rect.height - fg_height) / 2
            # draw_pixbuf(cr, self.fg_cache_pixbuf.get_cache(),  rect.x + self.fg_offset, fg_y)

            lg_width = int(self.current_progress_width)
            pat = cairo.LinearGradient(rect.x + self.fg_offset, fg_y,
                                       rect.x + self.fg_offset + lg_width,
                                       fg_y)
            pat.add_color_stop_rgb(
                0.6, *color_hex_to_cairo(self.fg_left_dcolor.get_color()))
            pat.add_color_stop_rgb(
                1.0, *color_hex_to_cairo(self.fg_right_dcolor.get_color()))
            cr.set_operator(cairo.OPERATOR_OVER)
            cr.set_source(pat)
            cr.rectangle(rect.x + self.fg_offset, fg_y, lg_width, fg_height)
            cr.fill()

            with cairo_disable_antialias(cr):
                cr.set_line_width(1)
                cr.set_source_rgba(1, 1, 1, 0.3)
                cr.rectangle(rect.x + self.fg_offset, fg_y, lg_width,
                             fg_height)
                cr.stroke()

        # Draw point.
        point_y = rect.y + (rect.height -
                            self.point_dpixbuf.get_pixbuf().get_height()) / 2
        draw_pixbuf(cr, self.point_dpixbuf.get_pixbuf(),
                    rect.x + self.point_offset + self.current_progress_width,
                    point_y)