mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
merged user_none's GUI additions scene break replacement
This commit is contained in:
commit
f7dc29c91e
@ -6,6 +6,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from PyQt4.Qt import Qt
|
from PyQt4.Qt import Qt
|
||||||
|
|
||||||
|
from calibre.gui2 import gprefs
|
||||||
from calibre.gui2.convert.heuristics_ui import Ui_Form
|
from calibre.gui2.convert.heuristics_ui import Ui_Form
|
||||||
from calibre.gui2.convert import Widget
|
from calibre.gui2.convert import Widget
|
||||||
|
|
||||||
@ -21,17 +22,35 @@ class HeuristicsWidget(Widget, Ui_Form):
|
|||||||
['enable_heuristics', 'markup_chapter_headings',
|
['enable_heuristics', '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', 'format_scene_breaks',
|
'delete_blank_paragraphs',
|
||||||
|
'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
|
||||||
|
self.rssb_defaults = ['', '<hr />', '* * *']
|
||||||
self.initialize_options(get_option, get_help, db, book_id)
|
self.initialize_options(get_option, get_help, db, book_id)
|
||||||
|
|
||||||
|
self.load_histories()
|
||||||
|
|
||||||
self.opt_enable_heuristics.stateChanged.connect(self.enable_heuristics)
|
self.opt_enable_heuristics.stateChanged.connect(self.enable_heuristics)
|
||||||
self.opt_unwrap_lines.stateChanged.connect(self.enable_unwrap)
|
self.opt_unwrap_lines.stateChanged.connect(self.enable_unwrap)
|
||||||
|
|
||||||
self.enable_heuristics(self.opt_enable_heuristics.checkState())
|
self.enable_heuristics(self.opt_enable_heuristics.checkState())
|
||||||
|
|
||||||
|
def restore_defaults(self, get_option):
|
||||||
|
Widget.restore_defaults(self, get_option)
|
||||||
|
|
||||||
|
rssb_hist = gprefs['replace_scene_breaks_history']
|
||||||
|
for x in self.rssb_defaults:
|
||||||
|
if x in rssb_hist:
|
||||||
|
del rssb_hist[rssb_hist.index(x)]
|
||||||
|
gprefs['replace_scene_breaks_history'] = self.rssb_defaults + gprefs['replace_scene_breaks_history']
|
||||||
|
|
||||||
|
def commit_options(self, save_defaults=False):
|
||||||
|
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)
|
||||||
|
|
||||||
@ -45,6 +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_scene_breaks:
|
||||||
|
g.lineEdit().setText('')
|
||||||
|
return True
|
||||||
|
|
||||||
|
def load_histories(self):
|
||||||
|
val = unicode(self.opt_replace_scene_breaks.currentText())
|
||||||
|
rssb_hist = gprefs.get('replace_scene_breaks_history', self.rssb_defaults)
|
||||||
|
if val in rssb_hist:
|
||||||
|
del rssb_hist[rssb_hist.index(val)]
|
||||||
|
rssb_hist.insert(0, val)
|
||||||
|
for v in rssb_hist:
|
||||||
|
# Ensure we don't have duplicate items.
|
||||||
|
if self.opt_replace_scene_breaks.findText(v) == -1:
|
||||||
|
self.opt_replace_scene_breaks.addItem(v)
|
||||||
|
self.opt_replace_scene_breaks.setCurrentIndex(0)
|
||||||
|
|
||||||
|
def save_histories(self):
|
||||||
|
rssb_history = []
|
||||||
|
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]:
|
||||||
|
# Ensure we don't have duplicate items.
|
||||||
|
if p not in rssb_history:
|
||||||
|
rssb_history.append(p)
|
||||||
|
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
|
||||||
|
@ -150,6 +150,42 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="sizeConstraint">
|
||||||
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Replace soft scene breaks:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="opt_replace_scene_breaks">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="insertPolicy">
|
||||||
|
<enum>QComboBox::InsertAtTop</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="opt_dehyphenate">
|
<widget class="QCheckBox" name="opt_dehyphenate">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user