def __init__(self, slide_infos, 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 slide_infos: infos fetched from network api @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_infos = slide_infos self.image_number = len(self.slide_infos) self.slide_images = [] for i in xrange(self.image_number): self.slide_images.append(get_common_image_pixbuf('slide/default_cache.png')) 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() self.fetch_image_id = 0 FetchImageFromUpyun(self.slide_infos[self.fetch_image_id][2], lambda local_path: self.update_images(local_path, self.fetch_image_id)).start()
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, ): # 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, 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, 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 buttons. for mask in button_mask: setattr(self, titlebar_button_dict[mask][0], titlebar_button_dict[mask][1]()) button = getattr(self, titlebar_button_dict[mask][0]) self.button_box.pack_start(button, False, False) Tooltip.text(button, titlebar_button_dict[mask][2]).show_delay(button, 2000) # Show. self.show_all()
def __init__( self, slide_infos, 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 slide_infos: infos fetched from network api @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_infos = slide_infos self.image_number = len(self.slide_infos) self.slide_images = [] for i in xrange(self.image_number): self.slide_images.append( get_common_image_pixbuf('slide/default_cache.png')) 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() self.fetch_image_id = 0 FetchImageFromUpyun( self.slide_infos[self.fetch_image_id][2], lambda local_path: self. update_images(local_path, self.fetch_image_id)).start()
class Titlebar(EventBox): 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, ): # 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, 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, 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 buttons. for mask in button_mask: setattr(self, titlebar_button_dict[mask][0], titlebar_button_dict[mask][1]()) button = getattr(self, titlebar_button_dict[mask][0]) self.button_box.pack_start(button, False, False) Tooltip.text(button, titlebar_button_dict[mask][2]).show_delay(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_name(self, name): ''' Change the name of the application, which is displayed on the center of the title bar. @param name: New name string that want to set. ''' self.app_name_box.set_text(name) def change_title(self, title): ''' Change the title of the application, which is displayed on the center of the title bar. @param title: New title string that want to set. ''' self.title_box.set_text(title)
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, ): # 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, 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, 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 buttons. for mask in button_mask: setattr(self, titlebar_button_dict[mask][0], titlebar_button_dict[mask][1]()) button = getattr(self, titlebar_button_dict[mask][0]) self.button_box.pack_start(button, False, False) Tooltip.text(button, titlebar_button_dict[mask][2]).show_delay( button, 2000) # Show. self.show_all()
class Titlebar(EventBox): 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, ): # 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, 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, 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 buttons. for mask in button_mask: setattr(self, titlebar_button_dict[mask][0], titlebar_button_dict[mask][1]()) button = getattr(self, titlebar_button_dict[mask][0]) self.button_box.pack_start(button, False, False) Tooltip.text(button, titlebar_button_dict[mask][2]).show_delay( 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_name(self, name): ''' Change the name of the application, which is displayed on the center of the title bar. @param name: New name string that want to set. ''' self.app_name_box.set_text(name) def change_title(self, title): ''' Change the title of the application, which is displayed on the center of the title bar. @param title: New title string that want to set. ''' self.title_box.set_text(title)
def __init__( self, items, add_separator=False, font_size=DEFAULT_FONT_SIZE, padding_x=10, padding_y=10, vertical=True, item_normal_pixbuf=None, 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_normal_pixbuf = item_normal_pixbuf 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.top_logo_box = TopLogoBox() self.nav_item_box = gtk.HBox() self.nav_item_box.pack_start(self.top_logo_box, False, False) 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_normal_pixbuf, 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()
def __init__( self, items, add_separator=False, font_size=DEFAULT_FONT_SIZE, padding_x=10, padding_y=10, vertical=True, item_normal_pixbuf=None, 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_normal_pixbuf = item_normal_pixbuf 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.top_logo_box = TopLogoBox() self.nav_item_box = gtk.HBox() self.nav_item_box.pack_start(self.top_logo_box, False, False) 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_normal_pixbuf, 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()