about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--KCC.ui20
-rw-r--r--kcc.py2
-rw-r--r--kcc/KCC_gui.py29
-rw-r--r--kcc/KCC_ui.py7
-rwxr-xr-xkcc/comic2ebook.py36
5 files changed, 74 insertions, 20 deletions
diff --git a/KCC.ui b/KCC.ui
index 6a27a95..d09ecf3 100644
--- a/KCC.ui
+++ b/KCC.ui
@@ -504,10 +504,6 @@
       <enum>Qt::Horizontal</enum>
      </property>
     </widget>
-    <zorder>GammaLabel</zorder>
-    <zorder>GammaSlider</zorder>
-    <zorder>OptionsExpert</zorder>
-    <zorder>OptionsExpert</zorder>
    </widget>
    <widget class="QFrame" name="OptionsExpert">
     <property name="geometry">
@@ -585,6 +581,22 @@
      </item>
     </layout>
    </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>
   <action name="ActionBasic">
    <property name="checkable">
diff --git a/kcc.py b/kcc.py
index 0eb4493..a64507f 100644
--- a/kcc.py
+++ b/kcc.py
@@ -26,7 +26,9 @@ import sys
 import os
 from PyQt4 import QtGui
 from kcc import KCC_gui, KCC_ui
+from multiprocessing import freeze_support
 
+freeze_support()
 if sys.platform == 'darwin':
     os.environ['PATH'] = '/usr/local/bin:' + os.environ['PATH']
 app = QtGui.QApplication(sys.argv)
diff --git a/kcc/KCC_gui.py b/kcc/KCC_gui.py
index 7d751e0..19c484f 100644
--- a/kcc/KCC_gui.py
+++ b/kcc/KCC_gui.py
@@ -43,13 +43,6 @@ class WorkerThread(QtCore.QThread):
         self.wait()
 
     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)
         profile = ProfileData.ProfileLabels[str(GUI.DeviceBox.currentText())]
         argv = ["--profile=" + profile]
@@ -94,7 +87,8 @@ class WorkerThread(QtCore.QThread):
             jobargv = list(argv)
             jobargv.append(job)
             try:
-                outputPath = comic2ebook.main(jobargv)
+                outputPath = comic2ebook.main(jobargv, self)
+                GUI.ProgressBar.hide()
             except Exception as err:
                 errors = True
                 type_, value_, traceback_ = sys.exc_info()
@@ -112,7 +106,7 @@ class WorkerThread(QtCore.QThread):
                 if str(GUI.FormatBox.currentText()) == 'MOBI':
                     if not os.path.getsize(outputPath) > 314572800:
                         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:
                             self.parent.addMessage('Creating MOBI file... Done!', self.parent.infoIcon, True)
                             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.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):
+        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()
 
     def __init__(self, ui, KCC):
@@ -318,6 +327,7 @@ class Ui_KCC(object):
         GUI.FileButton.clicked.connect(self.selectFile)
         GUI.ConvertButton.clicked.connect(self.convertStart)
         GUI.GammaSlider.valueChanged.connect(self.changeGamma)
+        self.thread.connect(self.thread, QtCore.SIGNAL("progressBarTick"), self.updateProgressbar)
 
         for profile in profiles:
             GUI.DeviceBox.addItem(kindleIcon, profile)
@@ -330,6 +340,7 @@ class Ui_KCC(object):
         GUI.FormatBox.setCurrentIndex(0)
 
         self.modeBasic()
+        GUI.ProgressBar.hide()
 
 
 
diff --git a/kcc/KCC_ui.py b/kcc/KCC_ui.py
index bfa9862..0ed4156 100644
--- a/kcc/KCC_ui.py
+++ b/kcc/KCC_ui.py
@@ -2,7 +2,7 @@
 
 # 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
 #
 # WARNING! All changes made in this file will be lost!
@@ -215,6 +215,11 @@ class Ui_KCC(object):
         self.customHeight.setMaxLength(4)
         self.customHeight.setObjectName(_fromUtf8("customHeight"))
         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)
         self.ActionBasic = QtGui.QAction(KCC)
         self.ActionBasic.setCheckable(True)
diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py
index 59384f8..463450c 100755
--- a/kcc/comic2ebook.py
+++ b/kcc/comic2ebook.py
@@ -32,7 +32,8 @@ from shutil import copytree
 from shutil import rmtree
 from shutil import make_archive
 from optparse import OptionParser
-from multiprocessing import Pool, freeze_support
+from multiprocessing import Pool, Queue, freeze_support
+from PyQt4 import QtCore
 import image
 import cbxarchive
 import pdfjpgextract
@@ -331,16 +332,29 @@ def dirImgProcess(path):
     work = []
     pagenumber = 0
     pagenumbermodifier = 0
-    pool = Pool()
+    queue = Queue()
+    pool = Pool(None, fileImgProcess_init, [queue, options])
     for (dirpath, dirnames, filenames) in os.walk(path):
         for afile in filenames:
             if getImageFileName(afile) is not None:
                 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:
-        splitpages = pool.map(fileImgProcess, work)
+        splitpages = pool.map_async(fileImgProcess, work)
         pool.close()
+        if GUI:
+            while True:
+                # noinspection PyBroadException
+                try:
+                    queue.get(True, 1)
+                except:
+                    break
+                GUI.emit(QtCore.SIGNAL("progressBarTick"))
         pool.join()
+        queue.close()
+        splitpages = splitpages.get()
         splitpages = filter(None, splitpages)
         splitpages.sort()
         for page in splitpages:
@@ -350,16 +364,23 @@ def dirImgProcess(path):
             pagenumbermodifier += 1
 
 
+def fileImgProcess_init(queue, options):
+    fileImgProcess.queue = queue
+    fileImgProcess.options = options
+
+
+# noinspection PyUnresolvedReferences
 def fileImgProcess(work):
     afile = work[0]
     dirpath = work[1]
     pagenumber = work[2]
-    options = work[3]
+    options = fileImgProcess.options
     output = None
     if options.verbose:
         print "Optimizing " + afile + " for " + options.profile
     else:
         print ".",
+    fileImgProcess.queue.put(".")
     img = image.ComicPage(os.path.join(dirpath, afile), options.profile)
     if options.nosplitrotate:
         split = None
@@ -608,7 +629,7 @@ def Usage():
     parser.print_help()
 
 
-def main(argv=None):
+def main(argv=None, qtGUI=None):
     global parser, options, epub_path, splitCount
     usage = "Usage: %prog [options] comic_file|comic_folder"
     parser = OptionParser(usage=usage, version=__version__)
@@ -648,6 +669,9 @@ def main(argv=None):
                       help="Verbose output [Default=False]")
     options, args = parser.parse_args(argv)
     checkOptions()
+    if qtGUI:
+        global GUI
+        GUI = qtGUI
     if len(args) != 1:
         parser.print_help()
         return