From dd0ed12cfb8150076c8c051ea1d9b13db0170313 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 7 Nov 2014 20:32:02 +0530 Subject: [PATCH] Allow the progress dialog to have an icon --- src/calibre/gui2/add.py | 2 +- src/calibre/gui2/dialogs/progress.py | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/add.py b/src/calibre/gui2/add.py index d108a4362d..92028345e9 100644 --- a/src/calibre/gui2/add.py +++ b/src/calibre/gui2/add.py @@ -283,7 +283,7 @@ class Adder(QObject): # {{{ def __init__(self, parent, db, callback, spare_server=None): QObject.__init__(self, parent) - self.pd = ProgressDialog(_('Adding...'), parent=parent) + self.pd = ProgressDialog(_('Adding...'), parent=parent, icon='add_book.png') self.pd.setMaximumWidth(min(600, int(available_width()*0.75))) self.spare_server = spare_server self.db = db diff --git a/src/calibre/gui2/dialogs/progress.py b/src/calibre/gui2/dialogs/progress.py index 7da72747e7..7de5069007 100644 --- a/src/calibre/gui2/dialogs/progress.py +++ b/src/calibre/gui2/dialogs/progress.py @@ -5,7 +5,7 @@ __docformat__ = 'restructuredtext en' from PyQt5.Qt import ( QDialog, pyqtSignal, Qt, QVBoxLayout, QLabel, QFont, QProgressBar, - QDialogButtonBox, QApplication, QFontMetrics) + QDialogButtonBox, QApplication, QFontMetrics, QHBoxLayout, QIcon) from calibre.gui2 import elided_text from calibre.gui2.progress_indicator import ProgressIndicator @@ -14,9 +14,20 @@ class ProgressDialog(QDialog): canceled_signal = pyqtSignal() - def __init__(self, title, msg=u'\u00a0', min=0, max=99, parent=None, cancelable=True): + def __init__(self, title, msg=u'\u00a0', min=0, max=99, parent=None, cancelable=True, icon=None): QDialog.__init__(self, parent) - self.l = l = QVBoxLayout(self) + if icon is None: + self.l = l = QVBoxLayout(self) + else: + self.h = h = QHBoxLayout(self) + self.icon = i = QLabel(self) + if not isinstance(icon, QIcon): + icon = QIcon(I(icon)) + i.setPixmap(icon.pixmap(64)) + h.addWidget(i) + self.l = l = QVBoxLayout() + h.addLayout(l) + self.setWindowIcon(icon) self.title = t = QLabel(title) self.setWindowTitle(title) @@ -144,6 +155,6 @@ class BlockingBusy(QDialog): if __name__ == '__main__': app = QApplication([]) - d = ProgressDialog('A title', 'A message ' * 100) + d = ProgressDialog('A title', 'A message ' * 100, icon='lt.png') d.show(), d.canceled_signal.connect(app.quit) app.exec_()