Ejemplo n.º 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
Ejemplo n.º 2
0
 def expose_droplist_item(self, widget, event, item_content):
     '''Expose droplist item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     font_color = ui_theme.get_color("menu_font").get_color()
     
     # Draw select effect.
     if self.subdroplist_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
         # Draw background.
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                      ui_theme.get_shadow_color("menu_item_select").get_color_info())
         
         # Set font color.
         font_color = ui_theme.get_color("menu_select_font").get_color()
         
     # Draw item content.
     draw_text(cr, item_content, 
                 rect.x + self.item_padding_left,
                 rect.y,
                 rect.width,
                 rect.height,
                 self.font_size, font_color,
                 )
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
Ejemplo n.º 3
0
    def render(self, cr, rect):
        '''
        IconView interface function.
        
        Render item.
        
        @param cr: Cairo context.
        @param rect: Render rectangle area.
        '''
        # Init.
        draw_x = rect.x + self.padding_x
        draw_y = rect.y + self.padding_y
        
        # Draw color.
        cr.set_source_rgb(*color_hex_to_cairo(self.color))
        cr.rectangle(draw_x, draw_y, self.width, self.height)
        cr.fill()
        
        if self.hover_flag:
            cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("color_item_hover").get_color()))
            cr.rectangle(draw_x, draw_y, self.width, self.height)
            cr.stroke()
        elif self.highlight_flag:
            cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("color_item_highlight").get_color()))
            cr.rectangle(draw_x, draw_y, self.width, self.height)
            cr.stroke()

        # Draw frame.
        with cairo_disable_antialias(cr):    
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("color_item_frame").get_color()))
            cr.rectangle(draw_x, draw_y, self.width, self.height)
            cr.stroke()
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def render(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()
        if isinstance(self.icon_normal_dpixbuf, gtk.gdk.Pixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf
        elif isinstance(self.icon_normal_dpixbuf, DynamicPixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf.get_pixbuf()

        if self.is_hover:
            # Draw background.
            draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height,
                         ui_theme.get_shadow_color("menu_item_select").get_color_info())

            # Set icon pixbuf.
            if isinstance(self.icon_hover_dpixbuf, gtk.gdk.Pixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf
            elif isinstance(self.icon_hover_dpixbuf, DynamicPixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf.get_pixbuf()

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

        draw_pixbuf(cr, icon_pixbuf,
                    rect.x + self.padding_x,
                    rect.y + (rect.height - icon_pixbuf.get_height()) / 2)

        draw_text(cr,
                  self.text,
                  rect.x + self.padding_x * 2 + self.icon_width,
                  rect.y,
                  rect.width - self.padding_x * 2,
                  rect.height,
                  text_color=font_color)
Ejemplo n.º 6
0
    def render(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()
        if isinstance(self.icon_normal_dpixbuf, gtk.gdk.Pixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf
        elif isinstance(self.icon_normal_dpixbuf, DynamicPixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf.get_pixbuf()

        if self.is_hover:
            # Draw background.
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("menu_item_select").get_color_info())

            # Set icon pixbuf.
            if isinstance(self.icon_hover_dpixbuf, gtk.gdk.Pixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf
            elif isinstance(self.icon_hover_dpixbuf, DynamicPixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf.get_pixbuf()

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

        draw_pixbuf(cr, icon_pixbuf, rect.x + self.padding_x,
                    rect.y + (rect.height - icon_pixbuf.get_height()) / 2)

        draw_text(cr,
                  self.text,
                  rect.x + self.padding_x * 2 + self.icon_width,
                  rect.y,
                  rect.width - self.padding_x * 2,
                  rect.height,
                  text_color=font_color)
Ejemplo n.º 7
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
Ejemplo n.º 8
0
    def __init__(self,
                 monitor_widget,
                 text_font=DEFAULT_FONT,
                 text_size=18,
                 offset_x=0,
                 offset_y=0,
                 text_color=ui_theme.get_color("osd_tooltip_text"),
                 border_color=ui_theme.get_color("osd_tooltip_border"),
                 border_radious=1):
        '''
        Initialize OSDTooltip class.

        @param monitor_widget: Widget to monitor event.
        @param text_font: Text font, default is DEFAULT_FONT.
        @param text_size: Text size, default is 18.
        @param offset_x: Offset X coordinate relative to monitor widget.
        @param offset_y: Offset Y coordinate relative to monitor widget.
        @param text_color: Text color.
        @param border_color: Border color.
        @param border_radious: Border radious.
        '''
        # Init.
        gtk.Window.__init__(self, gtk.WINDOW_POPUP)
        self.monitor_widget = monitor_widget
        self.text = ""
        self.text_size = text_size
        self.text_font = text_font
        self.offset_x = offset_x
        self.offset_y = offset_y
        self.text_color = text_color
        self.border_color = border_color
        self.border_radious = border_radious
        self.monitor_window = None
        self.monitor_window_x = None
        self.monitor_window_y = None
        self.monitor_window_width = None
        self.monitor_window_height = None
        self.start_hide_delay = 5000  # milliseconds
        self.hide_time = 500  # milliseconds

        # Init callback id.
        self.configure_event_callback_id = None
        self.destroy_callback_id = None
        self.start_hide_callback_id = None
        self.focus_out_callback_id = None

        # Init window.
        self.set_decorated(False)
        self.set_skip_taskbar_hint(True)
        self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)  # keeep above
        self.set_colormap(gtk.gdk.Screen().get_rgba_colormap())
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.set_accept_focus(False)  # make Alt+Space menu can't response

        # Connect signal.
        self.connect("expose-event", self.expose_osd_tooltip)
        self.connect("realize", self.realize_osd_tooltip)
        self.connect("show", self.show_osd_tooltip)
Ejemplo n.º 9
0
    def __init__(self,
                 monitor_widget,
                 text_font=DEFAULT_FONT,
                 text_size=18,
                 offset_x=0,
                 offset_y=0,
                 text_color=ui_theme.get_color("osd_tooltip_text"),
                 border_color=ui_theme.get_color("osd_tooltip_border"),
                 border_radious=1):
        '''
        Initialize OSDTooltip class.

        @param monitor_widget: Widget to monitor event.
        @param text_font: Text font, default is DEFAULT_FONT.
        @param text_size: Text size, default is 18.
        @param offset_x: Offset X coordinate relative to monitor widget.
        @param offset_y: Offset Y coordinate relative to monitor widget.
        @param text_color: Text color.
        @param border_color: Border color.
        @param border_radious: Border radious.
        '''
        # Init.
        gtk.Window.__init__(self, gtk.WINDOW_POPUP)
        self.monitor_widget = monitor_widget
        self.text = ""
        self.text_size = text_size
        self.text_font = text_font
        self.offset_x = offset_x
        self.offset_y = offset_y
        self.text_color = text_color
        self.border_color = border_color
        self.border_radious = border_radious
        self.monitor_window = None
        self.monitor_window_x = None
        self.monitor_window_y = None
        self.monitor_window_width = None
        self.monitor_window_height = None
        self.start_hide_delay = 5000 # milliseconds
        self.hide_time = 500         # milliseconds

        # Init callback id.
        self.configure_event_callback_id = None
        self.destroy_callback_id = None
        self.start_hide_callback_id = None
        self.focus_out_callback_id = None

        # Init window.
        self.set_decorated(False)
        self.set_skip_taskbar_hint(True)
        self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) # keeep above
        self.set_colormap(gtk.gdk.Screen().get_rgba_colormap())
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.set_accept_focus(False) # make Alt+Space menu can't response

        # Connect signal.
        self.connect("expose-event", self.expose_osd_tooltip)
        self.connect("realize", self.realize_osd_tooltip)
        self.connect("show", self.show_osd_tooltip)
Ejemplo n.º 10
0
 def expose_menu_item(self, widget, event):
     '''Expose menu item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     font_color = ui_theme.get_color("menu_font").get_color()
     (item_icons, item_content, item_node) = self.item[0:3]
     
     # Draw select effect.
     if self.submenu_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
         # Draw background.
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                      ui_theme.get_shadow_color("menu_item_select").get_color_info(),
                      MENU_ITEM_RADIUS)
         
         # Set font color.
         font_color = ui_theme.get_color("menu_select_font").get_color()
         
     # Draw item icon.
     pixbuf = None
     pixbuf_width = 0
     if item_icons:
         (item_normal_dpixbuf, item_hover_dpixbuf) = item_icons
         if self.submenu_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
             if item_hover_dpixbuf == None:
                 pixbuf = item_normal_dpixbuf.get_pixbuf()
             else:
                 pixbuf = item_hover_dpixbuf.get_pixbuf()
         else:
             pixbuf = item_normal_dpixbuf.get_pixbuf()
         pixbuf_width += pixbuf.get_width()
         draw_pixbuf(cr, pixbuf, rect.x + self.item_padding_x, rect.y + (rect.height - pixbuf.get_height()) / 2)
         
     # Draw item content.
     draw_text(cr, item_content, 
                 rect.x + self.item_padding_x * 2 + self.icon_width,
                 rect.y,
                 rect.width,
                 rect.height,
                 self.font_size, font_color,
                 )
     
     # Draw submenu arrow.
     if isinstance(item_node, Menu):
         if self.submenu_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
             submenu_pixbuf = ui_theme.get_pixbuf("menu/arrow_hover.png").get_pixbuf()
         else:
             submenu_pixbuf = ui_theme.get_pixbuf("menu/arrow_normal.png").get_pixbuf()
         draw_pixbuf(cr, submenu_pixbuf,
                     rect.x + rect.width - self.item_padding_x - submenu_pixbuf.get_width() - self.arrow_padding_x,
                     rect.y + (rect.height - submenu_pixbuf.get_height()) / 2)
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
Ejemplo n.º 11
0
 def expose_category_item(self, widget, event):
     '''Expose navigate item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     select_index = self.get_index()
     font_color = ui_theme.get_color("category_item").get_color()
     
     # Draw background.
     if widget.state == gtk.STATE_NORMAL:
         if select_index == self.index:
             select_status = BUTTON_PRESS
         else:
             select_status = BUTTON_NORMAL
     elif widget.state == gtk.STATE_PRELIGHT:
         if select_index == self.index:
             select_status = BUTTON_PRESS
         else:
             select_status = BUTTON_HOVER
     elif widget.state == gtk.STATE_ACTIVE:
         select_status = BUTTON_PRESS
         
     if select_status == BUTTON_PRESS:
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                     ui_theme.get_shadow_color("category_item_press").get_color_info())
 
         font_color = ui_theme.get_color("category_select_item").get_color()
     elif select_status == BUTTON_HOVER:
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                     ui_theme.get_shadow_color("category_item_hover").get_color_info())
         
         font_color = ui_theme.get_color("category_select_item").get_color()
         
     # Draw navigate item.
     category_item_pixbuf = self.icon_dpixbuf.get_pixbuf()
     draw_pixbuf(
         cr, category_item_pixbuf, 
         rect.x + self.padding_left,
         rect.y + (rect.height - category_item_pixbuf.get_height()) / 2
         )
     
     # Draw font.
     draw_text(cr, self.content, 
                 rect.x + self.padding_left + self.font_offset,
                 rect.y,
                 rect.width - self.padding_left - self.font_offset - self.padding_right,
                 rect.height,
                 self.font_size, 
                 font_color,
                 )
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
Ejemplo n.º 12
0
 def expose_button(self, widget, event):
     '''Expose button.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     # Get color info.
     if widget.state == gtk.STATE_NORMAL:
         text_color = ui_theme.get_color("button_font").get_color()
         border_color = ui_theme.get_color("button_border_normal").get_color()
         background_color = ui_theme.get_shadow_color("button_background_normal").get_color_info()
     elif widget.state == gtk.STATE_PRELIGHT:
         text_color = ui_theme.get_color("button_font").get_color()
         border_color = ui_theme.get_color("button_border_prelight").get_color()
         background_color = ui_theme.get_shadow_color("button_background_prelight").get_color_info()
     elif widget.state == gtk.STATE_ACTIVE:
         text_color = ui_theme.get_color("button_font").get_color()
         border_color = ui_theme.get_color("button_border_active").get_color()
         background_color = ui_theme.get_shadow_color("button_background_active").get_color_info()
     elif widget.state == gtk.STATE_INSENSITIVE:
         text_color = ui_theme.get_color("disable_text").get_color()
         border_color = ui_theme.get_color("disable_frame").get_color()
         disable_background_color = ui_theme.get_color("disable_background").get_color()
         background_color = [(0, (disable_background_color, 1.0)),
                             (1, (disable_background_color, 1.0))]
         
     # Draw background.
     draw_vlinear(
         cr,
         x + 1, y + 1, w - 2, h - 2,
         background_color)
     
     # Draw border.
     cr.set_source_rgb(*color_hex_to_cairo(border_color))
     draw_line(cr, x + 2, y + 1, x + w - 2, y + 1) # top
     draw_line(cr, x + 2, y + h, x + w - 2, y + h) # bottom
     draw_line(cr, x + 1, y + 2, x + 1, y + h - 2) # left
     draw_line(cr, x + w, y + 2, x + w, y + h - 2) # right
     
     # Draw four point.
     if widget.state == gtk.STATE_INSENSITIVE:
         top_left_point = ui_theme.get_pixbuf("button/disable_corner.png").get_pixbuf()
     else:
         top_left_point = ui_theme.get_pixbuf("button/corner.png").get_pixbuf()
     top_right_point = top_left_point.rotate_simple(270)
     bottom_right_point = top_left_point.rotate_simple(180)
     bottom_left_point = top_left_point.rotate_simple(90)
     
     draw_pixbuf(cr, top_left_point, x, y)
     draw_pixbuf(cr, top_right_point, x + w - top_left_point.get_width(), y)
     draw_pixbuf(cr, bottom_left_point, x, y + h - top_left_point.get_height())
     draw_pixbuf(cr, bottom_right_point, x + w - top_left_point.get_width(), y + h - top_left_point.get_height())
     
     # Draw font.
     draw_text(cr, self.label, x, y, w, h, self.font_size, text_color,
                 alignment=pango.ALIGN_CENTER)
     
     return True
Ejemplo n.º 13
0
    def render_title(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()

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

        draw_text(cr, self.title, rect.x + self.padding_x,
                  rect.y, rect.width - self.padding_x * 2,
                  rect.height, text_size=self.font_size,
                  text_color = font_color,
                  alignment=pango.ALIGN_LEFT)
Ejemplo n.º 14
0
 def render(self, cr, rect):
     # Init.
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     # Draw background frame.
     with cairo_state(cr):
         cr.rectangle(x, y + 1, w, h - 2)
         cr.rectangle(x + 1, y, w - 2, h)
         cr.clip()
         
         cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("progressbar_background_frame").get_color()))
         cr.rectangle(x, y, w, h)
         cr.set_line_width(1)
         cr.stroke()
         
     # Draw background.
     with cairo_state(cr):
         cr.rectangle(x + 1, y + 1, w - 2, h - 2)
         cr.clip()
         
         draw_vlinear(cr, x + 1, y + 1, w - 2, h - 2,
                      ui_theme.get_shadow_color("progressbar_background").get_color_info(), 
                      )
         
     if self.progress > 0:    
         # Draw foreground frame.
         with cairo_state(cr):
             cr.rectangle(x, y + 1, w, h - 2)
             cr.rectangle(x + 1, y, w - 2, h)
             cr.clip()
         
             cr.set_antialias(cairo.ANTIALIAS_NONE)
             cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("progressbar_foreground_frame").get_color()))
             cr.rectangle(x + 1, y + 1, int(w * self.progress / 100) - 1, h - 1)
             cr.set_line_width(1)
             cr.stroke()
             
         # Draw foreground.
         with cairo_state(cr):
             cr.rectangle(x + 1, y + 1, w - 2, h - 2)
             cr.clip()
             
             draw_vlinear(cr, x + 1, y + 1, int(w * self.progress / 100) - 2, h - 2,
                          ui_theme.get_shadow_color("progressbar_foreground").get_color_info(), 
                          )
         
     # Draw light.
     with cairo_disable_antialias(cr):
         cr.set_source_rgba(1, 1, 1, 0.5)
         cr.rectangle(x + 1, y + 1, w - 2, 1)
         cr.fill()
Ejemplo n.º 15
0
 def __init__(self, can_close_tab=False):
     '''
     Initialize TabBox class.
     '''
     # Init.
     gtk.VBox.__init__(self)
     self.tab_height = 29
     self.tab_padding_x = 19
     self.tab_padding_y = 9
     self.tab_select_bg_color = ui_theme.get_color("tab_select_bg")
     self.tab_select_frame_color = ui_theme.get_color("tab_select_frame")
     self.tab_unselect_bg_color = ui_theme.get_color("tab_unselect_bg")
     self.tab_unselect_frame_color = ui_theme.get_color("tab_unselect_bg")
     self.can_close_tab = can_close_tab
     self.close_button_size = 6
     self.close_button_frame_size = 3
     self.close_button_padding_x = 4
     self.close_button_padding_y = 6
     self.close_button_select_background_color = "#EE0000"
     self.close_button_select_foreground_color = "#FFFFFF"
     self.close_button_color = "#666666"
     self.hover_close_button_index = None
     
     self.tab_title_box = gtk.DrawingArea()
     self.tab_title_box.add_events(gtk.gdk.ALL_EVENTS_MASK)
     self.tab_title_box.set_size_request(-1, self.tab_height)
     self.tab_title_align = gtk.Alignment()
     self.tab_title_align.set(0.0, 0.0, 1.0, 1.0)
     self.tab_title_align.set_padding(0, 0, 0, 0)
     self.tab_title_align.add(self.tab_title_box)
     self.tab_content_align = gtk.Alignment()
     self.tab_content_align.set(0.0, 0.0, 1.0, 1.0)
     self.tab_content_align.set_padding(0, 0, 0, 0)
     self.tab_content_box = gtk.VBox()
     self.tab_content_align.add(self.tab_content_box)
     
     self.tab_items = []
     self.tab_title_widths = []
     self.tab_index = -1
     
     self.default_widget = None
     
     self.pack_start(self.tab_title_align, False, False)
     self.pack_start(self.tab_content_align, True, True)
     
     self.tab_title_box.connect("button-press-event", self.press_tab_title_box)
     self.tab_title_box.connect("expose-event", self.expose_tab_title_box)
     self.tab_title_box.connect("motion-notify-event", self.motion_notify_tab_title_box)
     self.tab_content_align.connect("expose-event", self.expose_tab_content_align)
     self.tab_content_box.connect("expose-event", self.expose_tab_content_box)
Ejemplo n.º 16
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()
Ejemplo n.º 17
0
 def __init__(self,
              shrink_first,
              enable_animation=False,
              always_show_button=False,
              enable_drag=False,
              handle_color=ui_theme.get_color("paned_line")):
     '''
     Initialize Paned class.
     '''
     gtk.Paned.__init__(self)
     self.shrink_first = shrink_first
     self.enable_animation = enable_animation
     self.always_show_button = always_show_button
     self.enable_drag = enable_drag
     self.handle_color = handle_color
     self.bheight = ui_theme.get_pixbuf(
         "paned/paned_up_normal.png").get_pixbuf().get_width()
     self.saved_position = -1
     self.handle_size = PANED_HANDLE_SIZE - 1
     self.show_button = False
     self.init_button("normal")
     self.animation_delay = 20  # milliseconds
     self.animation_times = 10
     self.animation_position_frames = []
     self.press_coordinate = None
Ejemplo n.º 18
0
 def __init__(self, 
              shrink_first,
              enable_animation=False,
              always_show_button=False,
              enable_drag=False,
              handle_color=ui_theme.get_color("paned_line")
              ):
     '''
     Initialize Paned class.
     '''
     gtk.Paned.__init__(self)
     self.shrink_first = shrink_first
     self.enable_animation = enable_animation
     self.always_show_button = always_show_button
     self.enable_drag = enable_drag
     self.handle_color = handle_color
     self.bheight = ui_theme.get_pixbuf("paned/paned_up_normal.png").get_pixbuf().get_width()
     self.saved_position = -1
     self.handle_size = PANED_HANDLE_SIZE - 1
     self.show_button = False
     self.init_button("normal")
     self.animation_delay = 20 # milliseconds
     self.animation_times = 10
     self.animation_position_frames = []
     self.press_coordinate = None
Ejemplo n.º 19
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,
                          )
Ejemplo n.º 20
0
    def __init__(self, tab_names, font_size=11, padding_x=0, padding_y=0):
        """
        Initialize TabSwitcher class.

        @param tab_names: The name of tabs.
        @param padding_x: The padding x around tab name, default is 0 pixel.
        @param padding_y: The padding y around tab name, default is 0 pixel.
        """
        EventBox.__init__(self)
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.tab_names = tab_names
        self.tab_name_size = font_size
        self.tab_number = len(self.tab_names)
        tab_sizes = map(lambda tab_name: get_content_size(tab_name, self.tab_name_size), self.tab_names)
        self.tab_name_padding_x = 10
        self.tab_name_padding_y = 2
        self.tab_width = max(map(lambda (width, height): width, tab_sizes)) + self.tab_name_padding_x * 2
        self.tab_height = tab_sizes[0][1] + self.tab_name_padding_y * 2
        self.tab_line_height = 3
        self.tab_index = 0

        self.tab_animation_x = 0
        self.tab_animation_time = 200  # milliseconds

        self.padding_x = padding_x
        self.padding_y = padding_y
        self.in_animiation = False
        self.line_dcolor = ui_theme.get_color("globalItemHighlight")

        self.set_size_request(-1, self.tab_height + self.tab_line_height)

        self.connect("realize", self.realize_tab_switcher)
        self.connect("expose-event", self.expose_tab_switcher)
        self.connect("button-press-event", self.button_press_tab_switcher)
Ejemplo n.º 21
0
 def __init__(self, text, link, enable_gaussian=True, 
              text_color=ui_theme.get_color("link_text")):
     '''Init link button.'''
     Label.__init__(self, text, text_color, enable_gaussian=enable_gaussian, text_size=9,
                    gaussian_radious=1, border_radious=0)
     
     self.connect("button-press-event", lambda w, e: run_command("xdg-open %s" % link))
     
     set_clickable_cursor(self)
Ejemplo n.º 22
0
    def render_title(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()

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

        draw_text(cr,
                  self.title,
                  rect.x + self.padding_x,
                  rect.y,
                  rect.width - self.padding_x * 2,
                  rect.height,
                  text_size=self.font_size,
                  text_color=font_color,
                  alignment=pango.ALIGN_LEFT)
Ejemplo n.º 23
0
 def __init__(self,
              shrink_first=True,
              enable_animation=False,
              always_show_button=False,
              enable_drag=False,
              handle_color=ui_theme.get_color("paned_line")):
     Paned.__init__(self, shrink_first, enable_animation,
                    always_show_button, enable_drag, handle_color)
     self.set_orientation(gtk.ORIENTATION_VERTICAL)
     self.cursor_type = gtk.gdk.Cursor(gtk.gdk.SB_V_DOUBLE_ARROW)
Ejemplo n.º 24
0
 def __init__(self, 
              shrink_first=True,
              enable_animation=False,
              always_show_button=False,
              enable_drag=False,
              handle_color=ui_theme.get_color("paned_line")
              ):
     Paned.__init__(self, shrink_first, enable_animation, always_show_button, enable_drag, handle_color)
     self.set_orientation(gtk.ORIENTATION_VERTICAL)
     self.cursor_type = gtk.gdk.Cursor(gtk.gdk.SB_V_DOUBLE_ARROW)
Ejemplo n.º 25
0
    def expose_droplist_frame(self, widget, event):
        '''Expose droplist frame.'''
        cr = widget.window.cairo_create()        
        rect = widget.allocation

        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("droplist_frame").get_color()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.fill()
Ejemplo n.º 26
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
Ejemplo n.º 27
0
    def on_expose_alignment(widget, event):
        '''Expose tooltip label.'''
        rect = widget.allocation
        cr = widget.window.cairo_create()

        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgba(*color_hex_to_cairo(ui_theme.get_color("tooltip_frame").get_color()))
            cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1)
            cr.stroke()
        return True
Ejemplo n.º 28
0
 def __init__(self, items, droplist_height=None, select_index=0, max_width=None):
     '''Init combo box.'''
     # Init.
     gtk.VBox.__init__(self)
     self.set_can_focus(True)
     self.items = items
     self.droplist_height = droplist_height
     self.select_index = select_index
     self.focus_flag = False
     
     self.droplist = Droplist(self.items, max_width=max_width)
     if self.droplist_height:
         self.droplist.set_size_request(-1, self.droplist_height)
     self.width = self.droplist.get_droplist_width() 
     self.height = 22
     self.label_padding_left = 6
     self.box = gtk.HBox()
     self.dropbutton_width = ui_theme.get_pixbuf("combo/dropbutton_normal.png").get_pixbuf().get_width()
     self.label = Label(self.items[select_index][0], 
                        label_width=self.width - self.dropbutton_width - 1 - self.label_padding_left,
                        enable_select=False,
                        enable_double_click=False)
     self.label.text_color = ui_theme.get_color("menu_font")
     self.dropbutton = DisableButton(
         (ui_theme.get_pixbuf("combo/dropbutton_normal.png"),
          ui_theme.get_pixbuf("combo/dropbutton_hover.png"),
          ui_theme.get_pixbuf("combo/dropbutton_press.png"),
          ui_theme.get_pixbuf("combo/dropbutton_disable.png")),
         )
             
     self.align = gtk.Alignment()
     self.align.set(0.5, 0.5, 0.0, 0.0)
     self.align.set_padding(1, 1, 1 + self.label_padding_left, 1)
     
     self.pack_start(self.align, False, False)
     self.align.add(self.box)
     self.box.pack_start(self.label, False, False)
     self.box.pack_start(self.dropbutton, False, False)
     
     self.align.connect("expose-event", self.expose_combobox_frame)
     self.label.connect("button-press-event", self.click_drop_button)
     self.dropbutton.connect("button-press-event", self.click_drop_button)
     self.droplist.connect("item-selected", self.update_select_content)
     self.droplist.connect("key-release", lambda dl, s, o, i: self.emit("key-release", s, o, i))
     self.connect("key-press-event", self.key_press_combo)
     self.connect("key-release-event", self.key_release_combo)
     self.connect("focus-in-event", self.focus_in_combo)
     self.connect("focus-out-event", self.focus_out_combo)
     
     self.keymap = {
         "Home" : self.select_first_item,
         "End" : self.select_last_item,
         "Up" : self.select_prev_item,
         "Down" : self.select_next_item}
Ejemplo n.º 29
0
    def expose_droplist_item(self, widget, event, item_content):
        '''
        Internal function to handle `expose-event` signal of item.

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

        # Draw select effect.
        if self.subdroplist_active or widget.state in [
                gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE
        ]:
            # Draw background.
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("menu_item_select").get_color_info())

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

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

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

        return True
Ejemplo n.º 30
0
    def expose_combo_list_frame(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(*rect)
        cr.fill()

        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("droplist_frame").get_color()))
            cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1)
            cr.stroke()
Ejemplo n.º 31
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
Ejemplo n.º 32
0
    def on_expose_alignment(widget, event):
        '''Expose tooltip label.'''
        rect = widget.allocation
        cr = widget.window.cairo_create()

        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgba(*color_hex_to_cairo(
                ui_theme.get_color("tooltip_frame").get_color()))
            cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 1,
                         rect.height - 1)
            cr.stroke()
        return True
Ejemplo n.º 33
0
    def __init__(
        self,
        right_space=2,
        top_bottom_space=3,
    ):
        '''
        Init scrolled window.

        @param right_space: the space between right border and the vertical scrollbar.
        @param top_bottom_space: the space between top border and the vertical scrollbar.
        '''
        gtk.Bin.__init__(self)
        self.bar_min_length = 50  #scrollbar smallest height
        self.bar_small_width = 7
        self.bar_width = 14  #normal scrollbar width
        self.bar_background = ui_theme.get_color("scrolledbar")
        self.right_space = right_space
        self.top_bottom_space = top_bottom_space

        self.h_value_change_id = None
        self.h_change_id = None
        self.v_value_change_id = None
        self.v_change_id = None

        self.vscrollbar_state = None

        class Record():
            def __init__(self):
                self.bar_len = 0  # scrollbar length
                self.last_pos = 0  # last mouse motion pointer's position (x or y)

                # Last mouse motion times-tamp, if user moved the window
                # then the last_pos is likely become invalid so we need "last_time"
                # to deal with this situation.
                self.last_time = 0
                self.virtual_len = 0  # the virtual window height or width length
                self.bar_pos = 0  # the scrollbar top-corner/left-corner position
                self.is_inside = False  # is pointer in the scrollbar region?
                self.in_motion = False  # is user is dragging scrollbar?
                self.policy = gtk.POLICY_AUTOMATIC
                self.need_update_region = False  # update gdk.Window's shape_region when need

        self._horizaontal = Record()
        self._vertical = Record()

        self.set_can_focus(True)
        self.vallocation = gdk.Rectangle()
        self.hallocation = gdk.Rectangle()
        self.set_vadjustment(gtk.Adjustment())
        self.set_hadjustment(gtk.Adjustment())
        self.set_has_window(False)
Ejemplo n.º 34
0
    def __init__(self,
                 right_space=2,
                 top_bottom_space=3,
                 ):
        '''
        Init scrolled window.

        @param right_space: the space between right border and the vertical scrollbar.
        @param top_bottom_space: the space between top border and the vertical scrollbar.
        '''
        gtk.Bin.__init__(self)
        self.bar_min_length = 50  #scrollbar smallest height
        self.bar_small_width = 7
        self.bar_width = 14  #normal scrollbar width
        self.bar_background = ui_theme.get_color("scrolledbar")
        self.right_space = right_space
        self.top_bottom_space = top_bottom_space

        self.h_value_change_id = None
        self.h_change_id = None
        self.v_value_change_id = None
        self.v_change_id = None

        self.vscrollbar_state = None

        class Record():
            def __init__(self):
                self.bar_len = 0  # scrollbar length
                self.last_pos = 0 # last mouse motion pointer's position (x or y)

                # Last mouse motion times-tamp, if user moved the window
                # then the last_pos is likely become invalid so we need "last_time"
                # to deal with this situation.
                self.last_time = 0
                self.virtual_len = 0   # the virtual window height or width length
                self.bar_pos = 0       # the scrollbar top-corner/left-corner position
                self.is_inside = False # is pointer in the scrollbar region?
                self.in_motion = False # is user is dragging scrollbar?
                self.policy = gtk.POLICY_AUTOMATIC
                self.need_update_region = False # update gdk.Window's shape_region when need

        self._horizaontal = Record()
        self._vertical = Record()

        self.set_can_focus(True)
        self.vallocation = gdk.Rectangle()
        self.hallocation = gdk.Rectangle()
        self.set_vadjustment(gtk.Adjustment())
        self.set_hadjustment(gtk.Adjustment())
        self.set_has_window(False)
Ejemplo n.º 35
0
    def expose_combo_list_frame(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(*rect)
        cr.fill()

        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo(
                ui_theme.get_color("droplist_frame").get_color()))
            cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 1,
                         rect.height - 1)
            cr.stroke()
Ejemplo n.º 36
0
 def __init__(self):
     '''Init tab box.'''
     # Init.
     gtk.VBox.__init__(self)
     self.tab_height = 29
     self.tab_padding_x = 19
     self.tab_padding_y = 9
     self.tab_select_bg_color = ui_theme.get_color("tab_select_bg")
     self.tab_select_frame_color = ui_theme.get_color("tab_select_frame")
     self.tab_unselect_bg_color = ui_theme.get_color("tab_unselect_bg")
     self.tab_unselect_frame_color = ui_theme.get_color("tab_unselect_bg")
     
     self.tab_title_box = EventBox()
     self.tab_title_box.set_size_request(-1, self.tab_height)
     self.tab_title_align = gtk.Alignment()
     self.tab_title_align.set(0.0, 0.0, 1.0, 1.0)
     self.tab_title_align.set_padding(0, 0, 0, 0)
     self.tab_title_align.add(self.tab_title_box)
     self.tab_content_align = gtk.Alignment()
     self.tab_content_align.set(0.0, 0.0, 1.0, 1.0)
     self.tab_content_align.set_padding(0, 1, 0, 0)
     self.tab_content_scrolled_window = ScrolledWindow()
     self.tab_content_align.add(self.tab_content_scrolled_window)
     self.tab_content_box = gtk.VBox()
     self.tab_content_scrolled_window.add_child(self.tab_content_box)
     
     self.tab_items = []
     self.tab_title_widths = []
     self.tab_index = -1
     
     self.pack_start(self.tab_title_align, False, False)
     self.pack_start(self.tab_content_align, True, True)
     
     self.tab_title_box.connect("button-press-event", self.press_tab_title_box)
     self.tab_title_box.connect("expose-event", self.expose_tab_title_box)
     self.tab_content_align.connect("expose-event", self.expose_tab_content_align)
     self.tab_content_box.connect("expose-event", self.expose_tab_content_box)
Ejemplo n.º 37
0
    def render(self, cr, rect):
        '''
        IconView interface function.

        Render item.

        @param cr: Cairo context.
        @param rect: Render rectangle area.
        '''
        # Init.
        draw_x = rect.x + self.padding_x
        draw_y = rect.y + self.padding_y

        # Draw color.
        cr.set_source_rgb(*color_hex_to_cairo(self.color))
        cr.rectangle(draw_x, draw_y, self.width, self.height)
        cr.fill()

        if self.hover_flag:
            cr.set_source_rgb(*color_hex_to_cairo(
                ui_theme.get_color("color_item_hover").get_color()))
            cr.rectangle(draw_x, draw_y, self.width, self.height)
            cr.stroke()
        elif self.highlight_flag:
            cr.set_source_rgb(*color_hex_to_cairo(
                ui_theme.get_color("color_item_highlight").get_color()))
            cr.rectangle(draw_x, draw_y, self.width, self.height)
            cr.stroke()

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo(
                ui_theme.get_color("color_item_frame").get_color()))
            cr.rectangle(draw_x, draw_y, self.width, self.height)
            cr.stroke()
Ejemplo n.º 38
0
    def expose_droplist_frame(self, widget, event):
        '''
        Callback for `expose-event` siangl of droplist frame.

        @param widget: Droplist widget.
        @param event: Expose event.
        '''
        cr = widget.window.cairo_create()
        rect = widget.allocation

        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo(
                ui_theme.get_color("droplist_frame").get_color()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.fill()
Ejemplo n.º 39
0
    def draw_handle(self, e):
        '''
        Draw the cusom handle apperance.
        '''
        handle = self.get_handle_window()
        line_width = 1
        cr = handle.cairo_create()
        cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("paned_line").get_color()))
        (width, height) = handle.get_size()
        if self.get_orientation() == gtk.ORIENTATION_HORIZONTAL:
            if self.shrink_first:
                cr.rectangle(0, 0, line_width, height)
                cr.fill()

                if self.show_button:
                    draw_pixbuf(cr, 
                                ui_theme.get_pixbuf("paned/paned_left_normal.png").get_pixbuf(),
                                0,
                                (height - self.bheight)  / 2)
            else:
                cr.rectangle(width - line_width, 0, line_width, height)
                cr.fill()
                
                if self.show_button:
                    draw_pixbuf(cr, 
                                ui_theme.get_pixbuf("paned/paned_right_normal.png").get_pixbuf(),
                                0,
                                (height - self.bheight)  / 2)
        else:
            if self.shrink_first:
                cr.rectangle(0, 0, width, line_width)
                cr.fill()
                
                if self.show_button:
                    draw_pixbuf(cr, 
                                ui_theme.get_pixbuf("paned/paned_up_normal.png").get_pixbuf(),
                                (width - self.bheight) / 2,
                                0)
            else:
                cr.rectangle(0, height - line_width, width, line_width)
                cr.fill()

                if self.show_button:
                    draw_pixbuf(cr, 
                                ui_theme.get_pixbuf("paned/paned_down_normal.png").get_pixbuf(),
                                (width - self.bheight) / 2,
                                0)
Ejemplo n.º 40
0
 def draw_entry_cursor(self, cr, rect):
     '''Draw entry cursor.'''
     if self.grab_focus_flag and self.select_start_index == self.select_end_index:
         # Init.
         x, y, w, h = rect.x, rect.y, rect.width, rect.height
         left_str = self.content[0:self.cursor_index]
         left_str_width = self.get_content_width(left_str)
         padding_y = (h - (get_content_size("Height", self.font_size)[-1])) / 2
         
         # Draw cursor.
         cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("entry_cursor").get_color()))
         cr.rectangle(x + self.padding_x + left_str_width - self.offset_x,
                      y + padding_y,
                      1, 
                      h - padding_y * 2
                      )
         cr.fill()
Ejemplo n.º 41
0
 def __init__(self):
     object.__setattr__(self, "show_delay", 1000)
     object.__setattr__(self, "hide_delay", 3000)
     object.__setattr__(self, "hide_duration", 1000)
     object.__setattr__(self, "text", None)
     object.__setattr__(self, "text_args", None)
     object.__setattr__(self, "text_kargs", None)
     object.__setattr__(self, "custom", None)
     object.__setattr__(self, "custom_args", None)
     object.__setattr__(self, "custom_kargs", None)
     object.__setattr__(self, "background", gtk.gdk.Color(ui_theme.get_color("tooltip_background").get_color()))
     object.__setattr__(self, "padding_t", 5)
     object.__setattr__(self, "padding_b", 5)
     object.__setattr__(self, "padding_l", 5)
     object.__setattr__(self, "padding_r", 5)
     object.__setattr__(self, "has_shadow", True)
     object.__setattr__(self, "enable", False) #don't modify the "enable" init value
     object.__setattr__(self, "always_update", False)
Ejemplo n.º 42
0
def draw_button(widget, cache_pixbuf, normal_dpixbuf, hover_dpixbuf, press_dpixbuf,
                scale_x=False, button_label=None, font_size=DEFAULT_FONT_SIZE, 
                label_dcolor=ui_theme.get_color("button_default_font")):
    '''Create button.'''
    # Init request size.
    if scale_x:
        request_width = get_content_size(button_label, font_size)[0]
    else:
        request_width = normal_dpixbuf.get_pixbuf().get_width()
    request_height = normal_dpixbuf.get_pixbuf().get_height()
    widget.set_size_request(request_width, request_height)
    
    # Expose button.
    widget.connect("expose-event", lambda w, e: expose_button(
            w, e,
            cache_pixbuf,
            scale_x, False,
            normal_dpixbuf, hover_dpixbuf, press_dpixbuf,
            button_label, font_size, label_dcolor))
Ejemplo n.º 43
0
 def __init__(self):
     object.__setattr__(self, "show_delay", 1000)
     object.__setattr__(self, "hide_delay", 3000)
     object.__setattr__(self, "hide_duration", 1000)
     object.__setattr__(self, "text", None)
     object.__setattr__(self, "text_args", None)
     object.__setattr__(self, "text_kargs", None)
     object.__setattr__(self, "custom", None)
     object.__setattr__(self, "custom_args", None)
     object.__setattr__(self, "custom_kargs", None)
     object.__setattr__(
         self, "background",
         gtk.gdk.Color(
             ui_theme.get_color("tooltip_background").get_color()))
     object.__setattr__(self, "padding_t", 5)
     object.__setattr__(self, "padding_b", 5)
     object.__setattr__(self, "padding_l", 5)
     object.__setattr__(self, "padding_r", 5)
     object.__setattr__(self, "has_shadow", True)
     object.__setattr__(self, "enable",
                        False)  #don't modify the "enable" init value
     object.__setattr__(self, "always_update", False)
Ejemplo n.º 44
0
    def __init__(self, 
                 inactive_normal_dpixbuf, active_normal_dpixbuf, 
                 inactive_hover_dpixbuf=None, active_hover_dpixbuf=None, 
                 inactive_press_dpixbuf=None, active_press_dpixbuf=None,
                 inactive_disable_dpixbuf=None, active_disable_dpixbuf=None,
                 button_label=None, padding_x=0):
        '''Init font button.'''
        gtk.ToggleButton.__init__(self)
        font_size = DEFAULT_FONT_SIZE
        label_dcolor = ui_theme.get_color("button_default_font")
        self.button_press_flag = False
        
        self.inactive_pixbuf_group = (inactive_normal_dpixbuf,
                                      inactive_hover_dpixbuf,
                                      inactive_press_dpixbuf,
                                      inactive_disable_dpixbuf)
        
        self.active_pixbuf_group = (active_normal_dpixbuf,
                                    active_hover_dpixbuf,
                                    active_press_dpixbuf,
                                    active_disable_dpixbuf)

        # Init request size.
        label_width = 0
        button_width = inactive_normal_dpixbuf.get_pixbuf().get_width()
        button_height = inactive_normal_dpixbuf.get_pixbuf().get_height()
        if button_label:
            label_width = get_content_size(button_label, font_size)[0]
        self.set_size_request(button_width + label_width + padding_x * 2,
                              button_height)
        
        self.connect("button-press-event", self.button_press_cb)
        self.connect("button-release-event", self.button_release_cb)
        
        # Expose button.
        self.connect("expose-event", lambda w, e : self.expose_toggle_button(
                w, e,
                button_label, padding_x, font_size, label_dcolor))
Ejemplo n.º 45
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
Ejemplo n.º 46
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
Ejemplo n.º 47
0
    def __init__(self,
                 text="",
                 text_color=None,
                 text_size=DEFAULT_FONT_SIZE,
                 text_x_align=ALIGN_START,
                 label_width=None,
                 enable_gaussian=False,
                 enable_select=True,
                 enable_double_click=True,
                 gaussian_radious=2,
                 border_radious=1,
                 wrap_width=None,
                 underline=False,
                 hover_color=None,
                 fixed_width=None):
        '''
        Initialize Label class.

        @param text: Label text.
        @param text_color: Label text color, default is None.
        @param text_size: Label text size, default is DEFAULT_FONT_SIZE.
        @param text_x_align: Horizontal align option, default is ALIGN_START.
        @param label_width: Label maximum width, default is None.
        @param enable_gaussian: Default is False, if it is True, color option no effect, default gaussian effect is white text and black shadow.
        @param enable_select: Default is True, label content can't select if it is False.
        @param gaussian_radious: Radious of gaussian.
        @param border_radious: Radious of border.
        @param wrap_width: Wrap width.
        @param underline: Whether display underline, default is False.
        @param hover_color: Hover color, default is None.
        @param fixed_width: Fixed width, default is None.
        '''
        # Init.
        gtk.EventBox.__init__(self)
        self.set_visible_window(False)
        self.set_can_focus(True)  # can focus to response key-press signal
        self.label_width = label_width
        self.enable_gaussian = enable_gaussian
        self.enable_select = enable_select
        self.enable_double_click = enable_double_click
        self.select_start_index = self.select_end_index = 0
        self.double_click_flag = False
        self.left_click_flag = False
        self.left_click_coordindate = None
        self.drag_start_index = 0
        self.drag_end_index = 0
        self.wrap_width = wrap_width
        self.underline = underline
        self.hover_color = hover_color
        self.is_hover = False
        self.ellipsize = pango.ELLIPSIZE_END
        self.update_size_hook = None
        self.fixed_width = fixed_width

        self.text = text
        self.text_size = text_size
        if text_color == None:
            self.text_color = ui_theme.get_color("label_text")
        else:
            self.text_color = text_color
        self.text_select_color = ui_theme.get_color("label_select_text")
        self.text_select_background = ui_theme.get_color(
            "label_select_background")

        if self.enable_gaussian:
            self.gaussian_radious = gaussian_radious
            self.border_radious = border_radious
            self.gaussian_color = "#000000"
            self.border_color = "#000000"
        else:
            self.gaussian_radious = None
            self.border_radious = None
            self.gaussian_color = None
            self.border_color = None

        self.text_x_align = text_x_align

        self.update_size()

        self.connect("expose-event", self.expose_label)
        self.connect("button-press-event", self.button_press_label)
        self.connect("button-release-event", self.button_release_label)
        self.connect("motion-notify-event", self.motion_notify_label)
        self.connect("key-press-event", self.key_press_label)
        self.connect("focus-out-event", self.focus_out_label)

        # Add keymap.
        self.keymap = {
            "Ctrl + c": self.copy_to_clipboard,
        }
Ejemplo n.º 48
0
    def __init__(
        self,
        button_mask=["theme", "menu", "max", "min", "close"],
        icon_path=None,
        app_name=None,
        title=None,
        add_separator=False,
        height=26,
        show_title=True,
        enable_gaussian=True,
        name_size=DEFAULT_FONT_SIZE,
        title_size=DEFAULT_FONT_SIZE,
    ):
        '''
        Initialize the title bar.

        @param button_mask: A string list. Each item of it indicates that there is a corresponding button on the title bar. By default, it's ["theme", "menu", "max", "min", "close"], which means theme button, menu button, max button, min button and close button, respectively.
        @param icon_path: The path of icon image.
        @param app_name: Application name string. It will be displayed just next to the icon_dpixbuf. By default, it's None.
        @param title: Title string of the application. It will be displayed on the center of the title bar. By default, it's None.
        @param add_separator: If True, add a separation line between the title bar and the body of the window. By default, it's False.
        @param height: The height of the title bar. By default, it's 26 pixels.
        @param show_title: If False, the title bar will not be displayed. By default, it's True.
        @param enable_gaussian: Whether enable gaussian on title, default is True.
        @param name_size: The size of name, default is DEFAULT_FONT_SIZE.
        @param title_size: The size of title, default is DEFAULT_FONT_SIZE.
        '''
        # Init.
        EventBox.__init__(self)
        self.set_size_request(-1, height)
        self.v_layout_box = gtk.VBox()
        self.h_layout_box = gtk.HBox()
        self.add(self.v_layout_box)
        self.v_layout_box.pack_start(self.h_layout_box, True, True)

        # Init separator.
        if add_separator:
            self.separator = gtk.HBox()
            self.separator.set_size_request(-1, 1)
            self.separator.connect("expose-event",
                                   self.expose_titlebar_separator)
            self.v_layout_box.pack_start(self.separator, True, True)

        # Add drag event box.
        self.drag_box = EventBox()
        self.h_layout_box.pack_start(self.drag_box, True, True)

        # Init left box to contain icon and title.
        self.left_box = gtk.HBox()
        self.drag_box.add(self.left_box)

        if show_title:
            # Add icon.
            if icon_path != None:
                self.icon_image_box = gtk.image_new_from_pixbuf(
                    gtk.gdk.pixbuf_new_from_file(icon_path))
                self.icon_align = gtk.Alignment()
                self.icon_align.set(0.5, 0.5, 0.0, 0.0)
                self.icon_align.set_padding(5, 5, 5, 0)
                self.icon_align.add(self.icon_image_box)
                self.left_box.pack_start(self.icon_align, False, False)

            # Add app name.
            if app_name == None:
                app_name_label = ""
            else:
                app_name_label = app_name
            self.app_name_box = Label(
                app_name_label,
                text_color=ui_theme.get_color("title_text"),
                enable_gaussian=enable_gaussian,
                text_size=name_size,
            )
            self.app_name_align = gtk.Alignment()
            self.app_name_align.set(0.5, 0.5, 0.0, 0.0)
            self.app_name_align.set_padding(2, 0, 5, 0)
            self.app_name_align.add(self.app_name_box)
            self.left_box.pack_start(self.app_name_align, False, False)

            # Add title.
            if title == None:
                title_label = ""
            else:
                title_label = title
            self.title_box = Label(
                title_label,
                text_color=ui_theme.get_color("title_text"),
                enable_gaussian=enable_gaussian,
                text_x_align=pango.ALIGN_CENTER,
                text_size=title_size,
            )
            self.title_align = gtk.Alignment()
            self.title_align.set(0.5, 0.5, 0.0, 0.0)
            self.title_align.set_padding(2, 0, 30, 30)
            self.title_align.add(self.title_box)
            self.left_box.pack_start(self.title_align, True, True)

        # Add button box.
        self.button_box = gtk.HBox()
        self.button_align = gtk.Alignment()
        self.button_align.set(1.0, 0.0, 0.0, 0.0)
        self.button_align.set_padding(0, 0, 0, 0)
        self.button_align.add(self.button_box)
        self.right_box = gtk.VBox()
        self.right_box.pack_start(self.button_align, False, False)
        self.h_layout_box.pack_start(self.right_box, False, False)

        # Add theme button.
        if "theme" in button_mask:
            self.theme_button = ThemeButton()
            self.button_box.pack_start(self.theme_button, False, False, 1)
            Tooltip.text(self.theme_button,
                         _("Change skin")).show_delay(self.theme_button, 2000)

        # Add menu button.
        if "menu" in button_mask:
            self.menu_button = MenuButton()
            self.button_box.pack_start(self.menu_button, False, False, 1)
            Tooltip.text(self.menu_button,
                         _("Main menu")).show_delay(self.menu_button, 2000)

        # Add min button.
        if "min" in button_mask:
            self.min_button = MinButton()
            self.button_box.pack_start(self.min_button, False, False, 1)
            Tooltip.text(self.min_button,
                         _("Minimize")).show_delay(self.min_button, 2000)

        # Add max button.
        if "max" in button_mask:
            self.max_button = MaxButton()
            self.button_box.pack_start(self.max_button, False, False, 1)
            Tooltip.text(self.max_button,
                         _("Maximize")).show_delay(self.max_button, 2000)

        # Add close button.
        if "close" in button_mask:
            self.close_button = CloseButton()
            self.button_box.pack_start(self.close_button, False, False)
            Tooltip.text(self.close_button,
                         _("Close")).show_delay(self.close_button, 2000)

        # Show.
        self.show_all()
Ejemplo n.º 49
0
    def __init__(
        self,
        can_close_tab=False,
        dockfill=False,
        current_tab_index=-1,
    ):
        '''
        Initialize TabBox class.

        @param can_close_tab: Whether display close button on tab, default is False.
        @param dockfill: Whether make tab's width fill with TabBox's width.
        @param current_tab_index: The index of current tab, default is -1.
        '''
        # Init.
        gtk.VBox.__init__(self)
        self.tab_height = 29
        self.tab_padding_x = 19
        self.tab_padding_y = 9
        self.tab_select_bg_color = ui_theme.get_color("tab_select_bg")
        self.tab_select_frame_color = ui_theme.get_color("tab_select_frame")
        self.tab_unselect_bg_color = ui_theme.get_color("tab_unselect_bg")
        self.tab_unselect_frame_color = ui_theme.get_color("tab_unselect_bg")
        self.can_close_tab = can_close_tab
        self.close_button_size = 6
        self.close_button_frame_size = 3
        self.close_button_padding_x = 4
        self.close_button_padding_y = 6
        self.close_button_select_background_color = "#EE0000"
        self.close_button_select_foreground_color = "#FFFFFF"
        self.close_button_color = "#666666"
        self.hover_close_button_index = None
        self.dockfill = dockfill
        self.tab_box_width = -1
        self.current_tab_index = current_tab_index

        self.tab_title_box = gtk.DrawingArea()
        self.tab_title_box.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.tab_title_box.set_size_request(-1, self.tab_height)
        self.tab_title_align = gtk.Alignment()
        self.tab_title_align.set(0.0, 0.0, 1.0, 1.0)
        self.tab_title_align.set_padding(0, 0, 0, 0)
        self.tab_title_align.add(self.tab_title_box)
        self.tab_content_align = gtk.Alignment()
        self.tab_content_align.set(0.0, 0.0, 1.0, 1.0)
        self.tab_content_align.set_padding(0, 0, 0, 0)
        self.tab_content_box = gtk.VBox()
        self.tab_content_align.add(self.tab_content_box)

        self.tab_items = []
        self.tab_title_widths = []
        self.tab_index = -1

        self.default_widget = None

        self.pack_start(self.tab_title_align, False, False)
        self.pack_start(self.tab_content_align, True, True)

        self.tab_title_box.connect("button-press-event",
                                   self.press_tab_title_box)
        self.tab_title_box.connect("expose-event", self.expose_tab_title_box)
        self.tab_title_box.connect("motion-notify-event",
                                   self.motion_notify_tab_title_box)
        self.tab_content_align.connect("expose-event",
                                       self.expose_tab_content_align)
        self.tab_content_box.connect("expose-event",
                                     self.expose_tab_content_box)
Ejemplo n.º 50
0
    def expose_menu_item(self, widget, event):
        '''
        Internal callback for `expose` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        font_color = ui_theme.get_color("menu_font").get_color()
        (item_icons, item_content, item_node) = self.item[0:3]

        # Draw select effect.
        if widget.state == gtk.STATE_INSENSITIVE:
            # Set font color.
            font_color = ui_theme.get_color("menu_disable_font").get_color()
        elif self.submenu_active or widget.state in [
                gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE
        ]:
            # Draw background.
            if self.menu_item_select_color:
                item_select_color = self.menu_item_select_color
            else:
                item_select_color = ui_theme.get_shadow_color(
                    "menu_item_select").get_color_info()
            draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height,
                         item_select_color, MENU_ITEM_RADIUS)

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

        # Draw item icon.
        pixbuf = None
        pixbuf_width = 0
        if item_icons:
            (item_normal_dpixbuf, item_hover_dpixbuf,
             item_disable_dpixbuf) = item_icons
            if widget.state == gtk.STATE_INSENSITIVE:
                pixbuf = item_disable_dpixbuf.get_pixbuf()
            elif self.submenu_active or widget.state in [
                    gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE
            ]:
                if item_hover_dpixbuf == None:
                    pixbuf = item_normal_dpixbuf.get_pixbuf()
                else:
                    pixbuf = item_hover_dpixbuf.get_pixbuf()
            else:
                pixbuf = item_normal_dpixbuf.get_pixbuf()
            pixbuf_width += pixbuf.get_width()
            draw_pixbuf(cr, pixbuf, rect.x + self.item_padding_x,
                        rect.y + (rect.height - pixbuf.get_height()) / 2)

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

        # Draw submenu arrow.
        if isinstance(item_node, Menu):
            if widget.state == gtk.STATE_INSENSITIVE:
                submenu_pixbuf = ui_theme.get_pixbuf(
                    "menu/arrow_disable.png").get_pixbuf()
            elif self.submenu_active or widget.state in [
                    gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE
            ]:
                submenu_pixbuf = ui_theme.get_pixbuf(
                    "menu/arrow_hover.png").get_pixbuf()
            else:
                submenu_pixbuf = ui_theme.get_pixbuf(
                    "menu/arrow_normal.png").get_pixbuf()
            draw_pixbuf(
                cr, submenu_pixbuf, rect.x + rect.width - self.item_padding_x -
                submenu_pixbuf.get_width() - self.arrow_padding_x,
                rect.y + (rect.height - submenu_pixbuf.get_height()) / 2)

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

        return True
Ejemplo n.º 51
0
    def render(self, cr, rect):
        # Init.
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

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

            cr.set_source_rgb(*color_hex_to_cairo(
                ui_theme.get_color(
                    "progressbar_background_frame").get_color()))
            cr.rectangle(x, y, w, h)
            cr.set_line_width(1)
            cr.stroke()

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

            draw_vlinear(
                cr,
                x + 1,
                y + 1,
                w - 2,
                h - 2,
                ui_theme.get_shadow_color(
                    "progressbar_background").get_color_info(),
            )

        if self.progress > 0:
            # Draw foreground frame.
            with cairo_state(cr):
                cr.rectangle(x, y + 1, w, h - 2)
                cr.rectangle(x + 1, y, w - 2, h)
                cr.clip()

                cr.set_antialias(cairo.ANTIALIAS_NONE)
                cr.set_source_rgb(*color_hex_to_cairo(
                    ui_theme.get_color(
                        "progressbar_foreground_frame").get_color()))
                cr.rectangle(x + 1, y + 1,
                             int(w * self.progress / 100) - 1, h - 1)
                cr.set_line_width(1)
                cr.stroke()

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

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

        # Draw light.
        with cairo_disable_antialias(cr):
            cr.set_source_rgba(1, 1, 1, 0.5)
            cr.rectangle(x + 1, y + 1, w - 2, 1)
            cr.fill()
Ejemplo n.º 52
0
    def __init__(self):
        '''
        Initialize MACEntry class.
        '''
        gtk.VBox.__init__(self)
        self.width = 130
        self.height = 22
        self.set_size_request(self.width, self.height)
        self.normal_frame = ui_theme.get_color("entry_normal_frame")
        self.alert_frame = ui_theme.get_color("entry_alert_frame")
        self.frame_color = self.normal_frame
        self.default_address = ":::::"
        self.mac = self.default_address
        self.grab_focus_flag = False
        self.segment_split_char = ":"
        self.dot_size = get_content_size(self.segment_split_char)[0]
        self.chars_a_z = map(lambda a: str(chr(a)), range(97, 103))
        self.chars_A_Z = map(lambda a: str(chr(a)), range(65, 71))
        self.mac_chars = self.chars_a_z + self.chars_A_Z + map(
            str, range(0, 10)) + [self.segment_split_char]
        self.select_active_color = ui_theme.get_shadow_color(
            "select_active_background")
        self.select_inactive_color = ui_theme.get_shadow_color(
            "select_inactive_background")
        self.segment_number = 6
        self.last_segment_index = self.segment_number - 1
        self.segment_max_chars = 2

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

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

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

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

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

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

        self.calculate_cursor_positions()
Ejemplo n.º 53
0
    def draw_label_text(self, cr, rect):
        '''
        Internal fucntion to draw label text.

        @param cr: Cairo context.
        @param rect: Draw area.
        '''
        if self.enable_gaussian:
            label_color = "#FFFFFF"
        elif self.is_hover and self.hover_color:
            label_color = self.hover_color.get_color()
        else:
            label_color = self.text_color.get_color()

        if not self.get_sensitive():
            draw_text(
                cr,
                self.text,
                rect.x,
                rect.y,
                rect.width,
                rect.height,
                self.text_size,
                ui_theme.get_color("disable_text").get_color(),
                alignment=self.text_x_align,
                gaussian_radious=self.gaussian_radious,
                gaussian_color=self.gaussian_color,
                border_radious=self.border_radious,
                border_color=self.border_color,
                wrap_width=self.wrap_width,
                underline=self.underline,
                ellipsize=self.ellipsize,
            )
        elif self.select_start_index == self.select_end_index:
            draw_text(
                cr,
                self.text,
                rect.x,
                rect.y,
                rect.width,
                rect.height,
                self.text_size,
                label_color,
                alignment=self.text_x_align,
                gaussian_radious=self.gaussian_radious,
                gaussian_color=self.gaussian_color,
                border_radious=self.border_radious,
                border_color=self.border_color,
                wrap_width=self.wrap_width,
                underline=self.underline,
                ellipsize=self.ellipsize,
            )
        else:
            select_start_width = self.get_content_width(
                self.text[0:self.select_start_index])
            select_end_width = self.get_content_width(
                self.text[0:self.select_end_index])

            # Draw left text.
            if self.text[0:self.select_start_index] != "":
                draw_text(
                    cr,
                    self.text[0:self.select_start_index],
                    rect.x,
                    rect.y,
                    rect.width,
                    rect.height,
                    self.text_size,
                    label_color,
                    alignment=self.text_x_align,
                    gaussian_radious=self.gaussian_radious,
                    gaussian_color=self.gaussian_color,
                    border_radious=self.border_radious,
                    border_color=self.border_color,
                    wrap_width=self.wrap_width,
                    underline=self.underline,
                    ellipsize=self.ellipsize,
                )

            # Draw middle text.
            if self.text[self.select_start_index:self.select_end_index] != "":
                draw_text(
                    cr,
                    self.text[self.select_start_index:self.select_end_index],
                    rect.x + select_start_width,
                    rect.y,
                    rect.width,
                    rect.height,
                    self.text_size,
                    self.text_select_color.get_color(),
                    alignment=self.text_x_align,
                    gaussian_radious=self.gaussian_radious,
                    gaussian_color=self.gaussian_color,
                    border_radious=self.border_radious,
                    border_color=self.border_color,
                    wrap_width=self.wrap_width,
                    underline=self.underline,
                    ellipsize=self.ellipsize,
                )

            # Draw right text.
            if self.text[self.select_end_index::] != "":
                draw_text(
                    cr,
                    self.text[self.select_end_index::],
                    rect.x + select_end_width,
                    rect.y,
                    rect.width,
                    rect.height,
                    self.text_size,
                    label_color,
                    alignment=self.text_x_align,
                    gaussian_radious=self.gaussian_radious,
                    gaussian_color=self.gaussian_color,
                    border_radious=self.border_radious,
                    border_color=self.border_color,
                    wrap_width=self.wrap_width,
                    underline=self.underline,
                    ellipsize=self.ellipsize,
                )
Ejemplo n.º 54
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
Ejemplo n.º 55
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
Ejemplo n.º 56
0
    def expose_notebook(self, widget, event):
        '''
        Internal callback for `expose-event` signal.

        @param widget: Notebook wiget.
        @param event: Expose event.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        foreground_left_pixbuf = self.foreground_left_pixbuf.get_pixbuf()
        self.cache_fg_pixbuf.scale(
            self.foreground_middle_pixbuf.get_pixbuf(),
            self.tab_width - foreground_left_pixbuf.get_width() * 2,
            self.tab_height)
        foreground_middle_pixbuf = self.cache_fg_pixbuf.get_cache()
        foreground_right_pixbuf = self.foreground_right_pixbuf.get_pixbuf()
        background_left_pixbuf = self.background_left_pixbuf.get_pixbuf()
        self.cache_bg_pixbuf.scale(
            self.background_middle_pixbuf.get_pixbuf(),
            self.tab_width - background_left_pixbuf.get_width() * 2,
            self.tab_height)
        background_middle_pixbuf = self.cache_bg_pixbuf.get_cache()
        background_right_pixbuf = self.background_right_pixbuf.get_pixbuf()

        # Draw tab.
        for (index, (item_icon, item_content,
                     item_callback)) in enumerate(self.items):
            # Draw background.
            if self.current_item_index == index:
                draw_pixbuf(cr, foreground_left_pixbuf,
                            rect.x + index * self.tab_width, rect.y)
                draw_pixbuf(
                    cr, foreground_middle_pixbuf,
                    rect.x + index * self.tab_width +
                    foreground_left_pixbuf.get_width(), rect.y)
                draw_pixbuf(
                    cr, foreground_right_pixbuf,
                    rect.x + (index + 1) * self.tab_width -
                    foreground_left_pixbuf.get_width(), rect.y)
            else:
                draw_pixbuf(cr, background_left_pixbuf,
                            rect.x + index * self.tab_width, rect.y)
                draw_pixbuf(
                    cr, background_middle_pixbuf,
                    rect.x + index * self.tab_width +
                    background_left_pixbuf.get_width(), rect.y)
                draw_pixbuf(
                    cr, background_right_pixbuf,
                    rect.x + (index + 1) * self.tab_width -
                    background_left_pixbuf.get_width(), rect.y)

            # Draw content.
            (content_width,
             content_height) = get_content_size(item_content,
                                                DEFAULT_FONT_SIZE)
            if item_icon != None:
                tab_render_width = self.icon_width + self.padding_middle + content_width
                draw_pixbuf(
                    cr, item_icon.get_pixbuf(),
                    rect.x + index * self.tab_width +
                    (self.tab_width - tab_render_width) / 2, rect.y +
                    (self.tab_height - item_icon.get_pixbuf().get_height()) /
                    2)

                draw_text(
                    cr,
                    item_content,
                    rect.x + index * self.tab_width +
                    (self.tab_width - tab_render_width) / 2 + self.icon_width +
                    self.padding_middle,
                    rect.y + (self.tab_height - content_height) / 2,
                    content_width,
                    content_height,
                    DEFAULT_FONT_SIZE,
                    ui_theme.get_color("notebook_font").get_color(),
                )
            else:
                tab_render_width = content_width
                draw_text(
                    cr,
                    item_content,
                    rect.x + index * self.tab_width +
                    (self.tab_width - tab_render_width) / 2 + self.icon_width +
                    self.padding_middle,
                    rect.y + (self.tab_height - content_height) / 2,
                    content_width,
                    content_height,
                    DEFAULT_FONT_SIZE,
                    ui_theme.get_color("notebook_font").get_color(),
                )

        propagate_expose(widget, event)

        return True