utils.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:transpyler 作者: Transpyler 项目源码 文件源码
def qtproperty(name, unwrap=lambda x: x, wrap=lambda x: x):
    """
    Expose a property of an attribute that respects Qt's get/setter
    conventions.

    If transform is defined, it is applied to the value passed to the setter
    method.

    Example::

        class MyObj:
            title = qtproperty('_widget.title')
    """

    prop, action = name.split('.')
    set_name = '%s.set%s' % (prop, action.title())
    getter = op.attrgetter(name)
    setter = op.attrgetter(set_name)
    return property(
        lambda x: unwrap(getter(x)()),
        lambda x, v: setter(x)(wrap(v)),
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号