Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Property not notified of changes in ReadOnly trait. #1735

Open
felixkol opened this issue Mar 2, 2023 · 0 comments
Open

[BUG] Property not notified of changes in ReadOnly trait. #1735

felixkol opened this issue Mar 2, 2023 · 0 comments

Comments

@felixkol
Copy link

felixkol commented Mar 2, 2023

Using a Property depending on a nested trait in a ReadOnly, the Property doesn't fire change events, when the nested trait changed.
However, an observe on this nested trait fires.

from traits.api import Float, HasTraits, Instance, Property, ReadOnly


class Data(HasTraits):
    x = Float(default_value=0.0)


class DataManager(HasTraits):
    dataA = Instance(Data)
    dataB = ReadOnly()

    ax_square = Property(observe="dataA.x")
    bx_square = Property(observe="dataB.x")

    def _get_ax_square(self):
        return self.dataA.x**2

    def _get_bx_square(self):
        return self.dataB.x**2


def main():
    d = Data()

    dm = DataManager(dataA=d, dataB=d)
    dm.observe(lambda x: print(f"dataA.x: {x}"), "dataA.x")
    dm.observe(lambda x: print(f"dataB.x: {x}"), "dataB.x")

    dm.observe(lambda x: print(f"ax_square: {x}"), "ax_square")
    dm.observe(lambda x: print(f"bx_square: {x}"), "bx_square")

    d.x = 2.0


if __name__ == "__main__":
    main()

yields the output:

ax_square: TraitChangeEvent(object=<__main__.DataManager object at 0x7fa9f7e87680>, name='ax_square', old=<undefined>, new=4.0)
dataA.x: TraitChangeEvent(object=<__main__.Data object at 0x7fa9f7e87220>, name='x', old=0.0, new=2.0)
dataB.x: TraitChangeEvent(object=<__main__.Data object at 0x7fa9f7e87220>, name='x', old=0.0, new=2.0)
@felixkol felixkol changed the title Property not notified of changes in ReadOnly trait. [BUG] Property not notified of changes in ReadOnly trait. May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant