Get rid of another .ui file and fix that the confirm location dialog had no parent

This commit is contained in:
Kovid Goyal 2024-03-29 09:53:27 +05:30
parent 822646d494
commit bc0b5fdcaf
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 42 additions and 151 deletions

View File

@ -415,7 +415,7 @@ class DeleteAction(InterfaceActionWithLibraryDrop):
if on_device: if on_device:
loc = confirm_location('<p>' + _('Some of the selected books are on the attached device. ' loc = confirm_location('<p>' + _('Some of the selected books are on the attached device. '
'<b>Where</b> do you want the selected files deleted from?'), '<b>Where</b> do you want the selected files deleted from?'),
self.gui) name='device-and-or-lib', parent=self.gui)
if not loc: if not loc:
return return
elif loc == 'dev': elif loc == 'dev':

View File

@ -6,25 +6,50 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' \
'2010, John Schember <john@nachtimwald.com>' '2010, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en' __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 from calibre.startup import connect_lambda
class Dialog(QDialog, Ui_Dialog): class Dialog(QDialog):
def __init__(self, msg, name, parent): def __init__(self, msg, name, parent, icon='dialog_warning.png'):
QDialog.__init__(self, parent) super().__init__(parent)
self.setupUi(self) 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.loc = None
self.msg.setText(msg)
self.name = name 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_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_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_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): def set_loc(self, loc):
self.loc = loc self.loc = loc
@ -43,13 +68,13 @@ class Dialog(QDialog, Ui_Dialog):
def confirm_location(msg, name, parent=None, pixmap='dialog_warning.png'): def confirm_location(msg, name, parent=None, pixmap='dialog_warning.png'):
d = Dialog(msg, name, parent) d = Dialog(msg, name, parent, icon=pixmap)
ic = QIcon.ic(pixmap)
d.label.setPixmap(ic.pixmap(ic.availableSizes()[0]))
d.setWindowIcon(ic)
d.resize(d.sizeHint())
ret = d.exec() ret = d.exec()
d.break_cycles() d.break_cycles()
if ret == QDialog.DialogCode.Accepted: return d.choice() if ret == QDialog.DialogCode.Accepted else None
return d.choice()
return None
if __name__ == '__main__':
from calibre.gui2 import Application
app = Application([])
confirm_location('testing this dialog', 'test dialog')

View File

@ -1,134 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>459</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Where do you want to delete from?</string>
</property>
<property name="windowIcon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/dialog_warning.png</normaloff>:/images/dialog_warning.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="pixmap">
<pixmap resource="../../../../resources/images.qrc">:/images/dialog_warning.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="msg">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="button_lib">
<property name="text">
<string>Library</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/lt.png</normaloff>:/images/lt.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_device">
<property name="text">
<string>Device</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/reader.png</normaloff>:/images/reader.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_both">
<property name="text">
<string>Library and device</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/trash.png</normaloff>:/images/trash.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../../../resources/images.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>