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.
This commit is contained in:
Jan 2013-10-10 20:50:15 +11:00
parent df08b06d33
commit 6256c08bb4
2 changed files with 8 additions and 20 deletions

View File

@ -22,6 +22,7 @@ from image import ImageFlags
from about import DialogAbout from about import DialogAbout
from options import DialogOptions from options import DialogOptions
from convert import DialogConvert from convert import DialogConvert
from natsort import natsorted
class Book(object): class Book(object):
@ -352,13 +353,11 @@ class MainWindowBook(QtGui.QMainWindow):
def addImageFiles(self, filenames): def addImageFiles(self, filenames):
filenames.sort()
filenamesListed = [] filenamesListed = []
for i in xrange(0, self.listWidgetFiles.count()): for i in xrange(0, self.listWidgetFiles.count()):
filenamesListed.append(self.listWidgetFiles.item(i).text()) filenamesListed.append(self.listWidgetFiles.item(i).text())
for filename in filenames: for filename in natsorted(filenames):
if filename not in filenamesListed: if filename not in filenamesListed:
filename = QtCore.QString(filename) filename = QtCore.QString(filename)
self.listWidgetFiles.addItem(filename) self.listWidgetFiles.addItem(filename)
@ -370,14 +369,11 @@ class MainWindowBook(QtGui.QMainWindow):
filenames = [] filenames = []
for directory in directories: for directory in directories:
directory = unicode(directory) for root, subdirs, subfiles in os.walk(unicode(directory)):
for item in sorted(os.listdir(directory), key=util.tokenize): for filename in subfiles:
item = unicode(item) path = os.path.join(root, filename)
path = os.path.join(directory, item) if self.isImageFile(path):
if self.isImageFile(path): filenames.append(path)
filenames.append(path)
elif os.path.isdir(path):
self.addImageDirs([path])
self.addImageFiles(filenames) self.addImageFiles(filenames)

View File

@ -21,11 +21,3 @@ import re
def buildResPath(relative): def buildResPath(relative):
directory = os.path.dirname(__file__) directory = os.path.dirname(__file__)
return os.path.join(directory, relative) 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)))