Example #1
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()
Example #2
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))
Example #3
0
    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 = min(size_hint.width(), self.width() - 2 * padding)
            left = (self.width() - width) // 2 if centered else 0

        height_padding = 20
        status_position = config.val.statusbar.position
        if status_position == 'bottom':
            if self.status.isVisible():
                status_height = self.status.height()
                bottom = self.status.geometry().top()
            else:
                status_height = 0
                bottom = self.height()
            top = self.height() - status_height - size_hint.height()
            top = qtutils.check_overflow(top, 'int', fatal=False)
            topleft = QPoint(left, max(height_padding, top))
            bottomright = QPoint(left + width, bottom)
        elif status_position == 'top':
            if self.status.isVisible():
                status_height = self.status.height()
                top = self.status.geometry().bottom()
            else:
                status_height = 0
                top = 0
            topleft = QPoint(left, top)
            bottom = 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)
    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)
Example #5
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:
                 frame = self._widget.page().mainFrame()
                 maximum = frame.scrollBarMaximum(orientation)
                 if maximum == 0:
                     continue
                 pos = int(maximum * val / 100)
                 pos = qtutils.check_overflow(pos, 'int', fatal=False)
                 frame.setScrollBarValue(orientation, pos)
Example #6
0
 def setInterval(self, msec):
     """Extend setInterval to check for overflows."""
     qtutils.check_overflow(msec, 'int')
     super().setInterval(msec)
Example #7
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)
Example #8
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
Example #9
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)
Example #10
0
 def test_good_values(self, ctype, val):
     """Test values which are inside bounds."""
     qtutils.check_overflow(val, ctype)