Beispiel #1
0
    def draw_mask_multiple_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_MULTIPLE_PAGE type.

        @param cr: Cairo context.
        @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.
        '''
        titlebar_height = self.titlebar.get_allocation().height
        button_box_height = self.right_button_box.get_allocation().height
        dominant_color = skin_config.dominant_color

        draw_vlinear(
            cr, x, y + titlebar_height, w, h - titlebar_height,
            ui_theme.get_shadow_color("mask_single_page_bottom").get_color_info(),
            )

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            [(0, (dominant_color, 1.0)),
             (1, (dominant_color, 1.0))])

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            ui_theme.get_shadow_color("mask_multiple_page").get_color_info(),
            )
Beispiel #2
0
    def draw_mask_multiple_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_MULTIPLE_PAGE type.
        
        @param cr: Cairo context.
        @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.
        '''
        titlebar_height = self.titlebar.get_allocation().height
        button_box_height = self.right_button_box.get_allocation().height
        dominant_color = skin_config.dominant_color
        
        draw_vlinear(
            cr, x, y + titlebar_height, w, h - titlebar_height,
            ui_theme.get_shadow_color("mask_single_page_bottom").get_color_info(),
            )
        
        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            [(0, (dominant_color, 1.0)),
             (1, (dominant_color, 1.0))])

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            ui_theme.get_shadow_color("mask_multiple_page").get_color_info(),
            )
Beispiel #3
0
 def expose_button(self, widget, event):
     '''Expose button.'''
     # 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:
         text_color = ui_theme.get_color("button_font").get_color()
         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:
         text_color = ui_theme.get_color("button_font").get_color()
         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:
         text_color = ui_theme.get_color("button_font").get_color()
         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:
         text_color = ui_theme.get_color("disable_text").get_color()
         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 font.
     draw_text(cr, self.label, x, y, w, h, self.font_size, text_color,
                 alignment=pango.ALIGN_CENTER)
     
     return True
Beispiel #4
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
Beispiel #5
0
 def draw_mask_glass_page(self, cr, x, y, w, h):
     '''Draw make for glass page type.'''
     top_height = 70
     
     draw_vlinear(
         cr, x, y, w, top_height,
         ui_theme.get_shadow_color("mask_glass_page_top").get_color_info(),
         )
     
     draw_vlinear(
         cr, x, y + top_height, w, h - top_height,
         ui_theme.get_shadow_color("mask_glass_page_bottom").get_color_info(),
         )
Beispiel #6
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(), 
                      )
         
     if self.progress > 0:    
         # Draw foreground 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_antialias(cairo.ANTIALIAS_NONE)
             cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("progressbar_foreground_frame").get_color()))
             cr.rectangle(x + 1, y + 1, int(w * self.progress / 100) - 1, h - 1)
             cr.set_line_width(1)
             cr.stroke()
             
         # Draw foreground.
         with cairo_state(cr):
             cr.rectangle(x + 1, y + 1, w - 2, h - 2)
             cr.clip()
             
             draw_vlinear(cr, x + 1, y + 1, int(w * self.progress / 100) - 2, h - 2,
                          ui_theme.get_shadow_color("progressbar_foreground").get_color_info(), 
                          )
         
     # 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()
Beispiel #7
0
    def render_size(self, cr, rect):
        '''
        Render size of DirItem.
        '''
        # 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 size.
        draw_text(cr, self.size_name,
                  rect.x,
                  rect.y,
                  rect.width,
                  rect.height,
                  alignment=pango.ALIGN_RIGHT,
                  )

        # 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()
Beispiel #8
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()
Beispiel #9
0
 def expose_droplist_item(self, widget, event, item_content):
     '''Expose droplist item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     font_color = ui_theme.get_color("menu_font").get_color()
     
     # Draw select effect.
     if self.subdroplist_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())
         
         # Set font color.
         font_color = ui_theme.get_color("menu_select_font").get_color()
         
     # Draw item content.
     draw_text(cr, item_content, 
                 rect.x + self.item_padding_left,
                 rect.y,
                 rect.width,
                 rect.height,
                 self.font_size, font_color,
                 )
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
Beispiel #10
0
 def __init__(self, 
              items, 
              font_size=DEFAULT_FONT_SIZE, 
              padding_left=20, 
              padding_middle=10, 
              padding_right=25):
     '''
     Initialize Categorybar class.
     
     @param items: A list of category item, format: (icon_dpixbuf, content, click_callback)
     '''
     # Init event box.
     super(Categorybar, self).__init__()
     self.category_index = 0
     self.connect(
         "expose-event",
         lambda w, e:
             expose_linear_background(w, e, ui_theme.get_shadow_color("categorybar_background").get_color_info()))
     
     # Init category box.
     self.category_item_box = gtk.VBox()
     self.add(self.category_item_box)
     
     # Init item.
     if items:
         icon_width = self.get_icon_width(items)
         for (index, item) in enumerate(items):
             category_item = CategoryItem(item, index, font_size, icon_width, padding_left, padding_middle, padding_right,
                              self.set_index, self.get_index)
             self.category_item_box.pack_start(category_item)
             
     # Show.
     self.show_all()        
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
0
 def create_separator_item(self):
     '''Create separator item.'''
     self.item_box = HSeparator(
         ui_theme.get_shadow_color("h_separator").get_color_info(),
         self.item_padding_left, 
         self.item_padding_y)
     self.item_box_height = self.item_padding_y * 2 + 1
Beispiel #15
0
 def render_size(self, cr, rect):
     '''
     Render size 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())
     
     # Draw directory size.
     draw_text(cr, self.size_name,
               rect.x,
               rect.y,
               rect.width, 
               rect.height,
               alignment=pango.ALIGN_RIGHT,
               )
     
     # 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()
Beispiel #16
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,
        )
Beispiel #17
0
 def create_separator_item(self):
     """
     Internal function to create separator item.
     """
     self.item_box = HSeparator(
         ui_theme.get_shadow_color("h_separator").get_color_info(), self.item_padding_x, self.item_padding_y
     )
     self.item_box_height = self.item_padding_y * 2 + 1
Beispiel #18
0
 def create_separator_item(self):
     '''
     Internal function to create separator item.
     '''
     self.item_box = HSeparator(
         ui_theme.get_shadow_color("h_separator").get_color_info(),
         self.item_padding_x, self.item_padding_y)
     self.item_box_height = self.item_padding_y * 2 + 1
Beispiel #19
0
 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
Beispiel #20
0
 def draw_menu_mask(self, cr, x, y, w, h):
     '''Draw mask.'''
     # Draw background.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("menu_mask").get_color_info()))
     cr.rectangle(x, y, w, h)    
     cr.fill()
     
     # Draw left side.
     draw_hlinear(cr, x + 1, y + 1, 16 + self.padding_x + self.padding_x * 2, h - 2,
                  ui_theme.get_shadow_color("menu_side").get_color_info())
Beispiel #21
0
    def render(self, cr, rect):
        # 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())

        # Draw loading text.
        draw_text(cr, "(空)", rect.x + COLUMN_OFFSET * self.column_index,
                  rect.y, rect.width, rect.height)
Beispiel #22
0
    def draw_mask_multiple_page(self, cr, x, y, w, h):
        '''Draw make for multiple page type.'''
        titlebar_height = self.titlebar.get_allocation().height
        button_box_height = self.right_button_box.get_allocation().height
        dominant_color = skin_config.dominant_color
        
        draw_vlinear(
            cr, x, y + titlebar_height, w, h - titlebar_height,
            ui_theme.get_shadow_color("mask_single_page_bottom").get_color_info(),
            )
        
        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            [(0, (dominant_color, 1.0)),
             (1, (dominant_color, 1.0))])

        draw_vlinear(
            cr, x, y + h - button_box_height, w, button_box_height,
            ui_theme.get_shadow_color("mask_multiple_page").get_color_info(),
            )
Beispiel #23
0
    def render(self, cr, rect):
        # 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())

        # Draw loading text.
        draw_text(cr, "(空)",
                  rect.x + COLUMN_OFFSET * self.column_index,
                  rect.y,
                  rect.width, rect.height)
Beispiel #24
0
 def expose_progressbar(self, widget, event):
     '''Expose progressbar.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     
     # Draw frame.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("progressbar_frame").get_color_info()))
     cr.set_operator(cairo.OPERATOR_OVER)
     draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, 1)
     cr.stroke()
     
     # Draw background.
     draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                  ui_theme.get_shadow_color("progressbar_background").get_color_info(), 
                  1)
 
     # Draw foreground.
     draw_vlinear(cr, rect.x, rect.y, rect.width * self.progress / 100.0, rect.height, 
                  ui_theme.get_shadow_color("progressbar_foreground").get_color_info(), 
                  1)
     
     # Draw font.
     draw_text(cr, str(self.progress) + "%", 
               rect.x, rect.y, rect.width, rect.height, 
               rect.height - 5, "#000000",
               alignment=pango.ALIGN_CENTER)
     
     # Draw light.
     light_radius = rect.height * 4
     light_offset_x = min(self.light_ticker % 150, 100) / 100.0 * (rect.width + light_radius * 2)
     with cairo_state(cr):
         cr.rectangle(rect.x, rect.y, rect.width * self.progress / 100.0, rect.height)
         cr.clip()
         draw_radial_round(cr, rect.x + light_offset_x - light_radius, rect.y - light_radius / 2, light_radius, 
                           ui_theme.get_shadow_color("progressbar_light").get_color_info())
            
     # Propagate expose.
     propagate_expose(widget, event)
     
     return True        
Beispiel #25
0
    def render_title(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()

        if self.is_hover:
            draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, ui_theme.get_shadow_color("menu_item_select").get_color_info())
            font_color = ui_theme.get_color("menu_select_font").get_color()

        draw_text(cr, self.title, rect.x + self.padding_x,
                  rect.y, rect.width - self.padding_x * 2,
                  rect.height, text_size=self.font_size,
                  text_color = font_color,
                  alignment=pango.ALIGN_LEFT)
Beispiel #26
0
    def draw_mask_glass_page(self, cr, x, y, w, h):
        '''
        Internal render function for DIALOG_MASK_GLASS_PAGE type.

        @param cr: Cairo context.
        @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.
        '''
        top_height = 70

        draw_vlinear(
            cr, x, y, w, top_height,
            ui_theme.get_shadow_color("mask_glass_page_top").get_color_info(),
            )

        draw_vlinear(
            cr, x, y + top_height, w, h - top_height,
            ui_theme.get_shadow_color("mask_glass_page_bottom").get_color_info(),
            )
Beispiel #27
0
 def draw_mask_glass_page(self, cr, x, y, w, h):
     '''
     Internal render function for DIALOG_MASK_GLASS_PAGE type.
     
     @param cr: Cairo context.
     @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.
     '''
     top_height = 70
     
     draw_vlinear(
         cr, x, y, w, top_height,
         ui_theme.get_shadow_color("mask_glass_page_top").get_color_info(),
         )
     
     draw_vlinear(
         cr, x, y + top_height, w, h - top_height,
         ui_theme.get_shadow_color("mask_glass_page_bottom").get_color_info(),
         )
Beispiel #28
0
    def draw_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.

        @param cr: Cairo context.
        @param x: X coordiante of draw area.
        @param y: Y coordiante of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        draw_vlinear(
            cr, x, y, w, h,
            ui_theme.get_shadow_color("linear_background").get_color_info())
Beispiel #29
0
 def draw_mask(self, cr, x, y, w, h):
     '''
     Mask render function.
     
     @param cr: Cairo context.
     @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.
     '''
     draw_vlinear(cr, x, y, w, h,
                  ui_theme.get_shadow_color("linear_background").get_color_info()
                  )
Beispiel #30
0
    def render_title(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()

        if self.is_hover:
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("menu_item_select").get_color_info())
            font_color = ui_theme.get_color("menu_select_font").get_color()

        draw_text(cr,
                  self.title,
                  rect.x + self.padding_x,
                  rect.y,
                  rect.width - self.padding_x * 2,
                  rect.height,
                  text_size=self.font_size,
                  text_color=font_color,
                  alignment=pango.ALIGN_LEFT)
Beispiel #31
0
 def draw_menu_mask(self, cr, x, y, w, h):
     '''
     Draw mask interface.
     
     @param cr: Cairo context.
     @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.
     '''
     # Draw background.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("menu_mask").get_color_info()))
     cr.rectangle(x, y, w, h)    
     cr.fill()
     
     # Draw left side.
     draw_hlinear(cr, x + 1, y + 1, 16 + self.padding_x + self.padding_x * 2, h - 2,
                  ui_theme.get_shadow_color("menu_side").get_color_info())
Beispiel #32
0
    def expose_window_shadow(self, widget, event):
        '''
        Internal function to expose the window shadow.

        @param widget: the window of gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        '''
        if self.expose_shadow_function:
            self.expose_shadow_function(widget, event)
        elif self.shadow_is_visible:
            # Init.
            cr = widget.window.cairo_create()
            rect = widget.allocation
            x, y, w, h = rect.x, rect.y, rect.width, rect.height

            # Draw window shadow.
            draw_window_shadow(cr, x, y, w, h, self.shadow_radius,
                               self.shadow_padding,
                               ui_theme.get_shadow_color("window_shadow"))
Beispiel #33
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()
Beispiel #34
0
    def draw_menu_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.

        @param cr: Cairo context.
        @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.
        '''
        # Draw background.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(
            ui_theme.get_alpha_color("menu_mask").get_color_info()))
        cr.rectangle(x, y, w, h)
        cr.fill()

        # Draw left side.
        draw_hlinear(cr, x + 1, y + 1,
                     16 + self.padding_x + self.padding_x * 2, h - 2,
                     ui_theme.get_shadow_color("menu_side").get_color_info())
Beispiel #35
0
    def expose_droplist_item(self, widget, event, item_content):
        '''
        Internal function to handle `expose-event` signal of item.

        @param widget: DropItem widget.
        @param event: Expose event.
        @param item_content: Item content.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        font_color = ui_theme.get_color("menu_font").get_color()

        # Draw select effect.
        if self.subdroplist_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())

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

        # Draw item content.
        draw_text(
            cr,
            item_content,
            rect.x + self.item_padding_left,
            rect.y,
            rect.width,
            rect.height,
            self.font_size,
            font_color,
        )

        # Propagate expose to children.
        propagate_expose(widget, event)

        return True
Beispiel #36
0
    def expose_window_shadow(self, widget, event):
        '''
        Internal fucntion to expose the window shadow.

        @param widget: the window of gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        '''
        if self.shadow_is_visible:
            # Init.
            cr = widget.window.cairo_create()
            rect = widget.allocation
            x, y, w, h = rect.x, rect.y, rect.width, rect.height

            # Clear color to transparent window.
            cr.set_source_rgba(0.0, 0.0, 0.0, 0.0)
            cr.set_operator(cairo.OPERATOR_SOURCE)
            cr.paint()

            # Draw window shadow.
            draw_window_shadow(cr, x, y, w, h, self.shadow_radius,
                               self.shadow_padding,
                               ui_theme.get_shadow_color("window_shadow"))
Beispiel #37
0
 def render_modification_time(self, cr, rect):
     '''
     Render type of DirItem.
     '''
     # 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 type.
     draw_text(cr, self.modification_time, 
               rect.x + MODIFICATION_TIME_PADDING_LEFT,
               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()
Beispiel #38
0
    def render_type(self, cr, rect):
        '''
        Render type of DirItem.
        '''
        # 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 type.
        draw_text(cr, self.content_type,
                  rect.x + CONTENT_TYPE_PADDING_LEFT,
                  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()
Beispiel #39
0
 def render_type(self, cr, rect):
     '''
     Render type 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())
     
     # Draw directory type.
     draw_text(cr, self.content_type, 
               rect.x + CONTENT_TYPE_PADDING_LEFT,
               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()
Beispiel #40
0
def render_background(item, cr, rect):
    if item.is_select:
        draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height,
                     ui_theme.get_shadow_color("listview_select").get_color_info())
Beispiel #41
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
Beispiel #42
0
 def expose_window_shadow(self, widget, event):
     '''Callback for 'expose-event' event of window shadow.'''
     if self.shadow_is_visible:
         # Init.
         cr = widget.window.cairo_create()
         rect = widget.allocation
         x, y, w, h = rect.x, rect.y, rect.width, rect.height
         
         # Clear color to transparent window.
         cr.set_source_rgba(0.0, 0.0, 0.0, 0.0)
         cr.set_operator(cairo.OPERATOR_SOURCE)
         cr.paint()
     
         # Draw window shadow.
         draw_window_shadow(cr, x, y, w, h, self.shadow_radius, self.shadow_padding, ui_theme.get_shadow_color("window_shadow"))
Beispiel #43
0
    def expose_menu_item(self, widget, event):
        '''
        Internal callback for `expose` signal.
        '''
        # 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 widget.state == gtk.STATE_INSENSITIVE:
            # Set font color.
            font_color = ui_theme.get_color("menu_disable_font").get_color()
        elif self.submenu_active or widget.state in [
                gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE
        ]:
            # Draw background.
            if self.menu_item_select_color:
                item_select_color = self.menu_item_select_color
            else:
                item_select_color = ui_theme.get_shadow_color(
                    "menu_item_select").get_color_info()
            draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height,
                         item_select_color, 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_disable_dpixbuf) = item_icons
            if widget.state == gtk.STATE_INSENSITIVE:
                pixbuf = item_disable_dpixbuf.get_pixbuf()
            elif 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 widget.state == gtk.STATE_INSENSITIVE:
                submenu_pixbuf = ui_theme.get_pixbuf(
                    "menu/arrow_disable.png").get_pixbuf()
            elif 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
Beispiel #44
0
    def __init__(self):
        '''
        Initialize IPV4Entry class.
        '''
        gtk.VBox.__init__(self)
        self.width = 120
        self.height = 22
        self.set_size_request(self.width, self.height)
        self.normal_frame = ui_theme.get_color("entry_normal_frame")
        self.alert_frame = ui_theme.get_color("entry_alert_frame")
        self.frame_color = self.normal_frame
        self.default_address = "..."
        self.ip = self.default_address
        self.dot_size = 2
        self.grab_focus_flag = False
        self.segment_split_char = "."
        self.ip_chars = map(str, range(0, 10)) + [self.segment_split_char]
        self.select_active_color=ui_theme.get_shadow_color("select_active_background")
        self.select_inactive_color=ui_theme.get_shadow_color("select_inactive_background")
        self.segment_number = 4
        self.last_segment_index = self.segment_number - 1
        self.segment_max_chars = 3

        self.cursor_index = 0
        self.cursor_padding_y = 2
        self.cursor_positions = []
        self.cursor_segment_index = 0
        self.highlight_segment_index = None

        self.cursor_alpha = 1
        self.cursor_blank_id = None
        self.edit_complete_flag = True
        self.edit_timeout_id = None

        self.draw_area = gtk.EventBox()
        self.draw_area.set_visible_window(False)
        self.draw_area.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.draw_area.set_can_focus(True) # can focus to response key-press signal
        self.pack_start(self.draw_area, True, True, 1)

        self.draw_area.connect("button-press-event", self.button_press_ipv4_entry)
        self.draw_area.connect("key-press-event", self.key_press_ipv4_entry)
        self.draw_area.connect("expose-event", self.expose_ipv4_entry)
        self.draw_area.connect("focus-in-event", self.focus_in_ipv4_entry)
        self.draw_area.connect("focus-out-event", self.focus_out_ipv4_entry)
        self.connect("editing", self.__edit_going)

        self.keymap = {
            "Left" : self.move_to_left,
            "Right" : self.move_to_right,
            "Home" : self.move_to_start,
            "End" : self.move_to_end,
            "Ctrl + a" : self.select_current_segment,
            "Ctrl + c" : self.copy_to_clipboard,
            "Ctrl + x" : self.cut_to_clipboard,
            "Ctrl + v" : self.paste_from_clipboard,
            "BackSpace" : self.backspace,
            "Space" : self.insert_ip_dot,
            "." : self.insert_ip_dot,
            }

        self.right_menu = Menu(
            [(None, _("Cut"), self.cut_to_clipboard),
             (None, _("Copy"), self.copy_to_clipboard),
             (None, _("Paste"), self.paste_from_clipboard),
             ],
            True)

        self.calculate_cursor_positions()
Beispiel #45
0
    def expose_window_shadow(self, widget, event):
        '''
        Internal function to expose the window shadow.

        @param widget: the window of gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        '''
        if self.shadow_is_visible:
            # Init.
            cr = widget.window.cairo_create()
            rect = widget.allocation
            x, y, w, h = rect.x, rect.y, rect.width, rect.height
            
            # Draw window shadow.
            draw_window_shadow(cr, x, y, w, h, self.shadow_radius, self.shadow_padding, ui_theme.get_shadow_color("window_shadow"))
Beispiel #46
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(),
            )

        if self.progress > 0:
            # Draw foreground 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_antialias(cairo.ANTIALIAS_NONE)
                cr.set_source_rgb(*color_hex_to_cairo(
                    ui_theme.get_color(
                        "progressbar_foreground_frame").get_color()))
                cr.rectangle(x + 1, y + 1,
                             int(w * self.progress / 100) - 1, h - 1)
                cr.set_line_width(1)
                cr.stroke()

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

                draw_vlinear(
                    cr,
                    x + 1,
                    y + 1,
                    int(w * self.progress / 100) - 2,
                    h - 2,
                    ui_theme.get_shadow_color(
                        "progressbar_foreground").get_color_info(),
                )

        # 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()
Beispiel #47
0
    def __init__(self):
        '''
        Initialize MACEntry class.
        '''
        gtk.VBox.__init__(self)
        self.width = 130
        self.height = 22
        self.set_size_request(self.width, self.height)
        self.normal_frame = ui_theme.get_color("entry_normal_frame")
        self.alert_frame = ui_theme.get_color("entry_alert_frame")
        self.frame_color = self.normal_frame
        self.default_address = ":::::"
        self.mac = self.default_address
        self.grab_focus_flag = False
        self.segment_split_char = ":"
        self.dot_size = get_content_size(self.segment_split_char)[0]
        self.chars_a_z = map(lambda a: str(chr(a)), range(97, 103))
        self.chars_A_Z = map(lambda a: str(chr(a)), range(65, 71))
        self.mac_chars = self.chars_a_z + self.chars_A_Z + map(
            str, range(0, 10)) + [self.segment_split_char]
        self.select_active_color = ui_theme.get_shadow_color(
            "select_active_background")
        self.select_inactive_color = ui_theme.get_shadow_color(
            "select_inactive_background")
        self.segment_number = 6
        self.last_segment_index = self.segment_number - 1
        self.segment_max_chars = 2

        self.cursor_index = 0
        self.cursor_padding_y = 2
        self.cursor_positions = []
        self.cursor_segment_index = 0
        self.highlight_segment_index = None

        self.cursor_alpha = 1
        self.cursor_blank_id = None
        self.edit_complete_flag = True
        self.edit_timeout_id = None

        self.draw_area = gtk.EventBox()
        self.draw_area.set_visible_window(False)
        self.draw_area.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.draw_area.set_can_focus(
            True)  # can focus to response key-press signal
        self.pack_start(self.draw_area, True, True, 1)

        self.draw_area.connect("button-press-event",
                               self.button_press_mac_entry)
        self.draw_area.connect("key-press-event", self.key_press_mac_entry)
        self.draw_area.connect("expose-event", self.expose_mac_entry)
        self.draw_area.connect("focus-in-event", self.focus_in_mac_entry)
        self.draw_area.connect("focus-out-event", self.focus_out_mac_entry)
        self.connect("editing", self.__edit_going)

        self.keymap = {
            "Left": self.move_to_left,
            "Right": self.move_to_right,
            "Home": self.move_to_start,
            "End": self.move_to_end,
            "Ctrl + a": self.select_current_segment,
            "Ctrl + c": self.copy_to_clipboard,
            "Ctrl + x": self.cut_to_clipboard,
            "Ctrl + v": self.paste_from_clipboard,
            "BackSpace": self.backspace,
            "Space": self.insert_mac_dot,
            ":": self.insert_mac_dot,
        }

        self.right_menu = Menu([
            (None, _("Cut"), self.cut_to_clipboard),
            (None, _("Copy"), self.copy_to_clipboard),
            (None, _("Paste"), self.paste_from_clipboard),
        ], True)

        self.calculate_cursor_positions()
Beispiel #48
0
 def __init__(self, content="", 
              padding_x=5, 
              padding_y=2,
              text_color=ui_theme.get_color("entry_text"),
              text_select_color=ui_theme.get_color("entry_select_text"),
              background_select_color=ui_theme.get_shadow_color("entry_select_background"),
              font_size=DEFAULT_FONT_SIZE, 
              ):
     '''Init entry.'''
     # Init.
     gtk.EventBox.__init__(self)
     self.set_visible_window(False)
     self.set_can_focus(True) # can focus to response key-press signal
     self.im = gtk.IMMulticontext()
     self.font_size = font_size
     self.text_color = text_color
     self.text_select_color = text_select_color
     self.background_select_color = background_select_color
     self.padding_x = padding_x
     self.padding_y = padding_y
     self.move_direction = self.MOVE_NONE
     self.double_click_flag = False
     self.left_click_flag = False
     self.left_click_coordindate = None
     self.drag_start_index = 0
     self.drag_end_index = 0
     self.grab_focus_flag = False
     self.editable_flag = True
     self.check_text = None
     self.cursor_visible_flag = True
     self.right_menu_visible_flag = True
     self.select_area_visible_flag = True
     
     self.content = content
     self.cursor_index = len(self.content)
     self.select_start_index = self.select_end_index = self.cursor_index
     self.offset_x = 0
     
     # Add keymap.
     self.keymap = {
         "Left" : self.move_to_left,
         "Right" : self.move_to_right,
         "Home" : self.move_to_start,
         "End" : self.move_to_end,
         "BackSpace" : self.backspace,
         "Delete" : self.delete,
         "Shift + Left" : self.select_to_left,
         "Shift + Right" : self.select_to_right,
         "Shift + Home" : self.select_to_start,
         "Shift + End" : self.select_to_end,
         "Ctrl + a" : self.select_all,
         "Ctrl + x" : self.cut_to_clipboard,
         "Ctrl + c" : self.copy_to_clipboard,
         "Ctrl + v" : self.paste_from_clipboard,
         "Return" : self.press_return}
     
     # Add menu.
     self.right_menu = Menu(
         [(None, "剪切", self.cut_to_clipboard),
          (None, "复制", self.copy_to_clipboard),
          (None, "粘贴", self.paste_from_clipboard),
          (None, "全选", self.select_all)],
         True)
     
     # Connect signal.
     self.connect_after("realize", self.realize_entry)
     self.connect("key-press-event", self.key_press_entry)
     self.connect("expose-event", self.expose_entry)
     self.connect("button-press-event", self.button_press_entry)
     self.connect("button-release-event", self.button_release_entry)
     self.connect("motion-notify-event", self.motion_notify_entry)
     self.connect("focus-in-event", self.focus_in_entry)
     self.connect("focus-out-event", self.focus_out_entry)
     
     self.im.connect("commit", lambda im, input_text: self.commit_entry(input_text))
Beispiel #49
0
 def draw_mask(self, cr, x, y, w, h):
     '''Draw mask.'''
     draw_vlinear(cr, x, y, w, h,
                  ui_theme.get_shadow_color("linear_background").get_color_info())
Beispiel #50
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