Skip to content

Commit

Permalink
Show a busy cursor when running the search in the match books dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Feb 23, 2016
1 parent 37eacf6 commit 9e775f3
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/calibre/gui2/dialogs/match_books.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


from PyQt5.Qt import (Qt, QDialog, QAbstractItemView, QTableWidgetItem,
QByteArray)
QByteArray, QApplication, QCursor)

from calibre.gui2 import gprefs, error_dialog
from calibre.gui2.dialogs.match_books_ui import Ui_MatchBooks
Expand Down Expand Up @@ -129,25 +129,31 @@ def do_search(self):
_('You must enter a search expression into the search box'))
d.exec_()
return
books = self.library_db.data.search(query, return_matches=True)
self.books_table.setRowCount(len(books))

self.books_table.setSortingEnabled(False)
for row, b in enumerate(books):
mi = self.library_db.get_metadata(b, index_is_id=True, get_user_categories=False)
a = TableItem(mi.title, mi.title_sort)
a.setData(Qt.UserRole, b)
self.books_table.setItem(row, 0, a)
a = TableItem(' & '.join(mi.authors), mi.author_sort)
self.books_table.setItem(row, 1, a)
series = mi.format_field('series')[1]
if series is None:
series = ''
a = TableItem(series, mi.series, mi.series_index)
self.books_table.setItem(row, 2, a)
self.books_table.setRowHeight(row, self.books_table_row_height)

self.books_table.setSortingEnabled(True)
try:
self.search_button.setEnabled(False)
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
books = self.library_db.data.search(query, return_matches=True)
self.books_table.setRowCount(len(books))

self.books_table.setSortingEnabled(False)
for row, b in enumerate(books):
mi = self.library_db.get_metadata(b, index_is_id=True, get_user_categories=False)
a = TableItem(mi.title, mi.title_sort)
a.setData(Qt.UserRole, b)
self.books_table.setItem(row, 0, a)
a = TableItem(' & '.join(mi.authors), mi.author_sort)
self.books_table.setItem(row, 1, a)
series = mi.format_field('series')[1]
if series is None:
series = ''
a = TableItem(series, mi.series, mi.series_index)
self.books_table.setItem(row, 2, a)
self.books_table.setRowHeight(row, self.books_table_row_height)

self.books_table.setSortingEnabled(True)
finally:
self.search_button.setEnabled(True)
QApplication.restoreOverrideCursor()

# Deal with sizing the table columns. Done here because the numbers are not
# correct until the first paint.
Expand Down

0 comments on commit 9e775f3

Please sign in to comment.