mirror of
https://github.com/Kilian/Trimage.git
synced 2026-01-26 10:08:40 -05:00
Merge branch 'master' of git@host.fluxility.com:optimg
Conflicts: trimage.py
This commit is contained in:
commit
6e1bf4138c
2 changed files with 164 additions and 132 deletions
22
trimage.py
22
trimage.py
|
|
@ -3,12 +3,13 @@ from os import system
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
|
|
||||||
from hurry.filesize import *
|
from hurry.filesize import *
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from ui import Ui_trimage
|
from ui import Ui_trimage
|
||||||
|
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
class StartQT4(QMainWindow):
|
class StartQT4(QMainWindow):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
|
|
@ -85,8 +86,8 @@ class StartQT4(QMainWindow):
|
||||||
for image in imagelistcopy:
|
for image in imagelistcopy:
|
||||||
self.compress_file(image[-1])
|
self.compress_file(image[-1])
|
||||||
|
|
||||||
|
|
||||||
def compress_file(self, filename):
|
def compress_file(self, filename):
|
||||||
|
print filename
|
||||||
oldfile = QFileInfo(filename)
|
oldfile = QFileInfo(filename)
|
||||||
name = oldfile.fileName()
|
name = oldfile.fileName()
|
||||||
oldfilesize = oldfile.size()
|
oldfilesize = oldfile.size()
|
||||||
|
|
@ -97,7 +98,8 @@ class StartQT4(QMainWindow):
|
||||||
runfile = system(runstr)
|
runfile = system(runstr)
|
||||||
|
|
||||||
elif name.endsWith("png"):
|
elif name.endsWith("png"):
|
||||||
#runstr = 'optipng -force -o7 "' + str(filename) + '"; advpng -z4 "' + str(filename) + '"' ## don't do advpng yet
|
#runstr = ('optipng -force -o7 "' + str(filename)
|
||||||
|
#+ '"; advpng -z4 "' + str(filename) + '"') ## don't do advpng yet
|
||||||
runstr = 'optipng -force -o7 "' + str(filename) + '"'
|
runstr = 'optipng -force -o7 "' + str(filename) + '"'
|
||||||
runfile = system(runstr)
|
runfile = system(runstr)
|
||||||
|
|
||||||
|
|
@ -109,19 +111,18 @@ class StartQT4(QMainWindow):
|
||||||
ratio = 100 - (float(newfilesize) / float(oldfilesize) * 100)
|
ratio = 100 - (float(newfilesize) / float(oldfilesize) * 100)
|
||||||
ratiostr = "%.1f%%" % ratio
|
ratiostr = "%.1f%%" % ratio
|
||||||
|
|
||||||
self.imagelist.append((name, oldfilesizestr, newfilesizestr, ratiostr, filename))
|
self.imagelist.append(
|
||||||
|
(name, oldfilesizestr, newfilesizestr, ratiostr, filename))
|
||||||
self.update_table()
|
self.update_table()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "uh. not good" #throw dialogbox error or something?
|
print "uh. not good" #throw dialogbox error or something?
|
||||||
|
|
||||||
|
|
||||||
def update_table(self):
|
def update_table(self):
|
||||||
tview = self.ui.processedfiles
|
tview = self.ui.processedfiles
|
||||||
|
|
||||||
# set table model
|
# set table model
|
||||||
tmodel = tri_table_model(self,
|
tmodel = tri_table_model(self, self.imagelist,
|
||||||
self.imagelist,
|
|
||||||
['Filename', 'Old Size', 'New Size', 'Compressed'])
|
['Filename', 'Old Size', 'New Size', 'Compressed'])
|
||||||
tview.setModel(tmodel)
|
tview.setModel(tmodel)
|
||||||
|
|
||||||
|
|
@ -137,13 +138,14 @@ class StartQT4(QMainWindow):
|
||||||
nrows = len(self.imagelist)
|
nrows = len(self.imagelist)
|
||||||
for row in range(nrows):
|
for row in range(nrows):
|
||||||
tview.setRowHeight(row, 25)
|
tview.setRowHeight(row, 25)
|
||||||
tview.setColumnWidth(0,300)
|
tview.setColumnWidth(0, 300)
|
||||||
tview.setDragDropMode(QAbstractItemView.DropOnly)
|
#tview.setDragDropMode(QAbstractItemView.DropOnly)
|
||||||
tview.setAcceptDrops(True)
|
#tview.setAcceptDrops(True)
|
||||||
self.enable_recompress()
|
self.enable_recompress()
|
||||||
|
|
||||||
|
|
||||||
class tri_table_model(QAbstractTableModel):
|
class tri_table_model(QAbstractTableModel):
|
||||||
|
|
||||||
def __init__(self, parent, imagelist, header, *args):
|
def __init__(self, parent, imagelist, header, *args):
|
||||||
"""
|
"""
|
||||||
mydata is list of tuples
|
mydata is list of tuples
|
||||||
|
|
|
||||||
40
ui.py
40
ui.py
|
|
@ -8,6 +8,36 @@
|
||||||
# WARNING! All changes made in this file will be lost!
|
# WARNING! All changes made in this file will be lost!
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
from PyQt4.QtCore import QUrl, QString
|
||||||
|
import trimage
|
||||||
|
|
||||||
|
|
||||||
|
class TrimageTableView(QtGui.QTableView):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(TrimageTableView, self).__init__(parent)
|
||||||
|
self.setAcceptDrops(True)
|
||||||
|
|
||||||
|
def dragEnterEvent(self, event):
|
||||||
|
if event.mimeData().hasFormat("text/uri-list"):
|
||||||
|
if trimage.DEBUG:
|
||||||
|
print("Accepting event: %s" % list(event.mimeData().formats()))
|
||||||
|
event.accept()
|
||||||
|
else:
|
||||||
|
if trimage.DEBUG:
|
||||||
|
print("Rejecting event: %s" % list(event.mimeData().formats()))
|
||||||
|
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()
|
||||||
|
if trimage.DEBUG:
|
||||||
|
for file in files:
|
||||||
|
print("Drop received: %s" % file)
|
||||||
|
|
||||||
|
|
||||||
class Ui_trimage(object):
|
class Ui_trimage(object):
|
||||||
def setupUi(self, trimage):
|
def setupUi(self, trimage):
|
||||||
|
|
@ -88,18 +118,18 @@ class Ui_trimage(object):
|
||||||
self.horizontalLayout.addWidget(self.recompress)
|
self.horizontalLayout.addWidget(self.recompress)
|
||||||
self.verticalLayout_2.addLayout(self.horizontalLayout)
|
self.verticalLayout_2.addLayout(self.horizontalLayout)
|
||||||
|
|
||||||
self.processedfiles = QtGui.QTableView(self.frame)
|
self.processedfiles = TrimageTableView(self.frame)
|
||||||
self.processedfiles.setEnabled(True)
|
self.processedfiles.setEnabled(True)
|
||||||
self.processedfiles.setAcceptDrops(True)
|
# self.processedfiles.setAcceptDrops(True)
|
||||||
self.processedfiles.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
|
# self.processedfiles.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
|
||||||
self.processedfiles.setFrameShape(QtGui.QFrame.NoFrame)
|
self.processedfiles.setFrameShape(QtGui.QFrame.NoFrame)
|
||||||
self.processedfiles.setFrameShadow(QtGui.QFrame.Plain)
|
self.processedfiles.setFrameShadow(QtGui.QFrame.Plain)
|
||||||
self.processedfiles.setLineWidth(0)
|
self.processedfiles.setLineWidth(0)
|
||||||
self.processedfiles.setMidLineWidth(0)
|
self.processedfiles.setMidLineWidth(0)
|
||||||
self.processedfiles.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
self.processedfiles.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||||
self.processedfiles.setTabKeyNavigation(True)
|
self.processedfiles.setTabKeyNavigation(True)
|
||||||
self.processedfiles.setDragEnabled(False)
|
# self.processedfiles.setDragEnabled(True)
|
||||||
self.processedfiles.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
|
# self.processedfiles.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
|
||||||
self.processedfiles.setAlternatingRowColors(True)
|
self.processedfiles.setAlternatingRowColors(True)
|
||||||
self.processedfiles.setTextElideMode(QtCore.Qt.ElideRight)
|
self.processedfiles.setTextElideMode(QtCore.Qt.ElideRight)
|
||||||
self.processedfiles.setShowGrid(True)
|
self.processedfiles.setShowGrid(True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue