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

        cr.set_source_rgb(0.0, 0.0, 0.0)
        cr.set_operator(cairo.OPERATOR_CLEAR)
        cr.paint()
        
        cr.set_operator(cairo.OPERATOR_OVER)
        with cairo_disable_antialias(cr):
            draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, 4)
            cr.fill()
        widget.shape_combine_mask(bitmap, 0, 0)        
    def expose_button(self, widget, event, font_size, label_dcolor):
        # Init.
        rect = widget.allocation
        image = self.pixbuf_normal.get_pixbuf()
        
        # Get pixbuf along with button's sate.
        if widget.state == gtk.STATE_NORMAL:
            image = self.pixbuf_normal.get_pixbuf()
            label_dcolor = app_theme.get_color('button_text_fg_normal')
            bg_dcolor = app_theme.get_alpha_color('button_bg_normal')
        elif widget.state == gtk.STATE_PRELIGHT:
            image = self.pixbuf_hover.get_pixbuf()
            label_dcolor = app_theme.get_color('button_text_fg_hover')
            bg_dcolor = app_theme.get_alpha_color('button_bg_hover')
        elif widget.state == gtk.STATE_ACTIVE:
            image = self.pixbuf_press.get_pixbuf()
            label_dcolor = app_theme.get_color('button_text_fg_press')
            bg_dcolor = app_theme.get_alpha_color('button_bg_press')
        
        # Draw button.
        cr = widget.window.cairo_create()
        draw_pixbuf(cr, image, rect.x + self.padding_edge, rect.y)
        
        # Draw font.
        if widget.state == gtk.STATE_INSENSITIVE:
            label_color = ui_theme.get_color("disable_text").get_color()
        else:
            label_color = label_dcolor.get_color()
        if self.button_label:
            draw_text(cr, self.button_label, 
                        rect.x + image.get_width() + self.padding_edge + self.padding_middle,
                        rect.y, 
                        rect.width - image.get_width() - self.padding_middle - self.padding_edge*2,
                        rect.height,
                        font_size, 
                        label_color,
                        alignment=pango.ALIGN_LEFT
                        )

        if self.draw_background:
            cr.set_source_rgba(*alpha_color_hex_to_cairo(bg_dcolor.get_color_info()))
            draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, rect.height/2)
            cr.fill()
    
        # Propagate expose to children.
        propagate_expose(widget, event)
        
        return True
Example #3
0
 def __render_blur(self, cr, rect):
     x, y, w, h = rect
     
     img_surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
     img_surf_cr = cairo.Context(img_surf)
     draw_round_rectangle(img_surf_cr, x + 3, y + 3, w - 6, h - 6, BORDER_RADIOUS)
     
     img_surf_cr.set_source_rgb(0, 0, 0)
     img_surf_cr.set_line_width(1)
     img_surf_cr.stroke()
     gaussian_blur(img_surf, 2)
     
     cr.set_operator(cairo.OPERATOR_SOURCE)
     cr.set_source_surface(img_surf, 0, 0)
     cr.rectangle(*rect)
     cr.fill()
     
     cr.set_source_rgb(0, 0, 0)
     cr.set_line_width(1)
     draw_round_rectangle(cr, x + 3, y + 3, w - 6, h - 6, BORDER_RADIOUS)
     cr.stroke_preserve()
     
     cr.clip()
    def expose_nav_item(self, widget, event):
        """
        Internal callback `expose-event` signal.
        """
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        select_index = self.get_index()
        hover_pixbuf = self.item_hover_pixbuf.get_pixbuf()
        press_pixbuf = self.item_press_pixbuf.get_pixbuf()

        # Draw background.
        if widget.state == gtk.STATE_NORMAL:
            if select_index == self.index:
                select_pixbuf = press_pixbuf
            else:
                select_pixbuf = None
        elif widget.state == gtk.STATE_PRELIGHT:
            if select_index == self.index:
                select_pixbuf = press_pixbuf
            else:
                select_pixbuf = hover_pixbuf
        elif widget.state == gtk.STATE_ACTIVE:
            select_pixbuf = press_pixbuf

        if select_pixbuf:
            to_draw_pixbuf = select_pixbuf
        elif self.item_normal_pixbuf:
            to_draw_pixbuf = self.item_normal_pixbuf.get_pixbuf()
        if self.pixbuf_width_scale:
            to_draw_pixbuf = to_draw_pixbuf.scale_simple(
                self.item_button.get_size_request()[0], self.item_button.get_size_request()[1], gtk.gdk.INTERP_BILINEAR
            )

        draw_pixbuf(cr, to_draw_pixbuf, rect.x, rect.y)
        # cr.set_source_rgba(1, 1, 1, 0.3)
        # draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, 0)
        # cr.fill()

        # Draw navigate item.
        if self.icon_dpixbuf:
            nav_item_pixbuf = self.icon_dpixbuf.get_pixbuf()
            nav_item_pixbuf_width = nav_item_pixbuf.get_width()
            nav_item_pixbuf_height = nav_item_pixbuf.get_height()
            padding_x = (rect.width - nav_item_pixbuf_width - self.text_width) / 2

            draw_pixbuf(cr, nav_item_pixbuf, rect.x + padding_x, rect.y + (rect.height - nav_item_pixbuf_height) / 2)
        else:
            nav_item_pixbuf_width = 0
            nav_item_pixbuf_height = 0
            padding_x = (rect.width - nav_item_pixbuf_width - self.text_width) / 2 - 1

        draw_text(
            cr,
            self.content,
            rect.x + nav_item_pixbuf_width + padding_x,
            rect.y,
            rect.width,
            rect.height,
            text_size=self.font_size,
            text_color="#FFFFFF",
            gaussian_radious=2,
            gaussian_color="#000000",
            border_radious=1,
            border_color="#000000",
        )

        # Draw notify number.
        text_size = 8
        (number_width, number_height) = get_content_size(str(self.notify_num), text_size)
        padding_x = 2
        padding_y = 0
        radious = 3
        draw_offset_x = -5
        draw_offset_y = 8
        draw_x = rect.x + nav_item_pixbuf_width + padding_x + draw_offset_x
        draw_y = rect.y + draw_offset_y
        if self.notify_num > 0:
            cr.set_source_rgb(*color_hex_to_cairo("#BF0000"))
            draw_round_rectangle(
                cr, draw_x, draw_y, number_width + padding_x * 2, number_height + padding_y * 2, radious
            )
            cr.fill()

            draw_text(
                cr,
                str(self.notify_num),
                draw_x + padding_x,
                draw_y + padding_y,
                number_width,
                number_height,
                text_color="#FFFFFF",
                text_size=text_size,
            )

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

        return True
    def expose_toggle_button(self, widget, event, font_size, label_dcolor):
        '''
        Callback for `expose-event` signal.
        
        @param widget: ToggleButton widget.
        @param event: Expose event.
        @param button_label: Button label string.
        @param padding_x: horticultural padding value.
        @param font_size: Font size.
        @param label_dcolor: Label DynamicColor.
        '''
        # Init.
        inactive_normal_dpixbuf, inactive_hover_dpixbuf, inactive_press_dpixbuf, inactive_disable_dpixbuf = self.inactive_pixbuf_group
        active_normal_dpixbuf, active_hover_dpixbuf, active_press_dpixbuf, active_disable_dpixbuf = self.active_pixbuf_group
        rect = widget.allocation
        image = inactive_normal_dpixbuf.get_pixbuf()

        if not widget.get_active():
            button_label = self.active_button_label
        else:
            button_label = self.inactive_button_label

        # Get pixbuf along with button's sate.
        if widget.state == gtk.STATE_INSENSITIVE:
            if widget.get_active():
                image = active_disable_dpixbuf.get_pixbuf()
            else:
                image = inactive_disable_dpixbuf.get_pixbuf()
        elif widget.state == gtk.STATE_NORMAL:
            label_dcolor = app_theme.get_color('button_text_fg_normal')
            bg_dcolor = app_theme.get_alpha_color('button_bg_normal')
            image = inactive_normal_dpixbuf.get_pixbuf()
        elif widget.state == gtk.STATE_PRELIGHT:
            label_dcolor = app_theme.get_color('button_text_fg_hover')
            bg_dcolor = app_theme.get_alpha_color('button_bg_hover')
            if not inactive_hover_dpixbuf and not active_hover_dpixbuf:
                if widget.get_active():
                    image = active_normal_dpixbuf.get_pixbuf()
                else:    
                    image = inactive_normal_dpixbuf.get_pixbuf()
            else:    
                if inactive_hover_dpixbuf and active_hover_dpixbuf:
                    if widget.get_active():
                        image = active_hover_dpixbuf.get_pixbuf()
                    else:    
                        image = inactive_hover_dpixbuf.get_pixbuf()
                elif inactive_hover_dpixbuf:        
                    image = inactive_hover_dpixbuf.get_pixbuf()
                elif active_hover_dpixbuf:    
                    image = active_hover_dpixbuf.get_pixbuf()
        elif widget.state == gtk.STATE_ACTIVE:
            if inactive_press_dpixbuf and active_press_dpixbuf:
                if self.button_press_flag:
                    label_dcolor = app_theme.get_color('button_text_fg_press')
                    bg_dcolor = app_theme.get_alpha_color('button_bg_press')
                    if widget.get_active():
                        image = active_press_dpixbuf.get_pixbuf()
                    else:    
                        image = inactive_press_dpixbuf.get_pixbuf()
                else:    
                    label_dcolor = app_theme.get_color('button_text_fg_normal')
                    bg_dcolor = app_theme.get_alpha_color('button_bg_normal')
                    image = active_normal_dpixbuf.get_pixbuf()
            else:        
                image = active_normal_dpixbuf.get_pixbuf()
        
        # Draw button.
        cr = widget.window.cairo_create()
        draw_pixbuf(cr, image, rect.x + self.padding_edge, rect.y)
        
        # Draw font.
        if widget.state == gtk.STATE_INSENSITIVE:
            label_color = ui_theme.get_color("disable_text").get_color()
        else:
            label_color = label_dcolor.get_color()
        if button_label:
            draw_text(cr, button_label, 
                        rect.x + image.get_width() + self.padding_edge + self.padding_middle,
                        rect.y, 
                        rect.width - image.get_width() - self.padding_edge * 2 - self.padding_middle + self.more_width,
                        rect.height,
                        font_size, 
                        label_color,
                        alignment=pango.ALIGN_LEFT
                        )

        if self.draw_background:
            cr.set_source_rgba(*alpha_color_hex_to_cairo(bg_dcolor.get_color_info()))
            draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, rect.height/2)
            cr.fill()
    
        # Propagate expose to children.
        propagate_expose(widget, event)
        
        return True
Example #6
0
    def expose_nav_item(self, widget, event):
        '''
        Internal callback `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        select_index = self.get_index()
        hover_pixbuf = self.item_hover_pixbuf.get_pixbuf()
        press_pixbuf = self.item_press_pixbuf.get_pixbuf()

        # Draw background.
        if widget.state == gtk.STATE_NORMAL:
            if select_index == self.index:
                select_pixbuf = press_pixbuf
            else:
                select_pixbuf = None
        elif widget.state == gtk.STATE_PRELIGHT:
            if select_index == self.index:
                select_pixbuf = press_pixbuf
            else:
                select_pixbuf = hover_pixbuf
        elif widget.state == gtk.STATE_ACTIVE:
            select_pixbuf = press_pixbuf

        if select_pixbuf:
            to_draw_pixbuf = select_pixbuf
        elif self.item_normal_pixbuf:
            to_draw_pixbuf = self.item_normal_pixbuf.get_pixbuf()
        if self.pixbuf_width_scale:
            to_draw_pixbuf = to_draw_pixbuf.scale_simple(
                self.item_button.get_size_request()[0],
                self.item_button.get_size_request()[1],
                gtk.gdk.INTERP_BILINEAR)

        draw_pixbuf(cr, to_draw_pixbuf, rect.x, rect.y)
        #cr.set_source_rgba(1, 1, 1, 0.3)
        #draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, 0)
        #cr.fill()

        # Draw navigate item.
        if self.icon_dpixbuf:
            nav_item_pixbuf = self.icon_dpixbuf.get_pixbuf()
            nav_item_pixbuf_width = nav_item_pixbuf.get_width()
            nav_item_pixbuf_height = nav_item_pixbuf.get_height()
            padding_x = (rect.width - nav_item_pixbuf_width -
                         self.text_width) / 2

            draw_pixbuf(cr, nav_item_pixbuf, rect.x + padding_x,
                        rect.y + (rect.height - nav_item_pixbuf_height) / 2)
        else:
            nav_item_pixbuf_width = 0
            nav_item_pixbuf_height = 0
            padding_x = (rect.width - nav_item_pixbuf_width -
                         self.text_width) / 2 - 1

        draw_text(
            cr,
            self.content,
            rect.x + nav_item_pixbuf_width + padding_x,
            rect.y,
            rect.width,
            rect.height,
            text_size=self.font_size,
            text_color="#FFFFFF",
            gaussian_radious=2,
            gaussian_color="#000000",
            border_radious=1,
            border_color="#000000",
        )

        # Draw notify number.
        text_size = 8
        (number_width,
         number_height) = get_content_size(str(self.notify_num), text_size)
        padding_x = 2
        padding_y = 0
        radious = 3
        draw_offset_x = -5
        draw_offset_y = 8
        draw_x = rect.x + nav_item_pixbuf_width + padding_x + draw_offset_x
        draw_y = rect.y + draw_offset_y
        if self.notify_num > 0:
            cr.set_source_rgb(*color_hex_to_cairo("#BF0000"))
            draw_round_rectangle(cr, draw_x, draw_y,
                                 number_width + padding_x * 2,
                                 number_height + padding_y * 2, radious)
            cr.fill()

            draw_text(
                cr,
                str(self.notify_num),
                draw_x + padding_x,
                draw_y + padding_y,
                number_width,
                number_height,
                text_color="#FFFFFF",
                text_size=text_size,
            )

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

        return True