mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #8244 (Merging two books fails 0.7.38). Fix bug in formatter where parse errors at end of file threw an exception instead of providing the message. Add access to the larger template editor from plugboards via context menu.
This commit is contained in:
commit
60d5f0f04d
@ -5,11 +5,11 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4.Qt import Qt
|
||||
from PyQt4.Qt import Qt, QLineEdit, QComboBox, SIGNAL, QListWidgetItem
|
||||
|
||||
from calibre.gui2 import error_dialog
|
||||
from calibre.gui2.device import device_name_for_plugboards
|
||||
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||
from calibre.gui2.preferences.plugboard_ui import Ui_Form
|
||||
from calibre.customize.ui import metadata_writers, device_plugins
|
||||
@ -17,6 +17,27 @@ from calibre.library.save_to_disk import plugboard_any_format_value, \
|
||||
plugboard_any_device_value, plugboard_save_to_disk_value
|
||||
from calibre.utils.formatter import validation_formatter
|
||||
|
||||
|
||||
class LineEditWithTextBox(QLineEdit):
|
||||
|
||||
'''
|
||||
Extend the context menu of a QLineEdit to include more actions.
|
||||
'''
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
menu = self.createStandardContextMenu()
|
||||
menu.addSeparator()
|
||||
|
||||
action_open_editor = menu.addAction(_('Open Editor'))
|
||||
|
||||
self.connect(action_open_editor, SIGNAL('triggered()'), self.open_editor)
|
||||
menu.exec_(event.globalPos())
|
||||
|
||||
def open_editor(self):
|
||||
t = TemplateDialog(self, self.text())
|
||||
if t.exec_():
|
||||
self.setText(t.textbox.toPlainText())
|
||||
|
||||
class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
|
||||
def genesis(self, gui):
|
||||
@ -72,10 +93,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.source_widgets = []
|
||||
self.dest_widgets = []
|
||||
for i in range(0, len(self.dest_fields)-1):
|
||||
w = QtGui.QLineEdit(self)
|
||||
w = LineEditWithTextBox(self)
|
||||
self.source_widgets.append(w)
|
||||
self.fields_layout.addWidget(w, 5+i, 0, 1, 1)
|
||||
w = QtGui.QComboBox(self)
|
||||
w = QComboBox(self)
|
||||
self.dest_widgets.append(w)
|
||||
self.fields_layout.addWidget(w, 5+i, 1, 1, 1)
|
||||
|
||||
@ -297,7 +318,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
for op in self.current_plugboards[f][d]:
|
||||
ops.append('([' + op[0] + '] -> ' + op[1] + ')')
|
||||
txt = '%s:%s = %s\n'%(f, d, ', '.join(ops))
|
||||
item = QtGui.QListWidgetItem(txt)
|
||||
item = QListWidgetItem(txt)
|
||||
item.setData(Qt.UserRole, (f, d))
|
||||
self.existing_plugboards.addItem(item)
|
||||
self.refilling = False
|
||||
|
@ -151,6 +151,8 @@ class CustomColumns(object):
|
||||
return v
|
||||
|
||||
def adapt_number(x, d):
|
||||
if x is None:
|
||||
return None
|
||||
if isinstance(x, (str, unicode, bytes)):
|
||||
if x.lower() == 'none':
|
||||
return None
|
||||
|
@ -98,9 +98,10 @@ class _Parser(object):
|
||||
m = 'Formatter: ' + message + _(' near ')
|
||||
if self.lex_pos > 0:
|
||||
m = '{0} {1}'.format(m, self.prog[self.lex_pos-1][1])
|
||||
m = '{0} {1}'.format(m, self.prog[self.lex_pos][1])
|
||||
if self.lex_pos < len(self.prog):
|
||||
elif self.lex_pos < len(self.prog):
|
||||
m = '{0} {1}'.format(m, self.prog[self.lex_pos+1][1])
|
||||
else:
|
||||
m = '{0} {1}'.format(m, _('end of program'))
|
||||
raise ValueError(m)
|
||||
|
||||
def token(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user