Source code for quill.exporter.base2

"""
More advanced base class

You probably want to implement your exporter on top of this base class.

EXAMPLES::

    >>> from quill.exporter.base2 import ExporterBase2
    >>> ExporterBase2().book(sample_book)    # doctest: +ELLIPSIS
    Beginning export
    Title is set to Example Notebook
    UUID is set to 1fd6a485-33ed-4a45-a5a1-e06e55fdca57
    Creation time set to 2012-12-09 14:57:25
    Last modification time set to 2012-12-09 14:57:25
    New page, aspect ratio 0.707
    Draw image at (0.13,0.605):(0.455,0.739)
    Draw pen stroke with 40 points
    Draw pen stroke with 8 points
    Draw pen stroke with 59 points
    Draw pen stroke with 31 points
    Draw pen stroke with 44 points
    Draw pen stroke with 36 points
    Draw pen stroke with 22 points
    Draw pen stroke with 9 points
    Draw pen stroke with 6 points
    Draw pen stroke with 18 points
    Draw pen stroke with 21 points
    ...
    Draw pen stroke with 17 points
    Draw pen stroke with 14 points
    Draw pen stroke with 34 points
    Draw pen stroke with 11 points
    Draw pen stroke with 18 points
    Draw pen stroke with 11 points
    Draw pen stroke with 11 points
    Draw pen stroke with 4 points
    Draw pen stroke with 28 points
    Draw pen stroke with 32 points
    Draw pen stroke with 29 points
    Draw pen stroke with 21 points
    New page, aspect ratio 0.707
    Draw pen stroke with 12 points
    Draw pen stroke with 30 points
    Draw pen stroke with 26 points
    Draw pen stroke with 50 points
    Draw pen stroke with 54 points
    New page, aspect ratio 0.707
    Ending export
"""

from base import ExporterBase





[docs]class ExporterBase2(ExporterBase): ################################################################## # # Easier way to implement your own exporter: define exporters for # metadata and graphics objects. # ##################################################################
[docs] def begin_export(self): """ Called at the beginning of the export process. """ print 'Beginning export'
[docs] def end_export(self): """ Called at the beginning of the export process. """ print 'Ending export'
[docs] def title(self, title): """ Set the title. """ print 'Title is set to '+title
[docs] def uuid(self, uuid): print 'UUID is set to '+uuid
[docs] def creation_time(self, ctime, ctime_millis): print 'Creation time set to '+str(ctime)
[docs] def modification_time(self, mtime, mtime_millis): print 'Last modification time set to '+str(mtime)
[docs] def new_page(self, page): """ Add a new empty page to the exported document. """ print 'New page, aspect ratio '+str(round(page.aspect_ratio(), 3))
[docs] def stroke(self, stroke): """ """ print 'Draw '+str(stroke)
[docs] def image(self, image): print 'Draw '+str(image) ################################################################## # # The rest is the implementation of the book() method, you # shouldn't have to override anything. # ##################################################################
[docs] def book(self, book): """ Export the notebook. :param book: the notebook to export """ self.begin_export() self.title(book.title()) self.uuid(book.uuid()) self.creation_time(book.ctime(), book.ctime_millis()) self.modification_time(book.mtime(), book.mtime_millis()) for i in range(book.n_pages()): page = book.get_page(i) self.page(page) self.end_export()
[docs] def page(self, page): """ Export a page """ self.new_page(page) for image in page.images(): self.image(image) for stroke in page.strokes(): self.stroke(stroke)