• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.compact_text函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qutebrowser.utils.utils.compact_text函数的典型用法代码示例。如果您正苦于以下问题:Python compact_text函数的具体用法?Python compact_text怎么用?Python compact_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了compact_text函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: format_args

def format_args(args=None, kwargs=None):
    """Format a list of arguments/kwargs to a function-call like string."""
    if args is not None:
        arglist = [utils.compact_text(repr(arg), 200) for arg in args]
    else:
        arglist = []
    if kwargs is not None:
        for k, v in kwargs.items():
            arglist.append('{}={}'.format(k, utils.compact_text(repr(v), 200)))
    return ', '.join(arglist)
开发者ID:blyxxyz,项目名称:qutebrowser,代码行数:10,代码来源:debug.py


示例2: _rect_on_view_js

    def _rect_on_view_js(self, adjust_zoom):
        """Javascript implementation for rect_on_view."""
        rects = self._elem.evaluateJavaScript("this.getClientRects()")
        if rects is None:  # pragma: no cover
            # Depending on unknown circumstances, this might not work with JS
            # disabled in QWebSettings:
            # https://github.com/The-Compiler/qutebrowser/issues/1641
            return None

        text = utils.compact_text(self._elem.toOuterXml(), 500)
        log.hints.vdebug("Client rectangles of element '{}': {}".format(
            text, rects))

        for i in range(int(rects.get("length", 0))):
            rect = rects[str(i)]
            width = rect.get("width", 0)
            height = rect.get("height", 0)
            if width > 1 and height > 1:
                # fix coordinates according to zoom level
                zoom = self._elem.webFrame().zoomFactor()
                if not config.get('ui', 'zoom-text-only') and adjust_zoom:
                    rect["left"] *= zoom
                    rect["top"] *= zoom
                    width *= zoom
                    height *= zoom
                rect = QRect(rect["left"], rect["top"], width, height)
                frame = self._elem.webFrame()
                while frame is not None:
                    # Translate to parent frames' position (scroll position
                    # is taken care of inside getClientRects)
                    rect.translate(frame.geometry().topLeft())
                    frame = frame.parentFrame()
                return rect

        return None
开发者ID:LadyClaire,项目名称:qutebrowser,代码行数:35,代码来源:webelem.py


示例3: trace

    def trace(frame, event, arg):
        """Trace function passed to sys.settrace.

        Return:
            Itself, so tracing continues.
        """
        if sys is not None:
            loc = '{}:{}'.format(frame.f_code.co_filename, frame.f_lineno)
            if arg is not None:
                arg = utils.compact_text(str(arg), 200)
            else:
                arg = ''
            print("{:11} {:80} {}".format(event, loc, arg), file=sys.stderr)
            return trace
        else:
            # When tracing while shutting down, it seems sys can be None
            # sometimes... if that's the case, we stop tracing.
            return None
开发者ID:HalosGhost,项目名称:qutebrowser,代码行数:18,代码来源:debug.py


示例4: _rect_on_view_js

    def _rect_on_view_js(self):
        """Javascript implementation for rect_on_view."""
        # FIXME:qtwebengine maybe we can reuse this?
        rects = self._elem.evaluateJavaScript("this.getClientRects()")
        if rects is None:  # pragma: no cover
            # On e.g. Void Linux with musl libc, the stack size is too small
            # for jsc, and running JS will fail. If that happens, fall back to
            # the Python implementation.
            # https://github.com/qutebrowser/qutebrowser/issues/1641
            return None

        text = utils.compact_text(self._elem.toOuterXml(), 500)
        log.webelem.vdebug("Client rectangles of element '{}': {}".format(
            text, rects))

        for i in range(int(rects.get("length", 0))):
            rect = rects[str(i)]
            width = rect.get("width", 0)
            height = rect.get("height", 0)
            if width > 1 and height > 1:
                # fix coordinates according to zoom level
                zoom = self._elem.webFrame().zoomFactor()
                if not config.get('ui', 'zoom-text-only'):
                    rect["left"] *= zoom
                    rect["top"] *= zoom
                    width *= zoom
                    height *= zoom
                rect = QRect(rect["left"], rect["top"], width, height)
                frame = self._elem.webFrame()
                while frame is not None:
                    # Translate to parent frames' position (scroll position
                    # is taken care of inside getClientRects)
                    rect.translate(frame.geometry().topLeft())
                    frame = frame.parentFrame()
                return rect

        return None
开发者ID:michaelbeaumont,项目名称:qutebrowser,代码行数:37,代码来源:webkitelem.py


示例5: debug_text

 def debug_text(self):
     """Get a text based on an element suitable for debug output."""
     return utils.compact_text(self.outer_xml(), 500)
开发者ID:julianuu,项目名称:qutebrowser,代码行数:3,代码来源:webelem.py


示例6: debug_text

 def debug_text(self):
     """Get a text based on an element suitable for debug output."""
     self._check_vanished()
     return utils.compact_text(self._elem.toOuterXml(), 500)
开发者ID:axs221,项目名称:qutebrowser,代码行数:4,代码来源:webelem.py


示例7: rect_on_view

    def rect_on_view(self, *, elem_geometry=None, adjust_zoom=True,
                     no_js=False):
        """Get the geometry of the element relative to the webview.

        Uses the getClientRects() JavaScript method to obtain the collection of
        rectangles containing the element and returns the first rectangle which
        is large enough (larger than 1px times 1px). If all rectangles returned
        by getClientRects() are too small, falls back to elem.rect_on_view().

        Skipping of small rectangles is due to <a> elements containing other
        elements with "display:block" style, see
        https://github.com/The-Compiler/qutebrowser/issues/1298

        Args:
            elem_geometry: The geometry of the element, or None.
                           Calling QWebElement::geometry is rather expensive so
                           we want to avoid doing it twice.
            adjust_zoom: Whether to adjust the element position based on the
                         current zoom level.
            no_js: Fall back to the Python implementation
        """
        self._check_vanished()

        # First try getting the element rect via JS, as that's usually more
        # accurate
        if elem_geometry is None and not no_js:
            rects = self._elem.evaluateJavaScript("this.getClientRects()")
            text = utils.compact_text(self._elem.toOuterXml(), 500)
            log.hints.vdebug("Client rectangles of element '{}': {}".format(
                text, rects))
            for i in range(int(rects.get("length", 0))):
                rect = rects[str(i)]
                width = rect.get("width", 0)
                height = rect.get("height", 0)
                if width > 1 and height > 1:
                    # fix coordinates according to zoom level
                    zoom = self._elem.webFrame().zoomFactor()
                    if not config.get('ui', 'zoom-text-only') and adjust_zoom:
                        rect["left"] *= zoom
                        rect["top"] *= zoom
                        width *= zoom
                        height *= zoom
                    rect = QRect(rect["left"], rect["top"], width, height)
                    frame = self._elem.webFrame()
                    while frame is not None:
                        # Translate to parent frames' position (scroll position
                        # is taken care of inside getClientRects)
                        rect.translate(frame.geometry().topLeft())
                        frame = frame.parentFrame()
                    return rect

        # No suitable rects found via JS, try via the QWebElement API
        if elem_geometry is None:
            geometry = self._elem.geometry()
        else:
            geometry = elem_geometry
        frame = self._elem.webFrame()
        rect = QRect(geometry)
        while frame is not None:
            rect.translate(frame.geometry().topLeft())
            rect.translate(frame.scrollPosition() * -1)
            frame = frame.parentFrame()
        # We deliberately always adjust the zoom here, even with
        # adjust_zoom=False
        if elem_geometry is None:
            zoom = self._elem.webFrame().zoomFactor()
            if not config.get('ui', 'zoom-text-only'):
                rect.moveTo(rect.left() / zoom, rect.top() / zoom)
                rect.setWidth(rect.width() / zoom)
                rect.setHeight(rect.height() / zoom)
        return rect
开发者ID:Swoorup,项目名称:qutebrowser,代码行数:71,代码来源:webelem.py


示例8: __repr__

 def __repr__(self):
     try:
         html = utils.compact_text(self.outer_xml(), 500)
     except Error:
         html = None
     return utils.get_repr(self, html=html)
开发者ID:tlplu,项目名称:qutebrowser,代码行数:6,代码来源:webelem.py



注:本文中的qutebrowser.utils.utils.compact_text函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.elide函数代码示例发布时间:2022-05-26
下一篇:
Python usertypes.enum函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap