Example #1
0
    def current_changed(self, item):
        name = self.current_name = unicode(item.data(Qt.DisplayRole) or '')
        self.current_frag = None
        path = self.container.name_to_abspath(name)
        # Ensure encoding map is populated
        root = self.container.parsed(name)
        nasty = root.xpath('//*[local-name()="head"]/*[local-name()="p"]')
        if nasty:
            body = root.xpath('//*[local-name()="body"]')
            if not body:
                return error_dialog(self, _('Bad markup'),
                             _('This book has severely broken markup, its ToC cannot be edited.'), show=True)
            for x in reversed(nasty):
                body[0].insert(0, x)
            self.container.commit_item(name, keep_parsed=True)
        encoding = self.container.encoding_map.get(name, None) or 'utf-8'

        load_html(path, self.view, codec=encoding,
                  mime_type=self.container.mime_map[name])
        self.view.load_js()
        self.dest_label.setText(self.base_msg + '<br>' + _('File:') + ' ' +
                                name + '<br>' + _('Top of the file'))
        if hasattr(self, 'pending_search'):
            f = self.pending_search
            del self.pending_search
            f()
Example #2
0
    def current_changed(self, item):
        name = self.current_name = str(item.data(Qt.DisplayRole) or '')
        self.current_frag = None
        path = self.container.name_to_abspath(name)
        # Ensure encoding map is populated
        root = self.container.parsed(name)
        nasty = root.xpath('//*[local-name()="head"]/*[local-name()="p"]')
        if nasty:
            body = root.xpath('//*[local-name()="body"]')
            if not body:
                return error_dialog(
                    self,
                    _('Bad markup'),
                    _('This book has severely broken markup, its ToC cannot be edited.'
                      ),
                    show=True)
            for x in reversed(nasty):
                body[0].insert(0, x)
            self.container.commit_item(name, keep_parsed=True)
        encoding = self.container.encoding_map.get(name, None) or 'utf-8'

        load_html(path,
                  self.view,
                  codec=encoding,
                  mime_type=self.container.mime_map[name])
        self.view.load_js()
        self.dest_label.setText(self.base_msg + '<br>' + _('File:') + ' ' +
                                name + '<br>' + _('Top of the file'))
        if hasattr(self, 'pending_search'):
            f = self.pending_search
            del self.pending_search
            f()
Example #3
0
 def load_network(self):
     path = P(u'adventurous_map_viewer/book_renderer.html').replace(os.sep, '/')
     path = str(path)
     load_html(path, self, codec=getattr(path, 'encoding', 'utf-8'), 
             mime_type=getattr(path, 'mime_type', 'text/html'))
     self.loaded = False
     self.toc_created = False
Example #4
0
    def render_next(self):
        item = unicode_type(self.render_queue.pop(0))

        self.logger.debug('Processing %s...' % item)
        self.current_item = item
        load_html(item, self.view)
        self.last_load_progress_at = monotonic()
        self.hang_check_timer.start()
Example #5
0
    def _render_next(self):
        item = unicode(self.render_queue.pop(0))
        self.combine_queue.append(
            os.path.join(self.tmp_path,
                         '%i.pdf' % (len(self.combine_queue) + 1)))

        self.logger.debug('Processing %s...' % item)
        load_html(item, self.view)
Example #6
0
    def render_next(self):
        item = unicode_type(self.render_queue.pop(0))

        self.logger.debug('Processing %s...' % item)
        self.current_item = item
        load_html(item, self.view)
        self.last_load_progress_at = monotonic()
        self.hang_check_timer.start()
Example #7
0
    def do_print(self, printer):
        painter = QPainter(printer)
        zoomx = printer.logicalDpiX() / self.view.logicalDpiX()
        zoomy = printer.logicalDpiY() / self.view.logicalDpiY()
        painter.scale(zoomx, zoomy)
        pr = printer.pageRect()
        self.view.page().setViewportSize(
            QSize(pr.width() / zoomx,
                  pr.height() / zoomy))
        evaljs = self.mf.evaluateJavaScript
        loop = QEventLoop(self)
        pagenum = 0
        from_, to = printer.fromPage(), printer.toPage()
        first = True

        for path in self.iterator.spine:
            self.loaded_ok = None
            load_html(path,
                      self.view,
                      codec=getattr(path, 'encoding', 'utf-8'),
                      mime_type=getattr(path, 'mime_type', None))
            while self.loaded_ok is None:
                loop.processEvents(loop.ExcludeUserInputEvents)
            if not self.loaded_ok:
                return error_dialog(self.parent(),
                                    _('Failed to render'),
                                    _('Failed to render document %s') % path,
                                    show=True)
            evaljs(self.paged_js)
            evaljs('''
                document.body.style.backgroundColor = "white";
                paged_display.set_geometry(1, 0, 0, 0);
                paged_display.layout();
                paged_display.fit_images();
            ''')

            while True:
                pagenum += 1
                if (pagenum >= from_ and (to == 0 or pagenum <= to)):
                    if not first:
                        printer.newPage()
                    first = False
                    self.mf.render(painter)
                try:
                    nsl = int(evaljs('paged_display.next_screen_location()'))
                except (TypeError, ValueError):
                    break
                if nsl <= 0:
                    break
                evaljs('window.scrollTo(%d, 0)' % nsl)

        painter.end()
Example #8
0
    def show_footnote(self, fd):
        path, target, self.showing_url = fd

        if hasattr(self, 'footnotes_view'):
            if load_html(path, self.footnotes_view.view, codec=getattr(path, 'encoding', 'utf-8'),
                         mime_type=getattr(path, 'mime_type', 'text/html')):
                self.footnotes_view.page().set_footnote_data(target, {k:True for k in self.known_footnote_targets[path]})
Example #9
0
    def current_changed(self, item):
        name = self.current_name = unicode(item.data(Qt.DisplayRole).toString())
        path = self.container.name_to_abspath(name)
        # Ensure encoding map is populated
        self.container.parsed(name)
        encoding = self.container.encoding_map.get(name, None) or 'utf-8'

        load_html(path, self.view, codec=encoding,
                  mime_type=self.container.mime_map[name])
        self.view.load_js()
        self.dest_label.setText(self.base_msg + '<br>' + _('File:') + ' ' +
                                name + '<br>' + _('Top of the file'))
        if hasattr(self, 'pending_search'):
            f = self.pending_search
            del self.pending_search
            f()
Example #10
0
    def show_footnote(self, fd):
        path, target, self.showing_url = fd

        if hasattr(self, 'footnotes_view'):
            if load_html(path, self.footnotes_view.view, codec=getattr(path, 'encoding', 'utf-8'),
                         mime_type=getattr(path, 'mime_type', 'text/html')):
                self.footnotes_view.page().set_footnote_data(target, {k:True for k in self.known_footnote_targets[path]})
Example #11
0
    def do_print(self, printer):
        painter = QPainter(printer)
        zoomx = printer.logicalDpiX()/self.view.logicalDpiX()
        zoomy = printer.logicalDpiY()/self.view.logicalDpiY()
        painter.scale(zoomx, zoomy)
        pr = printer.pageRect()
        self.view.page().setViewportSize(QSize(pr.width()/zoomx,
            pr.height()/zoomy))
        evaljs = self.mf.evaluateJavaScript
        loop = QEventLoop(self)
        pagenum = 0
        from_, to = printer.fromPage(), printer.toPage()
        first = True

        for path in self.iterator.spine:
            self.loaded_ok = None
            load_html(path, self.view, codec=getattr(path, 'encoding', 'utf-8'),
                    mime_type=getattr(path, 'mime_type', None))
            while self.loaded_ok is None:
                loop.processEvents(loop.ExcludeUserInputEvents)
            if not self.loaded_ok:
                return error_dialog(self.parent(), _('Failed to render'),
                        _('Failed to render document %s')%path, show=True)
            evaljs(self.paged_js)
            evaljs('''
                document.body.style.backgroundColor = "white";
                paged_display.set_geometry(1, 0, 0, 0);
                paged_display.layout();
                paged_display.fit_images();
            ''')

            while True:
                pagenum += 1
                if (pagenum >= from_ and (to == 0 or pagenum <= to)):
                    if not first:
                        printer.newPage()
                    first = False
                    self.mf.render(painter)
                try:
                    nsl = int(evaljs('paged_display.next_screen_location()'))
                except (TypeError, ValueError):
                    break
                if nsl <= 0:
                    break
                evaljs('window.scrollTo(%d, 0)'%nsl)

        painter.end()
Example #12
0
    def load_path(self, path, pos=0.0):
        self.initial_pos = pos

        def callback(lu):
            self.loading_url = lu
            if self.manager is not None:
                self.manager.load_started()

        load_html(path, self, codec=getattr(path, 'encoding', 'utf-8'), mime_type=getattr(path,
            'mime_type', None), pre_load_callback=callback)
        entries = set()
        for ie in getattr(path, 'index_entries', []):
            if ie.start_anchor:
                entries.add(ie.start_anchor)
            if ie.end_anchor:
                entries.add(ie.end_anchor)
        self.document.index_anchors = entries
Example #13
0
    def load_path(self, path, pos=0.0):
        self.initial_pos = pos
        self.last_loaded_path = path

        def callback(lu):
            self.loading_url = lu
            if self.manager is not None:
                self.manager.load_started()

        load_html(path, self, codec=getattr(path, 'encoding', 'utf-8'), mime_type=getattr(path,
            'mime_type', 'text/html'), pre_load_callback=callback)
        entries = set()
        for ie in getattr(path, 'index_entries', []):
            if ie.start_anchor:
                entries.add(ie.start_anchor)
            if ie.end_anchor:
                entries.add(ie.end_anchor)
        self.document.index_anchors = entries
Example #14
0
    def current_changed(self, item):
        name = self.current_name = unicode(
            item.data(Qt.DisplayRole).toString())
        path = self.container.name_to_abspath(name)
        # Ensure encoding map is populated
        self.container.parsed(name)
        encoding = self.container.encoding_map.get(name, None) or 'utf-8'

        load_html(path,
                  self.view,
                  codec=encoding,
                  mime_type=self.container.mime_map[name])
        self.view.load_js()
        self.dest_label.setText(self.base_msg + '<br>' + _('File:') + ' ' +
                                name + '<br>' + _('Top of the file'))
        if hasattr(self, 'pending_search'):
            f = self.pending_search
            del self.pending_search
            f()
Example #15
0
    def load_path(self, path, pos=0.0):
        self.initial_pos = pos
        self.last_loaded_path = path

        def callback(lu):
            self.loading_url = lu
            if self.manager is not None:
                self.manager.load_started()

        load_html(
            path,
            self,
            codec=getattr(path, "encoding", "utf-8"),
            mime_type=getattr(path, "mime_type", "text/html"),
            pre_load_callback=callback,
        )
        entries = set()
        for ie in getattr(path, "index_entries", []):
            if ie.start_anchor:
                entries.add(ie.start_anchor)
            if ie.end_anchor:
                entries.add(ie.end_anchor)
        self.document.index_anchors = entries
Example #16
0
    def render_next(self):
        item = unicode(self.render_queue.pop(0))

        self.logger.debug('Processing %s...' % item)
        self.current_item = item
        load_html(item, self.view)
Example #17
0
 def render_next(self):
     item = unicode(self.render_queue.pop(0))
     self.current_item = item
     load_html(item, self.view)
Example #18
0
 def render_next(self):
     item = unicode(self.render_queue.pop(0))
     self.current_item = item
     load_html(item, self.view)
Example #19
0
    def _render_next(self):
        item = unicode(self.render_queue.pop(0))

        self.logger.debug('Processing %s...' % item)
        self.current_item = item
        load_html(item, self.view)
Example #20
0
    def _render_next(self):
        item = unicode(self.render_queue.pop(0))
        self.combine_queue.append(os.path.join(self.tmp_path, '%i.pdf' % (len(self.combine_queue) + 1)))

        self.logger.debug('Processing %s...' % item)
        load_html(item, self.view)