コード例 #1
0
ファイル: from_html.py プロジェクト: iwannafly/calibre
    def __init__(self, opts, log, cover_data=None, toc=None):
        from calibre.gui2 import is_ok_to_use_qt
        if not is_ok_to_use_qt():
            raise Exception('Not OK to use Qt')
        QObject.__init__(self)

        self.logger = self.log = log
        self.opts = opts
        self.cover_data = cover_data
        self.paged_js = None
        self.toc = toc

        self.loop = QEventLoop()
        self.view = QWebView()
        self.page = Page(opts, self.log)
        self.view.setPage(self.page)
        self.view.setRenderHints(QPainter.Antialiasing|
                    QPainter.TextAntialiasing|QPainter.SmoothPixmapTransform)
        self.view.loadFinished.connect(self.render_html,
                type=Qt.QueuedConnection)
        for x in (Qt.Horizontal, Qt.Vertical):
            self.view.page().mainFrame().setScrollBarPolicy(x,
                    Qt.ScrollBarAlwaysOff)
        self.report_progress = lambda x, y: x
        self.current_section = ''
コード例 #2
0
ファイル: writer.py プロジェクト: sss/calibre
    def __init__(self, opts, log, cover_data=None, toc=None):
        from calibre.gui2 import is_ok_to_use_qt
        from calibre.utils.podofo import get_podofo
        if not is_ok_to_use_qt():
            raise Exception('Not OK to use Qt')
        QObject.__init__(self)

        self.logger = self.log = log
        self.podofo = get_podofo()
        self.doc = self.podofo.PDFDoc()

        self.loop = QEventLoop()
        self.view = QWebView()
        self.page = Page(opts, self.log)
        self.view.setPage(self.page)
        self.view.setRenderHints(QPainter.Antialiasing
                                 | QPainter.TextAntialiasing
                                 | QPainter.SmoothPixmapTransform)
        self.view.loadFinished.connect(self._render_html,
                                       type=Qt.QueuedConnection)
        for x in (Qt.Horizontal, Qt.Vertical):
            self.view.page().mainFrame().setScrollBarPolicy(
                x, Qt.ScrollBarAlwaysOff)
        self.render_queue = []
        self.combine_queue = []
        self.tmp_path = PersistentTemporaryDirectory(u'_pdf_output_parts')

        self.opts = opts
        self.cover_data = cover_data
        self.paged_js = None
        self.toc = toc
コード例 #3
0
ファイル: writer.py プロジェクト: hashken/calibre
    def __init__(self, opts, log, cover_data=None, toc=None):
        from calibre.gui2 import is_ok_to_use_qt
        from calibre.utils.podofo import get_podofo

        if not is_ok_to_use_qt():
            raise Exception("Not OK to use Qt")
        QObject.__init__(self)

        self.logger = self.log = log
        self.podofo = get_podofo()
        self.doc = self.podofo.PDFDoc()

        self.loop = QEventLoop()
        self.view = QWebView()
        self.page = Page(opts, self.log)
        self.view.setPage(self.page)
        self.view.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing | QPainter.SmoothPixmapTransform)
        self.view.loadFinished.connect(self._render_html, type=Qt.QueuedConnection)
        for x in (Qt.Horizontal, Qt.Vertical):
            self.view.page().mainFrame().setScrollBarPolicy(x, Qt.ScrollBarAlwaysOff)
        self.render_queue = []
        self.combine_queue = []
        self.tmp_path = PersistentTemporaryDirectory(u"_pdf_output_parts")

        self.opts = opts
        self.cover_data = cover_data
        self.paged_js = None
        self.toc = toc
コード例 #4
0
ファイル: table_as_image.py プロジェクト: yesplease/calibre
def do_render(html, base_dir, width, height, dpi, factor):
    from calibre.gui2 import is_ok_to_use_qt
    if not is_ok_to_use_qt():
        raise Exception('Not OK to use Qt')
    tr = HTMLTableRenderer(html, base_dir, width, height, dpi, factor)
    tr.loop.exec_()
    return tr.images, tr.tdir
コード例 #5
0
ファイル: __init__.py プロジェクト: yeyanchao/calibre
def render_html(path_to_html, width=590, height=750, as_xhtml=True):
    from PyQt4.QtWebKit import QWebPage
    from PyQt4.Qt import QEventLoop, QPalette, Qt, QUrl, QSize
    from calibre.gui2 import is_ok_to_use_qt
    if not is_ok_to_use_qt(): return None
    path_to_html = os.path.abspath(path_to_html)
    with CurrentDir(os.path.dirname(path_to_html)):
        page = QWebPage()
        pal = page.palette()
        pal.setBrush(QPalette.Background, Qt.white)
        page.setPalette(pal)
        page.setViewportSize(QSize(width, height))
        page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
        page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
        loop = QEventLoop()
        renderer = HTMLRenderer(page, loop)
        page.loadFinished.connect(renderer, type=Qt.QueuedConnection)
        if as_xhtml:
            page.mainFrame().setContent(open(path_to_html, 'rb').read(),
                    'application/xhtml+xml', QUrl.fromLocalFile(path_to_html))
        else:
            page.mainFrame().load(QUrl.fromLocalFile(path_to_html))
        loop.exec_()
    renderer.loop = renderer.page = None
    page.loadFinished.disconnect()
    del page
    del loop
    if isinstance(renderer.exception, ParserError) and as_xhtml:
        return render_html(path_to_html, width=width, height=height,
                as_xhtml=False)
    return renderer
コード例 #6
0
ファイル: __init__.py プロジェクト: harrywright/calibre
def render_html_svg_workaround(path_to_html, log, width=590, height=750):
    from calibre.ebooks.oeb.base import SVG_NS
    raw = open(path_to_html, 'rb').read()
    data = None
    if SVG_NS in raw:
        try:
            data = extract_cover_from_embedded_svg(raw,
                   os.path.dirname(path_to_html), log)
        except:
            pass
    if data is None:
        try:
            data = extract_calibre_cover(raw, os.path.dirname(path_to_html), log)
        except:
            pass

    if data is None:
        from calibre.gui2 import is_ok_to_use_qt
        if is_ok_to_use_qt():
            data = render_html_data(path_to_html, width, height)
        else:
            from calibre.utils.ipc.simple_worker import fork_job, WorkerError
            try:
                result = fork_job('calibre.ebooks',
                                  'render_html_data',
                                  (path_to_html, width, height),
                                  no_output=True)
                data = result['result']
            except WorkerError as err:
                prints(err.orig_tb)
            except:
                traceback.print_exc()
    return data
コード例 #7
0
def render_html(path_to_html, width=590, height=750, as_xhtml=True):
    from PyQt4.QtWebKit import QWebPage
    from PyQt4.Qt import QEventLoop, QPalette, Qt, QUrl, QSize
    from calibre.gui2 import is_ok_to_use_qt
    if not is_ok_to_use_qt():
        return None
    path_to_html = os.path.abspath(path_to_html)
    with CurrentDir(os.path.dirname(path_to_html)):
        page = QWebPage()
        pal = page.palette()
        pal.setBrush(QPalette.Background, Qt.white)
        page.setPalette(pal)
        page.setViewportSize(QSize(width, height))
        page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
        page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
        loop = QEventLoop()
        renderer = HTMLRenderer(page, loop)
        page.loadFinished.connect(renderer, type=Qt.QueuedConnection)
        if as_xhtml:
            page.mainFrame().setContent(open(path_to_html, 'rb').read(),
                    'application/xhtml+xml', QUrl.fromLocalFile(path_to_html))
        else:
            page.mainFrame().load(QUrl.fromLocalFile(path_to_html))
        loop.exec_()
    renderer.loop = renderer.page = None
    page.loadFinished.disconnect()
    del page
    del loop
    if isinstance(renderer.exception, ParserError) and as_xhtml:
        return render_html(path_to_html, width=width, height=height,
                as_xhtml=False)
    return renderer
コード例 #8
0
ファイル: mobidedrm.py プロジェクト: tjgaghan/KindleDecrypt
 def run(self, path_to_ebook):
     from calibre.gui2 import is_ok_to_use_qt
     from PyQt4.Qt import QMessageBox
     PID = self.site_customization
     data_file = file(path_to_ebook, 'rb').read()
     ar = PID.split(',')
     for i in ar:
         try:
             unlocked_file = DrmStripper(data_file, i).getResult()
         except DrmException:
             # ignore the error
             pass
         else:
             of = self.temporary_file('.mobi')
             of.write(unlocked_file)
             of.close()
             return of.name
     if is_ok_to_use_qt():
         d = QMessageBox(
             QMessageBox.Warning, "MobiDeDRM Plugin",
             "Couldn't decode: %s\n\nImporting encrypted version." %
             path_to_ebook)
         d.show()
         d.raise_()
         d.exec_()
     return path_to_ebook
コード例 #9
0
ファイル: table_as_image.py プロジェクト: JimmXinu/calibre
def do_render(html, base_dir, width, height, dpi, factor):
    from calibre.gui2 import is_ok_to_use_qt
    if not is_ok_to_use_qt():
        raise Exception('Not OK to use Qt')
    tr = HTMLTableRenderer(html, base_dir, width, height, dpi, factor)
    tr.loop.exec_()
    return tr.images, tr.tdir
コード例 #10
0
ファイル: from_html.py プロジェクト: iwannafly/calibre
    def __init__(self, opts, log, cover_data=None, toc=None):
        from calibre.gui2 import is_ok_to_use_qt
        if not is_ok_to_use_qt():
            raise Exception('Not OK to use Qt')
        QObject.__init__(self)

        self.logger = self.log = log
        self.opts = opts
        self.cover_data = cover_data
        self.paged_js = None
        self.toc = toc

        self.loop = QEventLoop()
        self.view = QWebView()
        self.page = Page(opts, self.log)
        self.view.setPage(self.page)
        self.view.setRenderHints(QPainter.Antialiasing
                                 | QPainter.TextAntialiasing
                                 | QPainter.SmoothPixmapTransform)
        self.view.loadFinished.connect(self.render_html,
                                       type=Qt.QueuedConnection)
        for x in (Qt.Horizontal, Qt.Vertical):
            self.view.page().mainFrame().setScrollBarPolicy(
                x, Qt.ScrollBarAlwaysOff)
        self.report_progress = lambda x, y: x
        self.current_section = ''
コード例 #11
0
def render_html_svg_workaround(path_to_html, log, width=590, height=750):
    from calibre.ebooks.oeb.base import SVG_NS
    raw = open(path_to_html, 'rb').read()
    data = None
    if SVG_NS in raw:
        try:
            data = extract_cover_from_embedded_svg(raw,
                   os.path.dirname(path_to_html), log)
        except:
            pass
    if data is None:
        try:
            data = extract_calibre_cover(raw, os.path.dirname(path_to_html), log)
        except:
            pass

    if data is None:
        from calibre.gui2 import is_ok_to_use_qt
        if is_ok_to_use_qt():
            data = render_html_data(path_to_html, width, height)
        else:
            from calibre.utils.ipc.simple_worker import fork_job, WorkerError
            try:
                result = fork_job('calibre.ebooks',
                                  'render_html_data',
                                  (path_to_html, width, height),
                                  no_output=True)
                data = result['result']
            except WorkerError as err:
                prints(err.orig_tb)
            except:
                traceback.print_exc()
    return data
コード例 #12
0
def get_pdf_printer(opts, for_comic=False, output_file_name=None):
    from calibre.gui2 import is_ok_to_use_qt
    if not is_ok_to_use_qt():
        raise Exception('Not OK to use Qt')

    printer = QPrinter(QPrinter.HighResolution)
    custom_size = get_custom_size(opts)
    if isosx and not for_comic:
        # On OSX, the native engine can only produce a single page size
        # (usually A4). The Qt engine on the other hand produces image based
        # PDFs. If we set a custom page size using QSizeF the native engine
        # produces unreadable output, so we just ignore the custom size
        # settings.
        printer.setPaperSize(paper_size(opts.paper_size))
    else:
        if opts.output_profile.short_name == 'default' or \
                opts.output_profile.width > 9999:
            if custom_size is None:
                printer.setPaperSize(paper_size(opts.paper_size))
            else:
                printer.setPaperSize(QSizeF(custom_size[0], custom_size[1]),
                                     unit(opts.unit))
        else:
            w = opts.output_profile.comic_screen_size[0] if for_comic else \
                    opts.output_profile.width
            h = opts.output_profile.comic_screen_size[1] if for_comic else \
                    opts.output_profile.height
            dpi = opts.output_profile.dpi
            printer.setPaperSize(QSizeF(float(w) / dpi,
                                        float(h) / dpi), QPrinter.Inch)

    if for_comic:
        # Comic pages typically have their own margins, or their background
        # color is not white, in which case the margin looks bad
        printer.setPageMargins(0, 0, 0, 0, QPrinter.Point)
    else:
        printer.setPageMargins(opts.margin_left, opts.margin_top,
                               opts.margin_right, opts.margin_bottom,
                               QPrinter.Point)
    printer.setOrientation(orientation(opts.orientation))
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setFullPage(for_comic)
    if output_file_name:
        printer.setOutputFileName(output_file_name)
    if isosx and not for_comic:
        # Ensure we are not generating enormous image based PDFs
        printer.setOutputFormat(QPrinter.NativeFormat)

    return printer
コード例 #13
0
ファイル: writer.py プロジェクト: hashken/calibre
def get_pdf_printer(opts, for_comic=False, output_file_name=None):  # {{{
    from calibre.gui2 import is_ok_to_use_qt

    if not is_ok_to_use_qt():
        raise Exception("Not OK to use Qt")

    printer = QPrinter(QPrinter.HighResolution)
    custom_size = get_custom_size(opts)
    if isosx and not for_comic:
        # On OSX, the native engine can only produce a single page size
        # (usually A4). The Qt engine on the other hand produces image based
        # PDFs. If we set a custom page size using QSizeF the native engine
        # produces unreadable output, so we just ignore the custom size
        # settings.
        printer.setPaperSize(paper_size(opts.paper_size))
    else:
        if (
            opts.output_profile.short_name == "default"
            or opts.output_profile.width > 9999
            or opts.override_profile_size
        ):
            if custom_size is None:
                printer.setPaperSize(paper_size(opts.paper_size))
            else:
                printer.setPaperSize(QSizeF(custom_size[0], custom_size[1]), unit(opts.unit))
        else:
            w = opts.output_profile.comic_screen_size[0] if for_comic else opts.output_profile.width
            h = opts.output_profile.comic_screen_size[1] if for_comic else opts.output_profile.height
            dpi = opts.output_profile.dpi
            printer.setPaperSize(QSizeF(float(w) / dpi, float(h) / dpi), QPrinter.Inch)

    if for_comic:
        # Comic pages typically have their own margins, or their background
        # color is not white, in which case the margin looks bad
        printer.setPageMargins(0, 0, 0, 0, QPrinter.Point)
    else:
        printer.setPageMargins(opts.margin_left, opts.margin_top, opts.margin_right, opts.margin_bottom, QPrinter.Point)
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setFullPage(for_comic)
    if output_file_name:
        printer.setOutputFileName(output_file_name)
    if isosx and not for_comic:
        # Ensure we are not generating enormous image based PDFs
        printer.setOutputFormat(QPrinter.NativeFormat)

    return printer
コード例 #14
0
ファイル: mobidedrm.py プロジェクト: lrobot/kindledecrypt
 def run(self, path_to_ebook):
     from calibre.gui2 import is_ok_to_use_qt
     from PyQt4.Qt import QMessageBox
     PID = self.site_customization
     data_file = file(path_to_ebook, 'rb').read()
     ar = PID.split(',')
     for i in ar:
         try:
             unlocked_file = DrmStripper(data_file, i).getResult()
         except DrmException:
             # ignore the error
             pass
         else:
             of = self.temporary_file('.mobi')
             of.write(unlocked_file)
             of.close()
             return of.name
     if is_ok_to_use_qt():
         d = QMessageBox(QMessageBox.Warning, "MobiDeDRM Plugin", "Couldn't decode: %s\n\nImporting encrypted version." % path_to_ebook)
         d.show()
         d.raise_()
         d.exec_()
     return path_to_ebook
コード例 #15
0
ファイル: rasterize.py プロジェクト: 089git/calibre
 def __init__(self):
     from calibre.gui2 import is_ok_to_use_qt
     if not is_ok_to_use_qt():
         raise Unavailable('Not OK to use Qt')
コード例 #16
0
ファイル: font_key.py プロジェクト: BobPyron/calibre
        dbase = self.dbase
        fsize = self.input_font_size.value()
        try:
            fsizes = self.fsizes
        except:
            return

        if dbase == 0.0 or not fsizes:
            pd, pfs = self.get_profile_values()
            if dbase == 0.0:
                dbase = pd
            if not fsizes:
                fsizes = pfs

        from calibre.ebooks.oeb.transforms.flatcss import KeyMapper
        mapper = KeyMapper(sbase, dbase, fsizes)
        msize = mapper[fsize]
        self.input_mapped_font_size.setText('%.1f pt'%msize)

    def use_default(self):
        dbase, fsizes = self.get_profile_values()
        self.output_base_font_size.setValue(dbase)
        self.font_size_key.setText(', '.join(['%.1f'%x for x in fsizes]))


if __name__ == '__main__':
    from calibre.gui2 import is_ok_to_use_qt
    is_ok_to_use_qt()
    d = FontKeyChooser()
    d.exec_()
コード例 #17
0
ファイル: rasterize.py プロジェクト: sss/calibre
 def __init__(self):
     from calibre.gui2 import is_ok_to_use_qt
     if not is_ok_to_use_qt():
         raise Unavailable('Not OK to use Qt')
コード例 #18
0
ファイル: font_key.py プロジェクト: sss/calibre
        dbase = self.dbase
        fsize = self.input_font_size.value()
        try:
            fsizes = self.fsizes
        except:
            return

        if dbase == 0.0 or not fsizes:
            pd, pfs = self.get_profile_values()
            if dbase == 0.0:
                dbase = pd
            if not fsizes:
                fsizes = pfs

        from calibre.ebooks.oeb.transforms.flatcss import KeyMapper
        mapper = KeyMapper(sbase, dbase, fsizes)
        msize = mapper[fsize]
        self.input_mapped_font_size.setText('%.1f pt'%msize)

    def use_default(self):
        dbase, fsizes = self.get_profile_values()
        self.output_base_font_size.setValue(dbase)
        self.font_size_key.setText(', '.join(['%.1f'%x for x in fsizes]))


if __name__ == '__main__':
    from calibre.gui2 import is_ok_to_use_qt
    is_ok_to_use_qt()
    d = FontKeyChooser()
    d.exec_()
コード例 #19
0
ファイル: rescale.py プロジェクト: siebert/calibre
 def __call__(self, oeb, opts):
     self.oeb, self.opts, self.log = oeb, opts, oeb.log
     from calibre.gui2 import is_ok_to_use_qt
     self.rescale(qt=is_ok_to_use_qt())