mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cleanup S&R preferences widget
This commit is contained in:
parent
4b25d9ef0d
commit
383b15e254
@ -94,7 +94,7 @@ class BulkConfig(Config):
|
|||||||
if not c: break
|
if not c: break
|
||||||
self.stack.removeWidget(c)
|
self.stack.removeWidget(c)
|
||||||
|
|
||||||
widgets = [lf, hw, sr, ps, sd, toc]
|
widgets = [lf, hw, ps, sd, toc, sr]
|
||||||
if output_widget is not None:
|
if output_widget is not None:
|
||||||
widgets.append(output_widget)
|
widgets.append(output_widget)
|
||||||
for w in widgets:
|
for w in widgets:
|
||||||
|
@ -15,6 +15,7 @@ class SearchAndReplaceWidget(Widget, Ui_Form):
|
|||||||
TITLE = _('Search &\nReplace')
|
TITLE = _('Search &\nReplace')
|
||||||
HELP = _('Modify the document text and structure using user defined patterns.')
|
HELP = _('Modify the document text and structure using user defined patterns.')
|
||||||
COMMIT_NAME = 'search_and_replace'
|
COMMIT_NAME = 'search_and_replace'
|
||||||
|
ICON = I('search.png')
|
||||||
|
|
||||||
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,
|
Widget.__init__(self, parent,
|
||||||
@ -24,13 +25,13 @@ class SearchAndReplaceWidget(Widget, Ui_Form):
|
|||||||
)
|
)
|
||||||
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)
|
||||||
self.opt_sr1_search.set_msg(_('Search Regular Expression'))
|
self.opt_sr1_search.set_msg(_('&Search Regular Expression'))
|
||||||
self.opt_sr1_search.set_book_id(book_id)
|
self.opt_sr1_search.set_book_id(book_id)
|
||||||
self.opt_sr1_search.set_db(db)
|
self.opt_sr1_search.set_db(db)
|
||||||
self.opt_sr2_search.set_msg(_('Search Regular Expression'))
|
self.opt_sr2_search.set_msg(_('&Search Regular Expression'))
|
||||||
self.opt_sr2_search.set_book_id(book_id)
|
self.opt_sr2_search.set_book_id(book_id)
|
||||||
self.opt_sr2_search.set_db(db)
|
self.opt_sr2_search.set_db(db)
|
||||||
self.opt_sr3_search.set_msg(_('Search Regular Expression'))
|
self.opt_sr3_search.set_msg(_('&Search Regular Expression'))
|
||||||
self.opt_sr3_search.set_book_id(book_id)
|
self.opt_sr3_search.set_book_id(book_id)
|
||||||
self.opt_sr3_search.set_db(db)
|
self.opt_sr3_search.set_db(db)
|
||||||
|
|
||||||
@ -45,10 +46,11 @@ class SearchAndReplaceWidget(Widget, Ui_Form):
|
|||||||
for x in ('sr1_search', 'sr2_search', 'sr3_search'):
|
for x in ('sr1_search', 'sr2_search', 'sr3_search'):
|
||||||
x = getattr(self, 'opt_'+x)
|
x = getattr(self, 'opt_'+x)
|
||||||
try:
|
try:
|
||||||
pat = unicode(x.regex)
|
pat = unicode(x.regex).strip()
|
||||||
re.compile(pat)
|
if pat:
|
||||||
|
re.compile(pat)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
error_dialog(self, _('Invalid regular expression'),
|
error_dialog(self, _('Invalid regular expression'),
|
||||||
_('Invalid regular expression: %s')%err).exec_()
|
_('Invalid regular expression: %s')%err, show=True)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>198</width>
|
<width>468</width>
|
||||||
<height>350</height>
|
<height>451</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -23,7 +23,7 @@
|
|||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
<enum>QLayout::SetDefaultConstraint</enum>
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||||
@ -32,7 +32,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>1.</string>
|
<string>First expression</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
@ -57,7 +57,10 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Replacement Text</string>
|
<string>&Replacement Text</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_sr1_replace</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -74,7 +77,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QGroupBox" name="groupBox_2">
|
<widget class="QGroupBox" name="groupBox_2">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||||
@ -83,7 +86,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>2.</string>
|
<string>Second Expression</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
@ -108,7 +111,10 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Replacement Text</string>
|
<string>&Replacement Text</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_sr2_replace</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -125,7 +131,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QGroupBox" name="groupBox_3">
|
<widget class="QGroupBox" name="groupBox_3">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||||
@ -134,7 +140,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>3.</string>
|
<string>Third expression</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
@ -159,7 +165,10 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Replacement Text</string>
|
<string>&Replacement Text</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_sr3_replace</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -176,6 +185,19 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string><p>Search and replace uses <i>regular expressions</i>. See the <a href="http://calibre-ebook.com/user_manual/regexp.html">regular expressions tutorial</a> to get started with regular expressions. Also clicking the wizard buttons below will allow you to test your regular expression against the current input document.</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="openExternalLinks">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
@ -207,7 +207,7 @@ class Config(ResizableDialog, Ui_Dialog):
|
|||||||
if not c: break
|
if not c: break
|
||||||
self.stack.removeWidget(c)
|
self.stack.removeWidget(c)
|
||||||
|
|
||||||
widgets = [self.mw, lf, hw, sr, ps, sd, toc]
|
widgets = [self.mw, lf, hw, ps, sd, toc, sr]
|
||||||
if input_widget is not None:
|
if input_widget is not None:
|
||||||
widgets.append(input_widget)
|
widgets.append(input_widget)
|
||||||
if output_widget is not None:
|
if output_widget is not None:
|
||||||
|
@ -85,8 +85,8 @@ class CommonOptions(Base):
|
|||||||
|
|
||||||
def load_conversion_widgets(self):
|
def load_conversion_widgets(self):
|
||||||
self.conversion_widgets = [LookAndFeelWidget, HeuristicsWidget,
|
self.conversion_widgets = [LookAndFeelWidget, HeuristicsWidget,
|
||||||
SearchAndReplaceWidget, PageSetupWidget,
|
PageSetupWidget,
|
||||||
StructureDetectionWidget, TOCWidget]
|
StructureDetectionWidget, TOCWidget, SearchAndReplaceWidget,]
|
||||||
|
|
||||||
class InputOptions(Base):
|
class InputOptions(Base):
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ This is, inevitably, going to be somewhat technical- after all, regular expressi
|
|||||||
Where in |app| can you use regular expressions?
|
Where in |app| can you use regular expressions?
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
There are a few places |app| uses regular expressions. There's the header/footer removal in conversion options, metadata detection from filenames in the import settings and, since last version, there's the option to use regular expressions to search and replace in metadata of multiple books.
|
There are a few places |app| uses regular expressions. There's the Search & Replace in conversion options, metadata detection from filenames in the import settings and Search & Replace when editing the metadata of books in bulk.
|
||||||
|
|
||||||
What on earth *is* a regular expression?
|
What on earth *is* a regular expression?
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user