Example #1
0
 def draw_entry_text(self, cr, rect):
     ''' draw text.expose-event callback'''
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     with cairo_state(cr):
         # Clip text area first.
         draw_x = x + self.padding_x
         draw_y = y + self.padding_y
         draw_width = w - self.padding_x * 2
         draw_height = h - self.padding_y * 2
         cr.rectangle(draw_x, draw_y, draw_width, draw_height)
         cr.clip()
         # Create pangocairo context.
         context = pangocairo.CairoContext(cr)
         # Move text.
         cr.move_to(draw_x, draw_y)
         # Draw text.
         cr.set_source_rgb(
             *color_hex_to_cairo(self.entry_buffer.text_color))
         context.update_layout(self._layout)
         context.show_layout(self._layout)
     # draw selection
     if not self.buffer.get_has_selection():
         return
     bounds = self.buffer.get_selection_bounds()
     self.draw_selection_lines(bounds[0], bounds[1], cr, x, y)
Example #2
0
    def render(self, cr, rect):
        # Init.
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw background frame.
        with cairo_state(cr):
            cr.rectangle(x, y + 1, w, h - 2)
            cr.rectangle(x + 1, y, w - 2, h)
            cr.clip()

            cr.set_source_rgb(*color_hex_to_cairo(
                ui_theme.get_color(
                    "progressbar_background_frame").get_color()))
            cr.rectangle(x, y, w, h)
            cr.set_line_width(1)
            cr.stroke()

        # Draw background.
        with cairo_state(cr):
            cr.rectangle(x + 1, y + 1, w - 2, h - 2)
            cr.clip()

            draw_vlinear(
                cr,
                x + 1,
                y + 1,
                w - 2,
                h - 2,
                ui_theme.get_shadow_color(
                    "progressbar_background").get_color_info(),
            )
            cache_pixbuf_object = CachePixbuf()
            if self.progress > 0 and self.progress < 100:
                cache_pixbuf_object.scale(
                    self.percentage_dpixbuf[int(self.progress /
                                                10)].get_pixbuf(), w, h)
            if self.progress == 100:
                cache_pixbuf_object.scale(
                    self.percentage_dpixbuf[9].get_pixbuf(), w, h)
            draw_pixbuf(cr, cache_pixbuf_object.get_cache(), x, y)

        # Draw light.
        with cairo_disable_antialias(cr):
            cr.set_source_rgba(1, 1, 1, 0.5)
            cr.rectangle(x + 1, y + 1, w - 2, 1)
            cr.fill()
 def __draw_rotate(self, cr, rect, pixbuf):
     from dtk.ui.utils import cairo_state
     from math import radians
     with cairo_state(cr):
         cr.translate(rect.x + rect.width/2 , rect.y + rect.height/2)
         cr.rotate(radians(self.rotate_angle))
         cr.translate(-rect.width/2, -rect.height/2)
         x_padding =  rect.width/2 - pixbuf.get_width()/2
         y_padding = rect.height/2 - pixbuf.get_height()/2
         draw_pixbuf(cr, pixbuf, x_padding, y_padding)
    def draw_loop_pixbuf(self, cr, loop_pixbuf, loop_x, loop_y):
        width = loop_pixbuf.get_width()
        height = loop_pixbuf.get_height()
        ox = loop_x + width * 0.5
        oy = loop_y + height * 0.5 

        with cairo_state(cr):
            cr.translate(ox, oy)
            cr.rotate(radians(self.degree))                      
            cr.translate(-width * 0.5, -height * 0.5)
            draw_pixbuf(cr, loop_pixbuf, 0, 0)
Example #5
0
    def draw_loop_pixbuf(self, cr, loop_pixbuf, loop_x, loop_y):
        width = loop_pixbuf.get_width()
        height = loop_pixbuf.get_height()
        ox = loop_x + width * 0.5
        oy = loop_y + height * 0.5

        with cairo_state(cr):
            cr.translate(ox, oy)
            cr.rotate(radians(self.degree))
            cr.translate(-width * 0.5, -height * 0.5)
            draw_pixbuf(cr, loop_pixbuf, 0, 0)
 def render(self, cr, rect):
     # Init.
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     # Draw background frame.
     with cairo_state(cr):
         cr.rectangle(x, y + 1, w, h - 2)
         cr.rectangle(x + 1, y, w - 2, h)
         cr.clip()
         
         cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("progressbar_background_frame").get_color()))
         cr.rectangle(x, y, w, h)
         cr.set_line_width(1)
         cr.stroke()
         
     # Draw background.
     with cairo_state(cr):
         cr.rectangle(x + 1, y + 1, w - 2, h - 2)
         cr.clip()
         
         draw_vlinear(cr, x + 1, y + 1, w - 2, h - 2,
                      ui_theme.get_shadow_color("progressbar_background").get_color_info(), 
                      )
         cache_pixbuf_object = CachePixbuf()
         if self.progress > 0 and self.progress < 100:
             cache_pixbuf_object.scale(self.percentage_dpixbuf[int(self.progress / 10)].get_pixbuf(), 
                                       w, 
                                       h)
         if self.progress == 100:
             cache_pixbuf_object.scale(self.percentage_dpixbuf[9].get_pixbuf(), 
                                       w, 
                                       h)
         draw_pixbuf(cr, cache_pixbuf_object.get_cache(), x, y)
     
     # Draw light.
     with cairo_disable_antialias(cr):
         cr.set_source_rgba(1, 1, 1, 0.5)
         cr.rectangle(x + 1, y + 1, w - 2, 1)
         cr.fill()
    def render_info(self, cr, rect):
        if self.row_index % 2 == 1:
            cr.set_source_rgba(1, 1, 1, 0.5)
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.fill()
        
        # Render icon.
        if self.icon_pixbuf == None:
            self.icon_pixbuf = gtk.gdk.pixbuf_new_from_file(
                    get_icon_pixbuf_path(utils.get_origin_name(self.pkg_name)))
            
        render_pkg_icon(cr, rect, self.icon_pixbuf)

        # Render name.
        render_pkg_name(cr, rect, get_match_context(self.alias_name, self.keywords), rect.width)
        
        # Render search result.
        with cairo_state(cr):
            text_padding_left = ITEM_PADDING_X + ICON_SIZE + ITEM_PADDING_MIDDLE
            text_padding_right = 10
            text_padding_y = ITEM_PADDING_Y + DEFAULT_FONT_SIZE * 2
            text_width = rect.width - text_padding_left - text_padding_right
            text_height = 30
            
            cr.rectangle(rect.x, rect.y + text_padding_y, rect.width, text_height)
            cr.clip()
            
            draw_text(
                cr, 
                self.highlight_string,
                rect.x + text_padding_left,
                rect.y + text_padding_y,
                text_width,
                text_height,
                text_size=DEFAULT_FONT_SIZE,
                wrap_width=text_width,
                )
Example #8
0
    def render_info(self, cr, rect):
        if self.row_index % 2 == 1:
            cr.set_source_rgba(1, 1, 1, 0.5)
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.fill()

        # Render icon.
        if self.icon_pixbuf == None:
            self.icon_pixbuf = gtk.gdk.pixbuf_new_from_file(
                    get_icon_pixbuf_path(utils.get_origin_name(self.pkg_name)))

        render_pkg_icon(cr, rect, self.icon_pixbuf)

        # Render name.
        render_pkg_name(cr, rect, get_match_context(self.alias_name, self.keywords), rect.width)

        # Render search result.
        with cairo_state(cr):
            text_padding_left = ITEM_PADDING_X + ICON_SIZE + ITEM_PADDING_MIDDLE
            text_padding_right = 10
            text_padding_y = ITEM_PADDING_Y + DEFAULT_FONT_SIZE * 2
            text_width = rect.width - text_padding_left - text_padding_right
            text_height = 30

            cr.rectangle(rect.x, rect.y + text_padding_y, rect.width, text_height)
            cr.clip()

            draw_text(
                cr,
                self.highlight_string,
                rect.x + text_padding_left,
                rect.y + text_padding_y,
                text_width,
                text_height,
                text_size=DEFAULT_FONT_SIZE,
                wrap_width=text_width,
                )
Example #9
0
 def draw_entry_text(self, cr, rect):
     ''' draw text.expose-event callback'''
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     with cairo_state(cr):
         # Clip text area first.
         draw_x = x + self.padding_x
         draw_y = y + self.padding_y
         draw_width = w - self.padding_x * 2
         draw_height = h - self.padding_y * 2
         cr.rectangle(draw_x, draw_y, draw_width, draw_height)
         cr.clip()
         # Create pangocairo context.
         context = pangocairo.CairoContext(cr)
         # Move text.
         cr.move_to(draw_x, draw_y)
         # Draw text.
         cr.set_source_rgb(*color_hex_to_cairo(self.text_color))
         context.update_layout(self._layout)
         context.show_layout(self._layout)
     # draw selection
     if not self.buffer.get_has_selection():
         return
     bounds = self.buffer.get_selection_bounds()
     self.draw_selection_lines(bounds[0], bounds[1], cr, x, y)
    def render(self, cr, rect):
        # Draw icon.
        if self.pkg_icon_pixbuf == None:
            self.pkg_icon_pixbuf = gtk.gdk.pixbuf_new_from_file(get_icon_pixbuf_path(self.pkg_name))        

        draw_pixbuf(
            cr,
            self.pkg_icon_pixbuf,
            rect.x + self.DRAW_PADDING_LEFT + (ICON_SIZE - self.pkg_icon_pixbuf.get_width()) / 2,
            rect.y + self.DRAW_PADDING_Y)    
        
        # Draw button.
        if self.is_installed:
            name = "button/start_small"
        else:
            name = "button/install_small"
        
        if self.button_status == BUTTON_NORMAL:
            status = "normal"
        elif self.button_status == BUTTON_HOVER:
            status = "hover"
        elif self.button_status == BUTTON_PRESS:
            status = "press"
            
        pixbuf = app_theme.get_pixbuf("%s_%s.png" % (name, status)).get_pixbuf()
        draw_pixbuf(
            cr,
            pixbuf,
            rect.x + self.DRAW_PADDING_LEFT,
            rect.y + self.DRAW_PADDING_Y + self.DRAW_ICON_SIZE + self.DRAW_BUTTON_PADDING_Y)
        
        # Draw name.
        self.text_width = rect.width - self.DRAW_PADDING_LEFT - self.DRAW_PADDING_RIGHT - self.DRAW_INFO_PADDING_X - self.pkg_icon_pixbuf.get_width()
        self.pkg_name_area.render(
            cr,
            self.alias_name,
            gtk.gdk.Rectangle(
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE + self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_PADDING_Y,
                self.text_width,
                NAME_SIZE))

        # Draw star.
        self.star_buffer.render(
            cr,
            gtk.gdk.Rectangle(
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE + self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_STAR_PADDING_Y,
                STAR_SIZE * 5,
                STAR_SIZE
                ))
        
        # Draw long desc.
        long_desc_height = 32
        if self.long_desc == None:
            self.long_desc = "FIX ME"
        #if self.long_desc and len(self.long_desc.split("\n")) == 1:
            #self.long_desc += "\n"
        with cairo_state(cr):
            cr.rectangle(
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE + self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_LONG_DESC_PADDING_Y,
                self.text_width,
                long_desc_height,
                )
            cr.clip()
            draw_text(
                cr,
                self.long_desc,
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE + self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_LONG_DESC_PADDING_Y,
                self.text_width,
                long_desc_height,
                wrap_width=self.text_width,
                )
Example #11
0
def render_text(
    cr,
    markup,
    x,
    y,
    w,
    h,
    text_size=DEFAULT_FONT_SIZE,
    text_color="#000000",
    text_font=DEFAULT_FONT,
    alignment=pango.ALIGN_LEFT,
    wrap_width=None,
    underline=False,
    vertical_alignment=TEXT_ALIGN_MIDDLE,
    clip_line_count=None,
    ellipsize=pango.ELLIPSIZE_END,
):
    '''
    Render text for function L{ I{draw_text} <draw_text>}, you can use this function individually.
    
    @param cr: Cairo context.
    @param markup: Pango markup string.
    @param x: X coordinate of draw area.
    @param y: Y coordinate of draw area.
    @param w: Width of draw area.
    @param h: Height of draw area.
    @param text_size: Text size, default is DEFAULT_FONT_SIZE.
    @param text_color: Text color, default is \"#000000\".
    @param text_font: Text font, default is DEFAULT_FONT.
    @param alignment: Font alignment option, default is pango.ALIGN_LEFT. You can set pango.ALIGN_MIDDLE or pango.ALIGN_RIGHT.
    @param wrap_width: Wrap width of text, default is None.
    @param underline: Whether draw underline for text, default is False.
    @param vertical_alignment: Vertical alignment value, default is TEXT_ALIGN_MIDDLE, can use below value:
     - TEXT_ALIGN_TOP
     - TEXT_ALIGN_MIDDLE
     - TEXT_ALIGN_BOTTOM
    @param clip_line_count: The line number to clip text area, if set 2, all lines that above 2 will clip out, default is None.
    @param ellipsize: Ellipsize style of text when text width longer than draw area, it can use below value:
     - pango.ELLIPSIZE_START
     - pango.ELLIPSIZE_CENTER
     - pango.ELLIPSIZE_END
    '''
    with cairo_state(cr):
        # Set color.
        cr.set_source_rgb(*color_hex_to_cairo(text_color))

        # Create pangocairo context.
        context = pangocairo.CairoContext(cr)

        # Set layout.
        layout = context.create_layout()
        layout.set_font_description(
            pango.FontDescription("%s %s" % (text_font, text_size)))
        layout.set_markup(markup)
        layout.set_alignment(alignment)
        if wrap_width == None:
            layout.set_single_paragraph_mode(True)
            layout.set_width(w * pango.SCALE)
            layout.set_ellipsize(ellipsize)
        else:
            layout.set_width(wrap_width * pango.SCALE)
            layout.set_wrap(pango.WRAP_WORD)

        (text_width, text_height) = layout.get_pixel_size()

        if underline:
            if alignment == pango.ALIGN_LEFT:
                cr.rectangle(x, y + text_height + (h - text_height) / 2,
                             text_width, 1)
            elif alignment == pango.ALIGN_CENTER:
                cr.rectangle(x + (w - text_width) / 2,
                             y + text_height + (h - text_height) / 2,
                             text_width, 1)
            else:
                cr.rectangle(x + w - text_width,
                             y + text_height + (h - text_height) / 2,
                             text_width, 1)
            cr.fill()

        # Set render y coordinate.
        if vertical_alignment == TEXT_ALIGN_TOP:
            render_y = y
        elif vertical_alignment == TEXT_ALIGN_MIDDLE:
            render_y = y + max(0, (h - text_height) / 2)
        else:
            render_y = y + max(0, h - text_height)

        # Clip area.
        if clip_line_count:
            line_count = layout.get_line_count()
            if line_count > 0:
                line_height = text_height / line_count
                cr.rectangle(x, render_y, text_width,
                             line_height * clip_line_count)
                cr.clip()

        # Draw text.
        cr.move_to(x, render_y)
        context.update_layout(layout)
        context.show_layout(layout)
def render_hyperlink_support_text(obj, cr, markup, 
                                  x, y, w, h, 
                                  text_size=DEFAULT_FONT_SIZE, 
                                  text_color="#000000", 
                                  text_font=DEFAULT_FONT, 
                                  alignment=pango.ALIGN_LEFT,
                                  wrap_width=None, 
                                  underline=False,
                                  vertical_alignment=TEXT_ALIGN_MIDDLE,
                                  clip_line_count=None,
                                  ellipsize=pango.ELLIPSIZE_END,
                                  ):
    
    with cairo_state(cr):
        # Set color.
        cr.set_source_rgb(*color_hex_to_cairo(text_color))
    
        # Create pangocairo context.
        context = pangocairo.CairoContext(cr)
        
        # Set layout.
        layout = context.create_layout()
        layout.set_font_description(pango.FontDescription("%s %s" % (text_font, text_size)))
        layout.set_markup(markup)
        layout.set_alignment(alignment)
        if wrap_width == None:
            layout.set_single_paragraph_mode(True)
            layout.set_width(w * pango.SCALE)
            layout.set_ellipsize(ellipsize)
        else:
            layout.set_width(wrap_width * pango.SCALE)
            layout.set_wrap(pango.WRAP_WORD_CHAR)
            
        (text_width, text_height) = layout.get_pixel_size()
        
        if underline:
            if alignment == pango.ALIGN_LEFT:
                cr.rectangle(x, y + text_height + (h - text_height) / 2, text_width, 1)
            elif alignment == pango.ALIGN_CENTER:
                cr.rectangle(x + (w - text_width) / 2, y + text_height + (h - text_height) / 2, text_width, 1)
            else:
                cr.rectangle(x + w - text_width, y + text_height + (h - text_height) / 2, text_width, 1)
            cr.fill()
            
        # Set render y coordinate.
        if vertical_alignment == TEXT_ALIGN_TOP:
            render_y = y
        elif vertical_alignment == TEXT_ALIGN_MIDDLE:
            render_y = y + max(0, (h - text_height) / 2)
        else:
            render_y = y + max(0, h - text_height)
            
        # Clip area.
        if clip_line_count:
            line_count = layout.get_line_count()
            if line_count > 0:
                line_height = text_height / line_count
                cr.rectangle(x, render_y, text_width, clip_line_count * line_height)
                cr.clip()
                
        # Draw text.
        cr.move_to(x, render_y)
        context.update_layout(layout)
        context.show_layout(layout)
        
        get_pointer_hand_rectangles(obj, markup, layout, x, render_y)
 def draw_loading(self, cr, rect):
     with cairo_state(cr):
         cr.translate(rect.x + 18 , rect.y + 15)
         cr.rotate(radians(60*self.position))
         cr.translate(-18, -15)
         draw_pixbuf(cr, self.loading_pixbuf.get_pixbuf(), 10 , 7)
Example #14
0
    def render(self, cr, rect):
        # Draw icon.
        self.init_pkg_icon_pixbuf()

        draw_pixbuf(
            cr, self.pkg_icon_pixbuf, rect.x + self.DRAW_PADDING_LEFT +
            (ICON_SIZE - self.pkg_icon_width) / 2,
            rect.y + self.DRAW_PADDING_Y)

        # Draw button.
        name = ""
        draw_str = ""
        if self.install_status == "uninstalled":
            name = "button/install_small"
        elif self.install_status == "unknown":
            draw_str = _("Not found")
        else:
            if self.desktops:
                name = "button/start_small"
            else:
                draw_str = _("Installed")

        if name:
            pixbuf = app_theme.get_pixbuf(
                "%s_%s.png" %
                (name, button_status_dict[self.button_status])).get_pixbuf()
            draw_pixbuf(
                cr, pixbuf, rect.x + self.DRAW_PADDING_LEFT,
                rect.y + self.DRAW_PADDING_Y + self.DRAW_ICON_SIZE +
                self.DRAW_BUTTON_PADDING_Y)
        else:
            str_width, str_height = get_content_size(draw_str, 10)
            draw_text(
                cr,
                draw_str,
                rect.x + self.DRAW_PADDING_LEFT,
                rect.y + self.DRAW_PADDING_Y + self.DRAW_ICON_SIZE +
                self.DRAW_BUTTON_PADDING_Y,
                rect.width,
                str_height,
                wrap_width=rect.width,
            )

        # Draw name.
        self.text_width = rect.width - self.DRAW_PADDING_LEFT - self.DRAW_PADDING_RIGHT - self.DRAW_INFO_PADDING_X - self.pkg_icon_width
        self.pkg_name_area.render(
            cr, self.alias_name,
            gtk.gdk.Rectangle(
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE +
                self.DRAW_INFO_PADDING_X, rect.y + self.DRAW_PADDING_Y,
                self.text_width, NAME_SIZE))

        # Draw star.
        self.star_buffer.render(
            cr,
            gtk.gdk.Rectangle(
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE +
                self.DRAW_INFO_PADDING_X, rect.y + self.DRAW_STAR_PADDING_Y,
                STAR_SIZE * 5, STAR_SIZE))

        # Draw long desc.
        long_desc_height = 32
        if self.short_desc == None:
            self.short_desc = "FIX ME"
        with cairo_state(cr):
            cr.rectangle(
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE +
                self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_LONG_DESC_PADDING_Y,
                self.text_width,
                long_desc_height,
            )
            cr.clip()
            draw_text(
                cr,
                self.short_desc,
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE +
                self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_LONG_DESC_PADDING_Y,
                self.text_width,
                long_desc_height,
                wrap_width=self.text_width,
            )
    def render(self, cr, rect):
        '''
        Render item.
        
        This is IconView interface, you should implement it.
        
        '''
        # Draw background.
        if self.highlight_flag:                
            with cairo_disable_antialias(cr):
                cr.set_source_rgb(*color_hex_to_cairo(self.highlight_fill_color))
                cr.rectangle(rect.x + self.hover_offset, 
                             rect.y + self.hover_offset, 
                             rect.width - self.hover_offset * 2, 
                             rect.height - self.hover_offset * 2)
                cr.fill_preserve()
                cr.set_line_width(1)
                cr.set_source_rgb(*color_hex_to_cairo(self.highlight_stroke_color))
                cr.stroke()
        
        elif self.hover_flag:
            with cairo_disable_antialias(cr):
                cr.set_source_rgb(*color_hex_to_cairo(self.hover_fill_dcolor.get_color()))
                cr.rectangle(rect.x + self.hover_offset, 
                             rect.y + self.hover_offset, 
                             rect.width - self.hover_offset * 2, 
                             rect.height - self.hover_offset * 2)
                cr.fill_preserve()
                cr.set_line_width(1)
                cr.set_source_rgb(*color_hex_to_cairo(self.hover_stroke_dcolor.get_color()))
                cr.stroke()
                
        # Draw wallpapers.
        if self.pixbufs == []:
            wallpaper_paths = self.theme.get_wallpaper_paths()[:3]
            wallpaper_paths = wallpaper_paths[::-1]
            for wallpaper_file in wallpaper_paths:
                self.pixbufs.append(get_optimum_pixbuf_from_file(wallpaper_file, self.wallpaper_width, self.wallpaper_height))
                
        theme_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, rect.width, rect.height)   
        theme_surface_cr = gtk.gdk.CairoContext(cairo.Context(theme_surface))
        
        with cairo_state(theme_surface_cr):
            reflection_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 
                                                    self.wallpaper_width + self.wallpaper_frame_size * 2 + 2, 
                                                    self.reflection_height)
            
            reflection_surface_cr = gtk.gdk.CairoContext(cairo.Context(reflection_surface))
            wallpaper_x = self.wallpaper_offset_x
            wallpaper_y = self.wallpaper_offset_y
        
            for (index, pixbuf) in enumerate(self.pixbufs):
                wallpaper_draw_x = wallpaper_x - 3 * self.wallpaper_render_offset + \
                    (len(self.pixbufs) - index) * self.wallpaper_render_offset
                wallpaper_draw_y = wallpaper_y + 3 * self.wallpaper_render_offset - \
                    (len(self.pixbufs) - index) * self.wallpaper_render_offset
                
                self.render_wallpaper(theme_surface_cr, pixbuf, wallpaper_draw_x, wallpaper_draw_y)
                
                if index == len(self.pixbufs) - 1:
                    self.render_wallpaper(reflection_surface_cr, 
                                          pixbuf, 
                                          self.wallpaper_frame_size + 1, 
                                          self.wallpaper_frame_size + 1,
                                          True)
                    
                    i = 0
                    while (i <= self.reflection_height):
                        with cairo_state(theme_surface_cr):
                            theme_surface_cr.rectangle(
                                wallpaper_draw_x - self.wallpaper_frame_size - 1, 
                                wallpaper_draw_y + self.wallpaper_height + self.wallpaper_frame_size + i,
                                self.wallpaper_width + self.wallpaper_frame_size * 2 + 2,
                                1)
                            theme_surface_cr.clip()
                            theme_surface_cr.set_source_surface(
                                reflection_surface, 
                                wallpaper_draw_x - self.wallpaper_frame_size - 1, 
                                wallpaper_draw_y + self.wallpaper_frame_size + self.wallpaper_height
                                )
                            theme_surface_cr.paint_with_alpha(1.0 - (math.sin(i * math.pi / 2 / self.reflection_height)))
                        i += 1    
            
        # Paint wallpapers.
        cr.set_source_surface(theme_surface, rect.x, rect.y)                
        cr.paint()
        
        '''
        # Init window coordiante.
        window_frame_x = rect.x + self.window_frame_padding_x
        window_frame_y = rect.y + self.window_frame_padding_y
        
        # Paint gaussian area.
        gaussian_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.window_frame_width, self.window_frame_height)   
        gaussian_surface_cr = gtk.gdk.CairoContext(cairo.Context(gaussian_surface))
        gaussian_surface_cr.set_source_surface(theme_surface, -self.window_frame_padding_x, -self.window_frame_padding_y)
        gaussian_surface_cr.paint()
        dtk_cairo_blur.gaussian_blur(gaussian_surface, 3)
        cr.set_source_surface(gaussian_surface, window_frame_x, window_frame_y)
        cr.paint()

        # Draw window frame.
        cr.set_source_rgba(*alpha_color_hex_to_cairo((COLOR_NAME_DICT[self.theme.get_color()], 0.5)))
        cr.rectangle(window_frame_x + 1, window_frame_y, self.window_frame_width - 2, 1)
        cr.rectangle(window_frame_x, window_frame_y + 1, self.window_frame_width, self.window_frame_height - 2)
        cr.rectangle(window_frame_x + 1, window_frame_y + self.window_frame_height - 1, self.window_frame_width - 2, 1) 
        cr.fill()
        
        draw_window_frame(cr, window_frame_x, window_frame_y, self.window_frame_width, self.window_frame_height,
                          ui_theme.get_alpha_color("window_frame_outside_1"),
                          ui_theme.get_alpha_color("window_frame_outside_2"),
                          ui_theme.get_alpha_color("window_frame_outside_3"),
                          ui_theme.get_alpha_color("window_frame_inside_1"),
                          ui_theme.get_alpha_color("window_frame_inside_2"),
                          )
        '''

        draw_text(cr, 
                  self.name, 
                  rect.x, 
                  rect.y + self.window_frame_padding_y + self.window_frame_height + self.title_padding_y, 
                  rect.width,
                  DEFAULT_FONT_SIZE,
                  self.title_size,
                  alignment=pango.ALIGN_CENTER
                  )
    def render(self, cr, rect):
        # Draw icon.
        self.init_pkg_icon_pixbuf()

        draw_pixbuf(
            cr,
            self.pkg_icon_pixbuf,
            rect.x + self.DRAW_PADDING_LEFT + (ICON_SIZE - self.pkg_icon_width) / 2,
            rect.y + self.DRAW_PADDING_Y)    
        
        # Draw button.
        name = ""
        draw_str = ""
        if self.install_status == "uninstalled":
            name = "button/install_small"
        elif self.install_status == "unknown":
            draw_str = _("Not found")
        else:
            desktops = json.loads(self.install_status)
            if desktops:
                name = "button/start_small"
                self.desktops = self.data_manager.get_pkg_desktop_info(desktops)
            else:
                draw_str = _("Installed")

        if name:
            if self.button_status == BUTTON_NORMAL:
                status = "normal"
            elif self.button_status == BUTTON_HOVER:
                status = "hover"
            elif self.button_status == BUTTON_PRESS:
                status = "press"
                
            pixbuf = app_theme.get_pixbuf("%s_%s.png" % (name, status)).get_pixbuf()
            draw_pixbuf(
                cr,
                pixbuf,
                rect.x + self.DRAW_PADDING_LEFT,
                rect.y + self.DRAW_PADDING_Y + self.DRAW_ICON_SIZE + self.DRAW_BUTTON_PADDING_Y)
        else:
            str_width, str_height = get_content_size(draw_str, 10)
            draw_text(
                cr,
                draw_str,
                rect.x + self.DRAW_PADDING_LEFT,
                rect.y + self.DRAW_PADDING_Y + self.DRAW_ICON_SIZE + self.DRAW_BUTTON_PADDING_Y,
                rect.width,
                str_height,
                wrap_width=rect.width,
            )

        
        # Draw name.
        self.text_width = rect.width - self.DRAW_PADDING_LEFT - self.DRAW_PADDING_RIGHT - self.DRAW_INFO_PADDING_X - self.pkg_icon_width
        self.pkg_name_area.render(
            cr,
            self.alias_name,
            gtk.gdk.Rectangle(
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE + self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_PADDING_Y,
                self.text_width,
                NAME_SIZE))

        # Draw star.
        self.star_buffer.render(
            cr,
            gtk.gdk.Rectangle(
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE + self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_STAR_PADDING_Y,
                STAR_SIZE * 5,
                STAR_SIZE
                ))
        
        # Draw long desc.
        long_desc_height = 32
        if self.short_desc == None:
            self.short_desc = "FIX ME"
        with cairo_state(cr):
            cr.rectangle(
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE + self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_LONG_DESC_PADDING_Y,
                self.text_width,
                long_desc_height,
                )
            cr.clip()
            draw_text(
                cr,
                self.short_desc,
                rect.x + self.DRAW_PADDING_LEFT + ICON_SIZE + self.DRAW_INFO_PADDING_X,
                rect.y + self.DRAW_LONG_DESC_PADDING_Y,
                self.text_width,
                long_desc_height,
                wrap_width=self.text_width,
                )
 def draw_loading(self, cr, rect):
     with cairo_state(cr):
         cr.translate(rect.x + rect.width*0.5 , rect.y + rect.height * 0.5)
         cr.rotate(radians(60*self.position))
         cr.translate(-rect.width* 0.5, -rect.height * 0.5)
         draw_pixbuf(cr, self.loading_pixbuf.get_pixbuf(), 10, 7)
Example #18
0
 def draw_loading(self, cr, rect):
     with cairo_state(cr):
         cr.translate(rect.x + 18, rect.y + 15)
         cr.rotate(radians(self.position))
         cr.translate(-18, -15)
         draw_pixbuf(cr, self.loading_pixbuf.get_pixbuf(), 10, 7)
Example #19
0
def render_text(
    cr,
    markup,
    x,
    y,
    w,
    h,
    text_size=DEFAULT_FONT_SIZE,
    text_color="#000000",
    text_font=DEFAULT_FONT,
    alignment=pango.ALIGN_LEFT,
    wrap_width=None,
    underline=False,
    vertical_alignment=TEXT_ALIGN_MIDDLE,
    clip_line_count=None,
    ellipsize=pango.ELLIPSIZE_END,
):
    """
    Render text for function L{ I{draw_text} <draw_text>}, you can use this function individually.
    
    @param cr: Cairo context.
    @param markup: Pango markup string.
    @param x: X coordinate of draw area.
    @param y: Y coordinate of draw area.
    @param w: Width of draw area.
    @param h: Height of draw area.
    @param text_size: Text size, default is DEFAULT_FONT_SIZE.
    @param text_color: Text color, default is \"#000000\".
    @param text_font: Text font, default is DEFAULT_FONT.
    @param alignment: Font alignment option, default is pango.ALIGN_LEFT. You can set pango.ALIGN_MIDDLE or pango.ALIGN_RIGHT.
    @param wrap_width: Wrap width of text, default is None.
    @param underline: Whether draw underline for text, default is False.
    @param vertical_alignment: Vertical alignment value, default is TEXT_ALIGN_MIDDLE, can use below value:
     - TEXT_ALIGN_TOP
     - TEXT_ALIGN_MIDDLE
     - TEXT_ALIGN_BOTTOM
    @param clip_line_count: The line number to clip text area, if set 2, all lines that above 2 will clip out, default is None.
    @param ellipsize: Ellipsize style of text when text width longer than draw area, it can use below value:
     - pango.ELLIPSIZE_START
     - pango.ELLIPSIZE_CENTER
     - pango.ELLIPSIZE_END
    """
    with cairo_state(cr):
        # Set color.
        cr.set_source_rgb(*color_hex_to_cairo(text_color))

        # Create pangocairo context.
        context = pangocairo.CairoContext(cr)

        # Set layout.
        layout = context.create_layout()
        layout.set_font_description(pango.FontDescription("%s %s" % (text_font, text_size)))
        layout.set_markup(markup)
        layout.set_alignment(alignment)
        if wrap_width == None:
            layout.set_single_paragraph_mode(True)
            layout.set_width(w * pango.SCALE)
            layout.set_ellipsize(ellipsize)
        else:
            layout.set_width(wrap_width * pango.SCALE)
            layout.set_wrap(pango.WRAP_WORD)

        (text_width, text_height) = layout.get_pixel_size()

        if underline:
            if alignment == pango.ALIGN_LEFT:
                cr.rectangle(x, y + text_height + (h - text_height) / 2, text_width, 1)
            elif alignment == pango.ALIGN_CENTER:
                cr.rectangle(x + (w - text_width) / 2, y + text_height + (h - text_height) / 2, text_width, 1)
            else:
                cr.rectangle(x + w - text_width, y + text_height + (h - text_height) / 2, text_width, 1)
            cr.fill()

        # Set render y coordinate.
        if vertical_alignment == TEXT_ALIGN_TOP:
            render_y = y
        elif vertical_alignment == TEXT_ALIGN_MIDDLE:
            render_y = y + max(0, (h - text_height) / 2)
        else:
            render_y = y + max(0, h - text_height)

        # Clip area.
        if clip_line_count:
            line_count = layout.get_line_count()
            if line_count > 0:
                line_height = text_height / line_count
                cr.rectangle(x, render_y, text_width, line_height * clip_line_count)
                cr.clip()

        # Draw text.
        cr.move_to(x, render_y)
        context.update_layout(layout)
        context.show_layout(layout)