mirror of
https://github.com/Kilian/Trimage.git
synced 2026-01-26 10:08:40 -05:00
Tasks can no longer be lost
How to reproduce: - add 2 images - before any of them finishes add 2 more images - some of them will never finish Cli always exits nicely (without ugly sleep)
This commit is contained in:
parent
a89a8a3302
commit
9fafa54f2e
1 changed files with 11 additions and 14 deletions
|
|
@ -12,6 +12,8 @@ from PyQt4.QtGui import *
|
||||||
from hurry.filesize import *
|
from hurry.filesize import *
|
||||||
from imghdr import what as determinetype
|
from imghdr import what as determinetype
|
||||||
|
|
||||||
|
from Queue import Queue
|
||||||
|
|
||||||
from ui import Ui_trimage
|
from ui import Ui_trimage
|
||||||
|
|
||||||
VERSION = "1.0.0b3"
|
VERSION = "1.0.0b3"
|
||||||
|
|
@ -81,6 +83,10 @@ class StartQT4(QMainWindow):
|
||||||
|
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
|
# make sure we quit after processing finished if using cli
|
||||||
|
if options.filename or options.directory:
|
||||||
|
QObject.connect(self.thread, SIGNAL("finished()"), quit)
|
||||||
|
|
||||||
# send to correct function
|
# send to correct function
|
||||||
if options.filename:
|
if options.filename:
|
||||||
self.file_from_cmd(options.filename.decode("utf-8"))
|
self.file_from_cmd(options.filename.decode("utf-8"))
|
||||||
|
|
@ -287,6 +293,7 @@ class Worker(QThread):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QThread.__init__(self, parent)
|
QThread.__init__(self, parent)
|
||||||
self.exiting = False
|
self.exiting = False
|
||||||
|
self.toProcess=Queue()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.exiting = True
|
self.exiting = True
|
||||||
|
|
@ -294,7 +301,8 @@ class Worker(QThread):
|
||||||
|
|
||||||
def compress_file(self, images, showapp, verbose, imagelist):
|
def compress_file(self, images, showapp, verbose, imagelist):
|
||||||
"""Start the worker thread."""
|
"""Start the worker thread."""
|
||||||
self.images = images
|
for image in images:
|
||||||
|
self.toProcess.put(image)
|
||||||
self.showapp = showapp
|
self.showapp = showapp
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
self.imagelist = imagelist
|
self.imagelist = imagelist
|
||||||
|
|
@ -302,10 +310,9 @@ class Worker(QThread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Compress the given file, get data from it and call update_table."""
|
"""Compress the given file, get data from it and call update_table."""
|
||||||
for image in self.images:
|
while self.showapp or not self.toProcess.empty():
|
||||||
#gather old file data
|
#gather old file data
|
||||||
filename = image[0]
|
filename, icon = self.toProcess.get()
|
||||||
icon = image[1]
|
|
||||||
oldfile = QFileInfo(filename)
|
oldfile = QFileInfo(filename)
|
||||||
name = oldfile.fileName()
|
name = oldfile.fileName()
|
||||||
oldfilesize = oldfile.size()
|
oldfilesize = oldfile.size()
|
||||||
|
|
@ -354,16 +361,6 @@ class Worker(QThread):
|
||||||
else:
|
else:
|
||||||
sys.stderr.write("[error] %s" % runfile)
|
sys.stderr.write("[error] %s" % runfile)
|
||||||
|
|
||||||
if not self.showapp:
|
|
||||||
# A little sleep to avoid segfault...
|
|
||||||
# If you pass an empty directory(-d) to trimage,
|
|
||||||
# python segfaults when you call quit here.
|
|
||||||
if len(self.images)==0:
|
|
||||||
import time
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
#make sure the app quits after all images are done
|
|
||||||
quit()
|
|
||||||
|
|
||||||
class TrimageTableView(QTableView):
|
class TrimageTableView(QTableView):
|
||||||
"""Init the table drop event."""
|
"""Init the table drop event."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue