mirror of
https://github.com/Kilian/Trimage.git
synced 2026-01-26 01:58:41 -05:00
implement optipng, fix recompressing
This commit is contained in:
parent
e1972f814f
commit
b02d6e0aa6
4 changed files with 54 additions and 11 deletions
24
todo
24
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
|
||||
|
||||
|
|
|
|||
31
trimage.py
31
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,30 +43,43 @@ 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"
|
||||
else:
|
||||
print "run optipng"
|
||||
runfile = system('ls')
|
||||
|
||||
newfile = oldfile # for now ;)
|
||||
elif name.endsWith("png"):
|
||||
runstr = 'optipng -force "' + str(filename) + '"'
|
||||
runfile = system(runstr)
|
||||
|
||||
else:
|
||||
print "run something for gif"
|
||||
runfile = system('ls')
|
||||
|
||||
|
||||
if runfile == 0:
|
||||
newfile = QFile(filename)
|
||||
newfilesize = newfile.size()
|
||||
newfilesizestr = size(newfilesize, system=alternative)
|
||||
|
||||
ratio = 100 - (newfilesize / oldfilesize * 100)
|
||||
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):
|
||||
tview = self.ui.processedfiles
|
||||
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
|||
2
ui.py
2
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)
|
||||
|
|
|
|||
BIN
ui.pyc
BIN
ui.pyc
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue