View Single Post
Old 12-04-2011, 02:49 PM   #5
nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'nickredding knows the difference between 'who' and 'whom'
Posts: 324
Karma: 10143
Join Date: Dec 2009
Location: Phoenix, AZ & Victoria, BC
Device: Kindle 3, Kindle Fire, IPad3, iPhone4, Playbook, HTC Inspire
Kovid - I have tested the changes on both Windows and Linux (Ubuntu). I don't have any way of testing on OS-X but I'm guessing the changes will work on that as well.

I have attached the modified files (from the latest release) as well as modified NY Times recipes to use the thumbnail image capability.

Folowing are the changes required (line numbers refer to the current files before any changes are applied).

Let me know if you see any issues.


Insert after line 33:
        self.toc_thumbnail = None
Insert after line 89:
TOC thumb   : %s
Replace line 92:
'''%(self.title, self.url,, self.summary[:20]+'...', ('None' if self.toc_thumbnail is None else self.toc_thumbnail), self.localtime.strftime('%a, %d %b, %Y %H:%M'),

Insert before line 656:
    def add_toc_thumbnail(self, article, src):
        Call this from populate_article_metadata with the src of an img tag you want to
        appear as a thumbnail image in the articles list view of the table of contents
        (Kindle feature)
        article.toc_thumbnail = re.sub(r'^.*feed','feed',src.replace('\\','/'),flags=re.IGNORECASE)
Insert after line 1287:
                    idx = a.toc_thumbnail
                    if not idx:
                        idx = None
Replace lines 1293-1294:
                    parent.add_item('%sindex.html'%adir, None, a.title if a.title else _('Untitled Article'),
                                    play_order=po, author=auth, description=desc, toc_thumbnail=idx)

Replace lines 32-34:
    def __init__(self, href=None, fragment=None, text=None, parent=None, play_order=0,
                 base_path=os.getcwd(), type='unknown', author=None,
                 description=None, toc_thumbnail=None):
Insert after line 45:
        self.toc_thumbnail = toc_thumbnail
Replace lines 74-80:
    def add_item(self, href, fragment, text, play_order=None, type='unknown',
            author=None, description=None, toc_thumbnail=None):
        if play_order is None:
            play_order = (self[-1].play_order if len(self) else self.play_order) + 1
        self.append(TOC(href=href, fragment=fragment, text=text, parent=self,
                        base_path=self.base_path, play_order=play_order,
                        type=type, author=author, description=description, toc_thumbnail=toc_thumbnail))
Insert after line 271:
            idx = getattr(np, 'toc_thumbnail', None)
            if idx:
                elem.append(C.meta(idx, name='toc_thumbnail'))

Replace lines 1619-1651 with:
class TOC(object):
    """Represents a hierarchical table of contents or navigation tree for
    accessing arbitrary semantic sections within an OEB data model book.

    Acts as a node within the navigation tree.  Provides list-like access to
    sub-nodes.  Provides the follow node instance data attributes:

    :attr:`title`: The title of this navigation node.
    :attr:`href`: Book-internal URL referenced by this node.
    :attr:`klass`: Optional semantic class referenced by this node.
    :attr:`id`: Option unique identifier for this node.
    :attr:`author`: Optional author attribution for periodicals <mbp:>
    :attr:`description`: Optional description attribute for periodicals <mbp:>
    :attr:`toc_thumbnail`: Optional toc thumbnail image
    def __init__(self, title=None, href=None, klass=None, id=None,
            play_order=None, author=None, description=None, toc_thumbnail=None):
        self.title = title
        self.href = urlnormalize(href) if href else href
        self.klass = klass = id
        self.nodes = []
        self.play_order = 0
        if play_order is None:
            play_order = self.next_play_order()
        self.play_order = play_order = author
        self.description = description
        self.toc_thumbnail = toc_thumbnail

    def add(self, title, href, klass=None, id=None, play_order=0, author=None, description=None, toc_thumbnail=None):
        """Create and return a new sub-node of this node."""
        node = TOC(title, href, klass, id, play_order, author, description, toc_thumbnail)
        return node

Replace lines 374-375:
            indeximageElement = xpath(child,
                    'descendant::calibre:meta[@name = "toc_thumbnail"]')
            if indeximageElement :
                toc_thumbnail = indeximageElement[0].text
            else :
                toc_thumbnail = None

            node = toc.add(title, href, id=id, klass=klass,
                    play_order=po, description=description, author=author,


Replace line 139 with:
            'author_offset': 71,
(Note that the original value of 73 for author_offset is incorrect and this change doesn't relate specifically to the TOC thumbnail image changes.)

Insert after line 756:
                if art.toc_thumbnail is not None:
                    if art.toc_thumbnail in self.serializer.images:
                        article.image_index = self.serializer.images[art.toc_thumbnail]
Attached Files
File Type: zip (16.7 KB, 149 views)
File Type: zip python (56.5 KB, 158 views)
nickredding is offline   Reply With Quote