From 3b78209a8d6fbb2e20c55d2163f025bd89cc43fd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 16 Apr 2011 21:24:04 -0600 Subject: [PATCH] Edit metadata dialog: Add an action to generate author sort from author --- src/calibre/gui2/metadata/basic_widgets.py | 12 +++++++++++- src/calibre/gui2/metadata/single.py | 14 ++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index 73913ba58f..25034bbfbd 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -222,7 +222,8 @@ class AuthorSortEdit(EnLineEdit): 'red, then the authors and this text do not match.') LABEL = _('Author s&ort:') - def __init__(self, parent, authors_edit, autogen_button, db): + def __init__(self, parent, authors_edit, autogen_button, db, + copy_as_to_a_action): EnLineEdit.__init__(self, parent) self.authors_edit = authors_edit self.db = db @@ -241,6 +242,7 @@ class AuthorSortEdit(EnLineEdit): self.textChanged.connect(self.update_state) autogen_button.clicked.connect(self.auto_generate) + copy_as_to_a_action.triggered.connect(self.copy_to_authors) self.update_state() @dynamic_property @@ -273,6 +275,14 @@ class AuthorSortEdit(EnLineEdit): self.setToolTip(tt) self.setWhatsThis(tt) + def copy_to_authors(self): + aus = self.current_val + if aus: + ln, _, rest = aus.partition(',') + if rest: + au = rest.strip() + ' ' + ln.strip() + self.authors_edit.current_val = [au] + def auto_generate(self, *args): au = unicode(self.authors_edit.text()) au = re.sub(r'\s+et al\.$', '', au) diff --git a/src/calibre/gui2/metadata/single.py b/src/calibre/gui2/metadata/single.py index 2e5b43ceba..215a41a68d 100644 --- a/src/calibre/gui2/metadata/single.py +++ b/src/calibre/gui2/metadata/single.py @@ -13,7 +13,7 @@ from functools import partial from PyQt4.Qt import (Qt, QVBoxLayout, QHBoxLayout, QWidget, QPushButton, QGridLayout, pyqtSignal, QDialogButtonBox, QScrollArea, QFont, QTabWidget, QIcon, QToolButton, QSplitter, QGroupBox, QSpacerItem, - QSizePolicy, QPalette, QFrame, QSize, QKeySequence) + QSizePolicy, QPalette, QFrame, QSize, QKeySequence, QMenu) from calibre.ebooks.metadata import authors_to_string, string_to_authors from calibre.gui2 import ResizableDialog, error_dialog, gprefs, pixmap_to_data @@ -102,15 +102,17 @@ class MetadataSingleDialogBase(ResizableDialog): self.deduce_title_sort_button) self.basic_metadata_widgets.extend([self.title, self.title_sort]) - self.authors = AuthorsEdit(self) - self.deduce_author_sort_button = QToolButton(self) - self.deduce_author_sort_button.setToolTip(_( + self.deduce_author_sort_button = b = QToolButton(self) + b.setToolTip(_( 'Automatically create the author sort entry based on the current' ' author entry.\n' 'Using this button to create author sort will change author sort from' ' red to green.')) - self.author_sort = AuthorSortEdit(self, self.authors, - self.deduce_author_sort_button, self.db) + b.m = m = QMenu() + ac = m.addAction(QIcon(I('back.png')), _('Set author from author sort')) + b.setMenu(m) + self.authors = AuthorsEdit(self) + self.author_sort = AuthorSortEdit(self, self.authors, b, self.db, ac) self.basic_metadata_widgets.extend([self.authors, self.author_sort]) self.swap_title_author_button = QToolButton(self)