def main(): parser = optparse.OptionParser(usage="usage: %prog [options] FILE...") parser.add_option("-r", "--recursive", action="store_true", default=False) parser.add_option("-c", "--check", action="store_true", default=False) parser.add_option("-s", "--stats", action="store_true", default=False) parser.add_option("-b", "--base-dir") options, args = parser.parse_args() if not args: args = ["."] if options.check: check_directories(args) return scanner = FileScanner(recursive=options.recursive) files, start_file = scanner.get_files_from_args(args) if options.stats: print_stats(files) return try: app = ViewerApp(files, start_file, options.base_dir) app.run() except Exception, e: import traceback traceback.print_exc() print "Error:", e
def get_items_from_dir(self): # Obtain the directories first: scanner = FileScanner() dirs = scanner.get_dirs_from_dir(self.directory) for dir_ in sorted(dirs, key=lambda dir_: os.stat(dir_).st_mtime, reverse=True): if self.filter_ and not self.filter_.lower() in dir_.lower(): continue yield DirectoryItem(dir_, self.thumb_size/2) # Now the files: files = scanner.get_files_from_dir(self.directory) file_manager = FileManager() file_manager.set_files(files) file_manager.sort_by_date(True) file_manager.go_first() for _ in range(file_manager.get_list_length()): current_file = file_manager.get_current_file() if not self.filter_ or self.filter_.lower() in current_file.get_basename().lower(): yield ImageItem(current_file, self.thumb_size/2) file_manager.go_forward(1) self.items_count = (len(dirs), len(files))
def get_pixbuf(self): scanner = FileScanner() files = scanner.get_files_from_dir(self.directory) if files: file_manager = FileManager(on_list_modified=lambda: None) file_manager.set_files(files) file_manager.sort_by_date(True) file_manager.go_first() return self.get_mixed_thumbnail(file_manager.get_current_file(), self.default_thumbnail_size) else: dir_icon = GTKIconImage(gtk.STOCK_DIRECTORY, self.default_gtk_icon_size) return dir_icon.get_pixbuf()
def on_dir_selected(self, item): scanner = FileScanner() dirs = scanner.get_dirs_from_dir(item) if self.dir_selector and not dirs: self.on_dir_selected_cb(item, self.recursive_check.get_active()) self.close() return self.curdir = item self.go_up.set_sensitive(self.curdir != "/") self.update_model() self.last_filter = "" self.filter_entry.set_text("") self.filter_entry.grab_focus()
def get_items_count(self): scanner = FileScanner() return (len(scanner.get_dirs_from_dir(self.directory)), len(scanner.get_files_from_dir(self.directory)))