예제 #1
0
파일: group.py 프로젝트: netphi/deepin-ui
 def expose_button_item(self, widget, event):    
     
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     select_index = self.get_index()
     
     # Draw background
     if widget.state == gtk.STATE_NORMAL:
         if select_index == self.index:
             select_status = BUTTON_PRESS
         else:    
             select_status = BUTTON_NORMAL
             
     elif widget.state == gtk.STATE_PRELIGHT:        
         if select_index == self.index:
             select_status = BUTTON_PRESS
         else:    
             select_status = BUTTON_HOVER
             
     elif widget.state == gtk.STATE_ACTIVE:   
         select_status = BUTTON_PRESS
         
     if select_status == BUTTON_PRESS:    
         pixbuf = self.press_dpixbuf.get_pixbuf()
     elif select_status == BUTTON_NORMAL:    
         pixbuf = self.normal_dpixbuf.get_pixbuf()
     elif select_status == BUTTON_HOVER:    
         pixbuf = self.hover_dpixbuf.get_pixbuf()
         
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)    
     propagate_expose(widget, event)
     return True
예제 #2
0
파일: button.py 프로젝트: wlemuel/Petro-UI
    def expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(*color_hex_to_cairo(THEME['bg']))
        cr.rectangle(*rect)
        cr.fill()

        if self.changable:
            if widget.state == gtk.STATE_PRELIGHT:
                x_offset = rect.width
            elif widget.state == gtk.STATE_ACTIVE:
                x_offset = rect.width * 2
            elif self.show_state == "active":
                x_offset = rect.width * 2
            else:
                x_offset = 0
            pixbuf = self.image.scale_simple(rect.width * 3,
                                             rect.height,
                                             gtk.gdk.INTERP_BILINEAR)
            pixbuf = pixbuf.subpixbuf(x_offset,
                                      0,
                                      rect.width,
                                      rect.height)
        else:
            pixbuf = self.image.scale_simple(rect.width, rect.height,
                                             gtk.gdk.INTERP_BILINEAR)

        draw_pixbuf(cr, pixbuf, rect.x, rect.y)
        propagate_expose(widget, event)
        return True
예제 #3
0
 def render_name(self, cr, rect):
     '''
     Render icon and name of DirItem.
     '''
     # Draw select background.
     if self.is_select:
         draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height,
                      ui_theme.get_shadow_color("listview_select").get_color_info())
     
     # Init.
     expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_right.png").get_pixbuf()
     
     # Draw directory icon.
     draw_pixbuf(cr, self.pixbuf, 
                 rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT,
                 rect.y + (rect.height - ICON_SIZE) / 2,
                 )
     
     # Draw directory name.
     draw_text(cr, self.name, 
               rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT + ICON_SIZE + ICON_PADDING_RIGHT,
               rect.y,
               rect.width, rect.height)
     
     # Draw drag line.
     if self.drag_line:
         with cairo_disable_antialias(cr):
             cr.set_line_width(1)
             if self.drag_line_at_bottom:
                 cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
             else:
                 cr.rectangle(rect.x, rect.y, rect.width, 1)
             cr.fill()
 def __draw_left_line(self, widget, cr, x, y, w, h):
     # draw left line.
     if widget.get_state() in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
         draw_pixbuf(cr, 
                     self.left_line_pixbuf, 
                     x, 
                     y + h/2 - self.left_line_h/2)
예제 #5
0
    def expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(*color_hex_to_cairo(THEME['bg']))
        cr.rectangle(0, 0, rect.width, rect.height)
        cr.fill()

        pixbuf = gtk.gdk.pixbuf_new_from_file(self.image)

        image_size = [pixbuf.get_width(),
                      pixbuf.get_height()]
        self.real_size = self.get_real_size(
            [rect.width, rect.height], image_size
        )
        pixbuf = pixbuf.scale_simple(self.real_size[0],
                                     self.real_size[1],
                                     gtk.gdk.INTERP_HYPER)
        pixbuf = pixbuf.rotate_simple(self.rotate_type[self.rotate])

        offset_x = (rect.width - self.real_size[0]) / 2
        offset_y = (rect.height - self.real_size[1]) / 2
        draw_pixbuf(cr, pixbuf, offset_x, offset_y)

        propagate_expose(widget, event)
        return True
    def __paint_seek_button(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        #
        cr.set_source_rgb(*color_hex_to_cairo("#000000"))
        y_padding = 2
        x_padding = 2
        w_padding = 5
        h_padding = 2
        if self.type == "fseek":
            x_padding = 3

        cr.rectangle(rect.x - x_padding, 
                     rect.y - y_padding, 
                     rect.width + w_padding, 
                     rect.height + h_padding)
        cr.fill()
        if self.type == "fseek":
            pixbuf = self.f_normal_pixbuf.get_pixbuf()
        else:
            pixbuf = self.b_normal_pixbuf.get_pixbuf()
        if (widget.state == gtk.STATE_PRELIGHT or 
              widget.state == gtk.STATE_SELECTED or
              widget.state == gtk.STATE_ACTIVE):
            if self.get_sensitive(): # 
                if self.type == "fseek":
                    pixbuf = self.f_press_pixbuf.get_pixbuf()
                else:
                    pixbuf = self.b_press_pixbuf.get_pixbuf()
        ###########################################
        draw_pixbuf(cr, pixbuf, rect.x, rect.y + 1)
예제 #7
0
    def render(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()
        if isinstance(self.icon_normal_dpixbuf, gtk.gdk.Pixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf
        elif isinstance(self.icon_normal_dpixbuf, DynamicPixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf.get_pixbuf()

        if self.is_hover:
            # Draw background.
            draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height,
                         ui_theme.get_shadow_color("menu_item_select").get_color_info())

            # Set icon pixbuf.
            if isinstance(self.icon_hover_dpixbuf, gtk.gdk.Pixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf
            elif isinstance(self.icon_hover_dpixbuf, DynamicPixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf.get_pixbuf()

            # Set font color.
            font_color = ui_theme.get_color("menu_select_font").get_color()

        draw_pixbuf(cr, icon_pixbuf,
                    rect.x + self.padding_x,
                    rect.y + (rect.height - icon_pixbuf.get_height()) / 2)

        draw_text(cr,
                  self.text,
                  rect.x + self.padding_x * 2 + self.icon_width,
                  rect.y,
                  rect.width - self.padding_x * 2,
                  rect.height,
                  text_color=font_color)
예제 #8
0
    def render(self, cr, rect):
        """
        Render icon and name of DirItem.
        """
        # Draw select background.
        if self.is_button_press == True:
            draw_vlinear(
                cr,
                rect.x,
                rect.y,
                rect.width,
                rect.height,
                ui_theme.get_shadow_color("listview_select").get_color_info(),
            )

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

        # Draw directory name.
        draw_text(
            cr,
            self.name,
            rect.x,
            rect.y + self.icon_size + ITEM_PADDING_Y * 2,
            rect.width,
            DEFAULT_FONT_SIZE,
            DEFAULT_FONT_SIZE,
            alignment=pango.ALIGN_CENTER,
        )
예제 #9
0
    def render(self, cr, rect):
        '''
        Render icon and name of DirItem.
        '''
        # Draw select background.
        if self.is_button_press == True:
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("listview_select").get_color_info())

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

        # Draw directory name.
        draw_text(cr,
                  self.name,
                  rect.x,
                  rect.y + self.icon_size + ITEM_PADDING_Y * 2,
                  rect.width,
                  DEFAULT_FONT_SIZE,
                  DEFAULT_FONT_SIZE,
                  alignment=pango.ALIGN_CENTER)
예제 #10
0
    def render(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()
        if isinstance(self.icon_normal_dpixbuf, gtk.gdk.Pixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf
        elif isinstance(self.icon_normal_dpixbuf, DynamicPixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf.get_pixbuf()

        if self.is_hover:
            # Draw background.
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("menu_item_select").get_color_info())

            # Set icon pixbuf.
            if isinstance(self.icon_hover_dpixbuf, gtk.gdk.Pixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf
            elif isinstance(self.icon_hover_dpixbuf, DynamicPixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf.get_pixbuf()

            # Set font color.
            font_color = ui_theme.get_color("menu_select_font").get_color()

        draw_pixbuf(cr, icon_pixbuf, rect.x + self.padding_x,
                    rect.y + (rect.height - icon_pixbuf.get_height()) / 2)

        draw_text(cr,
                  self.text,
                  rect.x + self.padding_x * 2 + self.icon_width,
                  rect.y,
                  rect.width - self.padding_x * 2,
                  rect.height,
                  text_color=font_color)
 def __draw_right_line(self, widget, cr, x, y, w, h):
     # draw right line.
     if widget.get_state() in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
         draw_pixbuf(cr, 
                     self.right_lien_pixbuf, 
                     x + w - self.right_line_w, 
                     y + h/2 - self.right_lien_h/2)
예제 #12
0
 def render(self, cr, rect):
     '''
     Render item.
     
     This is IconView interface, you should implement it.
     '''
     # Draw cover border.
     border_size = 4
     
     if self.hover_flag:
         cr.set_source_rgb(1, 0, 0)
     elif self.highlight_flag:
         cr.set_source_rgb(0, 1, 0)
     else:
         cr.set_source_rgb(1, 1, 1)
     cr.rectangle(
         rect.x + (rect.width - self.image_width) / 2 - border_size,
         rect.y + (rect.height - self.image_height) / 2 - border_size,
         self.image_width + border_size * 2,
         self.image_height + border_size * 2)
     cr.fill()
     
     # Draw cover.
     if not self.pixbuf:
         self.pixbuf = gtk.gdk.pixbuf_new_from_file(self.pixbuf_path)
         
     draw_pixbuf(
         cr, 
         self.pixbuf, 
         rect.x + self.padding_x,
         rect.y + self.padding_y)
예제 #13
0
    def draw_point(self, cr, rect):
        pixbuf_w_average = self.point_pixbuf.get_pixbuf().get_width() / 2
        x = rect.x + self.point_width / 2 + int(float(self.value) / self.value_max * (rect.width - self.point_width)) - pixbuf_w_average

        draw_pixbuf(cr,
                    self.point_pixbuf.get_pixbuf(),
                    x,
                    rect.y + (rect.height-self.bottom_space)/2 - self.point_pixbuf.get_pixbuf().get_height()/2)
예제 #14
0
    def draw_point(self, cr, rect):
        pixbuf_w_average = self.point_pixbuf.get_pixbuf().get_width() / 2
        x = rect.x + self.point_width / 2 + int(float(self.value) / self.value_max * (rect.width - self.point_width)) - pixbuf_w_average

        draw_pixbuf(cr,
                    self.point_pixbuf.get_pixbuf(), 
                    x, 
                    rect.y + (rect.height-self.bottom_space)/2 - self.point_pixbuf.get_pixbuf().get_height()/2)
예제 #15
0
 def __treeview_paint_nodes_event(self, node_event):
     color = self.listview_color.get_color()
     text_color = "#FFFFFF"
     # 单击和移动, 双击.
     if node_event.node in node_event.single_items:
         color_info = [(0, (color, 0.45)), (1, (color, 0.45))] 
         draw_vlinear(node_event.cr,
                      node_event.x, node_event.y, node_event.w, node_event.h,
                      color_info
                      )
         #text_color = "#000000"
     elif node_event.node in node_event.motion_items:
         color_info = [(0, (color, 0.75)), (1, (color, 0.75))] 
         draw_vlinear(node_event.cr,
                      node_event.x, node_event.y, node_event.w, node_event.h,
                      color_info
                      )
     #
     x_padding = 12 # 因为要和搜索框对齐.
     if 0 == node_event.node.leave: # 根节点. :比如->> >我看过的. >优酷视频. >pps.
         if node_event.node.is_expanded:
             pixbuf = self.one_open.get_pixbuf()
         else:
             pixbuf = self.one_close.get_pixbuf()
     elif 1 == node_event.node.leave: # 
         if node_event.node.is_expanded:
             pixbuf = self.two_open.get_pixbuf()
         else:
             pixbuf = self.two_close.get_pixbuf()
     else:
         if node_event.node.is_expanded:
             pixbuf = self.three_open.get_pixbuf()
         else:
             pixbuf = self.three_close.get_pixbuf()
     #
     icon_x = node_event.x + x_padding
     icon_y = node_event.y + node_event.h/2 - pixbuf.get_height()/2 + 1
     if node_event.node.leave > 1:
         icon_x += (node_event.node.leave - 1) * pixbuf.get_width()
     if node_event.node.leave > 0:
         text_color = "#a8a8a8"
     ##########
     # 画图标.
     if node_event.node.nodes != []:
         draw_pixbuf(node_event.cr,
                     pixbuf,
                     icon_x,
                     icon_y) 
     # 画文本.
     text_x_padding = 15
     text_size = 9
     draw_text(node_event.cr, 
               node_event.node.text, 
               icon_x + text_x_padding,
               node_event.y + node_event.h/2 - get_text_size(node_event.node.text, text_size=9)[1]/2,
               text_color=text_color,
               text_size=text_size
               )
예제 #16
0
 def paint_clear_button(self, cr, rect, offset_y=0):
     if self.clear_check:
         pixbuf = self.clear_hover_pixbuf
     else:
         pixbuf = self.clear_normal_pixbuf
     #
     draw_pixbuf(cr, pixbuf, 
                 rect.x + rect.width + pixbuf.get_width()/2 + 4, 
                 rect.y + rect.height/2 - pixbuf.get_height()/2)
예제 #17
0
 def __on_draw_item_hd(self, e):
     #print "__on_draw_item_hd...", e.drag_rect
     e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#272727",1.0)))
     e.cr.rectangle(*e.rect)
     e.cr.fill()
     if e.drag_rect[0] != None:
         drag_pixbuf = app_theme.get_pixbuf("listview/drag_line.png").get_pixbuf()
         drag_pixbuf = drag_pixbuf.scale_simple(e.drag_rect[2], 5, gtk.gdk.INTERP_BILINEAR)
         draw_pixbuf(e.cr, drag_pixbuf, 0, e.drag_rect[0] * e.drag_rect[1])
예제 #18
0
파일: menu.py 프로젝트: netphi/deepin-ui
 def expose_menu_item(self, widget, event):
     '''Expose menu item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     font_color = ui_theme.get_color("menu_font").get_color()
     (item_icons, item_content, item_node) = self.item[0:3]
     
     # Draw select effect.
     if self.submenu_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
         # Draw background.
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                      ui_theme.get_shadow_color("menu_item_select").get_color_info(),
                      MENU_ITEM_RADIUS)
         
         # Set font color.
         font_color = ui_theme.get_color("menu_select_font").get_color()
         
     # Draw item icon.
     pixbuf = None
     pixbuf_width = 0
     if item_icons:
         (item_normal_dpixbuf, item_hover_dpixbuf) = item_icons
         if self.submenu_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
             if item_hover_dpixbuf == None:
                 pixbuf = item_normal_dpixbuf.get_pixbuf()
             else:
                 pixbuf = item_hover_dpixbuf.get_pixbuf()
         else:
             pixbuf = item_normal_dpixbuf.get_pixbuf()
         pixbuf_width += pixbuf.get_width()
         draw_pixbuf(cr, pixbuf, rect.x + self.item_padding_x, rect.y + (rect.height - pixbuf.get_height()) / 2)
         
     # Draw item content.
     draw_text(cr, item_content, 
                 rect.x + self.item_padding_x * 2 + self.icon_width,
                 rect.y,
                 rect.width,
                 rect.height,
                 self.font_size, font_color,
                 )
     
     # Draw submenu arrow.
     if isinstance(item_node, Menu):
         if self.submenu_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
             submenu_pixbuf = ui_theme.get_pixbuf("menu/arrow_hover.png").get_pixbuf()
         else:
             submenu_pixbuf = ui_theme.get_pixbuf("menu/arrow_normal.png").get_pixbuf()
         draw_pixbuf(cr, submenu_pixbuf,
                     rect.x + rect.width - self.item_padding_x - submenu_pixbuf.get_width() - self.arrow_padding_x,
                     rect.y + (rect.height - submenu_pixbuf.get_height()) / 2)
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
예제 #19
0
    def __expose_text_entry(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        draw_pixbuf(cr, self.search_bg_pixbuf, rect.x, rect.y)
        
        propagate_expose(widget, event)
        
        return True
 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)
예제 #21
0
 def expose_category_item(self, widget, event):
     '''Expose navigate item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     select_index = self.get_index()
     font_color = ui_theme.get_color("category_item").get_color()
     
     # Draw background.
     if widget.state == gtk.STATE_NORMAL:
         if select_index == self.index:
             select_status = BUTTON_PRESS
         else:
             select_status = BUTTON_NORMAL
     elif widget.state == gtk.STATE_PRELIGHT:
         if select_index == self.index:
             select_status = BUTTON_PRESS
         else:
             select_status = BUTTON_HOVER
     elif widget.state == gtk.STATE_ACTIVE:
         select_status = BUTTON_PRESS
         
     if select_status == BUTTON_PRESS:
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                     ui_theme.get_shadow_color("category_item_press").get_color_info())
 
         font_color = ui_theme.get_color("category_select_item").get_color()
     elif select_status == BUTTON_HOVER:
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                     ui_theme.get_shadow_color("category_item_hover").get_color_info())
         
         font_color = ui_theme.get_color("category_select_item").get_color()
         
     # Draw navigate item.
     category_item_pixbuf = self.icon_dpixbuf.get_pixbuf()
     draw_pixbuf(
         cr, category_item_pixbuf, 
         rect.x + self.padding_left,
         rect.y + (rect.height - category_item_pixbuf.get_height()) / 2
         )
     
     # Draw font.
     draw_text(cr, self.content, 
                 rect.x + self.padding_left + self.font_offset,
                 rect.y,
                 rect.width - self.padding_left - self.font_offset - self.padding_right,
                 rect.height,
                 self.font_size, 
                 font_color,
                 )
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
예제 #22
0
 def __ok_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     #
     if widget.state:
         pixbuf = self.search_normal_pixbuf
     else:
     #elif widget.state:
         pixbuf = self.search_hover_pixbuf
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)
     return True
예제 #23
0
 def __popup_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     if widget.state == gtk.STATE_NORMAL:
         pixbuf = self.right_normal_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_PRELIGHT:
         pixbuf = self.right_hover_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_ACTIVE:
         pixbuf = self.right_press_pixbuf.get_pixbuf()
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)
     return True
예제 #24
0
 def __popup_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     if widget.state == gtk.STATE_NORMAL:
         pixbuf = self.right_normal_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_PRELIGHT:
         pixbuf = self.right_hover_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_ACTIVE:
         pixbuf = self.right_press_pixbuf.get_pixbuf()
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)
     return True
예제 #25
0
 def __on_draw_item_fg(self, cr, rect):
     top_pixbuf = app_theme.get_pixbuf("playlist/list_top.png").get_pixbuf()
     bottom_pixbuf = app_theme.get_pixbuf("playlist/list_bottom.png").get_pixbuf()
     #
     scroll_win = get_match_parent(self, "ScrolledWindow")
     vadjust = scroll_win.get_vadjustment()
     if vadjust.get_value() != vadjust.get_lower():
         draw_pixbuf(cr, top_pixbuf, 0, vadjust.get_value() - 1)
     if vadjust.get_value() + vadjust.get_page_size() != vadjust.get_upper():
         y = vadjust.get_value() + vadjust.get_page_size() - bottom_pixbuf.get_height()
         draw_pixbuf(cr, bottom_pixbuf, 0, y)
예제 #26
0
 def add_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     self.paint_bg(cr, rect)
     x = rect.x + rect.width/2 - self.add_pixbuf.get_width()/2
     y = rect.y + rect.height/2  - self.add_pixbuf.get_height()/2
     if widget.state == gtk.STATE_ACTIVE:
         x += 1
         y += 1
     draw_pixbuf(cr, self.add_pixbuf, x, y)
     return True
예제 #27
0
    def render(self, cr, rect):
        """
        Render star buffer on given cairo and rectangle.

        @param cr: The cairo object.
        @param rect: The render rectangle.
        """
        for (star_index, star_pixbuf) in enumerate(self.get_star_pixbufs()):
            draw_pixbuf(
                cr, star_pixbuf, rect.x + star_index * STAR_SIZE, rect.y + (rect.height - star_pixbuf.get_height()) / 2
            )
 def add_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     self.paint_bg(cr, rect)
     x = rect.x + rect.width / 2 - self.add_pixbuf.get_width() / 2
     y = rect.y + rect.height / 2 - self.add_pixbuf.get_height() / 2
     if widget.state == gtk.STATE_ACTIVE:
         x += 1
         y += 1
     draw_pixbuf(cr, self.add_pixbuf, x, y)
     return True
예제 #29
0
 def __on_draw_item_hd(self, e):
     #print "__on_draw_item_hd...", e.drag_rect
     e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#272727", 1.0)))
     e.cr.rectangle(*e.rect)
     e.cr.fill()
     if e.drag_rect[0] != None:
         drag_pixbuf = app_theme.get_pixbuf(
             "listview/drag_line.png").get_pixbuf()
         drag_pixbuf = drag_pixbuf.scale_simple(e.drag_rect[2], 5,
                                                gtk.gdk.INTERP_BILINEAR)
         draw_pixbuf(e.cr, drag_pixbuf, 0, e.drag_rect[0] * e.drag_rect[1])
예제 #30
0
    def expose_cycle_strip(self, widget, event):
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation

        background_pixbuf = self.background_dpixbuf.get_pixbuf()

        self.cache_pixbuf.scale(background_pixbuf, rect.width, rect.height)

        draw_pixbuf(cr, self.cache_pixbuf.get_cache(), rect.x, rect.y)

        return False
예제 #31
0
    def expose_cycle_strip(self, widget, event):
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation

        background_pixbuf = self.background_dpixbuf.get_pixbuf()

        self.cache_pixbuf.scale(background_pixbuf, rect.width, rect.height)

        draw_pixbuf(cr, self.cache_pixbuf.get_cache(), rect.x, rect.y)

        return False
    def __treeview_paint_nodes_event(self, node_event):
        leave_width = 20
        color = self.listview_color.get_color()
        text_color = "#FFFFFF"
        #
        if node_event.node in node_event.single_items:
            color_info = [(0, (color, 0.45)), (1, (color, 0.45))] 
            draw_vlinear(node_event.cr,
                         node_event.x, node_event.y, node_event.w, node_event.h,
                         color_info
                         )
            text_color = "#000000"
        elif node_event.node in node_event.motion_items:
            color_info = [(0, (color, 0.75)), (1, (color, 0.75))] 
            draw_vlinear(node_event.cr,
                         node_event.x, node_event.y, node_event.w, node_event.h,
                         color_info
                         )
        #
        if node_event.node.leave == 1: # 根节点.
            x = node_event.x + 20
            # 画root的图标.
            if node_event.node.is_expanded:
                pixbuf = self.tree_view_close.get_pixbuf()
            else:
                pixbuf = self.tree_view_open.get_pixbuf()
            # node_event.x + 5 是图标与文字之间的宽度.
            draw_pixbuf(node_event.cr,
                        pixbuf,
                        node_event.x + 5,
                        node_event.y + node_event.h/2 - pixbuf.get_height()/2 )
        else:
            #x_padding = node_event.node.leave * leave_width
            #x = node_event.x + 18 + x_padding
            x = node_event.x + 20
            #
            if node_event.node.is_expanded:
                pixbuf = self.tree_view_bottom.get_pixbuf()
            else:
                pixbuf = self.tree_view_right.get_pixbuf()
            icon_x = node_event.x + pixbuf.get_width()/2
            icon_y = node_event.y + node_event.h/2 - pixbuf.get_height()/2

            if node_event.node.nodes or node_event.node.leave == 2:
                draw_pixbuf(node_event.cr, pixbuf, icon_x, icon_y)
        #
        draw_text(node_event.cr, 
                  node_event.node.text, 
                  x + 5,
                  node_event.y + node_event.h/2 - get_text_size(node_event.node.text, text_size=9)[1]/2,
                  text_color=text_color,
                  text_size=9
                  )
예제 #33
0
파일: image.py 프로젝트: wlemuel/Petro-UI
    def expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        size = min(rect. width, rect.height)

        pixbuf = self.image.scale_simple(size, size,
                                         gtk.gdk.INTERP_BILINEAR)
        draw_pixbuf(cr, pixbuf,
                    rect.x + (rect.width - size) / 2,
                    rect.y + (rect.height - size) / 2)
        propagate_expose(widget, event)
        return True
예제 #34
0
    def render(self, cr, rect):
        '''
        Render star buffer on given cairo and rectangle.

        @param cr: The cairo object.
        @param rect: The render rectangle.
        '''
        for (star_index, star_pixbuf) in enumerate(self.get_star_pixbufs()):
            draw_pixbuf(cr,
                        star_pixbuf,
                        rect.x + star_index * STAR_SIZE,
                        rect.y + (rect.height - star_pixbuf.get_height()) / 2,
                        )
 def __treeview_paint_nodes_event(self, node_event):
     color = self.listview_color.get_color()
     text_color = "#FFFFFF"
     # 单击和移动, 双击.
     if node_event.node in node_event.single_items:
         color_info = [(0, (color, 0.45)), (1, (color, 0.45))]
         draw_vlinear(node_event.cr, node_event.x, node_event.y,
                      node_event.w, node_event.h, color_info)
         #text_color = "#000000"
     elif node_event.node in node_event.motion_items:
         color_info = [(0, (color, 0.75)), (1, (color, 0.75))]
         draw_vlinear(node_event.cr, node_event.x, node_event.y,
                      node_event.w, node_event.h, color_info)
     #
     x_padding = 12  # 因为要和搜索框对齐.
     if 0 == node_event.node.leave:  # 根节点. :比如->> >我看过的. >优酷视频. >pps.
         if node_event.node.is_expanded:
             pixbuf = self.one_open.get_pixbuf()
         else:
             pixbuf = self.one_close.get_pixbuf()
     elif 1 == node_event.node.leave:  #
         if node_event.node.is_expanded:
             pixbuf = self.two_open.get_pixbuf()
         else:
             pixbuf = self.two_close.get_pixbuf()
     else:
         if node_event.node.is_expanded:
             pixbuf = self.three_open.get_pixbuf()
         else:
             pixbuf = self.three_close.get_pixbuf()
     #
     icon_x = node_event.x + x_padding
     icon_y = node_event.y + node_event.h / 2 - pixbuf.get_height() / 2 + 1
     if node_event.node.leave > 1:
         icon_x += (node_event.node.leave - 1) * pixbuf.get_width()
     if node_event.node.leave > 0:
         text_color = "#a8a8a8"
     ##########
     # 画图标.
     if node_event.node.nodes != []:
         draw_pixbuf(node_event.cr, pixbuf, icon_x, icon_y)
     # 画文本.
     text_x_padding = 15
     text_size = 9
     draw_text(node_event.cr,
               node_event.node.text,
               icon_x + text_x_padding,
               node_event.y + node_event.h / 2 -
               get_text_size(node_event.node.text, text_size=9)[1] / 2,
               text_color=text_color,
               text_size=text_size)
예제 #36
0
 def __on_draw_item_fg(self, cr, rect):
     top_pixbuf = app_theme.get_pixbuf("playlist/list_top.png").get_pixbuf()
     bottom_pixbuf = app_theme.get_pixbuf(
         "playlist/list_bottom.png").get_pixbuf()
     #
     scroll_win = get_match_parent(self, "ScrolledWindow")
     vadjust = scroll_win.get_vadjustment()
     if vadjust.get_value() != vadjust.get_lower():
         draw_pixbuf(cr, top_pixbuf, 0, vadjust.get_value() - 1)
     if vadjust.get_value() + vadjust.get_page_size() != vadjust.get_upper(
     ):
         y = vadjust.get_value() + vadjust.get_page_size(
         ) - bottom_pixbuf.get_height()
         draw_pixbuf(cr, bottom_pixbuf, 0, y)
예제 #37
0
    def __expose(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y = rect.x, rect.y
        x -= self.padding_left
        y -= self.padding_top * 2

        with cairo_state(cr):
            cr.set_source_rgb(*color_hex_to_cairo("#FFFFFF"))
            cr.rectangle(x,
                         y,
                         rect.width,
                         rect.height + self.padding_top)
            cr.fill()

            if self.width < self.__const_width or self.height < self.__const_height:
                self.cache_bg_pixbuf.scale(self.bg_pixbuf.get_pixbuf(),
                                           self.width,
                                           self.height)
                self.cache_timezone_pixbuf.scale(self.timezone_pixbuf[self.__timezone].get_pixbuf(),
                                                 self.width,
                                                 self.height)

                draw_pixbuf(cr, self.cache_bg_pixbuf.get_cache(), x, y)
                draw_pixbuf(cr, self.cache_timezone_pixbuf.get_cache(), x, y)
            else:
                draw_pixbuf(cr, self.bg_pixbuf.get_pixbuf(), x, y)
                draw_pixbuf(cr,
                            self.timezone_pixbuf[self.__timezone].get_pixbuf(),
                            x,
                            y)

        return True
예제 #38
0
 def __paint_progressbar(self, cr, rect):
     # 画黑色背景.
     cr.set_source_rgb(*color_hex_to_cairo("#000000"))
     cr.rectangle(*rect)
     cr.fill()
     # 画背景. draw background.
     bg_w = self.allocation.width
     bg_h = self.drag_pixbuf_height - 4 # 4(上下各留一像素,该死的设计师.)
     bg_x = rect.x
     bg_y = rect.y + rect.height/2 - bg_h/2
     bg_pixbuf = self.bg_pixbuf.scale_simple(
                     bg_w,
                     bg_h,
                     gtk.gdk.INTERP_BILINEAR
                     )
     draw_pixbuf(cr, bg_pixbuf, bg_x, bg_y)
     ################################
     if self.get_sensitive(): # 
         if self.max_value:
             d_value = float(rect.width) / self.max_value # 差值.
             # 画前景, 进度效果.
             fg_w = min(int(self.pos * d_value), int(self.max_value * d_value))
             fg_h = self.drag_pixbuf_height - 4 
             fg_x = rect.x
             fg_y = rect.y + rect.height/2 - fg_h/2
             fg_color = self.color.get_color()
             fg_color_info = [(0.1, (fg_color, 1.0)),
                              (0.75, (fg_color, 1.0)),
                              (1.0, (fg_color, 0.85))]
             #
             pat = cairo.LinearGradient(0, 0, fg_w, 0)
             pat.add_color_stop_rgb(0.7, *color_hex_to_cairo(self.fg_left_color.get_color()))
             pat.add_color_stop_rgb(1.0, *color_hex_to_cairo(self.fg_right_color.get_color()))
             #draw_hlinear(cr, fg_x, fg_y, fg_w, fg_h, fg_color_info)
             cr.set_operator(cairo.OPERATOR_OVER)
             cr.set_source(pat)
             cr.rectangle(fg_x, fg_y, fg_w, fg_h)
             cr.fill()
             # 画拖动的点.
             if self.drag_show_check: # 是否显示拖动的点.
                 drag_value = int(self.pos * d_value) + self.drag_pixbuf_width/2 - 4
                 max_drag_value = int(self.max_value * d_value) - 2
                 min_drag_value = rect.x - 1
                 # 防止拖动的点跑出可视区域.
                 drag_x = max(min(drag_value, max_drag_value), min_drag_value)
                 drag_y = rect.y + rect.height/2 - self.drag_pixbuf_height/2
                 draw_pixbuf(cr, 
                             self.drag_pixbuf, 
                             drag_x, 
                             drag_y)
예제 #39
0
파일: paned.py 프로젝트: masums/deepin-ui
    def draw_handle(self, e):
        '''
        Draw the cusom handle apperance.
        '''
        handle = self.get_handle_window()
        line_width = 1
        cr = handle.cairo_create()
        cr.set_source_rgb(*color_hex_to_cairo(self.handle_color.get_color()))
        (width, height) = handle.get_size()
        if self.get_orientation() == gtk.ORIENTATION_HORIZONTAL:
            if self.shrink_first:
                if self.get_position() != 0:
                    cr.rectangle(0, 0, line_width, height)
                    cr.fill()

                if self.always_show_button or self.show_button:
                    if self.get_position() == 0:
                        pixbuf = ui_theme.get_pixbuf(
                            "paned/paned_right_normal.png").get_pixbuf()
                    else:
                        pixbuf = ui_theme.get_pixbuf(
                            "paned/paned_left_normal.png").get_pixbuf()
                    draw_pixbuf(cr, pixbuf, 0, (height - self.bheight) / 2)
            else:
                cr.rectangle(width - line_width, 0, line_width, height)
                cr.fill()

                if self.always_show_button or self.show_button:
                    if self.get_position() == 0:
                        pixbuf = ui_theme.get_pixbuf(
                            "paned/paned_left_normal.png").get_pixbuf()
                    else:
                        pixbuf = ui_theme.get_pixbuf(
                            "paned/paned_right_normal.png").get_pixbuf()
                    draw_pixbuf(cr, pixbuf, 0, (height - self.bheight) / 2)
        else:
            if self.shrink_first:
                cr.rectangle(0, 0, width, line_width)
                cr.fill()

                if self.always_show_button or self.show_button:
                    if self.get_position() == 0:
                        pixbuf = ui_theme.get_pixbuf(
                            "paned/paned_down_normal.png").get_pixbuf()
                    else:
                        pixbuf = ui_theme.get_pixbuf(
                            "paned/paned_up_normal.png").get_pixbuf()
                    draw_pixbuf(cr, pixbuf, (width - self.bheight) / 2, 0)
            else:
                cr.rectangle(0, height - line_width, width, line_width)
                cr.fill()

                if self.always_show_button or self.show_button:
                    if self.get_position() == 0:
                        pixbuf = ui_theme.get_pixbuf(
                            "paned/paned_up_normal.png").get_pixbuf()
                    else:
                        pixbuf = ui_theme.get_pixbuf(
                            "paned/paned_down_normal.png").get_pixbuf()
                    draw_pixbuf(cr, pixbuf, (width - self.bheight) / 2, 0)
예제 #40
0
파일: box.py 프로젝트: netphi/deepin-ui
 def expose_image_box(self, widget, event):
     '''Expose image box.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     pixbuf = self.image_dpixbuf.get_pixbuf()
     
     # Draw.
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)
     
     # Propagate expose.
     propagate_expose(widget, event)
 
     return True
예제 #41
0
    def image_button_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        if widget.state == gtk.STATE_NORMAL:
            image = self.normal_image_pixbuf
        elif widget.state == gtk.STATE_PRELIGHT:
            image = self.hover_image_pixbuf
        elif widget.state == gtk.STATE_ACTIVE:
            image = self.press_image_pixbuf

        draw_pixbuf(cr, image, rect.x, rect.y)

        propagate_expose(widget, event)
        return True
예제 #42
0
파일: slider.py 프로젝트: masums/deepin-ui
    def on_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        cr.save()
        draw_pixbuf(cr, self.slider_pixbufs[self.active_index],
                    rect.x + self.active_x, rect.x + self.slider_y,
                    self.active_alpha)

        if self.target_index != None and self.target_x != None:
            draw_pixbuf(cr, self.slider_pixbufs[self.target_index],
                        rect.x + self.target_x, rect.y + self.slider_y,
                        self.target_alpha)
        cr.restore()

        # Draw select pointer.
        dot_start_x = rect.x + self.dot_start_x

        for index in range(self.slider_numuber):
            if self.target_index == None:
                if self.active_index == index:
                    dot_pixbuf = self.dot_active_pixbuf
                else:
                    dot_pixbuf = self.dot_normal_pixbuf
            else:
                if self.target_index == index:
                    dot_pixbuf = self.dot_active_pixbuf
                else:
                    dot_pixbuf = self.dot_normal_pixbuf

            pointer_rect = gtk.gdk.Rectangle(dot_start_x, rect.y + self.dot_y,
                                             self.dot_width, self.dot_height)
            self.pointer_coords[index] = pointer_rect
            draw_pixbuf(cr, dot_pixbuf, dot_start_x, rect.y + self.dot_y)
            dot_start_x += self.dot_width_offset

        # Draw close pixbuf.
        draw_pixbuf(cr, self.close_dpixbuf.get_pixbuf(),
                    rect.x + self.close_rect.x, rect.y + self.close_rect.y)

        if self.show_button and self.target_index == self.slider_numuber - 1:
            if self.button_hover_flag:
                pixbuf = self.button_press_pixbuf
            else:
                pixbuf = self.button_normal_pixbuf
            draw_pixbuf(cr, pixbuf, rect.x + self.button_rect.x,
                        rect.y + self.button_rect.y)
        return True
예제 #43
0
    def mute_btn_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        #
        if widget.state == gtk.STATE_NORMAL:
            pixbuf = self.get_normal_pixbuf()
        elif widget.state == gtk.STATE_PRELIGHT:
            pixbuf = self.get_hover_pixbuf()
        elif widget.state == gtk.STATE_ACTIVE:
            pixbuf = self.get_press_pixbuf()

        pixbuf_w, pixbuf_h = pixbuf.get_width(), pixbuf.get_height()
        draw_pixbuf(cr, pixbuf, rect.x + rect.width / 2 - pixbuf_w / 2,
                    rect.y + rect.height / 2 - pixbuf_h / 2)

        return True
예제 #44
0
    def __draw_volume_left(self, widget, event):
        cr = widget.window.cairo_create()
        x, y, w, h = widget.allocation

        if self.__volume_state == MUTE_STATE:  # mute state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__mute_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__mute_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__mute_volume_press_pixbuf
        elif self.__volume_state == ZERO_STATE:  # zero state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__zero_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__zero_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__zero_volume_press_pixbuf
        elif self.__volume_state == MIN_STATE:  # min state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__min_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__min_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__min_volume_press_pixbuf
        elif self.__volume_state == MID_STATE:  # mid state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__mid_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__mid_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__mid_volume_press_pixbuf
        elif self.__volume_state == MAX_STATE:  # max state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__max_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__max_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__max_volume_press_pixbuf

        draw_pixbuf(
            cr,
            pixbuf.get_pixbuf(),
            x + self.__volume_left_x,
            y + self.__volume_left_y,
        )
예제 #45
0
 def __select_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     if widget.state == gtk.STATE_NORMAL:
         pixbuf = self.left_normal_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_PRELIGHT:
         pixbuf = self.left_hover_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_ACTIVE:
         pixbuf = self.left_press_pixbuf.get_pixbuf()
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)
     text_size = get_text_size(widget.get_label(), text_size=9)
     draw_text(cr,
               widget.get_label(),
               rect.x + rect.width / 2 - text_size[0] / 2 + 5,
               rect.y + rect.height / 2 - text_size[1] / 2,
               text_size=10)
     #
     return True
예제 #46
0
    def expose_image_box(self, widget, event):
        '''
        Callback for `expose-event` signal.

        @param widget: Gtk.Widget instance.
        @param event: Expose event.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        pixbuf = self.image_dpixbuf.get_pixbuf()

        # Draw.
        draw_pixbuf(cr, pixbuf, rect.x, rect.y)

        # Propagate expose.
        propagate_expose(widget, event)

        return True
예제 #47
0
    def render_name(self, cr, rect):
        '''
        Render icon and name of DirItem.
        '''
        if self.pixbuf == None:
            self.pixbuf = get_file_icon_pixbuf(self.directory_path, ICON_SIZE)

        # Draw select background.
        if self.is_select or self.is_highlight:
            draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height,
                         ui_theme.get_shadow_color("listview_select").get_color_info())

        # Draw directory arrow icon.
        if self.is_expand:
            expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_down.png").get_pixbuf()
        else:
            expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_right.png").get_pixbuf()
        draw_pixbuf(cr, expand_indicator_pixbuf,
                    rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT,
                    rect.y + (rect.height - expand_indicator_pixbuf.get_height()) / 2,
                    )

        # Draw directory icon.
        draw_pixbuf(cr, self.pixbuf,
                    rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT,
                    rect.y + (rect.height - ICON_SIZE) / 2,
                    )

        # Draw directory name.
        draw_text(cr, self.name,
                  rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT + ICON_SIZE + ICON_PADDING_RIGHT,
                  rect.y,
                  rect.width, rect.height)

        # Draw drag line.
        if self.drag_line:
            with cairo_disable_antialias(cr):
                cr.set_line_width(1)
                if self.drag_line_at_bottom:
                    cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
                else:
                    cr.rectangle(rect.x, rect.y, rect.width, 1)
                cr.fill()
예제 #48
0
 def test_paint_nodes_event(e):
     if e.node.leave == 0:  # 根节点.
         draw_text(e.cr, e.node.text,
                   e.x + e.w / 2 - get_text_size(e.node.text)[0] / 2,
                   e.y + e.h / 2 - get_text_size(e.node.text)[1] / 2)
         e.cr.set_source_rgba(1, 1, 1, 1.0)
         e.cr.rectangle(e.x, e.y, e.w, e.h)
         e.cr.stroke()
     else:
         pixbuf = gtk.gdk.pixbuf_new_from_file("logo.png")
         pixbuf = pixbuf.scale_simple(e.h, e.h, gtk.gdk.INTERP_BILINEAR)
         draw_pixbuf(
             e.cr, pixbuf, e.x + e.w / 2 - pixbuf.get_width() / 2 +
             (e.node.leave - 1) * e.h, e.y)
         draw_text(
             e.cr, e.node.text,
             e.x + e.w / 2 - get_text_size(e.node.text)[1] / 2 +
             pixbuf.get_width() + e.node.leave * e.h,
             e.y + e.h / 2 - get_text_size(e.node.text)[1] / 2)
예제 #49
0
    def color_test_widget_expose(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # Draw pixbuf.
        draw_pixbuf(cr, self.pixbuf, 0, 0)

        # Draw mask.
        draw_vlinear(cr, rect.x,
                     rect.y + self.pixbuf.get_height() - SHADOW_SIZE,
                     rect.width, SHADOW_SIZE,
                     [(0, (self.background_color, 0)),
                      (1, (self.background_color, 1))])

        draw_hlinear(cr, rect.x + self.pixbuf.get_width() - SHADOW_SIZE,
                     rect.y, SHADOW_SIZE, rect.height,
                     [(0, (self.background_color, 0)),
                      (1, (self.background_color, 1))])

        # Draw background.
        (similar_color_name,
         similar_color_value) = find_similar_color(self.background_color)
        print(similar_color_name, self.background_color, similar_color_value)
        cr.set_source_rgb(*color_hex_to_cairo(similar_color_value))
        cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y,
                     rect.width - self.pixbuf.get_width(), rect.height)
        cr.fill()
        cr.set_source_rgb(*color_hex_to_cairo(self.background_color))
        cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), rect.width,
                     rect.height - self.pixbuf.get_height())
        cr.fill()

        # cr.set_source_rgb(*color_hex_to_cairo(self.background_color))
        # cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y,
        #              rect.width - self.pixbuf.get_width(), rect.height)
        # cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(),
        #              rect.width, rect.height - self.pixbuf.get_height())

        # cr.fill()

        propagate_expose(widget, event)

        return True
예제 #50
0
파일: group.py 프로젝트: masums/deepin-ui
    def expose_toggle_button_item(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        select_index = self.get_index()

        if widget.state == gtk.STATE_NORMAL:
            if select_index == self.index:
                self.set_index(-1)
            pixbuf = self.inactive_dpixbuf.get_pixbuf()
        elif widget.state == gtk.STATE_PRELIGHT:
            if not self.inactive_hover_dpixbuf and not self.active_hover_dpixbuf:
                if widget.get_active():
                    pixbuf = self.active_dpixbuf.get_pixbuf()
                else:
                    pixbuf = self.inactive_dpixbuf.get_pixbuf()
            else:
                if self.inactive_hover_dpixbuf and self.active_hover_dpixbuf:
                    if widget.get_active():
                        pixbuf = self.active_hover_dpixbuf.get_pixbuf()
                    else:
                        pixbuf = self.inactive_hover_dpixbuf.get_pixbuf()
                elif self.inactive_hover_dpixbuf:
                    pixbuf = self.inactive_hover_dpixbuf.get_pixbuf()
                elif self.active_hover_dpixbuf:
                    pixbuf = self.active_hover_dpixbuf.get_pixbuf()

        elif widget.state == gtk.STATE_ACTIVE:
            if select_index == self.index:
                pixbuf = self.active_dpixbuf.get_pixbuf()
            else:
                widget.set_active(False)
                pixbuf = self.inactive_dpixbuf.get_pixbuf()

        draw_pixbuf(cr, pixbuf, rect.x, rect.y)
        propagate_expose(widget, event)
        return True
예제 #51
0
 def __expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     # 画背景.
     bg_pixbuf = self.bg.get_pixbuf().scale_simple(rect.width, rect.height,
                                                   gtk.gdk.INTERP_BILINEAR)
     x = rect.x
     y = rect.y
     draw_pixbuf(cr, bg_pixbuf, x, y)
     #
     if None != self.__index:
         cr.set_source_rgba(1, 1, 1, 0.1)
         cr.rectangle(x + 2, y + self.__index * self.__menu_height + 2,
                      rect.width - 4, self.__menu_height - 4)
         cr.fill()
     #
     index = 0
     for item in self.menu_items:
         pixbuf, text = item.pixbuf, item.text
         if pixbuf:
             draw_pixbuf(
                 cr, pixbuf, x + 8, y + index * self.__menu_height +
                 self.__menu_height / 2 - pixbuf.get_height() / 2)
         draw_text(
             cr, text, x + 35, y + index * self.__menu_height +
             self.__menu_height / 2 - get_text_size(text)[1] / 2)
         if item.child_menus:
             pixbuf = app_theme.get_pixbuf(
                 "screen_mid/menu_child.png").get_pixbuf()
             draw_pixbuf(
                 cr, pixbuf, x + rect.width - 10,
                 y + index * self.__menu_height + self.__menu_height / 2 -
                 pixbuf.get_height() / 2)
         index += 1
예제 #52
0
    def __draw_volume_right(self, widget, event):
        cr = widget.window.cairo_create()
        cr.set_line_width(self.__line_height)
        x, y, w, h = widget.allocation

        fg_height_average = (
            self.__point_volume_pixbuf.get_pixbuf().get_height() -
            self.__fg_pixbuf.get_pixbuf().get_height()) / 2
        bg_height_average = (
            self.__point_volume_pixbuf.get_pixbuf().get_height() -
            self.__bg_pixbuf.get_pixbuf().get_height()) / 2
        point_width_average = self.__point_volume_pixbuf.get_pixbuf(
        ).get_width() / 2
        ##################################################
        # Draw bg.
        if self.__volume_width > 0:
            self.__bg_cache_pixbuf.scale(
                self.__bg_pixbuf.get_pixbuf(),
                self.__volume_width,
                self.__bg_pixbuf.get_pixbuf().get_height(),
            )
            draw_pixbuf(cr, self.__bg_cache_pixbuf.get_cache(),
                        x + self.__bg_x + self.__bg_padding_x,
                        y + self.__bg_y + bg_height_average)

        temp_fg_padding_x = self.__point_padding_x - (self.__fg_x +
                                                      self.__fg_padding_x)

        if temp_fg_padding_x < 0:
            temp_fg_padding_x = 0
        if temp_fg_padding_x > self.__volume_width:
            temp_fg_padding_x = self.__volume_width
        # Get current value.
        self.__current_value = temp_fg_padding_x * (
            float(self.__volume_max_value) / self.__volume_width)

        # Draw fg.
        if temp_fg_padding_x > 0:
            self.__fg_cache_pixbuf.scale(
                self.__fg_pixbuf.get_pixbuf(),
                int(temp_fg_padding_x),
                self.__fg_pixbuf.get_pixbuf().get_height(),
            )
            draw_pixbuf(cr, self.__fg_cache_pixbuf.get_cache(),
                        x + self.__fg_x + self.__fg_padding_x,
                        y + self.__fg_y + fg_height_average)
        #################################################
        # Draw point.
        temp_point_padding_x = (self.__point_padding_x - point_width_average)

        temp_min = (self.__volume_right_x - point_width_average)
        temp_max = (self.__volume_right_x + self.__volume_width -
                    point_width_average)
        if temp_point_padding_x < temp_min:
            temp_point_padding_x = temp_min
        if temp_point_padding_x > temp_max:
            temp_point_padding_x = temp_max

        draw_pixbuf(cr, self.__point_volume_pixbuf.get_pixbuf(),
                    x + temp_point_padding_x, y + self.__point_y)
예제 #53
0
 def __paint_volume_btn(self, cr, rect, state):
     # 画背景.
     bg_pixbuf = self.bg_pixbuf.get_pixbuf()
     bg_pixbuf = bg_pixbuf.scale_simple(rect.width - 12,
                                        bg_pixbuf.get_height(),
                                        gtk.gdk.INTERP_BILINEAR)
     draw_pixbuf(cr, bg_pixbuf, rect.x + 6,
                 rect.y + rect.height / 2 - bg_pixbuf.get_height() / 2)
     point_x_padding = float(rect.width - 12) / self.max_value * self.value
     # 画前景.
     fg_pixbuf = self.fg_pixbuf.get_pixbuf()
     if self.value > 1:
         fg_pixbuf = fg_pixbuf.scale_simple(int(point_x_padding),
                                            fg_pixbuf.get_height(),
                                            gtk.gdk.INTERP_BILINEAR)
         if fg_pixbuf:
             draw_pixbuf(
                 cr, fg_pixbuf, rect.x + 6,
                 rect.y + rect.height / 2 - bg_pixbuf.get_height() / 2)
     # 画拖动的点.
     point_pixbuf = self.point_volume_pixbuf.get_pixbuf()
     point_w, point_h = point_pixbuf.get_width(), point_pixbuf.get_height()
     x = rect.x + point_x_padding - point_w / 2
     draw_pixbuf(cr, point_pixbuf, x + 6,
                 rect.y + rect.height / 2 - point_h / 2)
예제 #54
0
 def top_paned_paint(cr, handle_pos):
     in_pixbuf = ui_theme.get_pixbuf("paned/in.png").get_pixbuf()
     out_pixbuf = ui_theme.get_pixbuf("paned/out.png").get_pixbuf()
     #
     if handle_pos.can_visible:
         # 绘制例子.
         if handle_pos.can_in:
             # 判断要向那个方向的控件靠拢.
             if handle_pos.can_move_child2:
                 pixbuf = in_pixbuf
             else:
                 pixbuf = out_pixbuf
         else:
             # 判断要向那个方向的控件靠拢.
             if handle_pos.can_move_child2:
                 pixbuf = out_pixbuf
             else:
                 pixbuf = in_pixbuf
         # 判断是否为纵向.
         if top_paned.get_type() == gtk.ORIENTATION_VERTICAL:
             pixbuf = pixbuf.rotate_simple(270)
         #
         draw_pixbuf(cr, pixbuf, handle_pos.x, handle_pos.y)
예제 #55
0
파일: group.py 프로젝트: masums/deepin-ui
    def expose_image_button_item(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        select_index = self.get_index()

        # Draw background
        if widget.state == gtk.STATE_NORMAL:
            if select_index == self.index:
                select_status = BUTTON_PRESS
            else:
                select_status = BUTTON_NORMAL

        elif widget.state == gtk.STATE_PRELIGHT:
            if select_index == self.index:
                select_status = BUTTON_PRESS
            else:
                select_status = BUTTON_HOVER

        elif widget.state == gtk.STATE_ACTIVE:
            select_status = BUTTON_PRESS

        if select_status == BUTTON_PRESS:
            pixbuf = self.press_dpixbuf.get_pixbuf()
        elif select_status == BUTTON_NORMAL:
            pixbuf = self.normal_dpixbuf.get_pixbuf()
        elif select_status == BUTTON_HOVER:
            pixbuf = self.hover_dpixbuf.get_pixbuf()

        draw_pixbuf(cr, pixbuf, rect.x, rect.y)
        propagate_expose(widget, event)

        return True
예제 #56
0
    def __expose(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        ox = x + self.clockface_width * 0.5

        self.hour_value = time.localtime().tm_hour
        self.minute_value = time.localtime().tm_min
        self.second_value = time.localtime().tm_sec

        with cairo_state(cr):
            draw_pixbuf(cr, self.clockface.get_pixbuf(), x, y)

        #hour
        with cairo_state(cr):
            oy = y + self.hourhand_height * 0.5
            cr.translate(ox, oy)
            cr.rotate(radians(360 * self.hour_value / 12))
            cr.translate(-self.hourhand_width * 0.5, -self.hourhand_height * 0.5)
            draw_pixbuf(cr, self.hourhand.get_pixbuf(), 0, 0)

        #minute
        with cairo_state(cr):
            oy = y + self.minhand_height * 0.5
            cr.translate(ox, oy)
            cr.rotate(radians(360 * self.minute_value / 60))
            cr.translate(-self.minhand_width * 0.5, -self.minhand_height * 0.5)
            draw_pixbuf(cr, self.minhand.get_pixbuf(), 0, 0)

        #second
        with cairo_state(cr):
            oy = y + self.sechand_height * 0.5
            cr.translate(ox, oy)
            cr.rotate(radians(360 * self.second_value / 60))
            cr.translate(-self.sechand_width * 0.5, -self.sechand_height * 0.5)
            draw_pixbuf(cr, self.sechand.get_pixbuf(), 0, 0)
예제 #57
0
    def expose_button(self, widget, event):
        '''
        Internal function to handle `expose-event` signal.

        @param widget: ColorButton instance.
        @param event: Expose event.
        '''
        # Init.
        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_color = ui_theme.get_color(
                "button_border_normal").get_color()
            background_color = ui_theme.get_shadow_color(
                "button_background_normal").get_color_info()
        elif widget.state == gtk.STATE_PRELIGHT:
            border_color = ui_theme.get_color(
                "button_border_prelight").get_color()
            background_color = ui_theme.get_shadow_color(
                "button_background_prelight").get_color_info()
        elif widget.state == gtk.STATE_ACTIVE:
            border_color = ui_theme.get_color(
                "button_border_active").get_color()
            background_color = ui_theme.get_shadow_color(
                "button_background_active").get_color_info()
        elif widget.state == gtk.STATE_INSENSITIVE:
            border_color = ui_theme.get_color("disable_frame").get_color()
            disable_background_color = ui_theme.get_color(
                "disable_background").get_color()
            background_color = [(0, (disable_background_color, 1.0)),
                                (1, (disable_background_color, 1.0))]

        # Draw background.
        draw_vlinear(cr, x + 1, y + 1, w - 2, h - 2, background_color)

        # Draw border.
        cr.set_source_rgb(*color_hex_to_cairo(border_color))
        draw_line(cr, x + 2, 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 four point.
        if widget.state == gtk.STATE_INSENSITIVE:
            top_left_point = ui_theme.get_pixbuf(
                "button/disable_corner.png").get_pixbuf()
        else:
            top_left_point = ui_theme.get_pixbuf(
                "button/corner.png").get_pixbuf()
        top_right_point = top_left_point.rotate_simple(270)
        bottom_right_point = top_left_point.rotate_simple(180)
        bottom_left_point = top_left_point.rotate_simple(90)

        draw_pixbuf(cr, top_left_point, x, y)
        draw_pixbuf(cr, top_right_point, x + w - top_left_point.get_width(), y)
        draw_pixbuf(cr, bottom_left_point, x,
                    y + h - top_left_point.get_height())
        draw_pixbuf(cr, bottom_right_point, x + w - top_left_point.get_width(),
                    y + h - top_left_point.get_height())

        # Draw color frame.
        cr.set_source_rgb(*color_hex_to_cairo("#c0c0c0"))
        cr.rectangle(x + (w - self.color_area_width) / 2,
                     y + (h - self.color_area_height) / 2,
                     self.color_area_width, self.color_area_height)
        cr.stroke()

        # Draw color.
        cr.set_source_rgb(*color_hex_to_cairo(self.color))
        cr.rectangle(x + (w - self.color_area_width) / 2,
                     y + (h - self.color_area_height) / 2,
                     self.color_area_width, self.color_area_height)
        cr.fill()

        # Draw mask when widget is insensitive.
        if widget.state == gtk.STATE_INSENSITIVE:
            cr.set_source_rgba(*alpha_color_hex_to_cairo(
                ui_theme.get_alpha_color(
                    "color_button_disable_mask").get_color_info()))
            cr.rectangle(x + (w - self.color_area_width) / 2,
                         y + (h - self.color_area_height) / 2,
                         self.color_area_width, self.color_area_height)
            cr.fill()

        return True