mirror of
https://github.com/ciromattia/kcc
synced 2026-06-04 05:33:30 +00:00
Added progress bar
This commit is contained in:
@@ -504,10 +504,6 @@
|
|||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<zorder>GammaLabel</zorder>
|
|
||||||
<zorder>GammaSlider</zorder>
|
|
||||||
<zorder>OptionsExpert</zorder>
|
|
||||||
<zorder>OptionsExpert</zorder>
|
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QFrame" name="OptionsExpert">
|
<widget class="QFrame" name="OptionsExpert">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@@ -585,6 +581,22 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QProgressBar" name="ProgressBar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>401</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="textVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="ActionBasic">
|
<action name="ActionBasic">
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ import sys
|
|||||||
import os
|
import os
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
from kcc import KCC_gui, KCC_ui
|
from kcc import KCC_gui, KCC_ui
|
||||||
|
from multiprocessing import freeze_support
|
||||||
|
|
||||||
|
freeze_support()
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
os.environ['PATH'] = '/usr/local/bin:' + os.environ['PATH']
|
os.environ['PATH'] = '/usr/local/bin:' + os.environ['PATH']
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
|
|||||||
+20
-9
@@ -43,13 +43,6 @@ class WorkerThread(QtCore.QThread):
|
|||||||
self.wait()
|
self.wait()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.parent.needClean:
|
|
||||||
self.parent.needClean = False
|
|
||||||
GUI.JobList.clear()
|
|
||||||
if GUI.JobList.count() == 0:
|
|
||||||
self.parent.addMessage('No files selected! Please choose files to convert.', self.parent.errorIcon)
|
|
||||||
self.parent.needClean = True
|
|
||||||
return
|
|
||||||
self.parent.modeConvert(False)
|
self.parent.modeConvert(False)
|
||||||
profile = ProfileData.ProfileLabels[str(GUI.DeviceBox.currentText())]
|
profile = ProfileData.ProfileLabels[str(GUI.DeviceBox.currentText())]
|
||||||
argv = ["--profile=" + profile]
|
argv = ["--profile=" + profile]
|
||||||
@@ -94,7 +87,8 @@ class WorkerThread(QtCore.QThread):
|
|||||||
jobargv = list(argv)
|
jobargv = list(argv)
|
||||||
jobargv.append(job)
|
jobargv.append(job)
|
||||||
try:
|
try:
|
||||||
outputPath = comic2ebook.main(jobargv)
|
outputPath = comic2ebook.main(jobargv, self)
|
||||||
|
GUI.ProgressBar.hide()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
errors = True
|
errors = True
|
||||||
type_, value_, traceback_ = sys.exc_info()
|
type_, value_, traceback_ = sys.exc_info()
|
||||||
@@ -112,7 +106,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
if str(GUI.FormatBox.currentText()) == 'MOBI':
|
if str(GUI.FormatBox.currentText()) == 'MOBI':
|
||||||
if not os.path.getsize(outputPath) > 314572800:
|
if not os.path.getsize(outputPath) > 314572800:
|
||||||
self.parent.addMessage('Creating MOBI file...', self.parent.infoIcon)
|
self.parent.addMessage('Creating MOBI file...', self.parent.infoIcon)
|
||||||
retcode = call('kindlegen "' + outputPath + '"', stdout=PIPE, stderr=STDOUT, shell=True)
|
retcode = call('kindlegen "' + outputPath + '"', shell=True)
|
||||||
if retcode == 0:
|
if retcode == 0:
|
||||||
self.parent.addMessage('Creating MOBI file... Done!', self.parent.infoIcon, True)
|
self.parent.addMessage('Creating MOBI file... Done!', self.parent.infoIcon, True)
|
||||||
self.parent.addMessage('Removing SRCS header...', self.parent.infoIcon)
|
self.parent.addMessage('Removing SRCS header...', self.parent.infoIcon)
|
||||||
@@ -275,7 +269,22 @@ class Ui_KCC(object):
|
|||||||
GUI.JobList.takeItem(GUI.JobList.count()-1)
|
GUI.JobList.takeItem(GUI.JobList.count()-1)
|
||||||
GUI.JobList.addItem(item)
|
GUI.JobList.addItem(item)
|
||||||
|
|
||||||
|
def updateProgressbar(self, new=False):
|
||||||
|
if new:
|
||||||
|
GUI.ProgressBar.setMaximum(new - 1)
|
||||||
|
GUI.ProgressBar.reset()
|
||||||
|
GUI.ProgressBar.show()
|
||||||
|
else:
|
||||||
|
GUI.ProgressBar.setValue(GUI.ProgressBar.value() + 1)
|
||||||
|
|
||||||
def convertStart(self):
|
def convertStart(self):
|
||||||
|
if self.needClean:
|
||||||
|
self.needClean = False
|
||||||
|
GUI.JobList.clear()
|
||||||
|
if GUI.JobList.count() == 0:
|
||||||
|
self.addMessage('No files selected! Please choose files to convert.', self.errorIcon)
|
||||||
|
self.needClean = True
|
||||||
|
return
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
def __init__(self, ui, KCC):
|
def __init__(self, ui, KCC):
|
||||||
@@ -318,6 +327,7 @@ class Ui_KCC(object):
|
|||||||
GUI.FileButton.clicked.connect(self.selectFile)
|
GUI.FileButton.clicked.connect(self.selectFile)
|
||||||
GUI.ConvertButton.clicked.connect(self.convertStart)
|
GUI.ConvertButton.clicked.connect(self.convertStart)
|
||||||
GUI.GammaSlider.valueChanged.connect(self.changeGamma)
|
GUI.GammaSlider.valueChanged.connect(self.changeGamma)
|
||||||
|
self.thread.connect(self.thread, QtCore.SIGNAL("progressBarTick"), self.updateProgressbar)
|
||||||
|
|
||||||
for profile in profiles:
|
for profile in profiles:
|
||||||
GUI.DeviceBox.addItem(kindleIcon, profile)
|
GUI.DeviceBox.addItem(kindleIcon, profile)
|
||||||
@@ -330,6 +340,7 @@ class Ui_KCC(object):
|
|||||||
GUI.FormatBox.setCurrentIndex(0)
|
GUI.FormatBox.setCurrentIndex(0)
|
||||||
|
|
||||||
self.modeBasic()
|
self.modeBasic()
|
||||||
|
GUI.ProgressBar.hide()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# Form implementation generated from reading ui file 'KCC.ui'
|
# Form implementation generated from reading ui file 'KCC.ui'
|
||||||
#
|
#
|
||||||
# Created: Mon Jun 10 20:06:36 2013
|
# Created: Tue Jun 11 08:49:21 2013
|
||||||
# by: PyQt4 UI code generator 4.10.1
|
# by: PyQt4 UI code generator 4.10.1
|
||||||
#
|
#
|
||||||
# WARNING! All changes made in this file will be lost!
|
# WARNING! All changes made in this file will be lost!
|
||||||
@@ -215,6 +215,11 @@ class Ui_KCC(object):
|
|||||||
self.customHeight.setMaxLength(4)
|
self.customHeight.setMaxLength(4)
|
||||||
self.customHeight.setObjectName(_fromUtf8("customHeight"))
|
self.customHeight.setObjectName(_fromUtf8("customHeight"))
|
||||||
self.gridLayout_2.addWidget(self.customHeight, 0, 3, 1, 1)
|
self.gridLayout_2.addWidget(self.customHeight, 0, 3, 1, 1)
|
||||||
|
self.ProgressBar = QtGui.QProgressBar(self.Form)
|
||||||
|
self.ProgressBar.setGeometry(QtCore.QRect(10, 10, 401, 31))
|
||||||
|
self.ProgressBar.setProperty("value", 0)
|
||||||
|
self.ProgressBar.setTextVisible(False)
|
||||||
|
self.ProgressBar.setObjectName(_fromUtf8("ProgressBar"))
|
||||||
KCC.setCentralWidget(self.Form)
|
KCC.setCentralWidget(self.Form)
|
||||||
self.ActionBasic = QtGui.QAction(KCC)
|
self.ActionBasic = QtGui.QAction(KCC)
|
||||||
self.ActionBasic.setCheckable(True)
|
self.ActionBasic.setCheckable(True)
|
||||||
|
|||||||
+30
-6
@@ -32,7 +32,8 @@ from shutil import copytree
|
|||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from shutil import make_archive
|
from shutil import make_archive
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from multiprocessing import Pool, freeze_support
|
from multiprocessing import Pool, Queue, freeze_support
|
||||||
|
from PyQt4 import QtCore
|
||||||
import image
|
import image
|
||||||
import cbxarchive
|
import cbxarchive
|
||||||
import pdfjpgextract
|
import pdfjpgextract
|
||||||
@@ -331,16 +332,29 @@ def dirImgProcess(path):
|
|||||||
work = []
|
work = []
|
||||||
pagenumber = 0
|
pagenumber = 0
|
||||||
pagenumbermodifier = 0
|
pagenumbermodifier = 0
|
||||||
pool = Pool()
|
queue = Queue()
|
||||||
|
pool = Pool(None, fileImgProcess_init, [queue, options])
|
||||||
for (dirpath, dirnames, filenames) in os.walk(path):
|
for (dirpath, dirnames, filenames) in os.walk(path):
|
||||||
for afile in filenames:
|
for afile in filenames:
|
||||||
if getImageFileName(afile) is not None:
|
if getImageFileName(afile) is not None:
|
||||||
pagenumber += 1
|
pagenumber += 1
|
||||||
work.append([afile, dirpath, pagenumber, options])
|
work.append([afile, dirpath, pagenumber])
|
||||||
|
if GUI:
|
||||||
|
GUI.emit(QtCore.SIGNAL("progressBarTick"), pagenumber)
|
||||||
if len(work) > 0:
|
if len(work) > 0:
|
||||||
splitpages = pool.map(fileImgProcess, work)
|
splitpages = pool.map_async(fileImgProcess, work)
|
||||||
pool.close()
|
pool.close()
|
||||||
|
if GUI:
|
||||||
|
while True:
|
||||||
|
# noinspection PyBroadException
|
||||||
|
try:
|
||||||
|
queue.get(True, 1)
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
GUI.emit(QtCore.SIGNAL("progressBarTick"))
|
||||||
pool.join()
|
pool.join()
|
||||||
|
queue.close()
|
||||||
|
splitpages = splitpages.get()
|
||||||
splitpages = filter(None, splitpages)
|
splitpages = filter(None, splitpages)
|
||||||
splitpages.sort()
|
splitpages.sort()
|
||||||
for page in splitpages:
|
for page in splitpages:
|
||||||
@@ -350,16 +364,23 @@ def dirImgProcess(path):
|
|||||||
pagenumbermodifier += 1
|
pagenumbermodifier += 1
|
||||||
|
|
||||||
|
|
||||||
|
def fileImgProcess_init(queue, options):
|
||||||
|
fileImgProcess.queue = queue
|
||||||
|
fileImgProcess.options = options
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
def fileImgProcess(work):
|
def fileImgProcess(work):
|
||||||
afile = work[0]
|
afile = work[0]
|
||||||
dirpath = work[1]
|
dirpath = work[1]
|
||||||
pagenumber = work[2]
|
pagenumber = work[2]
|
||||||
options = work[3]
|
options = fileImgProcess.options
|
||||||
output = None
|
output = None
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print "Optimizing " + afile + " for " + options.profile
|
print "Optimizing " + afile + " for " + options.profile
|
||||||
else:
|
else:
|
||||||
print ".",
|
print ".",
|
||||||
|
fileImgProcess.queue.put(".")
|
||||||
img = image.ComicPage(os.path.join(dirpath, afile), options.profile)
|
img = image.ComicPage(os.path.join(dirpath, afile), options.profile)
|
||||||
if options.nosplitrotate:
|
if options.nosplitrotate:
|
||||||
split = None
|
split = None
|
||||||
@@ -608,7 +629,7 @@ def Usage():
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None, qtGUI=None):
|
||||||
global parser, options, epub_path, splitCount
|
global parser, options, epub_path, splitCount
|
||||||
usage = "Usage: %prog [options] comic_file|comic_folder"
|
usage = "Usage: %prog [options] comic_file|comic_folder"
|
||||||
parser = OptionParser(usage=usage, version=__version__)
|
parser = OptionParser(usage=usage, version=__version__)
|
||||||
@@ -648,6 +669,9 @@ def main(argv=None):
|
|||||||
help="Verbose output [Default=False]")
|
help="Verbose output [Default=False]")
|
||||||
options, args = parser.parse_args(argv)
|
options, args = parser.parse_args(argv)
|
||||||
checkOptions()
|
checkOptions()
|
||||||
|
if qtGUI:
|
||||||
|
global GUI
|
||||||
|
GUI = qtGUI
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user