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.dialogs.fetch_metadata_ui import Ui_FetchMetadata
|
||||||
from calibre.gui2 import error_dialog, NONE, info_dialog
|
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
|
from calibre import Settings
|
||||||
|
|
||||||
class Matches(QAbstractTableModel):
|
class Matches(QAbstractTableModel):
|
||||||
@ -88,8 +88,7 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
self.connect(self.matches, SIGNAL('activated(QModelIndex)'), self.chosen)
|
self.connect(self.matches, SIGNAL('activated(QModelIndex)'), self.chosen)
|
||||||
key = str(self.key.text())
|
key = str(self.key.text())
|
||||||
if key:
|
if key:
|
||||||
QTimer.singleShot(100, self.fetch.click)
|
QTimer.singleShot(100, self.fetch_metadata)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def show_summary(self, current, previous):
|
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'))
|
_('You must specify a valid access key for isbndb.com'))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
Settings().set('isbndb.com key', str(self.key.text()))
|
Settings().set('isbndb.com key', key)
|
||||||
|
|
||||||
args = ['isbndb']
|
args = ['isbndb']
|
||||||
if self.isbn:
|
if self.isbn:
|
||||||
@ -121,36 +120,41 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
self.fetch.setEnabled(False)
|
self.fetch.setEnabled(False)
|
||||||
self.setCursor(Qt.WaitCursor)
|
self.setCursor(Qt.WaitCursor)
|
||||||
QCoreApplication.instance().processEvents()
|
QCoreApplication.instance().processEvents()
|
||||||
|
try:
|
||||||
|
args.append(key)
|
||||||
|
parser = option_parser()
|
||||||
|
opts, args = parser.parse_args(args)
|
||||||
|
|
||||||
args.append(key)
|
self.logger = logging.getLogger('Job #'+str(id))
|
||||||
parser = option_parser()
|
self.logger.setLevel(logging.DEBUG)
|
||||||
opts, args = parser.parse_args(args)
|
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))
|
try:
|
||||||
self.logger.setLevel(logging.DEBUG)
|
books = create_books(opts, args, self.logger, self.timeout)
|
||||||
self.log_dest = cStringIO.StringIO()
|
except ISBNDBError, err:
|
||||||
handler = logging.StreamHandler(self.log_dest)
|
error_dialog(self, _('Error fetching metadata'), str(err)).exec_()
|
||||||
handler.setLevel(logging.DEBUG)
|
return
|
||||||
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.model = Matches(books)
|
self.matches.setModel(self.model)
|
||||||
if self.model.rowCount() < 1:
|
QObject.connect(self.matches.selectionModel(), SIGNAL('currentRowChanged(QModelIndex, QModelIndex)'),
|
||||||
info_dialog(self, _('No metadata found'), _('No metadata found, try adjusting the title and author or the ISBN key.')).exec_()
|
self.show_summary)
|
||||||
self.reject()
|
self.model.reset()
|
||||||
|
self.matches.selectionModel().select(self.model.index(0, 0),
|
||||||
self.matches.setModel(self.model)
|
QItemSelectionModel.Select | QItemSelectionModel.Rows)
|
||||||
QObject.connect(self.matches.selectionModel(), SIGNAL('currentRowChanged(QModelIndex, QModelIndex)'),
|
self.matches.setCurrentIndex(self.model.index(0, 0))
|
||||||
self.show_summary)
|
finally:
|
||||||
self.model.reset()
|
self.fetch.setEnabled(True)
|
||||||
self.matches.selectionModel().select(self.model.index(0, 0),
|
self.unsetCursor()
|
||||||
QItemSelectionModel.Select | QItemSelectionModel.Rows)
|
self.matches.resizeColumnsToContents()
|
||||||
self.matches.setCurrentIndex(self.model.index(0, 0))
|
|
||||||
self.fetch.setEnabled(True)
|
|
||||||
self.unsetCursor()
|
|
||||||
self.matches.resizeColumnsToContents()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_2" >
|
<widget class="QLabel" name="label_2" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>&Access Key;</string>
|
<string>&Access Key:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy" >
|
<property name="buddy" >
|
||||||
<cstring>key</cstring>
|
<cstring>key</cstring>
|
||||||
|
@ -6,7 +6,7 @@ add/remove formats
|
|||||||
'''
|
'''
|
||||||
import os
|
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
|
from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user