Ejemplo n.º 1
0
    def __init__(self, opts, parent, log):
        QWebEnginePage.__init__(self, parent.profile, parent)
        secure_webengine(self)
        self.working = False
        self.log = log
        self.load_complete = False
        self.settle_time = 0
        self.wait_for_title = None
        s = self.settings()
        s.setAttribute(s.JavascriptEnabled, True)
        s.setFontSize(s.DefaultFontSize, opts.pdf_default_font_size)
        s.setFontSize(s.DefaultFixedFontSize, opts.pdf_mono_font_size)
        s.setFontSize(s.MinimumLogicalFontSize, 8)
        s.setFontSize(s.MinimumFontSize, 8)
        std = {
            'serif': opts.pdf_serif_family,
            'sans' : opts.pdf_sans_family,
            'mono' : opts.pdf_mono_family
        }.get(opts.pdf_standard_font, opts.pdf_serif_family)
        if std:
            s.setFontFamily(s.StandardFont, std)
        if opts.pdf_serif_family:
            s.setFontFamily(s.SerifFont, opts.pdf_serif_family)
        if opts.pdf_sans_family:
            s.setFontFamily(s.SansSerifFont, opts.pdf_sans_family)
        if opts.pdf_mono_family:
            s.setFontFamily(s.FixedFont, opts.pdf_mono_family)

        self.titleChanged.connect(self.title_changed)
        self.loadStarted.connect(self.load_started)
        self.loadFinished.connect(self.load_finished)
Ejemplo n.º 2
0
 def __init__(self):
     QWebEnginePage.__init__(self)
     self.titleChanged.connect(self.title_changed)
     secure_webengine(self)
     self.scripts().insert(create_script(js, 'test-rapydscript.js'))
     self.setHtml('<p>initialize')
     self.working = True
Ejemplo n.º 3
0
 def __init__(self, prefs):
     self.log = default_log
     self.current_frag = None
     self.com_id = str(uuid4())
     QWebEnginePage.__init__(self)
     secure_webengine(self.settings(), for_viewer=True)
     self.titleChanged.connect(self.title_changed)
     self.loadFinished.connect(self.show_frag)
     s = QWebEngineScript()
     s.setName('toc.js')
     s.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentCreation)
     s.setRunsOnSubFrames(True)
     s.setWorldId(QWebEngineScript.ScriptWorldId.ApplicationWorld)
     js = P('toc.js', allow_user_override=False,
            data=True).decode('utf-8').replace('COM_ID', self.com_id, 1)
     if 'preview_background' in prefs.defaults and 'preview_foreground' in prefs.defaults:
         from calibre.gui2.tweak_book.preview import get_editor_settings
         settings = get_editor_settings(prefs)
     else:
         if is_dark_theme():
             settings = {
                 'is_dark_theme': True,
                 'bg': dark_color.name(),
                 'fg': dark_text_color.name(),
                 'link': dark_link_color.name(),
             }
         else:
             settings = {}
     js = js.replace('SETTINGS', json.dumps(settings), 1)
     dark_mode_css = P('dark_mode.css',
                       data=True,
                       allow_user_override=False).decode('utf-8')
     js = js.replace('CSS', json.dumps(dark_mode_css), 1)
     s.setSourceCode(js)
     self.scripts().insert(s)
Ejemplo n.º 4
0
 def __init__(self, parent):
     QWidget.__init__(self, parent)
     self.is_visible = False
     self.selected_text = ''
     self.current_query = ''
     self.current_source = ''
     self.l = l = QVBoxLayout(self)
     self.h = h = QHBoxLayout()
     l.addLayout(h)
     self.debounce_timer = t = QTimer(self)
     t.setInterval(150), t.timeout.connect(self.update_query)
     self.source_box = sb = QComboBox(self)
     self.label = la = QLabel(_('Lookup &in:'))
     h.addWidget(la), h.addWidget(sb), la.setBuddy(sb)
     self.view = QWebEngineView(self)
     self._page = Page(create_profile(), self.view)
     secure_webengine(self._page, for_viewer=True)
     self.view.setPage(self._page)
     l.addWidget(self.view)
     self.populate_sources()
     self.source_box.currentIndexChanged.connect(self.source_changed)
     self.view.setHtml('<p>' +
                       _('Double click on a word in the viewer window'
                         ' to look it up.'))
     self.add_button = b = QPushButton(QIcon(I('plus.png')),
                                       _('Add more sources'))
     b.clicked.connect(self.add_sources)
     l.addWidget(b)
Ejemplo n.º 5
0
 def __init__(self, parent):
     profile = create_profile()
     QWebEnginePage.__init__(self, profile, parent)
     profile.setParent(self)
     secure_webengine(self, for_viewer=True)
     apply_font_settings(self)
     self.bridge = ViewerBridge(self)
     self.bridge.copy_selection.connect(self.trigger_copy)
Ejemplo n.º 6
0
 def __init__(self):
     QWebEnginePage.__init__(self)
     secure_webengine(self)
     self.printing_started = False
     self.loadFinished.connect(self.load_finished, type=Qt.QueuedConnection)
     self.pdfPrintingFinished.connect(self.print_finished)
     self.hang_timer = t = QTimer(self)
     t.setInterval(500)
     t.timeout.connect(self.hang_check)
Ejemplo n.º 7
0
 def __init__(self):
     QWebEnginePage.__init__(self)
     self.errors = []
     secure_webengine(self)
     script = buf.getvalue().decode('utf-8')
     script += '\n\n;;\n\n' + vfs_script()
     self.scripts().insert(create_script(script, 'rapydscript.js'))
     self.setHtml('<p>initialize')
     while self.title() != 'compiler initialized':
         self.spin_loop()
Ejemplo n.º 8
0
 def __init__(self):
     must_use_qt()
     QWebEnginePage.__init__(self, create_profile(), QApplication.instance())
     self.titleChanged.connect(self.title_changed)
     secure_webengine(self.settings())
     self.console_messages = []
     self.ready = False
     self.working = False
     self.pending = None
     self.setHtml('')
Ejemplo n.º 9
0
 def __init__(self):
     profile = QWebEngineProfile(QApplication.instance())
     profile.setHttpUserAgent('calibre-tester')
     insert_scripts(profile, create_script('test-rapydscript.js', js, on_subframes=False))
     url_handler = UrlSchemeHandler(profile)
     profile.installUrlSchemeHandler(QByteArray(FAKE_PROTOCOL.encode('ascii')), url_handler)
     QWebEnginePage.__init__(self, profile, None)
     self.titleChanged.connect(self.title_changed)
     secure_webengine(self)
     self.setHtml('<p>initialize', QUrl(f'{FAKE_PROTOCOL}://{FAKE_HOST}/index.html'))
     self.working = True
Ejemplo n.º 10
0
 def __init__(self, parent):
     QWidget.__init__(self, parent)
     self.is_visible = False
     self.selected_text = ''
     self.current_query = ''
     self.current_source = ''
     self.l = l = QVBoxLayout(self)
     self.h = h = QHBoxLayout()
     l.addLayout(h)
     self.debounce_timer = t = QTimer(self)
     t.setInterval(150), t.timeout.connect(self.update_query)
     self.source_box = sb = QComboBox(self)
     self.label = la = QLabel(_('Lookup &in:'))
     h.addWidget(la), h.addWidget(sb), la.setBuddy(sb)
     self.view = View(self)
     self.view.inspect_element.connect(self.show_devtools)
     self._page = Page(create_profile(), self.view)
     apply_font_settings(self._page)
     secure_webengine(self._page, for_viewer=True)
     self.view.setPage(self._page)
     l.addWidget(self.view)
     self.populate_sources()
     self.source_box.currentIndexChanged.connect(self.source_changed)
     self.view.setHtml('<p>' +
                       _('Double click on a word in the book\'s text'
                         ' to look it up.'))
     self.add_button = b = QPushButton(QIcon(I('plus.png')),
                                       _('Add sources'))
     b.setToolTip(_('Add more sources at which to lookup words'))
     b.clicked.connect(self.add_sources)
     self.refresh_button = rb = QPushButton(QIcon(I('view-refresh.png')),
                                            _('Refresh'))
     rb.setToolTip(
         _('Refresh the result to match the currently selected text'))
     rb.clicked.connect(self.update_query)
     h = QHBoxLayout()
     l.addLayout(h)
     h.addWidget(b), h.addWidget(rb)
     self.auto_update_query = a = QCheckBox(_('Update on selection change'),
                                            self)
     self.disallow_auto_update = False
     a.setToolTip(
         textwrap.fill(
             _('Automatically update the displayed result when selected text in the book changes. With this disabled'
               ' the lookup is changed only when clicking the Refresh button.'
               )))
     a.setChecked(vprefs['auto_update_lookup'])
     a.stateChanged.connect(self.auto_update_state_changed)
     l.addWidget(a)
     self.update_refresh_button_status()
     set_sync_override.instance = self
Ejemplo n.º 11
0
 def __init__(self):
     self.log = default_log
     self.current_frag = None
     self.com_id = unicode_type(uuid4())
     QWebEnginePage.__init__(self)
     secure_webengine(self.settings(), for_viewer=True)
     self.titleChanged.connect(self.title_changed)
     self.loadFinished.connect(self.show_frag)
     s = QWebEngineScript()
     s.setName('toc.js')
     s.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentReady)
     s.setRunsOnSubFrames(True)
     s.setWorldId(QWebEngineScript.ScriptWorldId.ApplicationWorld)
     s.setSourceCode(P('toc.js', allow_user_override=False, data=True).decode('utf-8').replace('COM_ID', self.com_id))
     self.scripts().insert(s)
Ejemplo n.º 12
0
    def __init__(self, opts, parent, log):
        QWebEnginePage.__init__(self, parent.profile, parent)
        secure_webengine(self)
        self.working = False
        self.log = log
        self.load_complete = False
        self.settle_time = 0
        self.wait_for_title = None
        s = self.settings()
        s.setAttribute(s.JavascriptEnabled, True)
        s.setFontSize(s.DefaultFontSize, opts.pdf_default_font_size)
        s.setFontSize(s.DefaultFixedFontSize, opts.pdf_mono_font_size)
        s.setFontSize(s.MinimumLogicalFontSize, 8)
        s.setFontSize(s.MinimumFontSize, 8)
        std = {
            'serif': opts.pdf_serif_family,
            'sans' : opts.pdf_sans_family,
            'mono' : opts.pdf_mono_family
        }.get(opts.pdf_standard_font, opts.pdf_serif_family)
        if std:
            s.setFontFamily(s.StandardFont, std)
        if opts.pdf_serif_family:
            s.setFontFamily(s.SerifFont, opts.pdf_serif_family)
        if opts.pdf_sans_family:
            s.setFontFamily(s.SansSerifFont, opts.pdf_sans_family)
        if opts.pdf_mono_family:
            s.setFontFamily(s.FixedFont, opts.pdf_mono_family)

        self.titleChanged.connect(self.title_changed)
        self.loadStarted.connect(self.load_started)
        self.loadProgress.connect(self.load_progress)
        self.loadFinished.connect(self.load_finished)
        self.load_hang_check_timer = t = QTimer(self)
        self.load_started_at = 0
        t.setTimerType(Qt.TimerType.VeryCoarseTimer)
        t.setInterval(HANG_TIME * 1000)
        t.setSingleShot(True)
        t.timeout.connect(self.on_load_hang)
Ejemplo n.º 13
0
 def __init__(self, parent):
     QWebEnginePage.__init__(self, create_profile(), parent)
     secure_webengine(self, for_viewer=True)
     self.bridge = PreviewBridge(self)