From 885ca7b43a5296bcf539f6b79a8e069a2703b883 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 19 Dec 2020 13:09:32 +0530 Subject: [PATCH] More stupid PyQt enums --- src/calibre/gui2/convert/page_setup.py | 4 +-- src/calibre/gui2/cover_flow.py | 6 ++-- src/calibre/gui2/dialogs/custom_recipes.py | 4 +-- src/calibre/gui2/jobs.py | 4 +-- src/calibre/gui2/keyboard.py | 8 ++---- src/calibre/gui2/library/alternate_views.py | 18 ++++++------ src/calibre/gui2/library/views.py | 29 ++++++++++++-------- src/calibre/gui2/metadata/single_download.py | 8 +++--- src/calibre/gui2/preferences/coloring.py | 6 ++-- src/calibre/gui2/preferences/look_feel.py | 6 ++-- src/calibre/gui2/preferences/plugins.py | 5 ++-- src/calibre/gui2/preferences/toolbar.py | 6 ++-- src/calibre/gui2/preferences/tweaks.py | 5 ++-- src/calibre/gui2/tweak_book/file_list.py | 4 +-- src/calibre/gui2/tweak_book/search.py | 10 +++---- src/calibre/gui2/tweak_book/undo.py | 5 ++-- src/calibre/gui2/tweak_book/widgets.py | 6 ++-- 17 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/calibre/gui2/convert/page_setup.py b/src/calibre/gui2/convert/page_setup.py index 42bfaff371..1dcbf70e28 100644 --- a/src/calibre/gui2/convert/page_setup.py +++ b/src/calibre/gui2/convert/page_setup.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from PyQt5.Qt import Qt, QAbstractListModel, QModelIndex +from PyQt5.Qt import Qt, QAbstractListModel, QModelIndex, QItemSelectionModel from calibre.gui2.convert.page_setup_ui import Ui_Form from calibre.gui2.convert import Widget @@ -86,7 +86,7 @@ class PageSetupWidget(Widget, Ui_Form): idx = g.model().index(idx) sm = g.selectionModel() g.setCurrentIndex(idx) - sm.select(idx, sm.SelectCurrent) + sm.select(idx, QItemSelectionModel.SelectionFlag.SelectCurrent) return True return False diff --git a/src/calibre/gui2/cover_flow.py b/src/calibre/gui2/cover_flow.py index cedc104ecc..e9c8bd837a 100644 --- a/src/calibre/gui2/cover_flow.py +++ b/src/calibre/gui2/cover_flow.py @@ -12,7 +12,7 @@ Module to implement the Cover Flow feature import sys, os, time from PyQt5.Qt import (QImage, QSizePolicy, QTimer, QDialog, Qt, QSize, QAction, - QStackedLayout, QLabel, pyqtSignal, QKeySequence, QFont, QApplication) + QStackedLayout, QLabel, pyqtSignal, QKeySequence, QFont, QApplication, QItemSelectionModel) from calibre.ebooks.metadata import rating_to_stars from calibre.constants import islinux @@ -365,7 +365,7 @@ class CoverFlowMixin(object): idx = self.library_view.model().index(self.cover_flow.currentSlide(), 0) if idx.isValid(): sm = self.library_view.selectionModel() - sm.select(idx, sm.ClearAndSelect|sm.Rows) + sm.select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect|QItemSelectionModel.SelectionFlag.Rows) self.library_view.setCurrentIndex(idx) self.library_view.scroll_to_row(idx.row()) @@ -419,7 +419,7 @@ class CoverFlowMixin(object): m = self.library_view.model() index = m.index(row, 0) sm = self.library_view.selectionModel() - sm.select(index, sm.ClearAndSelect|sm.Rows) + sm.select(index, QItemSelectionModel.SelectionFlag.ClearAndSelect|QItemSelectionModel.SelectionFlag.Rows) self.library_view.setCurrentIndex(index) def cover_flow_do_sync(self): diff --git a/src/calibre/gui2/dialogs/custom_recipes.py b/src/calibre/gui2/dialogs/custom_recipes.py index 79ca6e493c..ca6e75ead3 100644 --- a/src/calibre/gui2/dialogs/custom_recipes.py +++ b/src/calibre/gui2/dialogs/custom_recipes.py @@ -8,7 +8,7 @@ __copyright__ = '2014, Kovid Goyal ' import os, re, textwrap, time from PyQt5.Qt import ( - QVBoxLayout, QStackedWidget, QSize, QPushButton, QIcon, QWidget, QListView, + QVBoxLayout, QStackedWidget, QSize, QPushButton, QIcon, QWidget, QListView, QItemSelectionModel, QHBoxLayout, QAbstractListModel, Qt, QLabel, QSizePolicy, pyqtSignal, QSortFilterProxyModel, QFormLayout, QSpinBox, QLineEdit, QGroupBox, QListWidget, QListWidgetItem, QToolButton, QTreeView, QDialog, QDialogButtonBox) @@ -217,7 +217,7 @@ class RecipeList(QWidget): # {{{ if v.model().rowCount() > 0: idx = v.model().index(row) if idx.isValid(): - v.selectionModel().select(idx, v.selectionModel().ClearAndSelect) + v.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect) v.setCurrentIndex(idx) self.recipe_selected(idx) diff --git a/src/calibre/gui2/jobs.py b/src/calibre/gui2/jobs.py index daf1447c7e..478b3a2d9a 100644 --- a/src/calibre/gui2/jobs.py +++ b/src/calibre/gui2/jobs.py @@ -14,7 +14,7 @@ import time from PyQt5.Qt import (QAbstractTableModel, QModelIndex, Qt, QPainter, QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication, QEvent, QSize, QStyleOptionProgressBar, QStyle, QToolTip, QWidget, QStyleOption, - QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QCoreApplication, QAction, + QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QCoreApplication, QAction, QItemSelectionModel, QByteArray, QSortFilterProxyModel, QTextBrowser, QPlainTextEdit, QDialogButtonBox) from calibre import strftime @@ -657,7 +657,7 @@ class JobsDialog(QDialog, Ui_JobsDialog): idx = self.jobs_view.model().index(0, 0) if idx.isValid(): sm = self.jobs_view.selectionModel() - sm.select(idx, sm.ClearAndSelect|sm.Rows) + sm.select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect|QItemSelectionModel.SelectionFlag.Rows) def save_state(self): try: diff --git a/src/calibre/gui2/keyboard.py b/src/calibre/gui2/keyboard.py index f55264f960..f395f47d01 100644 --- a/src/calibre/gui2/keyboard.py +++ b/src/calibre/gui2/keyboard.py @@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en' from collections import OrderedDict from functools import partial -from PyQt5.Qt import (QObject, QKeySequence, QAbstractItemModel, QModelIndex, +from PyQt5.Qt import (QObject, QKeySequence, QAbstractItemModel, QModelIndex, QItemSelectionModel, Qt, QStyledItemDelegate, QTextDocument, QStyle, pyqtSignal, QFrame, QApplication, QSize, QRectF, QWidget, QTreeView, QHBoxLayout, QVBoxLayout, QGridLayout, QLabel, QRadioButton, QPushButton, QToolButton, QIcon, QEvent) @@ -720,8 +720,7 @@ class ShortcutConfig(QWidget): # {{{ def highlight_index(self, idx): self.view.scrollTo(idx) - self.view.selectionModel().select(idx, - self.view.selectionModel().ClearAndSelect) + self.view.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect) self.view.setCurrentIndex(idx) self.view.setFocus(Qt.FocusReason.OtherFocusReason) @@ -746,8 +745,7 @@ class ShortcutConfig(QWidget): # {{{ if idx is not None: self.view.expand(idx) self.view.scrollTo(idx, self.view.PositionAtTop) - self.view.selectionModel().select(idx, - self.view.selectionModel().ClearAndSelect) + self.view.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect) self.view.setCurrentIndex(idx) self.view.setFocus(Qt.FocusReason.OtherFocusReason) diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index 34a600437b..cb4d33d358 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -990,8 +990,8 @@ class GridView(QListView): # performance if a large number of rows has to be selected. for k, g in itertools.groupby(enumerate(rows), lambda i_x:i_x[0]-i_x[1]): group = list(map(operator.itemgetter(1), g)) - sel.merge(QItemSelection(m.index(min(group), 0), m.index(max(group), 0)), sm.Select) - sm.select(sel, sm.ClearAndSelect) + sel.merge(QItemSelection(m.index(min(group), 0), m.index(max(group), 0)), QItemSelectionModel.SelectionFlag.Select) + sm.select(sel, QItemSelectionModel.SelectionFlag.ClearAndSelect) def selectAll(self): # We re-implement this to ensure that only indexes from column 0 are @@ -1001,11 +1001,11 @@ class GridView(QListView): m = self.model() sm = self.selectionModel() sel = QItemSelection(m.index(0, 0), m.index(m.rowCount(QModelIndex())-1, 0)) - sm.select(sel, sm.ClearAndSelect) + sm.select(sel, QItemSelectionModel.SelectionFlag.ClearAndSelect) def set_current_row(self, row): sm = self.selectionModel() - sm.setCurrentIndex(self.model().index(row, 0), sm.NoUpdate) + sm.setCurrentIndex(self.model().index(row, 0), QItemSelectionModel.SelectionFlag.NoUpdate) def set_context_menu(self, menu): self.context_menu = menu @@ -1040,17 +1040,17 @@ class GridView(QListView): return ci = self.currentIndex() sm = self.selectionModel() - sm.setCurrentIndex(index, sm.NoUpdate) + sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.NoUpdate) if not ci.isValid(): return if not sm.hasSelection(): - sm.select(index, sm.ClearAndSelect) + sm.select(index, QItemSelectionModel.SelectionFlag.ClearAndSelect) return cr = ci.row() tgt = index.row() top = self.model().index(min(cr, tgt), 0) bottom = self.model().index(max(cr, tgt), 0) - sm.select(QItemSelection(top, bottom), sm.Select) + sm.select(QItemSelection(top, bottom), QItemSelectionModel.SelectionFlag.Select) else: return QListView.mousePressEvent(self, ev) @@ -1098,8 +1098,8 @@ class GridView(QListView): end = c top = self.model().index(min(n, end), 0) bottom = self.model().index(max(n, end), 0) - sm.select(QItemSelection(top, bottom), sm.ClearAndSelect) - sm.setCurrentIndex(self.model().index(n, 0), sm.NoUpdate) + sm.select(QItemSelection(top, bottom), QItemSelectionModel.SelectionFlag.ClearAndSelect) + sm.setCurrentIndex(self.model().index(n, 0), QItemSelectionModel.SelectionFlag.NoUpdate) else: return QListView.keyPressEvent(self, ev) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index b4af913e01..f0de60d02d 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -1010,11 +1010,14 @@ class BooksView(QTableView): # {{{ current_row = ci.row() sm = self.selectionModel() if clicked_row == current_row: - sm.setCurrentIndex(index, sm.NoUpdate) + sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.NoUpdate) return sr = sm.selectedRows() if not len(sr): - sm.select(index, sm.Select | sm.Clear | sm.Current | sm.Rows) + sm.select( + index, + QItemSelectionModel.SelectionFlag.Select | QItemSelectionModel.SelectionFlag.Clear | + QItemSelectionModel.SelectionFlag.Current | QItemSelectionModel.SelectionFlag.Rows) return m = self.model() @@ -1035,15 +1038,17 @@ class BooksView(QTableView): # {{{ upper, lower = clicked_row, min_row else: upper, lower = max_row, clicked_row - existing_selection.merge(new_selection(upper, lower), sm.Select) + existing_selection.merge(new_selection(upper, lower), QItemSelectionModel.SelectionFlag.Select) else: if current_row < clicked_row: upper, lower = current_row, clicked_row else: upper, lower = clicked_row, current_row - existing_selection.merge(new_selection(upper, lower), sm.Toggle) - sm.select(existing_selection, sm.ClearAndSelect) - sm.setCurrentIndex(index, sm.Select | sm.Rows) # ensure clicked row is always selected + existing_selection.merge(new_selection(upper, lower), QItemSelectionModel.SelectionFlag.Toggle) + sm.select(existing_selection, QItemSelectionModel.SelectionFlag.ClearAndSelect) + sm.setCurrentIndex( + # ensure clicked row is always selected + index, QItemSelectionModel.SelectionFlag.Select | QItemSelectionModel.SelectionFlag.Rows) else: return QTableView.mousePressEvent(self, ev) @@ -1125,20 +1130,20 @@ class BooksView(QTableView): # {{{ index = self.model().index(row, i) if for_sync: sm = self.selectionModel() - sm.setCurrentIndex(index, sm.NoUpdate) + sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.NoUpdate) else: self.setCurrentIndex(index) if select: sm = self.selectionModel() - sm.select(index, sm.ClearAndSelect|sm.Rows) + sm.select(index, QItemSelectionModel.SelectionFlag.ClearAndSelect|QItemSelectionModel.SelectionFlag.Rows) def select_cell(self, row_number=0, logical_column=0): if row_number > -1 and row_number < self.model().rowCount(QModelIndex()): index = self.model().index(row_number, logical_column) self.setCurrentIndex(index) sm = self.selectionModel() - sm.select(index, sm.ClearAndSelect|sm.Rows) - sm.select(index, sm.Current) + sm.select(index, QItemSelectionModel.SelectionFlag.ClearAndSelect|QItemSelectionModel.SelectionFlag.Rows) + sm.select(index, QItemSelectionModel.SelectionFlag.Current) self.clicked.emit(index) def row_at_top(self): @@ -1237,8 +1242,8 @@ class BooksView(QTableView): # {{{ for k, g in itertools.groupby(enumerate(rows), lambda i_x:i_x[0]-i_x[1]): group = list(map(operator.itemgetter(1), g)) sel.merge(QItemSelection(m.index(min(group), 0), - m.index(max(group), max_col)), sm.Select) - sm.select(sel, sm.ClearAndSelect) + m.index(max(group), max_col)), QItemSelectionModel.SelectionFlag.Select) + sm.select(sel, QItemSelectionModel.SelectionFlag.ClearAndSelect) return rows def get_selected_ids(self, as_set=False): diff --git a/src/calibre/gui2/metadata/single_download.py b/src/calibre/gui2/metadata/single_download.py index 6f9bd1ac89..40032e6e8f 100644 --- a/src/calibre/gui2/metadata/single_download.py +++ b/src/calibre/gui2/metadata/single_download.py @@ -19,7 +19,7 @@ from PyQt5.Qt import ( QDialog, QVBoxLayout, QLabel, QDialogButtonBox, QStyle, QStackedWidget, QWidget, QTableView, QGridLayout, QPalette, QTimer, pyqtSignal, QAbstractTableModel, QSize, QListView, QPixmap, QModelIndex, - QAbstractListModel, QRect, QTextBrowser, QStringListModel, QMenu, + QAbstractListModel, QRect, QTextBrowser, QStringListModel, QMenu, QItemSelectionModel, QCursor, QHBoxLayout, QPushButton, QSizePolicy, QSplitter, QAbstractItemView) from calibre.customize.ui import metadata_plugins @@ -234,7 +234,7 @@ class ResultsView(QTableView): # {{{ if idx.isValid() and self.model().rowCount() > 0: self.show_details(idx) sm = self.selectionModel() - sm.select(idx, sm.ClearAndSelect|sm.Rows) + sm.select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect|QItemSelectionModel.SelectionFlag.Rows) def resize_delegate(self): self.rt_delegate.max_width = int(self.width()/2.1) @@ -295,7 +295,7 @@ class ResultsView(QTableView): # {{{ index = self.moveCursor(ac, ev.modifiers()) if index.isValid() and index != self.currentIndex(): m = self.selectionModel() - m.select(index, m.Select|m.Current|m.Rows) + m.select(index, QItemSelectionModel.SelectionFlag.Select|QItemSelectionModel.SelectionFlag.Current|QItemSelectionModel.SelectionFlag.Rows) self.setCurrentIndex(index) ev.accept() return @@ -796,7 +796,7 @@ class CoversView(QListView): # {{{ def select(self, num): current = self.model().index(num) sm = self.selectionModel() - sm.select(current, sm.SelectCurrent) + sm.select(current, QItemSelectionModel.SelectionFlag.SelectCurrent) def start(self): self.select(0) diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index a2cb7f35ef..ecaa137053 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -10,7 +10,7 @@ import os, textwrap, json from PyQt5.Qt import (QWidget, QDialog, QLabel, QGridLayout, QComboBox, QSize, QLineEdit, QIntValidator, QDoubleValidator, QFrame, Qt, QIcon, QHBoxLayout, - QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox, QToolButton, + QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox, QToolButton, QItemSelectionModel, QListView, QAbstractListModel, pyqtSignal, QSizePolicy, QSpacerItem, QPalette, QApplication, QStandardItem, QStandardItemModel, QCheckBox, QMenu, QAbstractItemView) @@ -1135,7 +1135,7 @@ class EditRules(QWidget): # {{{ if idx.isValid(): idx = self.model.move(idx, -1) if idx is not None: - sm.select(idx, sm.Toggle) + sm.select(idx, QItemSelectionModel.SelectionFlag.Toggle) self.changed.emit() def move_down(self): @@ -1149,7 +1149,7 @@ class EditRules(QWidget): # {{{ if idx.isValid(): idx = self.model.move(idx, 1) if idx is not None: - sm.select(idx, sm.Toggle) + sm.select(idx, QItemSelectionModel.SelectionFlag.Toggle) self.changed.emit() def clear(self): diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index b827c15537..10f14c86a7 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -14,7 +14,7 @@ from threading import Thread from PyQt5.Qt import ( QApplication, QFont, QFontInfo, QFontDialog, QColorDialog, QPainter, QDialog, QAbstractListModel, Qt, QIcon, QKeySequence, QColor, pyqtSignal, QCursor, - QWidget, QSizePolicy, QBrush, QPixmap, QSize, QPushButton, QVBoxLayout, + QWidget, QSizePolicy, QBrush, QPixmap, QSize, QPushButton, QVBoxLayout, QItemSelectionModel, QTableWidget, QTableWidgetItem, QLabel, QFormLayout, QLineEdit, QComboBox, QDialogButtonBox ) @@ -308,7 +308,7 @@ def move_field_up(widget, model): idx = model.move(idx, -1) if idx is not None: sm = widget.selectionModel() - sm.select(idx, sm.ClearAndSelect) + sm.select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect) widget.setCurrentIndex(idx) @@ -318,7 +318,7 @@ def move_field_down(widget, model): idx = model.move(idx, 1) if idx is not None: sm = widget.selectionModel() - sm.select(idx, sm.ClearAndSelect) + sm.select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect) widget.setCurrentIndex(idx) # }}} diff --git a/src/calibre/gui2/preferences/plugins.py b/src/calibre/gui2/preferences/plugins.py index 617dcc1813..aa4c69228f 100644 --- a/src/calibre/gui2/preferences/plugins.py +++ b/src/calibre/gui2/preferences/plugins.py @@ -10,7 +10,7 @@ import textwrap, os from collections import OrderedDict from PyQt5.Qt import (Qt, QModelIndex, QAbstractItemModel, QIcon, - QBrush, QDialog) + QBrush, QDialog, QItemSelectionModel) from calibre.gui2.preferences import ConfigWidgetBase, test_widget from calibre.gui2.preferences.plugins_ui import Ui_Form @@ -260,8 +260,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.highlight_index(idx) def highlight_index(self, idx): - self.plugin_view.selectionModel().select(idx, - self.plugin_view.selectionModel().ClearAndSelect) + self.plugin_view.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect) self.plugin_view.setCurrentIndex(idx) self.plugin_view.setFocus(Qt.FocusReason.OtherFocusReason) self.plugin_view.scrollTo(idx, self.plugin_view.EnsureVisible) diff --git a/src/calibre/gui2/preferences/toolbar.py b/src/calibre/gui2/preferences/toolbar.py index 03aa151361..2d5ca00cf3 100644 --- a/src/calibre/gui2/preferences/toolbar.py +++ b/src/calibre/gui2/preferences/toolbar.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from PyQt5.Qt import QAbstractListModel, Qt, QIcon +from PyQt5.Qt import QAbstractListModel, Qt, QIcon, QItemSelectionModel from calibre import force_unicode from calibre.gui2.preferences.toolbar_ui import Ui_Form @@ -343,10 +343,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): idx_map = m.move_many(x, delta) newci = idx_map.get(i) if newci is not None: - sm.setCurrentIndex(newci, sm.ClearAndSelect) + sm.setCurrentIndex(newci, QItemSelectionModel.SelectionFlag.ClearAndSelect) sm.clear() for idx in idx_map.values(): - sm.select(idx, sm.Select) + sm.select(idx, QItemSelectionModel.SelectionFlag.Select) self.changed_signal.emit() def commit(self): diff --git a/src/calibre/gui2/preferences/tweaks.py b/src/calibre/gui2/preferences/tweaks.py index 8cf191df43..4987d39413 100644 --- a/src/calibre/gui2/preferences/tweaks.py +++ b/src/calibre/gui2/preferences/tweaks.py @@ -11,7 +11,7 @@ from operator import attrgetter from PyQt5.Qt import ( QAbstractListModel, QApplication, QDialog, QDialogButtonBox, QFont, QGridLayout, QGroupBox, QIcon, QLabel, QListView, QMenu, QModelIndex, QPlainTextEdit, - QPushButton, QSizePolicy, QSplitter, QStyle, QStyledItemDelegate, QAbstractItemView, + QPushButton, QSizePolicy, QSplitter, QStyle, QStyledItemDelegate, QAbstractItemView, QItemSelectionModel, QStyleOptionViewItem, Qt, QVBoxLayout, QWidget, pyqtSignal ) @@ -581,8 +581,7 @@ class ConfigWidget(ConfigWidgetBase): if not idx.isValid(): return self.view.scrollTo(idx) - self.view.selectionModel().select(idx, - self.view.selectionModel().ClearAndSelect) + self.view.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect) self.view.setCurrentIndex(idx) def find_next(self, *args): diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index 3bde86dea8..61096a638c 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -10,7 +10,7 @@ import textwrap from collections import Counter, OrderedDict, defaultdict from functools import partial from PyQt5.Qt import ( - QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont, QFormLayout, + QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont, QFormLayout, QItemSelectionModel, QGridLayout, QIcon, QInputDialog, QLabel, QLineEdit, QListWidget, QAbstractItemView, QListWidgetItem, QMenu, QPainter, QPixmap, QRadioButton, QScrollArea, QSize, QSpinBox, QStyle, QStyledItemDelegate, Qt, QTimer, QTreeWidget, QTreeWidgetItem, @@ -338,7 +338,7 @@ class FileList(QTreeWidget, OpenWithHandler): if q == current_name: self.scrollToItem(c) s = self.selectionModel() - s.setCurrentIndex(self.indexFromItem(c), s.NoUpdate) + s.setCurrentIndex(self.indexFromItem(c), QItemSelectionModel.SelectionFlag.NoUpdate) def mark_name_as_current(self, name): current = self.item_from_name(name) diff --git a/src/calibre/gui2/tweak_book/search.py b/src/calibre/gui2/tweak_book/search.py index 36066de248..fcfd019770 100644 --- a/src/calibre/gui2/tweak_book/search.py +++ b/src/calibre/gui2/tweak_book/search.py @@ -12,7 +12,7 @@ from functools import partial from PyQt5.Qt import ( QAbstractListModel, QAction, QApplication, QCheckBox, QComboBox, QFont, QFrame, QGridLayout, QHBoxLayout, QIcon, QItemSelection, QKeySequence, QLabel, QLineEdit, - QListView, QMenu, QMimeData, QModelIndex, QPushButton, QScrollArea, QSize, + QListView, QMenu, QMimeData, QModelIndex, QPushButton, QScrollArea, QSize, QItemSelectionModel, QSizePolicy, QStackedLayout, QStyledItemDelegate, Qt, QTimer, QToolBar, QDialog, QToolButton, QVBoxLayout, QWidget, pyqtSignal, QAbstractItemView, QEvent, QDialogButtonBox ) @@ -1139,9 +1139,9 @@ class SavedSearches(QWidget): index = self.model.index_for_search(s) if index.isValid() and index.row() > -1: if s is current_search: - sm.setCurrentIndex(index, sm.Select) + sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.Select) else: - sm.select(index, sm.Select) + sm.select(index, QItemSelectionModel.SelectionFlag.Select) def search_editing_done(self, save_changes): if save_changes and not self.edit_search_widget.save_changes(): @@ -1187,7 +1187,7 @@ class SavedSearches(QWidget): index = self.model.index(self.model.rowCount() - 1) self.searches.scrollTo(index) sm = self.searches.selectionModel() - sm.setCurrentIndex(index, sm.ClearAndSelect) + sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.ClearAndSelect) self.show_details() def add_predefined_search(self, state): @@ -1239,7 +1239,7 @@ class SavedSearches(QWidget): self.model.add_searches(count=count) sm = self.searches.selectionModel() top, bottom = self.model.index(self.model.rowCount() - count), self.model.index(self.model.rowCount() - 1) - sm.select(QItemSelection(top, bottom), sm.ClearAndSelect) + sm.select(QItemSelection(top, bottom), QItemSelectionModel.SelectionFlag.ClearAndSelect) self.searches.scrollTo(bottom) def copy_to_search_panel(self): diff --git a/src/calibre/gui2/tweak_book/undo.py b/src/calibre/gui2/tweak_book/undo.py index b81a085cee..7370920551 100644 --- a/src/calibre/gui2/tweak_book/undo.py +++ b/src/calibre/gui2/tweak_book/undo.py @@ -9,7 +9,7 @@ import shutil from PyQt5.Qt import ( QAbstractListModel, Qt, QModelIndex, QApplication, QWidget, - QGridLayout, QListView, QStyledItemDelegate, pyqtSignal, QPushButton, QIcon) + QGridLayout, QListView, QStyledItemDelegate, pyqtSignal, QPushButton, QIcon, QItemSelectionModel) from calibre.gui2 import error_dialog @@ -217,7 +217,7 @@ class CheckpointView(QWidget): self.view.clearSelection() m = self.view.model() sm = self.view.selectionModel() - sm.select(m.index(m.pos), sm.ClearAndSelect) + sm.select(m.index(m.pos), QItemSelectionModel.SelectionFlag.ClearAndSelect) self.view.setCurrentIndex(m.index(m.pos)) def double_clicked(self, index): @@ -242,4 +242,3 @@ class CheckpointView(QWidget): return error_dialog(self, _('Cannot compare'), _( 'There is no point comparing the current state to itself'), show=True) self.compare_requested.emit(m.states[row].container) - diff --git a/src/calibre/gui2/tweak_book/widgets.py b/src/calibre/gui2/tweak_book/widgets.py index ce7258c2f5..4dd08c63d5 100644 --- a/src/calibre/gui2/tweak_book/widgets.py +++ b/src/calibre/gui2/tweak_book/widgets.py @@ -11,7 +11,7 @@ from collections import OrderedDict from PyQt5.Qt import ( QGridLayout, QLabel, QLineEdit, QVBoxLayout, QFormLayout, QHBoxLayout, QToolButton, QIcon, QApplication, Qt, QWidget, QPoint, QSizePolicy, - QPainter, QStaticText, pyqtSignal, QTextOption, QAbstractListModel, + QPainter, QStaticText, pyqtSignal, QTextOption, QAbstractListModel, QItemSelectionModel, QModelIndex, QStyledItemDelegate, QStyle, QCheckBox, QListView, QPalette, QTextDocument, QSize, QComboBox, QFrame, QCursor, QGroupBox, QSplitter, QPixmap, QRect, QPlainTextEdit, QMimeData, QDialog, QEvent, QDialogButtonBox) @@ -901,12 +901,12 @@ class InsertSemantics(Dialog): row = self.file_names.model().find_name(name) if row is not None: sm = self.file_names.selectionModel() - sm.select(self.file_names.model().index(row), sm.ClearAndSelect) + sm.select(self.file_names.model().index(row), QItemSelectionModel.SelectionFlag.ClearAndSelect) if frag: row = self.anchor_names.model().find_name(frag) if row is not None: sm = self.anchor_names.selectionModel() - sm.select(self.anchor_names.model().index(row), sm.ClearAndSelect) + sm.select(self.anchor_names.model().index(row), QItemSelectionModel.SelectionFlag.ClearAndSelect) self.target.blockSignals(True) if name is not None: self.target.setText(name + (('#' + frag) if frag else ''))