Exemplo n.º 1
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)
Exemplo n.º 2
0
 def __init__(self, items, add_separator=False, font_size=DEFAULT_FONT_SIZE, padding_x=10, padding_y=10):
     '''Init navigatebar.'''
     # Init event box.
     EventBox.__init__(self)
     self.nav_index = 0
     
     # Init nav box.
     self.nav_box = gtk.VBox()
     self.add(self.nav_box)
     
     # Init item box.
     self.nav_item_box = gtk.HBox()
     self.nav_box.pack_start(self.nav_item_box, False, False)
     
     # Add navigate item.
     if items:
         for (index, item) in enumerate(items):
             nav_item = NavItem(item, index, font_size, padding_x, padding_y, self.set_index, self.get_index)
             self.nav_item_box.pack_start(nav_item.item_box, False, False)
             
     # Add separator.
     if add_separator:                
         self.separator = gtk.HBox()
         self.separator.set_size_request(-1, 2)
         self.separator.connect("expose-event", self.expose_navseparator)
         self.nav_box.pack_start(self.separator, False, False)
     
     # Show.
     self.show_all()
Exemplo n.º 3
0
 def __init__(self, 
              height, 
              add_separator=False,
              ):
     '''
     Initialize Statusbar class.
     
     @param height: Statusbar height.
     @param add_separator: Whether add separator between statusbar and window body, default is False.
     '''
     # Init.
     EventBox.__init__(self)
     self.set_size_request(-1, height)
     
     # Init status box.
     self.status_box = gtk.VBox()
     self.add(self.status_box)
     
     # Init separator.
     if add_separator:
         self.separator = gtk.HBox()
         self.separator.set_size_request(-1, 2)
         self.separator.connect("expose-event", self.expose_status_separator)
         self.status_box.pack_start(self.separator, False, False)
     
     # Init status item box.
     self.status_item_box = gtk.HBox()
     self.status_box.pack_start(self.status_item_box, True, True)
     
     # Show.
     self.show_all()
Exemplo n.º 4
0
    def __init__(self, 
                 label_content,
                 label_wrap_width,
                 label_init_height,
                 label_init_line,
                 label_font_size=DEFAULT_FONT_SIZE,
                 label_font_color="#000000",
                 ):
        '''
        Initialize ResizableLabel class.
        
        @param label_content: The content of label.
        @param label_wrap_width: The wrap width of label.
        @param label_init_height: The initialize height of label. 
        @param label_init_line: The initialize line number of label.
        @param label_font_size: The font size.
        @param label_font_color: The font color.
        '''
        EventBox.__init__(self)
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.buffer = ResizableLabelBuffer(
            label_content,
            label_wrap_width,
            label_init_height,
            label_init_line,
            label_font_size,
            label_font_color,
            )
        
        self.set_size_request(self.buffer.init_width, self.buffer.init_height)

        self.buffer.connect("update", self.update_size)
        self.connect("expose-event", self.expose_resizable_label)
        self.connect("button-press-event", self.button_press_resizable_label)
Exemplo n.º 5
0
    def __init__(self,
                 label_content,
                 label_wrap_width,
                 label_init_height,
                 label_init_line,
                 label_font_size=DEFAULT_FONT_SIZE,
                 label_font_color="#000000",
                 ):
        '''
        Initialize ResizableLabel class.

        @param label_content: The content of label.
        @param label_wrap_width: The wrap width of label.
        @param label_init_height: The initialize height of label.
        @param label_init_line: The initialize line number of label.
        @param label_font_size: The font size.
        @param label_font_color: The font color.
        '''
        EventBox.__init__(self)
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.buffer = ResizableLabelBuffer(
            label_content,
            label_wrap_width,
            label_init_height,
            label_init_line,
            label_font_size,
            label_font_color,
            )

        self.set_size_request(self.buffer.init_width, self.buffer.init_height)

        self.buffer.connect("update", self.update_size)
        self.connect("expose-event", self.expose_resizable_label)
        self.connect("button-press-event", self.button_press_resizable_label)
Exemplo n.º 6
0
    def __init__(
        self,
        height,
        add_separator=False,
    ):
        '''
        Initialize Statusbar class.

        @param height: Statusbar height.
        @param add_separator: Whether add separator between statusbar and window body, default is False.
        '''
        # Init.
        EventBox.__init__(self)
        self.set_size_request(-1, height)

        # Init status box.
        self.status_box = gtk.VBox()
        self.add(self.status_box)

        # Init separator.
        if add_separator:
            self.separator = gtk.HBox()
            self.separator.set_size_request(-1, 2)
            self.separator.connect("expose-event",
                                   self.expose_status_separator)
            self.status_box.pack_start(self.separator, False, False)

        # Init status item box.
        self.status_item_box = gtk.HBox()
        self.status_box.pack_start(self.status_item_box, True, True)

        # Show.
        self.show_all()
Exemplo n.º 7
0
    def __init__(
        self,
        items,
        add_separator=False,
        font_size=DEFAULT_FONT_SIZE,
        padding_x=10,
        padding_y=10,
        vertical=True,
        item_hover_pixbuf=ui_theme.get_pixbuf(
            "navigatebar/nav_item_hover.png"),
        item_press_pixbuf=ui_theme.get_pixbuf(
            "navigatebar/nav_item_press.png"),
    ):
        '''
        Initialize Navigatebar class.

        @param items: A list of navigate item, item format: (item_icon_dpixbuf, item_content, clicked_callback)
        @param add_separator: Whether add separator between navigatebar and body, default is False.
        @param font_size: Font size, default is DEFAULT_FONT_SIZE.
        @param padding_x: Padding value horizontal.
        @param padding_y: Padding value vertical.
        @param vertical: Draw direction, default is vertical.
        @param item_hover_pixbuf: Item hover dpixbuf.
        @param item_press_pixbuf: Item press dpixbuf.
        '''
        # Init event box.
        EventBox.__init__(self)
        self.nav_index = 0
        self.item_hover_pixbuf = item_hover_pixbuf
        self.item_press_pixbuf = item_press_pixbuf
        self.nav_items = []

        # Init nav box.
        self.nav_box = gtk.VBox()
        self.add(self.nav_box)

        # Init item box.
        self.nav_item_box = gtk.HBox()
        self.nav_box.pack_start(self.nav_item_box, False, False)

        # Add navigate item.
        if items:
            for (index, item) in enumerate(items):
                nav_item = NavItem(item, index, font_size, padding_x,
                                   padding_y, vertical, self.set_index,
                                   self.get_index, self.item_hover_pixbuf,
                                   self.item_press_pixbuf)
                self.nav_items.append(nav_item)
                self.nav_item_box.pack_start(nav_item.item_box, False, False)

        # Add separator.
        if add_separator:
            self.separator = gtk.HBox()
            self.separator.set_size_request(-1, 2)
            self.separator.connect("expose-event", self.expose_nav_separator)
            self.nav_box.pack_start(self.separator, False, False)

        # Show.
        self.show_all()
Exemplo n.º 8
0
    def __init__(self,
                 items,
                 add_separator=False,
                 font_size=DEFAULT_FONT_SIZE,
                 padding_x=10,
                 padding_y=10,
                 vertical=True,
                 item_hover_pixbuf=ui_theme.get_pixbuf("navigatebar/nav_item_hover.png"),
                 item_press_pixbuf=ui_theme.get_pixbuf("navigatebar/nav_item_press.png"),
                 ):
        '''
        Initialize Navigatebar class.

        @param items: A list of navigate item, item format: (item_icon_dpixbuf, item_content, clicked_callback)
        @param add_separator: Whether add separator between navigatebar and body, default is False.
        @param font_size: Font size, default is DEFAULT_FONT_SIZE.
        @param padding_x: Padding value horizontal.
        @param padding_y: Padding value vertical.
        @param vertical: Draw direction, default is vertical.
        @param item_hover_pixbuf: Item hover dpixbuf.
        @param item_press_pixbuf: Item press dpixbuf.
        '''
        # Init event box.
        EventBox.__init__(self)
        self.nav_index = 0
        self.item_hover_pixbuf = item_hover_pixbuf
        self.item_press_pixbuf = item_press_pixbuf
        self.nav_items = []

        # Init nav box.
        self.nav_box = gtk.VBox()
        self.add(self.nav_box)

        # Init item box.
        self.nav_item_box = gtk.HBox()
        self.nav_box.pack_start(self.nav_item_box, False, False)

        # Add navigate item.
        if items:
            for (index, item) in enumerate(items):
                nav_item = NavItem(item, index, font_size, padding_x, padding_y, vertical,
                                   self.set_index, self.get_index,
                                   self.item_hover_pixbuf,
                                   self.item_press_pixbuf)
                self.nav_items.append(nav_item)
                self.nav_item_box.pack_start(nav_item.item_box, False, False)

        # Add separator.
        if add_separator:
            self.separator = gtk.HBox()
            self.separator.set_size_request(-1, 2)
            self.separator.connect("expose-event", self.expose_nav_separator)
            self.nav_box.pack_start(self.separator, False, False)

        # Show.
        self.show_all()
Exemplo n.º 9
0
 def __init__(self, height, add_separator=False):
     '''Init statusbar.'''
     # Init.
     EventBox.__init__(self)
     self.set_size_request(-1, height)
     
     # Init status box.
     self.status_box = gtk.VBox()
     self.add(self.status_box)
     
     # Init separator.
     if add_separator:
         self.separator = gtk.HBox()
         self.separator.set_size_request(-1, 2)
         self.separator.connect("expose-event", self.expose_status_separator)
         self.status_box.pack_start(self.separator, False, False)
     
     # Init status item box.
     self.status_item_box = gtk.HBox()
     self.status_box.pack_start(self.status_item_box, True, True)
     
     # Show.
     self.show_all()
Exemplo n.º 10
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)
Exemplo n.º 11
0
    def __init__(self, 
                 button_mask=["theme", "menu", "max", "min", "close"],
                 icon_dpixbuf=None,
                 app_name=None,
                 title=None,
                 add_separator=False,
                 height=26,
                 show_title=True,
                 ):
        """
        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_dpixbuf: A pixbuf of type dtk.ui.theme.DynamicPixbuf. It will be displayed at the top left of the window. By default, it's None.
        @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 hight 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.
        """
        # 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_dpixbuf != None:
                self.icon_image_box = ImageBox(icon_dpixbuf)
                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:
                self.app_name_box = Label(app_name, enable_gaussian=True)
                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:
                self.title_box = Label(title, enable_gaussian=True, text_x_align=pango.ALIGN_CENTER)
                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.h_layout_box.pack_start(self.button_align, 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, _("Minimum")).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()
Exemplo n.º 12
0
class Titlebar(EventBox):
    """
    Titlebar defines every thing of a title bar of a application based on deepin ui.
    
    @undocumented: expose_titlebar_separator
    """
    def __init__(self, 
                 button_mask=["theme", "menu", "max", "min", "close"],
                 icon_dpixbuf=None,
                 app_name=None,
                 title=None,
                 add_separator=False,
                 height=26,
                 show_title=True,
                 ):
        """
        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_dpixbuf: A pixbuf of type dtk.ui.theme.DynamicPixbuf. It will be displayed at the top left of the window. By default, it's None.
        @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 hight 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.
        """
        # 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_dpixbuf != None:
                self.icon_image_box = ImageBox(icon_dpixbuf)
                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:
                self.app_name_box = Label(app_name, enable_gaussian=True)
                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:
                self.title_box = Label(title, enable_gaussian=True, text_x_align=pango.ALIGN_CENTER)
                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.h_layout_box.pack_start(self.button_align, 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, _("Minimum")).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()
        
    def expose_titlebar_separator(self, widget, event):
        """
        Expose the separation line between the titlebar and the body of the window.

        @param widget: A widget of type Gtk.Widget.
        @param event: Not used.
        @return: Always return True.
        """
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
    
        # Draw separator.
        cr.set_source_rgba(1, 1, 1, 0.5)
        draw_line(cr, rect.x + 1, rect.y + 2, rect.x + rect.width - 1, rect.y + 1)
    
        return True
    
    def change_title(self, title):
        """
        Change the title of the application, which is diplayed on the center of the title bar.
        
        @param title: New title string that want to set.
        """
        self.title_box.set_text(title)
Exemplo n.º 13
0
class TabBox(gtk.VBox):
    '''Tab box.'''
	
    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)
        
    def add_items(self, items, default_index=0):
        '''Add items.'''
        self.tab_items += items
        
        for item in items:
            self.tab_title_widths.append(get_content_size(item[0], DEFAULT_FONT_SIZE)[0] + self.tab_padding_x * 2)
            
        self.switch_content(default_index)
    
    def switch_content(self, index):
        '''Switch content.'''
        if self.tab_index != index:
            self.tab_index = index
            widget = self.tab_items[index][1]
                
            container_remove_all(self.tab_content_box)
            self.tab_content_box.add(widget)
            self.tab_title_box.queue_draw()
            self.tab_content_box.queue_draw()
            
            self.show_all()
        
    def press_tab_title_box(self, widget, event):
        '''Press tab title box.'''
        for (index, item) in enumerate(self.tab_items):
            if is_in_rect((event.x, event.y), 
                          (sum(self.tab_title_widths[0:index]),
                           0,
                           self.tab_title_widths[index],
                           self.tab_height)):
                self.switch_content(index)
                break

    def expose_tab_title_box(self, widget, event):
        '''Expose tab title box.'''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        # Draw title unselect tab.
        tab_title_width = sum(self.tab_title_widths)
        
        with cairo_state(cr):
            with cairo_disable_antialias(cr):
                cr.rectangle(rect.x,
                             rect.y,
                             sum(self.tab_title_widths[0:self.tab_index]),
                             self.tab_height)
                cr.rectangle(rect.x + sum(self.tab_title_widths[0:min(self.tab_index + 1, len(self.tab_items))]) + 1,
                             rect.y,
                             sum(self.tab_title_widths) - sum(self.tab_title_widths[0:min(self.tab_index + 1, len(self.tab_items))]),
                             self.tab_height)
                cr.clip()
                
                cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_bg_color.get_color(), 0.7)))
                cr.rectangle(rect.x + 1, rect.y + 1, tab_title_width, self.tab_height)
                cr.fill()
                    
                cr.set_line_width(1)
                cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_frame_color.get_color(), 1.0)))
                cr.rectangle(rect.x + 1, rect.y + 1, tab_title_width, self.tab_height)
                cr.stroke()
                
                for (index, width) in enumerate(self.tab_title_widths[:-1]):
                    cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_frame_color.get_color(), 1.0)))
                    cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:index]) + width,
                                 rect.y + 1,
                                 1,
                                 self.tab_height)
                    cr.fill()
                    
                cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))    
                cr.rectangle(rect.x,
                             rect.y + rect.height - 1,
                             sum(self.tab_title_widths[0:self.tab_index]),
                             1)
                cr.fill()
            
                cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))    
                cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:self.tab_index]),
                             rect.y + rect.height - 1,
                             rect.width - sum(self.tab_title_widths[0:self.tab_index]),
                             1)
                cr.fill()
                        
        for (index, item) in enumerate(self.tab_items):
            # Draw title background.
            title = item[0]
            
            # Draw title tab.
            with cairo_disable_antialias(cr):
                if index == self.tab_index:
                    # Draw title select tab.
                    cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_select_bg_color.get_color(), 0.93)))    
                    if index == 0:
                        cr.rectangle(rect.x + sum(self.tab_title_widths[0:index]),
                                     rect.y + 1,
                                     self.tab_title_widths[index] + 1,
                                     self.tab_height)
                    else:
                        cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:index]),
                                     rect.y + 1,
                                     self.tab_title_widths[index],
                                     self.tab_height)
                    cr.fill()
                    
                    if index == 0:
                        cr.rectangle(rect.x,
                                     rect.y,
                                     rect.width,
                                     self.tab_height)
                        cr.clip()
                        
                    cr.set_line_width(1)
                    cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))    
                    if index == 0:
                        cr.rectangle(rect.x + sum(self.tab_title_widths[0:index]),
                                     rect.y + 1,
                                     self.tab_title_widths[index] + 2,
                                     self.tab_height)
                    else:
                        cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:index]),
                                     rect.y + 1,
                                     self.tab_title_widths[index] + 1,
                                     self.tab_height)
                    cr.stroke()
                    
            draw_text(cr, title, 
                        rect.x + sum(self.tab_title_widths[0:index]) + self.tab_padding_x,
                        rect.y + self.tab_padding_y,
                        self.tab_title_widths[index] - self.tab_padding_x * 2,
                        self.tab_height - self.tab_padding_y * 2,
                        )
    
    def expose_tab_content_align(self, widget, event):
        '''Expose tab content box.'''
        cr = widget.window.cairo_create()
        rect = widget.allocation

        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color()))
            cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2)
            cr.stroke()

    def expose_tab_content_box(self, widget, event):
        '''Expose tab content box.'''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        # Draw background.
        toplevel = widget.get_toplevel()
        coordinate = widget.translate_coordinates(toplevel, rect.x, rect.y)
        (offset_x, offset_y) = coordinate
        
        with cairo_state(cr):
            cr.translate(-offset_x, -offset_y)
            cr.rectangle(offset_x, offset_y, rect.width, rect.height)
            cr.clip()
            
            (shadow_x, shadow_y) = get_window_shadow_size(self.get_toplevel())
            skin_config.render_background(cr, self, rect.x + shadow_x, rect.y + shadow_y)
        
        # Draw mask.
        cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_select_bg_color.get_color(), 0.93)))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
Exemplo n.º 14
0
class Titlebar(EventBox):
    '''Title bar.'''    
    
    def __init__(self, 
                 button_mask=["theme", "menu", "max", "min", "close"],
                 icon_dpixbuf=None,
                 app_name=None,
                 title=None,
                 add_separator=False,
                 height=26
                 ):
        '''Init titlebar.'''
        # 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)
        
        # Add icon.
        if icon_dpixbuf != None:
            self.icon_image_box = ImageBox(icon_dpixbuf)
            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:
            self.app_name_box = Label(app_name, enable_gaussian=True)
            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:
            self.title_box = Label(title, enable_gaussian=True, text_x_align=pango.ALIGN_CENTER)
            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.h_layout_box.pack_start(self.button_align, 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, _("Minimum")).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()
        
    def expose_titlebar_separator(self, widget, event):
        '''Expose nav separator.'''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
    
        # Draw separator.
        cr.set_source_rgba(1, 1, 1, 0.5)
        draw_line(cr, rect.x + 1, rect.y + 2, rect.x + rect.width - 1, rect.y + 1)
    
        return True
    
    def change_title(self, title):
        '''Change title.'''
        self.title_box.change_text(title)
Exemplo n.º 15
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()
Exemplo n.º 16
0
    def __init__(
        self,
        images,
        pointer_offset_x=-130,
        pointer_offset_y=-20,
        pointer_padding=20,
        hover_animation_time=500,
        auto_animation_time=2000,
        auto_slide_timeout=5000,
        horizontal_align=ALIGN_START,
        vertical_align=ALIGN_START,
        height_offset=0,
        hover_switch=True,
        auto_switch=True,
        navigate_switch=False,
        active_dpixbuf=ui_theme.get_pixbuf("slide_switcher/active.png"),
        inactive_dpixbuf=ui_theme.get_pixbuf("slide_switcher/inactive.png"),
    ):
        """
        Initialize SlideSwitcher class.
        
        @param images: The image list of sliders.
        @param pointer_offset_x: The offset x of pointer relative to right edge of slider image, default is -130 pixels.
        @param pointer_offset_y: The offset y of pointer relative to bottom edge of slider image, default is -20 pixels.
        @param pointer_padding: The padding between pointers, default is 20 pixels.
        @param hover_animation_time: The animation time of hover operation, default is 500 milliseconds. 
        @param auto_animation_time: The animation time of automatic play, default is 2000 milliseconds. 
        @param auto_slide_timeout: The slide timeout of automatic play, default is 2000 milliseconds. 
        @param horizontal_align: The horizontal alignment, default is ALIGN_START.
        @param vertical_align: The vertical alignment, default is ALIGN_START.
        @param height_offset: The height offset, default is 0 pixels.
        @param hover_switch: Set as True to make slider switch when hover operation active.
        @param auto_switch: Set as True to make slider play automatically.
        @param navigate_switch: Set as True to make slider switch navigate.
        @param active_dpixbuf: The dynamic pixbuf of active status.
        @param inactive_dpixbuf: The dynamic pixbuf of inactive status.
        """
        EventBox.__init__(self)
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.slide_images = images
        self.image_number = len(self.slide_images)
        self.active_index = 0
        self.motion_index = None
        self.target_index = None
        self.active_alpha = 1.0
        self.target_alpha = 0.0
        self.in_animiation = False
        self.hover_animation_time = hover_animation_time  # animiation time of hover, in milliseconds
        self.auto_animation_time = auto_animation_time  # animiation time automatically, in milliseconds
        self.auto_slide_timeout = auto_slide_timeout  # slide timeout, in milliseconds
        self.auto_slide_timeout_id = None
        self.horizontal_align = horizontal_align
        self.vertical_align = vertical_align
        self.hover_switch = hover_switch
        self.auto_switch = auto_switch
        self.navigate_switch = navigate_switch
        self.in_right_nav = False
        self.in_left_nav = False
        self.active_dpixbuf = active_dpixbuf
        self.inactive_dpixbuf = inactive_dpixbuf
        size_pixbuf = self.slide_images[0]

        self.pointer_offset_x = pointer_offset_x
        self.pointer_offset_y = pointer_offset_y
        self.pointer_radious = self.active_dpixbuf.get_pixbuf().get_width() / 2
        self.pointer_padding = pointer_padding
        self.set_size_request(-1, size_pixbuf.get_height() + height_offset)

        self.connect("expose-event", self.expose_slide_switcher)
        self.connect("motion-notify-event", self.motion_notify_slide_switcher)
        self.connect("leave-notify-event", self.leave_notify_slide_switcher)
        self.connect("enter-notify-event", self.enter_notify_slide_switcher)
        self.connect("button-press-event", lambda w, e: self.handle_animation(w, e, True))

        self.start_auto_slide()
Exemplo n.º 17
0
    def __init__(self,
                 images,
                 pointer_offset_x=-130,
                 pointer_offset_y=-20,
                 pointer_padding=20,
                 hover_animation_time=500,
                 auto_animation_time=2000,
                 auto_slide_timeout=5000,
                 horizontal_align=ALIGN_START,
                 vertical_align=ALIGN_START,
                 height_offset=0,
                 hover_switch=True,
                 auto_switch=True,
                 navigate_switch=False,
                 active_dpixbuf=ui_theme.get_pixbuf("slide_switcher/active.png"),
                 inactive_dpixbuf=ui_theme.get_pixbuf("slide_switcher/inactive.png"),
                 ):
        '''
        Initialize SlideSwitcher class.

        @param images: The image list of sliders.
        @param pointer_offset_x: The offset x of pointer relative to right edge of slider image, default is -130 pixels.
        @param pointer_offset_y: The offset y of pointer relative to bottom edge of slider image, default is -20 pixels.
        @param pointer_padding: The padding between pointers, default is 20 pixels.
        @param hover_animation_time: The animation time of hover operation, default is 500 milliseconds.
        @param auto_animation_time: The animation time of automatic play, default is 2000 milliseconds.
        @param auto_slide_timeout: The slide timeout of automatic play, default is 2000 milliseconds.
        @param horizontal_align: The horizontal alignment, default is ALIGN_START.
        @param vertical_align: The vertical alignment, default is ALIGN_START.
        @param height_offset: The height offset, default is 0 pixels.
        @param hover_switch: Set as True to make slider switch when hover operation active.
        @param auto_switch: Set as True to make slider play automatically.
        @param navigate_switch: Set as True to make slider switch navigate.
        @param active_dpixbuf: The dynamic pixbuf of active status.
        @param inactive_dpixbuf: The dynamic pixbuf of inactive status.
        '''
        EventBox.__init__(self)
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.slide_images = images
        self.image_number = len(self.slide_images)
        self.active_index = 0
        self.motion_index = None
        self.target_index = None
        self.active_alpha = 1.0
        self.target_alpha = 0.0
        self.in_animiation = False
        self.hover_animation_time = hover_animation_time # animiation time of hover, in milliseconds
        self.auto_animation_time = auto_animation_time # animiation time automatically, in milliseconds
        self.auto_slide_timeout = auto_slide_timeout # slide timeout, in milliseconds
        self.auto_slide_timeout_id = None
        self.horizontal_align = horizontal_align
        self.vertical_align = vertical_align
        self.hover_switch = hover_switch
        self.auto_switch = auto_switch
        self.navigate_switch = navigate_switch
        self.in_right_nav = False
        self.in_left_nav = False
        self.active_dpixbuf = active_dpixbuf
        self.inactive_dpixbuf = inactive_dpixbuf
        size_pixbuf = self.slide_images[0]

        self.pointer_offset_x = pointer_offset_x
        self.pointer_offset_y = pointer_offset_y
        self.pointer_radious = self.active_dpixbuf.get_pixbuf().get_width() / 2
        self.pointer_padding = pointer_padding
        self.set_size_request(-1, size_pixbuf.get_height() + height_offset)

        self.connect("expose-event", self.expose_slide_switcher)
        self.connect("motion-notify-event", self.motion_notify_slide_switcher)
        self.connect("leave-notify-event", self.leave_notify_slide_switcher)
        self.connect("enter-notify-event", self.enter_notify_slide_switcher)
        self.connect("button-press-event", lambda w, e: self.handle_animation(w, e, True))

        self.start_auto_slide()
Exemplo n.º 18
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, _("Minimum")).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()
Exemplo n.º 19
0
    def __init__(self, 
                 button_mask=["theme", "menu", "max", "min", "close"],
                 icon_dpixbuf=None,
                 app_name=None,
                 title=None,
                 add_separator=False,
                 height=26
                 ):
        '''Init titlebar.'''
        # 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)
        
        # Add icon.
        if icon_dpixbuf != None:
            self.icon_image_box = ImageBox(icon_dpixbuf)
            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:
            self.app_name_box = Label(app_name, enable_gaussian=True)
            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:
            self.title_box = Label(title, enable_gaussian=True, text_x_align=pango.ALIGN_CENTER)
            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.h_layout_box.pack_start(self.button_align, 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, _("Minimum")).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()