diff --git a/dialog-warning.png b/dialog-warning.png index 704f1d7..3951521 100644 Binary files a/dialog-warning.png and b/dialog-warning.png differ diff --git a/todo b/todo index 35a0c47..b0918ee 100644 --- a/todo +++ b/todo @@ -25,7 +25,8 @@ optipng for png and gif, jpegoptim for jpeg. both are available in ubuntu as dep todo app wise - implement threading - errors need to go to standarderror -- make icon +- add file icon to table view +- hide jpegoptim from commandline todo else - figure out dependencies for a .deb/how to make a .deb diff --git a/trimage-icon.png b/trimage-icon.png index d478605..1ae7492 100644 Binary files a/trimage-icon.png and b/trimage-icon.png differ diff --git a/trimage.py b/trimage.py index ef32948..550c38d 100644 --- a/trimage.py +++ b/trimage.py @@ -2,6 +2,7 @@ import sys from os import system from os import listdir from os import path +from subprocess import * from PyQt4.QtCore import * from PyQt4.QtGui import * from hurry.filesize import * @@ -49,9 +50,9 @@ class StartQT4(QMainWindow): description="GUI front-end to compress png and jpg images via " "optipng, advpng and jpegoptim") parser.add_option("-f", "--file", action="store", type="string", - dest="filename", help="image to compress") + dest="filename", help="compresses image and exit") parser.add_option("-d", "--directory", action="store", type="string", - dest="directory", help="directory of images to compress", ) + dest="directory", help="compresses images in directory and exit", ) options, args = parser.parse_args() @@ -124,19 +125,26 @@ class StartQT4(QMainWindow): #decide with tool to use if path.splitext(str(filename))[1].lower() in [".jpg", ".jpeg"]: - runstr = 'jpegoptim --strip-all -f -q"' + str(filename) + '"' - runfile = system(runstr) - + runstr = 'jpegoptim -f --strip-all "' + str(filename) + '"' + try: + retcode = call(runstr, shell=True, stdout=PIPE) + runfile = retcode + except OSError, e: + runfile = e elif path.splitext(str(filename))[1].lower() in [".png"]: - # don't do advpng yet - runstr = ('optipng -q -force -o7 "' + str(filename) - + '"; advpng -z4 -q "' + str(filename) + '"') - #runstr = 'optipng -force -o7 "' + str(filename) + '"' - runfile = system(runstr) + runstr = ('optipng -force -o7 "' + str(filename) + + '"; advpng -z4 "' + str(filename) + '"') + try: + retcode = call(runstr, shell=True, stdout=PIPE) + runfile = retcode + except OSError, e: + runfile = e if runfile == 0: #gather new file data newfile = QFile(filename) + provider = QFileIconProvider() + newfileicon = provider.icon(QFileInfo(filename)) newfilesize = newfile.size() newfilesizestr = size(newfilesize, system=alternative) @@ -146,9 +154,15 @@ class StartQT4(QMainWindow): # append current image to list self.imagelist.append( - (name, oldfilesizestr, newfilesizestr, ratiostr, filename)) + (newfileicon, name, oldfilesizestr, newfilesizestr, ratiostr, + filename)) self.update_table() + if self.showapp != True: + # we work via the commandline + print("File:" + filename + ", Old Size:" + oldfilesizestr + + ", New Size:" + newfilesizestr + ", Ratio:" + ratiostr) + else: # TODO nice error recovery print("uh. not good") @@ -159,7 +173,7 @@ class StartQT4(QMainWindow): # set table model tmodel = TriTableModel(self, self.imagelist, - ["Filename", "Old Size", "New Size", "Compressed"]) + ["", "Filename", "Old Size", "New Size", "Compressed"]) tview.setModel(tmodel) # set minimum size of table @@ -175,8 +189,9 @@ class StartQT4(QMainWindow): for row in range(nrows): tview.setRowHeight(row, 25) - # set the first column to be longest - tview.setColumnWidth(0, 300) + # set the second column to be longest + tview.setColumnWidth(0, 30) + tview.setColumnWidth(1, 280) # enable recompress button self.enable_recompress()