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 6fed7e4..0152f5e 100644 Binary files a/ui.pyc and b/ui.pyc differ