More stupid PyQt enums

This commit is contained in:
Kovid Goyal 2020-12-09 20:58:05 +05:30
parent e0ea8ebc5b
commit a5eca3843b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
17 changed files with 48 additions and 47 deletions

View File

@ -41,7 +41,7 @@ class AddFromISBN(QDialog):
self.h = h = QHBoxLayout()
l.addLayout(h)
self.bb = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok|QDialogButtonBox.StandardButton.Cancel, self)
bb.button(bb.Ok).setText(_('&OK'))
bb.button(QDialogButtonBox.StandardButton.Ok).setText(_('&OK'))
l.addWidget(bb), bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
self.ll = l = QVBoxLayout()
h.addLayout(l)

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
from PyQt5.Qt import (
QVBoxLayout, QSplitter, QWidget, QLabel, QCheckBox, QTextBrowser, Qt, QDialog
QVBoxLayout, QSplitter, QWidget, QLabel, QCheckBox, QTextBrowser, Qt, QDialog, QDialogButtonBox
)
from calibre.ebooks.metadata import authors_to_string
@ -57,7 +57,7 @@ class ConfirmMerge(Dialog):
self.splitter = s = QSplitter(self)
s.setChildrenCollapsible(False)
l.addWidget(s), l.addWidget(self.bb)
self.bb.setStandardButtons(self.bb.Yes | self.bb.No)
self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Yes | QDialogButtonBox.StandardButton.No)
self.left = w = QWidget(self)
s.addWidget(w)
@ -103,7 +103,7 @@ class ChooseMerge(Dialog):
self.splitter = s = QSplitter(self)
s.setChildrenCollapsible(False)
l.addWidget(s), l.addWidget(self.bb)
self.bb.setStandardButtons(self.bb.Yes | self.bb.No)
self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Yes | QDialogButtonBox.StandardButton.No)
self.left = w = QWidget(self)
s.addWidget(w)
w.l = l = QVBoxLayout(w)

View File

@ -11,7 +11,7 @@ from PyQt5.Qt import (
QVBoxLayout, QStackedWidget, QSize, QPushButton, QIcon, QWidget, QListView,
QHBoxLayout, QAbstractListModel, Qt, QLabel, QSizePolicy, pyqtSignal, QSortFilterProxyModel,
QFormLayout, QSpinBox, QLineEdit, QGroupBox, QListWidget, QListWidgetItem,
QToolButton, QTreeView, QDialog)
QToolButton, QTreeView, QDialog, QDialogButtonBox)
from calibre.gui2 import error_dialog, open_local_file, choose_files, choose_save_file
from calibre.gui2.dialogs.confirm_delete import confirm as confirm_delete
@ -589,7 +589,7 @@ class CustomRecipes(Dialog):
b.setIcon(QIcon(I(icon))), b.setToolTip(tooltip)
b.clicked.connect(receiver)
else:
bb.setStandardButtons(bb.Cancel | bb.Save)
bb.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Save)
if self.stack.currentIndex() == 1:
text = _('S&witch to advanced mode')
tooltip = _('Edit this recipe in advanced mode')

View File

@ -88,7 +88,7 @@ class RunAction(QDialog):
def setup_ui(self):
self.l = l = QGridLayout(self)
self.bb = QDialogButtonBox(self)
self.bb.setStandardButtons(self.bb.Cancel)
self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Cancel)
self.bb.rejected.connect(self.reject)
self.la1 = la = QLabel('<h2>' + self.title)
@ -125,7 +125,7 @@ class RunAction(QDialog):
def reject(self):
self.abort.set()
self.bb.button(self.bb.Cancel).setEnabled(False)
self.bb.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
def finish_processing(self):
if self.abort.is_set():
@ -327,7 +327,7 @@ class EximDialog(Dialog):
def show_panel(self, which):
self.validate = self.run_action = lambda : True
if which is None:
self.bb.setStandardButtons(self.bb.Cancel)
self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Cancel)
else:
if which == 'export':
self.validate = self.validate_export
@ -338,7 +338,7 @@ class EximDialog(Dialog):
else:
self.validate = self.validate_import
self.run_action = self.run_import_action
self.bb.setStandardButtons(self.bb.Ok | self.bb.Cancel)
self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
self.stack.setCurrentIndex({'export':1, 'import':2}.get(which, 0))
def validate_export(self):

View File

@ -124,20 +124,20 @@ class MessageBox(QDialog): # {{{
self.is_question = type_ == self.QUESTION
if self.is_question:
self.bb.setStandardButtons(self.bb.Yes|self.bb.No)
self.bb.button(self.bb.Yes if default_yes else self.bb.No
self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Yes|QDialogButtonBox.StandardButton.No)
self.bb.button(QDialogButtonBox.StandardButton.Yes if default_yes else QDialogButtonBox.StandardButton.No
).setDefault(True)
self.default_yes = default_yes
if yes_text is not None:
self.bb.button(self.bb.Yes).setText(yes_text)
self.bb.button(QDialogButtonBox.StandardButton.Yes).setText(yes_text)
if no_text is not None:
self.bb.button(self.bb.No).setText(no_text)
self.bb.button(QDialogButtonBox.StandardButton.No).setText(no_text)
if yes_icon is not None:
self.bb.button(self.bb.Yes).setIcon(yes_icon if isinstance(yes_icon, QIcon) else QIcon(I(yes_icon)))
self.bb.button(QDialogButtonBox.StandardButton.Yes).setIcon(yes_icon if isinstance(yes_icon, QIcon) else QIcon(I(yes_icon)))
if no_icon is not None:
self.bb.button(self.bb.No).setIcon(no_icon if isinstance(no_icon, QIcon) else QIcon(I(no_icon)))
self.bb.button(QDialogButtonBox.StandardButton.No).setIcon(no_icon if isinstance(no_icon, QIcon) else QIcon(I(no_icon)))
else:
self.bb.button(self.bb.Ok).setDefault(True)
self.bb.button(QDialogButtonBox.StandardButton.Ok).setDefault(True)
if not det_msg:
self.det_msg_toggle.setVisible(False)
@ -173,12 +173,12 @@ class MessageBox(QDialog): # {{{
ret = QDialog.showEvent(self, ev)
if self.is_question:
try:
self.bb.button(self.bb.Yes if self.default_yes else self.bb.No
self.bb.button(QDialogButtonBox.StandardButton.Yes if self.default_yes else QDialogButtonBox.StandardButton.No
).setFocus(Qt.FocusReason.OtherFocusReason)
except:
pass # Buttons were changed
else:
self.bb.button(self.bb.Ok).setFocus(Qt.FocusReason.OtherFocusReason)
self.bb.button(QDialogButtonBox.StandardButton.Ok).setFocus(Qt.FocusReason.OtherFocusReason)
return ret
def set_details(self, msg):

View File

@ -10,7 +10,7 @@ from PyQt5.Qt import (
QApplication, QCheckBox, QComboBox, QCursor, QDateTime, QFont, QFormLayout, QDialog,
QHBoxLayout, QIcon, QKeySequence, QLabel, QMenu, QPalette, QPlainTextEdit, QSize,
QSplitter, Qt, QTextBrowser, QTimer, QToolButton, QTreeWidget, QTreeWidgetItem,
QVBoxLayout, QWidget, pyqtSignal, QAbstractItemView
QVBoxLayout, QWidget, pyqtSignal, QAbstractItemView, QDialogButtonBox
)
from calibre import prepare_string_for_xml
@ -125,7 +125,7 @@ class Export(Dialog): # {{{
l.addRow(_('Format to export in:'), ef)
l.addRow(self.bb)
self.bb.clear()
self.bb.addButton(self.bb.Cancel)
self.bb.addButton(QDialogButtonBox.StandardButton.Cancel)
b = self.bb.addButton(_('Copy to clipboard'), self.bb.ActionRole)
b.clicked.connect(self.copy_to_clipboard)
b.setIcon(QIcon(I('edit-copy.png')))

View File

@ -557,7 +557,7 @@ class CompareMany(QDialog):
sa.setWidgetResizable(True)
self.bb = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Cancel)
bb.button(bb.Cancel).setAutoDefault(False)
bb.button(QDialogButtonBox.StandardButton.Cancel).setAutoDefault(False)
bb.rejected.connect(self.reject)
if self.total > 1:
self.aarb = b = bb.addButton(_('&Accept all remaining'), bb.YesRole)

View File

@ -11,7 +11,7 @@ from threading import Thread
from glob import glob
from PyQt5.Qt import (
QDialog, QApplication, QLabel, QVBoxLayout, QDialogButtonBox, Qt, QAbstractItemView,
QDialog, QApplication, QLabel, QVBoxLayout, QDialogButtonBox, Qt, QAbstractItemView, QListView,
pyqtSignal, QListWidget, QListWidgetItem, QSize, QPixmap, QStyledItemDelegate
)
try:

View File

@ -95,8 +95,8 @@ class MetadataSingleDialogBase(QDialog):
self.button_box.addButton(self.prev_button, bb.ActionRole)
self.button_box.addButton(self.next_button, bb.ActionRole)
self.prev_button.clicked.connect(self.prev_clicked)
bb.setStandardButtons(bb.Ok|bb.Cancel)
bb.button(bb.Ok).setDefault(True)
bb.setStandardButtons(QDialogButtonBox.StandardButton.Ok|QDialogButtonBox.StandardButton.Cancel)
bb.button(QDialogButtonBox.StandardButton.Ok).setDefault(True)
self.central_widget = QTabWidget(self)

View File

@ -1034,7 +1034,7 @@ class FullFetch(QDialog): # {{{
l.addLayout(h)
self.bb.rejected.connect(self.reject)
self.bb.accepted.connect(self.accept)
self.ok_button = self.bb.button(self.bb.Ok)
self.ok_button = self.bb.button(QDialogButtonBox.StandardButton.Ok)
self.ok_button.setEnabled(False)
self.ok_button.clicked.connect(self.ok_clicked)
self.prev_button = pb = QPushButton(QIcon(I('back.png')), _('&Back'), self)

View File

@ -357,15 +357,15 @@ def show_config_widget(category, name, gui=None, show_restart_msg=False,
d.setWindowTitle(_('Configure ') + pl.gui_name)
d.setWindowIcon(QIcon(I('config.png')))
bb = QDialogButtonBox(d)
bb.setStandardButtons(bb.Apply|bb.Cancel|bb.RestoreDefaults)
bb.setStandardButtons(QDialogButtonBox.StandardButton.Apply|QDialogButtonBox.StandardButton.Cancel|QDialogButtonBox.StandardButton.RestoreDefaults)
bb.accepted.connect(d.accept)
bb.rejected.connect(d.reject)
w = pl.create_widget(d)
d.set_widget(w)
bb.button(bb.RestoreDefaults).clicked.connect(w.restore_defaults)
bb.button(bb.RestoreDefaults).setEnabled(w.supports_restoring_to_defaults)
bb.button(bb.Apply).setEnabled(False)
bb.button(bb.Apply).clicked.connect(d.accept)
bb.button(QDialogButtonBox.StandardButton.RestoreDefaults).clicked.connect(w.restore_defaults)
bb.button(QDialogButtonBox.StandardButton.RestoreDefaults).setEnabled(w.supports_restoring_to_defaults)
bb.button(QDialogButtonBox.StandardButton.Apply).setEnabled(False)
bb.button(QDialogButtonBox.StandardButton.Apply).clicked.connect(d.accept)
def onchange():
b = bb.button(bb.Apply)
@ -373,7 +373,7 @@ def show_config_widget(category, name, gui=None, show_restart_msg=False,
b.setDefault(True)
b.setAutoDefault(True)
w.changed_signal.connect(onchange)
bb.button(bb.Cancel).setFocus(True)
bb.button(QDialogButtonBox.StandardButton.Cancel).setFocus(True)
l = QVBoxLayout()
d.setLayout(l)
l.addWidget(w)

View File

@ -130,8 +130,9 @@ class ProceedQuestion(QWidget):
_('Show detailed information about this error'))
self.det_msg = PlainTextEdit(self)
self.det_msg.setReadOnly(True)
self.bb.setStandardButtons(self.bb.Yes|self.bb.No|self.bb.Ok)
self.bb.button(self.bb.Yes).setDefault(True)
self.bb.setStandardButtons(
QDialogButtonBox.StandardButton.Yes | QDialogButtonBox.StandardButton.No | QDialogButtonBox.StandardButton.Ok)
self.bb.button(QDialogButtonBox.StandardButton.Yes).setDefault(True)
self.title_label = title = QLabel('A dummy title')
f = title.font()
f.setBold(True)
@ -249,15 +250,15 @@ class ProceedQuestion(QWidget):
if question.checkbox_msg is not None:
self.checkbox.setText(question.checkbox_msg)
self.checkbox.setChecked(question.checkbox_checked)
self.bb.button(self.bb.Ok).setVisible(question.show_ok)
self.bb.button(self.bb.Yes).setVisible(not question.show_ok)
self.bb.button(self.bb.No).setVisible(not question.show_ok)
self.bb.button(QDialogButtonBox.StandardButton.Ok).setVisible(question.show_ok)
self.bb.button(QDialogButtonBox.StandardButton.Yes).setVisible(not question.show_ok)
self.bb.button(QDialogButtonBox.StandardButton.No).setVisible(not question.show_ok)
self.copy_button.setVisible(bool(question.show_copy_button))
self.action_button.setVisible(question.action_callback is not None)
self.toggle_det_msg() if question.show_det else self.do_resize()
self.show_widget()
button = self.action_button if question.focus_action and question.action_callback is not None else \
(self.bb.button(self.bb.Ok) if question.show_ok else self.bb.button(self.bb.Yes))
(self.bb.button(QDialogButtonBox.StandardButton.Ok) if question.show_ok else self.bb.button(QDialogButtonBox.StandardButton.Yes))
button.setDefault(True)
self.raise_()
self.start_show_animation()

View File

@ -7,7 +7,7 @@ from threading import Thread
from PyQt5.Qt import (
pyqtSignal, QWidget, QListWidget, QListWidgetItem, QLabel, Qt,
QVBoxLayout, QScrollArea, QProgressBar, QGridLayout, QSize, QIcon)
QVBoxLayout, QScrollArea, QProgressBar, QGridLayout, QSize, QIcon, QDialogButtonBox)
from calibre.gui2 import error_dialog, info_dialog, warning_dialog
from calibre.gui2.tweak_book import current_container
@ -224,8 +224,8 @@ class DownloadResources(Dialog):
self.state = 3
self.bb.clear()
self.resources_replaced = True
self.bb.setStandardButtons(self.bb.Ok | self.bb.Close)
b = self.bb.button(self.bb.Ok)
self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Close)
b = self.bb.button(QDialogButtonBox.StandardButton.Ok)
b.setText(_('See what &changed'))
b.setIcon(QIcon(I('diff.png')))
connect_lambda(b.clicked, self, lambda self: setattr(self, 'show_diff', True))

View File

@ -12,7 +12,7 @@ from PyQt5.Qt import (
QAbstractListModel, QApplication, QCheckBox, QFormLayout, QGridLayout,
QHBoxLayout, QIcon, QInputDialog, QLabel, QLineEdit, QListView, QMenu, QPainter,
QPixmap, QRect, QSize, QSizePolicy, QSortFilterProxyModel, QStyledItemDelegate,
Qt, QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, pyqtSignal, QDialog
Qt, QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, pyqtSignal, QDialog, QDialogButtonBox
)
from calibre import fit_image
@ -465,7 +465,7 @@ class NewBook(Dialog): # {{{
bb = self.bb
l.addRow(bb)
bb.clear()
bb.addButton(bb.Cancel)
bb.addButton(QDialogButtonBox.StandardButton.Cancel)
b = bb.addButton('&EPUB', bb.AcceptRole)
connect_lambda(b.clicked, self, lambda self: self.set_fmt('epub'))
b = bb.addButton('&AZW3', bb.AcceptRole)

View File

@ -980,7 +980,7 @@ class NewFileDialog(QDialog): # {{{
' file into the book.'))
b.clicked.connect(self.import_file)
self.ok_button = bb.button(bb.Ok)
self.ok_button = bb.button(QDialogButtonBox.StandardButton.Ok)
self.file_data = b''
self.using_template = False

View File

@ -274,12 +274,12 @@ class CompressImagesProgress(Dialog):
la.setAlignment(Qt.AlignmentFlag.AlignCenter), la.setTextFormat(Qt.TextFormat.PlainText)
l.addWidget(la)
self.bb.setStandardButtons(self.bb.Cancel)
self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Cancel)
l.addWidget(self.bb)
def reject(self):
self.keep_going = False
self.bb.button(self.bb.Cancel).setEnabled(False)
self.bb.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
Dialog.reject(self)
def progress_callback(self, num, total, name):

View File

@ -163,7 +163,7 @@ class UpdateNotification(QDialog):
b = self.bb.addButton(_('Update &plugins'), self.bb.ActionRole)
b.setIcon(QIcon(I('plugins/plugin_updater.png')))
b.clicked.connect(self.get_plugins, type=Qt.ConnectionType.QueuedConnection)
self.bb.addButton(self.bb.Cancel)
self.bb.addButton(QDialogButtonBox.StandardButton.Cancel)
self.l.addWidget(self.bb, 2, 0, 1, -1)
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)