force the update of a Property value

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

force the update of a Property value

Brennan Williams
I've forgotten how I can force the update of property's value.

e.g.

myvalue=Property()

def _get_myvalue(self):
    return ....

then later on I want to force the update of myvalue (but I don't want to
turn caching off as it is an operation on an array).

it's something to do with ...

self._myvalue

but I can't remember.

Brennan


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: force the update of a Property value

Peter Wang
Do you mean self.trait_property_changed("myvalue", oldvalue)?

-Peter

On Mon, Jan 10, 2011 at 8:59 PM, Brennan Williams
<[hidden email]> wrote:

> I've forgotten how I can force the update of property's value.
>
> e.g.
>
> myvalue=Property()
>
> def _get_myvalue(self):
>    return ....
>
> then later on I want to force the update of myvalue (but I don't want to
> turn caching off as it is an operation on an array).
>
> it's something to do with ...
>
> self._myvalue
>
> but I can't remember.
>
> Brennan
>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: force the update of a Property value

Brennan Williams
On 11/01/2011 4:08 p.m., Peter Wang wrote:
> Do you mean self.trait_property_changed("myvalue", oldvalue)?
>
No, but maybe I previously did it in an incorrect way. I'll give that a go.

BTW I have found that property traits that are displayed in a traits
view don't seem to (and I'm not sure whether this is always happening or
not) be updated - it looks like their values do change but this new
value is not displayed in the view. If I close the view and reopen it
then the new value appears. ???

Brennan

> -Peter
>
> On Mon, Jan 10, 2011 at 8:59 PM, Brennan Williams
> <[hidden email]>  wrote:
>> I've forgotten how I can force the update of property's value.
>>
>> e.g.
>>
>> myvalue=Property()
>>
>> def _get_myvalue(self):
>>     return ....
>>
>> then later on I want to force the update of myvalue (but I don't want to
>> turn caching off as it is an operation on an array).
>>
>> it's something to do with ...
>>
>> self._myvalue
>>
>> but I can't remember.
>>
>> Brennan
>>
>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: force the update of a Property value

Robert Kern
On Mon, Jan 10, 2011 at 9:32 PM, Brennan Williams
<[hidden email]> wrote:

> On 11/01/2011 4:08 p.m., Peter Wang wrote:
>> Do you mean self.trait_property_changed("myvalue", oldvalue)?
>>
> No, but maybe I previously did it in an incorrect way. I'll give that a go.
>
> BTW I have found that property traits that are displayed in a traits
> view don't seem to (and I'm not sure whether this is always happening or
> not) be updated - it looks like their values do change but this new
> value is not displayed in the view. If I close the view and reopen it
> then the new value appears. ???

Until something tells the UI that the Property's value has changed, it
doesn't know that it ought to update. If you close the view and reopen
it, that creates an entirely new UI, and it will request the current
value when it gets initialized.

BTW, if your my_value trait update is triggered by another trait's
change, you can avoid the .trait_property_changed() by just specifying
the dependency:

  my_value = Property(depends_on=['other_trait'])

--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: force the update of a Property value

Brennan Williams
On 11/01/2011 4:42 p.m., Robert Kern wrote:

> On Mon, Jan 10, 2011 at 9:32 PM, Brennan Williams
> <[hidden email]>  wrote:
>> On 11/01/2011 4:08 p.m., Peter Wang wrote:
>>> Do you mean self.trait_property_changed("myvalue", oldvalue)?
>>>
>> No, but maybe I previously did it in an incorrect way. I'll give that a go.
>>
>> BTW I have found that property traits that are displayed in a traits
>> view don't seem to (and I'm not sure whether this is always happening or
>> not) be updated - it looks like their values do change but this new
>> value is not displayed in the view. If I close the view and reopen it
>> then the new value appears. ???
> Until something tells the UI that the Property's value has changed, it
> doesn't know that it ought to update. If you close the view and reopen
> it, that creates an entirely new UI, and it will request the current
> value when it gets initialized.
>
How do I tell the view to update? I'm using TreeEditor so I have one
view for the whole window with the tree and then whatever is selected in
the tree has its own view in the pane on the rhs. So I suppose I somehow
need to get hold of the ui handle for that view? I've used ui.dispose()
before when closing a small dialog after performing some task. I presume
there is some sort of ui.refresh()?

> BTW, if your my_value trait update is triggered by another trait's
> change, you can avoid the .trait_property_changed() by just specifying
> the dependency:
>
>    my_value = Property(depends_on=['other_trait'])
>
Yes I've used that before although I keep forgetting it is a list and
not a string.



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: force the update of a Property value

Robert Kern
On Mon, Jan 10, 2011 at 9:51 PM, Brennan Williams
<[hidden email]> wrote:

> On 11/01/2011 4:42 p.m., Robert Kern wrote:
>> On Mon, Jan 10, 2011 at 9:32 PM, Brennan Williams
>> <[hidden email]>  wrote:
>>> On 11/01/2011 4:08 p.m., Peter Wang wrote:
>>>> Do you mean self.trait_property_changed("myvalue", oldvalue)?
>>>>
>>> No, but maybe I previously did it in an incorrect way. I'll give that a go.
>>>
>>> BTW I have found that property traits that are displayed in a traits
>>> view don't seem to (and I'm not sure whether this is always happening or
>>> not) be updated - it looks like their values do change but this new
>>> value is not displayed in the view. If I close the view and reopen it
>>> then the new value appears. ???
>> Until something tells the UI that the Property's value has changed, it
>> doesn't know that it ought to update. If you close the view and reopen
>> it, that creates an entirely new UI, and it will request the current
>> value when it gets initialized.
>>
> How do I tell the view to update?

.trait_property_changed(). The UI listens to the notification messages
for the traits it is editing and updates when it is told that the
traits do. You don't need to tell the view to update specifically.

--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev