diff --git a/debian/changelog b/debian/changelog index a070ef0..81d75e3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,6 @@ -trimage (1.0.0b-0ubuntu1) jaunty; urgency=low +trimage (1.0.0b2-0ubuntu1) jaunty; urgency=low - * Trimage image compressor - - -- Kilian Valkhof Tue, 23 Mar 2010 20:18:17 +0100 + * correct parsing of unicode characters in filenames + * changelog + -- Kilian Valkhof Sun, 28 Mar 2010 16:09:45 +0200 diff --git a/setup.py b/setup.py index 2e0ac48..f286b8b 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name = "trimage", - version = "1.0.0b", + version = "1.0.0b2", description = "Trimage image compressor - A cross-platform tool for optimizing PNG and JPG files", author = "Kilian Valkhof, Paul Chaplin", author_email = "help@trimage.org", diff --git a/src/trimage/trimage.py b/src/trimage/trimage.py index 53ba73f..e8a6182 100755 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -13,7 +13,8 @@ from hurry.filesize import * from ui import Ui_trimage -VERSION = "1.0.0b" +VERSION = "1.0.0b2" + class StartQT4(QMainWindow): @@ -100,8 +101,9 @@ class StartQT4(QMainWindow): imagedir = listdir(directory) filelist = QStringList() for image in imagedir: - image = QString(path.join(dirpath, image)) - filelist.append(image) + image = self.unicodize(path.join(dirpath, image)) + if self.checkname(image): + filelist.append(image) self.delegator(filelist) def file_from_cmd(self, image): @@ -109,13 +111,16 @@ class StartQT4(QMainWindow): self.showapp = False image = path.abspath(image) filecmdlist = QStringList() - filecmdlist.append(image) + if self.checkname(image): + filecmdlist.append(self.unicodize(image)) self.delegator(filecmdlist) def file_drop(self, images): """ Get a file from the drag and drop handler and send it to compress_file. """ + for image in images: + image = self.unicodize(unicode(image).encode('utf-8')) self.delegator(images) def file_dialog(self): @@ -126,6 +131,10 @@ class StartQT4(QMainWindow): "", # directory # this is a fix for file dialog differentiating between cases "Image files (*.png *.jpg *.jpeg *.PNG *.JPG *.JPEG)") + + for image in images: + image = self.unicodize(unicode(image)) + self.delegator(images) def recompress_files(self): @@ -151,7 +160,7 @@ class StartQT4(QMainWindow): self.imagelist.append(("Compressing...", "", "", "", image, QIcon(QPixmap(self.ui.get_image("pixmaps/compressing.gif"))))) else: - sys.stderr.write("[error] %s not an image file" % image) + sys.stderr.write("[error] %s not an image file\n" % image) self.update_table() self.thread.compress_file(delegatorlist, self.showapp, self.verbose, @@ -195,7 +204,7 @@ class StartQT4(QMainWindow): def checkname(self, name): """Check if the file is a jpg or png.""" - return path.splitext(str(name))[1].lower() in [".jpg", ".jpeg", ".png"] + return path.splitext(unicode(name))[1].lower() in [".jpg", ".jpeg", ".png"] def enable_recompress(self): """Enable the recompress button.""" @@ -230,6 +239,13 @@ class StartQT4(QMainWindow): else: raise + def unicodize(self, obj, encoding='utf-8'): + if isinstance(obj, basestring): + if not isinstance(obj, unicode): + obj = unicode(obj, encoding) + return obj + + class TriTableModel(QAbstractTableModel): def __init__(self, parent, imagelist, header, *args): @@ -294,7 +310,7 @@ class Worker(QThread): """Compress the given file, get data from it and call update_table.""" for image in self.images: #gather old file data - filename = str(image[0]) + filename = unicode(image[0]) icon = image[1] oldfile = QFileInfo(filename) name = oldfile.fileName() @@ -305,10 +321,9 @@ class Worker(QThread): extention = path.splitext(filename)[1] #decide with tool to use if extention in [".jpg", ".jpeg"]: - runString = "jpegoptim -f --strip-all '%(file)s'" + runString = u"jpegoptim -f --strip-all '%(file)s'" elif extention in [".png"]: - runString = ("optipng -force -o7 '%(file)s';" - "advpng -z4 '%(file)s'") + runString = (u"optipng -force -o7 '%(file)s'; advpng -z4 '%(file)s'") else: sys.stderr.write("[error] %s not an image file" % filename) diff --git a/src/trimage/ui.py b/src/trimage/ui.py index 0788c4f..6f4ec81 100644 --- a/src/trimage/ui.py +++ b/src/trimage/ui.py @@ -9,7 +9,7 @@ class TrimageTableView(QTableView): self.setAcceptDrops(True) def dragEnterEvent(self, event): - if event.mimeData().hasFormat("text/uri-list"): + if event.mimeData().hasUrls: event.accept() else: event.ignore() @@ -18,10 +18,12 @@ class TrimageTableView(QTableView): event.accept() def dropEvent(self, event): - files = str(event.mimeData().data("text/uri-list")).strip().split() - for i, file in enumerate(files): - files[i] = QUrl(QString(file)).toLocalFile() - self.emit(SIGNAL("fileDropEvent"), (files)) + event.accept() + filelist = [] + for url in event.mimeData().urls(): + filelist.append(unicode(url.toLocalFile())) + + self.emit(SIGNAL("fileDropEvent"), (filelist)) class Ui_trimage(object): diff --git a/website/index.html b/website/index.html index b902bdb..a80ac97 100644 --- a/website/index.html +++ b/website/index.html @@ -2,7 +2,7 @@ - Trimage image compressor + Trimage (lossless) image compressor