More stupid PyQt enums

This commit is contained in:
Kovid Goyal 2020-12-19 13:09:32 +05:30
parent 48000d4514
commit 885ca7b43a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
17 changed files with 67 additions and 67 deletions

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 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.page_setup_ui import Ui_Form
from calibre.gui2.convert import Widget from calibre.gui2.convert import Widget
@ -86,7 +86,7 @@ class PageSetupWidget(Widget, Ui_Form):
idx = g.model().index(idx) idx = g.model().index(idx)
sm = g.selectionModel() sm = g.selectionModel()
g.setCurrentIndex(idx) g.setCurrentIndex(idx)
sm.select(idx, sm.SelectCurrent) sm.select(idx, QItemSelectionModel.SelectionFlag.SelectCurrent)
return True return True
return False return False

View File

@ -12,7 +12,7 @@ Module to implement the Cover Flow feature
import sys, os, time import sys, os, time
from PyQt5.Qt import (QImage, QSizePolicy, QTimer, QDialog, Qt, QSize, QAction, 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.ebooks.metadata import rating_to_stars
from calibre.constants import islinux from calibre.constants import islinux
@ -365,7 +365,7 @@ class CoverFlowMixin(object):
idx = self.library_view.model().index(self.cover_flow.currentSlide(), 0) idx = self.library_view.model().index(self.cover_flow.currentSlide(), 0)
if idx.isValid(): if idx.isValid():
sm = self.library_view.selectionModel() 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.setCurrentIndex(idx)
self.library_view.scroll_to_row(idx.row()) self.library_view.scroll_to_row(idx.row())
@ -419,7 +419,7 @@ class CoverFlowMixin(object):
m = self.library_view.model() m = self.library_view.model()
index = m.index(row, 0) index = m.index(row, 0)
sm = self.library_view.selectionModel() 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) self.library_view.setCurrentIndex(index)
def cover_flow_do_sync(self): def cover_flow_do_sync(self):

View File

@ -8,7 +8,7 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
import os, re, textwrap, time import os, re, textwrap, time
from PyQt5.Qt import ( 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, QHBoxLayout, QAbstractListModel, Qt, QLabel, QSizePolicy, pyqtSignal, QSortFilterProxyModel,
QFormLayout, QSpinBox, QLineEdit, QGroupBox, QListWidget, QListWidgetItem, QFormLayout, QSpinBox, QLineEdit, QGroupBox, QListWidget, QListWidgetItem,
QToolButton, QTreeView, QDialog, QDialogButtonBox) QToolButton, QTreeView, QDialog, QDialogButtonBox)
@ -217,7 +217,7 @@ class RecipeList(QWidget): # {{{
if v.model().rowCount() > 0: if v.model().rowCount() > 0:
idx = v.model().index(row) idx = v.model().index(row)
if idx.isValid(): if idx.isValid():
v.selectionModel().select(idx, v.selectionModel().ClearAndSelect) v.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect)
v.setCurrentIndex(idx) v.setCurrentIndex(idx)
self.recipe_selected(idx) self.recipe_selected(idx)

View File

@ -14,7 +14,7 @@ import time
from PyQt5.Qt import (QAbstractTableModel, QModelIndex, Qt, QPainter, from PyQt5.Qt import (QAbstractTableModel, QModelIndex, Qt, QPainter,
QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication, QEvent, QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication, QEvent,
QSize, QStyleOptionProgressBar, QStyle, QToolTip, QWidget, QStyleOption, QSize, QStyleOptionProgressBar, QStyle, QToolTip, QWidget, QStyleOption,
QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QCoreApplication, QAction, QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QCoreApplication, QAction, QItemSelectionModel,
QByteArray, QSortFilterProxyModel, QTextBrowser, QPlainTextEdit, QDialogButtonBox) QByteArray, QSortFilterProxyModel, QTextBrowser, QPlainTextEdit, QDialogButtonBox)
from calibre import strftime from calibre import strftime
@ -657,7 +657,7 @@ class JobsDialog(QDialog, Ui_JobsDialog):
idx = self.jobs_view.model().index(0, 0) idx = self.jobs_view.model().index(0, 0)
if idx.isValid(): if idx.isValid():
sm = self.jobs_view.selectionModel() 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): def save_state(self):
try: try:

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
from collections import OrderedDict from collections import OrderedDict
from functools import partial 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, Qt, QStyledItemDelegate, QTextDocument, QStyle, pyqtSignal, QFrame,
QApplication, QSize, QRectF, QWidget, QTreeView, QHBoxLayout, QVBoxLayout, QApplication, QSize, QRectF, QWidget, QTreeView, QHBoxLayout, QVBoxLayout,
QGridLayout, QLabel, QRadioButton, QPushButton, QToolButton, QIcon, QEvent) QGridLayout, QLabel, QRadioButton, QPushButton, QToolButton, QIcon, QEvent)
@ -720,8 +720,7 @@ class ShortcutConfig(QWidget): # {{{
def highlight_index(self, idx): def highlight_index(self, idx):
self.view.scrollTo(idx) self.view.scrollTo(idx)
self.view.selectionModel().select(idx, self.view.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect)
self.view.selectionModel().ClearAndSelect)
self.view.setCurrentIndex(idx) self.view.setCurrentIndex(idx)
self.view.setFocus(Qt.FocusReason.OtherFocusReason) self.view.setFocus(Qt.FocusReason.OtherFocusReason)
@ -746,8 +745,7 @@ class ShortcutConfig(QWidget): # {{{
if idx is not None: if idx is not None:
self.view.expand(idx) self.view.expand(idx)
self.view.scrollTo(idx, self.view.PositionAtTop) self.view.scrollTo(idx, self.view.PositionAtTop)
self.view.selectionModel().select(idx, self.view.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect)
self.view.selectionModel().ClearAndSelect)
self.view.setCurrentIndex(idx) self.view.setCurrentIndex(idx)
self.view.setFocus(Qt.FocusReason.OtherFocusReason) self.view.setFocus(Qt.FocusReason.OtherFocusReason)

View File

@ -990,8 +990,8 @@ class GridView(QListView):
# performance if a large number of rows has to be selected. # 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]): for k, g in itertools.groupby(enumerate(rows), lambda i_x:i_x[0]-i_x[1]):
group = list(map(operator.itemgetter(1), g)) group = list(map(operator.itemgetter(1), g))
sel.merge(QItemSelection(m.index(min(group), 0), m.index(max(group), 0)), sm.Select) sel.merge(QItemSelection(m.index(min(group), 0), m.index(max(group), 0)), QItemSelectionModel.SelectionFlag.Select)
sm.select(sel, sm.ClearAndSelect) sm.select(sel, QItemSelectionModel.SelectionFlag.ClearAndSelect)
def selectAll(self): def selectAll(self):
# We re-implement this to ensure that only indexes from column 0 are # We re-implement this to ensure that only indexes from column 0 are
@ -1001,11 +1001,11 @@ class GridView(QListView):
m = self.model() m = self.model()
sm = self.selectionModel() sm = self.selectionModel()
sel = QItemSelection(m.index(0, 0), m.index(m.rowCount(QModelIndex())-1, 0)) 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): def set_current_row(self, row):
sm = self.selectionModel() 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): def set_context_menu(self, menu):
self.context_menu = menu self.context_menu = menu
@ -1040,17 +1040,17 @@ class GridView(QListView):
return return
ci = self.currentIndex() ci = self.currentIndex()
sm = self.selectionModel() sm = self.selectionModel()
sm.setCurrentIndex(index, sm.NoUpdate) sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.NoUpdate)
if not ci.isValid(): if not ci.isValid():
return return
if not sm.hasSelection(): if not sm.hasSelection():
sm.select(index, sm.ClearAndSelect) sm.select(index, QItemSelectionModel.SelectionFlag.ClearAndSelect)
return return
cr = ci.row() cr = ci.row()
tgt = index.row() tgt = index.row()
top = self.model().index(min(cr, tgt), 0) top = self.model().index(min(cr, tgt), 0)
bottom = self.model().index(max(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: else:
return QListView.mousePressEvent(self, ev) return QListView.mousePressEvent(self, ev)
@ -1098,8 +1098,8 @@ class GridView(QListView):
end = c end = c
top = self.model().index(min(n, end), 0) top = self.model().index(min(n, end), 0)
bottom = self.model().index(max(n, end), 0) bottom = self.model().index(max(n, end), 0)
sm.select(QItemSelection(top, bottom), sm.ClearAndSelect) sm.select(QItemSelection(top, bottom), QItemSelectionModel.SelectionFlag.ClearAndSelect)
sm.setCurrentIndex(self.model().index(n, 0), sm.NoUpdate) sm.setCurrentIndex(self.model().index(n, 0), QItemSelectionModel.SelectionFlag.NoUpdate)
else: else:
return QListView.keyPressEvent(self, ev) return QListView.keyPressEvent(self, ev)

View File

@ -1010,11 +1010,14 @@ class BooksView(QTableView): # {{{
current_row = ci.row() current_row = ci.row()
sm = self.selectionModel() sm = self.selectionModel()
if clicked_row == current_row: if clicked_row == current_row:
sm.setCurrentIndex(index, sm.NoUpdate) sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.NoUpdate)
return return
sr = sm.selectedRows() sr = sm.selectedRows()
if not len(sr): 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 return
m = self.model() m = self.model()
@ -1035,15 +1038,17 @@ class BooksView(QTableView): # {{{
upper, lower = clicked_row, min_row upper, lower = clicked_row, min_row
else: else:
upper, lower = max_row, clicked_row 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: else:
if current_row < clicked_row: if current_row < clicked_row:
upper, lower = current_row, clicked_row upper, lower = current_row, clicked_row
else: else:
upper, lower = clicked_row, current_row upper, lower = clicked_row, current_row
existing_selection.merge(new_selection(upper, lower), sm.Toggle) existing_selection.merge(new_selection(upper, lower), QItemSelectionModel.SelectionFlag.Toggle)
sm.select(existing_selection, sm.ClearAndSelect) sm.select(existing_selection, QItemSelectionModel.SelectionFlag.ClearAndSelect)
sm.setCurrentIndex(index, sm.Select | sm.Rows) # ensure clicked row is always selected sm.setCurrentIndex(
# ensure clicked row is always selected
index, QItemSelectionModel.SelectionFlag.Select | QItemSelectionModel.SelectionFlag.Rows)
else: else:
return QTableView.mousePressEvent(self, ev) return QTableView.mousePressEvent(self, ev)
@ -1125,20 +1130,20 @@ class BooksView(QTableView): # {{{
index = self.model().index(row, i) index = self.model().index(row, i)
if for_sync: if for_sync:
sm = self.selectionModel() sm = self.selectionModel()
sm.setCurrentIndex(index, sm.NoUpdate) sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.NoUpdate)
else: else:
self.setCurrentIndex(index) self.setCurrentIndex(index)
if select: if select:
sm = self.selectionModel() 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): def select_cell(self, row_number=0, logical_column=0):
if row_number > -1 and row_number < self.model().rowCount(QModelIndex()): if row_number > -1 and row_number < self.model().rowCount(QModelIndex()):
index = self.model().index(row_number, logical_column) index = self.model().index(row_number, logical_column)
self.setCurrentIndex(index) self.setCurrentIndex(index)
sm = self.selectionModel() sm = self.selectionModel()
sm.select(index, sm.ClearAndSelect|sm.Rows) sm.select(index, QItemSelectionModel.SelectionFlag.ClearAndSelect|QItemSelectionModel.SelectionFlag.Rows)
sm.select(index, sm.Current) sm.select(index, QItemSelectionModel.SelectionFlag.Current)
self.clicked.emit(index) self.clicked.emit(index)
def row_at_top(self): 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]): for k, g in itertools.groupby(enumerate(rows), lambda i_x:i_x[0]-i_x[1]):
group = list(map(operator.itemgetter(1), g)) group = list(map(operator.itemgetter(1), g))
sel.merge(QItemSelection(m.index(min(group), 0), sel.merge(QItemSelection(m.index(min(group), 0),
m.index(max(group), max_col)), sm.Select) m.index(max(group), max_col)), QItemSelectionModel.SelectionFlag.Select)
sm.select(sel, sm.ClearAndSelect) sm.select(sel, QItemSelectionModel.SelectionFlag.ClearAndSelect)
return rows return rows
def get_selected_ids(self, as_set=False): def get_selected_ids(self, as_set=False):

View File

@ -19,7 +19,7 @@ from PyQt5.Qt import (
QDialog, QVBoxLayout, QLabel, QDialogButtonBox, QStyle, QStackedWidget, QDialog, QVBoxLayout, QLabel, QDialogButtonBox, QStyle, QStackedWidget,
QWidget, QTableView, QGridLayout, QPalette, QTimer, pyqtSignal, QWidget, QTableView, QGridLayout, QPalette, QTimer, pyqtSignal,
QAbstractTableModel, QSize, QListView, QPixmap, QModelIndex, QAbstractTableModel, QSize, QListView, QPixmap, QModelIndex,
QAbstractListModel, QRect, QTextBrowser, QStringListModel, QMenu, QAbstractListModel, QRect, QTextBrowser, QStringListModel, QMenu, QItemSelectionModel,
QCursor, QHBoxLayout, QPushButton, QSizePolicy, QSplitter, QAbstractItemView) QCursor, QHBoxLayout, QPushButton, QSizePolicy, QSplitter, QAbstractItemView)
from calibre.customize.ui import metadata_plugins from calibre.customize.ui import metadata_plugins
@ -234,7 +234,7 @@ class ResultsView(QTableView): # {{{
if idx.isValid() and self.model().rowCount() > 0: if idx.isValid() and self.model().rowCount() > 0:
self.show_details(idx) self.show_details(idx)
sm = self.selectionModel() sm = self.selectionModel()
sm.select(idx, sm.ClearAndSelect|sm.Rows) sm.select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect|QItemSelectionModel.SelectionFlag.Rows)
def resize_delegate(self): def resize_delegate(self):
self.rt_delegate.max_width = int(self.width()/2.1) self.rt_delegate.max_width = int(self.width()/2.1)
@ -295,7 +295,7 @@ class ResultsView(QTableView): # {{{
index = self.moveCursor(ac, ev.modifiers()) index = self.moveCursor(ac, ev.modifiers())
if index.isValid() and index != self.currentIndex(): if index.isValid() and index != self.currentIndex():
m = self.selectionModel() 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) self.setCurrentIndex(index)
ev.accept() ev.accept()
return return
@ -796,7 +796,7 @@ class CoversView(QListView): # {{{
def select(self, num): def select(self, num):
current = self.model().index(num) current = self.model().index(num)
sm = self.selectionModel() sm = self.selectionModel()
sm.select(current, sm.SelectCurrent) sm.select(current, QItemSelectionModel.SelectionFlag.SelectCurrent)
def start(self): def start(self):
self.select(0) self.select(0)

View File

@ -10,7 +10,7 @@ import os, textwrap, json
from PyQt5.Qt import (QWidget, QDialog, QLabel, QGridLayout, QComboBox, QSize, from PyQt5.Qt import (QWidget, QDialog, QLabel, QGridLayout, QComboBox, QSize,
QLineEdit, QIntValidator, QDoubleValidator, QFrame, Qt, QIcon, QHBoxLayout, QLineEdit, QIntValidator, QDoubleValidator, QFrame, Qt, QIcon, QHBoxLayout,
QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox, QToolButton, QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox, QToolButton, QItemSelectionModel,
QListView, QAbstractListModel, pyqtSignal, QSizePolicy, QSpacerItem, QPalette, QListView, QAbstractListModel, pyqtSignal, QSizePolicy, QSpacerItem, QPalette,
QApplication, QStandardItem, QStandardItemModel, QCheckBox, QMenu, QAbstractItemView) QApplication, QStandardItem, QStandardItemModel, QCheckBox, QMenu, QAbstractItemView)
@ -1135,7 +1135,7 @@ class EditRules(QWidget): # {{{
if idx.isValid(): if idx.isValid():
idx = self.model.move(idx, -1) idx = self.model.move(idx, -1)
if idx is not None: if idx is not None:
sm.select(idx, sm.Toggle) sm.select(idx, QItemSelectionModel.SelectionFlag.Toggle)
self.changed.emit() self.changed.emit()
def move_down(self): def move_down(self):
@ -1149,7 +1149,7 @@ class EditRules(QWidget): # {{{
if idx.isValid(): if idx.isValid():
idx = self.model.move(idx, 1) idx = self.model.move(idx, 1)
if idx is not None: if idx is not None:
sm.select(idx, sm.Toggle) sm.select(idx, QItemSelectionModel.SelectionFlag.Toggle)
self.changed.emit() self.changed.emit()
def clear(self): def clear(self):

View File

@ -14,7 +14,7 @@ from threading import Thread
from PyQt5.Qt import ( from PyQt5.Qt import (
QApplication, QFont, QFontInfo, QFontDialog, QColorDialog, QPainter, QDialog, QApplication, QFont, QFontInfo, QFontDialog, QColorDialog, QPainter, QDialog,
QAbstractListModel, Qt, QIcon, QKeySequence, QColor, pyqtSignal, QCursor, 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 QTableWidget, QTableWidgetItem, QLabel, QFormLayout, QLineEdit, QComboBox, QDialogButtonBox
) )
@ -308,7 +308,7 @@ def move_field_up(widget, model):
idx = model.move(idx, -1) idx = model.move(idx, -1)
if idx is not None: if idx is not None:
sm = widget.selectionModel() sm = widget.selectionModel()
sm.select(idx, sm.ClearAndSelect) sm.select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect)
widget.setCurrentIndex(idx) widget.setCurrentIndex(idx)
@ -318,7 +318,7 @@ def move_field_down(widget, model):
idx = model.move(idx, 1) idx = model.move(idx, 1)
if idx is not None: if idx is not None:
sm = widget.selectionModel() sm = widget.selectionModel()
sm.select(idx, sm.ClearAndSelect) sm.select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect)
widget.setCurrentIndex(idx) widget.setCurrentIndex(idx)
# }}} # }}}

View File

@ -10,7 +10,7 @@ import textwrap, os
from collections import OrderedDict from collections import OrderedDict
from PyQt5.Qt import (Qt, QModelIndex, QAbstractItemModel, QIcon, 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 import ConfigWidgetBase, test_widget
from calibre.gui2.preferences.plugins_ui import Ui_Form from calibre.gui2.preferences.plugins_ui import Ui_Form
@ -260,8 +260,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.highlight_index(idx) self.highlight_index(idx)
def highlight_index(self, idx): def highlight_index(self, idx):
self.plugin_view.selectionModel().select(idx, self.plugin_view.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect)
self.plugin_view.selectionModel().ClearAndSelect)
self.plugin_view.setCurrentIndex(idx) self.plugin_view.setCurrentIndex(idx)
self.plugin_view.setFocus(Qt.FocusReason.OtherFocusReason) self.plugin_view.setFocus(Qt.FocusReason.OtherFocusReason)
self.plugin_view.scrollTo(idx, self.plugin_view.EnsureVisible) self.plugin_view.scrollTo(idx, self.plugin_view.EnsureVisible)

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __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 import force_unicode
from calibre.gui2.preferences.toolbar_ui import Ui_Form 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) idx_map = m.move_many(x, delta)
newci = idx_map.get(i) newci = idx_map.get(i)
if newci is not None: if newci is not None:
sm.setCurrentIndex(newci, sm.ClearAndSelect) sm.setCurrentIndex(newci, QItemSelectionModel.SelectionFlag.ClearAndSelect)
sm.clear() sm.clear()
for idx in idx_map.values(): for idx in idx_map.values():
sm.select(idx, sm.Select) sm.select(idx, QItemSelectionModel.SelectionFlag.Select)
self.changed_signal.emit() self.changed_signal.emit()
def commit(self): def commit(self):

View File

@ -11,7 +11,7 @@ from operator import attrgetter
from PyQt5.Qt import ( from PyQt5.Qt import (
QAbstractListModel, QApplication, QDialog, QDialogButtonBox, QFont, QGridLayout, QAbstractListModel, QApplication, QDialog, QDialogButtonBox, QFont, QGridLayout,
QGroupBox, QIcon, QLabel, QListView, QMenu, QModelIndex, QPlainTextEdit, 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 QStyleOptionViewItem, Qt, QVBoxLayout, QWidget, pyqtSignal
) )
@ -581,8 +581,7 @@ class ConfigWidget(ConfigWidgetBase):
if not idx.isValid(): if not idx.isValid():
return return
self.view.scrollTo(idx) self.view.scrollTo(idx)
self.view.selectionModel().select(idx, self.view.selectionModel().select(idx, QItemSelectionModel.SelectionFlag.ClearAndSelect)
self.view.selectionModel().ClearAndSelect)
self.view.setCurrentIndex(idx) self.view.setCurrentIndex(idx)
def find_next(self, *args): def find_next(self, *args):

View File

@ -10,7 +10,7 @@ import textwrap
from collections import Counter, OrderedDict, defaultdict from collections import Counter, OrderedDict, defaultdict
from functools import partial from functools import partial
from PyQt5.Qt import ( from PyQt5.Qt import (
QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont, QFormLayout, QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont, QFormLayout, QItemSelectionModel,
QGridLayout, QIcon, QInputDialog, QLabel, QLineEdit, QListWidget, QAbstractItemView, QGridLayout, QIcon, QInputDialog, QLabel, QLineEdit, QListWidget, QAbstractItemView,
QListWidgetItem, QMenu, QPainter, QPixmap, QRadioButton, QScrollArea, QSize, QListWidgetItem, QMenu, QPainter, QPixmap, QRadioButton, QScrollArea, QSize,
QSpinBox, QStyle, QStyledItemDelegate, Qt, QTimer, QTreeWidget, QTreeWidgetItem, QSpinBox, QStyle, QStyledItemDelegate, Qt, QTimer, QTreeWidget, QTreeWidgetItem,
@ -338,7 +338,7 @@ class FileList(QTreeWidget, OpenWithHandler):
if q == current_name: if q == current_name:
self.scrollToItem(c) self.scrollToItem(c)
s = self.selectionModel() 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): def mark_name_as_current(self, name):
current = self.item_from_name(name) current = self.item_from_name(name)

View File

@ -12,7 +12,7 @@ from functools import partial
from PyQt5.Qt import ( from PyQt5.Qt import (
QAbstractListModel, QAction, QApplication, QCheckBox, QComboBox, QFont, QFrame, QAbstractListModel, QAction, QApplication, QCheckBox, QComboBox, QFont, QFrame,
QGridLayout, QHBoxLayout, QIcon, QItemSelection, QKeySequence, QLabel, QLineEdit, 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, QSizePolicy, QStackedLayout, QStyledItemDelegate, Qt, QTimer, QToolBar, QDialog,
QToolButton, QVBoxLayout, QWidget, pyqtSignal, QAbstractItemView, QEvent, QDialogButtonBox QToolButton, QVBoxLayout, QWidget, pyqtSignal, QAbstractItemView, QEvent, QDialogButtonBox
) )
@ -1139,9 +1139,9 @@ class SavedSearches(QWidget):
index = self.model.index_for_search(s) index = self.model.index_for_search(s)
if index.isValid() and index.row() > -1: if index.isValid() and index.row() > -1:
if s is current_search: if s is current_search:
sm.setCurrentIndex(index, sm.Select) sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.Select)
else: else:
sm.select(index, sm.Select) sm.select(index, QItemSelectionModel.SelectionFlag.Select)
def search_editing_done(self, save_changes): def search_editing_done(self, save_changes):
if save_changes and not self.edit_search_widget.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) index = self.model.index(self.model.rowCount() - 1)
self.searches.scrollTo(index) self.searches.scrollTo(index)
sm = self.searches.selectionModel() sm = self.searches.selectionModel()
sm.setCurrentIndex(index, sm.ClearAndSelect) sm.setCurrentIndex(index, QItemSelectionModel.SelectionFlag.ClearAndSelect)
self.show_details() self.show_details()
def add_predefined_search(self, state): def add_predefined_search(self, state):
@ -1239,7 +1239,7 @@ class SavedSearches(QWidget):
self.model.add_searches(count=count) self.model.add_searches(count=count)
sm = self.searches.selectionModel() sm = self.searches.selectionModel()
top, bottom = self.model.index(self.model.rowCount() - count), self.model.index(self.model.rowCount() - 1) 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) self.searches.scrollTo(bottom)
def copy_to_search_panel(self): def copy_to_search_panel(self):

View File

@ -9,7 +9,7 @@ import shutil
from PyQt5.Qt import ( from PyQt5.Qt import (
QAbstractListModel, Qt, QModelIndex, QApplication, QWidget, QAbstractListModel, Qt, QModelIndex, QApplication, QWidget,
QGridLayout, QListView, QStyledItemDelegate, pyqtSignal, QPushButton, QIcon) QGridLayout, QListView, QStyledItemDelegate, pyqtSignal, QPushButton, QIcon, QItemSelectionModel)
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
@ -217,7 +217,7 @@ class CheckpointView(QWidget):
self.view.clearSelection() self.view.clearSelection()
m = self.view.model() m = self.view.model()
sm = self.view.selectionModel() 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)) self.view.setCurrentIndex(m.index(m.pos))
def double_clicked(self, index): def double_clicked(self, index):
@ -242,4 +242,3 @@ class CheckpointView(QWidget):
return error_dialog(self, _('Cannot compare'), _( return error_dialog(self, _('Cannot compare'), _(
'There is no point comparing the current state to itself'), show=True) 'There is no point comparing the current state to itself'), show=True)
self.compare_requested.emit(m.states[row].container) self.compare_requested.emit(m.states[row].container)

View File

@ -11,7 +11,7 @@ from collections import OrderedDict
from PyQt5.Qt import ( from PyQt5.Qt import (
QGridLayout, QLabel, QLineEdit, QVBoxLayout, QFormLayout, QHBoxLayout, QGridLayout, QLabel, QLineEdit, QVBoxLayout, QFormLayout, QHBoxLayout,
QToolButton, QIcon, QApplication, Qt, QWidget, QPoint, QSizePolicy, QToolButton, QIcon, QApplication, Qt, QWidget, QPoint, QSizePolicy,
QPainter, QStaticText, pyqtSignal, QTextOption, QAbstractListModel, QPainter, QStaticText, pyqtSignal, QTextOption, QAbstractListModel, QItemSelectionModel,
QModelIndex, QStyledItemDelegate, QStyle, QCheckBox, QListView, QPalette, QModelIndex, QStyledItemDelegate, QStyle, QCheckBox, QListView, QPalette,
QTextDocument, QSize, QComboBox, QFrame, QCursor, QGroupBox, QSplitter, QTextDocument, QSize, QComboBox, QFrame, QCursor, QGroupBox, QSplitter,
QPixmap, QRect, QPlainTextEdit, QMimeData, QDialog, QEvent, QDialogButtonBox) QPixmap, QRect, QPlainTextEdit, QMimeData, QDialog, QEvent, QDialogButtonBox)
@ -901,12 +901,12 @@ class InsertSemantics(Dialog):
row = self.file_names.model().find_name(name) row = self.file_names.model().find_name(name)
if row is not None: if row is not None:
sm = self.file_names.selectionModel() 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: if frag:
row = self.anchor_names.model().find_name(frag) row = self.anchor_names.model().find_name(frag)
if row is not None: if row is not None:
sm = self.anchor_names.selectionModel() 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) self.target.blockSignals(True)
if name is not None: if name is not None:
self.target.setText(name + (('#' + frag) if frag else '')) self.target.setText(name + (('#' + frag) if frag else ''))