def __paint_nodes_event(self, node_event):
     if node_event.node.leave == 0: # 根节点.
         x = node_event.x + 15
         if node_event.node.is_expanded:
             root_text = "-"
         else:
             root_text = "+"
         draw_text(node_event.cr, 
                   root_text, 
                   node_event.x + 5, 
                   node_event.y + get_text_size("+")[1]/2)
     else:
         x_padding = node_event.node.leave * self.leave_width
         x = node_event.x + 10 + x_padding
         if node_event.node.is_expanded:
             draw_text(node_event.cr, 
                       "*", 
                       node_event.x + x_padding, 
                       node_event.y + get_text_size("*")[1]/2)
         else:
             if node_event.node.leave < 2:
                 draw_text(node_event.cr, 
                           ">", 
                           node_event.x + x_padding, 
                           node_event.y + get_text_size(">")[1]/2)
     draw_text(node_event.cr, 
               node_event.node.text, 
               x,
               node_event.y + get_text_size(node_event.node.text)[1]/2)
Пример #2
0
 def set_text(self, text):
     self.draw_btn.set_label(text)
     rect = self.draw_btn.allocation
     self.draw_btn.queue_draw_area(rect.x, rect.y, rect.width, rect.height)
     size = get_text_size(text, text_size=self.text_size)
     width_padding = 12
     height_padding = 10
     self.resize(1, 1)
     text_size = get_text_size("我们", text_size=self.text_size)
     #
     self.set_size_request(size[0] + width_padding + self.ali_left + self.ali_right, 
                           text_size[1] + height_padding + self.ali_top + self.ali_bottom)
Пример #3
0
 def __expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     # 画背景.
     bg_pixbuf = self.bg.get_pixbuf().scale_simple(rect.width, rect.height,
                                                   gtk.gdk.INTERP_BILINEAR)
     x = rect.x
     y = rect.y
     draw_pixbuf(cr, bg_pixbuf, x, y)
     #
     if None != self.__index:
         cr.set_source_rgba(1, 1, 1, 0.1)
         cr.rectangle(x + 2, y + self.__index * self.__menu_height + 2,
                      rect.width - 4, self.__menu_height - 4)
         cr.fill()
     #
     index = 0
     for item in self.menu_items:
         pixbuf, text = item.pixbuf, item.text
         if pixbuf:
             draw_pixbuf(
                 cr, pixbuf, x + 8, y + index * self.__menu_height +
                 self.__menu_height / 2 - pixbuf.get_height() / 2)
         draw_text(
             cr, text, x + 35, y + index * self.__menu_height +
             self.__menu_height / 2 - get_text_size(text)[1] / 2)
         if item.child_menus:
             pixbuf = app_theme.get_pixbuf(
                 "screen_mid/menu_child.png").get_pixbuf()
             draw_pixbuf(
                 cr, pixbuf, x + rect.width - 10,
                 y + index * self.__menu_height + self.__menu_height / 2 -
                 pixbuf.get_height() / 2)
         index += 1
Пример #4
0
 def __init__(self,
              chapter_index,
              text,
              ali_padding=13,
              font_size=10):
     gtk.Button.__init__(self)
     # init values.
     self.chapter_index = chapter_index
     self.text = text
     self.font_size=font_size 
     self.ali_padding = ali_padding
     self.selected_bg_color = "#62b8ef"
     self.normal_bg_color = "#dfdfdf"
     self.selected_font_color = "#ffffff"
     self.normal_font_color = "#797979"
     self.draw_check = False
     self.__selected = False
     self.hover = False
     width, height = get_text_size(self.text, font_size)
     self.set_size_request(width+self.ali_padding*2, 23)
     # init events.
     self.add_events(gtk.gdk.ALL_EVENTS_MASK)
     self.connect("expose-event", self.select_button_expose_event)        
     self.connect("enter-notify-event", self._cursor_enter_redraw)
     self.connect("leave-notify-event", self._cursor_leave_redraw)
Пример #5
0
    def __listview_on_draw_sub_item(self, e):
        color = self.listview_color.get_color()
        if e.double_items == e.item:
            e.text_color = "#000000"
            text_size=9
            color_info = [(0, (color, 0.8)), (1, (color, 0.8))] 
            draw_vlinear(e.cr,
                         e.x, e.y, e.w, e.h,
                         color_info
                         )
        elif e.item in e.single_items:
            e.text_color = "#FFFFFF"
            text_size=9
            color_info = [(0, (color, 0.5)), (1, (color, 0.5))] 
            draw_vlinear(e.cr,
                         e.x, e.y, e.w, e.h,
                         color_info
                         )
        elif e.motion_items == e.item:
            e.text_color  = "#FFFFFF"
            text_size=9
            color_info = [(0, (color, 0.2)), (1, (color, 0.2))] 
            draw_vlinear(e.cr,
                         e.x, e.y, e.w, e.h,
                         color_info
                         )
        else:
            e.text_color = "#FFFFFF"
            text_size=9
        #
        text = e.text.decode("utf-8")
        one_width = self.list_view.columns[0].width
        two_width = self.list_view.columns[1].width
        #if e.w == one_width: # 显示播放名字的第一列.
        if e.column_index == 0:
            #
            t_width = 0
            t_index = 0
            add_point = False
            for t in text:
                t_width += get_text_size(t, text_size=text_size)[0]
                if t_width > one_width - 20:
                    add_point = True
                    break
                t_index += 1
            if add_point:
                text = text[:t_index] + "..."
            #
            alignment = Text.LEFT
            x = e.x + 15
        elif e.w == two_width:
            alignment = Text.RIGHT
            x = e.x - 15

        e.draw_text(e.cr, 
                str(text), 
                  x, e.y, e.w, e.h,
                  text_color=e.text_color, 
                  text_size=text_size,
                  alignment=alignment)
Пример #6
0
 def __expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     # 画背景.
     bg_pixbuf = self.bg.get_pixbuf().scale_simple(rect.width, 
                                                   rect.height, 
                                                   gtk.gdk.INTERP_BILINEAR)
     x = rect.x
     y = rect.y
     draw_pixbuf(cr, bg_pixbuf, x, y)
     #
     if None != self.__index:
         cr.set_source_rgba(1, 1, 1, 0.1)
         cr.rectangle(x + 2, 
                      y + self.__index * self.__menu_height + 2, 
                      rect.width - 4, 
                      self.__menu_height - 4)
         cr.fill()
     #
     index = 0
     for item in self.menu_items:
         pixbuf, text = item.pixbuf, item.text
         if pixbuf:
             draw_pixbuf(cr, pixbuf, 
                         x + 8, 
                         y + index * self.__menu_height + self.__menu_height/2 - pixbuf.get_height()/2)
         draw_text(cr, text, 
                   x + 35, 
                   y + index * self.__menu_height + self.__menu_height/2 - get_text_size(text)[1]/2)
         if item.child_menus:
             pixbuf = app_theme.get_pixbuf("screen_mid/menu_child.png").get_pixbuf()
             draw_pixbuf(cr, pixbuf,
                         x + rect.width - 10, 
                         y + index * self.__menu_height + self.__menu_height/2 - pixbuf.get_height()/2)
         index += 1
Пример #7
0
 def scroll_mode(self):
     rect = self.allocation
     full_width, font_height = get_text_size(
         self.text, text_size=self.font_size
     )
     font_width, font_height = get_text_size(
         self.lang == "zh" and "震" or "w",
         text_size=self.font_size
     )
     print "%d %d" % (rect.width, font_width)
     if full_width > rect.width:
         self.current_length = rect.width / font_width
         self.current_text = self.text[:self.current_length]
         t = CountDownExec(2, self._update, doLoop=2)
         t.start()
     else:
         return False
 def test_paint_nodes_event(e):
     if e.node.leave == 0: # 根节点.
         draw_text(e.cr, 
                   e.node.text, 
                   e.x + e.w/2 - get_text_size(e.node.text)[0]/2, 
                   e.y + e.h/2 - get_text_size(e.node.text)[1]/2)
         e.cr.set_source_rgba(1, 1, 1, 1.0)
         e.cr.rectangle(e.x, e.y, e.w, e.h)
         e.cr.stroke()
     else:
         pixbuf = gtk.gdk.pixbuf_new_from_file("logo.png")
         pixbuf = pixbuf.scale_simple(e.h, e.h, gtk.gdk.INTERP_BILINEAR)
         draw_pixbuf(e.cr, pixbuf, e.x + e.w/2 - pixbuf.get_width()/2 + (e.node.leave - 1)* e.h, e.y)
         draw_text(e.cr, 
                   e.node.text, 
                   e.x + e.w/2 - get_text_size(e.node.text)[1]/2 + pixbuf.get_width() + e.node.leave * e.h,
                   e.y + e.h/2 - get_text_size(e.node.text)[1]/2)
Пример #9
0
 def __treeview_paint_nodes_event(self, node_event):
     color = self.listview_color.get_color()
     text_color = "#FFFFFF"
     # 单击和移动, 双击.
     if node_event.node in node_event.single_items:
         color_info = [(0, (color, 0.45)), (1, (color, 0.45))] 
         draw_vlinear(node_event.cr,
                      node_event.x, node_event.y, node_event.w, node_event.h,
                      color_info
                      )
         #text_color = "#000000"
     elif node_event.node in node_event.motion_items:
         color_info = [(0, (color, 0.75)), (1, (color, 0.75))] 
         draw_vlinear(node_event.cr,
                      node_event.x, node_event.y, node_event.w, node_event.h,
                      color_info
                      )
     #
     x_padding = 12 # 因为要和搜索框对齐.
     if 0 == node_event.node.leave: # 根节点. :比如->> >我看过的. >优酷视频. >pps.
         if node_event.node.is_expanded:
             pixbuf = self.one_open.get_pixbuf()
         else:
             pixbuf = self.one_close.get_pixbuf()
     elif 1 == node_event.node.leave: # 
         if node_event.node.is_expanded:
             pixbuf = self.two_open.get_pixbuf()
         else:
             pixbuf = self.two_close.get_pixbuf()
     else:
         if node_event.node.is_expanded:
             pixbuf = self.three_open.get_pixbuf()
         else:
             pixbuf = self.three_close.get_pixbuf()
     #
     icon_x = node_event.x + x_padding
     icon_y = node_event.y + node_event.h/2 - pixbuf.get_height()/2 + 1
     if node_event.node.leave > 1:
         icon_x += (node_event.node.leave - 1) * pixbuf.get_width()
     if node_event.node.leave > 0:
         text_color = "#a8a8a8"
     ##########
     # 画图标.
     if node_event.node.nodes != []:
         draw_pixbuf(node_event.cr,
                     pixbuf,
                     icon_x,
                     icon_y) 
     # 画文本.
     text_x_padding = 15
     text_size = 9
     draw_text(node_event.cr, 
               node_event.node.text, 
               icon_x + text_x_padding,
               node_event.y + node_event.h/2 - get_text_size(node_event.node.text, text_size=9)[1]/2,
               text_color=text_color,
               text_size=text_size
               )
Пример #10
0
    def __init__(self, text, font_size=19, font_color="#373737"):
        gtk.Label.__init__(self)

        self.text = text
        self.font_size = font_size
        self.font_color = font_color
        width, height = get_text_size(self.text, self.font_size)
        self.set_size_request(width, height)
        
        self.connect("expose-event", self.expose)
Пример #11
0
    def top_text_btn_expose_event(self, widget, event, font_color):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        text = widget.get_label()
        font_size = 12
        size = get_text_size(text, font_size)
        size_padding = get_text_size("a", font_size)
        size_padding = size_padding[0] * 35

        draw_text(cr, 
                  text,
                  rect.x,
                  rect.y + rect.height/2 - size[1]/2,
                  font_size,
                  font_color,
                  markup=text)

        widget.set_size_request(size[0], size[1])
        return True
Пример #12
0
 def test_paint_nodes_event(e):
     if e.node.leave == 0:  # 根节点.
         draw_text(e.cr, e.node.text,
                   e.x + e.w / 2 - get_text_size(e.node.text)[0] / 2,
                   e.y + e.h / 2 - get_text_size(e.node.text)[1] / 2)
         e.cr.set_source_rgba(1, 1, 1, 1.0)
         e.cr.rectangle(e.x, e.y, e.w, e.h)
         e.cr.stroke()
     else:
         pixbuf = gtk.gdk.pixbuf_new_from_file("logo.png")
         pixbuf = pixbuf.scale_simple(e.h, e.h, gtk.gdk.INTERP_BILINEAR)
         draw_pixbuf(
             e.cr, pixbuf, e.x + e.w / 2 - pixbuf.get_width() / 2 +
             (e.node.leave - 1) * e.h, e.y)
         draw_text(
             e.cr, e.node.text,
             e.x + e.w / 2 - get_text_size(e.node.text)[1] / 2 +
             pixbuf.get_width() + e.node.leave * e.h,
             e.y + e.h / 2 - get_text_size(e.node.text)[1] / 2)
    def __listview_on_draw_sub_item(self, e):
        color = self.listview_color.get_color()
        if e.double_items == e.item:
            e.text_color = "#000000"
            text_size = 9
            color_info = [(0, (color, 0.8)), (1, (color, 0.8))]
            draw_vlinear(e.cr, e.x, e.y, e.w, e.h, color_info)
        elif e.item in e.single_items:
            e.text_color = "#FFFFFF"
            text_size = 9
            color_info = [(0, (color, 0.5)), (1, (color, 0.5))]
            draw_vlinear(e.cr, e.x, e.y, e.w, e.h, color_info)
        elif e.motion_items == e.item:
            e.text_color = "#FFFFFF"
            text_size = 9
            color_info = [(0, (color, 0.2)), (1, (color, 0.2))]
            draw_vlinear(e.cr, e.x, e.y, e.w, e.h, color_info)
        else:
            e.text_color = "#FFFFFF"
            text_size = 9
        #
        text = e.text.decode("utf-8")
        one_width = self.list_view.columns[0].width
        two_width = self.list_view.columns[1].width
        #if e.w == one_width: # 显示播放名字的第一列.
        if e.column_index == 0:
            #
            t_width = 0
            t_index = 0
            add_point = False
            for t in text:
                t_width += get_text_size(t, text_size=text_size)[0]
                if t_width > one_width - 20:
                    add_point = True
                    break
                t_index += 1
            if add_point:
                text = text[:t_index] + "..."
            #
            alignment = Text.LEFT
            x = e.x + 15
        elif e.w == two_width:
            alignment = Text.RIGHT
            x = e.x - 15

        e.draw_text(e.cr,
                    str(text),
                    x,
                    e.y,
                    e.w,
                    e.h,
                    text_color=e.text_color,
                    text_size=text_size,
                    alignment=alignment)
Пример #14
0
    def expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        if self.centre:
            font_width, font_height = get_text_size(
                self.text, text_size=self.font_size
            )
        else:
            font_width, font_height = get_text_size(
                self.lang == "zh" and "震" or "w",
                text_size=self.font_size)

        #x_padding = rect.x + (rect.width - font_width) / 2
        #y_padding = rect.y + (rect.height - font_height) / 2

        if self.reverse:
            cr.set_source_rgb(*color_hex_to_cairo(THEME['hover']))
            cr.rectangle(*rect)
            cr.fill()

        if self.multi:
            num = (rect.width - self.padding[0] * 2) / font_width
            for i in xrange(0, len(self.text) / num + 1):
                draw_text(cr, self.text[i * num: (i + 1) * num],
                          rect.x + self.padding[0],
                          rect.y + self.padding[1] + 5 + font_height * i,
                          text_size=self.font_size,
                          text_color=self.font_color)
        else:
            y_padding = (rect.height - font_height) / 2
            if self.centre:
                x_padding = (rect.width - font_width) / 2
            else:
                x_padding = self.padding[0]
            draw_text(cr, self.text,
                      rect.x + x_padding,
                      rect.y + y_padding,
                      text_size=self.font_size,
                      text_color=self.font_color)
        return True
    def __treeview_paint_nodes_event(self, node_event):
        leave_width = 20
        color = self.listview_color.get_color()
        text_color = "#FFFFFF"
        #
        if node_event.node in node_event.single_items:
            color_info = [(0, (color, 0.45)), (1, (color, 0.45))] 
            draw_vlinear(node_event.cr,
                         node_event.x, node_event.y, node_event.w, node_event.h,
                         color_info
                         )
            text_color = "#000000"
        elif node_event.node in node_event.motion_items:
            color_info = [(0, (color, 0.75)), (1, (color, 0.75))] 
            draw_vlinear(node_event.cr,
                         node_event.x, node_event.y, node_event.w, node_event.h,
                         color_info
                         )
        #
        if node_event.node.leave == 1: # 根节点.
            x = node_event.x + 20
            # 画root的图标.
            if node_event.node.is_expanded:
                pixbuf = self.tree_view_close.get_pixbuf()
            else:
                pixbuf = self.tree_view_open.get_pixbuf()
            # node_event.x + 5 是图标与文字之间的宽度.
            draw_pixbuf(node_event.cr,
                        pixbuf,
                        node_event.x + 5,
                        node_event.y + node_event.h/2 - pixbuf.get_height()/2 )
        else:
            #x_padding = node_event.node.leave * leave_width
            #x = node_event.x + 18 + x_padding
            x = node_event.x + 20
            #
            if node_event.node.is_expanded:
                pixbuf = self.tree_view_bottom.get_pixbuf()
            else:
                pixbuf = self.tree_view_right.get_pixbuf()
            icon_x = node_event.x + pixbuf.get_width()/2
            icon_y = node_event.y + node_event.h/2 - pixbuf.get_height()/2

            if node_event.node.nodes or node_event.node.leave == 2:
                draw_pixbuf(node_event.cr, pixbuf, icon_x, icon_y)
        #
        draw_text(node_event.cr, 
                  node_event.node.text, 
                  x + 5,
                  node_event.y + node_event.h/2 - get_text_size(node_event.node.text, text_size=9)[1]/2,
                  text_color=text_color,
                  text_size=9
                  )
Пример #16
0
 def __paint_nodes_event(self, node_event):
     if node_event.node.leave == 0:  # 根节点.
         x = node_event.x + 15
         if node_event.node.is_expanded:
             root_text = "-"
         else:
             root_text = "+"
         draw_text(node_event.cr, root_text, node_event.x + 5,
                   node_event.y + get_text_size("+")[1] / 2)
     else:
         x_padding = node_event.node.leave * self.leave_width
         x = node_event.x + 10 + x_padding
         if node_event.node.is_expanded:
             draw_text(node_event.cr, "*", node_event.x + x_padding,
                       node_event.y + get_text_size("*")[1] / 2)
         else:
             if node_event.node.leave < 2:
                 draw_text(node_event.cr, ">", node_event.x + x_padding,
                           node_event.y + get_text_size(">")[1] / 2)
     draw_text(node_event.cr, node_event.node.text, x,
               node_event.y + get_text_size(node_event.node.text)[1] / 2)
 def __treeview_paint_nodes_event(self, node_event):
     color = self.listview_color.get_color()
     text_color = "#FFFFFF"
     # 单击和移动, 双击.
     if node_event.node in node_event.single_items:
         color_info = [(0, (color, 0.45)), (1, (color, 0.45))]
         draw_vlinear(node_event.cr, node_event.x, node_event.y,
                      node_event.w, node_event.h, color_info)
         #text_color = "#000000"
     elif node_event.node in node_event.motion_items:
         color_info = [(0, (color, 0.75)), (1, (color, 0.75))]
         draw_vlinear(node_event.cr, node_event.x, node_event.y,
                      node_event.w, node_event.h, color_info)
     #
     x_padding = 12  # 因为要和搜索框对齐.
     if 0 == node_event.node.leave:  # 根节点. :比如->> >我看过的. >优酷视频. >pps.
         if node_event.node.is_expanded:
             pixbuf = self.one_open.get_pixbuf()
         else:
             pixbuf = self.one_close.get_pixbuf()
     elif 1 == node_event.node.leave:  #
         if node_event.node.is_expanded:
             pixbuf = self.two_open.get_pixbuf()
         else:
             pixbuf = self.two_close.get_pixbuf()
     else:
         if node_event.node.is_expanded:
             pixbuf = self.three_open.get_pixbuf()
         else:
             pixbuf = self.three_close.get_pixbuf()
     #
     icon_x = node_event.x + x_padding
     icon_y = node_event.y + node_event.h / 2 - pixbuf.get_height() / 2 + 1
     if node_event.node.leave > 1:
         icon_x += (node_event.node.leave - 1) * pixbuf.get_width()
     if node_event.node.leave > 0:
         text_color = "#a8a8a8"
     ##########
     # 画图标.
     if node_event.node.nodes != []:
         draw_pixbuf(node_event.cr, pixbuf, icon_x, icon_y)
     # 画文本.
     text_x_padding = 15
     text_size = 9
     draw_text(node_event.cr,
               node_event.node.text,
               icon_x + text_x_padding,
               node_event.y + node_event.h / 2 -
               get_text_size(node_event.node.text, text_size=9)[1] / 2,
               text_color=text_color,
               text_size=text_size)
Пример #18
0
    def expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        font_width, font_height = get_text_size(
            self.lang == "zh" and "震" or "w",
            text_size=self.font_size
        )
        y_padding = (rect.height - font_height) / 2
        draw_text(cr, self.current_text,
                  rect.x,
                  rect.y + y_padding,
                  text_size=self.font_size,
                  text_color=self.font_color)
        return True
Пример #19
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)
Пример #20
0
 def __select_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     if widget.state == gtk.STATE_NORMAL:
         pixbuf = self.left_normal_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_PRELIGHT:
         pixbuf = self.left_hover_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_ACTIVE:
         pixbuf = self.left_press_pixbuf.get_pixbuf()
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)
     text_size = get_text_size(widget.get_label(), text_size=9)
     draw_text(cr, widget.get_label(), 
               rect.x + rect.width/2 - text_size[0]/2 + 5, 
               rect.y + rect.height/2 - text_size[1]/2, 
               text_size=10)
     #
     return True
Пример #21
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)
 def __expose_event_function(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     x, y, w, h = rect
     #
     self.__draw_left_line(widget, cr, x, y, w, h)
     # draw text and pixbuf.
     text = widget.get_text() 
     text_size = 9
     text_w = 0
     pixbuf = widget.get_pixbuf()
     pixbuf_w = 0
     if pixbuf != None:
         pixbuf_w = pixbuf.get_width() 
         #pixbuf_h = pixbuf.get_height()
         pixbuf_x_padding = x + 5
         if text == "":
             pixbuf_x_padding = x + w/2 - pixbuf_w/2 
         # 旋转 rotate.
         if self.__rotate_check:
             self.__draw_rotate(cr, rect, pixbuf)
             #pixbuf = pixbuf.rotate_simple(self.rotate_angle)
         else:
         # draw pixbuf.
             draw_pixbuf(cr, 
                         pixbuf, 
                         pixbuf_x_padding, 
                         y + h/2 - pixbuf.get_height()/2)
     if text != "":
         text_w, text_h = get_text_size(text, text_size=text_size)
         text_x_padding = x + pixbuf_w + self.left_line_w + 5, 
         if pixbuf == None:
             text_x_padding = x + w/2 - text_w/2
         draw_tray_text(cr, 
                   text, 
                   text_x_padding,
                   y + h/2 - text_h/2,
                   text_size=text_size)
     #
     self.__draw_right_line(widget, cr, x, y, w, h)
     self.__draw_press_rectangle(widget, cr, x, y, w, h)
     #
     w_padding = pixbuf_w + text_w + 8 + self.left_line_w + self.right_line_w
     widget.set_size_request(w_padding - 4, 16)
     #
     return True
Пример #23
0
 def __select_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     if widget.state == gtk.STATE_NORMAL:
         pixbuf = self.left_normal_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_PRELIGHT:
         pixbuf = self.left_hover_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_ACTIVE:
         pixbuf = self.left_press_pixbuf.get_pixbuf()
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)
     text_size = get_text_size(widget.get_label(), text_size=9)
     draw_text(cr,
               widget.get_label(),
               rect.x + rect.width / 2 - text_size[0] / 2 + 5,
               rect.y + rect.height / 2 - text_size[1] / 2,
               text_size=10)
     #
     return True
Пример #24
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
Пример #25
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
Пример #26
0
 def __draw_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     # draw background.
     b_x_padding, b_y_padding, b_w_padding, b_h_padding = 2, 2, 4, 4
     cr.set_source_rgb(0, 0, 0)
     cr.rectangle(rect.x + b_x_padding, 
                  rect.y + b_y_padding, 
                  rect.width - b_w_padding, 
                  rect.height - b_h_padding)
     cr.fill()
     # draw text.
     text_color = "#FFFFFF"
     text = widget.get_label()
     size = get_text_size(text, text_size=self.text_size)
     x_padding = 5
     draw_text(cr, text, 
               rect.x + x_padding,
               rect.y + rect.height/2 - size[1]/2, text_color=text_color, text_size=self.text_size)
     return True
Пример #27
0
 def tooltip_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     #
     cr.set_source_rgba(*alpha_color_hex_to_cairo(("#fffacc", 1.0)))
     cr.rectangle(*rect)
     cr.fill()
     #
     text = widget.get_label()
     size = get_text_size(text)
     import pango
     draw_text(cr, 
               text, 
               rect.x - 1, rect.y, rect.width, rect.height,
               text_color="#000000",
               alignment=pango.ALIGN_CENTER)
     cr.set_source_rgba(*alpha_color_hex_to_cairo(("#e7e77c", 1.0)))
     cr.rectangle(*rect)
     cr.stroke()
     return True
Пример #28
0
    def expose_event(self, widget, event):
        self.set_size_request(*self.size)
        cr = widget.window.cairo_create()
        rect = widget.allocation
        font_width, font_height = get_text_size("Loading ...",
                                                text_size=20)

        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*color_hex_to_cairo(THEME['bg']))
            cr.rectangle(*rect)
            cr.fill()

        if self.haveLoadingHint:
            draw_text(cr, "Loading ...",
                      rect.x + (rect.width - font_width) / 2,
                      rect.y + (rect.height - font_height) / 2,
                      text_size=20,
                      text_color=THEME['font_color'])

        propagate_expose(widget, event)
        return True
 def __init__(self, 
              text="", 
              ali_padding=0,
              font_size=10,
              bg_color="#ebf4fd",
              line_color="#7da2ce"):
     gtk.Button.__init__(self)
     # init values.
     self.text = text
     self.font_size=font_size 
     self.ali_padding = ali_padding
     self.bg_color = bg_color
     self.line_color = line_color
     self.text_color = "#000000"
     self.draw_check = False
     width, height = get_text_size(self.text, font_size)
     self.set_size_request(width, height)
     # init events.
     self.add_events(gtk.gdk.ALL_EVENTS_MASK)
     self.connect("button-press-event", self.select_button_button_press_event)
     self.connect("button-release-event", self.select_button_button_release_event)
     self.connect("expose-event", self.select_button_expose_event)        
 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
Пример #31
0
 def tooltip_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     #
     cr.set_source_rgba(*alpha_color_hex_to_cairo(("#fffacc", 1.0)))
     cr.rectangle(*rect)
     cr.fill()
     #
     text = widget.get_label()
     size = get_text_size(text)
     import pango
     draw_text(cr,
               text,
               rect.x - 1,
               rect.y,
               rect.width,
               rect.height,
               text_color="#000000",
               alignment=pango.ALIGN_CENTER)
     cr.set_source_rgba(*alpha_color_hex_to_cairo(("#e7e77c", 1.0)))
     cr.rectangle(*rect)
     cr.stroke()
     return True
Пример #32
0
    def __init__(self,
                 text='Label',
                 font_size=12,
                 reverse=False,
                 centre=False,
                 padding=(0, 0),
                 multi=False,
                 lang="zh",
                 font_color=THEME['font_color']):
        super(MetroLabel, self).__init__()

        self.text = text
        self.multi = multi
        self.lang = lang
        self.padding = padding
        self.font_size = font_size
        width, height = get_text_size(self.text, font_size)
        self.set_size_request(width + self.padding[0] * 2,
                              height + self.padding[1] * 2)
        self.font_color = font_color
        self.reverse = reverse
        self.centre = centre
        self.connect('expose-event', self.expose_event)