![]() |
#1 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 183
Karma: 266070
Join Date: Dec 2010
Device: Win7,Win10,Lubuntu,smartphone
|
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? Last edited by carmenchu; 04-08-2020 at 08:46 AM. Reason: improve code |
![]() |
![]() |
![]() |
#2 |
Connoisseur
![]() Posts: 99
Karma: 10
Join Date: Jun 2014
Location: Poland, Żory
Device: Prestigio PER3464B, Onyx Lynx, Lenovo S5000 i Tab4-8"
|
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) |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 183
Karma: 266070
Join Date: Dec 2010
Device: Win7,Win10,Lubuntu,smartphone
|
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 Last edited by carmenchu; 04-11-2020 at 03:34 PM. |
![]() |
![]() |
![]() |
#4 |
Connoisseur
![]() Posts: 99
Karma: 10
Join Date: Jun 2014
Location: Poland, Żory
Device: Prestigio PER3464B, Onyx Lynx, Lenovo S5000 i Tab4-8"
|
Ok. Now the plugin has worked.
Status: success Thanks and best regards bravosx |
![]() |
![]() |
![]() |
#5 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 27,798
Karma: 198099188
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
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. |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 183
Karma: 266070
Join Date: Dec 2010
Device: Win7,Win10,Lubuntu,smartphone
|
Quote:
Attached a sligh modification: moving two lines of code improves the report ... I am learning ![]() Last edited by carmenchu; 04-08-2020 at 09:03 AM. Reason: correct word |
|
![]() |
![]() |
![]() |
#7 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 75,598
Karma: 134254544
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Any chance this could also be made as a Calibre plugin?
|
![]() |
![]() |
![]() |
#8 |
Zealot
![]() Posts: 131
Karma: 10
Join Date: Jan 2015
Location: Buenos Aires
Device: Android
|
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 |
![]() |
![]() |
![]() |
#9 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,634
Karma: 23190435
Join Date: Dec 2010
Device: Kindle PW2
|
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. |
|
![]() |
![]() |
![]() |
#10 | |||
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 183
Karma: 266070
Join Date: Dec 2010
Device: Win7,Win10,Lubuntu,smartphone
|
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. ![]() |
|||
![]() |
![]() |
![]() |
#11 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 27,798
Karma: 198099188
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
If the preferences are few and simple enough, directly editing the plugin's preferences json file is a way of editing preferences that many Sigil plugins utilize. Especially if they won't be changing very often. But if you're envisioning preferences that will be updated frequently (perhaps each time the plugin is run even), then you will probably want a gui dialog that retrieves/sets those preferences. There's plenty of examples of both approaches in the user-contributed plugins.
|
![]() |
![]() |
![]() |
#12 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,634
Karma: 23190435
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Displaying an input box is even easier: Spoiler:
|
|
![]() |
![]() |
![]() |
#13 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 183
Karma: 266070
Join Date: Dec 2010
Device: Win7,Win10,Lubuntu,smartphone
|
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: 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...' Last edited by carmenchu; 04-11-2020 at 03:34 PM. |
![]() |
![]() |
![]() |
#14 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,634
Karma: 23190435
Join Date: Dec 2010
Device: Kindle PW2
|
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 == ['']: tags = soup.find_all(class_=re.compile("calibre")) else: tags = soup.find_all(ttags, class_=re.compile("calibre")) Code:
"tags": "" |
![]() |
![]() |
![]() |
#15 | ||
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 183
Karma: 266070
Join Date: Dec 2010
Device: Win7,Win10,Lubuntu,smartphone
|
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!** Last edited by carmenchu; 04-10-2020 at 07:33 PM. Reason: mispelling |
||
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pseudo classes to be deleted as unused classes | Leonatus | Sigil | 2 | 09-23-2018 09:12 AM |
Calibre conversion adding classes and screwing the layout? | 1v4n0 | Conversion | 6 | 01-29-2015 12:57 PM |
Calibre Inserting Its Own CSS Classes | Xopher H | Conversion | 2 | 08-02-2011 10:21 PM |
possible to change classes name,id,stylename that generated by calibre? | hard13 | Conversion | 2 | 02-24-2011 09:23 PM |
keeping or removing a div with multiple classes | JohnsonZA | Recipes | 1 | 09-25-2010 10:33 AM |