mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Added a small dialog box to paste_isbn allowing the user to enter the isbn and have it automatically prefixed
This commit is contained in:
parent
1ae2ba5c67
commit
da86b8bb28
@ -11,8 +11,8 @@ import textwrap, re, os
|
||||
|
||||
from PyQt4.Qt import (Qt, QDateEdit, QDate, pyqtSignal, QMessageBox,
|
||||
QIcon, QToolButton, QWidget, QLabel, QGridLayout, QApplication,
|
||||
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap,
|
||||
QPushButton, QSpinBox, QLineEdit, QSizePolicy)
|
||||
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap, QDialog,
|
||||
QPushButton, QSpinBox, QLineEdit, QSizePolicy, QDialogButtonBox)
|
||||
|
||||
from calibre.gui2.widgets import EnLineEdit, FormatList, ImageView
|
||||
from calibre.gui2.complete import MultiCompleteLineEdit, MultiCompleteComboBox
|
||||
@ -1061,13 +1061,58 @@ class IdentifiersEdit(QLineEdit): # {{{
|
||||
|
||||
def paste_isbn(self):
|
||||
text = unicode(QApplication.clipboard().text()).strip()
|
||||
if text:
|
||||
vals = self.current_val
|
||||
vals['isbn'] = text
|
||||
self.current_val = vals
|
||||
if not text or not check_isbn(text):
|
||||
d = ISBNDialog(self, text)
|
||||
if not d.exec_():
|
||||
return
|
||||
text = d.text()
|
||||
if not text:
|
||||
return
|
||||
vals = self.current_val
|
||||
vals['isbn'] = text
|
||||
self.current_val = vals
|
||||
|
||||
# }}}
|
||||
|
||||
class ISBNDialog(QDialog) :
|
||||
|
||||
def __init__(self, parent, txt):
|
||||
QDialog.__init__(self, parent)
|
||||
l = QGridLayout()
|
||||
self.setLayout(l)
|
||||
self.setWindowTitle(_('Empty or Invalid ISBN'))
|
||||
w = QLabel(_('Enter a different ISBN value if desired'))
|
||||
l.addWidget(w, 0, 0, 1, 2)
|
||||
w = QLabel(_('Value:'))
|
||||
l.addWidget(w, 1, 0, 1, 1)
|
||||
self.line_edit = w = QLineEdit();
|
||||
w.setText(txt)
|
||||
w.selectAll()
|
||||
w.textChanged.connect(self.checkText)
|
||||
l.addWidget(w, 1, 1, 1, 1)
|
||||
w = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
|
||||
l.addWidget(w, 2, 0, 1, 2)
|
||||
w.accepted.connect(self.accept)
|
||||
w.rejected.connect(self.reject)
|
||||
self.checkText(self.text())
|
||||
|
||||
def checkText(self, txt):
|
||||
isbn = unicode(txt)
|
||||
if not isbn:
|
||||
col = 'none'
|
||||
extra = ''
|
||||
elif check_isbn(isbn) is not None:
|
||||
col = 'rgba(0,255,0,20%)'
|
||||
extra = _('This ISBN number is valid')
|
||||
else:
|
||||
col = 'rgba(255,0,0,20%)'
|
||||
extra = _('This ISBN number is invalid')
|
||||
self.line_edit.setToolTip(extra)
|
||||
self.line_edit.setStyleSheet('QLineEdit { background-color: %s }'%col)
|
||||
|
||||
def text(self):
|
||||
return unicode(self.line_edit.text())
|
||||
|
||||
class PublisherEdit(MultiCompleteComboBox): # {{{
|
||||
LABEL = _('&Publisher:')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user