def _update_overlay_geometry(self, widget, centered, padding):
        """Reposition/resize the given overlay."""
        if not widget.isVisible():
            return

        size_hint = widget.sizeHint()
        if widget.sizePolicy().horizontalPolicy() == QSizePolicy.Expanding:
            width = self.width() - 2 * padding
            left = padding
        else:
            width = size_hint.width()
            left = (self.width() - size_hint.width()) / 2 if centered else 0

        height_padding = 20
        status_position = config.get('ui', 'status-position')
        if status_position == 'bottom':
            top = self.height() - self.status.height() - size_hint.height()
            top = qtutils.check_overflow(top, 'int', fatal=False)
            topleft = QPoint(left, max(height_padding, top))
            bottomright = QPoint(left + width, self.status.geometry().top())
        elif status_position == 'top':
            topleft = QPoint(left, self.status.geometry().bottom())
            bottom = self.status.height() + size_hint.height()
            bottom = qtutils.check_overflow(bottom, 'int', fatal=False)
            bottomright = QPoint(left + width,
                                 min(self.height() - height_padding, bottom))
        else:
            raise ValueError("Invalid position {}!".format(status_position))

        rect = QRect(topleft, bottomright)
        log.misc.debug('new geometry for {!r}: {}'.format(widget, rect))
        if rect.isValid():
            widget.setGeometry(rect)
Beispiel #2
0
 def start(self, msec=None):
     """Extend start to check for overflows."""
     if msec is not None:
         qtutils.check_overflow(msec, 'int')
         super().start(msec)
     else:
         super().start()
Beispiel #3
0
 def test_bad_values_fatal(self):
     """Test values which are outside bounds with fatal=True."""
     for ctype, vals in self.BAD_VALUES.items():
         for (val, _) in vals:
             with self.subTest(ctype=ctype, val=val):
                 with self.assertRaises(OverflowError):
                     qtutils.check_overflow(val, ctype)
Beispiel #4
0
def check_overflow(arg, ctype):
    """Check if the given argument is in bounds for the given type.

    Args:
        arg: The argument to check
        ctype: The C/Qt type to check as a string.
    """
    try:
        qtutils.check_overflow(arg, ctype)
    except OverflowError:
        raise cmdexc.CommandError("Numeric argument is too large for internal {} " "representation.".format(ctype))
Beispiel #5
0
def check_overflow(arg: int, ctype: str) -> None:
    """Check if the given argument is in bounds for the given type.

    Args:
        arg: The argument to check.
        ctype: The C++/Qt type to check as a string ('int'/'int64').
    """
    try:
        qtutils.check_overflow(arg, ctype)
    except OverflowError:
        raise CommandError("Numeric argument is too large for internal {} "
                           "representation.".format(ctype))
Beispiel #6
0
 def _get_overlay_position(self, height):
     """Get the position for a full-width overlay with the given height."""
     status_position = config.get('ui', 'status-position')
     if status_position == 'bottom':
         top = self.height() - self.status.height() - height
         top = qtutils.check_overflow(top, 'int', fatal=False)
         topleft = QPoint(0, top)
         bottomright = self.status.geometry().topRight()
     elif status_position == 'top':
         topleft = self.status.geometry().bottomLeft()
         bottom = self.status.height() + height
         bottom = qtutils.check_overflow(bottom, 'int', fatal=False)
         bottomright = QPoint(self.width(), bottom)
     else:
         raise ValueError("Invalid position {}!".format(status_position))
     return QRect(topleft, bottomright)
Beispiel #7
0
 def resize_completion(self):
     """Adjust completion according to config."""
     if not self._completion.isVisible():
         # It doesn't make sense to resize the completion as long as it's
         # not shown anyways.
         return
     # Get the configured height/percentage.
     confheight = str(config.get("completion", "height"))
     if confheight.endswith("%"):
         perc = int(confheight.rstrip("%"))
         height = self.height() * perc / 100
     else:
         height = int(confheight)
     # Shrink to content size if needed and shrinking is enabled
     if config.get("completion", "shrink"):
         contents_height = (
             self._completion.viewportSizeHint().height()
             + self._completion.horizontalScrollBar().sizeHint().height()
         )
         if contents_height <= height:
             height = contents_height
     else:
         contents_height = -1
     # hpoint now would be the bottom-left edge of the widget if it was on
     # the top of the main window.
     topleft_y = self.height() - self.status.height() - height
     topleft_y = qtutils.check_overflow(topleft_y, "int", fatal=False)
     topleft = QPoint(0, topleft_y)
     bottomright = self.status.geometry().topRight()
     rect = QRect(topleft, bottomright)
     log.misc.debug("completion rect: {}".format(rect))
     if rect.isValid():
         self._completion.setGeometry(rect)
Beispiel #8
0
 def resize_completion(self):
     """Adjust completion according to config."""
     # Get the configured height/percentage.
     confheight = str(config.get('completion', 'height'))
     if confheight.endswith('%'):
         perc = int(confheight.rstrip('%'))
         height = self.height() * perc / 100
     else:
         height = int(confheight)
     # Shrink to content size if needed and shrinking is enabled
     if config.get('completion', 'shrink'):
         contents_height = (
             self._completion.viewportSizeHint().height() +
             self._completion.horizontalScrollBar().sizeHint().height())
         if contents_height <= height:
             height = contents_height
     else:
         contents_height = -1
     # hpoint now would be the bottom-left edge of the widget if it was on
     # the top of the main window.
     topleft_y = self.height() - self.status.height() - height
     topleft_y = qtutils.check_overflow(topleft_y, 'int', fatal=False)
     topleft = QPoint(0, topleft_y)
     bottomright = self.status.geometry().topRight()
     rect = QRect(topleft, bottomright)
     if rect.isValid():
         self._completion.setGeometry(rect)
Beispiel #9
0
 def test_bad_values_nonfatal(self):
     """Test values which are outside bounds with fatal=False."""
     for ctype, vals in self.BAD_VALUES.items():
         for (val, replacement) in vals:
             with self.subTest(ctype=ctype, val=val):
                 newval = qtutils.check_overflow(val, ctype, fatal=False)
                 self.assertEqual(newval, replacement)
Beispiel #10
0
def check_overflow(arg, ctype):
    """Check if the given argument is in bounds for the given type.

    Args:
        arg: The argument to check
        ctype: The C/Qt type to check as a string.

    Raise:
        CommandError if the argument is out of bounds.
        ValueError if the given ctype is unknown.
    """
    # FIXME we somehow should have nicer exceptions...
    try:
        qtutils.check_overflow(arg, ctype)
    except OverflowError:
        raise cmdexc.CommandError(
            "Numeric argument is too large for internal {} "
            "representation.".format(ctype))
    def set_http_cache_size(self):
        """Initialize the HTTP cache size for the given profile."""
        size = config.val.content.cache.size
        if size is None:
            size = 0
        else:
            size = qtutils.check_overflow(size, 'int', fatal=False)

        # 0: automatically managed by QtWebEngine
        self._profile.setHttpCacheMaximumSize(size)
Beispiel #12
0
 def resize_completion(self):
     """Adjust completion according to config."""
     if not self._completion.isVisible():
         # It doesn't make sense to resize the completion as long as it's
         # not shown anyways.
         return
     # Get the configured height/percentage.
     confheight = str(config.get('completion', 'height'))
     if confheight.endswith('%'):
         perc = int(confheight.rstrip('%'))
         height = self.height() * perc / 100
     else:
         height = int(confheight)
     # Shrink to content size if needed and shrinking is enabled
     if config.get('completion', 'shrink'):
         contents_height = (
             self._completion.viewportSizeHint().height() +
             self._completion.horizontalScrollBar().sizeHint().height())
         if contents_height <= height:
             height = contents_height
     else:
         contents_height = -1
     status_position = config.get('ui', 'status-position')
     if status_position == 'bottom':
         top = self.height() - self.status.height() - height
         top = qtutils.check_overflow(top, 'int', fatal=False)
         topleft = QPoint(0, top)
         bottomright = self.status.geometry().topRight()
     elif status_position == 'top':
         topleft = self.status.geometry().bottomLeft()
         bottom = self.status.height() + height
         bottom = qtutils.check_overflow(bottom, 'int', fatal=False)
         bottomright = QPoint(self.width(), bottom)
     else:
         raise ValueError("Invalid position {}!".format(status_position))
     rect = QRect(topleft, bottomright)
     log.misc.debug('completion rect: {}'.format(rect))
     if rect.isValid():
         self._completion.setGeometry(rect)
Beispiel #13
0
 def to_perc(self, x=None, y=None):
     if x is None and y == 0:
         self.top()
     elif x is None and y == 100:
         self.bottom()
     else:
         for val, orientation in [(x, Qt.Horizontal), (y, Qt.Vertical)]:
             if val is not None:
                 val = qtutils.check_overflow(val, 'int', fatal=False)
                 frame = self._widget.page().mainFrame()
                 m = frame.scrollBarMaximum(orientation)
                 if m == 0:
                     continue
                 frame.setScrollBarValue(orientation, int(m * val / 100))
Beispiel #14
0
    def _update_overlay_geometry(self, widget=None):
        """Reposition/resize the given overlay.

        If no widget is given, reposition/resize all overlays.
        """
        if widget is None:
            for w, _signal in self._overlays:
                self._update_overlay_geometry(w)
            return

        if not widget.isVisible():
            return

        size_hint = widget.sizeHint()
        if widget.sizePolicy().horizontalPolicy() == QSizePolicy.Expanding:
            width = self.width()
        else:
            width = size_hint.width()

        status_position = config.get("ui", "status-position")
        if status_position == "bottom":
            top = self.height() - self.status.height() - size_hint.height()
            top = qtutils.check_overflow(top, "int", fatal=False)
            topleft = QPoint(0, top)
            bottomright = QPoint(width, self.status.geometry().top())
        elif status_position == "top":
            topleft = self.status.geometry().bottomLeft()
            bottom = self.status.height() + size_hint.height()
            bottom = qtutils.check_overflow(bottom, "int", fatal=False)
            bottomright = QPoint(width, bottom)
        else:
            raise ValueError("Invalid position {}!".format(status_position))

        rect = QRect(topleft, bottomright)
        log.misc.debug("new geometry for {!r}: {}".format(widget, rect))
        if rect.isValid():
            widget.setGeometry(rect)
Beispiel #15
0
 def reposition_keyhint(self):
     """Adjust keyhint according to config."""
     if not self._keyhint.isVisible():
         return
     # Shrink the window to the shown text and place it at the bottom left
     width = self._keyhint.width()
     height = self._keyhint.height()
     topleft_y = self.height() - self.status.height() - height
     topleft_y = qtutils.check_overflow(topleft_y, "int", fatal=False)
     topleft = QPoint(0, topleft_y)
     bottomright = self.status.geometry().topLeft() + QPoint(width, 0)
     rect = QRect(topleft, bottomright)
     log.misc.debug("keyhint rect: {}".format(rect))
     if rect.isValid():
         self._keyhint.setGeometry(rect)
Beispiel #16
0
    def _scroll_percent(self, perc=None, count=None, orientation=None):
        """Inner logic for scroll_percent_(x|y).

        Args:
            perc: How many percent to scroll, or None
            count: How many percent to scroll, or None
            orientation: Qt.Horizontal or Qt.Vertical
        """
        if perc is None and count is None:
            perc = 100
        elif perc is None:
            perc = count
        perc = qtutils.check_overflow(perc, 'int', fatal=False)
        frame = self._current_widget().page().currentFrame()
        m = frame.scrollBarMaximum(orientation)
        if m == 0:
            return
        frame.setScrollBarValue(orientation, int(m * perc / 100))
Beispiel #17
0
 def test_good_values(self, ctype, val):
     """Test values which are inside bounds."""
     qtutils.check_overflow(val, ctype)
 'content.hyperlink_auditing':
 Attribute(QWebEngineSettings.HyperlinkAuditingEnabled),
 'content.local_content_can_access_remote_urls':
 Attribute(QWebEngineSettings.LocalContentCanAccessRemoteUrls),
 'content.local_content_can_access_file_urls':
 Attribute(QWebEngineSettings.LocalContentCanAccessFileUrls),
 'content.webgl':
 Attribute(QWebEngineSettings.WebGLEnabled),
 'content.local_storage':
 Attribute(QWebEngineSettings.LocalStorageEnabled),
 'content.cache.size':
 # 0: automatically managed by QtWebEngine
 DefaultProfileSetter(
     'setHttpCacheMaximumSize',
     default=0,
     converter=lambda val: qtutils.check_overflow(val, 'int', fatal=False)),
 'content.xss_auditing':
 Attribute(QWebEngineSettings.XSSAuditingEnabled),
 'content.default_encoding':
 Setter(QWebEngineSettings.setDefaultTextEncoding),
 'input.spatial_navigation':
 Attribute(QWebEngineSettings.SpatialNavigationEnabled),
 'input.links_included_in_focus_chain':
 Attribute(QWebEngineSettings.LinksIncludedInFocusChain),
 'fonts.web.family.standard':
 FontFamilySetter(QWebEngineSettings.StandardFont),
 'fonts.web.family.fixed':
 FontFamilySetter(QWebEngineSettings.FixedFont),
 'fonts.web.family.serif':
 FontFamilySetter(QWebEngineSettings.SerifFont),
 'fonts.web.family.sans_serif':
        Attribute(QWebEngineSettings.PluginsEnabled),
    'content.hyperlink_auditing':
        Attribute(QWebEngineSettings.HyperlinkAuditingEnabled),
    'content.local_content_can_access_remote_urls':
        Attribute(QWebEngineSettings.LocalContentCanAccessRemoteUrls),
    'content.local_content_can_access_file_urls':
        Attribute(QWebEngineSettings.LocalContentCanAccessFileUrls),
    'content.webgl':
        Attribute(QWebEngineSettings.WebGLEnabled),
    'content.local_storage':
        Attribute(QWebEngineSettings.LocalStorageEnabled),
    'content.cache.size':
        # 0: automatically managed by QtWebEngine
        DefaultProfileSetter('setHttpCacheMaximumSize', default=0,
                             converter=lambda val:
                             qtutils.check_overflow(val, 'int', fatal=False)),
    'content.xss_auditing':
        Attribute(QWebEngineSettings.XSSAuditingEnabled),
    'content.default_encoding':
        Setter(QWebEngineSettings.setDefaultTextEncoding),

    'input.spatial_navigation':
        Attribute(QWebEngineSettings.SpatialNavigationEnabled),
    'input.links_included_in_focus_chain':
        Attribute(QWebEngineSettings.LinksIncludedInFocusChain),

    'fonts.web.family.standard':
        FontFamilySetter(QWebEngineSettings.StandardFont),
    'fonts.web.family.fixed':
        FontFamilySetter(QWebEngineSettings.FixedFont),
    'fonts.web.family.serif':
Beispiel #20
0
 def test_bad_values_fatal(self, ctype, val):
     """Test values which are outside bounds with fatal=True."""
     with pytest.raises(OverflowError):
         qtutils.check_overflow(val, ctype)
Beispiel #21
0
 def test_good_values(self):
     """Test values which are inside bounds."""
     for ctype, vals in self.GOOD_VALUES.items():
         for val in vals:
             with self.subTest(ctype=ctype, val=val):
                 qtutils.check_overflow(val, ctype)
Beispiel #22
0
 def setInterval(self, msec):
     """Extend setInterval to check for overflows."""
     qtutils.check_overflow(msec, 'int')
     super().setInterval(msec)
Beispiel #23
0
 def test_bad_values_nonfatal(self, ctype, val, repl):
     """Test values which are outside bounds with fatal=False."""
     newval = qtutils.check_overflow(val, ctype, fatal=False)
     assert newval == repl
Beispiel #24
0
 def test_bad_values_fatal(self, ctype, val):
     """Test values which are outside bounds with fatal=True."""
     with pytest.raises(OverflowError):
         qtutils.check_overflow(val, ctype)
Beispiel #25
0
 def test_good_values(self, ctype, val):
     """Test values which are inside bounds."""
     qtutils.check_overflow(val, ctype)
Beispiel #26
0
 def delta(self, x=0, y=0):
     qtutils.check_overflow(x, 'int')
     qtutils.check_overflow(y, 'int')
     self._widget.page().mainFrame().scroll(x, y)
Beispiel #27
0
 def test_bad_values_nonfatal(self, ctype, val, repl):
     """Test values which are outside bounds with fatal=False."""
     newval = qtutils.check_overflow(val, ctype, fatal=False)
     assert newval == repl
Beispiel #28
0
 def delta(self, x=0, y=0):
     qtutils.check_overflow(x, 'int')
     qtutils.check_overflow(y, 'int')
     self._widget.page().mainFrame().scroll(x, y)
Beispiel #29
0
 def setInterval(self, msec):
     """Extend setInterval to check for overflows."""
     qtutils.check_overflow(msec, 'int')
     super().setInterval(msec)
Beispiel #30
0
 def test_good_values(self):
     """Test values which are inside bounds."""
     for ctype, vals in self.GOOD_VALUES.items():
         for val in vals:
             with self.subTest(ctype=ctype, val=val):
                 qtutils.check_overflow(val, ctype)