Ejemplo n.º 1
0
 def __paint_progressbar(self, cr, rect):
     # 画黑色背景.
     cr.set_source_rgb(*color_hex_to_cairo("#000000"))
     cr.rectangle(*rect)
     cr.fill()
     # 画背景. draw background.
     bg_w = self.allocation.width
     bg_h = self.drag_pixbuf_height - 4 # 4(上下各留一像素,该死的设计师.)
     bg_x = rect.x
     bg_y = rect.y + rect.height/2 - bg_h/2
     bg_pixbuf = self.bg_pixbuf.scale_simple(
                     bg_w,
                     bg_h,
                     gtk.gdk.INTERP_BILINEAR
                     )
     draw_pixbuf(cr, bg_pixbuf, bg_x, bg_y)
     ################################
     if self.get_sensitive(): # 
         if self.max_value:
             d_value = float(rect.width) / self.max_value # 差值.
             # 画前景, 进度效果.
             fg_w = min(int(self.pos * d_value), int(self.max_value * d_value))
             fg_h = self.drag_pixbuf_height - 4 
             fg_x = rect.x
             fg_y = rect.y + rect.height/2 - fg_h/2
             fg_color = self.color.get_color()
             fg_color_info = [(0.1, (fg_color, 1.0)),
                              (0.75, (fg_color, 1.0)),
                              (1.0, (fg_color, 0.85))]
             #
             pat = cairo.LinearGradient(0, 0, fg_w, 0)
             pat.add_color_stop_rgb(0.7, *color_hex_to_cairo(self.fg_left_color.get_color()))
             pat.add_color_stop_rgb(1.0, *color_hex_to_cairo(self.fg_right_color.get_color()))
             #draw_hlinear(cr, fg_x, fg_y, fg_w, fg_h, fg_color_info)
             cr.set_operator(cairo.OPERATOR_OVER)
             cr.set_source(pat)
             cr.rectangle(fg_x, fg_y, fg_w, fg_h)
             cr.fill()
             # 画拖动的点.
             if self.drag_show_check: # 是否显示拖动的点.
                 drag_value = int(self.pos * d_value) + self.drag_pixbuf_width/2 - 4
                 max_drag_value = int(self.max_value * d_value) - 2
                 min_drag_value = rect.x - 1
                 # 防止拖动的点跑出可视区域.
                 drag_x = max(min(drag_value, max_drag_value), min_drag_value)
                 drag_y = rect.y + rect.height/2 - self.drag_pixbuf_height/2
                 draw_pixbuf(cr, 
                             self.drag_pixbuf, 
                             drag_x, 
                             drag_y)
Ejemplo n.º 2
0
    def __paint_seek_button(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        #
        cr.set_source_rgb(*color_hex_to_cairo("#000000"))
        y_padding = 2
        x_padding = 2
        w_padding = 5
        h_padding = 2
        if self.type == "fseek":
            x_padding = 3

        cr.rectangle(rect.x - x_padding, 
                     rect.y - y_padding, 
                     rect.width + w_padding, 
                     rect.height + h_padding)
        cr.fill()
        if self.type == "fseek":
            pixbuf = self.f_normal_pixbuf.get_pixbuf()
        else:
            pixbuf = self.b_normal_pixbuf.get_pixbuf()
        if (widget.state == gtk.STATE_PRELIGHT or 
              widget.state == gtk.STATE_SELECTED or
              widget.state == gtk.STATE_ACTIVE):
            if self.get_sensitive(): # 
                if self.type == "fseek":
                    pixbuf = self.f_press_pixbuf.get_pixbuf()
                else:
                    pixbuf = self.b_press_pixbuf.get_pixbuf()
        ###########################################
        draw_pixbuf(cr, pixbuf, rect.x, rect.y + 1)
Ejemplo n.º 3
0
    def select_button_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        # 
        # get font width/height.
        font_w, font_h = get_text_size(self.text, text_size=self.font_size)
        # draw text.
        x_padding = rect.x + self.ali_padding
        x_padding = max(20, x_padding)

        if self.__selected or self.hover:
            # draw rectangle.
            with cairo_disable_antialias(cr):
                cr.set_source_rgb(*color_hex_to_cairo(self.selected_bg_color))
                cr.rectangle(rect.x, 
                            rect.y, 
                            rect.width, 
                            rect.height)
                cr.fill()
        
            draw_text(cr, self.text,
                    x_padding,
                    rect.y + rect.height/2 - font_h/2,
                    text_size=self.font_size, 
                    text_color=self.selected_font_color)        
        else:
            with cairo_disable_antialias(cr):
                cr.set_source_rgb(*color_hex_to_cairo(self.normal_bg_color))
                cr.rectangle(rect.x, 
                            rect.y, 
                            rect.width, 
                            rect.height)
                cr.fill()

            draw_text(cr, self.text,
                    x_padding,
                    rect.y + rect.height/2 - font_h/2,
                    text_size=self.font_size, 
                    text_color=self.normal_font_color)        
        # set size.
        if font_h > rect.height:
            widget.set_size_request(rect.width, font_h)
        return True
Ejemplo n.º 4
0
    def expose(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # draw backgound
        cr.rectangle(*rect)
        cr.set_source_rgb(*color_hex_to_cairo(BACKGROUND_COLOR))
        cr.fill()

        # draw seperator
        cr.set_source_rgb(*color_hex_to_cairo(SEPERATOR_COLOR_UP))
        cr.rectangle(0, rect.height-2, rect.width, 1)
        cr.fill()

        cr.set_source_rgb(*color_hex_to_cairo(SEPERATOR_COLOR_DOWN))
        cr.rectangle(0, rect.height-1, rect.width, 1)
        cr.fill()

        # 
        propagate_expose(widget, event)
        return True
Ejemplo n.º 5
0
    def draw_tooltip_text(self,
                          cr,
                          text,
                          x,
                          y,
                          out_text_color="#000000",
                          in_text_color="#8ad6ff",
                          line_width=3,
                          text_font=DEFAULT_FONT,
                          text_size=DEFAULT_FONT_SIZE,
                          alpha=1.0):
        line_width = line_width
        cr_alpha = alpha
        # set out text color.
        r, g, b = color_hex_to_cairo(out_text_color)
        context = pangocairo.CairoContext(cr)
        layout = context.create_layout()
        layout.set_font_description(
            pango.FontDescription("%s %s" % (text_font, text_size)))
        # set text.
        layout.set_text(text)
        #
        cr.move_to(x, y)
        cr.save()
        cr.layout_path(layout)
        cr.set_line_width(line_width)
        cr.set_source_rgba(r, g, b, cr_alpha)
        cr.stroke_preserve()
        cr.fill()
        cr.restore()

        cr.save()
        cr.new_path()

        r, g, b = color_hex_to_cairo(in_text_color)
        cr.set_source_rgba(r, g, b, cr_alpha)
        cr.set_operator(cairo.OPERATOR_OVER)

        cr.move_to(x, y)
        context.show_layout(layout)
 def select_button_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     # 
     if widget.state == gtk.STATE_PRELIGHT:
         # draw rectangle.
         with cairo_disable_antialias(cr):
             cr.set_source_rgb(*color_hex_to_cairo(self.bg_color))
             cr.rectangle(rect.x, 
                         rect.y, 
                         rect.width, 
                         rect.height)
             cr.fill()
     
             cr.set_line_width(1)
             cr.set_source_rgb(*color_hex_to_cairo(self.line_color))
             cr.rectangle(rect.x + 1,
                          rect.y + 1, 
                          rect.width - 2,
                          rect.height - 2)
             cr.stroke()              
     if widget.state == gtk.STATE_INSENSITIVE:
         text_color = "#a6a6a6"
     else:
         text_color = self.text_color
     # get font width/height.
     font_w, font_h = get_text_size(self.text, text_size=self.font_size)
     # draw text.
     x_padding = rect.x + rect.width - font_w - self.ali_padding
     x_padding = max(20, x_padding)
     draw_text(cr, self.text,
               x_padding,
               rect.y + rect.height/2 - font_h/2,
               text_size=self.font_size, 
               text_color=text_color)
     # set size.
     if font_h > rect.height:
         widget.set_size_request(rect.width, font_h)
     return True
Ejemplo n.º 7
0
def draw_tray_text(
    cr,
    text,
    x,
    y,
    out_text_color="#000000",
    in_text_color="#FFFFFF",
    line_width=2,
    text_font=DEFAULT_FONT,
    text_size=DEFAULT_FONT_SIZE,
):
    line_width = line_width
    cr_alpha = 0.35
    # set out text color.
    r, g, b = color_hex_to_cairo(out_text_color)
    context = pangocairo.CairoContext(cr)
    layout = context.create_layout()
    layout.set_font_description(pango.FontDescription("%s %s" % (text_font, text_size)))
    # set text.
    layout.set_text(text)
    #
    cr.move_to(x, y)
    cr.save()
    cr.layout_path(layout)
    cr.set_line_width(line_width)
    cr.set_source_rgba(r, g, b, cr_alpha)
    cr.stroke_preserve()
    cr.fill()
    cr.restore()

    cr.save()
    cr.new_path()

    r, g, b = color_hex_to_cairo(in_text_color)
    cr.set_source_rgb(r, g, b)
    cr.set_operator(cairo.OPERATOR_OVER)

    cr.move_to(x, y)
    context.show_layout(layout)
Ejemplo n.º 8
0
def draw_text(
    cr,
    text,
    x,
    y,
    w=0,
    h=0,
    text_size=DEFAULT_FONT_SIZE,
    text_color="#FFFFFF",
    text_font=DEFAULT_FONT,
    alignment=None,
    pango_list=None,
    markup=None,
):
    cr.set_source_rgb(*color_hex_to_cairo(text_color))

    context = pangocairo.CairoContext(cr)
    layout = context.create_layout()
    # 设置字体.
    layout.set_font_description(pango.FontDescription("%s %s" % (text_font, text_size)))
    # 设置文本.
    layout.set_text(text)
    # add pango list attributes.
    if pango_list:
        layout.set_attributes(pango_list)
    # 设置文本的alignment.
    text_size = get_text_size(text, text_size, text_font)
    x_padding, y_padding = 0, 0
    if alignment == pango.ALIGN_LEFT:
        x_padding = 0
        y_padding = h / 2 - text_size[1] / 2
    elif alignment == pango.ALIGN_CENTER:
        x_padding = w / 2 - text_size[0] / 2
        y_padding = h / 2 - text_size[1] / 2
    elif alignment == pango.ALIGN_RIGHT:
        x_padding = w - text_size[0]
        y_padding = h / 2 - text_size[1] / 2
    # 设置markup.
    if markup:
        layout.set_markup(markup)
        if alignment:
            layout.set_alignment(alignment)
    # 设置移动.
    cr.move_to(x + x_padding, y + y_padding)
    #
    context.update_layout(layout)
    context.show_layout(layout)
Ejemplo n.º 9
0
def draw_text(cr,
              text,
              x,
              y,
              w=0,
              h=0,
              text_size=DEFAULT_FONT_SIZE,
              text_color="#FFFFFF",
              text_font=DEFAULT_FONT,
              alignment=None,
              pango_list=None,
              markup=None):
    cr.set_source_rgb(*color_hex_to_cairo(text_color))

    context = pangocairo.CairoContext(cr)
    layout = context.create_layout()
    # 设置字体.
    layout.set_font_description(
        pango.FontDescription("%s %s" % (text_font, text_size)))
    # 设置文本.
    layout.set_text(text)
    # add pango list attributes.
    if pango_list:
        layout.set_attributes(pango_list)
    # 设置文本的alignment.
    text_size = get_text_size(text, text_size, text_font)
    x_padding, y_padding = 0, 0
    if alignment == pango.ALIGN_LEFT:
        x_padding = 0
        y_padding = h / 2 - text_size[1] / 2
    elif alignment == pango.ALIGN_CENTER:
        x_padding = w / 2 - text_size[0] / 2
        y_padding = h / 2 - text_size[1] / 2
    elif alignment == pango.ALIGN_RIGHT:
        x_padding = w - text_size[0]
        y_padding = h / 2 - text_size[1] / 2
    # 设置markup.
    if markup:
        layout.set_markup(markup)
        if alignment:
            layout.set_alignment(alignment)
    # 设置移动.
    cr.move_to(x + x_padding, y + y_padding)
    #
    context.update_layout(layout)
    context.show_layout(layout)
Ejemplo n.º 10
0
 def draw_background(self, cr, rect):
     x, y, w, h = rect
     cr.save()
     cairo_popover_rectangle(self, cr, 
                   self.trayicon_x + self.trayicon_border + 1, 
                   self.trayicon_y + self.trayicon_border + 1, 
                   w, h + 1, 
                   self.radius) 
     cr.clip()
     if self.bg_pixbuf:
         cr.set_source_pixbuf(self.bg_pixbuf, self.bg_x, self.bg_y)
         cr.paint_with_alpha(self.bg_alpha)
     else:
         cr.set_source_rgb(*color_hex_to_cairo(self.base_color))
         cr.rectangle(x, y, w, h)
         cr.fill()
     cr.restore()