You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The << operator is great for putting expressions into the view. For instance if the model contains a property that is a floating point number, the view can decide how to format it and will automatically be updated.
But I would like to have the auto-update feature of subscription expressions in the model as well; there are derived calculations which depend on the raw model properties that should be managed by the model, not by the view.
Is there a way to do this?
example class:
class ItemWithQuantityDiscount(Atom):
quantity = Int()
basePrice = Float()
def getQuantityDiscount(self):
# some complicated formula goes here, depends on quantity
def getUnitPrice(self):
return self.basePrice * self.getQuantityDiscount()
and in the view I would like to have:
Label:
text << '${0:2f} each'.format(model.getUnitPrice())
Subscription. RHS can be any expression. The expression will be parsed for dependencies, and any dependency which is a trait attribute on a HasTraits class will have a listener attached. When the listener fires, the expression will be re-evaluated and the value of the view property will be updated.
The text was updated successfully, but these errors were encountered:
What you want is something like a dependent property. Traits has this in the form of the Property trait and cached properties. Atom also has something similar, though the dependency tracking is not provided for you. As it stands, I'm not happy with any of the existing dependent property behaviors and regret adding one to Atom. I have seen the pattern abused far too often where it leads to slow, unmaintainable code.
That said, there is value in a pattern like that, I just don't think dependent properties is the right way to go about it. I'll need to spend some time thinking about the right way to expose behavior like this, so it scales in an efficient manner.
In any case, this is an issue for Atom, not Enaml, so I will close this topic and ask that you open a new issue on the Atom tracker.
The
<<
operator is great for putting expressions into the view. For instance if the model contains a property that is a floating point number, the view can decide how to format it and will automatically be updated.But I would like to have the auto-update feature of subscription expressions in the model as well; there are derived calculations which depend on the raw model properties that should be managed by the model, not by the view.
Is there a way to do this?
example class:
and in the view I would like to have:
From http://docs.enthought.com/enaml/instructional/tut_hello_world.html (yeah, i know, that's the old enaml, but I couldn't find the new docs)
The text was updated successfully, but these errors were encountered: