mirror of
https://github.com/ciromattia/kcc
synced 2026-10-18 15:32:33 +00:00
Litte cleanup
This commit is contained in:
+48
-39
@@ -33,6 +33,26 @@ from subprocess import call, STDOUT, PIPE
|
|||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
|
|
||||||
|
|
||||||
|
class Icons:
|
||||||
|
def __init__(self):
|
||||||
|
self.deviceKindle = QtGui.QIcon()
|
||||||
|
self.deviceKindle.addPixmap(QtGui.QPixmap(":/Devices/icons/Kindle.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
|
|
||||||
|
self.MOBIFormat = QtGui.QIcon()
|
||||||
|
self.MOBIFormat.addPixmap(QtGui.QPixmap(":/Formats/icons/MOBI.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
|
self.CBZFormat = QtGui.QIcon()
|
||||||
|
self.CBZFormat.addPixmap(QtGui.QPixmap(":/Formats/icons/CBZ.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
|
self.EPUBFormat = QtGui.QIcon()
|
||||||
|
self.EPUBFormat.addPixmap(QtGui.QPixmap(":/Formats/icons/EPUB.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
|
|
||||||
|
self.info = QtGui.QIcon()
|
||||||
|
self.info.addPixmap(QtGui.QPixmap(":/Status/icons/info.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
|
self.warning = QtGui.QIcon()
|
||||||
|
self.warning.addPixmap(QtGui.QPixmap(":/Status/icons/warning.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
|
self.error = QtGui.QIcon()
|
||||||
|
self.error.addPixmap(QtGui.QPixmap(":/Status/icons/error.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
class WorkerThread(QtCore.QThread):
|
class WorkerThread(QtCore.QThread):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -79,11 +99,11 @@ class WorkerThread(QtCore.QThread):
|
|||||||
GUI.JobList.clear()
|
GUI.JobList.clear()
|
||||||
for job in currentJobs:
|
for job in currentJobs:
|
||||||
errors = False
|
errors = False
|
||||||
self.parent.addMessage('Source: ' + job, self.parent.infoIcon)
|
self.parent.addMessage('Source: ' + job, icons.info)
|
||||||
if str(GUI.FormatBox.currentText()) == 'CBZ':
|
if str(GUI.FormatBox.currentText()) == 'CBZ':
|
||||||
self.parent.addMessage('Creating CBZ file...', self.parent.infoIcon)
|
self.parent.addMessage('Creating CBZ file...', icons.info)
|
||||||
else:
|
else:
|
||||||
self.parent.addMessage('Creating EPUB file...', self.parent.infoIcon)
|
self.parent.addMessage('Creating EPUB file...', icons.info)
|
||||||
jobargv = list(argv)
|
jobargv = list(argv)
|
||||||
jobargv.append(job)
|
jobargv.append(job)
|
||||||
try:
|
try:
|
||||||
@@ -96,20 +116,20 @@ class WorkerThread(QtCore.QThread):
|
|||||||
"Error on file %s:\n%s\nTraceback:\n%s"
|
"Error on file %s:\n%s\nTraceback:\n%s"
|
||||||
% (jobargv[-1], str(err), traceback.format_tb(traceback_)),
|
% (jobargv[-1], str(err), traceback.format_tb(traceback_)),
|
||||||
QtGui.QMessageBox.Ok)
|
QtGui.QMessageBox.Ok)
|
||||||
self.parent.addMessage('KCC failed to create EPUB!', self.parent.errorIcon)
|
self.parent.addMessage('KCC failed to create EPUB!', icons.error)
|
||||||
continue
|
continue
|
||||||
if not errors:
|
if not errors:
|
||||||
if str(GUI.FormatBox.currentText()) == 'CBZ':
|
if str(GUI.FormatBox.currentText()) == 'CBZ':
|
||||||
self.parent.addMessage('Creating CBZ file... Done!', self.parent.infoIcon, True)
|
self.parent.addMessage('Creating CBZ file... Done!', icons.info, True)
|
||||||
else:
|
else:
|
||||||
self.parent.addMessage('Creating EPUB file... Done!', self.parent.infoIcon, True)
|
self.parent.addMessage('Creating EPUB file... Done!', icons.info, True)
|
||||||
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...', icons.info)
|
||||||
retcode = call('kindlegen "' + outputPath + '"', 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!', icons.info, True)
|
||||||
self.parent.addMessage('Removing SRCS header...', self.parent.infoIcon)
|
self.parent.addMessage('Removing SRCS header...', icons.info)
|
||||||
os.remove(outputPath)
|
os.remove(outputPath)
|
||||||
mobiPath = outputPath.replace('.epub', '.mobi')
|
mobiPath = outputPath.replace('.epub', '.mobi')
|
||||||
shutil.move(mobiPath, mobiPath + '_tostrip')
|
shutil.move(mobiPath, mobiPath + '_tostrip')
|
||||||
@@ -120,30 +140,31 @@ class WorkerThread(QtCore.QThread):
|
|||||||
continue
|
continue
|
||||||
if not errors:
|
if not errors:
|
||||||
os.remove(mobiPath + '_tostrip')
|
os.remove(mobiPath + '_tostrip')
|
||||||
self.parent.addMessage('Removing SRCS header... Done!', self.parent.infoIcon, True)
|
self.parent.addMessage('Removing SRCS header... Done!', icons.info, True)
|
||||||
else:
|
else:
|
||||||
shutil.move(mobiPath + '_tostrip', mobiPath)
|
shutil.move(mobiPath + '_tostrip', mobiPath)
|
||||||
self.parent.addMessage('KindleStrip failed to remove SRCS header!',
|
self.parent.addMessage('KindleStrip failed to remove SRCS header!',
|
||||||
self.parent.warningIcon)
|
icons.warning)
|
||||||
self.parent.addMessage('MOBI file will work correctly but it will be highly oversized.',
|
self.parent.addMessage('MOBI file will work correctly but it will be highly oversized.',
|
||||||
self.parent.warningIcon)
|
icons.warning)
|
||||||
else:
|
else:
|
||||||
os.remove(outputPath)
|
os.remove(outputPath)
|
||||||
os.remove(outputPath.replace('.epub', '.mobi'))
|
os.remove(outputPath.replace('.epub', '.mobi'))
|
||||||
self.parent.addMessage('KindleGen failed to create MOBI!', self.parent.errorIcon)
|
self.parent.addMessage('KindleGen failed to create MOBI!', icons.error)
|
||||||
self.parent.addMessage('Try converting smaller batch.', self.parent.errorIcon)
|
self.parent.addMessage('Try converting smaller batch.', icons.error)
|
||||||
else:
|
else:
|
||||||
os.remove(outputPath)
|
os.remove(outputPath)
|
||||||
self.parent.addMessage('Created EPUB file is too big for KindleGen!', self.parent.errorIcon)
|
self.parent.addMessage('Created EPUB file is too big for KindleGen!', icons.error)
|
||||||
self.parent.addMessage('Try converting smaller batch.', self.parent.errorIcon)
|
self.parent.addMessage('Try converting smaller batch.', icons.error)
|
||||||
self.parent.needClean = True
|
self.parent.needClean = True
|
||||||
self.parent.addMessage('All jobs completed.', self.parent.warningIcon)
|
self.parent.addMessage('All jobs completed.', icons.warning)
|
||||||
self.parent.modeConvert(True)
|
self.parent.modeConvert(True)
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
class Ui_KCC(object):
|
class Ui_KCC(object):
|
||||||
def selectDir(self):
|
def selectDir(self):
|
||||||
|
# Dialog allow to select multiple directories but we can't parse that. QT Bug.
|
||||||
if self.needClean:
|
if self.needClean:
|
||||||
self.needClean = False
|
self.needClean = False
|
||||||
GUI.JobList.clear()
|
GUI.JobList.clear()
|
||||||
@@ -180,6 +201,7 @@ class Ui_KCC(object):
|
|||||||
GUI.JobList.clear()
|
GUI.JobList.clear()
|
||||||
|
|
||||||
def clearEmptyJobs(self):
|
def clearEmptyJobs(self):
|
||||||
|
# Sometimes empty records appear. Dirty workaround.
|
||||||
for i in range(GUI.JobList.count()):
|
for i in range(GUI.JobList.count()):
|
||||||
if str(GUI.JobList.item(i).text()) == '':
|
if str(GUI.JobList.item(i).text()) == '':
|
||||||
GUI.JobList.takeItem(i)
|
GUI.JobList.takeItem(i)
|
||||||
@@ -282,42 +304,35 @@ class Ui_KCC(object):
|
|||||||
self.needClean = False
|
self.needClean = False
|
||||||
GUI.JobList.clear()
|
GUI.JobList.clear()
|
||||||
if GUI.JobList.count() == 0:
|
if GUI.JobList.count() == 0:
|
||||||
self.addMessage('No files selected! Please choose files to convert.', self.errorIcon)
|
self.addMessage('No files selected! Please choose files to convert.', icons.error)
|
||||||
self.needClean = True
|
self.needClean = True
|
||||||
return
|
return
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
def __init__(self, ui, KCC):
|
def __init__(self, ui, KCC):
|
||||||
global GUI, MainWindow
|
global GUI, MainWindow, icons
|
||||||
GUI = ui
|
GUI = ui
|
||||||
MainWindow = KCC
|
MainWindow = KCC
|
||||||
profiles = sorted(ProfileData.ProfileLabels.iterkeys())
|
profiles = sorted(ProfileData.ProfileLabels.iterkeys())
|
||||||
kindleIcon = QtGui.QIcon()
|
icons = Icons()
|
||||||
kindleIcon.addPixmap(QtGui.QPixmap(":/Devices/icons/Kindle.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
|
||||||
self.thread = WorkerThread(self)
|
self.thread = WorkerThread(self)
|
||||||
self.needClean = True
|
self.needClean = True
|
||||||
self.GammaValue = 0
|
self.GammaValue = 0
|
||||||
self.infoIcon = QtGui.QIcon()
|
|
||||||
self.infoIcon.addPixmap(QtGui.QPixmap(":/Status/icons/info.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
|
||||||
self.warningIcon = QtGui.QIcon()
|
|
||||||
self.warningIcon.addPixmap(QtGui.QPixmap(":/Status/icons/warning.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
|
||||||
self.errorIcon = QtGui.QIcon()
|
|
||||||
self.errorIcon.addPixmap(QtGui.QPixmap(":/Status/icons/error.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
|
||||||
|
|
||||||
self.addMessage('Welcome!', self.infoIcon)
|
self.addMessage('Welcome!', icons.info)
|
||||||
self.addMessage('Remember: All options have additional informations in tooltips.', self.infoIcon)
|
self.addMessage('Remember: All options have additional informations in tooltips.', icons.info)
|
||||||
if call('kindlegen', stdout=PIPE, stderr=STDOUT, shell=True) == 0:
|
if call('kindlegen', stdout=PIPE, stderr=STDOUT, shell=True) == 0:
|
||||||
self.KindleGen = True
|
self.KindleGen = True
|
||||||
formats = ['MOBI', 'EPUB', 'CBZ']
|
formats = ['MOBI', 'EPUB', 'CBZ']
|
||||||
else:
|
else:
|
||||||
self.KindleGen = False
|
self.KindleGen = False
|
||||||
formats = ['EPUB', 'CBZ']
|
formats = ['EPUB', 'CBZ']
|
||||||
self.addMessage('Not found KindleGen! Creating MOBI files is disabled.', self.warningIcon)
|
self.addMessage('Not found KindleGen! Creating MOBI files is disabled.', icons.warning)
|
||||||
if call('unrar', stdout=PIPE, stderr=STDOUT, shell=True) == 0:
|
if call('unrar', stdout=PIPE, stderr=STDOUT, shell=True) == 0:
|
||||||
self.UnRAR = True
|
self.UnRAR = True
|
||||||
else:
|
else:
|
||||||
self.UnRAR = False
|
self.UnRAR = False
|
||||||
self.addMessage('Not found UnRAR! Processing of CBR/RAR files is disabled.', self.warningIcon)
|
self.addMessage('Not found UnRAR! Processing of CBR/RAR files is disabled.', icons.warning)
|
||||||
|
|
||||||
GUI.BasicModeButton.clicked.connect(self.modeBasic)
|
GUI.BasicModeButton.clicked.connect(self.modeBasic)
|
||||||
GUI.AdvModeButton.clicked.connect(self.modeAdvanced)
|
GUI.AdvModeButton.clicked.connect(self.modeAdvanced)
|
||||||
@@ -330,17 +345,11 @@ class Ui_KCC(object):
|
|||||||
self.thread.connect(self.thread, QtCore.SIGNAL("progressBarTick"), self.updateProgressbar)
|
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(icons.deviceKindle, profile)
|
||||||
GUI.DeviceBox.setCurrentIndex(10)
|
GUI.DeviceBox.setCurrentIndex(10)
|
||||||
for f in formats:
|
for f in formats:
|
||||||
formatIcon = QtGui.QIcon()
|
GUI.FormatBox.addItem(eval('icons.' + f + 'Format'), f)
|
||||||
formatIcon.addPixmap(QtGui.QPixmap(":/Formats/icons/" + f + ".png"), QtGui.QIcon.Normal,
|
|
||||||
QtGui.QIcon.Off)
|
|
||||||
GUI.FormatBox.addItem(formatIcon, f)
|
|
||||||
GUI.FormatBox.setCurrentIndex(0)
|
GUI.FormatBox.setCurrentIndex(0)
|
||||||
|
|
||||||
self.modeBasic()
|
self.modeBasic()
|
||||||
GUI.ProgressBar.hide()
|
GUI.ProgressBar.hide()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -345,10 +345,11 @@ def dirImgProcess(path):
|
|||||||
splitpages = pool.map_async(fileImgProcess, work)
|
splitpages = pool.map_async(fileImgProcess, work)
|
||||||
pool.close()
|
pool.close()
|
||||||
if GUI:
|
if GUI:
|
||||||
|
# This solution is far from perfect. Progress bar might break but it will not crash application.
|
||||||
while True:
|
while True:
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
queue.get(True, 1)
|
queue.get(True, 2)
|
||||||
except:
|
except:
|
||||||
break
|
break
|
||||||
GUI.emit(QtCore.SIGNAL("progressBarTick"))
|
GUI.emit(QtCore.SIGNAL("progressBarTick"))
|
||||||
|
|||||||
Reference in New Issue
Block a user