From 6256c08bb451f284b5f56d2e4d8106480bc3aeeb Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 10 Oct 2013 20:50:15 +1100 Subject: [PATCH] Reverted recursive sort, opted for natsorted lib Was having performance issue with very large directories. This does have the issue of order "File (1)" before "File", have raised an issue with natsorted. --- mangle/book.py | 20 ++++++++------------ mangle/util.py | 8 -------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/mangle/book.py b/mangle/book.py index 7b9fe72..f9544f2 100644 --- a/mangle/book.py +++ b/mangle/book.py @@ -22,6 +22,7 @@ from image import ImageFlags from about import DialogAbout from options import DialogOptions from convert import DialogConvert +from natsort import natsorted class Book(object): @@ -352,13 +353,11 @@ class MainWindowBook(QtGui.QMainWindow): def addImageFiles(self, filenames): - filenames.sort() - filenamesListed = [] for i in xrange(0, self.listWidgetFiles.count()): filenamesListed.append(self.listWidgetFiles.item(i).text()) - for filename in filenames: + for filename in natsorted(filenames): if filename not in filenamesListed: filename = QtCore.QString(filename) self.listWidgetFiles.addItem(filename) @@ -370,15 +369,12 @@ class MainWindowBook(QtGui.QMainWindow): filenames = [] for directory in directories: - directory = unicode(directory) - for item in sorted(os.listdir(directory), key=util.tokenize): - item = unicode(item) - path = os.path.join(directory, item) - if self.isImageFile(path): - filenames.append(path) - elif os.path.isdir(path): - self.addImageDirs([path]) - + for root, subdirs, subfiles in os.walk(unicode(directory)): + for filename in subfiles: + path = os.path.join(root, filename) + if self.isImageFile(path): + filenames.append(path) + self.addImageFiles(filenames) diff --git a/mangle/util.py b/mangle/util.py index 5b84855..ff749d2 100644 --- a/mangle/util.py +++ b/mangle/util.py @@ -21,11 +21,3 @@ import re def buildResPath(relative): directory = os.path.dirname(__file__) return os.path.join(directory, relative) - - -digits = re.compile(r'(\d+)') -def tokenize(filename): - return tuple(int(token) if match else token - for token, match in - ((fragment, digits.search(fragment)) - for fragment in digits.split(filename)))