More stupid PyQt enums

This commit is contained in:
Kovid Goyal 2020-12-19 12:38:19 +05:30
parent b30f58703b
commit 63fbb991e1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
16 changed files with 38 additions and 38 deletions

View File

@ -361,7 +361,7 @@ class Report(QDialog): # {{{
self.setWindowTitle(_('Polishing of %s')%book_title) self.setWindowTitle(_('Polishing of %s')%book_title)
self.view.setText(markdown('# %s\n\n'%book_title + report, self.view.setText(markdown('# %s\n\n'%book_title + report,
output_format='html4')) output_format='html4'))
self.bb.button(self.bb.Close).setFocus(Qt.FocusReason.OtherFocusReason) self.bb.button(QDialogButtonBox.StandardButton.Close).setFocus(Qt.FocusReason.OtherFocusReason)
self.backup_msg.setVisible(bool(fmts)) self.backup_msg.setVisible(bool(fmts))
if fmts: if fmts:
m = ngettext('The original file has been saved as %s.', m = ngettext('The original file has been saved as %s.',

View File

@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
import shutil import shutil
from PyQt5.Qt import QModelIndex, QDialog, QApplication from PyQt5.Qt import QModelIndex, QDialog, QApplication, QDialogButtonBox
from calibre.gui2.convert.single import Config, GroupModel, gprefs from calibre.gui2.convert.single import Config, GroupModel, gprefs
from calibre.gui2.convert.look_and_feel import LookAndFeelWidget from calibre.gui2.convert.look_and_feel import LookAndFeelWidget
@ -55,7 +55,7 @@ class BulkConfig(Config):
self.groups.activated[(QModelIndex)].connect(self.show_pane) self.groups.activated[(QModelIndex)].connect(self.show_pane)
self.groups.clicked[(QModelIndex)].connect(self.show_pane) self.groups.clicked[(QModelIndex)].connect(self.show_pane)
self.groups.entered[(QModelIndex)].connect(self.show_group_help) self.groups.entered[(QModelIndex)].connect(self.show_group_help)
rb = self.buttonBox.button(self.buttonBox.RestoreDefaults) rb = self.buttonBox.button(QDialogButtonBox.StandardButton.RestoreDefaults)
rb.setVisible(False) rb.setVisible(False)
self.groups.setMouseTracking(True) self.groups.setMouseTracking(True)
if not has_saved_settings: if not has_saved_settings:

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from PyQt5.Qt import QDialog from PyQt5.Qt import QDialog, QDialogButtonBox
from calibre.gui2.convert.font_key_ui import Ui_Dialog from calibre.gui2.convert.font_key_ui import Ui_Dialog
from calibre.utils.localization import localize_user_manual_link from calibre.utils.localization import localize_user_manual_link
@ -48,7 +48,7 @@ class FontKeyChooser(QDialog, Ui_Dialog):
self.calculate() self.calculate()
def button_clicked(self, button): def button_clicked(self, button):
if button is self.buttonBox.button(self.buttonBox.RestoreDefaults): if button is self.buttonBox.button(QDialogButtonBox.StandardButton.RestoreDefaults):
self.output_base_font_size.setValue(0.0) self.output_base_font_size.setValue(0.0)
self.font_size_key.setText('') self.font_size_key.setText('')
self.calculate() self.calculate()

View File

@ -87,7 +87,7 @@ class Config(QDialog):
self.groups.activated[(QModelIndex)].connect(self.show_pane) self.groups.activated[(QModelIndex)].connect(self.show_pane)
self.groups.clicked[(QModelIndex)].connect(self.show_pane) self.groups.clicked[(QModelIndex)].connect(self.show_pane)
self.groups.entered[(QModelIndex)].connect(self.show_group_help) self.groups.entered[(QModelIndex)].connect(self.show_group_help)
rb = self.buttonBox.button(self.buttonBox.RestoreDefaults) rb = self.buttonBox.button(QDialogButtonBox.StandardButton.RestoreDefaults)
rb.setText(_('Restore &defaults')) rb.setText(_('Restore &defaults'))
rb.clicked.connect(self.restore_defaults) rb.clicked.connect(self.restore_defaults)
self.groups.setMouseTracking(True) self.groups.setMouseTracking(True)

View File

@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
import os, sys, importlib, weakref import os, sys, importlib, weakref
from PyQt5.Qt import QDialog, QCoreApplication, QSize, QScrollArea, QApplication from PyQt5.Qt import QDialog, QCoreApplication, QSize, QScrollArea, QApplication, QDialogButtonBox
from calibre.customize.ui import config from calibre.customize.ui import config
from calibre.gui2.dialogs.catalog_ui import Ui_Dialog from calibre.gui2.dialogs.catalog_ui import Ui_Dialog
@ -124,8 +124,8 @@ class Catalog(QDialog, Ui_Dialog):
self.add_to_library.setChecked(dynamic.get('catalog_add_to_library', True)) self.add_to_library.setChecked(dynamic.get('catalog_add_to_library', True))
self.format.currentIndexChanged.connect(self.show_plugin_tab) self.format.currentIndexChanged.connect(self.show_plugin_tab)
self.buttonBox.button(self.buttonBox.Apply).clicked.connect(self.apply) self.buttonBox.button(QDialogButtonBox.StandardButton.Apply).clicked.connect(self.apply)
self.buttonBox.button(self.buttonBox.Help).clicked.connect(self.help) self.buttonBox.button(QDialogButtonBox.StandardButton.Help).clicked.connect(self.help)
self.show_plugin_tab(None) self.show_plugin_tab(None)
geom = dynamic.get('catalog_window_geom', None) geom = dynamic.get('catalog_window_geom', None)
@ -165,9 +165,9 @@ class Catalog(QDialog, Ui_Dialog):
self.tabs.addTab(s, pw.TITLE) self.tabs.addTab(s, pw.TITLE)
break break
if hasattr(self.options_widget, 'show_help'): if hasattr(self.options_widget, 'show_help'):
self.buttonBox.button(self.buttonBox.Help).setVisible(True) self.buttonBox.button(QDialogButtonBox.StandardButton.Help).setVisible(True)
else: else:
self.buttonBox.button(self.buttonBox.Help).setVisible(False) self.buttonBox.button(QDialogButtonBox.StandardButton.Help).setVisible(False)
def format_changed(self, idx): def format_changed(self, idx):
cf = unicode_type(self.format.currentText()) cf = unicode_type(self.format.currentText())

View File

@ -441,7 +441,7 @@ class JobError(QDialog): # {{{
def showEvent(self, ev): def showEvent(self, ev):
ret = QDialog.showEvent(self, ev) ret = QDialog.showEvent(self, ev)
self.bb.button(self.bb.Close).setFocus(Qt.FocusReason.OtherFocusReason) self.bb.button(QDialogButtonBox.StandardButton.Close).setFocus(Qt.FocusReason.OtherFocusReason)
return ret return ret
def show_error(self, title, msg, det_msg='', retry_func=None): def show_error(self, title, msg, det_msg='', retry_func=None):

View File

@ -240,10 +240,10 @@ class Preferences(QDialog):
QDialogButtonBox.StandardButton.Close | QDialogButtonBox.StandardButton.Apply | QDialogButtonBox.StandardButton.Close | QDialogButtonBox.StandardButton.Apply |
QDialogButtonBox.StandardButton.Discard | QDialogButtonBox.StandardButton.RestoreDefaults QDialogButtonBox.StandardButton.Discard | QDialogButtonBox.StandardButton.RestoreDefaults
) )
self.bb.button(self.bb.Apply).clicked.connect(self.accept) self.bb.button(QDialogButtonBox.StandardButton.Apply).clicked.connect(self.accept)
self.bb.button(self.bb.Discard).clicked.connect(self.reject) self.bb.button(QDialogButtonBox.StandardButton.Discard).clicked.connect(self.reject)
self.bb.button(self.bb.RestoreDefaults).setIcon(QIcon(I('clear_left.png'))) self.bb.button(QDialogButtonBox.StandardButton.RestoreDefaults).setIcon(QIcon(I('clear_left.png')))
self.bb.button(self.bb.RestoreDefaults).clicked.connect(self.restore_defaults) self.bb.button(QDialogButtonBox.StandardButton.RestoreDefaults).clicked.connect(self.restore_defaults)
self.wizard_button = self.bb.addButton(_('Run Welcome &wizard'), QDialogButtonBox.ButtonRole.ActionRole) self.wizard_button = self.bb.addButton(_('Run Welcome &wizard'), QDialogButtonBox.ButtonRole.ActionRole)
self.wizard_button.setIcon(QIcon(I('wizard.png'))) self.wizard_button.setIcon(QIcon(I('wizard.png')))
self.wizard_button.clicked.connect(self.run_wizard, type=Qt.ConnectionType.QueuedConnection) self.wizard_button.clicked.connect(self.run_wizard, type=Qt.ConnectionType.QueuedConnection)
@ -321,23 +321,23 @@ class Preferences(QDialog):
self.title_bar.show_plugin(plugin) self.title_bar.show_plugin(plugin)
self.setWindowIcon(QIcon(plugin.icon)) self.setWindowIcon(QIcon(plugin.icon))
self.bb.button(self.bb.Close).setVisible(False) self.bb.button(QDialogButtonBox.StandardButton.Close).setVisible(False)
self.wizard_button.setVisible(False) self.wizard_button.setVisible(False)
for button in (self.bb.Apply, self.bb.RestoreDefaults, self.bb.Discard): for button in (self.bb.Apply, self.bb.RestoreDefaults, self.bb.Discard):
button = self.bb.button(button) button = self.bb.button(button)
button.setVisible(True) button.setVisible(True)
self.bb.button(self.bb.Apply).setEnabled(False) self.bb.button(QDialogButtonBox.StandardButton.Apply).setEnabled(False)
self.bb.button(self.bb.Apply).setDefault(False), self.bb.button(self.bb.Apply).setDefault(True) self.bb.button(QDialogButtonBox.StandardButton.Apply).setDefault(False), self.bb.button(QDialogButtonBox.StandardButton.Apply).setDefault(True)
self.bb.button(self.bb.RestoreDefaults).setEnabled(self.showing_widget.supports_restoring_to_defaults) self.bb.button(QDialogButtonBox.StandardButton.RestoreDefaults).setEnabled(self.showing_widget.supports_restoring_to_defaults)
self.bb.button(self.bb.RestoreDefaults).setToolTip( self.bb.button(QDialogButtonBox.StandardButton.RestoreDefaults).setToolTip(
self.showing_widget.restore_defaults_desc if self.showing_widget.supports_restoring_to_defaults else self.showing_widget.restore_defaults_desc if self.showing_widget.supports_restoring_to_defaults else
(_('Restoring to defaults not supported for') + ' ' + plugin.gui_name)) (_('Restoring to defaults not supported for') + ' ' + plugin.gui_name))
self.bb.button(self.bb.RestoreDefaults).setText(_('Restore &defaults')) self.bb.button(QDialogButtonBox.StandardButton.RestoreDefaults).setText(_('Restore &defaults'))
self.showing_widget.changed_signal.connect(self.changed_signal) self.showing_widget.changed_signal.connect(self.changed_signal)
def changed_signal(self): def changed_signal(self):
b = self.bb.button(self.bb.Apply) b = self.bb.button(QDialogButtonBox.StandardButton.Apply)
b.setEnabled(True) b.setEnabled(True)
def hide_plugin(self): def hide_plugin(self):
@ -357,8 +357,8 @@ class Preferences(QDialog):
button = self.bb.button(button) button = self.bb.button(button)
button.setVisible(False) button.setVisible(False)
self.bb.button(self.bb.Close).setVisible(True) self.bb.button(QDialogButtonBox.StandardButton.Close).setVisible(True)
self.bb.button(self.bb.Close).setDefault(False), self.bb.button(self.bb.Close).setDefault(True) self.bb.button(QDialogButtonBox.StandardButton.Close).setDefault(False), self.bb.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
self.wizard_button.setVisible(True) self.wizard_button.setVisible(True)
def restart_now(self): def restart_now(self):

View File

@ -837,7 +837,7 @@ class Boss(QObject):
bb.rejected.connect(d.reject) bb.rejected.connect(d.reject)
d.b = b = bb.addButton(_('See what &changed'), QDialogButtonBox.ButtonRole.AcceptRole) d.b = b = bb.addButton(_('See what &changed'), QDialogButtonBox.ButtonRole.AcceptRole)
b.setIcon(QIcon(I('diff.png'))), b.setAutoDefault(False) b.setIcon(QIcon(I('diff.png'))), b.setAutoDefault(False)
bb.button(bb.Close).setDefault(True) bb.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
if d.exec_() == QDialog.DialogCode.Accepted: if d.exec_() == QDialog.DialogCode.Accepted:
self.show_current_diff(allow_revert=allow_revert, to_container=to_container) self.show_current_diff(allow_revert=allow_revert, to_container=to_container)

View File

@ -303,7 +303,7 @@ class Diff(Dialog):
b.setIcon(QIcon(I('edit-undo.png'))), b.setAutoDefault(False) b.setIcon(QIcon(I('edit-undo.png'))), b.setAutoDefault(False)
b.clicked.connect(self.revert_requested) b.clicked.connect(self.revert_requested)
b.clicked.connect(self.reject) b.clicked.connect(self.reject)
self.bb.button(self.bb.Close).setDefault(True) self.bb.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
self.hl.addWidget(self.bb, r) self.hl.addWidget(self.bb, r)
self.view.setFocus(Qt.FocusReason.OtherFocusReason) self.view.setFocus(Qt.FocusReason.OtherFocusReason)

View File

@ -245,7 +245,7 @@ class InsertImage(Dialog):
if self.for_browsing: if self.for_browsing:
self.bb.clear() self.bb.clear()
self.bb.addButton(self.bb.Close) self.bb.addButton(QDialogButtonBox.StandardButton.Close)
b = self.refresh_button = self.bb.addButton(_('&Refresh'), QDialogButtonBox.ButtonRole.ActionRole) b = self.refresh_button = self.bb.addButton(_('&Refresh'), QDialogButtonBox.ButtonRole.ActionRole)
b.clicked.connect(self.refresh) b.clicked.connect(self.refresh)
b.setIcon(QIcon(I('view-refresh.png'))) b.setIcon(QIcon(I('view-refresh.png')))

View File

@ -11,7 +11,7 @@ from PyQt5.Qt import (
QColor, QBrush, QFont, QApplication, QPalette, QComboBox, QColor, QBrush, QFont, QApplication, QPalette, QComboBox,
QPushButton, QIcon, QFormLayout, QLineEdit, QWidget, QScrollArea, QPushButton, QIcon, QFormLayout, QLineEdit, QWidget, QScrollArea,
QVBoxLayout, Qt, QHBoxLayout, pyqtSignal, QPixmap, QColorDialog, QDialog, QVBoxLayout, Qt, QHBoxLayout, pyqtSignal, QPixmap, QColorDialog, QDialog,
QToolButton, QCheckBox, QSize, QLabel, QSplitter, QTextCharFormat) QToolButton, QCheckBox, QSize, QLabel, QSplitter, QTextCharFormat, QDialogButtonBox)
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
from calibre.gui2.tweak_book import tprefs from calibre.gui2.tweak_book import tprefs
@ -603,7 +603,7 @@ class ThemeEditor(Dialog):
sp.addWidget(s), sp.addWidget(p) sp.addWidget(s), sp.addWidget(p)
self.bb.clear() self.bb.clear()
self.bb.addButton(self.bb.Close) self.bb.addButton(QDialogButtonBox.StandardButton.Close)
l.addWidget(self.bb) l.addWidget(self.bb)
if self.theme.count() > 0: if self.theme.count() > 0:

View File

@ -235,7 +235,7 @@ class ManageFonts(Dialog):
self.setLayout(l) self.setLayout(l)
self.bb.clear() self.bb.clear()
self.bb.addButton(self.bb.Close) self.bb.addButton(QDialogButtonBox.StandardButton.Close)
self.splitter = s = QSplitter(self) self.splitter = s = QSplitter(self)
self.h = h = QHBoxLayout() self.h = h = QHBoxLayout()
h.setContentsMargins(0, 0, 0, 0) h.setContentsMargins(0, 0, 0, 0)

View File

@ -125,7 +125,7 @@ def show_report(changed, title, report, parent, show_current_diff):
cp.setText(text) cp.setText(text)
b.clicked.connect(copy_report) b.clicked.connect(copy_report)
d.bb.button(d.bb.Close).setDefault(True) d.bb.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
d.l.addWidget(d.bb) d.l.addWidget(d.bb)
d.bb.rejected.connect(d.reject) d.bb.rejected.connect(d.reject)
d.bb.accepted.connect(d.accept) d.bb.accepted.connect(d.accept)

View File

@ -680,8 +680,8 @@ class TemplatesDialog(Dialog): # {{{
self.show_template() self.show_template()
self.bb.clear() self.bb.clear()
self.bb.addButton(self.bb.Close) self.bb.addButton(QDialogButtonBox.StandardButton.Close)
self.rd = b = self.bb.addButton(self.bb.RestoreDefaults) self.rd = b = self.bb.addButton(QDialogButtonBox.StandardButton.RestoreDefaults)
b.clicked.connect(self.restore_defaults) b.clicked.connect(self.restore_defaults)
l.addWidget(self.bb) l.addWidget(self.bb)

View File

@ -186,7 +186,7 @@ class ManageUserDictionaries(Dialog):
self.h = h = QHBoxLayout() self.h = h = QHBoxLayout()
l.addLayout(h) l.addLayout(h)
l.addWidget(self.bb) l.addWidget(self.bb)
self.bb.clear(), self.bb.addButton(self.bb.Close) self.bb.clear(), self.bb.addButton(QDialogButtonBox.StandardButton.Close)
b = self.bb.addButton(_('&New dictionary'), QDialogButtonBox.ButtonRole.ActionRole) b = self.bb.addButton(_('&New dictionary'), QDialogButtonBox.ButtonRole.ActionRole)
b.setIcon(QIcon(I('spell-check.png'))) b.setIcon(QIcon(I('spell-check.png')))
b.clicked.connect(self.new_dictionary) b.clicked.connect(self.new_dictionary)
@ -453,7 +453,7 @@ class ManageDictionaries(Dialog): # {{{
l.addLayout(s, 0, 1) l.addLayout(s, 0, 1)
self.bb.clear() self.bb.clear()
self.bb.addButton(self.bb.Close) self.bb.addButton(QDialogButtonBox.StandardButton.Close)
b = self.bb.addButton(_('Manage &user dictionaries'), QDialogButtonBox.ButtonRole.ActionRole) b = self.bb.addButton(_('Manage &user dictionaries'), QDialogButtonBox.ButtonRole.ActionRole)
b.setIcon(QIcon(I('user_profile.png'))) b.setIcon(QIcon(I('user_profile.png')))
b.setToolTip(_( b.setToolTip(_(
@ -940,7 +940,7 @@ class SpellCheck(Dialog):
l.addLayout(s) l.addLayout(s)
l.addWidget(self.bb) l.addWidget(self.bb)
self.bb.clear() self.bb.clear()
self.bb.addButton(self.bb.Close) self.bb.addButton(QDialogButtonBox.StandardButton.Close)
b = self.bb.addButton(_('&Refresh'), QDialogButtonBox.ButtonRole.ActionRole) b = self.bb.addButton(_('&Refresh'), QDialogButtonBox.ButtonRole.ActionRole)
b.setToolTip('<p>' + _('Re-scan the book for words, useful if you have edited the book since opening this dialog')) b.setToolTip('<p>' + _('Re-scan the book for words, useful if you have edited the book since opening this dialog'))
b.setIcon(QIcon(I('view-refresh.png'))) b.setIcon(QIcon(I('view-refresh.png')))

View File

@ -872,7 +872,7 @@ class InsertSemantics(Dialog):
fnl.addWidget(la), fnl.addWidget(f), fnl.addWidget(fn) fnl.addWidget(la), fnl.addWidget(f), fnl.addWidget(fn)
h.addLayout(fnl), h.setStretch(1, 1) h.addLayout(fnl), h.setStretch(1, 1)
self.bb.addButton(self.bb.Help) self.bb.addButton(QDialogButtonBox.StandardButton.Help)
self.bb.helpRequested.connect(self.help_requested) self.bb.helpRequested.connect(self.help_requested)
l.addWidget(self.bb) l.addWidget(self.bb)
self.semantic_type_changed() self.semantic_type_changed()