mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #789
This commit is contained in:
parent
908e31a80c
commit
a6361f395c
@ -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()
|
||||
try:
|
||||
args.append(key)
|
||||
parser = option_parser()
|
||||
opts, args = parser.parse_args(args)
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
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.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()
|
||||
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()
|
||||
|
||||
|
||||
|
||||
|
@ -47,7 +47,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2" >
|
||||
<property name="text" >
|
||||
<string>&Access Key;</string>
|
||||
<string>&Access Key:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>key</cstring>
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user