mirror of
https://github.com/Kilian/Trimage.git
synced 2026-01-26 01:58:41 -05:00
All merge conflicts resolved. Code is a step closer to PEP-8.
This commit is contained in:
parent
ed52fde42d
commit
c4f2f4186c
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
|
||||
QObject.connect(self.ui.addfiles, SIGNAL("clicked()"),
|
||||
self.file_dialog)
|
||||
self.file_dialog)
|
||||
QObject.connect(self.ui.recompress, SIGNAL("clicked()"),
|
||||
self.recompress_files)
|
||||
self.recompress_files)
|
||||
QObject.connect(self.quit_shortcut, SIGNAL("activated()"),
|
||||
qApp, SLOT('quit()'))
|
||||
qApp, SLOT('quit()'))
|
||||
|
||||
parser = OptionParser(version="%prog 1.0",
|
||||
description="GUI front-end to compress png and jpg images via "
|
||||
"optipng and jpegoptim")
|
||||
"optipng and jpegoptim")
|
||||
|
||||
parser.add_option("-f", "--file",
|
||||
action="store", type="string", dest="filename",
|
||||
help="image to compress")
|
||||
parser.add_option("-f", "--file", action="store", type="string",
|
||||
dest="filename", help="image to compress")
|
||||
|
||||
parser.add_option("-d", "--directory",
|
||||
action="store", type="string", dest="directory",
|
||||
help="directory of images to compress")
|
||||
parser.add_option("-d", "--directory", action="store", type="string",
|
||||
dest="directory", help="directory of images to compress")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
options, args = parser.parse_args()
|
||||
|
||||
if options.filename:
|
||||
self.file_from_cmd(options.filename)
|
||||
|
|
@ -67,7 +65,7 @@ class StartQT4(QMainWindow):
|
|||
self.compress_file(image)
|
||||
|
||||
def file_drop(self):
|
||||
print "booya"
|
||||
print("booya")
|
||||
|
||||
def checkname(self, filename):
|
||||
if filename.endsWith("png") or filename.endsWith("jpg"):
|
||||
|
|
@ -76,9 +74,9 @@ class StartQT4(QMainWindow):
|
|||
def file_dialog(self):
|
||||
fd = QFileDialog(self)
|
||||
images = fd.getOpenFileNames(self,
|
||||
"Select one or more image files to compress",
|
||||
"", # directory
|
||||
"Image files (*.png *.jpg)")
|
||||
"Select one or more image files to compress",
|
||||
"", # directory
|
||||
"Image files (*.png *.jpg)")
|
||||
for image in images:
|
||||
if self.checkname(name):
|
||||
self.compress_file(image)
|
||||
|
|
@ -93,7 +91,7 @@ class StartQT4(QMainWindow):
|
|||
self.compress_file(image[-1])
|
||||
|
||||
def compress_file(self, filename):
|
||||
print filename
|
||||
print(filename)
|
||||
oldfile = QFileInfo(filename)
|
||||
name = oldfile.fileName()
|
||||
oldfilesize = oldfile.size()
|
||||
|
|
@ -122,14 +120,14 @@ class StartQT4(QMainWindow):
|
|||
self.update_table()
|
||||
|
||||
else:
|
||||
print "uh. not good" #throw dialogbox error or something?
|
||||
print("uh. not good") #throw dialogbox error or something?
|
||||
|
||||
def update_table(self):
|
||||
tview = self.ui.processedfiles
|
||||
|
||||
# set table model
|
||||
tmodel = tri_table_model(self, self.imagelist,
|
||||
['Filename', 'Old Size', 'New Size', 'Compressed'])
|
||||
tmodel = TriTableModel(self, self.imagelist,
|
||||
["Filename", "Old Size", "New Size", "Compressed"])
|
||||
tview.setModel(tmodel)
|
||||
|
||||
# set minimum size of table
|
||||
|
|
@ -143,14 +141,12 @@ class StartQT4(QMainWindow):
|
|||
# set all row heights
|
||||
nrows = len(self.imagelist)
|
||||
for row in range(nrows):
|
||||
tview.setRowHeight(row, 25)
|
||||
tview.setRowHeight(row, 25)
|
||||
tview.setColumnWidth(0, 300)
|
||||
#tview.setDragDropMode(QAbstractItemView.DropOnly)
|
||||
#tview.setAcceptDrops(True)
|
||||
self.enable_recompress()
|
||||
|
||||
|
||||
class tri_table_model(QAbstractTableModel):
|
||||
class TriTableModel(QAbstractTableModel):
|
||||
|
||||
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.QtCore import QUrl, QString
|
||||
#import trimage
|
||||
|
||||
|
||||
DEBUG = True
|
||||
|
||||
|
||||
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:
|
||||
if DEBUG:
|
||||
print("Accepting event: %s" % list(event.mimeData().formats()))
|
||||
event.accept()
|
||||
else:
|
||||
if trimage.DEBUG:
|
||||
if DEBUG:
|
||||
print("Rejecting event: %s" % list(event.mimeData().formats()))
|
||||
event.ignore()
|
||||
|
||||
|
|
@ -34,12 +28,13 @@ class TrimageTableView(QtGui.QTableView):
|
|||
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:
|
||||
if DEBUG:
|
||||
for file in files:
|
||||
print("Drop received: %s" % file)
|
||||
|
||||
|
||||
class Ui_trimage(object):
|
||||
|
||||
def setupUi(self, trimage):
|
||||
trimage.setObjectName("trimage")
|
||||
trimage.resize(600, 170)
|
||||
|
|
@ -120,16 +115,12 @@ class Ui_trimage(object):
|
|||
|
||||
self.processedfiles = TrimageTableView(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)
|
||||
self.processedfiles.setMidLineWidth(0)
|
||||
self.processedfiles.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||
self.processedfiles.setTabKeyNavigation(True)
|
||||
# self.processedfiles.setDragEnabled(True)
|
||||
# self.processedfiles.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
|
||||
self.processedfiles.setAlternatingRowColors(True)
|
||||
self.processedfiles.setTextElideMode(QtCore.Qt.ElideRight)
|
||||
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.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))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue