mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
String changes
This commit is contained in:
parent
1c5eeeae83
commit
d264c14550
@ -17,7 +17,7 @@ Here, we will teach you how to create your own plugins to add new features to ca
|
||||
Anatomy of a calibre plugin
|
||||
---------------------------
|
||||
|
||||
A calibre plugin is very simple, it's just a zip file that contains some python code
|
||||
A calibre plugin is very simple, it's just a zip file that contains some Python code
|
||||
and any other resources like image files needed by the plugin. Without further ado,
|
||||
let's see a basic example.
|
||||
|
||||
@ -70,11 +70,11 @@ The first thing to note is that this zip file has a lot more files in it, explai
|
||||
|
||||
The prefix ``calibre_plugins`` must always be present. ``some_name`` comes from the filename of the empty text file.
|
||||
``some_module`` refers to :file:`some_module.py` file inside the zip file. Note that this importing is just as
|
||||
powerful as regular python imports. You can create packages and subpackages of .py modules inside the zip file,
|
||||
powerful as regular Python imports. You can create packages and subpackages of .py modules inside the zip file,
|
||||
just like you would normally (by defining __init__.py in each sub-directory), and everything should Just Work.
|
||||
|
||||
The name you use for ``some_name`` enters a global namespace shared by all plugins, **so make it as unique as possible**.
|
||||
But remember that it must be a valid python identifier (only alphabets, numbers and the underscore).
|
||||
But remember that it must be a valid Python identifier (only alphabets, numbers and the underscore).
|
||||
|
||||
**__init__.py**
|
||||
As before, the file that defines the plugin class
|
||||
@ -306,7 +306,7 @@ Or from within calibre by right-clicking the :guilabel:`Preferences` button or u
|
||||
|
||||
When running from the command line, debug output will be printed to the console, when running from within calibre the output will go to a txt file.
|
||||
|
||||
You can insert print statements anywhere in your plugin code, they will be output in debug mode. Remember, this is python, you really shouldn't need anything more than print statements to debug ;) I developed all of calibre using just this debugging technique.
|
||||
You can insert print statements anywhere in your plugin code, they will be output in debug mode. Remember, this is Python, you really shouldn't need anything more than print statements to debug ;) I developed all of calibre using just this debugging technique.
|
||||
|
||||
You can quickly test changes to your plugin by using the following command
|
||||
line::
|
||||
|
@ -342,7 +342,7 @@ Two other kinds of searches are available: equality search and search using `reg
|
||||
|
||||
Equality searches are indicated by prefixing the search string with an equals sign (=). For example, the query
|
||||
``tag:"=science"`` will match "science", but not "science fiction" or "hard science". Regular expression searches are
|
||||
indicated by prefixing the search string with a tilde (~). Any `python-compatible regular expression <https://docs.python.org/2/library/re.html>`_ can
|
||||
indicated by prefixing the search string with a tilde (~). Any `Python-compatible regular expression <https://docs.python.org/2/library/re.html>`_ can
|
||||
be used. Note that backslashes used to escape special characters in regular expressions must be doubled because single backslashes will be removed during query parsing. For example, to match a literal parenthesis you must enter ``\\(``. Regular expression searches are 'contains' searches unless the expression contains anchors.
|
||||
|
||||
Should you need to search for a string with a leading equals or tilde, prefix the string with a backslash.
|
||||
@ -621,7 +621,7 @@ The Jobs panel shows the number of currently running jobs. Jobs are tasks that r
|
||||
|
||||
<div style="clear:both"></div>
|
||||
|
||||
Keyboard Shortcuts
|
||||
Keyboard shortcuts
|
||||
---------------------
|
||||
|
||||
calibre has several keyboard shortcuts to save you time and mouse movement. These shortcuts are active in the book list view (when you're not editing the details of a particular book), and most of them affect the title you have selected. The calibre e-book viewer has its own shortcuts which can be customised by clicking the :guilabel:`Preferences` button in the viewer.
|
||||
|
@ -17,7 +17,7 @@ def option_parser():
|
||||
{0}
|
||||
|
||||
Various command line interfaces useful for debugging calibre. With no options,
|
||||
this command starts an embedded python interpreter. You can also run the main
|
||||
this command starts an embedded Python interpreter. You can also run the main
|
||||
calibre GUI, the calibre viewer and the calibre editor in debug mode.
|
||||
|
||||
It also contains interfaces to various bits of calibre that do not have
|
||||
@ -30,8 +30,8 @@ You can also use %prog to run standalone scripts. To do that use it like this:
|
||||
|
||||
Everything after the -- is passed to the script.
|
||||
''').format(_('%prog [options]'), '%prog myscript.py -- --option1 --option2 file1 file2 ...'))
|
||||
parser.add_option('-c', '--command', help=_('Run python code.'))
|
||||
parser.add_option('-e', '--exec-file', help=_('Run the python code in file.'))
|
||||
parser.add_option('-c', '--command', help=_('Run Python code.'))
|
||||
parser.add_option('-e', '--exec-file', help=_('Run the Python code in file.'))
|
||||
parser.add_option('-f', '--subset-font', action='store_true', default=False,
|
||||
help=_('Subset the specified font. Use -- after this option to pass option to the font subsetting program.'))
|
||||
parser.add_option('-d', '--debug-device-driver', default=False, action='store_true',
|
||||
|
@ -710,7 +710,7 @@ OptionRecommendation(name='search_replace',
|
||||
'Path to a file containing search and replace regular expressions. '
|
||||
'The file must contain alternating lines of regular expression '
|
||||
'followed by replacement pattern (which can be an empty line). '
|
||||
'The regular expression must be in the python regex syntax and '
|
||||
'The regular expression must be in the Python regex syntax and '
|
||||
'the file must be UTF-8 encoded.')),
|
||||
]
|
||||
# }}}
|
||||
|
@ -512,7 +512,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
|
||||
self.regexp_heading = _(
|
||||
'In regular expression mode, the search text is an '
|
||||
'arbitrary python-compatible regular expression. The '
|
||||
'arbitrary Python-compatible regular expression. The '
|
||||
'replacement text can contain backreferences to parenthesized '
|
||||
'expressions in the pattern. The search is not anchored, '
|
||||
'and can match and replace multiple times on the same string. '
|
||||
@ -522,7 +522,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
'matching and replacement is to be assigned. You can replace '
|
||||
'the text in the field, or prepend or append the matched text. '
|
||||
'See <a href="https://docs.python.org/library/re.html">'
|
||||
'this reference</a> for more information on python\'s regular '
|
||||
'this reference</a> for more information on Python\'s regular '
|
||||
'expressions, and in particular the \'sub\' function.'
|
||||
)
|
||||
|
||||
|
@ -412,7 +412,7 @@ class CreateCustomColumn(QDialog):
|
||||
else:
|
||||
l, dl = _('&Format for numbers'), (
|
||||
'<p>' + _('Default: Not formatted. For format language details see'
|
||||
' <a href="https://docs.python.org/library/string.html#format-string-syntax">the python documentation</a>'))
|
||||
' <a href="https://docs.python.org/library/string.html#format-string-syntax">the Python documentation</a>'))
|
||||
if col_type == 'int':
|
||||
self.format_box.setToolTip('<p>' +
|
||||
_('Examples: The format <code>{0:0>4d}</code> '
|
||||
|
@ -123,7 +123,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>&Program code: (be sure to follow python indenting rules)</string>
|
||||
<string>&Program code: (be sure to follow Python indenting rules)</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>program</cstring>
|
||||
|
@ -211,7 +211,7 @@ class ModeBox(QComboBox):
|
||||
<dt><b>Regex</b></dt>
|
||||
<dd>The search expression is interpreted as a regular expression. See the User Manual for more help on using regular expressions.</dd>
|
||||
<dt><b>Regex-function</b></dt>
|
||||
<dd>The search expression is interpreted as a regular expression. The replace expression is an arbitrarily powerful python function.</dd>
|
||||
<dd>The search expression is interpreted as a regular expression. The replace expression is an arbitrarily powerful Python function.</dd>
|
||||
</dl>'''))
|
||||
|
||||
@dynamic_property
|
||||
|
@ -108,6 +108,7 @@ class FormatterFunctions(object):
|
||||
for a in c.aliases:
|
||||
self._functions[a] = c
|
||||
|
||||
|
||||
_ff = FormatterFunctions()
|
||||
|
||||
|
||||
@ -597,7 +598,7 @@ class BuiltinRe(BuiltinFormatterFunction):
|
||||
__doc__ = doc = _('re(val, pattern, replacement) -- return val after applying '
|
||||
'the regular expression. All instances of `pattern` are replaced '
|
||||
'with `replacement`. As in all of calibre, these are '
|
||||
'python-compatible regular expressions')
|
||||
'Python-compatible regular expressions')
|
||||
|
||||
def evaluate(self, formatter, kwargs, mi, locals, val, pattern, replacement):
|
||||
return re.sub(pattern, replacement, val, flags=re.I)
|
||||
@ -848,10 +849,10 @@ class BuiltinFormatNumber(BuiltinFormatterFunction):
|
||||
arg_count = 2
|
||||
category = 'Formatting values'
|
||||
__doc__ = doc = _('format_number(v, template) -- format the number v using '
|
||||
'a python formatting template such as "{0:5.2f}" or '
|
||||
'a Python formatting template such as "{0:5.2f}" or '
|
||||
'"{0:,d}" or "${0:5,.2f}". The field_name part of the '
|
||||
'template must be a 0 (zero) (the "{0:" in the above examples). '
|
||||
'See the template language and python documentation for more '
|
||||
'See the template language and Python documentation for more '
|
||||
'examples. Returns the empty string if formatting fails.'
|
||||
)
|
||||
|
||||
@ -1564,6 +1565,7 @@ class BuiltinAuthorSorts(BuiltinFormatterFunction):
|
||||
names = [sort_data.get(n) for n in mi.authors if n.strip()]
|
||||
return val_sep.join(n for n in names)
|
||||
|
||||
|
||||
_formatter_builtins = [
|
||||
BuiltinAdd(), BuiltinAnd(), BuiltinApproximateFormats(), BuiltinAssign(),
|
||||
BuiltinAuthorLinks(), BuiltinAuthorSorts(), BuiltinBooksize(),
|
||||
@ -1598,6 +1600,7 @@ class FormatterUserFunction(FormatterFunction):
|
||||
self.arg_count = arg_count
|
||||
self.program_text = program_text
|
||||
|
||||
|
||||
tabs = re.compile(r'^\t*')
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user