Exemple #1
0
    def expose_spin_bg(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgb(*color_hex_to_cairo(
                    ui_theme.get_color("disable_frame").get_color()))
            else:
                cr.set_source_rgb(*color_hex_to_cairo(
                    ui_theme.get_color("combo_entry_frame").get_color()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.stroke()

            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((
                    ui_theme.get_color("disable_background").get_color(),
                    0.9)))
            else:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((
                    ui_theme.get_color("combo_entry_background").get_color(),
                    0.9)))
            cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1)
            cr.fill()

        propagate_expose(widget, event)

        return False
Exemple #2
0
    def expose_spin_bg(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("disable_frame").get_color()))
            else:
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("combo_entry_frame").get_color()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.stroke()

            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("disable_background").get_color(), 0.9)))
            else:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
            cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1)
            cr.fill()

        propagate_expose(widget, event)

        return False
Exemple #3
0
    def on_expose_combo_frame(self, widget, event):
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            if self.get_sensitive():
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("combo_entry_frame").get_color()))
            else:
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("disable_frame").get_color()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.stroke()

            if self.focus_flag:
                color = (ui_theme.get_color("combo_entry_select_background").get_color(), 0.9)
                cr.set_source_rgba(*alpha_color_hex_to_cairo(color))
                cr.rectangle(rect.x, rect.y, rect.width - 1 - self.drop_button_width, rect.height - 1)
                cr.fill()
                cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
                cr.rectangle(rect.x + rect.width - 1 - self.drop_button_width, rect.y, self.drop_button_width, rect.height - 1)
                cr.fill()
            else:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
                cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1)
                cr.fill()

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

        return True
Exemple #4
0
    def draw_background(self, cr, rect):
        with cairo_disable_antialias(cr):
            # Draw frame.
            x, y, w, h = rect.x, rect.y, rect.width, rect.height
            cr.set_line_width(1)
            cr.set_source_rgb(
                *color_hex_to_cairo(self.frame_color.get_color()))
            cr.rectangle(x, y, w, h)
            cr.stroke()

            # Draw background.
            cr.set_source_rgba(*alpha_color_hex_to_cairo((
                ui_theme.get_color("combo_entry_background").get_color(),
                0.9)))
            cr.rectangle(x, y, w - 1, h - 1)
            cr.fill()

            # Draw ipv4 dot.
            cr.set_source_rgba(0.5, 0.5, 0.5, 0.8)
            dot_distance = self.width / self.segment_number
            dot_bottom_padding = 9
            for index in range(0, self.last_segment_index):
                cr.rectangle(
                    x + dot_distance * (index + 1) - self.dot_size / 2,
                    y + h - dot_bottom_padding, self.dot_size, self.dot_size)
                cr.fill()
Exemple #5
0
    def expose_tab_content_box(self, widget, event):
        '''
        Internal function to `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        self.tab_box_width = rect.width

        # Draw background.
        toplevel = widget.get_toplevel()
        coordinate = widget.translate_coordinates(toplevel, 0, 0)
        (offset_x, offset_y) = coordinate

        with cairo_state(cr):
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.clip()
            
            (shadow_x, shadow_y) = get_window_shadow_size(self.get_toplevel())
            skin_config.render_background(cr, self, shadow_x, shadow_y)
        
        # Draw mask.
        cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_select_bg_color.get_color(), 0.93)))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
Exemple #6
0
    def expose_tab_content_box(self, widget, event):
        '''
        Internal function to `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        self.tab_box_width = rect.width

        # Draw background.
        toplevel = widget.get_toplevel()
        coordinate = widget.translate_coordinates(toplevel, 0, 0)
        (offset_x, offset_y) = coordinate

        with cairo_state(cr):
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.clip()

            (shadow_x, shadow_y) = get_window_shadow_size(self.get_toplevel())
            skin_config.render_background(cr, self, shadow_x, shadow_y)

        # Draw mask.
        cr.set_source_rgba(
            *alpha_color_hex_to_cairo((self.tab_select_bg_color.get_color(),
                                       0.93)))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
Exemple #7
0
    def draw_background(self, cr, rect):
        with cairo_disable_antialias(cr):
            # Draw frame.
            x, y, w, h = rect.x, rect.y, rect.width, rect.height
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo(
                self.frame_color.get_color()))
            cr.rectangle(x, y, w, h)
            cr.stroke()

            # Draw background.
            cr.set_source_rgba(*alpha_color_hex_to_cairo(
                (ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
            cr.rectangle(x, y, w - 1, h - 1)
            cr.fill()

            # Draw mac dot.
            cr.set_source_rgba(0.5, 0.5, 0.5, 0.8)
            dot_distance = self.width / self.segment_number
            dot_bottom_padding = 18
            for index in range(0, self.last_segment_index):
                draw_text(cr,
                          self.segment_split_char,
                          x + dot_distance * (index + 1) - self.dot_size / 2,
                          y + h - dot_bottom_padding,
                          self.dot_size,
                          self.dot_size,
                          )
Exemple #8
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())
Exemple #9
0
    def expose_bread_menu_frame(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        with cairo_disable_antialias(cr):
            outside_border = alpha_color_hex_to_cairo(("#666666", 0.5))
            cr.set_line_width(1)
            cr.set_source_rgba(*outside_border)
            cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2)
            cr.fill()
Exemple #10
0
    def on_expose_combo_frame(self, widget, event):
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            if self.get_sensitive():
                cr.set_source_rgb(*color_hex_to_cairo(
                    ui_theme.get_color("combo_entry_frame").get_color()))
            else:
                cr.set_source_rgb(*color_hex_to_cairo(
                    ui_theme.get_color("disable_frame").get_color()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.stroke()

            if self.focus_flag:
                color = (ui_theme.get_color(
                    "combo_entry_select_background").get_color(), 0.9)
                cr.set_source_rgba(*alpha_color_hex_to_cairo(color))
                cr.rectangle(rect.x, rect.y,
                             rect.width - 1 - self.drop_button_width,
                             rect.height - 1)
                cr.fill()
                cr.set_source_rgba(*alpha_color_hex_to_cairo((
                    ui_theme.get_color("combo_entry_background").get_color(),
                    0.9)))
                cr.rectangle(rect.x + rect.width - 1 - self.drop_button_width,
                             rect.y, self.drop_button_width, rect.height - 1)
                cr.fill()
            else:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((
                    ui_theme.get_color("combo_entry_background").get_color(),
                    0.9)))
                cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1)
                cr.fill()

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

        return True
Exemple #11
0
    def expose_bread_menu_frame(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        with cairo_disable_antialias(cr):
            outside_border = alpha_color_hex_to_cairo(("#666666", 0.5))
            cr.set_line_width(1)
            cr.set_source_rgba(*outside_border)
            cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 2,
                         rect.height - 2)
            cr.fill()
Exemple #12
0
 def expose_item_align(self, widget, event):
     '''Expose item align.'''
     # Init.
     cr = widget.window.cairo_create()        
     rect = widget.allocation
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     # Draw background.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("droplist_mask").get_color_info()))
     cr.rectangle(x, y, w, h)    
     cr.fill()
Exemple #13
0
    def _expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        rect.y, rect.x = 0, 0

        cr.set_source_rgba(*alpha_color_hex_to_cairo(
            (self.bg, self.opacity)))
        cr.rectangle(*rect)
        cr.fill()

        propagate_expose(widget, event)
        return True
Exemple #14
0
def draw_shadow(cr, x, y, w, h, r, color_window_shadow):
    '''
    Draw window shadow.
    
    @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.
    @param r: Radious of window shadow corner.
    @param color_window_shadow: theme.DyanmicShadowColor.
    '''
    color_infos = color_window_shadow.get_color_info()
    with cairo_state(cr):
        # Clip four corner.
        cr.rectangle(x, y, r, r)
        cr.rectangle(x + w - r, y, r, r)
        cr.rectangle(x, y + h - r, r, r)
        cr.rectangle(x + w - r, y + h - r, r, r)
        
        cr.clip()
        
        # Draw four round.
        draw_radial_round(cr, x + r, y + r, r, color_infos)
        draw_radial_round(cr, x + r, y + h - r, r, color_infos)
        draw_radial_round(cr, x + w - r, y + r, r, color_infos)
        draw_radial_round(cr, x + w - r, y + h - r, r, color_infos)
        
    with cairo_state(cr):
        # Draw four side.
        draw_vlinear(
            cr, 
            x + r, y, 
            w - r * 2, r, color_infos)
        draw_vlinear(
            cr, 
            x + r, y + h - r, 
            w - r * 2, r, color_infos, 0, False)
        draw_hlinear(
            cr, 
            x, y + r, 
            r, h - r * 2, color_infos)
        draw_hlinear(
            cr, 
            x + w - r, y + r, 
            r, h - r * 2, color_infos, 0, False)
        
    # Fill inside.
    cr.set_source_rgba(*alpha_color_hex_to_cairo(color_infos[-1][1]))    
    cr.rectangle(x + r, y + r, w - r * 2, h - r * 2)
    cr.fill()
Exemple #15
0
 def expose_item_align(self, widget, event):
     '''
     Internal function to handle `expose-event` signal.
     
     @param widget: Droplist widget.
     @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
     
     # Draw background.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("droplist_mask").get_color_info()))
     cr.rectangle(x, y, w, h)    
     cr.fill()
Exemple #16
0
 def expose_dragable_tabbar(self, widget, event):
     '''
     docs
     '''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     x, w, h = rect.x, rect.width, rect.height
     y = 0
     
     # Draw background.
     (offset_x, offset_y) = widget.translate_coordinates(self.get_toplevel(), 0, 0)
     with cairo_state(cr):
         cr.translate(-offset_x, -offset_y)
         
         (shadow_x, shadow_y) = get_window_shadow_size(self.get_toplevel())
         skin_config.render_background(cr, widget, shadow_x, shadow_y)
     
     # Draw inactive tab.
     draw_x_list = []
     width_offset = 0
     for (index, tab_name) in enumerate(self.names):
         draw_x_list.append(x + width_offset)
         width_offset += (self.name_widths[index] - (self.triangle_width + self.tab_radious * 2))
         
     for (index, tab_name) in enumerate(reversed(self.names)):
         tab_index = len(self.names) - index - 1
         if tab_index != self.active_index:
             self.draw_tab(cr, draw_x_list[tab_index], y, tab_name, tab_index)
             
     # Draw active tab.
     self.draw_tab(cr, draw_x_list[self.active_index], y, self.names[self.active_index], self.active_index)        
     
     # Draw bottom line.
     frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_bottom_active_frame").get_color_info())        
     cr.set_source_rgba(*frame_color)
     cr.rectangle(x, 
                  y + h - 1, 
                  draw_x_list[self.active_index],
                  1)
     cr.rectangle(x + draw_x_list[self.active_index] + self.name_widths[self.active_index], 
                  y + h - 1,
                  w - draw_x_list[self.active_index] - self.name_widths[self.active_index],
                  1)
     cr.fill()
     
     return True
Exemple #17
0
    def expose_item_align(self, widget, event):
        '''
        Internal function to handle `expose-event` signal.

        @param widget: Droplist widget.
        @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

        # Draw background.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(
            ui_theme.get_alpha_color("droplist_mask").get_color_info()))
        cr.rectangle(x, y, w, h)
        cr.fill()
Exemple #18
0
    def redraw_bg(self, widget, event):
        '''
        Internal callback function to "expose-event" signal.

        @param widget: gtk.EventBox
        @param event: event of type gtk.gdk.event
        '''
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # Draw backgroud.
        with cairo_state(cr):
            cr.set_source_rgba(*alpha_color_hex_to_cairo(("#def5ff", 1)))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.fill()

        return False
Exemple #19
0
    def redraw_bg(self, widget, event):
        '''
        Internal callback function to "expose-event" signal.

        @param widget: gtk.EventBox
        @param event: event of type gtk.gdk.event
        '''
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # Draw backgroud.
        with cairo_state(cr):
            cr.set_source_rgba(*alpha_color_hex_to_cairo(("#def5ff", 1)))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.fill()

        return False
Exemple #20
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())
Exemple #21
0
    def expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        if self.hover or self.steady:
            background_color = THEME['hover']
            text_color = THEME['bg']
            bg_opacity = self.opacity[1]
            content_opacity = self.opacity[3]
            if bg_opacity == 0:
                text_color = THEME['hover']
        else:
            background_color = THEME['bg']
            text_color = self.color
            bg_opacity = self.opacity[0]
            content_opacity = self.opacity[2]
        font_width, font_height = get_text_size(self.text,
                                                text_size=self.font_size)
        x_padding = rect.x + (rect.width - font_width) / 2
        y_padding = rect.y + (rect.height - font_height) / 2
        with cairo_disable_antialias(cr):
            cr.set_source_rgba(*alpha_color_hex_to_cairo(
                (background_color, bg_opacity)))
            cr.rectangle(rect.x,
                         rect.y,
                         rect.width,
                         rect.height)
            cr.fill()
        if self.border:
            draw_border(cr, rect=rect, pos=(1, 1, 0, 0))

        if self.icon:
            draw_icon(cr, self.symbol, text_color, rect,
                      opacity=content_opacity)
        else:
            draw_text(cr, self.text,
                      x_padding,
                      y_padding,
                      text_size=self.font_size,
                      text_color=text_color)

        if font_height > rect.height:
            widget.set_size_request(rect.width, font_height)
        return True
Exemple #22
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())
Exemple #23
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        
Exemple #24
0
    def expose_text_entry(self, widget, event):
        '''Callback for `expose-event` signal.'''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("combo_entry_frame").get_color()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.stroke()
            
            cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
            cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1)
            cr.fill()
        
        propagate_expose(widget, event)
        
        return True
Exemple #25
0
def draw_shadow(cr, x, y, w, h, r, color_window_shadow):
    '''
    Draw window shadow.

    @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.
    @param r: Radious of window shadow corner.
    @param color_window_shadow: theme.DyanmicShadowColor.
    '''
    color_infos = color_window_shadow.get_color_info()
    with cairo_state(cr):
        # Clip four corner.
        cr.rectangle(x, y, r, r)
        cr.rectangle(x + w - r, y, r, r)
        cr.rectangle(x, y + h - r, r, r)
        cr.rectangle(x + w - r, y + h - r, r, r)

        cr.clip()

        # Draw four round.
        draw_radial_round(cr, x + r, y + r, r, color_infos)
        draw_radial_round(cr, x + r, y + h - r, r, color_infos)
        draw_radial_round(cr, x + w - r, y + r, r, color_infos)
        draw_radial_round(cr, x + w - r, y + h - r, r, color_infos)

    with cairo_state(cr):
        # Draw four side.
        draw_vlinear(cr, x + r, y, w - r * 2, r, color_infos)
        draw_vlinear(cr, x + r, y + h - r, w - r * 2, r, color_infos, 0, False)
        draw_hlinear(cr, x, y + r, r, h - r * 2, color_infos)
        draw_hlinear(cr, x + w - r, y + r, r, h - r * 2, color_infos, 0, False)

    # Fill inside.
    cr.set_source_rgba(*alpha_color_hex_to_cairo(color_infos[-1][1]))
    cr.rectangle(x + r, y + r, w - r * 2, h - r * 2)
    cr.fill()
Exemple #26
0
    def expose_window_background(self, widget, event):
        """
        Internal function to expose the window background.

        @param widget: A window of type Gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        @return: Always return True.
        """
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        # Clear color to transparent window.
        cr.set_source_rgba(*self.background_color)
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.paint()
        
        # Save cairo context.
        if self.shadow_is_visible:
            x = rect.x + self.shadow_padding
            y = rect.y + self.shadow_padding
            w = rect.width - self.shadow_padding * 2
            h = rect.height - self.shadow_padding * 2
        else:
            x, y, w, h = rect.x, rect.y, rect.width, rect.height
            
        # Draw background.
        with cairo_state(cr):
            if self.window.get_state() != gtk.gdk.WINDOW_STATE_MAXIMIZED:
                cr.rectangle(x + 2, y, w - 4, 1)
                cr.rectangle(x + 1, y + 1, w - 2, 1)
                cr.rectangle(x, y + 2, w, h - 4)
                cr.rectangle(x + 2, y + h - 1, w - 4, 1)
                cr.rectangle(x + 1, y + h - 2, w - 2, 1)
                
                cr.clip()
            
            skin_config.render_background(cr, self, x, y)
        
            # Draw mask.
            self.draw_mask(cr, x, y, w, h)
            
        # Draw corner shadow.
        with cairo_state(cr):
            cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_shadow_corner").get_color_info()))
            
            cr.rectangle(x, y + 1, 1, 1) # top-left
            cr.rectangle(x + 1, y, 1, 1)
            
            cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
            cr.rectangle(x + w - 2, y, 1, 1)
            
            cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
            cr.rectangle(x + 1, y + h - 1, 1, 1)
            
            cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
            cr.rectangle(x + w - 2, y + h - 1, 1, 1)
            
            cr.fill()
            
        # Draw background corner.
        with cairo_state(cr):
            cr.rectangle(x, y + 1, 1, 1) # top-left
            cr.rectangle(x + 1, y, 1, 1)
            
            cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
            cr.rectangle(x + w - 2, y, 1, 1)
            
            cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
            cr.rectangle(x + 1, y + h - 1, 1, 1)
            
            cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
            cr.rectangle(x + w - 2, y + h - 1, 1, 1)
            
            cr.clip()
            
            skin_config.render_background(cr, self, x, y)
            
        # Propagate expose.
        propagate_expose(widget, event)
        
        return True
Exemple #27
0
    def expose_window_background(self, widget, event):
        '''
        Internal function to expose the window background.

        @param widget: A window of type Gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        @return: Always return True.
        '''
        if self.expose_background_function:
            self.expose_background_function(widget, event)
        else:
            # Init.
            cr = widget.window.cairo_create()
            rect = widget.allocation

            # Draw background.
            self.draw_background(cr, rect.x, rect.y, rect.width, rect.height)

            # Save cairo context.
            if self.shadow_is_visible:
                x = rect.x + self.shadow_padding
                y = rect.y + self.shadow_padding
                w = rect.width - self.shadow_padding * 2
                h = rect.height - self.shadow_padding * 2
            else:
                x, y, w, h = rect.x, rect.y, rect.width, rect.height

            # Draw skin and mask.
            with cairo_state(cr):
                if self.window.get_state(
                ) & gtk.gdk.WINDOW_STATE_MAXIMIZED != gtk.gdk.WINDOW_STATE_MAXIMIZED:
                    cr.rectangle(x + 2, y, w - 4, 1)
                    cr.rectangle(x + 1, y + 1, w - 2, 1)
                    cr.rectangle(x, y + 2, w, h - 4)
                    cr.rectangle(x + 2, y + h - 1, w - 4, 1)
                    cr.rectangle(x + 1, y + h - 2, w - 2, 1)

                    cr.clip()

                # Draw background.
                self.draw_skin(cr, x, y, w, h)

                # Draw mask.
                self.draw_mask(cr, x, y, w, h)

            # Draw corner shadow.
            with cairo_state(cr):
                cr.set_source_rgba(*alpha_color_hex_to_cairo(
                    ui_theme.get_alpha_color(
                        "window_shadow_corner").get_color_info()))

                cr.rectangle(x, y + 1, 1, 1)  # top-left
                cr.rectangle(x + 1, y, 1, 1)

                cr.rectangle(x + w - 1, y + 1, 1, 1)  # top-right
                cr.rectangle(x + w - 2, y, 1, 1)

                cr.rectangle(x, y + h - 2, 1, 1)  # bottom-left
                cr.rectangle(x + 1, y + h - 1, 1, 1)

                cr.rectangle(x + w - 1, y + h - 2, 1, 1)  # bottom-right
                cr.rectangle(x + w - 2, y + h - 1, 1, 1)

                cr.fill()

            # Draw background corner.
            with cairo_state(cr):
                cr.rectangle(x, y + 1, 1, 1)  # top-left
                cr.rectangle(x + 1, y, 1, 1)

                cr.rectangle(x + w - 1, y + 1, 1, 1)  # top-right
                cr.rectangle(x + w - 2, y, 1, 1)

                cr.rectangle(x, y + h - 2, 1, 1)  # bottom-left
                cr.rectangle(x + 1, y + h - 1, 1, 1)

                cr.rectangle(x + w - 1, y + h - 2, 1, 1)  # bottom-right
                cr.rectangle(x + w - 2, y + h - 1, 1, 1)

                cr.clip()

                self.draw_skin(cr, x, y, w, h)

            # Propagate expose.
            propagate_expose(widget, event)

        return True
Exemple #28
0
    def expose_window_background(self, widget, event):
        '''
        Internal function to expose the window background.

        @param widget: A window of type Gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        @return: Always return True.
        '''
        if self.expose_background_function:
            self.expose_background_function(widget, event)
        else:
            # Init.
            cr = widget.window.cairo_create()
            rect = widget.allocation
            
            # Draw background.
            self.draw_background(cr, rect.x, rect.y, rect.width, rect.height)
            
            # Save cairo context.
            if self.shadow_is_visible:
                x = rect.x + self.shadow_padding
                y = rect.y + self.shadow_padding
                w = rect.width - self.shadow_padding * 2
                h = rect.height - self.shadow_padding * 2
            else:
                x, y, w, h = rect.x, rect.y, rect.width, rect.height
                
            # Draw skin and mask.
            with cairo_state(cr):
                if self.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED != gtk.gdk.WINDOW_STATE_MAXIMIZED:
                    cr.rectangle(x + 2, y, w - 4, 1)
                    cr.rectangle(x + 1, y + 1, w - 2, 1)
                    cr.rectangle(x, y + 2, w, h - 4)
                    cr.rectangle(x + 2, y + h - 1, w - 4, 1)
                    cr.rectangle(x + 1, y + h - 2, w - 2, 1)
                    
                    cr.clip()
                
                # Draw background.
                self.draw_skin(cr, x, y, w, h)
            
                # Draw mask.
                self.draw_mask(cr, x, y, w, h)
                
            # Draw corner shadow.
            with cairo_state(cr):
                cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_shadow_corner").get_color_info()))
                
                cr.rectangle(x, y + 1, 1, 1) # top-left
                cr.rectangle(x + 1, y, 1, 1)
                
                cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
                cr.rectangle(x + w - 2, y, 1, 1)
                
                cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
                cr.rectangle(x + 1, y + h - 1, 1, 1)
                
                cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
                cr.rectangle(x + w - 2, y + h - 1, 1, 1)
                
                cr.fill()
                
            # Draw background corner.
            with cairo_state(cr):
                cr.rectangle(x, y + 1, 1, 1) # top-left
                cr.rectangle(x + 1, y, 1, 1)
                
                cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
                cr.rectangle(x + w - 2, y, 1, 1)
                
                cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
                cr.rectangle(x + 1, y + h - 1, 1, 1)
                
                cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
                cr.rectangle(x + w - 2, y + h - 1, 1, 1)
                
                cr.clip()
                
                self.draw_skin(cr, x, y, w, h)
                
            # Propagate expose.
            propagate_expose(widget, event)
            
        return True
Exemple #29
0
    def expose_tab_title_box(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        if self.dockfill:
            self.update_tab_title_widths(rect.width)

        # Draw background.
        self.draw_title_background(cr, widget)

        if len(self.tab_items) > 0:
            # Draw title unselect tab.
            tab_title_width = sum(self.tab_title_widths)

            with cairo_state(cr):
                with cairo_disable_antialias(cr):
                    cr.set_source_rgba(*alpha_color_hex_to_cairo((
                        self.tab_unselect_bg_color.get_color(), 0.7)))
                    cr.rectangle(1, 1, tab_title_width, self.tab_height)
                    cr.fill()

                    cr.set_line_width(1)
                    cr.set_source_rgba(*alpha_color_hex_to_cairo((
                        self.tab_unselect_frame_color.get_color(), 1.0)))
                    cr.rectangle(1, 1, tab_title_width, self.tab_height)
                    cr.stroke()

                    for (index,
                         width) in enumerate(self.tab_title_widths[:-1]):
                        cr.set_source_rgba(*alpha_color_hex_to_cairo((
                            self.tab_unselect_frame_color.get_color(), 1.0)))
                        cr.rectangle(
                            1 + sum(self.tab_title_widths[0:index]) + width, 1,
                            1, self.tab_height)
                        cr.fill()

                    cr.set_source_rgb(*color_hex_to_cairo(
                        self.tab_select_frame_color.get_color()))
                    cr.rectangle(0, rect.height - 1,
                                 sum(self.tab_title_widths[0:self.tab_index]),
                                 1)
                    cr.fill()

                    cr.set_source_rgb(*color_hex_to_cairo(
                        self.tab_select_frame_color.get_color()))
                    cr.rectangle(
                        1 + sum(self.tab_title_widths[0:self.tab_index]),
                        rect.height - 1, rect.width -
                        sum(self.tab_title_widths[0:self.tab_index]), 1)
                    cr.fill()

            for (index, item) in enumerate(self.tab_items):
                # Draw title background.
                title = item[0]

                # Draw title tab.
                with cairo_disable_antialias(cr):
                    if index == self.tab_index:
                        # Draw title select tab.
                        cr.set_source_rgba(*alpha_color_hex_to_cairo((
                            self.tab_select_bg_color.get_color(), 0.93)))
                        if index == 0:
                            cr.rectangle(sum(self.tab_title_widths[0:index]),
                                         1, self.tab_title_widths[index] + 1,
                                         self.tab_height)
                        else:
                            cr.rectangle(
                                1 + sum(self.tab_title_widths[0:index]), 1,
                                self.tab_title_widths[index], self.tab_height)
                        cr.fill()

                        if index == 0:
                            cr.rectangle(0, 0, rect.width, self.tab_height)
                            cr.clip()

                        cr.set_line_width(1)
                        cr.set_source_rgb(*color_hex_to_cairo(
                            self.tab_select_frame_color.get_color()))
                        if index == 0:
                            cr.rectangle(sum(self.tab_title_widths[0:index]),
                                         1, self.tab_title_widths[index] + 2,
                                         self.tab_height)
                        else:
                            cr.rectangle(
                                1 + sum(self.tab_title_widths[0:index]), 1,
                                self.tab_title_widths[index] + 1,
                                self.tab_height)
                        cr.stroke()

                draw_text(
                    cr,
                    title,
                    sum(self.tab_title_widths[0:index]) + self.tab_padding_x,
                    self.tab_padding_y,
                    self.tab_title_widths[index] - self.tab_padding_x * 2,
                    self.tab_height - self.tab_padding_y * 2,
                )

                # Draw close button.
                if self.can_close_tab:
                    button_x = sum(
                        self.tab_title_widths[0:index + 1]
                    ) - self.close_button_padding_x - self.close_button_size
                    button_y = self.close_button_padding_y

                    if self.hover_close_button_index == index:
                        cr.set_source_rgb(*color_hex_to_cairo(
                            self.close_button_select_background_color))
                        draw_round_rectangle(
                            cr, button_x - self.close_button_frame_size,
                            button_y - self.close_button_frame_size,
                            self.close_button_size +
                            self.close_button_frame_size * 2,
                            self.close_button_size +
                            self.close_button_frame_size * 2, 2)
                        cr.fill()

                    cr.set_line_width(1.5)
                    if self.hover_close_button_index == index:
                        cr.set_source_rgb(*color_hex_to_cairo(
                            self.close_button_select_foreground_color))
                    else:
                        cr.set_source_rgb(
                            *color_hex_to_cairo(self.close_button_color))
                    cr.move_to(button_x, button_y)
                    cr.line_to(button_x + self.close_button_size,
                               button_y + self.close_button_size)
                    cr.stroke()

                    cr.move_to(button_x + self.close_button_size, button_y)
                    cr.line_to(button_x, button_y + self.close_button_size)
                    cr.stroke()
        else:
            cr.set_source_rgba(*alpha_color_hex_to_cairo((
                self.tab_select_bg_color.get_color(), 0.93)))
            cr.rectangle(0, 0, rect.width, rect.height)
            cr.fill()
Exemple #30
0
 def expose_window_background(self, widget, event):
     '''Expose window background.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     
     # 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()
     
     # Save cairo context.
     if self.shadow_is_visible:
         x = rect.x + self.shadow_padding
         y = rect.y + self.shadow_padding
         w = rect.width - self.shadow_padding * 2
         h = rect.height - self.shadow_padding * 2
     else:
         x, y, w, h = rect.x, rect.y, rect.width, rect.height
         
     # Draw background.
     with cairo_state(cr):
         cr.rectangle(x + 2, y, w - 4, 1)
         cr.rectangle(x + 1, y + 1, w - 2, 1)
         cr.rectangle(x, y + 2, w, h - 4)
         cr.rectangle(x + 2, y + h - 1, w - 4, 1)
         cr.rectangle(x + 1, y + h - 2, w - 2, 1)
         
         cr.clip()
         
         skin_config.render_background(cr, self, x, y)
     
         # Draw mask.
         self.draw_mask(cr, x, y, w, h)
         
     # Draw corner shadow.
     with cairo_state(cr):
         cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_shadow_corner").get_color_info()))
         
         cr.rectangle(x, y + 1, 1, 1) # top-left
         cr.rectangle(x + 1, y, 1, 1)
         
         cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
         cr.rectangle(x + w - 2, y, 1, 1)
         
         cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
         cr.rectangle(x + 1, y + h - 1, 1, 1)
         
         cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
         cr.rectangle(x + w - 2, y + h - 1, 1, 1)
         
         cr.fill()
         
     # Draw background corner.
     with cairo_state(cr):
         cr.rectangle(x, y + 1, 1, 1) # top-left
         cr.rectangle(x + 1, y, 1, 1)
         
         cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
         cr.rectangle(x + w - 2, y, 1, 1)
         
         cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
         cr.rectangle(x + 1, y + h - 1, 1, 1)
         
         cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
         cr.rectangle(x + w - 2, y + h - 1, 1, 1)
         
         cr.clip()
         
         skin_config.render_background(cr, self, x, y)
         
     # Propagate expose.
     propagate_expose(widget, event)
     
     return True
Exemple #31
0
    def expose_cb(self, widget, event):
        '''
        Internal expose callback function.

        @param widget: Crumb instance.
        @param event: An event of gtk.gdk.Event.
        '''
        if self.menu == None:
            self.menu_min = 0
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Should move this part to Bread class since app_theme is golobalized.
        arrow_right = self.arrow_right
        arrow_down = self.arrow_down
        arrow_width, arrow_height = arrow_right.get_pixbuf().get_width(
        ), arrow_right.get_pixbuf().get_height()
        arrow_pixbuf = arrow_right

        outside_border = alpha_color_hex_to_cairo(("#000000", 0.15))
        inner_border = alpha_color_hex_to_cairo(("#ffffff", 0.5))
        active_mask = alpha_color_hex_to_cairo(("#000000", 0.1))

        if self.menu_show:
            self.set_state(gtk.STATE_PRELIGHT)

        if widget.state == gtk.STATE_NORMAL:
            text_color = ui_theme.get_color("title_text").get_color()
            button_color = None
            menu_color = None
            arrow_pixbuf = arrow_right

        elif widget.state == gtk.STATE_PRELIGHT:
            text_color = ui_theme.get_color("title_text").get_color()
            if self.menu_show:
                arrow_pixbuf = arrow_down
            else:
                arrow_pixbuf = arrow_right

            if self.in_menu:
                button_color = None
                menu_color = inner_border
            else:
                button_color = inner_border
                menu_color = None

        elif widget.state == gtk.STATE_ACTIVE:
            text_color = ui_theme.get_color("title_text").get_color()
            if self.in_button:
                button_color = inner_border
                menu_color = None
                arrow_pixbuf = arrow_right
            else:
                button_color = None
                menu_color = inner_border
                arrow_pixbuf = arrow_down

        elif widget.state == gtk.STATE_INSENSITIVE:
            arrow_pixbuf = arrow_right
            text_color = ui_theme.get_color("disable_text").get_color()
            disable_bg = ui_theme.get_color("disable_background").get_color()
            button_color = [(0, (disable_bg, 1.0)), (1, (disable_bg, 1.0))]
            menu_color = [(0, (disable_bg, 1.0)), (1, (disable_bg, 1.0))]

        # Draw background.
        if not widget.state == gtk.STATE_NORMAL:
            # Draw button border.
            def draw_rectangle(cr, x, y, w, h):
                draw_line(cr, x - 1, y, x + w, y)  # top
                draw_line(cr, x, y + h, x + w, y + h)  # bottom
                draw_line(cr, x, y, x, y + h)  # left
                draw_line(cr, x + w, y, x + w, y + h - 1)  # right

            cr.set_source_rgba(*outside_border)
            if button_color:
                draw_rectangle(cr, x + 1, y + 1, self.button_width - 1, h - 1)
            elif menu_color:
                draw_rectangle(cr, x + self.button_width, y + 1, self.menu_min,
                               h - 1)

            # Draw innner border.
            cr.set_source_rgba(*inner_border)
            if button_color:
                draw_rectangle(cr, x + 2, y + 2, self.button_width - 3, h - 3)
            elif menu_color:
                draw_rectangle(cr, x + self.button_width + 1, y + 2,
                               self.menu_min - 2, h - 3)

            if widget.state == gtk.STATE_ACTIVE:
                cr.set_source_rgba(*active_mask)
                if button_color:
                    cr.rectangle(x + 2, y + 2, self.button_width - 4, h - 4)
                    cr.fill()
                elif menu_color:
                    cr.rectangle(x + self.button_width + 1, y + 2,
                                 self.menu_min - 3, h - 4)
                    cr.fill()

        if self.menu != None:
            # Draw an arrow.
            draw_pixbuf(
                cr, arrow_pixbuf.get_pixbuf(),
                x + self.button_width + (self.menu_min - arrow_width) / 2,
                y + (h - arrow_height) / 2)

        # Draw text.
        draw_text(cr,
                  self.label,
                  x,
                  y,
                  self.button_width,
                  h,
                  self.font_size,
                  text_color,
                  alignment=pango.ALIGN_CENTER)

        return True
Exemple #32
0
 def draw_treeview_mask(self, cr, x, y, width, height):
     cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FFFFFF", 0.9)))
     cr.rectangle(x, y, width, height)
     cr.fill()
Exemple #33
0
    def expose_time_spin(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("disable_frame").get_color()))
            else:
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("combo_entry_frame").get_color()))
            cr.rectangle(x, y, w, h)
            cr.stroke()

            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("disable_background").get_color(), 0.9)))
            else:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
            cr.rectangle(x, y, w - 1, h - 1)
            cr.fill()

        if self.set_time == self.SET_HOUR:
            cr.set_source_rgba(*color_hex_to_cairo(self.set_time_bg_color))
            cr.rectangle(x + self.padding_x, y, self.time_width, h)
            cr.fill()

        if self.set_time == self.SET_MIN:
            cr.set_source_rgba(*color_hex_to_cairo(self.set_time_bg_color))
            cr.rectangle(x + self.padding_x + self.time_width + self.time_comma_width,
                         y,
                         self.time_width,
                         h)
            cr.fill()

        if self.set_time == self.SET_SEC:
            cr.set_source_rgba(*color_hex_to_cairo(self.set_time_bg_color))
            cr.rectangle(x + self.padding_x + (self.time_width + self.time_comma_width) * 2,
                         y,
                         self.time_width,
                         h)
            cr.fill()

        if not self.__pressed_button:
            if self.__24hour:
                self.hour_value = time.localtime().tm_hour
            else:
                self.hour_value = int(time.strftime('%I'))
            self.min_value = time.localtime().tm_min
            self.sec_value = time.localtime().tm_sec

        draw_text(cr,
                  "%02d : %02d : %02d" % (self.hour_value, self.min_value, self.sec_value),
                  x + self.padding_x,
                  y,
                  w,
                  h)

        propagate_expose(widget, event)

        return False
Exemple #34
0
    def expose_cb(self, widget, event):
        '''
        Internal expose callback function.

        @param widget: Crumb instance.
        @param event: An event of gtk.gdk.Event.
        '''
        if self.menu == None:
            self.menu_min = 0
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Should move this part to Bread class since app_theme is golobalized.
        arrow_right = self.arrow_right
        arrow_down = self.arrow_down
        arrow_width, arrow_height = arrow_right.get_pixbuf().get_width(), arrow_right.get_pixbuf().get_height()
        arrow_pixbuf = arrow_right

        outside_border = alpha_color_hex_to_cairo(("#000000", 0.15))
        inner_border = alpha_color_hex_to_cairo(("#ffffff", 0.5))
        active_mask = alpha_color_hex_to_cairo(("#000000", 0.1))

        if self.menu_show:
            self.set_state(gtk.STATE_PRELIGHT)

        if widget.state == gtk.STATE_NORMAL:
            text_color = ui_theme.get_color("title_text").get_color()
            button_color = None
            menu_color = None
            arrow_pixbuf = arrow_right

        elif widget.state == gtk.STATE_PRELIGHT:
            text_color = ui_theme.get_color("title_text").get_color()
            if self.menu_show:
                arrow_pixbuf = arrow_down
            else:
                arrow_pixbuf = arrow_right

            if self.in_menu:
                button_color = None
                menu_color = inner_border
            else:
                button_color = inner_border
                menu_color = None

        elif widget.state == gtk.STATE_ACTIVE:
            text_color = ui_theme.get_color("title_text").get_color()
            if self.in_button:
                button_color = inner_border
                menu_color = None
                arrow_pixbuf = arrow_right
            else:
                button_color = None
                menu_color = inner_border
                arrow_pixbuf = arrow_down

        elif widget.state == gtk.STATE_INSENSITIVE:
            arrow_pixbuf = arrow_right
            text_color = ui_theme.get_color("disable_text").get_color()
            disable_bg = ui_theme.get_color("disable_background").get_color()
            button_color = [(0, (disable_bg, 1.0)),
                            (1, (disable_bg, 1.0))]
            menu_color = [(0, (disable_bg, 1.0)),
                            (1, (disable_bg, 1.0))]

        # Draw background.
        if not widget.state == gtk.STATE_NORMAL:
            # Draw button border.
            def draw_rectangle(cr, x, y , w, h):
                draw_line(cr, x -1 , y , x + w, y)          # top
                draw_line(cr, x , y + h, x + w, y + h)      # bottom
                draw_line(cr, x , y , x , y + h)            # left
                draw_line(cr, x + w , y , x + w , y + h -1) # right

            cr.set_source_rgba(*outside_border)
            if button_color:
                draw_rectangle(cr, x + 1 , y + 1 , self.button_width -1 , h -1)
            elif menu_color:
                draw_rectangle(cr, x + self.button_width, y + 1, self.menu_min, h - 1)

            # Draw innner border.
            cr.set_source_rgba(*inner_border)
            if button_color:
                draw_rectangle(cr, x + 2, y + 2, self.button_width - 3, h -3)
            elif menu_color:
                draw_rectangle(cr, x + self.button_width + 1, y + 2, self.menu_min - 2, h -3)

            if widget.state == gtk.STATE_ACTIVE:
                cr.set_source_rgba(*active_mask)
                if button_color:
                    cr.rectangle(x + 2, y + 2, self.button_width - 4, h -4)
                    cr.fill()
                elif menu_color:
                    cr.rectangle( x + self.button_width + 1, y + 2, self.menu_min - 3, h -4)
                    cr.fill()

        if self.menu != None:
            # Draw an arrow.
            draw_pixbuf(cr, arrow_pixbuf.get_pixbuf(), x + self.button_width + (self.menu_min - arrow_width) / 2, y + (h - arrow_height) / 2)

        # Draw text.
        draw_text(cr, self.label, x, y , self.button_width, h, self.font_size, text_color,
                    alignment = pango.ALIGN_CENTER)

        return True
Exemple #35
0
def draw_window_frame(
    cr,
    x,
    y,
    w,
    h,
    color_frame_outside_1,
    color_frame_outside_2,
    color_frame_outside_3,
    color_frame_inside_1,
    color_frame_inside_2,
):
    '''
    Draw window frame.

    @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.
    @param color_frame_outside_1: Use for draw outside 8 points.
    @param color_frame_outside_2: Use for draw middle 4 points.
    @param color_frame_outside_3: Use for draw inside 4 points.
    @param color_frame_inside_1: Use for draw outside frame.
    @param color_frame_inside_2: Use for draw inner frame and inside 4 points.
    '''
    with cairo_disable_antialias(cr):
        # Set line width.
        cr.set_line_width(1)

        # Set OPERATOR_OVER operator.
        cr.set_operator(cairo.OPERATOR_OVER)

        # Draw outside 8 points.
        cr.set_source_rgba(
            *alpha_color_hex_to_cairo(color_frame_outside_1.get_color_info()))

        cr.rectangle(x, y + 1, 1, 1)  # top-left
        cr.rectangle(x + 1, y, 1, 1)

        cr.rectangle(x + w - 1, y + 1, 1, 1)  # top-right
        cr.rectangle(x + w - 2, y, 1, 1)

        cr.rectangle(x, y + h - 2, 1, 1)  # bottom-left
        cr.rectangle(x + 1, y + h - 1, 1, 1)

        cr.rectangle(x + w - 1, y + h - 2, 1, 1)  # bottom-right
        cr.rectangle(x + w - 2, y + h - 1, 1, 1)

        cr.fill()

        # Draw outside 4 points.
        cr.set_source_rgba(
            *alpha_color_hex_to_cairo(color_frame_outside_2.get_color_info()))

        cr.rectangle(x + 1, y + 1, 1, 1)  # top-left

        cr.rectangle(x + w - 2, y + 1, 1, 1)  # top-right

        cr.rectangle(x + 1, y + h - 2, 1, 1)  # bottom-left

        cr.rectangle(x + w - 2, y + h - 2, 1, 1)  # bottom-right

        cr.fill()

        # Draw outside frame.
        cr.set_source_rgba(
            *alpha_color_hex_to_cairo(color_frame_outside_3.get_color_info()))

        cr.rectangle(x + 2, y, w - 4, 1)  # top side

        cr.rectangle(x + 2, y + h - 1, w - 4, 1)  # bottom side

        cr.rectangle(x, y + 2, 1, h - 4)  # left side

        cr.rectangle(x + w - 1, y + 2, 1, h - 4)  # right side

        cr.fill()

        # Draw outside 4 points.
        cr.set_source_rgba(
            *alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info()))

        cr.rectangle(x + 1, y + 1, 1, 1)  # top-left

        cr.rectangle(x + w - 2, y + 1, 1, 1)  # top-right

        cr.rectangle(x + 1, y + h - 2, 1, 1)  # bottom-left

        cr.rectangle(x + w - 2, y + h - 2, 1, 1)  # bottom-right

        cr.fill()

        # Draw inside 4 points.
        cr.set_source_rgba(
            *alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info()))

        cr.rectangle(x + 2, y + 2, 1, 1)  # top-left

        cr.rectangle(x + w - 3, y + 2, 1, 1)  # top-right

        cr.rectangle(x + 2, y + h - 3, 1, 1)  # bottom-left

        cr.rectangle(x + w - 3, y + h - 3, 1, 1)  # bottom-right

        cr.fill()

        # Draw inside frame.
        cr.set_source_rgba(
            *alpha_color_hex_to_cairo(color_frame_inside_2.get_color_info()))

        cr.rectangle(x + 2, y + 1, w - 4, 1)  # top side

        cr.rectangle(x + 2, y + h - 2, w - 4, 1)  # bottom side

        cr.rectangle(x + 1, y + 2, 1, h - 4)  # left side

        cr.rectangle(x + w - 2, y + 2, 1, h - 4)  # right side

        cr.fill()
Exemple #36
0
def draw_window_frame(cr, x, y, w, h,
                      color_frame_outside_1,
                      color_frame_outside_2,
                      color_frame_outside_3,
                      color_frame_inside_1,
                      color_frame_inside_2,
                      ):
    '''Draw window frame.'''
    with cairo_disable_antialias(cr):    
        # Set line width.
        cr.set_line_width(1)
        
        # Set OPERATOR_OVER operator.
        cr.set_operator(cairo.OPERATOR_OVER)
        
        # Draw outside 8 points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_1.get_color_info()))
        
        cr.rectangle(x, y + 1, 1, 1) # top-left
        cr.rectangle(x + 1, y, 1, 1)
        
        cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
        cr.rectangle(x + w - 2, y, 1, 1)
        
        cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
        cr.rectangle(x + 1, y + h - 1, 1, 1)
        
        cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
        cr.rectangle(x + w - 2, y + h - 1, 1, 1)
        
        cr.fill()
        
        # Draw outside 4 points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_2.get_color_info()))
        
        cr.rectangle(x + 1, y + 1, 1, 1) # top-left
        
        cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right
        
        cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left
        
        cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right
        
        cr.fill()
        
        # Draw outside frame.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_3.get_color_info()))

        cr.rectangle(x + 2, y, w - 4, 1) # top side
        
        cr.rectangle(x + 2, y + h - 1, w - 4, 1) # bottom side
        
        cr.rectangle(x, y + 2, 1, h - 4) # left side
        
        cr.rectangle(x + w - 1, y + 2, 1, h - 4) # right side
        
        cr.fill()
        
        # Draw outside 4 points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info()))
        
        cr.rectangle(x + 1, y + 1, 1, 1) # top-left
        
        cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right
        
        cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left
        
        cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right
        
        cr.fill()
        
        # Draw inside 4 points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info()))
        
        cr.rectangle(x + 2, y + 2, 1, 1) # top-left
        
        cr.rectangle(x + w - 3, y + 2, 1, 1) # top-right
        
        cr.rectangle(x + 2, y + h - 3, 1, 1) # bottom-left
        
        cr.rectangle(x + w - 3, y + h - 3, 1, 1) # bottom-right
        
        cr.fill()
        
        # Draw inside frame.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_2.get_color_info()))

        cr.rectangle(x + 2, y + 1, w - 4, 1) # top side
        
        cr.rectangle(x + 2, y + h - 2, w - 4, 1) # bottom side
        
        cr.rectangle(x + 1, y + 2, 1, h - 4) # left side
        
        cr.rectangle(x + w - 2, y + 2, 1, h - 4) # right side
        
        cr.fill()
Exemple #37
0
def draw_icon(cr,
              symbol="x",
              color=THEME['fg'],
              rect=None,
              opacity=None):
    width = min(rect[2], rect[3]) / 3
    offset_X = rect[0] + rect[2] / 2 - width / 2
    offset_Y = rect[1] + rect[3] / 2 - width / 2
    cr.set_line_width(width / 5)
    if opacity:
        cr.set_source_rgba(*alpha_color_hex_to_cairo(
            (color, opacity)
        ))
    else:
        cr.set_source_rgb(*color_hex_to_cairo(color))
    if symbol == "_":
        cr.move_to(offset_X, offset_Y + width)
        cr.rel_line_to(width, 0)
    elif symbol == "o":
        cr.rectangle(offset_X, offset_Y,
                     width, width)
    elif symbol == "s":
        cr.move_to(offset_X, offset_Y)
        cr.rel_line_to(width, 0)
        cr.move_to(offset_X, offset_Y + width / 3)
        cr.rel_line_to(width, 0)
        cr.rel_line_to(-width / 2, width / 3 * 2)
        cr.rel_line_to(-width / 2, -width / 3 * 2)
    elif symbol == "unchecked":
        cr.rectangle(offset_X - width / 4,
                     offset_Y - width / 4,
                     width * 3 / 2,
                     width * 3 / 2)
    elif symbol == "checked":
        cr.rectangle(offset_X - width / 4,
                     offset_Y - width / 4,
                     width * 3 / 2,
                     width * 3 / 2)
        cr.move_to(offset_X, offset_Y + width / 2)
        cr.rel_line_to(width / 3, width / 2)
        cr.rel_line_to(width * 3 / 4, -width)
    elif symbol == "untoggled":
        cr.arc(offset_X + width / 2, offset_Y + width / 2,
               width * 3 / 4, 0, 2 * pi)
    elif symbol == "toggled":
        cr.arc(offset_X + width / 2, offset_Y + width / 2,
               width * 3 / 4, 0, 2 * pi)
        cr.move_to(offset_X, offset_Y + width / 2)
        cr.rel_line_to(width / 3, width / 2)
        cr.rel_line_to(width * 3 / 4, -width)
    elif symbol == "go_left":
        cr.set_line_cap(cairo.LINE_CAP_ROUND)
        cr.set_line_join(cairo.LINE_JOIN_BEVEL)
        cr.move_to(offset_X, offset_Y + width / 2)
        cr.rel_line_to(width, -width)
        cr.move_to(offset_X, offset_Y + width / 2)
        cr.rel_line_to(width, width)
    elif symbol == "go_right":
        cr.set_line_cap(cairo.LINE_CAP_ROUND)
        cr.set_line_join(cairo.LINE_JOIN_BEVEL)
        cr.move_to(offset_X + width, offset_Y + width / 2)
        cr.rel_line_to(-width, -width)
        cr.move_to(offset_X + width, offset_Y + width / 2)
        cr.rel_line_to(-width, width)
    elif symbol == "catelog":
        width = width * 2 / 3
        offset_X += width * 2 / 3
        offset_Y += width / 2
        cr.rectangle(offset_X - width / 2 - 1,
                     offset_Y - width / 2 - 1,
                     width, width)
        cr.rectangle(offset_X - width / 2 - 1,
                     offset_Y + width / 2 + 1,
                     width, width)
        cr.rectangle(offset_X + width / 2 + 1,
                     offset_Y - width / 2 - 1,
                     width, width)
        cr.rectangle(offset_X + width / 2 + 1,
                     offset_Y + width / 2 + 1,
                     width, width)
        cr.fill()
    elif symbol == "config":
        cr.rectangle(offset_X - width / 2 - 2,
                     offset_Y + width / 6,
                     width * 2 / 3,
                     width * 2 / 3)
        cr.rectangle(offset_X + width / 6,
                     offset_Y + width / 6,
                     width * 2 / 3,
                     width * 2 / 3)
        cr.rectangle(offset_X + width * 5 / 6 + 2,
                     offset_Y + width / 6,
                     width * 2 / 3,
                     width * 2 / 3)
        cr.fill()

    else:
        cr.move_to(offset_X, offset_Y)
        cr.rel_line_to(width, width)
        cr.move_to(offset_X, offset_Y + width)
        cr.rel_line_to(width, -width)

    cr.stroke()
    return True
Exemple #38
0
    def expose_time_spin(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgb(*color_hex_to_cairo(
                    ui_theme.get_color("disable_frame").get_color()))
            else:
                cr.set_source_rgb(*color_hex_to_cairo(
                    ui_theme.get_color("combo_entry_frame").get_color()))
            cr.rectangle(x, y, w, h)
            cr.stroke()

            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((
                    ui_theme.get_color("disable_background").get_color(),
                    0.9)))
            else:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((
                    ui_theme.get_color("combo_entry_background").get_color(),
                    0.9)))
            cr.rectangle(x, y, w - 1, h - 1)
            cr.fill()

        if self.set_time == self.SET_HOUR:
            cr.set_source_rgba(*color_hex_to_cairo(self.set_time_bg_color))
            cr.rectangle(x + self.padding_x, y, self.time_width, h)
            cr.fill()

        if self.set_time == self.SET_MIN:
            cr.set_source_rgba(*color_hex_to_cairo(self.set_time_bg_color))
            cr.rectangle(
                x + self.padding_x + self.time_width + self.time_comma_width,
                y, self.time_width, h)
            cr.fill()

        if self.set_time == self.SET_SEC:
            cr.set_source_rgba(*color_hex_to_cairo(self.set_time_bg_color))
            cr.rectangle(
                x + self.padding_x +
                (self.time_width + self.time_comma_width) * 2, y,
                self.time_width, h)
            cr.fill()

        if not self.__pressed_button:
            if self.__24hour:
                self.hour_value = time.localtime().tm_hour
            else:
                self.hour_value = int(time.strftime('%I'))
            self.min_value = time.localtime().tm_min
            self.sec_value = time.localtime().tm_sec

        draw_text(
            cr, "%02d : %02d : %02d" %
            (self.hour_value, self.min_value, self.sec_value),
            x + self.padding_x, y, w, h)

        propagate_expose(widget, event)

        return False
Exemple #39
0
    def expose_text_entry(self, widget, event):
        '''Callback for `expose-event` signal.'''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height
        
        # Draw background.
        with cairo_state(cr):
            cr.rectangle(x + 2, y, w - 4, 1)
            cr.rectangle(x + 1, y + 1, w - 2, 1)
            cr.rectangle(x, y + 2, w, h - 4)
            cr.rectangle(x + 2, y + h - 1, w - 4, 1)
            cr.rectangle(x + 1, y + h - 2, w - 2, 1)
            cr.clip()
            
            cr.set_source_rgba(*alpha_color_hex_to_cairo(self.background_color.get_color_info()))
            cr.rectangle(x, y, w, h)
            cr.fill()

        # Draw background four acme points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(self.acme_color.get_color_info()))
        cr.rectangle(x, y, 1, 1)
        cr.rectangle(x + w - 1, y, 1, 1)
        cr.rectangle(x, y + h - 1, 1, 1)
        cr.rectangle(x + w - 1, y + h - 1, 1, 1)
        cr.fill()

        # Draw background eight points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(self.point_color.get_color_info()))
        
        cr.rectangle(x + 1, y, 1, 1)
        cr.rectangle(x, y + 1, 1, 1)
        
        cr.rectangle(x + w - 2, y, 1, 1)
        cr.rectangle(x + w - 1, y + 1, 1, 1)
        
        cr.rectangle(x, y + h - 2, 1, 1)
        cr.rectangle(x + 1, y + h - 1, 1, 1)

        cr.rectangle(x + w - 1, y + h - 2, 1, 1)
        cr.rectangle(x + w - 2, y + h - 1, 1, 1)
        
        cr.fill()
        
        # Draw frame point.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(self.frame_point_color.get_color_info()))
        
        cr.rectangle(x + 1, y, 1, 1)
        cr.rectangle(x, y + 1, 1, 1)
        
        cr.rectangle(x + w - 2, y, 1, 1)
        cr.rectangle(x + w - 1, y + 1, 1, 1)
        
        cr.rectangle(x, y + h - 2, 1, 1)
        cr.rectangle(x + 1, y + h - 1, 1, 1)

        cr.rectangle(x + w - 1, y + h - 2, 1, 1)
        cr.rectangle(x + w - 2, y + h - 1, 1, 1)
        
        cr.fill()
        
        # Draw frame.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(self.frame_color.get_color_info()))
        
        cr.rectangle(x + 2, y, w - 4, 1)
        cr.rectangle(x, y + 2, 1, h - 4)
        cr.rectangle(x + 2, y + h - 1, w - 4, 1)
        cr.rectangle(x + w - 1, y + 2, 1, h - 4)
        
        cr.fill()
        
        propagate_expose(widget, event)
        
        return True
Exemple #40
0
 def expose_tab_title_box(self, widget, event):
     '''Expose tab title box.'''
     cr = widget.window.cairo_create()
     rect = widget.allocation
     
     # Draw title unselect tab.
     tab_title_width = sum(self.tab_title_widths)
     
     with cairo_state(cr):
         with cairo_disable_antialias(cr):
             cr.rectangle(rect.x,
                          rect.y,
                          sum(self.tab_title_widths[0:self.tab_index]),
                          self.tab_height)
             cr.rectangle(rect.x + sum(self.tab_title_widths[0:min(self.tab_index + 1, len(self.tab_items))]) + 1,
                          rect.y,
                          sum(self.tab_title_widths) - sum(self.tab_title_widths[0:min(self.tab_index + 1, len(self.tab_items))]),
                          self.tab_height)
             cr.clip()
             
             cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_bg_color.get_color(), 0.7)))
             cr.rectangle(rect.x + 1, rect.y + 1, tab_title_width, self.tab_height)
             cr.fill()
                 
             cr.set_line_width(1)
             cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_frame_color.get_color(), 1.0)))
             cr.rectangle(rect.x + 1, rect.y + 1, tab_title_width, self.tab_height)
             cr.stroke()
             
             for (index, width) in enumerate(self.tab_title_widths[:-1]):
                 cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_frame_color.get_color(), 1.0)))
                 cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:index]) + width,
                              rect.y + 1,
                              1,
                              self.tab_height)
                 cr.fill()
                 
             cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))    
             cr.rectangle(rect.x,
                          rect.y + rect.height - 1,
                          sum(self.tab_title_widths[0:self.tab_index]),
                          1)
             cr.fill()
         
             cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))    
             cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:self.tab_index]),
                          rect.y + rect.height - 1,
                          rect.width - sum(self.tab_title_widths[0:self.tab_index]),
                          1)
             cr.fill()
                     
     for (index, item) in enumerate(self.tab_items):
         # Draw title background.
         title = item[0]
         
         # Draw title tab.
         with cairo_disable_antialias(cr):
             if index == self.tab_index:
                 # Draw title select tab.
                 cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_select_bg_color.get_color(), 0.93)))    
                 if index == 0:
                     cr.rectangle(rect.x + sum(self.tab_title_widths[0:index]),
                                  rect.y + 1,
                                  self.tab_title_widths[index] + 1,
                                  self.tab_height)
                 else:
                     cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:index]),
                                  rect.y + 1,
                                  self.tab_title_widths[index],
                                  self.tab_height)
                 cr.fill()
                 
                 if index == 0:
                     cr.rectangle(rect.x,
                                  rect.y,
                                  rect.width,
                                  self.tab_height)
                     cr.clip()
                     
                 cr.set_line_width(1)
                 cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))    
                 if index == 0:
                     cr.rectangle(rect.x + sum(self.tab_title_widths[0:index]),
                                  rect.y + 1,
                                  self.tab_title_widths[index] + 2,
                                  self.tab_height)
                 else:
                     cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:index]),
                                  rect.y + 1,
                                  self.tab_title_widths[index] + 1,
                                  self.tab_height)
                 cr.stroke()
                 
         draw_text(cr, title, 
                     rect.x + sum(self.tab_title_widths[0:index]) + self.tab_padding_x,
                     rect.y + self.tab_padding_y,
                     self.tab_title_widths[index] - self.tab_padding_x * 2,
                     self.tab_height - self.tab_padding_y * 2,
                     )
Exemple #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
Exemple #42
0
def draw_window_frame(cr, x, y, w, h,
                      color_frame_outside_1,
                      color_frame_outside_2,
                      color_frame_outside_3,
                      color_frame_inside_1,
                      color_frame_inside_2,
                      ):
    '''
    Draw window frame.
    
    @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.
    @param color_frame_outside_1: Use for draw outside 8 points.
    @param color_frame_outside_2: Use for draw middle 4 points.
    @param color_frame_outside_3: Use for draw inside 4 points.
    @param color_frame_inside_1: Use for draw outside frame.
    @param color_frame_inside_2: Use for draw inner frame and inside 4 points.
    '''
    with cairo_disable_antialias(cr):    
        # Set line width.
        cr.set_line_width(1)
        
        # Set OPERATOR_OVER operator.
        cr.set_operator(cairo.OPERATOR_OVER)
        
        # Draw outside 8 points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_1.get_color_info()))
        
        cr.rectangle(x, y + 1, 1, 1) # top-left
        cr.rectangle(x + 1, y, 1, 1)
        
        cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
        cr.rectangle(x + w - 2, y, 1, 1)
        
        cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
        cr.rectangle(x + 1, y + h - 1, 1, 1)
        
        cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
        cr.rectangle(x + w - 2, y + h - 1, 1, 1)
        
        cr.fill()
        
        # Draw outside 4 points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_2.get_color_info()))
        
        cr.rectangle(x + 1, y + 1, 1, 1) # top-left
        
        cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right
        
        cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left
        
        cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right
        
        cr.fill()
        
        # Draw outside frame.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_3.get_color_info()))

        cr.rectangle(x + 2, y, w - 4, 1) # top side
        
        cr.rectangle(x + 2, y + h - 1, w - 4, 1) # bottom side
        
        cr.rectangle(x, y + 2, 1, h - 4) # left side
        
        cr.rectangle(x + w - 1, y + 2, 1, h - 4) # right side
        
        cr.fill()
        
        # Draw outside 4 points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info()))
        
        cr.rectangle(x + 1, y + 1, 1, 1) # top-left
        
        cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right
        
        cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left
        
        cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right
        
        cr.fill()
        
        # Draw inside 4 points.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info()))
        
        cr.rectangle(x + 2, y + 2, 1, 1) # top-left
        
        cr.rectangle(x + w - 3, y + 2, 1, 1) # top-right
        
        cr.rectangle(x + 2, y + h - 3, 1, 1) # bottom-left
        
        cr.rectangle(x + w - 3, y + h - 3, 1, 1) # bottom-right
        
        cr.fill()
        
        # Draw inside frame.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_2.get_color_info()))

        cr.rectangle(x + 2, y + 1, w - 4, 1) # top side
        
        cr.rectangle(x + 2, y + h - 2, w - 4, 1) # bottom side
        
        cr.rectangle(x + 1, y + 2, 1, h - 4) # left side
        
        cr.rectangle(x + w - 2, y + 2, 1, h - 4) # right side
        
        cr.fill()
Exemple #43
0
    def draw_tab(self, cr, x, y, tab_name, tab_index):
        # Init.
        (text_width, text_height) = get_content_size(tab_name)
        tab_x = x
        tab_y = y
        tab_height = self.height
        triangle_width = int(tab_height / math.tan(math.radians(self.tab_angle)))
        middle_width = text_width + self.tab_name_padding_x * 2
        tab_width = middle_width + self.tab_radious * 4 + triangle_width * 2
        round_radious = self.tab_radious * math.tan(math.radians((180 - self.tab_angle) / 2))
        round_angle = self.tab_angle
        
        if tab_index == self.active_index:
            frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_active_frame").get_color_info())        
            background_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_active_background").get_color_info())        
            top_frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_top_active_frame").get_color_info())        
        else:
            frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_inactive_frame").get_color_info())        
            background_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_inactive_background").get_color_info())        
            top_frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_top_inactive_frame").get_color_info())        
            
        # Init round coordinate.
        round_left_bottom_x = tab_x
        round_left_bottom_y = tab_y + tab_height - round_radious

        round_left_up_x = tab_x + self.tab_radious * 2 + triangle_width
        round_left_up_y = tab_y + round_radious

        round_right_bottom_x = tab_x + tab_width
        round_right_bottom_y = tab_y + tab_height - round_radious

        round_right_up_x = tab_x + tab_width - (self.tab_radious * 2 + triangle_width)
        round_right_up_y = tab_y + round_radious
        
        # Clip.
        with cairo_state(cr):
            # Clip.
            if tab_index != self.active_index and tab_index != 0:
                clip_offset_x = tab_width - (self.triangle_width + self.tab_radious * 2)
                cr.move_to(tab_x + tab_width - clip_offset_x, tab_y + tab_height)
                cr.arc(round_right_bottom_x - clip_offset_x,
                       round_right_bottom_y,
                       round_radious,
                       math.radians(90),
                       math.radians(90 + round_angle),
                       )
                
                cr.line_to(tab_x + tab_width - self.tab_radious - self.triangle_width + self.tab_radious_offset_x - clip_offset_x,
                           tab_y)
                
                cr.line_to(tab_x + tab_width, tab_y)
                cr.line_to(tab_x + tab_width, tab_y + tab_height)
                cr.line_to(tab_x + tab_width - clip_offset_x, tab_y + tab_height)
            else:
                cr.rectangle(tab_x, tab_y, tab_width, tab_height)
            cr.clip()
                
            # Draw background.
            # Draw left area.
            with cairo_state(cr):
                cr.move_to(tab_x, tab_y + tab_height)
                cr.arc_negative(round_left_bottom_x,
                                round_left_bottom_y,
                                round_radious,
                                math.radians(90),
                                math.radians(90 - round_angle),
                                )
                
                cr.line_to(tab_x + self.tab_radious + self.tab_radious_offset_x,
                           tab_y + tab_height - self.tab_radious_offset_y)
                
                cr.arc(round_left_up_x,
                       round_left_up_y,
                       round_radious,
                       math.radians(270 - round_angle),
                       math.radians(270))
            
            # Draw top area.
            with cairo_disable_antialias(cr):    
                cr.set_source_rgba(*frame_color)
                cr.set_line_width(1)
                cr.line_to(tab_x + self.tab_radious * 2 + triangle_width + middle_width, tab_y + 1)
            
            # Draw right area.
            with cairo_state(cr):
                cr.arc(round_right_up_x,
                       round_right_up_y,
                       round_radious,
                       math.radians(270),
                       math.radians(270 + round_angle),
                       )
                
                cr.line_to(tab_x + tab_width - (self.tab_radious + self.tab_radious_offset_x),
                           tab_y + tab_height - self.tab_radious_offset_y)
                
                cr.arc_negative(round_right_bottom_x,
                                round_right_bottom_y,
                                round_radious,
                                math.radians(90 + round_angle),
                                math.radians(90))
                
            cr.line_to(tab_x, tab_y + tab_height)
            
            cr.set_source_rgba(*background_color)
            cr.fill()
            
            # Draw frame.
            # Draw left area.
            with cairo_state(cr):
                cr.move_to(tab_x, tab_y + tab_height)
                cr.arc_negative(round_left_bottom_x,
                                round_left_bottom_y,
                                round_radious,
                                math.radians(90),
                                math.radians(90 - round_angle),
                                )
                
                cr.line_to(tab_x + self.tab_radious + self.tab_radious_offset_x,
                           tab_y + tab_height - self.tab_radious_offset_y)
                
                cr.arc(round_left_up_x,
                       round_left_up_y,
                       round_radious,
                       math.radians(270 - round_angle),
                       math.radians(270))
            
                cr.set_source_rgba(*frame_color)
                cr.set_line_width(1)
                cr.stroke()
                
            # Draw top area.
            with cairo_disable_antialias(cr):    
                offset = 1
                cr.set_source_rgba(*top_frame_color)
                cr.set_line_width(1)
                cr.move_to(tab_x + self.tab_radious * 2 + triangle_width - offset, tab_y + 1)
                cr.line_to(tab_x + self.tab_radious * 2 + triangle_width + middle_width + offset * 2, tab_y + 1)
                cr.stroke()
            
            # Draw right area.
            with cairo_state(cr):
                cr.move_to(tab_x + tab_width - (self.tab_radious * 2 + triangle_width), tab_y)
                cr.arc(round_right_up_x,
                       round_right_up_y,
                       round_radious,
                       math.radians(270),
                       math.radians(270 + round_angle),
                       )
                
                cr.line_to(tab_x + tab_width - (self.tab_radious + self.tab_radious_offset_x),
                           tab_y + tab_height - self.tab_radious_offset_y)
                
                cr.arc_negative(round_right_bottom_x,
                                round_right_bottom_y,
                                round_radious,
                                math.radians(90 + round_angle),
                                math.radians(90))
            
                cr.set_source_rgba(*frame_color)
                cr.set_line_width(1)
                cr.stroke()
            
            # Draw text.
            draw_text(cr, tab_name, tab_x, tab_y, tab_width, tab_height, alignment=pango.ALIGN_CENTER)
Exemple #44
0
 def draw_treeview_mask(self, cr, x, y, width, height):
     cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FFFFFF", 0.9)))
     cr.rectangle(x, y, width, height)
     cr.fill()
    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
Exemple #46
0
    def expose_tab_title_box(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        if self.dockfill:
            self.update_tab_title_widths(rect.width)

        # Draw background.
        self.draw_title_background(cr, widget)
            
        if len(self.tab_items) > 0:    
            # Draw title unselect tab.
            tab_title_width = sum(self.tab_title_widths)
            
            with cairo_state(cr):
                with cairo_disable_antialias(cr):
                    cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_bg_color.get_color(), 0.7)))
                    cr.rectangle(1, 1, tab_title_width, self.tab_height)
                    cr.fill()
                        
                    cr.set_line_width(1)
                    cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_frame_color.get_color(), 1.0)))
                    cr.rectangle(1, 1, tab_title_width, self.tab_height)
                    cr.stroke()
                    
                    for (index, width) in enumerate(self.tab_title_widths[:-1]):
                        cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_frame_color.get_color(), 1.0)))
                        cr.rectangle(1 + sum(self.tab_title_widths[0:index]) + width,
                                     1,
                                     1,
                                     self.tab_height)
                        cr.fill()
                        
                    cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))    
                    cr.rectangle(0,
                                 rect.height - 1,
                                 sum(self.tab_title_widths[0:self.tab_index]),
                                 1)
                    cr.fill()
                
                    cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))    
                    cr.rectangle(1 + sum(self.tab_title_widths[0:self.tab_index]),
                                 rect.height - 1,
                                 rect.width - sum(self.tab_title_widths[0:self.tab_index]),
                                 1)
                    cr.fill()
                            
            for (index, item) in enumerate(self.tab_items):
                # Draw title background.
                title = item[0]
                
                # Draw title tab.
                with cairo_disable_antialias(cr):
                    if index == self.tab_index:
                        # Draw title select tab.
                        cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_select_bg_color.get_color(), 0.93)))    
                        if index == 0:
                            cr.rectangle(sum(self.tab_title_widths[0:index]),
                                         1,
                                         self.tab_title_widths[index] + 1,
                                         self.tab_height)
                        else:
                            cr.rectangle(1 + sum(self.tab_title_widths[0:index]),
                                         1,
                                         self.tab_title_widths[index],
                                         self.tab_height)
                        cr.fill()
                        
                        if index == 0:
                            cr.rectangle(0,
                                         0,
                                         rect.width,
                                         self.tab_height)
                            cr.clip()
                            
                        cr.set_line_width(1)
                        cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))    
                        if index == 0:
                            cr.rectangle(sum(self.tab_title_widths[0:index]),
                                         1,
                                         self.tab_title_widths[index] + 2,
                                         self.tab_height)
                        else:
                            cr.rectangle(1 + sum(self.tab_title_widths[0:index]),
                                         1,
                                         self.tab_title_widths[index] + 1,
                                         self.tab_height)
                        cr.stroke()
                        
                draw_text(cr, title, 
                          sum(self.tab_title_widths[0:index]) + self.tab_padding_x,
                          self.tab_padding_y,
                          self.tab_title_widths[index] - self.tab_padding_x * 2,
                          self.tab_height - self.tab_padding_y * 2,
                          )
                
                # Draw close button.
                if self.can_close_tab:
                    button_x = sum(self.tab_title_widths[0:index + 1]) - self.close_button_padding_x - self.close_button_size
                    button_y = self.close_button_padding_y
                    
                    if self.hover_close_button_index == index:
                        cr.set_source_rgb(*color_hex_to_cairo(self.close_button_select_background_color))
                        draw_round_rectangle(
                            cr,
                            button_x - self.close_button_frame_size,
                            button_y - self.close_button_frame_size,
                            self.close_button_size + self.close_button_frame_size * 2,
                            self.close_button_size + self.close_button_frame_size * 2,
                            2
                            )
                        cr.fill()
                    
                    cr.set_line_width(1.5)
                    if self.hover_close_button_index == index:
                        cr.set_source_rgb(*color_hex_to_cairo(self.close_button_select_foreground_color))
                    else:
                        cr.set_source_rgb(*color_hex_to_cairo(self.close_button_color))
                    cr.move_to(button_x, button_y)
                    cr.line_to(button_x + self.close_button_size, button_y + self.close_button_size)
                    cr.stroke()

                    cr.move_to(button_x + self.close_button_size, button_y)
                    cr.line_to(button_x, button_y + self.close_button_size)
                    cr.stroke()
        else:
            cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_select_bg_color.get_color(), 0.93)))
            cr.rectangle(0, 0, rect.width, rect.height)
            cr.fill()