Quote:
Originally Posted by un_pogaz
And after a night's sleep, I just realized the inconsistency of using the arguments for python:.
*inhale, sigh*
In fact, I think I even misunderstood the purpose of python template (it's an alternative form to Stored, not a 3rd option totally inedite).
If you think that deleting them would improve the code, go ahead.
|
I will leave it. Reasoning:
- We should have a way to save and reuse python templates. It could be done with files but that seems a bit crude.
- "Stored templates" already exists, so why not reuse it?
- Stored GPM templates are callable with arguments.
- Therefore stored python templates should also be callable.
In addition there is a bona fide reason to have arguments in stored python templates: template searches. A person could write a template that does some sort of search, but with variants. Instead of duplicating the code, store the template and call it with arguments that tell it which variant to use.
All this opens the question "What is the difference between a python template and a python formatter function? Good question. Formatter functions can "see" into the formatter and easily use existing formatter builtin functions, but templates cannot. If I had thought of python templates years ago perhaps I wouldn't have built the user-defined function mechanism. But we have it now and it is used, so it can't go away or be changed.
Quote:
Also, I was going to say that syntax highlighting is possible, since "Action Chains" does it in its module editor... but it uses something different (TextEdit from calibre.gui2.tweak_book.editor.text), so no, crap.
At least, maybe highlight python: to identify what we are in.
... Maybe an idea, I'm looking at it.
EDIT: And, it works.
|
I had already taken the code to do python syntax highlighting from gui2.widgets.PythonHighlighter and integrated it into the highlighter used by the template dialog. It works quite well. The difficulty was dynamically switching between highlighters.
I didn't solve the problem of highlighting the mode indicator.
EDIT: Attached is template_dialog.py with python syntax highlighting.