From c9126ae19622eb22659f9e190080467ad4eb3d58 Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Wed, 31 Mar 2010 17:44:29 +0200 Subject: [PATCH 01/10] compress image, remove unneeded code, add more docstrings --- src/trimage/trimage.py | 34 +++++++--------------------------- website/ubuntu.png | Bin 1101 -> 1088 bytes 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/trimage/trimage.py b/src/trimage/trimage.py index 216ea26..7df6cf4 100755 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -281,18 +281,20 @@ class TriTableModel(QAbstractTableModel): class Image: def __init__(self, fullpath): + """ gather image information. """ self.valid = False self.fullpath = fullpath - if path.isfile(self.fullpath): + if path.isfile(self.fullpath): self.filetype = determinetype(self.fullpath) if self.filetype in ["jpeg", "png"]: oldfile = QFileInfo(self.fullpath) self.shortname = oldfile.fileName() - self.oldfilesize = oldfile.size() - self.icon = QIcon(self.fullpath) + self.oldfilesize = oldfile.size() + self.icon = QIcon(self.fullpath) self.valid = True def _determinetype(self): + """ Determine the filetype of the file using imghdr. """ filetype=determinetype(self.fullpath) if filetype in ["jpeg", "png"]: self.filetype=filetype @@ -301,6 +303,7 @@ class Image: return self.filetype def compress(self): + """ Compress the image and return it to the thread. """ if not self.valid: raise "Tried to compress invalid image (unsupported format or not file)" runString = { @@ -346,7 +349,7 @@ class Worker(QThread): # append current image to list for i, listitem in enumerate(self.imagelist): - if listitem[4] == image: + if listitem[4] == image: self.imagelist.remove(listitem) self.imagelist.insert(i, (image.shortname, oldfilesizestr, newfilesizestr, ratiostr, image.fullpath, image.icon)) @@ -361,29 +364,6 @@ class Worker(QThread): else: print >>sys.stderr, u"[error] %s could not be compressed" % image.fullpath - -class TrimageTableView(QTableView): - """Init the table drop event.""" - def __init__(self, parent=None): - super(TrimageTableView, self).__init__(parent) - self.setAcceptDrops(True) - - def dragEnterEvent(self, event): - if event.mimeData().hasFormat("text/uri-list"): - event.accept() - else: - event.ignore() - - def dragMoveEvent(self, event): - 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() - files=[i.toUtf8().decode("utf-8") for i in files] - self.emit(SIGNAL("fileDropEvent"), (files)) - if __name__ == "__main__": app = QApplication(sys.argv) myapp = StartQT4() diff --git a/website/ubuntu.png b/website/ubuntu.png index 0b2e82c8d04cfba0a449f55819093156c3583c05..3e77ad4940ef22aa903766ffff2c7810747cd707 100644 GIT binary patch delta 438 zcmX@hae!mPRHpiAo-U3d8t0P}6hwWtmc=!CuWRq0=$T=<>&3cvYfgOVVXivfFQ4A& zJ~`Voa1wLV&0`Lp*HlDS{^Xg><4{yIQ8DrcW>DJ*+2C9k)R$VE?s}9VuJur%#{mFWVEohHpw~ z%SXOrOsd6#Y)2VXO~smKM)S*_`}T<|vTH(2vWmKTJX6Y>&EXf;-4S~`wdakUe`x5_ z1ckXACQj9nt>Jc?o-Fiz9hS#_$xmVb*^F;mE}WCTzP|pREhx3Cs3tHw)X7Gk#WBSXcCpUrx*uMU%a($a9ARK;i%7a9kbLWofbidhmtHF$I`s0KH z`PZ+!*e`fAJ-AQzA=~M~tNQCRZ}iM-v9UNfY1!&Ud-go~w&=9kO|NbaZ@(8TR(j{M yjhM?Wyyxw?Gt)w)f64D3PYfQgbc;1>GO(I8inY(;WoBStVDNPHb6Mw<&;$U9_RISK delta 451 zcmX@Wah7AlRHpjHo-U3d6}P5d_-P&*D01NAU!UtX(|;-@w`rUd2vpiO{pHkCr>C?m zIyr%dlT&kZNXCSK7ow>>i+22<_IBO7>h!%^@A2>3|7P>`^tqo8H`bb$7$rtcx7|MF z<;`;qVXI@!*T-o6Ep`!LX|B=Dwyx_~?skZScRk~6>lyq{ziYkTAXcBk9X-ita`kzC_qJ9%oXnQq|8Y;XsI1u|8zy-@t&JQrf@*5^h?sD{ z>^yKXYR}g*0{ ziGQl>hWWA4(Mhpy-p;AAo+y>jxKdp-@Lv@BKkbR9PdlbRmOr|Yo7JpQETSUd1p@;E NgQu&X%Q~loCIGp$+WP Date: Fri, 2 Apr 2010 13:51:19 +0200 Subject: [PATCH 02/10] pep8 rewriting, version update, todo editing --- resources/todo | 8 +++ setup.py | 2 +- src/trimage/trimage.py | 107 ++++++++++++++++++++++++----------------- website/index.html | 8 +-- 4 files changed, 73 insertions(+), 52 deletions(-) diff --git a/resources/todo b/resources/todo index a215d43..d602f42 100644 --- a/resources/todo +++ b/resources/todo @@ -33,3 +33,11 @@ later versions: again would currently try to recompress all 100, when only 10 would be worthy of trying to compress further. + +1.1.0 changes: +- use multiprocessing for images +- more robust file handling +- re-adding images now results in recompressing them +- compressing message now shows filename +- wider array of status messages in the table + diff --git a/setup.py b/setup.py index 4ffd086..21635fa 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name = "trimage", - version = "1.0.0b3", + version = "1.1.0b", 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 c054d61..6f77c4d 100755 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -18,7 +18,7 @@ from multiprocessing import cpu_count from ui import Ui_trimage -VERSION = "1.0.0b3" +VERSION = "1.1.0b" class StartQT4(QMainWindow): @@ -148,20 +148,21 @@ class StartQT4(QMainWindow): """ delegatorlist = [] for fullpath in images: - try: # do not add already existing images again, recompress them instead - image=(i.image for i in self.imagelist + try: # recompress images already in the list + image = (i.image for i in self.imagelist if i.image.fullpath == fullpath).next() if image.compressed: - image.reset() - image.recompression=True - delegatorlist.append(image) + image.reset() + image.recompression = True + delegatorlist.append(image) except StopIteration: - image=Image(fullpath) + image = Image(fullpath) if image.valid: delegatorlist.append(image) - self.imagelist.append(ImageRow(image,QIcon(QPixmap(self.ui.get_image("pixmaps/compressing.gif"))))) + icon = QIcon(QPixmap(self.ui.get_image("pixmaps/compressing.gif"))) + self.imagelist.append(ImageRow(image, icon)) else: - print >>sys.stderr, u"[error] %s not a supported image file" % image.fullpath + print >> sys.stderr, u"[error] %s not a supported image file" % image.fullpath self.update_table() self.thread.compress_file(delegatorlist, self.showapp, self.verbose, @@ -237,6 +238,7 @@ class StartQT4(QMainWindow): else: raise + class TriTableModel(QAbstractTableModel): def __init__(self, parent, imagelist, header, *args): @@ -278,29 +280,38 @@ class TriTableModel(QAbstractTableModel): return QVariant(self.header[col]) return QVariant() -class ImageRow: - def __init__(self, image, waitingIcon=None): - self.image=image - d={ - 'shortname': lambda i: self.statusStr() % i.shortname, - 'oldfilesizestr': lambda i: size(i.oldfilesize, system=alternative) if i.compressed else "", - 'newfilesizestr': lambda i: size(i.newfilesize, system=alternative) if i.compressed else "", - 'ratiostr': lambda i: - "%.1f%%" % (100 - (float(i.newfilesize) / i.oldfilesize * 100)) if i.compressed else "", - 'icon': lambda i: i.icon if i.compressed else waitingIcon, - 'fullpath': lambda i: i.fullpath, #only used by cli +class ImageRow: + + def __init__(self, image, waitingIcon=None): + """ Build the information visible in the table image row. """ + self.image = image + d = { + 'shortname': lambda i: self.statusStr() % i.shortname, + 'oldfilesizestr': lambda i: size(i.oldfilesize, system=alternative) + if i.compressed else "", + 'newfilesizestr': lambda i: size(i.newfilesize, system=alternative) + if i.compressed else "", + 'ratiostr': lambda i: + "%.1f%%" % (100 - (float(i.newfilesize) / i.oldfilesize * 100)) + if i.compressed else "", + 'icon': lambda i: i.icon if i.compressed else waitingIcon, + 'fullpath': lambda i: i.fullpath, #only used by cli } - for i,n in enumerate(['shortname','oldfilesizestr','newfilesizestr','ratiostr','icon']): - d[i]=d[n] + names = ['shortname', 'oldfilesizestr', 'newfilesizestr', + 'ratiostr', 'icon'] + for i, n in enumerate(names): + d[i] = d[n] self.d = d def statusStr(self): + """ Set the status message. """ if self.image.failed: return "ERROR: %s" if self.image.compressing: - return "In Progress..." + message = "Compressing %s..." + return message if not self.image.compressed and self.image.recompression: return "Queued for recompression..." if not self.image.compressed: @@ -310,7 +321,9 @@ class ImageRow: def __getitem__(self, key): return self.d[key](self.image) + class Image: + def __init__(self, fullpath): """ gather image information. """ self.valid = False @@ -327,40 +340,41 @@ class Image: def _determinetype(self): """ Determine the filetype of the file using imghdr. """ - filetype=determinetype(self.fullpath) + filetype = determinetype(self.fullpath) if filetype in ["jpeg", "png"]: - self.filetype=filetype + self.filetype = filetype else: - self.filetype=None + self.filetype = None return self.filetype def reset(self): self.failed = False self.compressed = False self.compressing = False - self.recompression= False + self.recompression = False def compress(self): """ Compress the image and return it to the thread. """ if not self.valid: - raise "Tried to compress invalid image (unsupported format or not file)" + raise "Tried to compress invalid image (unsupported format or not \ + file)" self.reset() - self.compressing=True + self.compressing = True runString = { "jpeg": u"jpegoptim -f --strip-all '%(file)s'", - "png" : u"optipng -force -o7 '%(file)s'&&advpng -z4 '%(file)s'"} + "png": u"optipng -force -o7 '%(file)s'&&advpng -z4 '%(file)s'"} try: retcode = call(runString[self.filetype] % {"file": self.fullpath}, - shell = True, stdout=PIPE) + shell=True, stdout=PIPE) except: - retcode = -1 + retcode = -1 if retcode == 0: self.newfilesize = QFile(self.fullpath).size() - self.compressed=True + self.compressed = True else: - self.failed=True - self.compressing=False - self.retcode=retcode + self.failed = True + self.compressing = False + self.retcode = retcode return self @@ -368,7 +382,7 @@ class Worker(QThread): def __init__(self, parent=None): QThread.__init__(self, parent) - self.toDisplay=Queue() + self.toDisplay = Queue() self.threadpool = ThreadPool(max_workers=cpu_count()) def __del__(self): @@ -377,8 +391,10 @@ class Worker(QThread): def compress_file(self, images, showapp, verbose, imagelist): """Start the worker thread.""" for image in images: - time.sleep(0.05) #FIXME: Workaround http://code.google.com/p/pythonthreadpool/issues/detail?id=5 - self.threadpool.add_job(image.compress, None, return_callback=self.toDisplay.put) + #FIXME:http://code.google.com/p/pythonthreadpool/issues/detail?id=5 + time.sleep(0.05) + self.threadpool.add_job(image.compress, None, + return_callback=self.toDisplay.put) self.showapp = showapp self.verbose = verbose self.imagelist = imagelist @@ -387,19 +403,20 @@ class Worker(QThread): def run(self): """Compress the given file, get data from it and call update_table.""" tp = self.threadpool - while self.showapp or not (tp._ThreadPool__active_worker_count==0 and tp._ThreadPool__jobs.empty()): + while self.showapp or not (tp._ThreadPool__active_worker_count == 0 and + tp._ThreadPool__jobs.empty()): image = self.toDisplay.get() self.emit(SIGNAL("updateUi")) if not self.showapp and self.verbose: # we work via the commandline - if image.retcode==0: - ir=ImageRow(image) + if image.retcode == 0: + ir = ImageRow(image) print("File: " + ir['fullpath'] + ", Old Size: " - + ir['oldfilesizestr'] + ", New Size: " + ir['newfilesizestr'] - + ", Ratio: " + ir['ratiostr']) + + ir['oldfilesizestr'] + ", New Size: " + + ir['newfilesizestr'] + ", Ratio: " + ir['ratiostr']) else: - print >>sys.stderr, u"[error] %s could not be compressed" % image.fullpath + print >> sys.stderr, u"[error] %s could not be compressed" % image.fullpath if __name__ == "__main__": app = QApplication(sys.argv) diff --git a/website/index.html b/website/index.html index 2bd205d..c636199 100644 --- a/website/index.html +++ b/website/index.html @@ -69,7 +69,7 @@
-

Trimage image compressor – 1.0.0b3 (beta)

+

Trimage image compressor – 1.1.0b (beta)

A cross-platform tool for losslessly optimizing PNG and JPG files.

Trimage is a cross-platform GUI and command-line interface to optimize image files via optipng, @@ -165,16 +165,12 @@

Planned features

-

Version 1.0.0 final:

+

Version 1.1.0 final:

  • Expand command line options
  • Make sure a compressed file is always smaller than the original one, or don't compress
  • General refactoring
-

Version 1.1.0

-
    -
  • Use multiprocessing instead of threading
  • -

Beyond that

  • Deletion of rows in the table view
  • From 451269d96050b4cae611d6a9cf61618989fc2268 Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Fri, 2 Apr 2010 15:10:44 +0200 Subject: [PATCH 03/10] update changelog --- debian/changelog | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2df7d56..8d0ed63 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,10 @@ -trimage (1.0.0b3-0ubuntu1) jaunty; urgency=low +trimage (1.1.0b-0ubuntu1) jaunty; urgency=low - * better image filetype determination - * use unicode strings everywhere - * fix bug where Trimage would crash if a directory didn't end in a slash - * avoid a segfault when parsing empty directories - * ../../debian/changelog + * use multiprocessing for images + * more robust file handling + * re-adding images now results in recompressing them + * compressing message now shows filename + * wider array of status messages in the table -- Kilian Valkhof Mon, 29 Mar 2010 13:08:18 +0200 + From 8e781f54098503ddbc590f91695ad8fe17211483 Mon Sep 17 00:00:00 2001 From: Paul Chaplin Date: Fri, 2 Apr 2010 17:47:07 +0100 Subject: [PATCH 04/10] Added Unicode BOM to file to declare encoding; Python assumes ASCII and chokes unless told. --- trimage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trimage b/trimage index 6906ad3..574f5e9 100644 --- a/trimage +++ b/trimage @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python # #Copyright (c) 2010 Kilian Valkhof, Paul Chaplin, Tarnay Kálmán # From 348f97fabc5dc4d3eabdd27d44f3fc4b2fa61ad3 Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Mon, 5 Apr 2010 15:21:54 +0200 Subject: [PATCH 05/10] no multiprocessing, no subversion bump --- debian/changelog | 4 ++-- setup.py | 2 +- src/trimage/trimage.py | 2 +- website/index.html | 9 +++++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/debian/changelog b/debian/changelog index 8d0ed63..5bc1efa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,6 @@ -trimage (1.1.0b-0ubuntu1) jaunty; urgency=low +trimage (1.0.1b-0ubuntu1) jaunty; urgency=low - * use multiprocessing for images + * use a threadpool for images * more robust file handling * re-adding images now results in recompressing them * compressing message now shows filename diff --git a/setup.py b/setup.py index 21635fa..1c4c014 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name = "trimage", - version = "1.1.0b", + version = "1.0.1b", 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 6f77c4d..5b38142 100755 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -18,7 +18,7 @@ from multiprocessing import cpu_count from ui import Ui_trimage -VERSION = "1.1.0b" +VERSION = "1.0.1b" class StartQT4(QMainWindow): diff --git a/website/index.html b/website/index.html index c636199..23807d6 100644 --- a/website/index.html +++ b/website/index.html @@ -69,7 +69,7 @@
    -

    Trimage image compressor – 1.1.0b (beta)

    +

    Trimage image compressor – 1.0.1b (beta)

    A cross-platform tool for losslessly optimizing PNG and JPG files.

    Trimage is a cross-platform GUI and command-line interface to optimize image files via optipng, @@ -165,12 +165,17 @@

    Planned features

    -

    Version 1.1.0 final:

    +

    Version 1.0.0 final:

    • Expand command line options
    • Make sure a compressed file is always smaller than the original one, or don't compress
    • General refactoring
    +

    Version 1.1.0 final:

    +
      +
    • Use multiprocessing
    • +
    +

    Beyond that

    • Deletion of rows in the table view
    • From 773efc687012b44b28fe9dd0cd37f168bf285133 Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Wed, 21 Apr 2010 13:28:52 +0200 Subject: [PATCH 06/10] implement a system tray with basic functionality --- src/trimage/trimage.py | 39 +++++++++++++++++++++++++++++++++++++++ src/trimage/ui.py | 4 +++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/trimage/trimage.py b/src/trimage/trimage.py index 814de4c..a84e270 100644 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -28,6 +28,8 @@ class StartQT4(QMainWindow): self.ui = Ui_trimage() self.ui.setupUi(self) + self.systemtray = Systray(self) + self.showapp = True self.verbose = True self.imagelist = [] @@ -420,6 +422,43 @@ class Worker(QThread): else: print >> sys.stderr, u"[error] %s could not be compressed" % image.fullpath + +class Systray(QWidget): + def __init__(self, parent): + QWidget.__init__(self) + self.parent = parent + self.createActions() + self.createTrayIcon() + self.trayIcon.show() + + def createActions(self): + self.quitAction = QAction(self.tr("&Quit"), self) + QObject.connect(self.quitAction, SIGNAL("triggered()"), + qApp, SLOT("quit()")) + + self.addFiles = QAction(self.tr("&Add and compress"), self) + icon = QIcon() + icon.addPixmap(QPixmap(self.parent.ui.get_image(("pixmaps/list-add.png"))), QIcon.Normal, QIcon.Off) + self.addFiles.setIcon(icon) + QObject.connect(self.addFiles, SIGNAL("triggered()"), self.parent.file_dialog) + + self.recompress = QAction(self.tr("&Recompress"), self) + icon2 = QIcon() + icon2.addPixmap(QPixmap(self.parent.ui.get_image(("pixmaps/view-refresh.png"))), QIcon.Normal, QIcon.Off) + self.recompress.setIcon(icon2) + QObject.connect(self.addFiles, SIGNAL("triggered()"), self.parent.recompress_files) + + def createTrayIcon(self): + self.trayIconMenu = QMenu(self) + self.trayIconMenu.addAction(self.addFiles) + self.trayIconMenu.addAction(self.recompress) + self.trayIconMenu.addAction(self.quitAction) + + self.trayIcon = QSystemTrayIcon(self) + self.trayIcon.setContextMenu(self.trayIconMenu) + self.trayIcon.setIcon(QIcon(self.parent.ui.get_image("pixmaps/trimage-icon.png"))) + + if __name__ == "__main__": app = QApplication(sys.argv) myapp = StartQT4() diff --git a/src/trimage/ui.py b/src/trimage/ui.py index 86caee8..47937da 100644 --- a/src/trimage/ui.py +++ b/src/trimage/ui.py @@ -36,7 +36,9 @@ class Ui_trimage(object): """ Setup the entire UI """ trimage.setObjectName("trimage") trimage.resize(600, 170) - trimage.setWindowIcon(QIcon(self.get_image("pixmaps/trimage-icon.png"))) + + trimageIcon = QIcon(self.get_image("pixmaps/trimage-icon.png")) + trimage.setWindowIcon(trimageIcon) self.centralwidget = QWidget(trimage) self.centralwidget.setObjectName("centralwidget") From ba0bb856d2e0dc64817cf09c2baaa88da2435993 Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Wed, 21 Apr 2010 14:05:53 +0200 Subject: [PATCH 07/10] disable recompress systray button --- src/trimage/trimage.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/trimage/trimage.py b/src/trimage/trimage.py index a84e270..f51ee53 100644 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -209,6 +209,7 @@ class StartQT4(QMainWindow): def enable_recompress(self): """Enable the recompress button.""" self.ui.recompress.setEnabled(True) + self.systemtray.recompress.setEnabled(True) def checkapps(self): """Check if the required command line apps exist.""" @@ -424,6 +425,7 @@ class Worker(QThread): class Systray(QWidget): + def __init__(self, parent): QWidget.__init__(self) self.parent = parent @@ -438,14 +440,17 @@ class Systray(QWidget): self.addFiles = QAction(self.tr("&Add and compress"), self) icon = QIcon() - icon.addPixmap(QPixmap(self.parent.ui.get_image(("pixmaps/list-add.png"))), QIcon.Normal, QIcon.Off) + icon.addPixmap(QPixmap(self.parent.ui.get_image(("pixmaps/list-add.png"))), + QIcon.Normal, QIcon.Off) self.addFiles.setIcon(icon) QObject.connect(self.addFiles, SIGNAL("triggered()"), self.parent.file_dialog) self.recompress = QAction(self.tr("&Recompress"), self) icon2 = QIcon() - icon2.addPixmap(QPixmap(self.parent.ui.get_image(("pixmaps/view-refresh.png"))), QIcon.Normal, QIcon.Off) + icon2.addPixmap(QPixmap(self.parent.ui.get_image(("pixmaps/view-refresh.png"))), + QIcon.Normal, QIcon.Off) self.recompress.setIcon(icon2) + self.recompress.setDisabled(True) QObject.connect(self.addFiles, SIGNAL("triggered()"), self.parent.recompress_files) def createTrayIcon(self): @@ -454,9 +459,10 @@ class Systray(QWidget): self.trayIconMenu.addAction(self.recompress) self.trayIconMenu.addAction(self.quitAction) - self.trayIcon = QSystemTrayIcon(self) - self.trayIcon.setContextMenu(self.trayIconMenu) - self.trayIcon.setIcon(QIcon(self.parent.ui.get_image("pixmaps/trimage-icon.png"))) + if QSystemTrayIcon.isSystemTrayAvailable(): + self.trayIcon = QSystemTrayIcon(self) + self.trayIcon.setContextMenu(self.trayIconMenu) + self.trayIcon.setIcon(QIcon(self.parent.ui.get_image("pixmaps/trimage-icon.png"))) if __name__ == "__main__": From a0edd4f0036ed0648cc29d0b95f67da9acb4ad66 Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Wed, 21 Apr 2010 17:23:44 +0200 Subject: [PATCH 08/10] implement a show/hide function in the systray menu --- src/trimage/trimage.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/trimage/trimage.py b/src/trimage/trimage.py index f51ee53..5dd6fef 100644 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -242,6 +242,13 @@ class StartQT4(QMainWindow): else: raise + def hide_main_window(self): + if self.isVisible(): + self.hide() + self.systemtray.hideMain.setText("&Show window") + else: + self.show() + self.systemtray.hideMain.setText("&Hide window") class TriTableModel(QAbstractTableModel): @@ -453,10 +460,14 @@ class Systray(QWidget): self.recompress.setDisabled(True) QObject.connect(self.addFiles, SIGNAL("triggered()"), self.parent.recompress_files) + self.hideMain = QAction(self.tr("&Hide window"), self) + QObject.connect(self.hideMain, SIGNAL("triggered()"), self.parent.hide_main_window) + def createTrayIcon(self): self.trayIconMenu = QMenu(self) self.trayIconMenu.addAction(self.addFiles) self.trayIconMenu.addAction(self.recompress) + self.trayIconMenu.addAction(self.hideMain) self.trayIconMenu.addAction(self.quitAction) if QSystemTrayIcon.isSystemTrayAvailable(): From 7e8a0b7cd6ef8396b55c46e94ae2cbe333662a90 Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Wed, 21 Apr 2010 17:31:08 +0200 Subject: [PATCH 09/10] add systray tooltip --- src/trimage/trimage.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/trimage/trimage.py b/src/trimage/trimage.py index 5dd6fef..20a1322 100644 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -473,6 +473,7 @@ class Systray(QWidget): if QSystemTrayIcon.isSystemTrayAvailable(): self.trayIcon = QSystemTrayIcon(self) self.trayIcon.setContextMenu(self.trayIconMenu) + self.trayIcon.setToolTip("Trimage image compressor") self.trayIcon.setIcon(QIcon(self.parent.ui.get_image("pixmaps/trimage-icon.png"))) From 8a89a44c9e574ee9cfb2bfba7a6990caacbc0d20 Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Wed, 21 Apr 2010 17:49:14 +0200 Subject: [PATCH 10/10] get directory ready for settings --- src/trimage/trimage.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/trimage/trimage.py b/src/trimage/trimage.py index 20a1322..7e24db1 100644 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -128,9 +128,11 @@ class StartQT4(QMainWindow): def file_dialog(self): """Open a file dialog and send the selected images to compress_file.""" fd = QFileDialog(self) + directory = "" + images = fd.getOpenFileNames(self, "Select one or more image files to compress", - "", # directory + directory, # this is a fix for file dialog differentiating between cases "Image files (*.png *.jpg *.jpeg *.PNG *.JPG *.JPEG)")