1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-21 13:41:44 +00:00

Code cleanup

This commit is contained in:
Paweł Jastrzębski
2013-11-13 11:27:26 +01:00
parent 50f5b600b1
commit ddd223c2ec
5 changed files with 109 additions and 91 deletions

28
kcc.py
View File

@@ -39,22 +39,19 @@ except ImportError:
exit(1) exit(1)
from kcc import KCC_gui from kcc import KCC_gui
from multiprocessing import freeze_support from multiprocessing import freeze_support
# OS specific PATH variable workarounds
if sys.platform.startswith('darwin'): if sys.platform.startswith('darwin'):
if 'RESOURCEPATH' in os.environ: if 'RESOURCEPATH' in os.environ:
os.environ['PATH'] = os.environ['RESOURCEPATH'] + ':' + os.environ['PATH'] os.environ['PATH'] = os.environ['RESOURCEPATH'] + ':' + os.environ['PATH']
else: else:
os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/:' + os.environ['PATH'] os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/:' + os.environ['PATH']
from kcc import KCC_ui_osx as KCC_ui elif sys.platform.startswith('win'):
elif sys.platform.startswith('linux'):
from kcc import KCC_ui_linux as KCC_ui
else:
# Workaround for Windows file association mechanism
if getattr(sys, 'frozen', False): if getattr(sys, 'frozen', False):
os.chdir(os.path.dirname(os.path.abspath(sys.executable))) os.chdir(os.path.dirname(os.path.abspath(sys.executable)))
else: else:
os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/;' + os.environ['PATH'] os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/;' + os.environ['PATH']
os.chdir(os.path.dirname(os.path.abspath(__file__))) os.chdir(os.path.dirname(os.path.abspath(__file__)))
from kcc import KCC_ui
# Implementing detection of already running KCC instance and forwarding argv to it # Implementing detection of already running KCC instance and forwarding argv to it
@@ -98,10 +95,10 @@ class QApplicationMessaging(QtGui.QApplication):
return False return False
freeze_support() freeze_support()
APP = QApplicationMessaging(sys.argv) KCCAplication = QApplicationMessaging(sys.argv)
if APP.isRunning(): if KCCAplication.isRunning():
if len(sys.argv) > 1: if len(sys.argv) > 1:
APP.sendMessage(sys.argv[1].decode(sys.getfilesystemencoding())) KCCAplication.sendMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
sys.exit(0) sys.exit(0)
else: else:
messageBox = QtGui.QMessageBox() messageBox = QtGui.QMessageBox()
@@ -110,13 +107,8 @@ if APP.isRunning():
messageBox.setWindowIcon(icon) messageBox.setWindowIcon(icon)
QtGui.QMessageBox.critical(messageBox, 'KCC - Error', 'KCC is already running!', QtGui.QMessageBox.Ok) QtGui.QMessageBox.critical(messageBox, 'KCC - Error', 'KCC is already running!', QtGui.QMessageBox.Ok)
sys.exit(1) sys.exit(1)
KCC = QtGui.QMainWindow() KCCWindow = QtGui.QMainWindow()
UI = KCC_ui.Ui_KCC() KCCUI = KCC_gui.KCCGUI(KCCAplication, KCCWindow)
UI.setupUi(KCC)
GUI = KCC_gui.Ui_KCC(UI, KCC, APP)
KCC.setWindowTitle("Kindle Comic Converter " + __version__)
KCC.show()
KCC.raise_()
if len(sys.argv) > 1: if len(sys.argv) > 1:
GUI.handleMessage(sys.argv[1].decode(sys.getfilesystemencoding())) KCCUI.handleMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
sys.exit(APP.exec_()) sys.exit(KCCAplication.exec_())

View File

@@ -26,13 +26,12 @@ import os
import sys import sys
import traceback import traceback
import urllib2 import urllib2
import socket
import comic2ebook import comic2ebook
import kindlesplit import kindlesplit
import socket
from string import split from string import split
from time import sleep from time import sleep
from shutil import move from shutil import move
from KCC_rc_web import WebContent
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from SocketServer import ThreadingMixIn from SocketServer import ThreadingMixIn
from image import ProfileData from image import ProfileData
@@ -40,6 +39,7 @@ from subprocess import STDOUT, PIPE
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
from xml.dom.minidom import parse from xml.dom.minidom import parse
from HTMLParser import HTMLParser from HTMLParser import HTMLParser
from KCC_rc_web import WebContent
try: try:
#noinspection PyUnresolvedReferences #noinspection PyUnresolvedReferences
from psutil import TOTAL_PHYMEM, Popen from psutil import TOTAL_PHYMEM, Popen
@@ -52,6 +52,12 @@ except ImportError:
importRoot.withdraw() importRoot.withdraw()
tkMessageBox.showerror("KCC - Error", "Psutil is not installed!") tkMessageBox.showerror("KCC - Error", "Psutil is not installed!")
exit(1) exit(1)
if sys.platform.startswith('darwin'):
import KCC_ui_osx as KCC_ui
elif sys.platform.startswith('linux'):
import KCC_ui_linux as KCC_ui
else:
import KCC_ui
class Icons: class Icons:
@@ -116,15 +122,15 @@ class WebServerHandler(BaseHTTPRequestHandler):
self.wfile.write('<!DOCTYPE html>\n' self.wfile.write('<!DOCTYPE html>\n'
'<html lang="en">\n' '<html lang="en">\n'
'<head><meta charset="utf-8">\n' '<head><meta charset="utf-8">\n'
'<link href="' + GUIMain.webContent.favicon + '" rel="icon" type="image/x-icon" />\n' '<link href="' + GUI.webContent.favicon + '" rel="icon" type="image/x-icon" />\n'
'<title>Kindle Comic Converter</title>\n' '<title>Kindle Comic Converter</title>\n'
'</head>\n' '</head>\n'
'<body>\n' '<body>\n'
'<div style="text-align: center; font-size:25px">\n' '<div style="text-align: center; font-size:25px">\n'
'<p style="font-size:50px">- <img style="vertical-align: middle" ' '<p style="font-size:50px">- <img style="vertical-align: middle" '
'alt="KCC Logo" src="' + GUIMain.webContent.logo + '" /> -</p>\n') 'alt="KCC Logo" src="' + GUI.webContent.logo + '" /> -</p>\n')
if len(GUIMain.completedWork) > 0 and not GUIMain.conversionAlive: if len(GUI.completedWork) > 0 and not GUI.conversionAlive:
for key in sorted(GUIMain.completedWork.iterkeys()): for key in sorted(GUI.completedWork.iterkeys()):
self.wfile.write('<p><a href="' + key + '">' + split(key, '.')[0] + '</a></p>\n') self.wfile.write('<p><a href="' + key + '">' + split(key, '.')[0] + '</a></p>\n')
else: else:
self.wfile.write('<p style="font-weight: bold">No downloads are available.<br/>' self.wfile.write('<p style="font-weight: bold">No downloads are available.<br/>'
@@ -133,7 +139,7 @@ class WebServerHandler(BaseHTTPRequestHandler):
'</body>\n' '</body>\n'
'</html>\n') '</html>\n')
elif sendReply: elif sendReply:
outputFile = GUIMain.completedWork[urllib2.unquote(self.path[1:])].decode('utf-8') outputFile = GUI.completedWork[urllib2.unquote(self.path[1:])].decode('utf-8')
fp = open(outputFile, 'rb') fp = open(outputFile, 'rb')
self.send_response(200) self.send_response(200)
self.send_header('Content-type', mimetype) self.send_header('Content-type', mimetype)
@@ -320,12 +326,12 @@ class WorkerThread(QtCore.QThread):
self.wait() self.wait()
def sync(self): def sync(self):
self.conversionAlive = GUIMain.conversionAlive self.conversionAlive = GUI.conversionAlive
def clean(self): def clean(self):
GUIMain.progress.content = '' GUI.progress.content = ''
GUIMain.progress.stop() GUI.progress.stop()
GUIMain.needClean = True GUI.needClean = True
self.emit(QtCore.SIGNAL("hideProgressBar")) self.emit(QtCore.SIGNAL("hideProgressBar"))
self.emit(QtCore.SIGNAL("addMessage"), '<b>Conversion interrupted.</b>', 'error') self.emit(QtCore.SIGNAL("addMessage"), '<b>Conversion interrupted.</b>', 'error')
self.emit(QtCore.SIGNAL("addTrayMessage"), 'Conversion interrupted.', 'Critical') self.emit(QtCore.SIGNAL("addTrayMessage"), 'Conversion interrupted.', 'Critical')
@@ -348,7 +354,7 @@ class WorkerThread(QtCore.QThread):
argv.append("--quality=1") argv.append("--quality=1")
elif GUI.QualityBox.checkState() == 2: elif GUI.QualityBox.checkState() == 2:
argv.append("--quality=2") argv.append("--quality=2")
if GUIMain.currentMode > 1: if GUI.currentMode > 1:
if GUI.ProcessingBox.isChecked(): if GUI.ProcessingBox.isChecked():
argv.append("--noprocessing") argv.append("--noprocessing")
if GUI.NoRotateBox.isChecked(): if GUI.NoRotateBox.isChecked():
@@ -365,13 +371,13 @@ class WorkerThread(QtCore.QThread):
argv.append("--forcepng") argv.append("--forcepng")
if GUI.WebtoonBox.isChecked(): if GUI.WebtoonBox.isChecked():
argv.append("--webtoon") argv.append("--webtoon")
if float(GUIMain.GammaValue) > 0.09: if float(GUI.GammaValue) > 0.09:
argv.append("--gamma=" + GUIMain.GammaValue) argv.append("--gamma=" + GUI.GammaValue)
if str(GUI.FormatBox.currentText()) == 'CBZ': if str(GUI.FormatBox.currentText()) == 'CBZ':
argv.append("--cbz-output") argv.append("--cbz-output")
if str(GUI.FormatBox.currentText()) == 'MOBI': if str(GUI.FormatBox.currentText()) == 'MOBI':
argv.append("--batchsplit") argv.append("--batchsplit")
if GUIMain.currentMode > 2: if GUI.currentMode > 2:
argv.append("--customwidth=" + str(GUI.customWidth.text())) argv.append("--customwidth=" + str(GUI.customWidth.text()))
argv.append("--customheight=" + str(GUI.customHeight.text())) argv.append("--customheight=" + str(GUI.customHeight.text()))
if GUI.ColorBox.isChecked(): if GUI.ColorBox.isChecked():
@@ -390,10 +396,10 @@ class WorkerThread(QtCore.QThread):
self.emit(QtCore.SIGNAL("addMessage"), '<b>Source:</b> ' + job, 'info') self.emit(QtCore.SIGNAL("addMessage"), '<b>Source:</b> ' + job, 'info')
if str(GUI.FormatBox.currentText()) == 'CBZ': if str(GUI.FormatBox.currentText()) == 'CBZ':
self.emit(QtCore.SIGNAL("addMessage"), 'Creating CBZ files', 'info') self.emit(QtCore.SIGNAL("addMessage"), 'Creating CBZ files', 'info')
GUIMain.progress.content = 'Creating CBZ files' GUI.progress.content = 'Creating CBZ files'
else: else:
self.emit(QtCore.SIGNAL("addMessage"), 'Creating EPUB files', 'info') self.emit(QtCore.SIGNAL("addMessage"), 'Creating EPUB files', 'info')
GUIMain.progress.content = 'Creating EPUB files' GUI.progress.content = 'Creating EPUB files'
jobargv = list(argv) jobargv = list(argv)
jobargv.append(job) jobargv.append(job)
try: try:
@@ -404,13 +410,13 @@ class WorkerThread(QtCore.QThread):
self.clean() self.clean()
return return
else: else:
GUIMain.progress.content = '' GUI.progress.content = ''
self.errors = True self.errors = True
self.emit(QtCore.SIGNAL("addMessage"), str(warn), 'warning') self.emit(QtCore.SIGNAL("addMessage"), str(warn), 'warning')
self.emit(QtCore.SIGNAL("addMessage"), 'Failed to create output file!', 'warning') self.emit(QtCore.SIGNAL("addMessage"), 'Failed to create output file!', 'warning')
self.emit(QtCore.SIGNAL("addTrayMessage"), 'Failed to create output file!', 'Critical') self.emit(QtCore.SIGNAL("addTrayMessage"), 'Failed to create output file!', 'Critical')
except Exception as err: except Exception as err:
GUIMain.progress.content = '' GUI.progress.content = ''
self.errors = True self.errors = True
type_, value_, traceback_ = sys.exc_info() type_, value_, traceback_ = sys.exc_info()
self.emit(QtCore.SIGNAL("showDialog"), "Error during conversion %s:\n\n%s\n\nTraceback:\n%s" self.emit(QtCore.SIGNAL("showDialog"), "Error during conversion %s:\n\n%s\n\nTraceback:\n%s"
@@ -424,7 +430,7 @@ class WorkerThread(QtCore.QThread):
self.clean() self.clean()
return return
if not self.errors: if not self.errors:
GUIMain.progress.content = '' GUI.progress.content = ''
if str(GUI.FormatBox.currentText()) == 'CBZ': if str(GUI.FormatBox.currentText()) == 'CBZ':
self.emit(QtCore.SIGNAL("addMessage"), 'Creating CBZ files... <b>Done!</b>', 'info', True) self.emit(QtCore.SIGNAL("addMessage"), 'Creating CBZ files... <b>Done!</b>', 'info', True)
else: else:
@@ -434,7 +440,7 @@ class WorkerThread(QtCore.QThread):
self.emit(QtCore.SIGNAL("progressBarTick"), len(outputPath)*2+1) self.emit(QtCore.SIGNAL("progressBarTick"), len(outputPath)*2+1)
self.emit(QtCore.SIGNAL("progressBarTick")) self.emit(QtCore.SIGNAL("progressBarTick"))
self.emit(QtCore.SIGNAL("addMessage"), 'Creating MOBI files', 'info') self.emit(QtCore.SIGNAL("addMessage"), 'Creating MOBI files', 'info')
GUIMain.progress.content = 'Creating MOBI files' GUI.progress.content = 'Creating MOBI files'
self.workerOutput = [] self.workerOutput = []
# Number of KindleGen threads depends on the size of RAM # Number of KindleGen threads depends on the size of RAM
self.pool.setMaxThreadCount(self.threadNumber) self.pool.setMaxThreadCount(self.threadNumber)
@@ -458,10 +464,10 @@ class WorkerThread(QtCore.QThread):
self.clean() self.clean()
return return
if self.kindlegenErrorCode[0] == 0: if self.kindlegenErrorCode[0] == 0:
GUIMain.progress.content = '' GUI.progress.content = ''
self.emit(QtCore.SIGNAL("addMessage"), 'Creating MOBI files... <b>Done!</b>', 'info', True) self.emit(QtCore.SIGNAL("addMessage"), 'Creating MOBI files... <b>Done!</b>', 'info', True)
self.emit(QtCore.SIGNAL("addMessage"), 'Cleaning MOBI files', 'info') self.emit(QtCore.SIGNAL("addMessage"), 'Cleaning MOBI files', 'info')
GUIMain.progress.content = 'Cleaning MOBI files' GUI.progress.content = 'Cleaning MOBI files'
self.workerOutput = [] self.workerOutput = []
# Multithreading KindleUnpack in current form is a waste of resources. # Multithreading KindleUnpack in current form is a waste of resources.
# Unless we higly optimise KindleUnpack or drop 32bit support this will not change. # Unless we higly optimise KindleUnpack or drop 32bit support this will not change.
@@ -478,15 +484,15 @@ class WorkerThread(QtCore.QThread):
break break
if not self.errors: if not self.errors:
for item in outputPath: for item in outputPath:
GUIMain.progress.content = '' GUI.progress.content = ''
mobiPath = item.replace('.epub', '.mobi') mobiPath = item.replace('.epub', '.mobi')
os.remove(mobiPath + '_toclean') os.remove(mobiPath + '_toclean')
GUIMain.completedWork[os.path.basename(mobiPath).encode('utf-8')] = \ GUI.completedWork[os.path.basename(mobiPath).encode('utf-8')] = \
mobiPath.encode('utf-8') mobiPath.encode('utf-8')
self.emit(QtCore.SIGNAL("addMessage"), 'Cleaning MOBI files... <b>Done!</b>', 'info', self.emit(QtCore.SIGNAL("addMessage"), 'Cleaning MOBI files... <b>Done!</b>', 'info',
True) True)
else: else:
GUIMain.progress.content = '' GUI.progress.content = ''
for item in outputPath: for item in outputPath:
mobiPath = item.replace('.epub', '.mobi') mobiPath = item.replace('.epub', '.mobi')
if os.path.exists(mobiPath): if os.path.exists(mobiPath):
@@ -497,7 +503,7 @@ class WorkerThread(QtCore.QThread):
self.emit(QtCore.SIGNAL("addTrayMessage"), 'KindleUnpack failed to clean MOBI file!', self.emit(QtCore.SIGNAL("addTrayMessage"), 'KindleUnpack failed to clean MOBI file!',
'Critical') 'Critical')
else: else:
GUIMain.progress.content = '' GUI.progress.content = ''
epubSize = (os.path.getsize(self.kindlegenErrorCode[2]))/1024/1024 epubSize = (os.path.getsize(self.kindlegenErrorCode[2]))/1024/1024
for item in outputPath: for item in outputPath:
if os.path.exists(item): if os.path.exists(item):
@@ -516,11 +522,11 @@ class WorkerThread(QtCore.QThread):
' Supported size: ~300MB.', 'error') ' Supported size: ~300MB.', 'error')
else: else:
for item in outputPath: for item in outputPath:
GUIMain.completedWork[os.path.basename(item).encode('utf-8')] = item.encode('utf-8') GUI.completedWork[os.path.basename(item).encode('utf-8')] = item.encode('utf-8')
GUIMain.progress.content = '' GUI.progress.content = ''
GUIMain.progress.stop() GUI.progress.stop()
self.emit(QtCore.SIGNAL("hideProgressBar")) self.emit(QtCore.SIGNAL("hideProgressBar"))
GUIMain.needClean = True GUI.needClean = True
self.emit(QtCore.SIGNAL("addMessage"), '<b>All jobs completed.</b>', 'info') self.emit(QtCore.SIGNAL("addMessage"), '<b>All jobs completed.</b>', 'info')
self.emit(QtCore.SIGNAL("addTrayMessage"), 'All jobs completed.', 'Information') self.emit(QtCore.SIGNAL("addTrayMessage"), 'All jobs completed.', 'Information')
self.emit(QtCore.SIGNAL("modeConvert"), True) self.emit(QtCore.SIGNAL("modeConvert"), True)
@@ -530,27 +536,27 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
def __init__(self, parent=None): def __init__(self, parent=None):
if not sys.platform.startswith('darwin') and self.isSystemTrayAvailable(): if not sys.platform.startswith('darwin') and self.isSystemTrayAvailable():
QtGui.QSystemTrayIcon.__init__(self, parent) QtGui.QSystemTrayIcon.__init__(self, parent)
self.setIcon(GUIMain.icons.programIcon) self.setIcon(GUI.icons.programIcon)
self.activated.connect(self.catchClicks) self.activated.connect(self.catchClicks)
def catchClicks(self): def catchClicks(self):
MainWindow.raise_() MW.raise_()
MainWindow.activateWindow() MW.activateWindow()
def addTrayMessage(self, message, icon): def addTrayMessage(self, message, icon):
if not sys.platform.startswith('darwin'): if not sys.platform.startswith('darwin'):
icon = eval('QtGui.QSystemTrayIcon.' + icon) icon = eval('QtGui.QSystemTrayIcon.' + icon)
if self.supportsMessages() and not MainWindow.isActiveWindow(): if self.supportsMessages() and not MW.isActiveWindow():
self.showMessage('Kindle Comic Converter', message, icon) self.showMessage('Kindle Comic Converter', message, icon)
class Ui_KCC(object): class KCCGUI(KCC_ui.Ui_KCC):
def selectDir(self): def selectDir(self):
if self.needClean: if self.needClean:
self.needClean = False self.needClean = False
GUI.JobList.clear() GUI.JobList.clear()
# Dirty, dirty way but OS native QFileDialogs don't support directory multiselect # Dirty, dirty way but OS native QFileDialogs don't support directory multiselect
dirDialog = QtGui.QFileDialog(MainWindow, 'Select directory', self.lastPath) dirDialog = QtGui.QFileDialog(MW, 'Select directory', self.lastPath)
dirDialog.setFileMode(dirDialog.Directory) dirDialog.setFileMode(dirDialog.Directory)
dirDialog.setOption(dirDialog.ShowDirsOnly, True) dirDialog.setOption(dirDialog.ShowDirsOnly, True)
dirDialog.setOption(dirDialog.DontUseNativeDialog, True) dirDialog.setOption(dirDialog.DontUseNativeDialog, True)
@@ -570,7 +576,7 @@ class Ui_KCC(object):
dname = dname.replace('/', '\\') dname = dname.replace('/', '\\')
self.lastPath = os.path.abspath(os.path.join(unicode(dname), os.pardir)) self.lastPath = os.path.abspath(os.path.join(unicode(dname), os.pardir))
GUI.JobList.addItem(dname) GUI.JobList.addItem(dname)
MainWindow.setFocus() MW.setFocus()
def selectFile(self): def selectFile(self):
if self.needClean: if self.needClean:
@@ -578,17 +584,17 @@ class Ui_KCC(object):
GUI.JobList.clear() GUI.JobList.clear()
if self.UnRAR: if self.UnRAR:
if self.sevenza: if self.sevenza:
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath, fnames = QtGui.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf') '*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf')
else: else:
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath, fnames = QtGui.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'*.cbz *.cbr *.zip *.rar *.pdf') '*.cbz *.cbr *.zip *.rar *.pdf')
else: else:
if self.sevenza: if self.sevenza:
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath, fnames = QtGui.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'*.cbz *.cb7 *.zip *.7z *.pdf') '*.cbz *.cb7 *.zip *.7z *.pdf')
else: else:
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath, fnames = QtGui.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'*.cbz *.zip *.pdf') '*.cbz *.zip *.pdf')
for fname in fnames: for fname in fnames:
if unicode(fname) != "": if unicode(fname) != "":
@@ -601,13 +607,13 @@ class Ui_KCC(object):
def modeBasic(self): def modeBasic(self):
self.currentMode = 1 self.currentMode = 1
if sys.platform.startswith('darwin'): if sys.platform.startswith('darwin'):
MainWindow.setMinimumSize(QtCore.QSize(420, 291)) MW.setMinimumSize(QtCore.QSize(420, 291))
MainWindow.setMaximumSize(QtCore.QSize(420, 291)) MW.setMaximumSize(QtCore.QSize(420, 291))
MainWindow.resize(420, 291) MW.resize(420, 291)
else: else:
MainWindow.setMinimumSize(QtCore.QSize(420, 287)) MW.setMinimumSize(QtCore.QSize(420, 287))
MainWindow.setMaximumSize(QtCore.QSize(420, 287)) MW.setMaximumSize(QtCore.QSize(420, 287))
MainWindow.resize(420, 287) MW.resize(420, 287)
GUI.BasicModeButton.setStyleSheet('font-weight:Bold;') GUI.BasicModeButton.setStyleSheet('font-weight:Bold;')
GUI.AdvModeButton.setStyleSheet('font-weight:Normal;') GUI.AdvModeButton.setStyleSheet('font-weight:Normal;')
GUI.FormatBox.setCurrentIndex(0) GUI.FormatBox.setCurrentIndex(0)
@@ -626,9 +632,9 @@ class Ui_KCC(object):
def modeAdvanced(self): def modeAdvanced(self):
self.currentMode = 2 self.currentMode = 2
MainWindow.setMinimumSize(QtCore.QSize(420, 365)) MW.setMinimumSize(QtCore.QSize(420, 365))
MainWindow.setMaximumSize(QtCore.QSize(420, 365)) MW.setMaximumSize(QtCore.QSize(420, 365))
MainWindow.resize(420, 365) MW.resize(420, 365)
GUI.BasicModeButton.setStyleSheet('font-weight:Normal;') GUI.BasicModeButton.setStyleSheet('font-weight:Normal;')
GUI.AdvModeButton.setStyleSheet('font-weight:Bold;') GUI.AdvModeButton.setStyleSheet('font-weight:Bold;')
GUI.FormatBox.setEnabled(True) GUI.FormatBox.setEnabled(True)
@@ -643,9 +649,9 @@ class Ui_KCC(object):
def modeExpert(self, KFA=False): def modeExpert(self, KFA=False):
self.modeAdvanced() self.modeAdvanced()
self.currentMode = 3 self.currentMode = 3
MainWindow.setMinimumSize(QtCore.QSize(420, 397)) MW.setMinimumSize(QtCore.QSize(420, 397))
MainWindow.setMaximumSize(QtCore.QSize(420, 397)) MW.setMaximumSize(QtCore.QSize(420, 397))
MainWindow.resize(420, 397) MW.resize(420, 397)
GUI.OptionsExpert.setEnabled(True) GUI.OptionsExpert.setEnabled(True)
if KFA: if KFA:
GUI.ColorBox.setChecked(True) GUI.ColorBox.setChecked(True)
@@ -823,7 +829,7 @@ class Ui_KCC(object):
GUI.JobList.scrollToBottom() GUI.JobList.scrollToBottom()
def showDialog(self, message): def showDialog(self, message):
QtGui.QMessageBox.critical(MainWindow, 'KCC - Error', message, QtGui.QMessageBox.Ok) QtGui.QMessageBox.critical(MW, 'KCC - Error', message, QtGui.QMessageBox.Ok)
def updateProgressbar(self, new=False, status=False): def updateProgressbar(self, new=False, status=False):
if new == "status": if new == "status":
@@ -894,8 +900,8 @@ class Ui_KCC(object):
self.settings.sync() self.settings.sync()
def handleMessage(self, message): def handleMessage(self, message):
MainWindow.raise_() MW.raise_()
MainWindow.activateWindow() MW.activateWindow()
if not self.conversionAlive: if not self.conversionAlive:
if self.needClean: if self.needClean:
self.needClean = False self.needClean = False
@@ -919,11 +925,12 @@ class Ui_KCC(object):
else: else:
self.addMessage('This file type is unsupported!', 'error') self.addMessage('This file type is unsupported!', 'error')
def __init__(self, UI, KCC, APP): def __init__(self, KCCAplication, KCCWindow):
global GUI, GUIMain, MainWindow global APP, MW, GUI
GUI = UI APP = KCCAplication
GUIMain = self MW = KCCWindow
MainWindow = KCC GUI = self
self.setupUi(MW)
# User settings will be reverted to default ones if were created in one of the following versions # User settings will be reverted to default ones if were created in one of the following versions
# Empty string cover all versions before this system was implemented # Empty string cover all versions before this system was implemented
purgeSettingsVersions = [''] purgeSettingsVersions = ['']
@@ -1032,16 +1039,16 @@ class Ui_KCC(object):
GUI.ProcessingBox.stateChanged.connect(self.toggleProcessingBox) GUI.ProcessingBox.stateChanged.connect(self.toggleProcessingBox)
GUI.DeviceBox.activated.connect(self.changeDevice) GUI.DeviceBox.activated.connect(self.changeDevice)
GUI.FormatBox.activated.connect(self.changeFormat) GUI.FormatBox.activated.connect(self.changeFormat)
KCC.connect(self.worker, QtCore.SIGNAL("progressBarTick"), self.updateProgressbar) MW.connect(self.worker, QtCore.SIGNAL("progressBarTick"), self.updateProgressbar)
KCC.connect(self.worker, QtCore.SIGNAL("modeConvert"), self.modeConvert) MW.connect(self.worker, QtCore.SIGNAL("modeConvert"), self.modeConvert)
KCC.connect(self.worker, QtCore.SIGNAL("addMessage"), self.addMessage) MW.connect(self.worker, QtCore.SIGNAL("addMessage"), self.addMessage)
KCC.connect(self.worker, QtCore.SIGNAL("addTrayMessage"), self.tray.addTrayMessage) MW.connect(self.worker, QtCore.SIGNAL("addTrayMessage"), self.tray.addTrayMessage)
KCC.connect(self.worker, QtCore.SIGNAL("showDialog"), self.showDialog) MW.connect(self.worker, QtCore.SIGNAL("showDialog"), self.showDialog)
KCC.connect(self.worker, QtCore.SIGNAL("hideProgressBar"), self.hideProgressBar) MW.connect(self.worker, QtCore.SIGNAL("hideProgressBar"), self.hideProgressBar)
KCC.connect(self.versionCheck, QtCore.SIGNAL("addMessage"), self.addMessage) MW.connect(self.versionCheck, QtCore.SIGNAL("addMessage"), self.addMessage)
KCC.connect(self.contentServer, QtCore.SIGNAL("addMessage"), self.addMessage) MW.connect(self.contentServer, QtCore.SIGNAL("addMessage"), self.addMessage)
KCC.connect(self.progress, QtCore.SIGNAL("addMessage"), self.addMessage) MW.connect(self.progress, QtCore.SIGNAL("addMessage"), self.addMessage)
KCC.closeEvent = self.saveSettings MW.closeEvent = self.saveSettings
for f in formats: for f in formats:
GUI.FormatBox.addItem(eval('self.icons.' + f + 'Format'), f) GUI.FormatBox.addItem(eval('self.icons.' + f + 'Format'), f)
@@ -1085,3 +1092,6 @@ class Ui_KCC(object):
self.contentServer.start() self.contentServer.start()
self.hideProgressBar() self.hideProgressBar()
self.worker.sync() self.worker.sync()
MW.setWindowTitle("Kindle Comic Converter " + __version__)
MW.show()
MW.raise_()

View File

@@ -28,6 +28,7 @@ import sys
import re import re
import stat import stat
import string import string
import unicodedata
from tempfile import mkdtemp from tempfile import mkdtemp
from shutil import move, copyfile, copytree, rmtree, make_archive from shutil import move, copyfile, copytree, rmtree, make_archive
from optparse import OptionParser, OptionGroup from optparse import OptionParser, OptionGroup
@@ -42,7 +43,6 @@ import comic2panel
import image import image
import cbxarchive import cbxarchive
import pdfjpgextract import pdfjpgextract
import unicodedata
def buildHTML(path, imgfile): def buildHTML(path, imgfile):

View File

@@ -44,6 +44,14 @@ try:
exit(1) exit(1)
except ImportError: except ImportError:
print "ERROR: Pillow is not installed!" print "ERROR: Pillow is not installed!"
if sys.platform.startswith('linux'):
#noinspection PyUnresolvedReferences
import Tkinter
#noinspection PyUnresolvedReferences
import tkMessageBox
importRoot = Tkinter.Tk()
importRoot.withdraw()
tkMessageBox.showerror("KCC - Error", "Pillow 2.2.1 or newer is required!")
exit(1) exit(1)
try: try:
from PyQt4 import QtCore from PyQt4 import QtCore

View File

@@ -38,6 +38,14 @@ try:
exit(1) exit(1)
except ImportError: except ImportError:
print "ERROR: Pillow is not installed!" print "ERROR: Pillow is not installed!"
if platform.startswith('linux'):
#noinspection PyUnresolvedReferences
import Tkinter
#noinspection PyUnresolvedReferences
import tkMessageBox
importRoot = Tkinter.Tk()
importRoot.withdraw()
tkMessageBox.showerror("KCC - Error", "Pillow 2.2.1 or newer is required!")
exit(1) exit(1)