From 261eaad8d275667ff452a6e8d7287bbfb04794b7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 Apr 2011 16:34:05 -0600 Subject: [PATCH] Allow editing of all identifiers in the new metadata edit dialog --- src/calibre/gui2/metadata/basic_widgets.py | 37 +++++++++++++++------- src/calibre/gui2/metadata/single.py | 28 ++++++++-------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index 995fa082a7..bab9073588 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -902,8 +902,11 @@ class TagsEdit(MultiCompleteLineEdit): # {{{ # }}} -class ISBNEdit(QLineEdit): # {{{ - LABEL = _('IS&BN:') +class IdentifiersEdit(QLineEdit): # {{{ + LABEL = _('I&ds:') + BASE_TT = _('Edit the identifiers for this book. ' + 'For example: \n\n%s')%( + 'isbn:1565927249, doi:10.1000/182, amazon:1565927249') def __init__(self, parent): QLineEdit.__init__(self, parent) @@ -913,32 +916,44 @@ class ISBNEdit(QLineEdit): # {{{ @dynamic_property def current_val(self): def fget(self): - return self.pat.sub('', unicode(self.text()).strip()) + raw = unicode(self.text()).strip() + parts = [x.strip() for x in raw.split(',')] + ans = {} + for x in parts: + c = x.split(':') + if len(c) == 2: + ans[c[0]] = c[1] + return ans def fset(self, val): if not val: - val = '' - self.setText(val.strip()) + val = {} + txt = ', '.join(['%s:%s'%(k, v) for k, v in val.iteritems()]) + self.setText(txt.strip()) return property(fget=fget, fset=fset) def initialize(self, db, id_): - self.current_val = db.isbn(id_, index_is_id=True) + self.current_val = db.get_identifiers(id_, index_is_id=True) self.original_val = self.current_val def commit(self, db, id_): - db.set_isbn(id_, self.current_val, notify=False, commit=False) + if self.original_val != self.current_val: + db.set_identifiers(id_, self.current_val, notify=False, commit=False) return True def validate(self, *args): - isbn = self.current_val - tt = _('This ISBN number is valid') + identifiers = self.current_val + isbn = identifiers.get('isbn', '') + tt = self.BASE_TT + extra = '' if not isbn: col = 'rgba(0,255,0,0%)' elif check_isbn(isbn) is not None: col = 'rgba(0,255,0,20%)' + extra = '\n\n'+_('This ISBN number is valid') else: col = 'rgba(255,0,0,20%)' - tt = _('This ISBN number is invalid') - self.setToolTip(tt) + extra = '\n\n' + _('This ISBN number is invalid') + self.setToolTip(tt+extra) self.setStyleSheet('QLineEdit { background-color: %s }'%col) # }}} diff --git a/src/calibre/gui2/metadata/single.py b/src/calibre/gui2/metadata/single.py index e20c519aa8..70307eb3b1 100644 --- a/src/calibre/gui2/metadata/single.py +++ b/src/calibre/gui2/metadata/single.py @@ -17,10 +17,10 @@ from PyQt4.Qt import (Qt, QVBoxLayout, QHBoxLayout, QWidget, QPushButton, from calibre.ebooks.metadata import authors_to_string, string_to_authors from calibre.gui2 import ResizableDialog, error_dialog, gprefs -from calibre.gui2.metadata.basic_widgets import TitleEdit, AuthorsEdit, \ - AuthorSortEdit, TitleSortEdit, SeriesEdit, SeriesIndexEdit, ISBNEdit, \ - RatingEdit, PublisherEdit, TagsEdit, FormatsManager, Cover, CommentsEdit, \ - BuddyLabel, DateEdit, PubdateEdit +from calibre.gui2.metadata.basic_widgets import (TitleEdit, AuthorsEdit, + AuthorSortEdit, TitleSortEdit, SeriesEdit, SeriesIndexEdit, IdentifiersEdit, + RatingEdit, PublisherEdit, TagsEdit, FormatsManager, Cover, CommentsEdit, + BuddyLabel, DateEdit, PubdateEdit) from calibre.gui2.custom_column_widgets import populate_metadata_page from calibre.utils.config import tweaks @@ -147,8 +147,8 @@ class MetadataSingleDialogBase(ResizableDialog): self.tags_editor_button.clicked.connect(self.tags_editor) self.basic_metadata_widgets.append(self.tags) - self.isbn = ISBNEdit(self) - self.basic_metadata_widgets.append(self.isbn) + self.identifiers = IdentifiersEdit(self) + self.basic_metadata_widgets.append(self.identifiers) self.publisher = PublisherEdit(self) self.basic_metadata_widgets.append(self.publisher) @@ -282,8 +282,8 @@ class MetadataSingleDialogBase(ResizableDialog): self.publisher.current_val = mi.publisher if not mi.is_null('tags'): self.tags.current_val = mi.tags - if not mi.is_null('isbn'): - self.isbn.current_val = mi.isbn + if not mi.is_null('identifiers'): + self.identifiers.current_val = mi.identifiers if not mi.is_null('pubdate'): self.pubdate.current_val = mi.pubdate if not mi.is_null('series') and mi.series.strip(): @@ -486,9 +486,9 @@ class MetadataSingleDialog(MetadataSingleDialogBase): # {{{ create_row2(1, self.rating) sto(self.rating, self.tags) create_row2(2, self.tags, self.tags_editor_button) - sto(self.tags_editor_button, self.isbn) - create_row2(3, self.isbn) - sto(self.isbn, self.timestamp) + sto(self.tags_editor_button, self.identifiers) + create_row2(3, self.identifiers) + sto(self.identifiers, self.timestamp) create_row2(4, self.timestamp, self.timestamp.clear_button) sto(self.timestamp.clear_button, self.pubdate) create_row2(5, self.pubdate, self.pubdate.clear_button) @@ -573,9 +573,9 @@ class MetadataSingleDialogAlt(MetadataSingleDialogBase): # {{{ create_row(8, self.pubdate, self.publisher, button=self.pubdate.clear_button, icon='trash.png') create_row(9, self.publisher, self.timestamp) - create_row(10, self.timestamp, self.isbn, + create_row(10, self.timestamp, self.identifiers, button=self.timestamp.clear_button, icon='trash.png') - create_row(11, self.isbn, self.comments) + create_row(11, self.identifiers, self.comments) tl.addItem(QSpacerItem(1, 1, QSizePolicy.Fixed, QSizePolicy.Expanding), 12, 1, 1 ,1) @@ -591,7 +591,7 @@ class MetadataSingleDialogAlt(MetadataSingleDialogBase): # {{{ sr.setWidget(w) gbl.addWidget(sr) self.tabs[0].l.addWidget(gb, 0, 1, 1, 1) - sto(self.isbn, gb) + sto(self.identifiers, gb) w = QGroupBox(_('&Comments'), tab0) sp = QSizePolicy()