diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index f761453e43..2bcb049a9a 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -415,7 +415,7 @@ class DeleteAction(InterfaceActionWithLibraryDrop): if on_device: loc = confirm_location('

' + _('Some of the selected books are on the attached device. ' 'Where do you want the selected files deleted from?'), - self.gui) + name='device-and-or-lib', parent=self.gui) if not loc: return elif loc == 'dev': diff --git a/src/calibre/gui2/dialogs/confirm_delete_location.py b/src/calibre/gui2/dialogs/confirm_delete_location.py index 3dacabbde0..acad8e9fb7 100644 --- a/src/calibre/gui2/dialogs/confirm_delete_location.py +++ b/src/calibre/gui2/dialogs/confirm_delete_location.py @@ -6,25 +6,50 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' \ '2010, John Schember ' __docformat__ = 'restructuredtext en' -from qt.core import QDialog, QIcon, Qt +from qt.core import QDialog, QIcon, Qt, QVBoxLayout, QHBoxLayout, QSizePolicy, QLabel, QPushButton -from calibre.gui2.dialogs.confirm_delete_location_ui import Ui_Dialog from calibre.startup import connect_lambda -class Dialog(QDialog, Ui_Dialog): +class Dialog(QDialog): - def __init__(self, msg, name, parent): - QDialog.__init__(self, parent) - self.setupUi(self) + def __init__(self, msg, name, parent, icon='dialog_warning.png'): + super().__init__(parent) + ic = QIcon.ic(icon) + self.setWindowIcon(ic) + self.l = l = QVBoxLayout(self) + h = QHBoxLayout() + la = QLabel(self) + sp = QSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Preferred) + sp.setHorizontalStretch(0), sp.setVerticalStretch(0) + sp.setHeightForWidth(la.sizePolicy().hasHeightForWidth()) + la.setSizePolicy(sp) + la.setPixmap(ic.pixmap(ic.availableSizes()[0])) + h.addWidget(la) + la = QLabel(msg) + h.addWidget(la) + la.setWordWrap(True) + l.addLayout(h) + h = QHBoxLayout() + l.addLayout(h) + self.button_lib = b = QPushButton(QIcon.ic('lt.png'), _('&Library'), self) + h.addWidget(b) + self.button_device = b = QPushButton(QIcon.ic('reader.png'), _('&Device'), self) + h.addWidget(b) + self.button_both = b = QPushButton(QIcon.ic('trash.png'), _('Library &and device'), self) + h.addWidget(b) + h.addStretch(10) + self.button_cancel = b = QPushButton(QIcon.ic('window-close.png'), _('&Cancel'), self) + h.addWidget(b) self.loc = None - self.msg.setText(msg) self.name = name - self.buttonBox.setFocus(Qt.FocusReason.OtherFocusReason) + self.button_cancel.setFocus(Qt.FocusReason.OtherFocusReason) connect_lambda(self.button_lib.clicked, self, lambda self: self.set_loc('lib')) connect_lambda(self.button_device.clicked, self, lambda self: self.set_loc('dev')) connect_lambda(self.button_both.clicked, self, lambda self: self.set_loc('both')) + connect_lambda(self.button_cancel.clicked, self, lambda self: self.reject()) + self.resize(self.sizeHint()) def set_loc(self, loc): self.loc = loc @@ -43,13 +68,13 @@ class Dialog(QDialog, Ui_Dialog): def confirm_location(msg, name, parent=None, pixmap='dialog_warning.png'): - d = Dialog(msg, name, parent) - ic = QIcon.ic(pixmap) - d.label.setPixmap(ic.pixmap(ic.availableSizes()[0])) - d.setWindowIcon(ic) - d.resize(d.sizeHint()) + d = Dialog(msg, name, parent, icon=pixmap) ret = d.exec() d.break_cycles() - if ret == QDialog.DialogCode.Accepted: - return d.choice() - return None + return d.choice() if ret == QDialog.DialogCode.Accepted else None + + +if __name__ == '__main__': + from calibre.gui2 import Application + app = Application([]) + confirm_location('testing this dialog', 'test dialog') diff --git a/src/calibre/gui2/dialogs/confirm_delete_location.ui b/src/calibre/gui2/dialogs/confirm_delete_location.ui deleted file mode 100644 index 45084daa0d..0000000000 --- a/src/calibre/gui2/dialogs/confirm_delete_location.ui +++ /dev/null @@ -1,134 +0,0 @@ - - - Dialog - - - - 0 - 0 - 459 - 300 - - - - Where do you want to delete from? - - - - :/images/dialog_warning.png:/images/dialog_warning.png - - - - - - - - - 0 - 0 - - - - :/images/dialog_warning.png - - - - - - - - - - true - - - - - - - - - - - Library - - - - :/images/lt.png:/images/lt.png - - - - - - - Device - - - - :/images/reader.png:/images/reader.png - - - - - - - Library and device - - - - :/images/trash.png:/images/trash.png - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel - - - - - - - - - - - - - buttonBox - accepted() - Dialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - Dialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - -