class FileIconView(ScrolledWindow): def __init__(self, items=None): ScrolledWindow.__init__(self, 0, 0) self.file_iconview = IconView() self.file_iconview.draw_mask = self.draw_mask if items != None: self.file_iconview.add_items(items) self.file_scrolledwindow = ScrolledWindow() self.file_scrolledwindow.add_child(self.file_iconview) self.add_child(self.file_scrolledwindow) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def add_items(self, items, clear=False): self.file_iconview.clear() self.file_iconview.add_items(items)
def __init__(self, right_space=2, top_bottom_space=3): ''' Initialize DroplistScrolledWindow class. @param right_space: the space between right border and the vertical scroolbar. @param top_bottom_space: the space between top border and the vertical scroolbar. ''' ScrolledWindow.__init__(self, right_space, top_bottom_space)
def __init__(self, items=None): ScrolledWindow.__init__(self, 0, 0) self.file_iconview = IconView() self.file_iconview.draw_mask = self.draw_mask if items != None: self.file_iconview.add_items(items) self.file_scrolledwindow = ScrolledWindow() self.file_scrolledwindow.add_child(self.file_iconview) self.add_child(self.file_scrolledwindow)
def _inspect_web_view_cb (self, inspector, web_view): """Called when the 'inspect' menu item is activated""" from scrolled_window import ScrolledWindow scrolled_window = ScrolledWindow() webview = webkit.WebView() scrolled_window.add(webview) scrolled_window.show_all() self.add(scrolled_window) return webview
def __init__(self, right_space=2, top_bottom_space=3): ''' Initialize TalkView class. ''' # Init. ScrolledWindow.__init__(self, right_space, top_bottom_space) self.draw_area = gtk.DrawingArea() self.draw_align = gtk.Alignment() self.draw_align.set(0.5, 0.5, 1, 1) self.draw_align.add(self.draw_area) self.add_child(self.draw_align)
class PopupWindow(Window): '''PopupWindow.''' def __init__(self, parent_widget=None, widget=None, x=None, y=None): '''Init PopupWindow.''' Window.__init__(self) # Init Window. self.set_position(gtk.WIN_POS_MOUSE) self.set_modal(True) self.set_size_request(200,300) self.main_box = gtk.VBox() self.titlebar = Titlebar(["close"]) self.titlebar.close_button.connect("clicked", lambda w: self.destroy()) self.scrolled_align = gtk.Alignment() self.scrolled_align.set(0.0, 0.0, 1.0, 1.0) self.scrolled_window = ScrolledWindow(gtk.POLICY_NEVER) self.scrolled_align.add(self.scrolled_window) self.scrolled_align.set_padding(10, 10, 10, 10) if widget: self.scrolled_window.add_child(widget) else: self.buffer = gtk.TextBuffer() self.text_view = gtk.TextView(self.buffer) self.buffer.set_text("Linux Deepin") self.scrolled_window.add_child(self.text_view) if x and y: self.move(x, y) self.titlebar.drag_box.connect('button-press-event', lambda w, e: move_window(w, e, self)) if parent_widget: self.connect("show", lambda w:self.show_window(w, parent_widget)) self.main_box = gtk.VBox() self.main_box.pack_start(self.titlebar, False, False) self.main_box.pack_start(self.scrolled_align, True, True) self.window_frame.add(self.main_box) self.show_all() def show_window(self, widget, parent_widget): '''Show window''' parent_rect = parent_widget.get_toplevel().get_allocation() widget.move(parent_rect.x + parent_rect.width/2, parent_rect.y + parent_rect.height/2)
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)
class ColorSelectDialog(DialogBox): ''' ColorSelectionDialog widget. @undocumented: click_confirm_button @undocumented: click_cancel_button @undocumented: click_rgb_spin @undocumented: press_return_color_entry @undocumented: expose_display_button ''' DEFAULT_COLOR_LIST = [ "#000000", "#808080", "#E20417", "#F29300", "#FFEC00", "#95BE0D", "#008F35", "#00968F", "#FFFFFF", "#C0C0C0", "#E2004E", "#E2007A", "#920A7E", "#162883", "#0069B2", "#009DE0" ] def __init__( self, init_color="#FFFFFF", confirm_callback=None, cancel_callback=None, cancel_first=True, ): ''' Initialize ColorSelectDialog class. @param init_color: Initialize color of dialog. @param confirm_callback: Callback when user click OK, this callback accept one argument, color string. @param cancel_callback: Callback when user click cancel, this callback don't accept any argument. @param cancel_first: Set as True if to make cancel button before confirm button, default is True. ''' DialogBox.__init__(self, _("Select color"), mask_type=DIALOG_MASK_SINGLE_PAGE) self.confirm_callback = confirm_callback self.cancel_callback = cancel_callback self.cancel_first = cancel_first self.color_box = gtk.HBox() self.color_align = gtk.Alignment() self.color_align.set(0.5, 0.5, 0.0, 0.0) self.color_align.set_padding(10, 0, 8, 8) self.color_align.add(self.color_box) self.color_hsv = HSV() self.color_string = init_color (self.color_r, self.color_g, self.color_b) = self.color_hsv.get_rgb_color() self.color_hsv.get_hsv_widget().connect( "button-release-event", lambda w, e: self.update_color_info( self.color_hsv.get_color_string())) self.color_box.pack_start(self.color_hsv, False, False) self.color_right_box = gtk.VBox() self.color_right_align = gtk.Alignment() self.color_right_align.set(0.5, 0.5, 0.0, 0.0) self.color_right_align.set_padding(8, 0, 0, 0) self.color_right_align.add(self.color_right_box) self.color_box.pack_start(self.color_right_align) self.color_info_box = gtk.HBox() self.color_right_box.pack_start(self.color_info_box, False, False) self.color_display_box = gtk.VBox() self.color_display_button = gtk.Button() self.color_display_button.connect("expose-event", self.expose_display_button) self.color_display_button.set_size_request(70, 58) self.color_display_align = gtk.Alignment() self.color_display_align.set(0.5, 0.5, 1.0, 1.0) self.color_display_align.set_padding(5, 5, 5, 5) self.color_display_align.add(self.color_display_button) self.color_display_box.pack_start(self.color_display_align, False, False, 5) self.color_hex_box = gtk.HBox() self.color_hex_label = Label(_("Color value")) self.color_hex_box.pack_start(self.color_hex_label, False, False, 5) self.color_hex_entry = InputEntry(self.color_string) self.color_hex_entry.entry.check_text = is_hex_color self.color_hex_entry.entry.connect("press-return", self.press_return_color_entry) self.color_hex_entry.set_size(70, 24) self.color_hex_box.pack_start(self.color_hex_entry, False, False, 5) self.color_display_box.pack_start(self.color_hex_box, False, False, 5) self.color_info_box.pack_start(self.color_display_box, False, False, 5) self.color_rgb_box = gtk.VBox() self.color_r_box = gtk.HBox() self.color_r_label = Label(_("Red: ")) self.color_r_spin = SpinBox(self.color_r, 0, 255, 1, check_text=self.is_color_value) self.color_r_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_r_box.pack_start(self.color_r_label, False, False) self.color_r_box.pack_start(self.color_r_spin, False, False) self.color_g_box = gtk.HBox() self.color_g_label = Label(_("Green: ")) self.color_g_spin = SpinBox(self.color_g, 0, 255, 1, check_text=self.is_color_value) self.color_g_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_g_box.pack_start(self.color_g_label, False, False) self.color_g_box.pack_start(self.color_g_spin, False, False) self.color_b_box = gtk.HBox() self.color_b_label = Label(_("Blue: ")) self.color_b_spin = SpinBox(self.color_b, 0, 255, 1, check_text=self.is_color_value) self.color_b_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_b_box.pack_start(self.color_b_label, False, False) self.color_b_box.pack_start(self.color_b_spin, False, False) self.color_rgb_box.pack_start(self.color_r_box, False, False, 8) self.color_rgb_box.pack_start(self.color_g_box, False, False, 8) self.color_rgb_box.pack_start(self.color_b_box, False, False, 8) self.color_info_box.pack_start(self.color_rgb_box, False, False, 5) self.color_select_view = IconView() self.color_select_view.set_size_request(250, 60) self.color_select_view.connect( "button-press-item", lambda view, item, x, y: self.update_color_info(item.color, False)) self.color_select_view.draw_mask = self.get_mask_func( self.color_select_view) self.color_select_scrolled_window = ScrolledWindow() for color in self.DEFAULT_COLOR_LIST: self.color_select_view.add_items([ColorItem(color)]) self.color_select_align = gtk.Alignment() self.color_select_align.set(0.5, 0.5, 1.0, 1.0) self.color_select_align.set_padding(10, 5, 6, 5) self.color_select_scrolled_window.add_child(self.color_select_view) self.color_select_scrolled_window.set_size_request(-1, 60) self.color_select_align.add(self.color_select_scrolled_window) self.color_right_box.pack_start(self.color_select_align, True, True) self.confirm_button = Button(_("OK")) self.cancel_button = Button(_("Cancel")) self.confirm_button.connect("clicked", lambda w: self.click_confirm_button()) self.cancel_button.connect("clicked", lambda w: self.click_cancel_button()) if self.cancel_first: self.right_button_box.set_buttons( [self.cancel_button, self.confirm_button]) else: self.right_button_box.set_buttons( [self.confirm_button, self.cancel_button]) self.body_box.pack_start(self.color_align, True, True) self.update_color_info(self.color_string) def is_color_value(self, string): return len(string) == 0 or (is_int(string) and 0 <= int(string) <= 255) def click_confirm_button(self): ''' Wrap callback when user click ok button. ''' if self.confirm_callback != None: self.confirm_callback(self.color_hex_entry.get_text()) self.destroy() def click_cancel_button(self): ''' Wrap callback when user click cancel button. ''' if self.cancel_callback != None: self.cancel_callback() self.destroy() def click_rgb_spin(self): ''' Callback when user click RGB spin. ''' self.update_color_info( color_rgb_to_hex( (self.color_r_spin.get_value(), self.color_g_spin.get_value(), self.color_b_spin.get_value()))) def press_return_color_entry(self, entry): ''' Callback when user press `return` key on entry. @param entry: Color input entry. ''' self.update_color_info(entry.get_text()) entry.select_all() def expose_display_button(self, widget, event): ''' Callback for `expose-event` signal. @param widget: Gtk.Widget instance. @param event: Expose event. @return: Always return True ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(*color_hex_to_cairo(self.color_string)) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() # Propagate expose. propagate_expose(widget, event) return True def update_color_info(self, color_string, clear_highlight=True): ''' Update color information. @param color_string: Hex color string. @param clear_highlight: Whether clear color select view's highlight status, default is True. ''' self.color_string = color_string (self.color_r, self.color_g, self.color_b) = color_hex_to_rgb(self.color_string) self.color_r_spin.update(self.color_r) self.color_g_spin.update(self.color_g) self.color_b_spin.update(self.color_b) self.color_hex_entry.set_text(self.color_string) if not color_string.startswith("#"): color_string = "#" + color_string self.color_hsv.set_current_color(gtk.gdk.color_parse(color_string)) if clear_highlight: self.color_select_view.clear_highlight() self.color_rgb_box.queue_draw() self.color_display_button.queue_draw()
def __init__(self, crumb, arrow_right=ui_theme.get_pixbuf("treeview/arrow_right.png"), arrow_down=ui_theme.get_pixbuf("treeview/arrow_down.png"), show_others=False, show_entry=False, show_left_right_box=True ): ''' Initialize Bread class. @param crumb: Crumb instance or a list of crumb instances @param arrow_right: Dynamic pixbuf for right arrow, default is \"treeview/arrow_right.png\" from ui theme. @param arrow_down: Dynamic pixbuf for down arrow, default is \"treeview/arrow_down.png\" from ui theme. @param show_others: If True, crumbs will not be destroyed, otherwise all crumbs on the right side will be destroyed. @param show_entry: If True, an entry will pop up when click space area in Bread. ''' # Init. super(Bread, self).__init__(spacing = 0) self.arrow_right = arrow_right self.arrow_down = arrow_down self.item_list = list() self.show_others = show_others self.show_entry = show_entry self.crumb = self.create_crumb(crumb) self.button_width = ARROW_BUTTON_WIDTH # for left & right buttons self.in_event_box = False # Init left button and right button. self.show_left_right_box = show_left_right_box left_box = gtk.HBox(spacing = 0) right_box = gtk.HBox(spacing = 0) # FIXME: left && right box static setting size # it is better to consider whether or not shown left && right box # at runtime if self.show_left_right_box: left_box.set_size_request(self.button_width, -1) right_box.set_size_request(self.button_width, -1) self.left_btn = Button("<") self.right_btn = Button(">") self.left_btn.set_no_show_all(True) self.right_btn.set_no_show_all(True) self.right_btn.connect("clicked", self.move_right) self.left_btn.connect("clicked", self.move_left) self.left_btn.set_size_request(self.button_width, -1) self.right_btn.set_size_request(self.button_width, -1) left_box.pack_start(self.left_btn, False, False) right_box.pack_start(self.right_btn, False, False) # Init Hbox self.hbox = gtk.HBox(False, 0) self.hbox.show() self.eventbox = gtk.EventBox() self.eventbox.set_visible_window(False) if self.show_entry: self.eventbox.connect("enter-notify-event", self.enter_notify) self.eventbox.connect("leave-notify-event", self.leave_notify) self.eventbox.connect("button-press-event", self.event_box_press) self.hbox.pack_end(self.eventbox, True, True) self.scroll_win = ScrolledWindow() self.pack_start(left_box, False, True) self.pack_start(self.hbox, True, True) # Add Bread Items self.adj = self.scroll_win.get_hadjustment() self.add(self.crumb)
def __init__(self, confirm_callback=None, cancel_callback=None): ''' Initialize ColorSelectDialog class. @param confirm_callback: Callback when user click OK, this callback accept one argument, color string. @param cancel_callback: Callback when user click cancel, this callback don't accept any argument. ''' DialogBox.__init__(self, _("Select color"), mask_type=DIALOG_MASK_SINGLE_PAGE) self.confirm_callback = confirm_callback self.cancel_callback = cancel_callback self.color_box = gtk.HBox() self.color_align = gtk.Alignment() self.color_align.set(0.5, 0.5, 0.0, 0.0) self.color_align.set_padding(10, 0, 8, 8) self.color_align.add(self.color_box) self.color_hsv = HSV() self.color_string = self.color_hsv.get_color_string() (self.color_r, self.color_g, self.color_b) = self.color_hsv.get_rgb_color() self.color_hsv.get_hsv_widget().connect( "button-release-event", lambda w, e: self.update_color_info(self.color_hsv.get_color_string())) self.color_box.pack_start(self.color_hsv, False, False) self.color_right_box = gtk.VBox() self.color_right_align = gtk.Alignment() self.color_right_align.set(0.5, 0.5, 0.0, 0.0) self.color_right_align.set_padding(8, 0, 0, 0) self.color_right_align.add(self.color_right_box) self.color_box.pack_start(self.color_right_align) self.color_info_box = gtk.HBox() self.color_right_box.pack_start(self.color_info_box, False, False) self.color_display_box = gtk.VBox() self.color_display_button = gtk.Button() self.color_display_button.connect("expose-event", self.expose_display_button) self.color_display_button.set_size_request(70, 49) self.color_display_align = gtk.Alignment() self.color_display_align.set(0.5, 0.5, 1.0, 1.0) self.color_display_align.set_padding(5, 5, 5, 5) self.color_display_align.add(self.color_display_button) self.color_display_box.pack_start(self.color_display_align, False, False, 5) self.color_hex_box = gtk.HBox() self.color_hex_label = Label(_("Color value")) self.color_hex_box.pack_start(self.color_hex_label, False, False, 5) self.color_hex_entry = TextEntry(self.color_string) self.color_hex_entry.entry.check_text = is_hex_color self.color_hex_entry.entry.connect("press-return", self.press_return_color_entry) self.color_hex_entry.set_size(70, 24) self.color_hex_box.pack_start(self.color_hex_entry, False, False, 5) self.color_display_box.pack_start(self.color_hex_box, False, False, 5) self.color_info_box.pack_start(self.color_display_box, False, False, 5) self.color_rgb_box = gtk.VBox() self.color_r_box = gtk.HBox() self.color_r_label = Label(_("Red: ")) self.color_r_spin = SpinBox(self.color_r, 0, 255, 1) self.color_r_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_r_box.pack_start(self.color_r_label, False, False) self.color_r_box.pack_start(self.color_r_spin, False, False) self.color_g_box = gtk.HBox() self.color_g_label = Label(_("Green: ")) self.color_g_spin = SpinBox(self.color_g, 0, 255, 1) self.color_g_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_g_box.pack_start(self.color_g_label, False, False) self.color_g_box.pack_start(self.color_g_spin, False, False) self.color_b_box = gtk.HBox() self.color_b_label = Label(_("Blue: ")) self.color_b_spin = SpinBox(self.color_b, 0, 255, 1) self.color_b_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_b_box.pack_start(self.color_b_label, False, False) self.color_b_box.pack_start(self.color_b_spin, False, False) self.color_rgb_box.pack_start(self.color_r_box, False, False, 8) self.color_rgb_box.pack_start(self.color_g_box, False, False, 8) self.color_rgb_box.pack_start(self.color_b_box, False, False, 8) self.color_info_box.pack_start(self.color_rgb_box, False, False, 5) self.color_select_view = IconView() self.color_select_view.set_size_request(250, 60) self.color_select_view.connect("button-press-item", lambda view, item, x, y: self.update_color_info(item.color, False)) self.color_select_view.draw_mask = self.get_mask_func(self.color_select_view) self.color_select_scrolled_window = ScrolledWindow() for color in self.DEFAULT_COLOR_LIST: self.color_select_view.add_items([ColorItem(color)]) self.color_select_align = gtk.Alignment() self.color_select_align.set(0.5, 0.5, 1.0, 1.0) self.color_select_align.set_padding(10, 5, 6, 5) self.color_select_scrolled_window.add_child(self.color_select_view) self.color_select_scrolled_window.set_size_request(-1, 60) self.color_select_align.add(self.color_select_scrolled_window) self.color_right_box.pack_start(self.color_select_align, True, True) self.confirm_button = Button(_("OK")) self.cancel_button = Button(_("Cancel")) self.confirm_button.connect("clicked", lambda w: self.click_confirm_button()) self.cancel_button.connect("clicked", lambda w: self.click_cancel_button()) self.right_button_box.set_buttons([self.confirm_button, self.cancel_button]) self.body_box.pack_start(self.color_align, True, True) self.update_color_info(self.color_string)
class ColorSelectDialog(DialogBox): ''' ColorSelectionDialog widget. @undocumented: click_confirm_button @undocumented: click_cancel_button @undocumented: click_rgb_spin @undocumented: press_return_color_entry @undocumented: expose_display_button ''' DEFAULT_COLOR_LIST = ["#000000", "#808080", "#E20417", "#F29300", "#FFEC00", "#95BE0D", "#008F35", "#00968F", "#FFFFFF", "#C0C0C0", "#E2004E", "#E2007A", "#920A7E", "#162883", "#0069B2", "#009DE0"] def __init__(self, confirm_callback=None, cancel_callback=None): ''' Initialize ColorSelectDialog class. @param confirm_callback: Callback when user click OK, this callback accept one argument, color string. @param cancel_callback: Callback when user click cancel, this callback don't accept any argument. ''' DialogBox.__init__(self, _("Select color"), mask_type=DIALOG_MASK_SINGLE_PAGE) self.confirm_callback = confirm_callback self.cancel_callback = cancel_callback self.color_box = gtk.HBox() self.color_align = gtk.Alignment() self.color_align.set(0.5, 0.5, 0.0, 0.0) self.color_align.set_padding(10, 0, 8, 8) self.color_align.add(self.color_box) self.color_hsv = HSV() self.color_string = self.color_hsv.get_color_string() (self.color_r, self.color_g, self.color_b) = self.color_hsv.get_rgb_color() self.color_hsv.get_hsv_widget().connect( "button-release-event", lambda w, e: self.update_color_info(self.color_hsv.get_color_string())) self.color_box.pack_start(self.color_hsv, False, False) self.color_right_box = gtk.VBox() self.color_right_align = gtk.Alignment() self.color_right_align.set(0.5, 0.5, 0.0, 0.0) self.color_right_align.set_padding(8, 0, 0, 0) self.color_right_align.add(self.color_right_box) self.color_box.pack_start(self.color_right_align) self.color_info_box = gtk.HBox() self.color_right_box.pack_start(self.color_info_box, False, False) self.color_display_box = gtk.VBox() self.color_display_button = gtk.Button() self.color_display_button.connect("expose-event", self.expose_display_button) self.color_display_button.set_size_request(70, 49) self.color_display_align = gtk.Alignment() self.color_display_align.set(0.5, 0.5, 1.0, 1.0) self.color_display_align.set_padding(5, 5, 5, 5) self.color_display_align.add(self.color_display_button) self.color_display_box.pack_start(self.color_display_align, False, False, 5) self.color_hex_box = gtk.HBox() self.color_hex_label = Label(_("Color value")) self.color_hex_box.pack_start(self.color_hex_label, False, False, 5) self.color_hex_entry = TextEntry(self.color_string) self.color_hex_entry.entry.check_text = is_hex_color self.color_hex_entry.entry.connect("press-return", self.press_return_color_entry) self.color_hex_entry.set_size(70, 24) self.color_hex_box.pack_start(self.color_hex_entry, False, False, 5) self.color_display_box.pack_start(self.color_hex_box, False, False, 5) self.color_info_box.pack_start(self.color_display_box, False, False, 5) self.color_rgb_box = gtk.VBox() self.color_r_box = gtk.HBox() self.color_r_label = Label(_("Red: ")) self.color_r_spin = SpinBox(self.color_r, 0, 255, 1) self.color_r_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_r_box.pack_start(self.color_r_label, False, False) self.color_r_box.pack_start(self.color_r_spin, False, False) self.color_g_box = gtk.HBox() self.color_g_label = Label(_("Green: ")) self.color_g_spin = SpinBox(self.color_g, 0, 255, 1) self.color_g_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_g_box.pack_start(self.color_g_label, False, False) self.color_g_box.pack_start(self.color_g_spin, False, False) self.color_b_box = gtk.HBox() self.color_b_label = Label(_("Blue: ")) self.color_b_spin = SpinBox(self.color_b, 0, 255, 1) self.color_b_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_b_box.pack_start(self.color_b_label, False, False) self.color_b_box.pack_start(self.color_b_spin, False, False) self.color_rgb_box.pack_start(self.color_r_box, False, False, 8) self.color_rgb_box.pack_start(self.color_g_box, False, False, 8) self.color_rgb_box.pack_start(self.color_b_box, False, False, 8) self.color_info_box.pack_start(self.color_rgb_box, False, False, 5) self.color_select_view = IconView() self.color_select_view.set_size_request(250, 60) self.color_select_view.connect("button-press-item", lambda view, item, x, y: self.update_color_info(item.color, False)) self.color_select_view.draw_mask = self.get_mask_func(self.color_select_view) self.color_select_scrolled_window = ScrolledWindow() for color in self.DEFAULT_COLOR_LIST: self.color_select_view.add_items([ColorItem(color)]) self.color_select_align = gtk.Alignment() self.color_select_align.set(0.5, 0.5, 1.0, 1.0) self.color_select_align.set_padding(10, 5, 6, 5) self.color_select_scrolled_window.add_child(self.color_select_view) self.color_select_scrolled_window.set_size_request(-1, 60) self.color_select_align.add(self.color_select_scrolled_window) self.color_right_box.pack_start(self.color_select_align, True, True) self.confirm_button = Button(_("OK")) self.cancel_button = Button(_("Cancel")) self.confirm_button.connect("clicked", lambda w: self.click_confirm_button()) self.cancel_button.connect("clicked", lambda w: self.click_cancel_button()) self.right_button_box.set_buttons([self.confirm_button, self.cancel_button]) self.body_box.pack_start(self.color_align, True, True) self.update_color_info(self.color_string) def click_confirm_button(self): ''' Wrap callback when user click ok button. ''' if self.confirm_callback != None: self.confirm_callback(self.color_hex_entry.get_text()) self.destroy() def click_cancel_button(self): ''' Wrap callback when user click cancel button. ''' if self.cancel_callback != None: self.cancel_callback() self.destroy() def click_rgb_spin(self): ''' Callback when user click RGB spin. ''' self.update_color_info(color_rgb_to_hex((self.color_r_spin.get_value(), self.color_g_spin.get_value(), self.color_b_spin.get_value()))) def press_return_color_entry(self, entry): ''' Callback when user press `return` key on entry. @param entry: Color input entry. ''' self.update_color_info(entry.get_text()) entry.select_all() def expose_display_button(self, widget, event): ''' Callback for `expose-event` signal. @param widget: Gtk.Widget instance. @param event: Expose event. @return: Always return True ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(*color_hex_to_cairo(self.color_string)) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() # Propagate expose. propagate_expose(widget, event) return True def update_color_info(self, color_string, clear_highlight=True): ''' Update color information. @param color_string: Hex color string. @param clear_highlight: Whether clear color select view's highlight status, default is True. ''' self.color_string = color_string (self.color_r, self.color_g, self.color_b) = color_hex_to_rgb(self.color_string) self.color_r_spin.update(self.color_r) self.color_g_spin.update(self.color_g) self.color_b_spin.update(self.color_b) self.color_hex_entry.set_text(self.color_string) if not color_string.startswith("#"): color_string = "#" + color_string self.color_hsv.set_current_color(gtk.gdk.color_parse(color_string)) if clear_highlight: self.color_select_view.clear_highlight() self.color_display_button.queue_draw()
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()
def __init__( self, init_color="#FFFFFF", confirm_callback=None, cancel_callback=None, cancel_first=True, ): ''' Initialize ColorSelectDialog class. @param init_color: Initialize color of dialog. @param confirm_callback: Callback when user click OK, this callback accept one argument, color string. @param cancel_callback: Callback when user click cancel, this callback don't accept any argument. @param cancel_first: Set as True if to make cancel button before confirm button, default is True. ''' DialogBox.__init__(self, _("Select color"), mask_type=DIALOG_MASK_SINGLE_PAGE) self.confirm_callback = confirm_callback self.cancel_callback = cancel_callback self.cancel_first = cancel_first self.color_box = gtk.HBox() self.color_align = gtk.Alignment() self.color_align.set(0.5, 0.5, 0.0, 0.0) self.color_align.set_padding(10, 0, 8, 8) self.color_align.add(self.color_box) self.color_hsv = HSV() self.color_string = init_color (self.color_r, self.color_g, self.color_b) = self.color_hsv.get_rgb_color() self.color_hsv.get_hsv_widget().connect( "button-release-event", lambda w, e: self.update_color_info( self.color_hsv.get_color_string())) self.color_box.pack_start(self.color_hsv, False, False) self.color_right_box = gtk.VBox() self.color_right_align = gtk.Alignment() self.color_right_align.set(0.5, 0.5, 0.0, 0.0) self.color_right_align.set_padding(8, 0, 0, 0) self.color_right_align.add(self.color_right_box) self.color_box.pack_start(self.color_right_align) self.color_info_box = gtk.HBox() self.color_right_box.pack_start(self.color_info_box, False, False) self.color_display_box = gtk.VBox() self.color_display_button = gtk.Button() self.color_display_button.connect("expose-event", self.expose_display_button) self.color_display_button.set_size_request(70, 58) self.color_display_align = gtk.Alignment() self.color_display_align.set(0.5, 0.5, 1.0, 1.0) self.color_display_align.set_padding(5, 5, 5, 5) self.color_display_align.add(self.color_display_button) self.color_display_box.pack_start(self.color_display_align, False, False, 5) self.color_hex_box = gtk.HBox() self.color_hex_label = Label(_("Color value")) self.color_hex_box.pack_start(self.color_hex_label, False, False, 5) self.color_hex_entry = InputEntry(self.color_string) self.color_hex_entry.entry.check_text = is_hex_color self.color_hex_entry.entry.connect("press-return", self.press_return_color_entry) self.color_hex_entry.set_size(70, 24) self.color_hex_box.pack_start(self.color_hex_entry, False, False, 5) self.color_display_box.pack_start(self.color_hex_box, False, False, 5) self.color_info_box.pack_start(self.color_display_box, False, False, 5) self.color_rgb_box = gtk.VBox() self.color_r_box = gtk.HBox() self.color_r_label = Label(_("Red: ")) self.color_r_spin = SpinBox(self.color_r, 0, 255, 1, check_text=self.is_color_value) self.color_r_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_r_box.pack_start(self.color_r_label, False, False) self.color_r_box.pack_start(self.color_r_spin, False, False) self.color_g_box = gtk.HBox() self.color_g_label = Label(_("Green: ")) self.color_g_spin = SpinBox(self.color_g, 0, 255, 1, check_text=self.is_color_value) self.color_g_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_g_box.pack_start(self.color_g_label, False, False) self.color_g_box.pack_start(self.color_g_spin, False, False) self.color_b_box = gtk.HBox() self.color_b_label = Label(_("Blue: ")) self.color_b_spin = SpinBox(self.color_b, 0, 255, 1, check_text=self.is_color_value) self.color_b_spin.connect("value-changed", lambda s, v: self.click_rgb_spin()) self.color_b_box.pack_start(self.color_b_label, False, False) self.color_b_box.pack_start(self.color_b_spin, False, False) self.color_rgb_box.pack_start(self.color_r_box, False, False, 8) self.color_rgb_box.pack_start(self.color_g_box, False, False, 8) self.color_rgb_box.pack_start(self.color_b_box, False, False, 8) self.color_info_box.pack_start(self.color_rgb_box, False, False, 5) self.color_select_view = IconView() self.color_select_view.set_size_request(250, 60) self.color_select_view.connect( "button-press-item", lambda view, item, x, y: self.update_color_info(item.color, False)) self.color_select_view.draw_mask = self.get_mask_func( self.color_select_view) self.color_select_scrolled_window = ScrolledWindow() for color in self.DEFAULT_COLOR_LIST: self.color_select_view.add_items([ColorItem(color)]) self.color_select_align = gtk.Alignment() self.color_select_align.set(0.5, 0.5, 1.0, 1.0) self.color_select_align.set_padding(10, 5, 6, 5) self.color_select_scrolled_window.add_child(self.color_select_view) self.color_select_scrolled_window.set_size_request(-1, 60) self.color_select_align.add(self.color_select_scrolled_window) self.color_right_box.pack_start(self.color_select_align, True, True) self.confirm_button = Button(_("OK")) self.cancel_button = Button(_("Cancel")) self.confirm_button.connect("clicked", lambda w: self.click_confirm_button()) self.cancel_button.connect("clicked", lambda w: self.click_cancel_button()) if self.cancel_first: self.right_button_box.set_buttons( [self.cancel_button, self.confirm_button]) else: self.right_button_box.set_buttons( [self.confirm_button, self.cancel_button]) self.body_box.pack_start(self.color_align, True, True) self.update_color_info(self.color_string)
class Bread(gtk.HBox): ''' Bread widget is a container which can hold crumbs widget. @undocumented: create_crumb @undocumented: enter_notify @undocumented: leave_notify @undocumented: event_box_press @undocumented: enter_cb @undocumented: redraw_bg @undocumented: click_cb @undocumented: move_right @undocumented: move_left ''' __gsignals__= { "entry-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)), "item_clicked" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,gobject.TYPE_STRING,)) } def __init__(self, crumb, arrow_right=ui_theme.get_pixbuf("treeview/arrow_right.png"), arrow_down=ui_theme.get_pixbuf("treeview/arrow_down.png"), show_others=False, show_entry=False, show_left_right_box=True ): ''' Initialize Bread class. @param crumb: Crumb instance or a list of crumb instances @param arrow_right: Dynamic pixbuf for right arrow, default is \"treeview/arrow_right.png\" from ui theme. @param arrow_down: Dynamic pixbuf for down arrow, default is \"treeview/arrow_down.png\" from ui theme. @param show_others: If True, crumbs will not be destroyed, otherwise all crumbs on the right side will be destroyed. @param show_entry: If True, an entry will pop up when click space area in Bread. ''' # Init. super(Bread, self).__init__(spacing = 0) self.arrow_right = arrow_right self.arrow_down = arrow_down self.item_list = list() self.show_others = show_others self.show_entry = show_entry self.crumb = self.create_crumb(crumb) self.button_width = ARROW_BUTTON_WIDTH # for left & right buttons self.in_event_box = False # Init left button and right button. self.show_left_right_box = show_left_right_box left_box = gtk.HBox(spacing = 0) right_box = gtk.HBox(spacing = 0) # FIXME: left && right box static setting size # it is better to consider whether or not shown left && right box # at runtime if self.show_left_right_box: left_box.set_size_request(self.button_width, -1) right_box.set_size_request(self.button_width, -1) self.left_btn = Button("<") self.right_btn = Button(">") self.left_btn.set_no_show_all(True) self.right_btn.set_no_show_all(True) self.right_btn.connect("clicked", self.move_right) self.left_btn.connect("clicked", self.move_left) self.left_btn.set_size_request(self.button_width, -1) self.right_btn.set_size_request(self.button_width, -1) left_box.pack_start(self.left_btn, False, False) right_box.pack_start(self.right_btn, False, False) # Init Hbox self.hbox = gtk.HBox(False, 0) self.hbox.show() self.eventbox = gtk.EventBox() self.eventbox.set_visible_window(False) if self.show_entry: self.eventbox.connect("enter-notify-event", self.enter_notify) self.eventbox.connect("leave-notify-event", self.leave_notify) self.eventbox.connect("button-press-event", self.event_box_press) self.hbox.pack_end(self.eventbox, True, True) self.scroll_win = ScrolledWindow() self.pack_start(left_box, False, True) self.pack_start(self.hbox, True, True) # Add Bread Items self.adj = self.scroll_win.get_hadjustment() self.add(self.crumb) def create_crumb(self, crumb): ''' Internal function to create a Crumb list for different types of inputs. @param crumb: Support inputs are: ["a label", Menu] [("a label",[(None, "menu label", None)])] Crumb instance [Crumb, Crumb] ''' if isinstance(crumb, Crumb): return [crumb,] elif isinstance(crumb[0], str): return [Crumb(crumb[0], crumb[1]),] elif isinstance(crumb[0], Crumb): return crumb else: return [Crumb(c[0], c[1]) for c in crumb] def enter_notify(self, widget, event): ''' Internal callback function to "enter-notify-event" signal. @param widget: gtk.EventBox. @param event: The pointer event of type gtk.gdk.Event. ''' self.in_event_box = True def leave_notify(self, widget, event): ''' Internal callback function to "leave-notify-event" signal. @param widget: Gtk.EventBox. @param event: The pointer event of type gtk.gdk.Event. ''' self.in_event_box = False def event_box_press(self, widget, event): ''' Internal callback function to "button-press-event" signal. @param widget: gtk.eventbox. @param event: event of type gtk.gdk.event. ''' obj = self.hbox.get_children() label = [] for o in obj[:-1]: label.append("/"+o.label) o.destroy() self.entry = gtk.Entry() self.entry.connect("activate", self.enter_cb) self.entry.set_text("".join(label)) self.entry.show() self.entry.select_region(0, len(self.entry.get_text())) self.eventbox.hide() self.hbox.pack_start(self.entry, True, True) def enter_cb(self, widget): ''' Internal callback function to "press-return" signal. @param widget: gtk.Entry widget instance. ''' label = widget.get_text() widget.destroy() self.eventbox.show() self.emit("entry-changed", label) def redraw_bg(self, widget, event): ''' Internal callback function to "expose-event" signal. @param widget: gtk.EventBox @param event: event of type gtk.gdk.event ''' cr = widget.window.cairo_create() rect = widget.allocation # Draw backgroud. with cairo_state(cr): cr.set_source_rgba(*alpha_color_hex_to_cairo(("#def5ff", 1))) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() return False def add(self, crumbs): ''' Add crumbs. Can accept Crumb instance or a list of Crumb instances @param crumbs: Supported inputs are: ["a label", Menu] [("a label",[(None, "menu label", None)])] Crumb instance [Crumb, Crumb] ''' crumbs = self.create_crumb(crumbs) for crumb in crumbs: crumb.show() crumb.arrow_right = self.arrow_right crumb.arrow_down = self.arrow_down crumb.index_id = len(self.item_list) crumb.connect("item_clicked", self.click_cb) self.hbox.pack_start(crumb, False, False) self.item_list.append(crumb.get_size_request()[0]) page_size = self.adj.page_size # Show right button if crumbs exceed scrolled window size. if sum(self.item_list) > page_size and not page_size == 1.0: self.right_btn.show() def change_node(self, index, crumbs): ''' Change any nodes start from specified index @param index: Start index @param crumbs: Crumb instance or Crumb list For instance, there exist a list contain [Crumb1, Crumb2], by using change_node(1, [Crumb3, Crumb4]), previous list will be change to [Crumb1, Crumb3, Crumb4]. In this way, application can operate crumbs ''' objects = self.hbox.get_children() for i in objects[index: -1]: i.destroy() self.item_list[index:] = [] self.add(crumbs) def remove_node_after_index(self, index): ''' Remove any nodes after given index. @param index: To specified remove after given index. ''' for i in self.hbox.get_children()[(index + 1): -1]: i.destroy() self.item_list[(index + 1):] = [] def click_cb(self, widget, index, label): ''' Internal callback function to "clicked" signal. @param widget: Crumb instance. @param index: The index value of clicked crumb. @param label: Label of the crumb. ''' if not self.show_others: for i in self.hbox.get_children()[(index + 1): -1]: i.destroy() self.item_list[(index + 1):] = [] self.emit("item_clicked", index, label) def move_right(self, widget): ''' Internal callback function to "clicked" signal. @param widget: Right button. ''' upper, page_size, value = self.adj.upper, self.adj.page_size, self.adj.value shift_value = 0 temp = 0 if upper > (page_size + value): self.left_btn.show() for i in xrange(len(self.item_list)+1): temp += self.item_list[i] if temp > (page_size + value): shift_value = temp - (page_size + value) #play animation ani = Animation(self.adj, lambda widget, v1: widget.set_value(v1),200,[value, value+shift_value]) ani.start() break if not upper > (page_size + self.adj.value + shift_value): self.right_btn.hide() def move_left(self, widget): ''' Internal callback function to "clicked" signal. @param widget: Left button. ''' upper, page_size, value = self.adj.upper, self.adj.page_size, self.adj.value shift_value = 0 temp = 0 if not value == 0: self.right_btn.show() for i in xrange(len(self.item_list)): temp += self.item_list[i] if temp >= value: shift_value = self.item_list[i] - (temp - value) break #play animation ani = Animation(self.adj, lambda widget, v1: widget.set_value(v1),200,[value, value-shift_value]) ani.start() if (self.adj.value - shift_value) == 0: self.left_btn.hide() def set_size(self, width, height): ''' Set Bread size. @param width: Width of Bread. @param height: Height of Bread. ''' self.scroll_win.set_size_request(width - 2 * self.button_width, height) self.hbox.set_size_request(-1, self.hbox.get_children()[0].height)
class Bread(gtk.HBox): ''' Bread widget is a container which can hold crumbs widget. @undocumented: create_crumb @undocumented: enter_notify @undocumented: leave_notify @undocumented: event_box_press @undocumented: enter_cb @undocumented: redraw_bg @undocumented: click_cb @undocumented: move_right @undocumented: move_left ''' __gsignals__ = { "entry-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )), "item_clicked": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ( gobject.TYPE_INT, gobject.TYPE_STRING, )) } def __init__(self, crumb, arrow_right=ui_theme.get_pixbuf("treeview/arrow_right.png"), arrow_down=ui_theme.get_pixbuf("treeview/arrow_down.png"), show_others=False, show_entry=False, show_left_right_box=True): ''' Initialize Bread class. @param crumb: Crumb instance or a list of crumb instances @param arrow_right: Dynamic pixbuf for right arrow, default is \"treeview/arrow_right.png\" from ui theme. @param arrow_down: Dynamic pixbuf for down arrow, default is \"treeview/arrow_down.png\" from ui theme. @param show_others: If True, crumbs will not be destroyed, otherwise all crumbs on the right side will be destroyed. @param show_entry: If True, an entry will pop up when click space area in Bread. ''' # Init. super(Bread, self).__init__(spacing=0) self.arrow_right = arrow_right self.arrow_down = arrow_down self.item_list = list() self.show_others = show_others self.show_entry = show_entry self.crumb = self.create_crumb(crumb) self.button_width = ARROW_BUTTON_WIDTH # for left & right buttons self.in_event_box = False # Init left button and right button. self.show_left_right_box = show_left_right_box left_box = gtk.HBox(spacing=0) right_box = gtk.HBox(spacing=0) # FIXME: left && right box static setting size # it is better to consider whether or not shown left && right box # at runtime if self.show_left_right_box: left_box.set_size_request(self.button_width, -1) right_box.set_size_request(self.button_width, -1) self.left_btn = Button("<") self.right_btn = Button(">") self.left_btn.set_no_show_all(True) self.right_btn.set_no_show_all(True) self.right_btn.connect("clicked", self.move_right) self.left_btn.connect("clicked", self.move_left) self.left_btn.set_size_request(self.button_width, -1) self.right_btn.set_size_request(self.button_width, -1) left_box.pack_start(self.left_btn, False, False) right_box.pack_start(self.right_btn, False, False) # Init Hbox self.hbox = gtk.HBox(False, 0) self.hbox.show() self.eventbox = gtk.EventBox() self.eventbox.set_visible_window(False) if self.show_entry: self.eventbox.connect("enter-notify-event", self.enter_notify) self.eventbox.connect("leave-notify-event", self.leave_notify) self.eventbox.connect("button-press-event", self.event_box_press) self.hbox.pack_end(self.eventbox, True, True) self.scroll_win = ScrolledWindow() self.pack_start(left_box, False, True) self.pack_start(self.hbox, True, True) # Add Bread Items self.adj = self.scroll_win.get_hadjustment() self.add(self.crumb) def create_crumb(self, crumb): ''' Internal function to create a Crumb list for different types of inputs. @param crumb: Support inputs are: ["a label", Menu] [("a label",[(None, "menu label", None)])] Crumb instance [Crumb, Crumb] ''' if isinstance(crumb, Crumb): return [ crumb, ] elif isinstance(crumb[0], str): return [ Crumb(crumb[0], crumb[1]), ] elif isinstance(crumb[0], Crumb): return crumb else: return [Crumb(c[0], c[1]) for c in crumb] def enter_notify(self, widget, event): ''' Internal callback function to "enter-notify-event" signal. @param widget: gtk.EventBox. @param event: The pointer event of type gtk.gdk.Event. ''' self.in_event_box = True def leave_notify(self, widget, event): ''' Internal callback function to "leave-notify-event" signal. @param widget: Gtk.EventBox. @param event: The pointer event of type gtk.gdk.Event. ''' self.in_event_box = False def event_box_press(self, widget, event): ''' Internal callback function to "button-press-event" signal. @param widget: gtk.eventbox. @param event: event of type gtk.gdk.event. ''' obj = self.hbox.get_children() label = [] for o in obj[:-1]: label.append("/" + o.label) o.destroy() self.entry = gtk.Entry() self.entry.connect("activate", self.enter_cb) self.entry.set_text("".join(label)) self.entry.show() self.entry.select_region(0, len(self.entry.get_text())) self.eventbox.hide() self.hbox.pack_start(self.entry, True, True) def enter_cb(self, widget): ''' Internal callback function to "press-return" signal. @param widget: gtk.Entry widget instance. ''' label = widget.get_text() widget.destroy() self.eventbox.show() self.emit("entry-changed", label) def redraw_bg(self, widget, event): ''' Internal callback function to "expose-event" signal. @param widget: gtk.EventBox @param event: event of type gtk.gdk.event ''' cr = widget.window.cairo_create() rect = widget.allocation # Draw backgroud. with cairo_state(cr): cr.set_source_rgba(*alpha_color_hex_to_cairo(("#def5ff", 1))) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() return False def add(self, crumbs): ''' Add crumbs. Can accept Crumb instance or a list of Crumb instances @param crumbs: Supported inputs are: ["a label", Menu] [("a label",[(None, "menu label", None)])] Crumb instance [Crumb, Crumb] ''' crumbs = self.create_crumb(crumbs) for crumb in crumbs: crumb.show() crumb.arrow_right = self.arrow_right crumb.arrow_down = self.arrow_down crumb.index_id = len(self.item_list) crumb.connect("item_clicked", self.click_cb) self.hbox.pack_start(crumb, False, False) self.item_list.append(crumb.get_size_request()[0]) page_size = self.adj.page_size # Show right button if crumbs exceed scrolled window size. if sum(self.item_list) > page_size and not page_size == 1.0: self.right_btn.show() def change_node(self, index, crumbs): ''' Change any nodes start from specified index @param index: Start index @param crumbs: Crumb instance or Crumb list For instance, there exist a list contain [Crumb1, Crumb2], by using change_node(1, [Crumb3, Crumb4]), previous list will be change to [Crumb1, Crumb3, Crumb4]. In this way, application can operate crumbs ''' objects = self.hbox.get_children() for i in objects[index:-1]: i.destroy() self.item_list[index:] = [] self.add(crumbs) def remove_node_after_index(self, index): ''' Remove any nodes after given index. @param index: To specified remove after given index. ''' for i in self.hbox.get_children()[(index + 1):-1]: i.destroy() self.item_list[(index + 1):] = [] def click_cb(self, widget, index, label): ''' Internal callback function to "clicked" signal. @param widget: Crumb instance. @param index: The index value of clicked crumb. @param label: Label of the crumb. ''' if not self.show_others: for i in self.hbox.get_children()[(index + 1):-1]: i.destroy() self.item_list[(index + 1):] = [] self.emit("item_clicked", index, label) def move_right(self, widget): ''' Internal callback function to "clicked" signal. @param widget: Right button. ''' upper, page_size, value = self.adj.upper, self.adj.page_size, self.adj.value shift_value = 0 temp = 0 if upper > (page_size + value): self.left_btn.show() for i in xrange(len(self.item_list) + 1): temp += self.item_list[i] if temp > (page_size + value): shift_value = temp - (page_size + value) #play animation ani = Animation(self.adj, lambda widget, v1: widget.set_value(v1), 200, [value, value + shift_value]) ani.start() break if not upper > (page_size + self.adj.value + shift_value): self.right_btn.hide() def move_left(self, widget): ''' Internal callback function to "clicked" signal. @param widget: Left button. ''' upper, page_size, value = self.adj.upper, self.adj.page_size, self.adj.value shift_value = 0 temp = 0 if not value == 0: self.right_btn.show() for i in xrange(len(self.item_list)): temp += self.item_list[i] if temp >= value: shift_value = self.item_list[i] - (temp - value) break #play animation ani = Animation(self.adj, lambda widget, v1: widget.set_value(v1), 200, [value, value - shift_value]) ani.start() if (self.adj.value - shift_value) == 0: self.left_btn.hide() def set_size(self, width, height): ''' Set Bread size. @param width: Width of Bread. @param height: Height of Bread. ''' self.scroll_win.set_size_request(width - 2 * self.button_width, height) self.hbox.set_size_request(-1, self.hbox.get_children()[0].height)
def __init__(self, right_space=2, top_bootm_space=3): '''Init droplist scrolled window.''' ScrolledWindow.__init__(self, right_space, top_bootm_space)
def __init__(self, crumb, arrow_right=ui_theme.get_pixbuf("treeview/arrow_right.png"), arrow_down=ui_theme.get_pixbuf("treeview/arrow_down.png"), show_others=False, show_entry=False, show_left_right_box=True): ''' Initialize Bread class. @param crumb: Crumb instance or a list of crumb instances @param arrow_right: Dynamic pixbuf for right arrow, default is \"treeview/arrow_right.png\" from ui theme. @param arrow_down: Dynamic pixbuf for down arrow, default is \"treeview/arrow_down.png\" from ui theme. @param show_others: If True, crumbs will not be destroyed, otherwise all crumbs on the right side will be destroyed. @param show_entry: If True, an entry will pop up when click space area in Bread. ''' # Init. super(Bread, self).__init__(spacing=0) self.arrow_right = arrow_right self.arrow_down = arrow_down self.item_list = list() self.show_others = show_others self.show_entry = show_entry self.crumb = self.create_crumb(crumb) self.button_width = ARROW_BUTTON_WIDTH # for left & right buttons self.in_event_box = False # Init left button and right button. self.show_left_right_box = show_left_right_box left_box = gtk.HBox(spacing=0) right_box = gtk.HBox(spacing=0) # FIXME: left && right box static setting size # it is better to consider whether or not shown left && right box # at runtime if self.show_left_right_box: left_box.set_size_request(self.button_width, -1) right_box.set_size_request(self.button_width, -1) self.left_btn = Button("<") self.right_btn = Button(">") self.left_btn.set_no_show_all(True) self.right_btn.set_no_show_all(True) self.right_btn.connect("clicked", self.move_right) self.left_btn.connect("clicked", self.move_left) self.left_btn.set_size_request(self.button_width, -1) self.right_btn.set_size_request(self.button_width, -1) left_box.pack_start(self.left_btn, False, False) right_box.pack_start(self.right_btn, False, False) # Init Hbox self.hbox = gtk.HBox(False, 0) self.hbox.show() self.eventbox = gtk.EventBox() self.eventbox.set_visible_window(False) if self.show_entry: self.eventbox.connect("enter-notify-event", self.enter_notify) self.eventbox.connect("leave-notify-event", self.leave_notify) self.eventbox.connect("button-press-event", self.event_box_press) self.hbox.pack_end(self.eventbox, True, True) self.scroll_win = ScrolledWindow() self.pack_start(left_box, False, True) self.pack_start(self.hbox, True, True) # Add Bread Items self.adj = self.scroll_win.get_hadjustment() self.add(self.crumb)