Exemplo n.º 1
0
class FileManager(HPaned):
    HOME_DIR = os.getenv("HOME", "") + "/"
    ICONVIEW = 0
    TREEVIEW = 1

    def __init__(self,
                 dir=HOME_DIR,
                 view_mode=ICONVIEW
                ):
        HPaned.__init__(self)
        self.categorybar = Categorybar([
            (ui_theme.get_pixbuf("filemanager/computer.png"), _("Computer"), None),
            (ui_theme.get_pixbuf("filemanager/user-home.png"), _("Home"), lambda : self.open_dir(self.HOME_DIR)),
            (ui_theme.get_pixbuf("filemanager/user-desktop.png"), _("Desktop"), lambda : self.open_dir(self.HOME_DIR + "Desktop/")),
            (ui_theme.get_pixbuf("filemanager/folder-documents.png"), _("Documents"), lambda : self.open_dir(self.HOME_DIR + "Documents/")),
            (ui_theme.get_pixbuf("filemanager/folder-download.png"), _("Downloads"), lambda : self.open_dir(self.HOME_DIR + "Downloads/")),
            (ui_theme.get_pixbuf("filemanager/folder-music.png"), _("Music"), lambda : self.open_dir(self.HOME_DIR + "Music/")),
            (ui_theme.get_pixbuf("filemanager/folder-pictures.png"), _("Pictures"), lambda : self.open_dir(self.HOME_DIR + "Pictures/")),
            (ui_theme.get_pixbuf("filemanager/folder-videos.png"), _("Videos"), lambda : self.open_dir(self.HOME_DIR + "Videos/")),
            (ui_theme.get_pixbuf("filemanager/user-trash.png"), _("Trash"), lambda : self.open_dir("trash:///"))
            ])
        self.icon_size = 48
        self.iconview = FileIconView()
        self.iconview.add_items(iconview_get_dir_items(dir, self.icon_size))
        self.treeview = TreeView(get_dir_items(dir))
        self.add1(self.categorybar)
        if view_mode == self.ICONVIEW:
            self.add2(self.iconview)
        else:
            self.add2(self.treeview)

    def open_dir(self, dir):
        self.iconview.add_items(iconview_get_dir_items(dir), True)
        self.treeview.add_items(get_dir_items(dir), None, True)
Exemplo n.º 2
0
class FileManager(HPaned):
    HOME_DIR = os.getenv("HOME", "") + "/"
    ICONVIEW = 0
    TREEVIEW = 1

    def __init__(self, dir=HOME_DIR, view_mode=ICONVIEW):
        HPaned.__init__(self)
        self.categorybar = Categorybar([
            (ui_theme.get_pixbuf("filemanager/computer.png"), _("Computer"),
             None),
            (ui_theme.get_pixbuf("filemanager/user-home.png"), _("Home"),
             lambda: self.open_dir(self.HOME_DIR)),
            (ui_theme.get_pixbuf("filemanager/user-desktop.png"), _("Desktop"),
             lambda: self.open_dir(self.HOME_DIR + "Desktop/")),
            (ui_theme.get_pixbuf("filemanager/folder-documents.png"),
             _("Documents"),
             lambda: self.open_dir(self.HOME_DIR + "Documents/")),
            (ui_theme.get_pixbuf("filemanager/folder-download.png"),
             _("Downloads"),
             lambda: self.open_dir(self.HOME_DIR + "Downloads/")),
            (ui_theme.get_pixbuf("filemanager/folder-music.png"), _("Music"),
             lambda: self.open_dir(self.HOME_DIR + "Music/")),
            (ui_theme.get_pixbuf("filemanager/folder-pictures.png"),
             _("Pictures"),
             lambda: self.open_dir(self.HOME_DIR + "Pictures/")),
            (ui_theme.get_pixbuf("filemanager/folder-videos.png"), _("Videos"),
             lambda: self.open_dir(self.HOME_DIR + "Videos/")),
            (ui_theme.get_pixbuf("filemanager/user-trash.png"), _("Trash"),
             lambda: self.open_dir("trash:///"))
        ])
        self.icon_size = 48
        self.iconview = FileIconView()
        self.iconview.add_items(iconview_get_dir_items(dir, self.icon_size))
        self.treeview = TreeView(get_dir_items(dir))
        self.add1(self.categorybar)
        if view_mode == self.ICONVIEW:
            self.add2(self.iconview)
        else:
            self.add2(self.treeview)

    def open_dir(self, dir):
        self.iconview.add_items(iconview_get_dir_items(dir), True)
        self.treeview.add_items(get_dir_items(dir), None, True)
Exemplo n.º 3
0
class PreferenceDialog(DialogBox):
    '''
    PreferenceDialog class.
    
    @undocumented: button_press_preference_item
    @undocumented: set_item_widget
    @undocumented: draw_treeview_mask
    '''
	
    def __init__(self,
                 default_width=575,
                 default_height=495,
                 ):
        '''
        Initialize PreferenceDialog class.
        
        @param default_width: The default width, default is 575 pixels.
        @param default_height: The default height, default is 495 pixels.
        '''
        DialogBox.__init__(
            self,
            _("Preferences"), 
            default_width,
            default_height,
            mask_type=DIALOG_MASK_MULTIPLE_PAGE,
            close_callback=self.hide_dialog,
            )
        self.set_position(gtk.WIN_POS_CENTER)
        
        self.main_box = gtk.VBox()
        close_button = Button(_("Close"))
        close_button.connect("clicked", lambda w: self.hide_all())
        
        # Category bar
        category_bar_width = 132
        self.category_bar = TreeView(
            enable_drag_drop=False, 
            enable_multiple_select=False,
            )
        self.category_bar.set_expand_column(1)
        self.category_bar.draw_mask = self.draw_treeview_mask
        self.category_bar.set_size_request(category_bar_width, 516)
        self.category_bar.connect("button-press-item", self.button_press_preference_item)
        
        category_box = gtk.VBox()
        background_box = BackgroundBox()
        background_box.set_size_request(category_bar_width, 11)
        background_box.draw_mask = self.draw_treeview_mask
        category_box.pack_start(background_box, False, False)
        
        category_bar_align = gtk.Alignment()
        category_bar_align.set(0, 0, 1, 1,)
        category_bar_align.set_padding(0, 1, 0, 0)
        category_bar_align.add(self.category_bar)
        category_box.pack_start(category_bar_align, True, True)
        
        # Pack widget.
        left_box = gtk.VBox()
        self.right_box = gtk.VBox()
        left_box.add(category_box)
        right_align = gtk.Alignment()
        right_align.set_padding(0, 0, 0, 0)
        right_align.add(self.right_box)

        body_box = gtk.HBox()
        body_box.pack_start(left_box, False, False)
        body_box.pack_start(right_align, False, False)
        self.main_box.add(body_box)
        
        # DialogBox code.
        self.body_box.pack_start(self.main_box, True, True)
        self.right_button_box.set_buttons([close_button])        
        
    def hide_dialog(self):
        self.hide_all()
        
        return True
        
    def button_press_preference_item(self, treeview, item, column_index, offset_x, offset_y):
        if self.set_item_widget(item):
            self.show_all()
            
    def set_item_widget(self, item):
        if isinstance(item, PreferenceItem):
            container_remove_all(self.right_box)
            self.right_box.pack_start(item.item_widget)
            self.category_bar.select_items([item])
            
            return True
        else:
            return False
            
    def draw_treeview_mask(self, cr, x, y, width, height):
        cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FFFFFF", 0.9)))
        cr.rectangle(x, y, width, height)
        cr.fill()
        
    def set_preference_items(self, preference_items):
        '''
        Set preference items.
        
        @param preference_items: The list of preference item, item format is:
         - (item_name, item_widget)
         - Item list support recursively add.
        '''
        items = []
        for (item_name, item_content) in preference_items:
            if isinstance(item_content, gtk.Widget):
                items.append(PreferenceItem(item_name, item_content))
            elif isinstance(item_content, list):
                expand_item = ExpandPreferenceItem(item_name)
                items.append(expand_item)
                
                child_items = []
                for (child_item_name, child_item_content) in item_content:
                    child_items.append(PreferenceItem(child_item_name, child_item_content))
                    
                expand_item.add_items(child_items)
            
        self.category_bar.add_items(items)
        
        for item in items:
            if self.set_item_widget(item):
                break
Exemplo n.º 4
0
class PreferenceDialog(DialogBox):
    '''
    PreferenceDialog class.

    @undocumented: button_press_preference_item
    @undocumented: set_item_widget
    @undocumented: draw_treeview_mask
    '''

    def __init__(self,
                 default_width=575,
                 default_height=495,
                 ):
        '''
        Initialize PreferenceDialog class.

        @param default_width: The default width, default is 575 pixels.
        @param default_height: The default height, default is 495 pixels.
        '''
        DialogBox.__init__(
            self,
            _("Preferences"),
            default_width,
            default_height,
            mask_type=DIALOG_MASK_MULTIPLE_PAGE,
            close_callback=self.hide_dialog,
            )
        self.set_position(gtk.WIN_POS_CENTER)

        self.main_box = gtk.VBox()
        close_button = Button(_("Close"))
        close_button.connect("clicked", lambda w: self.hide_all())

        # Category bar
        category_bar_width = 132
        self.category_bar = TreeView(
            enable_drag_drop=False,
            enable_multiple_select=False,
            )
        self.category_bar.set_expand_column(1)
        self.category_bar.draw_mask = self.draw_treeview_mask
        self.category_bar.set_size_request(category_bar_width, 516)
        self.category_bar.connect("button-press-item", self.button_press_preference_item)

        category_box = gtk.VBox()
        background_box = BackgroundBox()
        background_box.set_size_request(category_bar_width, 11)
        background_box.draw_mask = self.draw_treeview_mask
        category_box.pack_start(background_box, False, False)

        category_bar_align = gtk.Alignment()
        category_bar_align.set(0, 0, 1, 1,)
        category_bar_align.set_padding(0, 1, 0, 0)
        category_bar_align.add(self.category_bar)
        category_box.pack_start(category_bar_align, True, True)

        # Pack widget.
        left_box = gtk.VBox()
        self.right_box = gtk.VBox()
        left_box.add(category_box)
        right_align = gtk.Alignment()
        right_align.set_padding(0, 0, 0, 0)
        right_align.add(self.right_box)

        body_box = gtk.HBox()
        body_box.pack_start(left_box, False, False)
        body_box.pack_start(right_align, False, False)
        self.main_box.add(body_box)

        # DialogBox code.
        self.body_box.pack_start(self.main_box, True, True)
        self.right_button_box.set_buttons([close_button])

    def hide_dialog(self):
        self.hide_all()

        return True

    def button_press_preference_item(self, treeview, item, column_index, offset_x, offset_y):
        if self.set_item_widget(item):
            self.show_all()

    def set_item_widget(self, item):
        if isinstance(item, PreferenceItem):
            container_remove_all(self.right_box)
            self.right_box.pack_start(item.item_widget)
            self.category_bar.select_items([item])

            return True
        else:
            return False

    def draw_treeview_mask(self, cr, x, y, width, height):
        cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FFFFFF", 0.9)))
        cr.rectangle(x, y, width, height)
        cr.fill()

    def set_preference_items(self, preference_items):
        '''
        Set preference items.

        @param preference_items: The list of preference item, item format is:
         - (item_name, item_widget)
         - Item list support recursively add.
        '''
        items = []
        for (item_name, item_content) in preference_items:
            if isinstance(item_content, gtk.Widget):
                items.append(PreferenceItem(item_name, item_content))
            elif isinstance(item_content, list):
                expand_item = ExpandPreferenceItem(item_name)
                items.append(expand_item)

                child_items = []
                for (child_item_name, child_item_content) in item_content:
                    child_items.append(PreferenceItem(child_item_name, child_item_content))

                expand_item.add_items(child_items)

        self.category_bar.add_items(items)

        for item in items:
            if self.set_item_widget(item):
                break