Edit metadata dialog: Allow right clicking the Paste isbn button to instead paste an identifier with a different prefix. Fixes #1698543 [Enhancement: Paste of various IDs in Edit Metadata dialog](https://bugs.launchpad.net/calibre/+bug/1698543)

This commit is contained in:
Kovid Goyal 2017-06-22 09:24:50 +05:30
parent 7de2e366cf
commit 638ef59082
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 46 additions and 7 deletions

View File

@ -151,6 +151,7 @@ def create_defs():
defs['row_numbers_in_book_list'] = True
defs['hidpi'] = 'auto'
defs['tag_browser_item_padding'] = 0.5
defs['paste_isbn_prefixes'] = ['isbn', 'url', 'amazon', 'google']
create_defs()

View File

@ -25,7 +25,7 @@ from calibre.ebooks.metadata import (
title_sort, string_to_authors, check_isbn, authors_to_sort_string)
from calibre.ebooks.metadata.meta import get_metadata
from calibre.gui2 import (file_icon_provider, UNDEFINED_QDATETIME,
choose_files, error_dialog, choose_images)
choose_files, error_dialog, choose_images, gprefs)
from calibre.gui2.complete2 import EditWithComplete
from calibre.utils.date import (
local_tz, qt_to_dt, as_local_time, UNDEFINED_DATE, is_date_undefined,
@ -1536,6 +1536,23 @@ class IdentifiersEdit(QLineEdit, ToMetadataMixin):
self.setToolTip(tt+extra)
self.setStyleSheet(INDICATOR_SHEET % col)
def paste_identifier(self):
try:
prefix = gprefs['paste_isbn_prefixes'][0]
except IndexError:
prefix = 'isbn'
self.paste_prefix(prefix)
def paste_prefix(self, prefix):
if prefix == 'isbn':
self.paste_isbn()
else:
text = unicode(QApplication.clipboard().text()).strip()
if text:
vals = self.current_val
vals[prefix] = text
self.current_val = vals
def paste_isbn(self):
text = unicode(QApplication.clipboard().text()).strip()
if not text or not check_isbn(text):

View File

@ -9,10 +9,11 @@ __docformat__ = 'restructuredtext en'
import os, errno
from datetime import datetime
from functools import partial
from PyQt5.Qt import (Qt, QVBoxLayout, QHBoxLayout, QWidget, QPushButton,
QGridLayout, pyqtSignal, QDialogButtonBox, QScrollArea, QFont, QCoreApplication,
QTabWidget, QIcon, QToolButton, QSplitter, QGroupBox, QSpacerItem,
QTabWidget, QIcon, QToolButton, QSplitter, QGroupBox, QSpacerItem, QInputDialog,
QSizePolicy, QFrame, QSize, QKeySequence, QMenu, QShortcut, QDialog)
from calibre.constants import isosx
@ -242,12 +243,16 @@ class MetadataSingleDialogBase(QDialog):
self.clear_identifiers_button.setIcon(QIcon(I('trash.png')))
self.clear_identifiers_button.setToolTip(_('Clear Ids'))
self.clear_identifiers_button.clicked.connect(self.identifiers.clear)
self.paste_isbn_button = QToolButton(self)
self.paste_isbn_button.setToolTip('<p>' +
self.paste_isbn_button = b = RightClickButton(self)
b.setToolTip('<p>' +
_('Paste the contents of the clipboard into the '
'identifiers box prefixed with isbn:') + '</p>')
self.paste_isbn_button.setIcon(QIcon(I('edit-paste.png')))
self.paste_isbn_button.clicked.connect(self.identifiers.paste_isbn)
'identifiers prefixed with isbn:. Or right click, '
'to choose a different prefix.') + '</p>')
b.setIcon(QIcon(I('edit-paste.png')))
b.clicked.connect(self.identifiers.paste_identifier)
b.setPopupMode(b.DelayedPopup)
b.setMenu(QMenu())
self.update_paste_identifiers_menu()
self.publisher = PublisherEdit(self)
self.basic_metadata_widgets.append(self.publisher)
@ -290,6 +295,22 @@ class MetadataSingleDialogBase(QDialog):
# }}}
def update_paste_identifiers_menu(self):
m = self.paste_isbn_button.menu()
m.clear()
m.addAction(_('Edit list of prefixes'), self.edit_prefix_list)
m.addSeparator()
for prefix in gprefs['paste_isbn_prefixes'][1:]:
m.addAction(prefix, partial(self.identifiers.paste_prefix, prefix))
def edit_prefix_list(self):
prefixes, ok = QInputDialog.getMultiLineText(
self, _('Edit prefixes'), _('Enter prefixes, one on a line. The first prefix becomes the default.'),
'\n'.join(list(map(type(u''), gprefs['paste_isbn_prefixes']))))
if ok:
gprefs['paste_isbn_prefixes'] = list(filter(None, (x.strip() for x in prefixes.splitlines()))) or gprefs.defaults['paste_isbn_prefixes']
self.update_paste_identifiers_menu()
def create_custom_metadata_widgets(self): # {{{
self.custom_metadata_widgets_parent = w = QWidget(self)
layout = QGridLayout()