Heuristics: Rename scene break option. Fix bug preventing saving settings.

This commit is contained in:
John Schember 2011-02-01 07:29:01 -05:00
parent 241ef0b6e1
commit c4f74eb182
5 changed files with 19 additions and 19 deletions

View File

@ -45,8 +45,7 @@ For full documentation of the conversion system see
HEURISTIC_OPTIONS = ['markup_chapter_headings', HEURISTIC_OPTIONS = ['markup_chapter_headings',
'italicize_common_cases', 'fix_indents', 'italicize_common_cases', 'fix_indents',
'html_unwrap_factor', 'unwrap_lines', 'html_unwrap_factor', 'unwrap_lines',
'delete_blank_paragraphs', 'delete_blank_paragraphs', 'format_scene_breaks',
'format_scene_breaks', 'replace_soft_scene_breaks',
'dehyphenate', 'renumber_headings'] 'dehyphenate', 'renumber_headings']
def print_help(parser, log): def print_help(parser, log):
@ -144,7 +143,7 @@ def add_pipeline_options(parser, plumber):
' patterns. Disabled by default. Use %s to enable. ' ' patterns. Disabled by default. Use %s to enable. '
' Individual actions can be disabled with the %s options.') ' Individual actions can be disabled with the %s options.')
% ('--enable-heuristics', '--disable-*'), % ('--enable-heuristics', '--disable-*'),
['enable_heuristics'] + HEURISTIC_OPTIONS ['enable_heuristics', 'replace_scene_breaks'] + HEURISTIC_OPTIONS
), ),
'SEARCH AND REPLACE' : ( 'SEARCH AND REPLACE' : (

View File

@ -531,9 +531,9 @@ OptionRecommendation(name='format_scene_breaks',
'Replace soft scene breaks that use multiple blank lines with' 'Replace soft scene breaks that use multiple blank lines with'
'horizontal rules.')), 'horizontal rules.')),
OptionRecommendation(name='replace_soft_scene_breaks', OptionRecommendation(name='replace_scene_breaks',
recommended_value='', level=OptionRecommendation.LOW, recommended_value='', level=OptionRecommendation.LOW,
help=_('Replace soft scene breaks with the specified text.')), help=_('Replace scene breaks with the specified text.')),
OptionRecommendation(name='dehyphenate', OptionRecommendation(name='dehyphenate',
recommended_value=True, level=OptionRecommendation.LOW, recommended_value=True, level=OptionRecommendation.LOW,

View File

@ -23,7 +23,7 @@ class HeuristicsWidget(Widget, Ui_Form):
'italicize_common_cases', 'fix_indents', 'italicize_common_cases', 'fix_indents',
'html_unwrap_factor', 'unwrap_lines', 'html_unwrap_factor', 'unwrap_lines',
'delete_blank_paragraphs', 'delete_blank_paragraphs',
'format_scene_breaks', 'replace_soft_scene_breaks', 'format_scene_breaks', 'replace_scene_breaks',
'dehyphenate', 'renumber_headings'] 'dehyphenate', 'renumber_headings']
) )
self.db, self.book_id = db, book_id self.db, self.book_id = db, book_id
@ -40,17 +40,17 @@ class HeuristicsWidget(Widget, Ui_Form):
def restore_defaults(self, get_option): def restore_defaults(self, get_option):
Widget.restore_defaults(self, get_option) Widget.restore_defaults(self, get_option)
rssb_hist = gprefs['replace_soft_scene_breaks_history'] rssb_hist = gprefs['replace_scene_breaks_history']
for x in self.rssb_defaults: for x in self.rssb_defaults:
if x in rssb_hist: if x in rssb_hist:
del rssb_hist[rssb_hist.index(x)] del rssb_hist[rssb_hist.index(x)]
gprefs['replace_soft_scene_breaks_history'] = self.rssb_defaults + gprefs['replace_soft_scene_breaks_history'] gprefs['replace_scene_breaks_history'] = self.rssb_defaults + gprefs['replace_scene_breaks_history']
def commit_options(self, save_defaults=False): def commit_options(self, save_defaults=False):
Widget.commit_options(self, save_defaults)
self.save_histories() self.save_histories()
return Widget.commit_options(self, save_defaults)
def break_cycles(self): def break_cycles(self):
Widget.break_cycles(self) Widget.break_cycles(self)
@ -64,30 +64,30 @@ class HeuristicsWidget(Widget, Ui_Form):
if val is None and g is self.opt_html_unwrap_factor: if val is None and g is self.opt_html_unwrap_factor:
g.setValue(0.0) g.setValue(0.0)
return True return True
if not val and g is self.opt_replace_soft_scene_breaks: if not val and g is self.opt_replace_scene_breaks:
g.lineEdit().setText('') g.lineEdit().setText('')
return True return True
def load_histories(self): def load_histories(self):
val = unicode(self.opt_replace_soft_scene_breaks.currentText()) val = unicode(self.opt_replace_scene_breaks.currentText())
rssb_hist = gprefs.get('replace_soft_scene_breaks_history', self.rssb_defaults) rssb_hist = gprefs.get('replace_scene_breaks_history', self.rssb_defaults)
if val in rssb_hist: if val in rssb_hist:
del rssb_hist[rssb_hist.index(val)] del rssb_hist[rssb_hist.index(val)]
rssb_hist.insert(0, val) rssb_hist.insert(0, val)
for v in rssb_hist: for v in rssb_hist:
# Ensure we don't have duplicate items. # Ensure we don't have duplicate items.
if self.opt_replace_soft_scene_breaks.findText(v) == -1: if self.opt_replace_scene_breaks.findText(v) == -1:
self.opt_replace_soft_scene_breaks.addItem(v) self.opt_replace_scene_breaks.addItem(v)
self.opt_replace_soft_scene_breaks.setCurrentIndex(0) self.opt_replace_scene_breaks.setCurrentIndex(0)
def save_histories(self): def save_histories(self):
rssb_history = [] rssb_history = []
history_pats = [unicode(self.opt_replace_soft_scene_breaks.lineEdit().text())] + [unicode(self.opt_replace_soft_scene_breaks.itemText(i)) for i in xrange(self.opt_replace_soft_scene_breaks.count())] history_pats = [unicode(self.opt_replace_scene_breaks.lineEdit().text())] + [unicode(self.opt_replace_scene_breaks.itemText(i)) for i in xrange(self.opt_replace_scene_breaks.count())]
for p in history_pats[:10]: for p in history_pats[:10]:
# Ensure we don't have duplicate items. # Ensure we don't have duplicate items.
if p not in rssb_history: if p not in rssb_history:
rssb_history.append(p) rssb_history.append(p)
gprefs['replace_soft_scene_breaks_history'] = rssb_history gprefs['replace_scene_breaks_history'] = rssb_history
def enable_heuristics(self, state): def enable_heuristics(self, state):
state = state == Qt.Checked state = state == Qt.Checked

View File

@ -169,7 +169,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="opt_replace_soft_scene_breaks"> <widget class="QComboBox" name="opt_replace_scene_breaks">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>

View File

@ -258,6 +258,7 @@ class Config(ResizableDialog, Ui_Dialog):
if not w.pre_commit_check(): if not w.pre_commit_check():
return return
x = w.commit(save_defaults=False) x = w.commit(save_defaults=False)
print x
recs.update(x) recs.update(x)
self.opf_file, self.cover_file = self.mw.opf_file, self.mw.cover_file self.opf_file, self.cover_file = self.mw.opf_file, self.mw.cover_file
self._recommendations = recs self._recommendations = recs