本文整理汇总了Python中qutebrowser.utils.qtutils.check_overflow函数的典型用法代码示例。如果您正苦于以下问题:Python check_overflow函数的具体用法?Python check_overflow怎么用?Python check_overflow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_overflow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bad_values_fatal
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)
示例2: start
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()
示例3: _update_overlay_geometry
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)
示例4: check_overflow
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))
示例5: check_overflow
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))
示例6: _get_overlay_position
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)
示例7: resize_completion
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)
示例8: test_bad_values_nonfatal
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)
示例9: resize_completion
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)
示例10: check_overflow
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))
示例11: set_http_cache_size
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)
示例12: resize_completion
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)
示例13: to_perc
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))
示例14: _update_overlay_geometry
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)
示例15: reposition_keyhint
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)