Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 12-04-2015, 05:33 AM   #31
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,686
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by rubeus View Post
For example inserting images. I dont want them to blow up on hires screens over the "natural" size so i have a common code snippet and to make it individual to each image i'm applaying the with via inline stylesheet [...]:
You should be able to this with beautifulsoup4 and PIL. I.e. grab all img tags with BS4, get the dimensions with PIL and then add a style attribute with BS4.

The following edit plugin code, which requires Sigil 0.9 (and higher) and the bundled interpreter, should work.

Spoiler:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*- 
from sigil_bs4 import BeautifulSoup
from PIL import Image
import os

def run(bk):

    for (html_id, linear) in bk.getspine():
        mime = bk.id_to_mime(html_id)
        
        if mime == 'application/xhtml+xml':
            html = bk.readfile(html_id)
            soup = BeautifulSoup(html)
            orig_soup = str(soup)
            images = soup.find_all('img')

            for image in images:
                image_path = os.path.join(bk._w.ebook_root, 'OEBPS', 'Images', os.path.basename(image['src']))
                img = Image.open(image_path)
                width, height = img.size
                image['style'] = 'max-width: ' + str(width) + 'px'
                
            if str(soup) != orig_soup:
                bk.writefile(html_id, str(soup.prettyprint_xhtml(indent_level=0, eventual_encoding="utf-8", formatter="minimal", indent_chars="  ")))
                print(bk.id_to_href(html_id) + ' updated')
    
    return 0

def main():
    print ('I reached main when I should not have\n')
    return -1

if __name__ == "__main__":
    sys.exit(main())
Attached Files
File Type: zip German Dictionary Test.zip (6.3 KB, 266 views)

Last edited by Doitsu; 02-04-2016 at 05:46 AM.
Doitsu is offline   Reply With Quote
Old 12-04-2015, 07:20 AM   #32
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,365
Karma: 203720150
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by eschwartz View Post
I noticed in master the ability to set SIGIL_CUSTOM_PREFS_DIR=/path/to/sigil/config/dir

Would it be possible to make that less wordy?
SIGIL_CONFIG_DIRECTORY (similar to calibre) or maybe SIGIL_PREFS_DIR

The word "custom" in there is unnecessary.


P.S. Thank you for the change.
I'm a book reader. I like wordy.

I'll take it under advisement, but you have to admit it's a pretty nitpicky request. Unnecessary is in the eye of the beholder. The whole feature is "unnecessary" when you get right down to it.
DiapDealer is online now   Reply With Quote
Advert
Old 12-04-2015, 10:34 AM   #33
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
I agree the name is a bit nitpicky. I wouldn't mention it at all if not for the fact that a) it's unreleased, and b) it would match the similar change that was languishing half-finished in my working tree.

But I don't know that the feature is "unnecessary". It would be a very nice-to-have thing for running a PortableApp.
Easy to turn into a batch/bash script, and also an improvement on the PortableApps.com method which currently copies the config dir to/from AppData.
eschwartz is offline   Reply With Quote
Old 12-04-2015, 10:52 AM   #34
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,365
Karma: 203720150
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
My main motivation was for easily testing/debugging multiple configs (and for consolidating all the calls to QStandardPaths::WritableLocation so switching/migrating to the recommended AppDataLocation will be easier some time down the road). If others find it useful, so be it.

I'll consider changing it to SIGIL_PREFS_DIR dir before release. That will aesthetically match the "Open Preferences Location" button in the Preferences widget. I don't want to be the guy who can't take constructive criticism, afterall.

Last edited by DiapDealer; 12-04-2015 at 10:58 AM.
DiapDealer is online now   Reply With Quote
Old 12-04-2015, 11:14 AM   #35
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Thanks for considering. I can't ask for more than that.

And yes, it's got several uses.
eschwartz is offline   Reply With Quote
Advert
Old 12-04-2015, 01:21 PM   #36
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,488
Karma: 5703586
Join Date: Nov 2009
Device: many
Hi rubeus,

FYI, there are quite a few parsers available to you in a plugin. QuickParser, lxml, sigil_bs4 with html5lib, sigil_bs4 with lxml, sigil_bs4 with gumbo, etc. So simply have it walk all xhtml docs and parse them and get the image tag, and add the right attributes if needed, serialize it and continue.

Parsing with QuickParser is quite easy and using sigil_bs4 (html5lib, gumbo, lxml) to do the modifications and then serialize is easy too.

There really is no reason to do any of that manually when this is perfect for a plugin.

KevinH



Quote:
Originally Posted by rubeus View Post
The plugin runner window shows up clearly the break between Sigil itself and the plugins: A plugin isnt working on the data directly but on a copy which can be send back. If this wouldnt be so clear more peoplewill ask for a plugin working more integrated in Sigil (for example paste imagesa dn the workaround by doits works, but isnt really smoothly integrated,)

The only thing i miss a little bit is the possibility to insert code having some special attributes.

For example inserting images. I dont want them to blow up on hires screens over the "natural" size so i have a common code snippet and to make it individual to each image i'm applaying the with via inline stylesheet:

Code:
<div...>
<img ... style="max-width=xxxpx;" />
</div>
would be extremly helpful when this could be more automated. Currently i have a plugin creating an allpic html file containing the code snippets go each picture so i can copy & paste the code.

But when i remember the 034 and what was possible in former times...

ps. I see Doitsu has already beaten me to the punch with his solution. If you decide to use BS4, I would recommend the serialize_xhtml call in sigil_bs4 over the prettyprint_xhtml call since the serialize call will make fewer changes to the source code (ie. is less likely to introduce errors from incorrect pretty-printing).

Last edited by KevinH; 12-04-2015 at 01:25 PM.
KevinH is offline   Reply With Quote
Old 12-04-2015, 03:00 PM   #37
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
Thanks guys, but first of all i need a new keyboard

I will dig in bs4 as it looks easier to modify an existing max-width so a rerun after a picture has been scaled down doesnt add a second inline style. Need to read the documentation first. Still i'm a beginner in python and a novice in beautifulsoup.

With lxml i'm always struggling with the namespace
rubeus is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sigil-0.8.900 released for testing - Wait for Sigil-0.8.901 KevinH Sigil 106 10-04-2015 10:41 AM
Sigil 0.8.5 Released user_none Sigil 12 03-30-2015 11:28 AM
Sigil 0.6.2 Released user_none Sigil 89 05-04-2014 06:42 AM
Sigil 0.5.3 Released user_none Sigil 85 05-13-2012 05:29 AM


All times are GMT -4. The time now is 05:36 AM.


MobileRead.com is a privately owned, operated and funded community.