mirror of
https://github.com/Kilian/Trimage.git
synced 2026-01-26 01:58:41 -05:00
Merge branch 'master' of git@host.fluxility.com:optimg
This commit is contained in:
commit
adbdf15fe9
2 changed files with 27 additions and 41 deletions
42
trimage.py
42
trimage.py
|
|
@ -26,25 +26,23 @@ class StartQT4(QMainWindow):
|
||||||
|
|
||||||
# connect signals with slots
|
# connect signals with slots
|
||||||
QObject.connect(self.ui.addfiles, SIGNAL("clicked()"),
|
QObject.connect(self.ui.addfiles, SIGNAL("clicked()"),
|
||||||
self.file_dialog)
|
self.file_dialog)
|
||||||
QObject.connect(self.ui.recompress, SIGNAL("clicked()"),
|
QObject.connect(self.ui.recompress, SIGNAL("clicked()"),
|
||||||
self.recompress_files)
|
self.recompress_files)
|
||||||
QObject.connect(self.quit_shortcut, SIGNAL("activated()"),
|
QObject.connect(self.quit_shortcut, SIGNAL("activated()"),
|
||||||
qApp, SLOT('quit()'))
|
qApp, SLOT('quit()'))
|
||||||
|
|
||||||
parser = OptionParser(version="%prog 1.0",
|
parser = OptionParser(version="%prog 1.0",
|
||||||
description="GUI front-end to compress png and jpg images via "
|
description="GUI front-end to compress png and jpg images via "
|
||||||
"optipng and jpegoptim")
|
"optipng and jpegoptim")
|
||||||
|
|
||||||
parser.add_option("-f", "--file",
|
parser.add_option("-f", "--file", action="store", type="string",
|
||||||
action="store", type="string", dest="filename",
|
dest="filename", help="image to compress")
|
||||||
help="image to compress")
|
|
||||||
|
|
||||||
parser.add_option("-d", "--directory",
|
parser.add_option("-d", "--directory", action="store", type="string",
|
||||||
action="store", type="string", dest="directory",
|
dest="directory", help="directory of images to compress")
|
||||||
help="directory of images to compress")
|
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
if options.filename:
|
if options.filename:
|
||||||
self.file_from_cmd(options.filename)
|
self.file_from_cmd(options.filename)
|
||||||
|
|
@ -67,7 +65,7 @@ class StartQT4(QMainWindow):
|
||||||
self.compress_file(image)
|
self.compress_file(image)
|
||||||
|
|
||||||
def file_drop(self):
|
def file_drop(self):
|
||||||
print "booya"
|
print("booya")
|
||||||
|
|
||||||
def checkname(self, filename):
|
def checkname(self, filename):
|
||||||
if filename.endsWith("png") or filename.endsWith("jpg"):
|
if filename.endsWith("png") or filename.endsWith("jpg"):
|
||||||
|
|
@ -76,9 +74,9 @@ class StartQT4(QMainWindow):
|
||||||
def file_dialog(self):
|
def file_dialog(self):
|
||||||
fd = QFileDialog(self)
|
fd = QFileDialog(self)
|
||||||
images = fd.getOpenFileNames(self,
|
images = fd.getOpenFileNames(self,
|
||||||
"Select one or more image files to compress",
|
"Select one or more image files to compress",
|
||||||
"", # directory
|
"", # directory
|
||||||
"Image files (*.png *.jpg)")
|
"Image files (*.png *.jpg)")
|
||||||
for image in images:
|
for image in images:
|
||||||
if self.checkname(image):
|
if self.checkname(image):
|
||||||
self.compress_file(image)
|
self.compress_file(image)
|
||||||
|
|
@ -93,7 +91,7 @@ class StartQT4(QMainWindow):
|
||||||
self.compress_file(image[-1])
|
self.compress_file(image[-1])
|
||||||
|
|
||||||
def compress_file(self, filename):
|
def compress_file(self, filename):
|
||||||
print filename
|
print(filename)
|
||||||
oldfile = QFileInfo(filename)
|
oldfile = QFileInfo(filename)
|
||||||
name = oldfile.fileName()
|
name = oldfile.fileName()
|
||||||
oldfilesize = oldfile.size()
|
oldfilesize = oldfile.size()
|
||||||
|
|
@ -122,14 +120,14 @@ class StartQT4(QMainWindow):
|
||||||
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, self.imagelist,
|
tmodel = TriTableModel(self, self.imagelist,
|
||||||
['Filename', 'Old Size', 'New Size', 'Compressed'])
|
["Filename", "Old Size", "New Size", "Compressed"])
|
||||||
tview.setModel(tmodel)
|
tview.setModel(tmodel)
|
||||||
|
|
||||||
# set minimum size of table
|
# set minimum size of table
|
||||||
|
|
@ -143,14 +141,12 @@ class StartQT4(QMainWindow):
|
||||||
# set all row heights
|
# set all row heights
|
||||||
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.setAcceptDrops(True)
|
|
||||||
self.enable_recompress()
|
self.enable_recompress()
|
||||||
|
|
||||||
|
|
||||||
class tri_table_model(QAbstractTableModel):
|
class TriTableModel(QAbstractTableModel):
|
||||||
|
|
||||||
def __init__(self, parent, imagelist, header, *args):
|
def __init__(self, parent, imagelist, header, *args):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
26
ui.py
26
ui.py
|
|
@ -1,29 +1,23 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Form implementation generated from reading ui file 'window.ui'
|
|
||||||
#
|
|
||||||
# Created: Mon Feb 1 19:37:17 2010
|
|
||||||
# by: PyQt4 UI code generator 4.4.4
|
|
||||||
#
|
|
||||||
# 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
|
from PyQt4.QtCore import QUrl, QString
|
||||||
#import trimage
|
|
||||||
|
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
|
||||||
class TrimageTableView(QtGui.QTableView):
|
class TrimageTableView(QtGui.QTableView):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(TrimageTableView, self).__init__(parent)
|
super(TrimageTableView, self).__init__(parent)
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
|
|
||||||
def dragEnterEvent(self, event):
|
def dragEnterEvent(self, event):
|
||||||
if event.mimeData().hasFormat("text/uri-list"):
|
if event.mimeData().hasFormat("text/uri-list"):
|
||||||
if trimage.DEBUG:
|
if DEBUG:
|
||||||
print("Accepting event: %s" % list(event.mimeData().formats()))
|
print("Accepting event: %s" % list(event.mimeData().formats()))
|
||||||
event.accept()
|
event.accept()
|
||||||
else:
|
else:
|
||||||
if trimage.DEBUG:
|
if DEBUG:
|
||||||
print("Rejecting event: %s" % list(event.mimeData().formats()))
|
print("Rejecting event: %s" % list(event.mimeData().formats()))
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
|
||||||
|
|
@ -34,12 +28,13 @@ class TrimageTableView(QtGui.QTableView):
|
||||||
files = str(event.mimeData().data("text/uri-list")).strip().split()
|
files = str(event.mimeData().data("text/uri-list")).strip().split()
|
||||||
for i, file in enumerate(files):
|
for i, file in enumerate(files):
|
||||||
files[i] = QUrl(QString(file)).toLocalFile()
|
files[i] = QUrl(QString(file)).toLocalFile()
|
||||||
if trimage.DEBUG:
|
if DEBUG:
|
||||||
for file in files:
|
for file in files:
|
||||||
print("Drop received: %s" % file)
|
print("Drop received: %s" % file)
|
||||||
|
|
||||||
|
|
||||||
class Ui_trimage(object):
|
class Ui_trimage(object):
|
||||||
|
|
||||||
def setupUi(self, trimage):
|
def setupUi(self, trimage):
|
||||||
trimage.setObjectName("trimage")
|
trimage.setObjectName("trimage")
|
||||||
trimage.resize(600, 170)
|
trimage.resize(600, 170)
|
||||||
|
|
@ -120,16 +115,12 @@ class Ui_trimage(object):
|
||||||
|
|
||||||
self.processedfiles = TrimageTableView(self.frame)
|
self.processedfiles = TrimageTableView(self.frame)
|
||||||
self.processedfiles.setEnabled(True)
|
self.processedfiles.setEnabled(True)
|
||||||
# self.processedfiles.setAcceptDrops(True)
|
|
||||||
# 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(True)
|
|
||||||
# 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)
|
||||||
|
|
@ -157,4 +148,3 @@ class Ui_trimage(object):
|
||||||
self.recompress.setShortcut(QtGui.QApplication.translate("trimage", "Alt+R", None, QtGui.QApplication.UnicodeUTF8))
|
self.recompress.setShortcut(QtGui.QApplication.translate("trimage", "Alt+R", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.processedfiles.setToolTip(QtGui.QApplication.translate("trimage", "Drag files in here", None, QtGui.QApplication.UnicodeUTF8))
|
self.processedfiles.setToolTip(QtGui.QApplication.translate("trimage", "Drag files in here", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.processedfiles.setWhatsThis(QtGui.QApplication.translate("trimage", "Drag files in here", None, QtGui.QApplication.UnicodeUTF8))
|
self.processedfiles.setWhatsThis(QtGui.QApplication.translate("trimage", "Drag files in here", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue