More stupid PyQt enums

This commit is contained in:
Kovid Goyal 2020-12-20 11:19:36 +05:30
parent dec3f403f0
commit 1a3ca21b18
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 7 additions and 7 deletions

View File

@ -1137,10 +1137,10 @@ class GridView(QListView):
def moveCursor(self, action, modifiers): def moveCursor(self, action, modifiers):
index = QListView.moveCursor(self, action, modifiers) index = QListView.moveCursor(self, action, modifiers)
if action in (QListView.MoveLeft, QListView.MoveRight) and index.isValid(): if action in (QAbstractItemView.CursorAction.MoveLeft, QAbstractItemView.CursorAction.MoveRight) and index.isValid():
ci = self.currentIndex() ci = self.currentIndex()
if ci.isValid() and index.row() == ci.row(): if ci.isValid() and index.row() == ci.row():
nr = index.row() + (1 if action == QListView.MoveRight else -1) nr = index.row() + (1 if action == QAbstractItemView.CursorAction.MoveRight else -1)
if 0 <= nr < self.model().rowCount(QModelIndex()): if 0 <= nr < self.model().rowCount(QModelIndex()):
index = self.model().index(nr, 0) index = self.model().index(nr, 0)
return index return index

View File

@ -1166,7 +1166,7 @@ class BooksView(QTableView): # {{{
def moveCursor(self, action, modifiers): def moveCursor(self, action, modifiers):
orig = self.currentIndex() orig = self.currentIndex()
index = QTableView.moveCursor(self, action, modifiers) index = QTableView.moveCursor(self, action, modifiers)
if action == QTableView.MovePageDown: if action == QAbstractItemView.CursorAction.MovePageDown:
moved = index.row() - orig.row() moved = index.row() - orig.row()
try: try:
rows = self.row_at_bottom() - self.row_at_top() rows = self.row_at_bottom() - self.row_at_top()
@ -1174,7 +1174,7 @@ class BooksView(QTableView): # {{{
rows = moved rows = moved
if moved > rows: if moved > rows:
index = self.model().index(orig.row() + rows, index.column()) index = self.model().index(orig.row() + rows, index.column())
elif action == QTableView.MovePageUp: elif action == QAbstractItemView.CursorAction.MovePageUp:
moved = orig.row() - index.row() moved = orig.row() - index.row()
try: try:
rows = self.row_at_bottom() - self.row_at_top() rows = self.row_at_bottom() - self.row_at_top()
@ -1182,9 +1182,9 @@ class BooksView(QTableView): # {{{
rows = moved rows = moved
if moved > rows: if moved > rows:
index = self.model().index(orig.row() - rows, index.column()) index = self.model().index(orig.row() - rows, index.column())
elif action == QTableView.MoveHome and modifiers & Qt.KeyboardModifier.ControlModifier: elif action == QAbstractItemView.CursorAction.MoveHome and modifiers & Qt.KeyboardModifier.ControlModifier:
return self.model().index(0, orig.column()) return self.model().index(0, orig.column())
elif action == QTableView.MoveEnd and modifiers & Qt.KeyboardModifier.ControlModifier: elif action == QAbstractItemView.CursorAction.MoveEnd and modifiers & Qt.KeyboardModifier.ControlModifier:
return self.model().index(self.model().rowCount(QModelIndex()) - 1, orig.column()) return self.model().index(self.model().rowCount(QModelIndex()) - 1, orig.column())
return index return index

View File

@ -291,7 +291,7 @@ class ResultsView(QTableView): # {{{
def keyPressEvent(self, ev): def keyPressEvent(self, ev):
if ev.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right): if ev.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right):
ac = self.MoveDown if ev.key() == Qt.Key.Key_Right else self.MoveUp ac = QAbstractItemView.CursorAction.MoveDown if ev.key() == Qt.Key.Key_Right else QAbstractItemView.CursorAction.MoveUp
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()