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)),
)
评论列表
文章目录