From a6361f395ce0afec03468a238a7b0b08561e9ba8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 15 Jun 2008 22:50:19 -0700 Subject: [PATCH] Fix #789 --- src/calibre/gui2/dialogs/fetch_metadata.py | 72 +++++++++++---------- src/calibre/gui2/dialogs/fetch_metadata.ui | 2 +- src/calibre/gui2/dialogs/metadata_single.py | 2 +- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/calibre/gui2/dialogs/fetch_metadata.py b/src/calibre/gui2/dialogs/fetch_metadata.py index 9a64c8dc42..f905e72e81 100644 --- a/src/calibre/gui2/dialogs/fetch_metadata.py +++ b/src/calibre/gui2/dialogs/fetch_metadata.py @@ -12,7 +12,7 @@ from PyQt4.QtGui import QDialog, QItemSelectionModel from calibre.gui2.dialogs.fetch_metadata_ui import Ui_FetchMetadata from calibre.gui2 import error_dialog, NONE, info_dialog -from calibre.ebooks.metadata.isbndb import create_books, option_parser +from calibre.ebooks.metadata.isbndb import create_books, option_parser, ISBNDBError from calibre import Settings class Matches(QAbstractTableModel): @@ -88,8 +88,7 @@ class FetchMetadata(QDialog, Ui_FetchMetadata): self.connect(self.matches, SIGNAL('activated(QModelIndex)'), self.chosen) key = str(self.key.text()) if key: - QTimer.singleShot(100, self.fetch.click) - + QTimer.singleShot(100, self.fetch_metadata) def show_summary(self, current, previous): @@ -106,7 +105,7 @@ class FetchMetadata(QDialog, Ui_FetchMetadata): _('You must specify a valid access key for isbndb.com')) return else: - Settings().set('isbndb.com key', str(self.key.text())) + Settings().set('isbndb.com key', key) args = ['isbndb'] if self.isbn: @@ -121,36 +120,41 @@ class FetchMetadata(QDialog, Ui_FetchMetadata): self.fetch.setEnabled(False) self.setCursor(Qt.WaitCursor) QCoreApplication.instance().processEvents() - - args.append(key) - parser = option_parser() - opts, args = parser.parse_args(args) - - self.logger = logging.getLogger('Job #'+str(id)) - self.logger.setLevel(logging.DEBUG) - self.log_dest = cStringIO.StringIO() - handler = logging.StreamHandler(self.log_dest) - handler.setLevel(logging.DEBUG) - handler.setFormatter(logging.Formatter('[%(levelname)s] %(filename)s:%(lineno)s: %(message)s')) - self.logger.addHandler(handler) - - books = create_books(opts, args, self.logger, self.timeout) - - self.model = Matches(books) - if self.model.rowCount() < 1: - info_dialog(self, _('No metadata found'), _('No metadata found, try adjusting the title and author or the ISBN key.')).exec_() - self.reject() - - self.matches.setModel(self.model) - QObject.connect(self.matches.selectionModel(), SIGNAL('currentRowChanged(QModelIndex, QModelIndex)'), - self.show_summary) - self.model.reset() - self.matches.selectionModel().select(self.model.index(0, 0), - QItemSelectionModel.Select | QItemSelectionModel.Rows) - self.matches.setCurrentIndex(self.model.index(0, 0)) - self.fetch.setEnabled(True) - self.unsetCursor() - self.matches.resizeColumnsToContents() + try: + args.append(key) + parser = option_parser() + opts, args = parser.parse_args(args) + + self.logger = logging.getLogger('Job #'+str(id)) + self.logger.setLevel(logging.DEBUG) + self.log_dest = cStringIO.StringIO() + handler = logging.StreamHandler(self.log_dest) + handler.setLevel(logging.DEBUG) + handler.setFormatter(logging.Formatter('[%(levelname)s] %(filename)s:%(lineno)s: %(message)s')) + self.logger.addHandler(handler) + + try: + books = create_books(opts, args, self.logger, self.timeout) + except ISBNDBError, err: + error_dialog(self, _('Error fetching metadata'), str(err)).exec_() + return + + self.model = Matches(books) + if self.model.rowCount() < 1: + info_dialog(self, _('No metadata found'), _('No metadata found, try adjusting the title and author or the ISBN key.')).exec_() + self.reject() + + self.matches.setModel(self.model) + QObject.connect(self.matches.selectionModel(), SIGNAL('currentRowChanged(QModelIndex, QModelIndex)'), + self.show_summary) + self.model.reset() + self.matches.selectionModel().select(self.model.index(0, 0), + QItemSelectionModel.Select | QItemSelectionModel.Rows) + self.matches.setCurrentIndex(self.model.index(0, 0)) + finally: + self.fetch.setEnabled(True) + self.unsetCursor() + self.matches.resizeColumnsToContents() diff --git a/src/calibre/gui2/dialogs/fetch_metadata.ui b/src/calibre/gui2/dialogs/fetch_metadata.ui index 959fb18d89..e8b4252d8d 100644 --- a/src/calibre/gui2/dialogs/fetch_metadata.ui +++ b/src/calibre/gui2/dialogs/fetch_metadata.ui @@ -47,7 +47,7 @@ - &Access Key; + &Access Key: key diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index af2c97a3be..f4fce00482 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -6,7 +6,7 @@ add/remove formats ''' import os -from PyQt4.QtCore import SIGNAL, QObject, QCoreApplication, Qt, QVariant +from PyQt4.QtCore import SIGNAL, QObject, QCoreApplication, Qt from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog