Fix #1864341 [Python error when trying to select several books](https://bugs.launchpad.net/calibre/+bug/1864341)

This commit is contained in:
Kovid Goyal 2020-02-23 11:42:32 +05:30
parent 8439a6b09c
commit df0dfd04de
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1049,12 +1049,15 @@ class GridView(QListView):
def number_of_columns(self): def number_of_columns(self):
# Number of columns currently visible in the grid # Number of columns currently visible in the grid
if self._ncols is None: if self._ncols is None:
dpr = self.device_pixel_ratio
width = int(dpr * self.delegate.cover_size.width())
height = int(dpr * self.delegate.cover_size.height())
step = max(10, self.spacing()) step = max(10, self.spacing())
for y in range(step, 500, step): for y in range(step, 2 * height, step):
for x in range(step, 500, step): for x in range(step, 2 * width, step):
i = self.indexAt(QPoint(x, y)) i = self.indexAt(QPoint(x, y))
if i.isValid(): if i.isValid():
for x in range(self.viewport().width() - step, self.viewport().width() - 300, -step): for x in range(self.viewport().width() - step, self.viewport().width() - width, -step):
j = self.indexAt(QPoint(x, y)) j = self.indexAt(QPoint(x, y))
if j.isValid(): if j.isValid():
self._ncols = j.row() - i.row() + 1 self._ncols = j.row() - i.row() + 1
@ -1070,7 +1073,8 @@ class GridView(QListView):
if not ci.isValid(): if not ci.isValid():
return return
c = ci.row() c = ci.row()
delta = {Qt.Key_Left: -1, Qt.Key_Right: 1, Qt.Key_Up: -self.number_of_columns(), Qt.Key_Down: self.number_of_columns()}[k] ncols = self.number_of_columns() or 1
delta = {Qt.Key_Left: -1, Qt.Key_Right: 1, Qt.Key_Up: -ncols, Qt.Key_Down: ncols}[k]
n = max(0, min(c + delta, self.model().rowCount(None) - 1)) n = max(0, min(c + delta, self.model().rowCount(None) - 1))
if n == c: if n == c:
return return