show a compressing message in table while image is compressing TODO: add a better image

This commit is contained in:
Kilian Valkhof 2010-02-04 13:06:42 +01:00
parent 0e928e496b
commit e0453ca056
3 changed files with 26 additions and 15 deletions

4
todo
View file

@ -1,7 +1,8 @@
========================================== ==========================================
todo app wise todo app wise
- implement threading => http://diotavelli.net/PyQtWiki/Threading,_Signals_and_Slots
- errors need to go to standarderror - errors need to go to standarderror
- fix command line options
- give a visual when thread is working
todo else todo else
- figure out dependencies for a .deb/how to make a .deb - figure out dependencies for a .deb/how to make a .deb
@ -19,6 +20,7 @@ advancecomp 1.15
=========================================== ===========================================
later versions: later versions:
allow selection/deletion of rows from table (and subsequently the imagelist) allow selection/deletion of rows from table (and subsequently the imagelist)
check for double files
pnypng api? http://www.gracepointafterfive.com/punypng/api pnypng api? http://www.gracepointafterfive.com/punypng/api
imagemagick/graphicmagick? imagemagick/graphicmagick?

View file

@ -11,7 +11,7 @@ from hurry.filesize import *
from ui import Ui_trimage from ui import Ui_trimage
VERSION = "1.0"
DEBUG = True DEBUG = True
#init imagelist #init imagelist
@ -32,8 +32,6 @@ class StartQT4(QMainWindow):
# disable recompress # disable recompress
self.ui.recompress.setEnabled(False) self.ui.recompress.setEnabled(False)
# activate command line options # activate command line options
self.commandline_options() self.commandline_options()
@ -55,7 +53,7 @@ class StartQT4(QMainWindow):
def commandline_options(self): def commandline_options(self):
"""Set up the command line options.""" """Set up the command line options."""
parser = OptionParser(version="%prog 1.0", parser = OptionParser(version="%prog " + VERSION,
description="GUI front-end to compress png and jpg images via " description="GUI front-end to compress png and jpg images via "
"optipng, advpng and jpegoptim") "optipng, advpng and jpegoptim")
parser.add_option("-f", "--file", action="store", type="string", parser.add_option("-f", "--file", action="store", type="string",
@ -78,22 +76,23 @@ class StartQT4(QMainWindow):
compress_file.""" compress_file."""
showapp = False showapp = False
imagedir = listdir(directory) imagedir = listdir(directory)
filelist = QStringList()
for image in imagedir: for image in imagedir:
image = path.join(directory, image) image = path.join(directory, image)
self.delegator(imagedir) filelist.append(image)
self.delegator(filelist)
def file_from_cmd(self, image): def file_from_cmd(self, image):
"""Get the file and send it to compress_file""" """Get the file and send it to compress_file"""
showapp = False showapp = False
filecmdlist = [] filecmdlist = QStringList()
filecmdlist.append(image) filecmdlist.append(image)
self.delegator(filecmdlist) self.delegator(filecmdlist)
def file_drop(self, image): def file_drop(self, images):
"""Get a file from the drag and drop handler and send it to """Get a file from the drag and drop handler and send it to
compress_file.""" compress_file."""
if self.checkname(image): self.delegator(images)
self.delegator(image)
def file_dialog(self): def file_dialog(self):
"""Open a file dialog and send the selected images to compress_file.""" """Open a file dialog and send the selected images to compress_file."""
@ -105,11 +104,17 @@ class StartQT4(QMainWindow):
"Image files (*.png *.jpg *.jpeg *.PNG *.JPG *.JPEG)") "Image files (*.png *.jpg *.jpeg *.PNG *.JPG *.JPEG)")
self.delegator(images) self.delegator(images)
def recompress_files(self): def recompress_files(self):
"""Send each file in the current file list to compress_file again.""" """Send each file in the current file list to compress_file again."""
self.delegator(imagelist) newimagelist = []
for image in imagelist:
newimagelist.append(image[4])
for i, image in enumerate(imagelist):
imagelist.remove(image)
self.delegator(newimagelist)
""" """
Compress functions Compress functions
""" """
@ -118,6 +123,7 @@ class StartQT4(QMainWindow):
for image in images: for image in images:
if self.checkname(image): if self.checkname(image):
delegatorlist.append((image, QIcon(image))) delegatorlist.append((image, QIcon(image)))
imagelist.append(("Compressing...", "", "", "", image, QIcon(QPixmap("view-refresh.png"))))
self.thread.compress_file(delegatorlist) self.thread.compress_file(delegatorlist)
""" """
@ -258,7 +264,11 @@ class Worker(QThread):
ratiostr = "%.1f%%" % ratio ratiostr = "%.1f%%" % ratio
# append current image to list # append current image to list
imagelist.append((name, oldfilesizestr, newfilesizestr, ratiostr, for i, image in enumerate(imagelist):
print(image[4], filename)
if image[4] == filename:
imagelist.remove(image)
imagelist.insert(i, (name, oldfilesizestr, newfilesizestr, ratiostr,
filename, icon)) filename, icon))
self.emit(SIGNAL("updateUi")) self.emit(SIGNAL("updateUi"))

3
ui.py
View file

@ -28,8 +28,7 @@ class TrimageTableView(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()
for file in files: self.emit(SIGNAL("fileDropEvent"), (files))
self.emit(SIGNAL("fileDropEvent"), (file))
class Ui_trimage(object): class Ui_trimage(object):