Fetch metadata from server button works again, hooray!

This commit is contained in:
Kovid Goyal 2011-04-09 20:54:08 -06:00
parent 1d39d6df7f
commit dedc0979b1
3 changed files with 29 additions and 10 deletions

View File

@ -315,7 +315,7 @@ class SeriesEdit(MultiCompleteComboBox):
if not val: if not val:
val = '' val = ''
self.setEditText(val.strip()) self.setEditText(val.strip())
self.setCursorPosition(0) self.lineEdit().setCursorPosition(0)
return property(fget=fget, fset=fset) return property(fget=fget, fset=fset)
@ -862,6 +862,7 @@ class TagsEdit(MultiCompleteLineEdit): # {{{
if not val: if not val:
val = [] val = []
self.setText(', '.join([x.strip() for x in val])) self.setText(', '.join([x.strip() for x in val]))
self.setCursorPosition(0)
return property(fget=fget, fset=fset) return property(fget=fget, fset=fset)
def initialize(self, db, id_): def initialize(self, db, id_):
@ -928,6 +929,7 @@ class IdentifiersEdit(QLineEdit): # {{{
val = {} val = {}
txt = ', '.join(['%s:%s'%(k, v) for k, v in val.iteritems()]) txt = ', '.join(['%s:%s'%(k, v) for k, v in val.iteritems()])
self.setText(txt.strip()) self.setText(txt.strip())
self.setCursorPosition(0)
return property(fget=fget, fset=fset) return property(fget=fget, fset=fset)
def initialize(self, db, id_): def initialize(self, db, id_):
@ -977,7 +979,7 @@ class PublisherEdit(MultiCompleteComboBox): # {{{
if not val: if not val:
val = '' val = ''
self.setEditText(val.strip()) self.setEditText(val.strip())
self.setCursorPosition(0) self.lineEdit().setCursorPosition(0)
return property(fget=fget, fset=fset) return property(fget=fget, fset=fset)

View File

@ -16,11 +16,12 @@ from PyQt4.Qt import (Qt, QVBoxLayout, QHBoxLayout, QWidget, QPushButton,
QSizePolicy, QPalette, QFrame, QSize, QKeySequence) QSizePolicy, QPalette, QFrame, QSize, QKeySequence)
from calibre.ebooks.metadata import authors_to_string, string_to_authors from calibre.ebooks.metadata import authors_to_string, string_to_authors
from calibre.gui2 import ResizableDialog, error_dialog, gprefs from calibre.gui2 import ResizableDialog, error_dialog, gprefs, pixmap_to_data
from calibre.gui2.metadata.basic_widgets import (TitleEdit, AuthorsEdit, from calibre.gui2.metadata.basic_widgets import (TitleEdit, AuthorsEdit,
AuthorSortEdit, TitleSortEdit, SeriesEdit, SeriesIndexEdit, IdentifiersEdit, AuthorSortEdit, TitleSortEdit, SeriesEdit, SeriesIndexEdit, IdentifiersEdit,
RatingEdit, PublisherEdit, TagsEdit, FormatsManager, Cover, CommentsEdit, RatingEdit, PublisherEdit, TagsEdit, FormatsManager, Cover, CommentsEdit,
BuddyLabel, DateEdit, PubdateEdit) BuddyLabel, DateEdit, PubdateEdit)
from calibre.gui2.metadata.single_download import FullFetch
from calibre.gui2.custom_column_widgets import populate_metadata_page from calibre.gui2.custom_column_widgets import populate_metadata_page
from calibre.utils.config import tweaks from calibre.utils.config import tweaks
@ -303,7 +304,15 @@ class MetadataSingleDialogBase(ResizableDialog):
self.comments.current_val = mi.comments self.comments.current_val = mi.comments
def fetch_metadata(self, *args): def fetch_metadata(self, *args):
pass # TODO: fetch metadata d = FullFetch(self.cover.pixmap(), self)
ret = d.start(title=self.title.current_val, authors=self.authors.current_val,
identifiers=self.identifiers.current_val)
if ret == d.Accepted:
mi = d.book
if mi is not None:
self.update_from_mi(mi)
if d.cover_pixmap is not None:
self.cover.current_val = pixmap_to_data(d.cover_pixmap)
# }}} # }}}
def apply_changes(self): def apply_changes(self):

View File

@ -428,7 +428,7 @@ class IdentifyWidget(QWidget): # {{{
if authors: if authors:
parts.append('authors:'+authors_to_string(authors)) parts.append('authors:'+authors_to_string(authors))
if identifiers: if identifiers:
x = ', '.join('%s:%s'%(k, v) for k, v in identifiers) x = ', '.join('%s:%s'%(k, v) for k, v in identifiers.iteritems())
parts.append(x) parts.append(x)
self.query.setText(_('Query: ')+'; '.join(parts)) self.query.setText(_('Query: ')+'; '.join(parts))
self.log(unicode(self.query.text())) self.log(unicode(self.query.text()))
@ -755,6 +755,10 @@ class LogViewer(QDialog): # {{{
self.bb = QDialogButtonBox(QDialogButtonBox.Close) self.bb = QDialogButtonBox(QDialogButtonBox.Close)
l.addWidget(self.bb) l.addWidget(self.bb)
self.copy_button = self.bb.addButton(_('Copy to clipboard'),
self.bb.ActionRole)
self.copy_button.clicked.connect(self.copy_to_clipboard)
self.copy_button.setIcon(QIcon(I('edit-copy.png')))
self.bb.rejected.connect(self.reject) self.bb.rejected.connect(self.reject)
self.bb.accepted.connect(self.accept) self.bb.accepted.connect(self.accept)
@ -769,6 +773,9 @@ class LogViewer(QDialog): # {{{
self.show() self.show()
def copy_to_clipboard(self):
QApplication.clipboard().setText(''.join(self.log.plain_text))
def stop(self, *args): def stop(self, *args):
self.keep_updating = False self.keep_updating = False
@ -785,9 +792,10 @@ class LogViewer(QDialog): # {{{
class FullFetch(QDialog): # {{{ class FullFetch(QDialog): # {{{
def __init__(self, log, current_cover=None, parent=None): def __init__(self, current_cover=None, parent=None):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
self.log, self.current_cover = log, current_cover self.current_cover = current_cover
self.log = Log()
self.book = self.cover_pixmap = None self.book = self.cover_pixmap = None
self.setWindowTitle(_('Downloading metadata...')) self.setWindowTitle(_('Downloading metadata...'))
@ -813,7 +821,7 @@ class FullFetch(QDialog): # {{{
self.log_button.setIcon(QIcon(I('debug.png'))) self.log_button.setIcon(QIcon(I('debug.png')))
self.ok_button.setVisible(False) self.ok_button.setVisible(False)
self.identify_widget = IdentifyWidget(log, self) self.identify_widget = IdentifyWidget(self.log, self)
self.identify_widget.rejected.connect(self.reject) self.identify_widget.rejected.connect(self.reject)
self.identify_widget.results_found.connect(self.identify_results_found) self.identify_widget.results_found.connect(self.identify_results_found)
self.identify_widget.book_selected.connect(self.book_selected) self.identify_widget.book_selected.connect(self.book_selected)
@ -870,12 +878,12 @@ class FullFetch(QDialog): # {{{
self.title, self.authors = title, authors self.title, self.authors = title, authors
self.identify_widget.start(title=title, authors=authors, self.identify_widget.start(title=title, authors=authors,
identifiers=identifiers) identifiers=identifiers)
self.exec_() return self.exec_()
# }}} # }}}
if __name__ == '__main__': if __name__ == '__main__':
#DEBUG_DIALOG = True #DEBUG_DIALOG = True
app = QApplication([]) app = QApplication([])
d = FullFetch(Log()) d = FullFetch()
d.start(title='jurassic', authors=['crichton']) d.start(title='jurassic', authors=['crichton'])