![]() |
Removing calibre classes...
As begun in this thread (moved from another, misleading title), I have working in a plug-in to remove those 'calibre#' classes that usually implement just the CSS defaults for the tag, and also redundant/unnecessary <meta.../> tags.
My (working) code so far is: Spoiler:
- When run, it outputs in the plug-in window the full list of removals, so that one can check that nothing unintended is affected, and gets rid of calibre classes from i,b,small,sup,sub,br,a,li--plus all meta tags. Composite classes and <meta *name="*cover*"*/> excluded. Now, I would appreciate further help from experts in improving the plug-in, allowing as options: * edit the tag list * include/exclude the metas removal * include/exclude showing the (huge!) list of removals (i.e., a 'test mode') As the Sigil_Plugin_Framework_rev12.epub lacks information on GUIs, please: - For my needs, would Tkinter or PyQt5 be the simpler approach? - Can some-helpful-body provide a very simple template (no bell or whistles) working in Sigil? * Improvement of code welcome (I am learning) ** If somebody is interested, I can provide the plug-in in its present working state... for use only if those classes are in your way: maybe some 'user agents' require them? |
I'm trying to use your plugin and I get this error:
Status: failed Traceback (most recent call last): File "C:\Program Files\Sigil\plugin_launchers\python\launcher.py", line 135, in launch target_script = __import__(script_module) File "C:\Users\xxxxxxxx\AppData\Local\sigil-ebook\sigil\plugins\MyPlugin\plugin.py", line 10 deletec=[] ^ IndentationError: expected an indented block Error: expected an indented block (plugin.py, line 10) |
Sorry, that is just the 'run' code (and my 'copy & paste' deleted the python indents: cannot work!): attached the working (for me) plug-in.
Caveat: * test it in a 'short' epub * look at plug-in window to see what has has been deleted * and test further with preview before saving the changed epub |
Ok. Now the plugin has worked.
Status: success Thanks and best regards bravosx |
Quote:
"Simpler" is in the eye of the beholder. I've done a lot of tkinter guis for my various plugins, but I've always found tkinter to be terribly unintuitive for some reason. I'm not sure why; it might just be me. One advantage PyQt has is that the gui will match Sigil's gui style, and the plugin framework even offers ways to ensure that the plugin's dialogs will match Sigil's lightmode/darkmode user preference. Tkinter will only automatically do that on macOS (with newer versions of macOS). My plugins with GUI's will eventually all use PyQt5 instead of tkinter. |
1 Attachment(s)
Quote:
Attached a sligh modification: moving two lines of code improves the report ... I am learning:o |
Any chance this could also be made as a Calibre plugin?
|
Hi,
i tested your plugin on a small epub. Not much to remove. The plugin successfully removed some unnecessary meta tags. Working good so far. Thomas |
Quote:
Also have a look at DiapDealer's plugins. BTW, if you just want some customization options, you could "cheat," and simply read and write preference settings, which is very easy. |
Quote:
Quote:
Quote:
Of course, I intend to use preferences as well--those seem to have a documentation I can understand. But my search into PyQt documentation has devolved into headache. Maybe I have been spoiled by Gimp, which offers a framework for python plugins which makes their GUIs quite trivial. :thanks: |
Quote:
|
Quote:
Displaying an input box is even easier: Spoiler:
|
1 Attachment(s)
Many thanks, every body!
Attached is a new version of the plug-in, doing the same, but with: - an improved (short!) report - use of 'preferences', per PrefsExampleSimple_v0.0.2--edit them for options. -------- And now, some grumbling: adding a very simple GUI, with a frame, an editable text field and a couple of buttons, still seems (to me!) a headache. I sorely miss in Sigil the Gimp (traditional) approach, which looks in code: Spoiler:
(notice the register() at bottom: thatīs the plug-in GUI) and runs as: Attachment 178226 the pop-up dialog being created by the PF_... entries, which also gather them as variables for the function in the script. The main point is that one can focus on the code, and leave the main program to extrude a 'standard' dialog (advanced plug-in coders can also implement their own, non-standard dialogs). I suspect that one should be able to do something of the kind in Sigil through 'class instances' (above my head!) as 'Seven classes for the seven options under the sky, For wizards, of course!one class to bind them all and under Sigil run them...' |
IMHO, your plugin is almost ready for an official release. I only have one minor nitpick: the plugin never reads or writes the "metas" preference setting.
I also have a minor suggestion: if you change: Code:
tags = soup.find_all(ttags, class_=re.compile("calibre"))Code:
if ttags == ['']:Code:
"tags": "" |
1 Attachment(s)
Quote:
Query: can really Code:
prefs['metas'] = prefs['metas']Quote:
It's an option which I wouldn't recommend, save for report purposes: one can achieve the same result by a simple search & replace of class="calibre\d*" (I purposely skip class="calibre\d* other" except in report: my notion isn't to eliminate manuel searchs and edits, but only their mechanical part). By the way, is there a simple way of getting the list of tags ordered? It would be easier to read and edit, but I can't get it done... ---- **Do people know that there is a downloadable epub version of the python manual here? The improvement of consulting on i.e., the calibre viewer, with full, searchable toc and searcheable text, cannot be told--try it!** |
| All times are GMT -4. The time now is 08:44 PM. |
Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.