Esempio n. 1
0
 def load_theme(self, theme_id):
     themes = load_themes()
     theme = themes[theme_id]
     opts = config(theme).parse()
     self.document.apply_settings(opts)
     if self.document.in_fullscreen_mode:
         self.document.switch_to_fullscreen_mode()
     self.setFocus(Qt.OtherFocusReason)
Esempio n. 2
0
 def load_theme(self, theme_id):
     themes = load_themes()
     theme = themes[theme_id]
     opts = config(theme).parse()
     self.document.apply_settings(opts)
     if self.document.in_fullscreen_mode:
         self.document.switch_to_fullscreen_mode()
     self.setFocus(Qt.OtherFocusReason)
Esempio n. 3
0
    def __init__(self, shortcuts, parent=None, debug_javascript=False):
        QWebPage.__init__(self, parent)
        self.setObjectName("py_bridge")
        self.in_paged_mode = False
        # Use this to pass arbitrary JSON encodable objects between python and
        # javascript. In python get/set the value as: self.bridge_value. In
        # javascript, get/set the value as: py_bridge.value
        self.bridge_value = None
        self.first_load = True

        self.debug_javascript = debug_javascript
        self.anchor_positions = {}
        self.index_anchors = set()
        self.current_language = None
        self.loaded_javascript = False
        self.js_loader = JavaScriptLoader(
                    dynamic_coffeescript=self.debug_javascript)
        self.in_fullscreen_mode = False

        self.setLinkDelegationPolicy(self.DelegateAllLinks)
        self.scroll_marks = []
        self.shortcuts = shortcuts
        pal = self.palette()
        pal.setBrush(QPalette.Background, QColor(0xee, 0xee, 0xee))
        self.setPalette(pal)
        self.page_position = PagePosition(self)

        settings = self.settings()

        # Fonts
        load_builtin_fonts()
        self.all_viewer_plugins = tuple(all_viewer_plugins())
        for pl in self.all_viewer_plugins:
            pl.load_fonts()
        opts = config().parse()
        self.set_font_settings(opts)

        # Security
        settings.setAttribute(QWebSettings.JavaEnabled, False)
        settings.setAttribute(QWebSettings.PluginsEnabled, False)
        settings.setAttribute(QWebSettings.JavascriptCanOpenWindows, False)
        settings.setAttribute(QWebSettings.JavascriptCanAccessClipboard, False)

        # Miscellaneous
        settings.setAttribute(QWebSettings.LinksIncludedInFocusChain, True)
        settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
        self.set_user_stylesheet(opts)
        self.misc_config(opts)

        # Load javascript
        self.mainFrame().javaScriptWindowObjectCleared.connect(
                self.add_window_objects)

        self.turn_off_internal_scrollbars()
Esempio n. 4
0
    def __init__(self, shortcuts, parent=None, debug_javascript=False):
        QWebPage.__init__(self, parent)
        self.setObjectName("py_bridge")
        self.in_paged_mode = False
        # Use this to pass arbitrary JSON encodable objects between python and
        # javascript. In python get/set the value as: self.bridge_value. In
        # javascript, get/set the value as: py_bridge.value
        self.bridge_value = None
        self.first_load = True

        self.debug_javascript = debug_javascript
        self.anchor_positions = {}
        self.index_anchors = set()
        self.current_language = None
        self.loaded_javascript = False
        self.js_loader = JavaScriptLoader(
                    dynamic_coffeescript=self.debug_javascript)
        self.in_fullscreen_mode = False

        self.setLinkDelegationPolicy(self.DelegateAllLinks)
        self.scroll_marks = []
        self.shortcuts = shortcuts
        pal = self.palette()
        pal.setBrush(QPalette.Background, QColor(0xee, 0xee, 0xee))
        self.setPalette(pal)
        self.page_position = PagePosition(self)

        settings = self.settings()

        # Fonts
        self.all_viewer_plugins = tuple(all_viewer_plugins())
        for pl in self.all_viewer_plugins:
            pl.load_fonts()
        opts = config().parse()
        self.set_font_settings(opts)

        # Security
        settings.setAttribute(QWebSettings.JavaEnabled, False)
        settings.setAttribute(QWebSettings.PluginsEnabled, False)
        settings.setAttribute(QWebSettings.JavascriptCanOpenWindows, False)
        settings.setAttribute(QWebSettings.JavascriptCanAccessClipboard, False)

        # Miscellaneous
        settings.setAttribute(QWebSettings.LinksIncludedInFocusChain, True)
        settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
        self.set_user_stylesheet(opts)
        self.misc_config(opts)

        # Load javascript
        self.mainFrame().javaScriptWindowObjectCleared.connect(
                self.add_window_objects)

        self.turn_off_internal_scrollbars()
Esempio n. 5
0
 def set_font_settings(self):
     opts = config().parse()
     settings = self.settings()
     settings.setFontSize(QWebSettings.DefaultFontSize, opts.default_font_size)
     settings.setFontSize(QWebSettings.DefaultFixedFontSize, opts.mono_font_size)
     settings.setFontSize(QWebSettings.MinimumLogicalFontSize, 8)
     settings.setFontSize(QWebSettings.MinimumFontSize, 8)
     settings.setFontFamily(QWebSettings.StandardFont, {'serif':opts.serif_family, 'sans':opts.sans_family, 'mono':opts.mono_family}[opts.standard_font])
     settings.setFontFamily(QWebSettings.SerifFont, opts.serif_family)
     settings.setFontFamily(QWebSettings.SansSerifFont, opts.sans_family)
     settings.setFontFamily(QWebSettings.FixedFont, opts.mono_family)
     settings.setAttribute(QWebSettings.ZoomTextOnly, True)
Esempio n. 6
0
 def misc_config(self):
     opts = config().parse()
     self.hyphenate = opts.hyphenate
     self.hyphenate_default_lang = opts.hyphenate_default_lang
     self.do_fit_images = opts.fit_images
     self.page_flip_duration = opts.page_flip_duration
     self.enable_page_flip = self.page_flip_duration > 0.1
     self.font_magnification_step = opts.font_magnification_step
     self.wheel_flips_pages = opts.wheel_flips_pages
     self.line_scrolling_stops_on_pagebreaks = opts.line_scrolling_stops_on_pagebreaks
     screen_width = QApplication.desktop().screenGeometry().width()
     # Leave some space for the scrollbar and some border
     self.max_fs_width = min(opts.max_fs_width, screen_width-50)
     self.fullscreen_clock = opts.fullscreen_clock
 def misc_config(self):
     opts = config().parse()
     self.hyphenate = opts.hyphenate
     self.hyphenate_default_lang = opts.hyphenate_default_lang
     self.do_fit_images = opts.fit_images
     self.page_flip_duration = opts.page_flip_duration
     self.enable_page_flip = self.page_flip_duration > 0.1
     self.font_magnification_step = opts.font_magnification_step
     self.wheel_flips_pages = opts.wheel_flips_pages
     self.line_scrolling_stops_on_pagebreaks = opts.line_scrolling_stops_on_pagebreaks
     screen_width = QApplication.desktop().screenGeometry().width()
     # Leave some space for the scrollbar and some border
     self.max_fs_width = min(opts.max_fs_width, screen_width - 50)
     self.fullscreen_clock = opts.fullscreen_clock
Esempio n. 8
0
    def __init__(self, parent):
        QWebPage.__init__(self, parent)
        settings = self.settings()
        apply_settings(settings, config().parse())
        settings.setMaximumPagesInCache(0)
        secure_web_page(settings)
        settings.setAttribute(settings.PrivateBrowsingEnabled, True)
        settings.setAttribute(settings.LinksIncludedInFocusChain, False)
        settings.setAttribute(settings.DeveloperExtrasEnabled, True)
        settings.setDefaultTextEncoding('utf-8')
        data = 'data:text/css;charset=utf-8;base64,'
        css = '[data-in-split-mode="1"] [data-is-block="1"]:hover { cursor: pointer !important; border-top: solid 5px green !important }'
        data += b64encode(css.encode('utf-8'))
        settings.setUserStyleSheetUrl(QUrl(data))

        self.setNetworkAccessManager(NetworkAccessManager(self))
        self.setLinkDelegationPolicy(self.DelegateAllLinks)
        self.mainFrame().javaScriptWindowObjectCleared.connect(self.init_javascript)
        self.init_javascript()
Esempio n. 9
0
    def __init__(self, parent):
        QWebPage.__init__(self, parent)
        settings = self.settings()
        apply_settings(settings, config().parse())
        settings.setMaximumPagesInCache(0)
        secure_web_page(settings)
        settings.setAttribute(settings.PrivateBrowsingEnabled, True)
        settings.setAttribute(settings.LinksIncludedInFocusChain, False)
        settings.setAttribute(settings.DeveloperExtrasEnabled, True)
        settings.setDefaultTextEncoding('utf-8')
        data = 'data:text/css;charset=utf-8;base64,'
        css = '[data-in-split-mode="1"] [data-is-block="1"]:hover { cursor: pointer !important; border-top: solid 5px green !important }'
        data += b64encode(css.encode('utf-8'))
        settings.setUserStyleSheetUrl(QUrl(data))

        self.setNetworkAccessManager(NetworkAccessManager(self))
        self.setLinkDelegationPolicy(self.DelegateAllLinks)
        self.mainFrame().javaScriptWindowObjectCleared.connect(self.init_javascript)
        self.init_javascript()
 def set_font_settings(self):
     opts = config().parse()
     settings = self.settings()
     settings.setFontSize(QWebSettings.DefaultFontSize,
                          opts.default_font_size)
     settings.setFontSize(QWebSettings.DefaultFixedFontSize,
                          opts.mono_font_size)
     settings.setFontSize(QWebSettings.MinimumLogicalFontSize, 8)
     settings.setFontSize(QWebSettings.MinimumFontSize, 8)
     settings.setFontFamily(
         QWebSettings.StandardFont, {
             'serif': opts.serif_family,
             'sans': opts.sans_family,
             'mono': opts.mono_family
         }[opts.standard_font])
     settings.setFontFamily(QWebSettings.SerifFont, opts.serif_family)
     settings.setFontFamily(QWebSettings.SansSerifFont, opts.sans_family)
     settings.setFontFamily(QWebSettings.FixedFont, opts.mono_family)
     settings.setAttribute(QWebSettings.ZoomTextOnly, True)
Esempio n. 11
0
    def __init__(self, parent=None):
        QWebView.__init__(self, parent)
        self.inspector = QWebInspector(self)
        w = QApplication.instance().desktop().availableGeometry(self).width()
        self._size_hint = QSize(int(w/3), int(w/2))
        settings = self.page().settings()
        apply_settings(settings, config().parse())
        settings.setMaximumPagesInCache(0)
        settings.setAttribute(settings.JavaEnabled, False)
        settings.setAttribute(settings.PluginsEnabled, False)
        settings.setAttribute(settings.PrivateBrowsingEnabled, True)
        settings.setAttribute(settings.JavascriptCanOpenWindows, False)
        settings.setAttribute(settings.JavascriptCanAccessClipboard, False)
        settings.setAttribute(settings.LinksIncludedInFocusChain, False)
        settings.setAttribute(settings.DeveloperExtrasEnabled, True)
        settings.setDefaultTextEncoding('utf-8')

        self.page().setNetworkAccessManager(NetworkAccessManager(self))
        self.page().setLinkDelegationPolicy(self.page().DelegateAllLinks)

        self.clear()
Esempio n. 12
0
 def do_config(self, parent=None):
     d = ConfigDialog(self.shortcuts, parent)
     if d.exec_() == QDialog.Accepted:
         opts = config().parse()
         self.apply_settings(opts)
Esempio n. 13
0
 def do_config(self, parent=None):
     d = ConfigDialog(self.shortcuts, parent)
     if d.exec_() == QDialog.Accepted:
         opts = config().parse()
         self.apply_settings(opts)
Esempio n. 14
0
 def set_user_stylesheet(self):
     raw = config().parse().user_css
     raw = '::selection {background:#ffff00; color:#000;}\nbody {background-color: white;}\n'+raw
     data = 'data:text/css;charset=utf-8;base64,'
     data += b64encode(raw.encode('utf-8'))
     self.settings().setUserStyleSheetUrl(QUrl(data))
 def set_user_stylesheet(self):
     raw = config().parse().user_css
     raw = '::selection {background:#ffff00; color:#000;}\nbody {background-color: white;}\n' + raw
     data = 'data:text/css;charset=utf-8;base64,'
     data += b64encode(raw.encode('utf-8'))
     self.settings().setUserStyleSheetUrl(QUrl(data))