mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:Word wrap tooltips in the conversion preferences
This commit is contained in:
parent
63a37da4ea
commit
e2b1c6d508
@ -36,6 +36,17 @@ class TXTOutput(OutputFormatPlugin):
|
|||||||
OptionRecommendation(name='flush_paras',
|
OptionRecommendation(name='flush_paras',
|
||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
help=_('Do not add a blank line between paragraphs.')),
|
help=_('Do not add a blank line between paragraphs.')),
|
||||||
|
OptionRecommendation(name='max_line_length',
|
||||||
|
recommended_value=0, level=OptionRecommendation.LOW,
|
||||||
|
help=_('The maximum number of characters per line. This splits on '
|
||||||
|
'the first space before the specified value. If no space is found '
|
||||||
|
'the line will be broken at the space after and will exceed the '
|
||||||
|
'specified value. Also, there is a minimum of 25 characters. '
|
||||||
|
'Use 0 to disable line splitting.')),
|
||||||
|
OptionRecommendation(name='force_max_line_length',
|
||||||
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
|
help=_('Force splitting on the max-line-length value when no space '
|
||||||
|
'is present. Also allows max-line-length to be below the minimum')),
|
||||||
OptionRecommendation(name='indent_paras',
|
OptionRecommendation(name='indent_paras',
|
||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
help=_('Add a tab at the beginning of each paragraph.')),
|
help=_('Add a tab at the beginning of each paragraph.')),
|
||||||
|
@ -105,6 +105,40 @@ class TXTMLizer(object):
|
|||||||
if self.opts.indent_paras:
|
if self.opts.indent_paras:
|
||||||
text = re.sub('(?imu)^(?=.)', '\t', text)
|
text = re.sub('(?imu)^(?=.)', '\t', text)
|
||||||
|
|
||||||
|
if self.opts.max_line_length:
|
||||||
|
max_length = self.opts.max_line_length
|
||||||
|
if self.opts.max_line_length < 25 and not self.opts.force_max_line_length:
|
||||||
|
max_length = 25
|
||||||
|
short_lines = []
|
||||||
|
lines = text.splitlines()
|
||||||
|
for line in lines:
|
||||||
|
while len(line) > max_length:
|
||||||
|
space = line.rfind(' ', 0, max_length)
|
||||||
|
if space != -1:
|
||||||
|
# Space was found.
|
||||||
|
short_lines.append(line[:space])
|
||||||
|
line = line[space + 1:]
|
||||||
|
else:
|
||||||
|
# Space was not found.
|
||||||
|
if self.opts.force_max_line_length:
|
||||||
|
# Force breaking at max_lenght.
|
||||||
|
short_lines.append(line[:max_length])
|
||||||
|
line = line[max_length:]
|
||||||
|
else:
|
||||||
|
# Look for the first space after max_length.
|
||||||
|
space = line.find(' ', max_length, len(line))
|
||||||
|
if space != -1:
|
||||||
|
# Space was found.
|
||||||
|
short_lines.append(line[:space])
|
||||||
|
line = line[space + 1:]
|
||||||
|
else:
|
||||||
|
# No space was found cannot break line.
|
||||||
|
short_lines.append(line)
|
||||||
|
line = ''
|
||||||
|
# Add the text that was less than max_lengh to the list
|
||||||
|
short_lines.append(line)
|
||||||
|
text = '\n'.join(short_lines)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def dump_text(self, elem, stylizer, end=''):
|
def dump_text(self, elem, stylizer, end=''):
|
||||||
|
@ -6,6 +6,8 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from PyQt4.Qt import QWidget, QSpinBox, QDoubleSpinBox, QLineEdit, QTextEdit, \
|
from PyQt4.Qt import QWidget, QSpinBox, QDoubleSpinBox, QLineEdit, QTextEdit, \
|
||||||
QCheckBox, QComboBox, Qt, QIcon, SIGNAL
|
QCheckBox, QComboBox, Qt, QIcon, SIGNAL
|
||||||
|
|
||||||
@ -135,6 +137,7 @@ class Widget(QWidget):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def setup_help(self, help_provider):
|
def setup_help(self, help_provider):
|
||||||
|
w = textwrap.TextWrapper(80)
|
||||||
for name in self._options:
|
for name in self._options:
|
||||||
g = getattr(self, 'opt_'+name, None)
|
g = getattr(self, 'opt_'+name, None)
|
||||||
if g is None:
|
if g is None:
|
||||||
@ -142,8 +145,10 @@ class Widget(QWidget):
|
|||||||
help = help_provider(name)
|
help = help_provider(name)
|
||||||
if not help: continue
|
if not help: continue
|
||||||
g._help = help
|
g._help = help
|
||||||
g.setToolTip(help.replace('<', '<').replace('>', '>'))
|
g.setToolTip('\n'.join(w.wrap(help.replace('<', '<').replace('>',
|
||||||
g.setWhatsThis(help.replace('<', '<').replace('>', '>'))
|
'>'))))
|
||||||
|
g.setWhatsThis('\n'.join(w.wrap(help.replace('<', '<').replace('>',
|
||||||
|
'>'))))
|
||||||
g.__class__.enterEvent = lambda obj, event: self.set_help(getattr(obj, '_help', obj.toolTip()))
|
g.__class__.enterEvent = lambda obj, event: self.set_help(getattr(obj, '_help', obj.toolTip()))
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
HELP = _('Options specific to')+' TXT '+_('output')
|
HELP = _('Options specific to')+' TXT '+_('output')
|
||||||
|
|
||||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||||
Widget.__init__(self, parent, 'txt_output', ['newline', 'inline_toc',
|
Widget.__init__(self, parent, 'txt_output',
|
||||||
'flush_paras', 'indent_paras'])
|
['newline', 'max_line_length', 'force_max_line_length',
|
||||||
|
'inline_toc', 'flush_paras', 'indent_paras'])
|
||||||
self.db, self.book_id = db, book_id
|
self.db, self.book_id = db, book_id
|
||||||
self.initialize_options(get_option, get_help, db, book_id)
|
self.initialize_options(get_option, get_help, db, book_id)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QComboBox" name="opt_newline"/>
|
<widget class="QComboBox" name="opt_newline"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="6" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -40,27 +40,47 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="2">
|
<item row="3" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_inline_toc">
|
<widget class="QCheckBox" name="opt_inline_toc">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Inline TOC</string>
|
<string>&Inline TOC</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
<item row="4" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_flush_paras">
|
<widget class="QCheckBox" name="opt_flush_paras">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Do not add a blank line between paragraphs.</string>
|
<string>Do not add a blank line between paragraphs.</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0" colspan="2">
|
<item row="5" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_indent_paras">
|
<widget class="QCheckBox" name="opt_indent_paras">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add a tab at the beginning of each paragraph</string>
|
<string>Add a tab at the beginning of each paragraph</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QSpinBox" name="opt_max_line_length"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Maximum line length:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_max_line_length</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="opt_force_max_line_length">
|
||||||
|
<property name="text">
|
||||||
|
<string>Force maximum line lenght</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user