Python 在混乱中使用BindConstraint约束参与者的大小

Python 在混乱中使用BindConstraint约束参与者的大小,python,c,gtk,clutter,Python,C,Gtk,Clutter,我最近在混乱中发现,但是,我找不到关于如何按比例约束参与者大小的信息。例如,我希望一个演员的宽度保持在另一个演员的1/2,比如说它的父母。它似乎只能强制宽度按源100%缩放。杂波。BindConstraint匹配源参与者的位置和/或维度属性。对于分数定位,您可以使用杂波.AlignConstraint,但没有允许您设置分数维属性的杂波.Constraint类。您可以实现自己的ClutterConstraint,方法是子类化Clutter.Constraint并重写Clutter.Constrai

我最近在混乱中发现,但是,我找不到关于如何按比例约束参与者大小的信息。例如,我希望一个演员的宽度保持在另一个演员的1/2,比如说它的父母。它似乎只能强制宽度按源100%缩放。

杂波。BindConstraint
匹配源参与者的位置和/或维度属性。对于分数定位,您可以使用
杂波.AlignConstraint
,但没有允许您设置分数维属性的
杂波.Constraint
类。您可以实现自己的
ClutterConstraint
,方法是子类化
Clutter.Constraint
并重写
Clutter.Constraint.do\u update\u allocation()
虚拟函数,该函数通过应由约束修改的参与者的分配。类似于此(未经测试)代码的东西应该可以工作:

class MyConstraint (Clutter.Constraint):
    def __init__(self, source, width_fraction=1.0, height_fraction=1.0):
        Clutter.Constraint.__init__(self)
        self._source = source
        self._widthf = width_fraction
        self._heightf = height_fraction
    def do_update_allocation(self, actor, allocation):
        source_alloc = self._source.get_allocation()
        width = source_alloc.get_width() * self._widthf
        height = source_alloc.get_height() * self._heightf
        allocation.x2 = allocation.x1 + width
        allocation.y2 = allocation.y1 + height
这应该说明
croot.Constraint
修改参与者分配所使用的机制