From b02d6e0aa61aa90cc4a4999e9d18c1ad83e6e32d Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Tue, 2 Feb 2010 00:33:35 +0100 Subject: [PATCH] implement optipng, fix recompressing --- todo | 24 ++++++++++++++++++++++++ trimage.py | 39 ++++++++++++++++++++++++++++----------- ui.py | 2 ++ ui.pyc | Bin 4815 -> 4857 bytes 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/todo b/todo index 350416d..98d4f15 100644 --- a/todo +++ b/todo @@ -19,3 +19,27 @@ trimage: simple gui for: optipng for png and gif, jpegoptim for jpeg. both are available in ubuntu as dependencies (our primary platform) + +========================================== +todo app wise +- implement jpegoptim +- implement something for gifs +- implement drag and drop on table +- clean up code, make it PEP-8 +- figure out what to do with: + - recompress and optipng ( −o7? ) not really doing anything + - lockup when opening files (i'd like it to not lock up the file dialog) + +todo else +- figure out dependencies for a .deb/how to make a .deb +- figure out launchpad repo or something +- figure out how to make mac and win versions + +current dependencies: +python +python-qt4 +hurry.filesize (bundled) + +optipng +jpgegoptim + diff --git a/trimage.py b/trimage.py index 3143e30..7bb19ed 100644 --- a/trimage.py +++ b/trimage.py @@ -1,4 +1,5 @@ import sys +from os import system from PyQt4.QtCore import * from PyQt4.QtGui import * @@ -14,14 +15,16 @@ class StartQT4(QMainWindow): self.quit_shortcut = QShortcut(QKeySequence("Ctrl+Q"), self); # todo use standardKey Quit. # set recompress to false self.ui.recompress.setEnabled(False) - self.imagelist = [] # connect signals with slots QObject.connect(self.ui.addfiles, SIGNAL("clicked()"), self.file_dialog) QObject.connect(self.ui.recompress, SIGNAL("clicked()"), self.recompress_files) QObject.connect(self.quit_shortcut, SIGNAL("activated()"), qApp, SLOT('quit()')) + QObject.connect(self.ui.processedfiles, SIGNAL("dragEnterEvent()"), self.file_drop) + def file_drop(self): + print "booya" def file_dialog(self): fd = QFileDialog(self) @@ -40,29 +43,42 @@ class StartQT4(QMainWindow): def recompress_files(self): newimage = self.imagelist self.imagelist = [] - for image in self.imagelist: + for image in newimage: self.compress_file(image[-1]) def compress_file(self, filename): + print filename oldfile = QFileInfo(filename); name = oldfile.fileName() oldfilesize = oldfile.size() if name.endsWith("jpg"): print "run jpegoptim" + runfile = system('ls') + + elif name.endsWith("png"): + runstr = 'optipng -force "' + str(filename) + '"' + runfile = system(runstr) + else: - print "run optipng" + print "run something for gif" + runfile = system('ls') - newfile = oldfile # for now ;) - newfilesize = newfile.size() - newfilesizestr = size(newfilesize, system=alternative) - ratio = 100 - (newfilesize / oldfilesize * 100) - ratiostr = "%.1f%%" % ratio + if runfile == 0: + newfile = QFile(filename) + newfilesize = newfile.size() + newfilesizestr = size(newfilesize, system=alternative) - self.imagelist.append((name, newfilesizestr, ratiostr, filename)) - self.update_table() + ratio = 100 - (float(newfilesize) / float(oldfilesize) * 100) + ratiostr = "%.1f%%" % ratio + + self.imagelist.append((name, newfilesizestr, ratiostr, filename)) + self.update_table() + + else: + print "uh. not good" #implement, something went wrong def update_table(self): @@ -87,7 +103,8 @@ class StartQT4(QMainWindow): for row in range(nrows): tview.setRowHeight(row, 25) tview.setColumnWidth(0,400) - + tview.setDragDropMode(QAbstractItemView.DropOnly) + tview.setAcceptDrops(True) self.enable_recompress() diff --git a/ui.py b/ui.py index bede175..198ab61 100644 --- a/ui.py +++ b/ui.py @@ -58,6 +58,7 @@ class Ui_trimage(object): icon.addPixmap(QtGui.QPixmap("list-add.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.addfiles.setIcon(icon) self.addfiles.setObjectName("addfiles") + self.addfiles.setAcceptDrops(True) self.horizontalLayout.addWidget(self.addfiles) self.label = QtGui.QLabel(self.frame) @@ -90,6 +91,7 @@ class Ui_trimage(object): self.processedfiles = QtGui.QTableView(self.frame) self.processedfiles.setEnabled(True) self.processedfiles.setAcceptDrops(True) + self.processedfiles.setDragDropMode(QtGui.QAbstractItemView.DropOnly) self.processedfiles.setFrameShape(QtGui.QFrame.NoFrame) self.processedfiles.setFrameShadow(QtGui.QFrame.Plain) self.processedfiles.setLineWidth(0) diff --git a/ui.pyc b/ui.pyc index 6fed7e48835ae0945a8f618b396991a2522cc54a..0152f5e952700705a5e58b5a9376959a9eb5f6a3 100644 GIT binary patch delta 861 zcmX@F`cswd;wN4%j?js0hZxg0p4`P`EW?ng#Zbb{(9FodSi``ODaDYf%>ZJ^fQ3q! z7&3Lhd~p!JhJhhocXA<%$mCtjT=lvPneq%Z%peJ{UR{PvJqC~tF@{WiWKnj86n133 z0YeH8GM|AVMF`G^yFeE#1TxQ%Aw`%WMFea%4@0IAgrUcfY0S{f!cfZ!cAykPrU^q0 zD_oN_SQPGT)5(P_a)PF4PBxvqfW@=klp#}-p@t2t736nQhDd^$O!Tz&h$g~BU1#*!UL#7>A zRE#0h9$6GifLk$SIxwU_0s^Yn5smM}P@>3?sl<@!3^J=89D7y_nJ#D!aYYUUD~3$$ z4s%1(>*UNBYO4E3*C z7&86gHc7zJuN7QK6eff)hz%yh2@06a=h>2(h4>g47>ZL%9Fvn%3rbvy@(YS58*&|* uyoTF+G8^}@&5yaKF*0tMT*Vta`82Q1W>&s^%#7uej|fg+%$gi3R0RNPe5jTH delta 813 zcmeyVdR~?7;wN4%Z~uvGhZr3a?zp7kaSnVJkWY+$V*kC-rInlhA_A@dm+QpDhVxD!p_LJ|y_=3on@ zz(OEbTY&j+2Uvo+mJFF(3?a2fv}DL+U`PRn6*wtbGGzKPG&3;3IDRnq_`}VRfTdJRxR5AJ2w@N# zL#Ec|*KE1Wle4)F3h^;8FchbjI3_2j7L>RYp2$*^qA!Gh^xGcY+fbGbYyyRRI9Y;h@X_