Ejemplo n.º 1
0
def create_profile():
    ans = getattr(create_profile, 'ans', None)
    if ans is None:
        ans = create_profile.ans = QWebEngineProfile(QApplication.instance())
        s = QWebEngineScript()
        s.setName('csslint.js')
        s.setSourceCode(csslint_js())
        s.setWorldId(QWebEngineScript.ScriptWorldId.ApplicationWorld)
        ans.scripts().insert(s)
    return ans
Ejemplo n.º 2
0
def create_script(
    name, src, world=QWebEngineScript.ScriptWorldId.ApplicationWorld,
    injection_point=QWebEngineScript.InjectionPoint.DocumentReady,
    on_subframes=True
):
    script = QWebEngineScript()
    if isinstance(src, bytes):
        src = src.decode('utf-8')
    script.setSourceCode(src)
    script.setName(name)
    script.setWorldId(world)
    script.setInjectionPoint(injection_point)
    script.setRunsOnSubFrames(on_subframes)
    return script
Ejemplo n.º 3
0
 def create_script(src, name):
     s = QWebEngineScript()
     s.setName(name)
     s.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentReady)
     s.setWorldId(QWebEngineScript.ScriptWorldId.ApplicationWorld)
     s.setRunsOnSubFrames(True)
     s.setSourceCode(src)
     return s
Ejemplo n.º 4
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.º 5
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)