From 59541e36a5287cb43a8e430b80ec65e13482f6e6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 14 Jul 2022 08:04:54 +0530 Subject: [PATCH] more pyqt6 enum goodness The stateChanged signal delivers ints instead of Qt.CheckState. Fixes #1981627 [Heuristic-Page greyed out](https://bugs.launchpad.net/calibre/+bug/1981627) --- src/calibre/gui2/convert/heuristics.py | 3 +-- src/calibre/gui2/dialogs/multisort.py | 3 +-- src/calibre/gui2/dialogs/password.py | 4 ++-- src/calibre/gui2/dialogs/scheduler.py | 2 +- src/calibre/gui2/dialogs/smartdevice.py | 2 +- src/calibre/gui2/tweak_book/widgets.py | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/convert/heuristics.py b/src/calibre/gui2/convert/heuristics.py index 3ab07c9df6..e60bc76b3a 100644 --- a/src/calibre/gui2/convert/heuristics.py +++ b/src/calibre/gui2/convert/heuristics.py @@ -97,8 +97,7 @@ class HeuristicsWidget(Widget, Ui_Form): gprefs['replace_scene_breaks_history'] = rssb_history def enable_heuristics(self, state): - state = state == Qt.CheckState.Checked - self.heuristic_options.setEnabled(state) + self.heuristic_options.setEnabled(self.opt_enable_heuristics.isChecked()) def enable_unwrap(self, state): if state == Qt.CheckState.Checked: diff --git a/src/calibre/gui2/dialogs/multisort.py b/src/calibre/gui2/dialogs/multisort.py index c9e9b9c64f..0cae89eb75 100644 --- a/src/calibre/gui2/dialogs/multisort.py +++ b/src/calibre/gui2/dialogs/multisort.py @@ -89,8 +89,7 @@ class ChooseMultiSort(Dialog): self.column_list.sortItems() def item_double_clicked(self, item): - cs = item.checkState() - item.setCheckState(Qt.CheckState.Checked if cs == Qt.CheckState.Unchecked else Qt.CheckState.Unchecked) + item.setCheckState(Qt.CheckState.Checked if item.checkState() == Qt.CheckState.Unchecked else Qt.CheckState.Unchecked) def current_changed(self): self.update_order_label() diff --git a/src/calibre/gui2/dialogs/password.py b/src/calibre/gui2/dialogs/password.py index 3e5ab4ce57..47a3f02c9d 100644 --- a/src/calibre/gui2/dialogs/password.py +++ b/src/calibre/gui2/dialogs/password.py @@ -26,10 +26,10 @@ class PasswordDialog(QDialog, Ui_Dialog): self.gui_password.setText(pw) self.sname = name self.msg.setText(msg) - self.show_password.stateChanged[(int)].connect(self.toggle_password) + self.show_password.stateChanged.connect(self.toggle_password) def toggle_password(self, state): - if state == Qt.CheckState.Unchecked: + if Qt.CheckState(state) == Qt.CheckState.Unchecked: self.gui_password.setEchoMode(QLineEdit.EchoMode.Password) else: self.gui_password.setEchoMode(QLineEdit.EchoMode.Normal) diff --git a/src/calibre/gui2/dialogs/scheduler.py b/src/calibre/gui2/dialogs/scheduler.py index 04480e244c..e7262266aa 100644 --- a/src/calibre/gui2/dialogs/scheduler.py +++ b/src/calibre/gui2/dialogs/scheduler.py @@ -377,7 +377,7 @@ class SchedulerDialog(QDialog): def set_pw_echo_mode(self, state): self.password.setEchoMode(QLineEdit.EchoMode.Normal - if state == Qt.CheckState.Checked else QLineEdit.EchoMode.Password) + if Qt.CheckState(state) == Qt.CheckState.Checked else QLineEdit.EchoMode.Password) def schedule_type_selected(self, *args): for i, st in enumerate(self.SCHEDULE_TYPES): diff --git a/src/calibre/gui2/dialogs/smartdevice.py b/src/calibre/gui2/dialogs/smartdevice.py index 4116af7dc5..2b0bd7d7bc 100644 --- a/src/calibre/gui2/dialogs/smartdevice.py +++ b/src/calibre/gui2/dialogs/smartdevice.py @@ -99,7 +99,7 @@ class SmartdeviceDialog(QDialog, Ui_Dialog): self.resize(self.sizeHint()) def use_fixed_port_changed(self, state): - self.fixed_port.setEnabled(state == Qt.CheckState.Checked) + self.fixed_port.setEnabled(Qt.CheckState(state) == Qt.CheckState.Checked) def toggle_password(self, state): self.password_box.setEchoMode(QLineEdit.EchoMode.Password if state == diff --git a/src/calibre/gui2/tweak_book/widgets.py b/src/calibre/gui2/tweak_book/widgets.py index 5950773056..f77a922912 100644 --- a/src/calibre/gui2/tweak_book/widgets.py +++ b/src/calibre/gui2/tweak_book/widgets.py @@ -1166,7 +1166,7 @@ class AddCover(Dialog): p.setVisible(self.container.book_type != 'azw3') def on_state_change(s): - tprefs.set('add_cover_preserve_aspect_ratio', s == Qt.CheckState.Checked) + tprefs.set('add_cover_preserve_aspect_ratio', Qt.CheckState(s) == Qt.CheckState.Checked) p.stateChanged.connect(on_state_change) self.info_label = il = QLabel('\xa0')