diff --git a/KCC-Linux.ui b/KCC-Linux.ui index 365b911..04328ed 100644 --- a/KCC-Linux.ui +++ b/KCC-Linux.ui @@ -28,7 +28,7 @@ - Qt::NoFocus + Qt::StrongFocus Kindle Comic Converter diff --git a/KCC-OSX.ui b/KCC-OSX.ui index ef8a83d..32d6f6a 100644 --- a/KCC-OSX.ui +++ b/KCC-OSX.ui @@ -28,7 +28,7 @@ - Qt::NoFocus + Qt::StrongFocus Kindle Comic Converter diff --git a/KCC.ui b/KCC.ui index 9226306..acb0305 100644 --- a/KCC.ui +++ b/KCC.ui @@ -28,7 +28,7 @@ - Qt::NoFocus + Qt::StrongFocus Kindle Comic Converter diff --git a/kcc/KCC_gui.py b/kcc/KCC_gui.py index cee55fc..f85e2c6 100644 --- a/kcc/KCC_gui.py +++ b/kcc/KCC_gui.py @@ -75,6 +75,9 @@ class Icons: self.error = QtGui.QIcon() self.error.addPixmap(QtGui.QPixmap(":/Status/icons/error.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.programIcon = QtGui.QIcon() + self.programIcon.addPixmap(QtGui.QPixmap(":/Icon/icons/comic2ebook.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + class HTMLStripper(HTMLParser): def __init__(self): @@ -325,6 +328,7 @@ class WorkerThread(QtCore.QThread): GUIMain.needClean = True self.emit(QtCore.SIGNAL("hideProgressBar")) self.emit(QtCore.SIGNAL("addMessage"), 'Conversion interrupted.', 'error') + self.emit(QtCore.SIGNAL("addTrayMessage"), 'Conversion interrupted.', 'Critical') self.emit(QtCore.SIGNAL("modeConvert"), True) def addResult(self, output): @@ -404,6 +408,7 @@ class WorkerThread(QtCore.QThread): self.errors = True self.emit(QtCore.SIGNAL("addMessage"), str(warn), 'warning') self.emit(QtCore.SIGNAL("addMessage"), 'Failed to create output file!', 'warning') + self.emit(QtCore.SIGNAL("addTrayMessage"), 'Failed to create output file!', 'Critical') except Exception as err: GUIMain.progress.content = '' self.errors = True @@ -411,6 +416,7 @@ class WorkerThread(QtCore.QThread): self.emit(QtCore.SIGNAL("showDialog"), "Error during conversion %s:\n\n%s\n\nTraceback:\n%s" % (jobargv[-1], str(err), traceback.format_tb(traceback_))) self.emit(QtCore.SIGNAL("addMessage"), 'Failed to create EPUB!', 'error') + self.emit(QtCore.SIGNAL("addTrayMessage"), 'Failed to create EPUB!', 'Critical') if not self.conversionAlive: for item in outputPath: if os.path.exists(item): @@ -488,6 +494,8 @@ class WorkerThread(QtCore.QThread): if os.path.exists(mobiPath + '_toclean'): os.remove(mobiPath + '_toclean') self.emit(QtCore.SIGNAL("addMessage"), 'KindleUnpack failed to clean MOBI file!', 'error') + self.emit(QtCore.SIGNAL("addTrayMessage"), 'KindleUnpack failed to clean MOBI file!', + 'Critical') else: GUIMain.progress.content = '' epubSize = (os.path.getsize(self.kindlegenErrorCode[2]))/1024/1024 @@ -497,6 +505,7 @@ class WorkerThread(QtCore.QThread): if os.path.exists(item.replace('.epub', '.mobi')): os.remove(item.replace('.epub', '.mobi')) self.emit(QtCore.SIGNAL("addMessage"), 'KindleGen failed to create MOBI!', 'error') + self.emit(QtCore.SIGNAL("addTrayMessage"), 'KindleGen failed to create MOBI!', 'Critical') if self.kindlegenErrorCode[0] == 1 and self.kindlegenErrorCode[1] != '': self.emit(QtCore.SIGNAL("showDialog"), "KindleGen error:\n\n" + self.self.kindlegenErrorCode[1]) @@ -513,9 +522,32 @@ class WorkerThread(QtCore.QThread): self.emit(QtCore.SIGNAL("hideProgressBar")) GUIMain.needClean = True self.emit(QtCore.SIGNAL("addMessage"), 'All jobs completed.', 'info') + self.emit(QtCore.SIGNAL("addTrayMessage"), 'All jobs completed.', 'Information') self.emit(QtCore.SIGNAL("modeConvert"), True) +class SystemTrayIcon(QtGui.QSystemTrayIcon): + def __init__(self, parent=None): + QtGui.QSystemTrayIcon.__init__(self, parent) + self.setIcon(GUIMain.icons.programIcon) + self.activated.connect(self.catchClicks) + + def catchClicks(self): + MainWindow.raise_() + MainWindow.activateWindow() + + def addTrayMessage(self, message, icon): + icon = eval('QtGui.QSystemTrayIcon.' + icon) + if self.supportsMessages() and not MainWindow.isActiveWindow(): + self.showMessage('Kindle Comic Converter', message, icon) + + def focusChange(self, _): + if self.isSystemTrayAvailable() and not MainWindow.isActiveWindow(): + self.show() + else: + self.hide() + + class Ui_KCC(object): def selectDir(self): if self.needClean: @@ -542,6 +574,7 @@ class Ui_KCC(object): dname = dname.replace('/', '\\') self.lastPath = os.path.abspath(os.path.join(unicode(dname), os.pardir)) GUI.JobList.addItem(dname) + MainWindow.setFocus() def selectFile(self): if self.needClean: @@ -893,6 +926,7 @@ class Ui_KCC(object): purgeSettingsVersions = [''] self.icons = Icons() self.webContent = WebContent() + self.tray = SystemTrayIcon() self.settings = QtCore.QSettings('KindleComicConverter', 'KindleComicConverter') self.settingsVersion = self.settings.value('settingsVersion', '', type=str) if self.settingsVersion in purgeSettingsVersions: @@ -962,6 +996,8 @@ class Ui_KCC(object): self.addMessage('Cannot find 7za!' ' Processing of CB7/7Z files will be disabled.', 'warning') + KCC.focusInEvent = self.tray.focusChange + KCC.focusOutEvent = self.tray.focusChange APP.connect(APP, QtCore.SIGNAL('messageFromOtherInstance'), self.handleMessage) GUI.BasicModeButton.clicked.connect(self.modeBasic) GUI.AdvModeButton.clicked.connect(self.modeAdvanced) @@ -978,6 +1014,7 @@ class Ui_KCC(object): KCC.connect(self.worker, QtCore.SIGNAL("progressBarTick"), self.updateProgressbar) KCC.connect(self.worker, QtCore.SIGNAL("modeConvert"), self.modeConvert) KCC.connect(self.worker, QtCore.SIGNAL("addMessage"), self.addMessage) + KCC.connect(self.worker, QtCore.SIGNAL("addTrayMessage"), self.tray.addTrayMessage) KCC.connect(self.worker, QtCore.SIGNAL("showDialog"), self.showDialog) KCC.connect(self.worker, QtCore.SIGNAL("hideProgressBar"), self.hideProgressBar) KCC.connect(self.versionCheck, QtCore.SIGNAL("addMessage"), self.addMessage) diff --git a/kcc/KCC_ui.py b/kcc/KCC_ui.py index ed5385a..70e2a8c 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: Sat Oct 12 11:28:00 2013 +# Created: Tue Nov 12 11:51:07 2013 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! @@ -32,7 +32,7 @@ class Ui_KCC(object): font = QtGui.QFont() font.setPointSize(9) KCC.setFont(font) - KCC.setFocusPolicy(QtCore.Qt.NoFocus) + KCC.setFocusPolicy(QtCore.Qt.StrongFocus) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/Icon/icons/comic2ebook.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) KCC.setWindowIcon(icon) diff --git a/kcc/KCC_ui_linux.py b/kcc/KCC_ui_linux.py index a23678c..e1087fd 100644 --- a/kcc/KCC_ui_linux.py +++ b/kcc/KCC_ui_linux.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'KCC-Linux.ui' # -# Created: Sat Oct 12 11:28:11 2013 +# Created: Tue Nov 12 11:51:18 2013 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! @@ -32,7 +32,7 @@ class Ui_KCC(object): font = QtGui.QFont() font.setPointSize(9) KCC.setFont(font) - KCC.setFocusPolicy(QtCore.Qt.NoFocus) + KCC.setFocusPolicy(QtCore.Qt.StrongFocus) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/Icon/icons/comic2ebook.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) KCC.setWindowIcon(icon) diff --git a/kcc/KCC_ui_osx.py b/kcc/KCC_ui_osx.py index 3417eae..28937a7 100644 --- a/kcc/KCC_ui_osx.py +++ b/kcc/KCC_ui_osx.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'KCC-OSX.ui' # -# Created: Sat Oct 12 11:28:19 2013 +# Created: Tue Nov 12 11:51:32 2013 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! @@ -32,7 +32,7 @@ class Ui_KCC(object): font = QtGui.QFont() font.setPointSize(9) KCC.setFont(font) - KCC.setFocusPolicy(QtCore.Qt.NoFocus) + KCC.setFocusPolicy(QtCore.Qt.StrongFocus) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/Icon/icons/comic2ebook.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) KCC.setWindowIcon(icon)