updating the data in an ArrayViewEditor

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

updating the data in an ArrayViewEditor

Brennan Williams
I have a view that is in a tree editor. The view contains amongst other
things two columns of x,y data display as as an array of shape (n,2) in
an ArrayViewEditor.

If I change the array (i.e. completely recreate it with new data) then I
can't get the view of the data to update even if I resize the
window/group it is in (part of an HSplit with a plot of the data to the
rhs of the array view).

If I change the data in the array, e.g. using something like...

def updatexyarray(self):
    print 'updatexyarray'
    xlist=self.xarray1d.tolist()
    vlist=self.yarray1d.tolist()
    for index,t in enumerate(xlist):
      v=vlist[index]
      self.xyarray[index,0]=t
      self.xyarray[index,1]=v

then I can get the view of the data to update but only if I resize the
window/group it is in so it refreshes.

I'd like to have both the plot and array view updating automatically as
I change the data. What's the best way for me to do that? Something
other than ArrayViewEditor?

Brennan


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

Re: updating the data in an ArrayViewEditor

Robert Kern
On Wed, Mar 24, 2010 at 3:48 PM, Brennan Williams
<[hidden email]> wrote:

> I have a view that is in a tree editor. The view contains amongst other
> things two columns of x,y data display as as an array of shape (n,2) in
> an ArrayViewEditor.
>
> If I change the array (i.e. completely recreate it with new data) then I
> can't get the view of the data to update even if I resize the
> window/group it is in (part of an HSplit with a plot of the data to the
> rhs of the array view).
>
> If I change the data in the array, e.g. using something like...
>
> def updatexyarray(self):
>    print 'updatexyarray'
>    xlist=self.xarray1d.tolist()
>    vlist=self.yarray1d.tolist()
>    for index,t in enumerate(xlist):
>      v=vlist[index]
>      self.xyarray[index,0]=t
>      self.xyarray[index,1]=v
>
> then I can get the view of the data to update but only if I resize the
> window/group it is in so it refreshes.
>
> I'd like to have both the plot and array view updating automatically as
> I change the data. What's the best way for me to do that? Something
> other than ArrayViewEditor?

Use the comparison_mode=NO_COMPARE trait metadata, then you can assign
the attribute to itself after you have modified it in-place in order
to trigger the appropriate trait change notifications.


import numpy as np

from enthought.traits.api import Array, HasTraits, NO_COMPARE

class Klass(HasTraits):
    anarray = Array(comparison_mode = NO_COMPARE)

    def _anarray_changed(self):
        print 'Array changed!'

k = Klass()
k.anarray = np.ones(5)
k.anarray = k.anarray


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: updating the data in an ArrayViewEditor

Brennan Williams
Robert Kern wrote:

> On Wed, Mar 24, 2010 at 3:48 PM, Brennan Williams
> <[hidden email]> wrote:
>  
>> I have a view that is in a tree editor. The view contains amongst other
>> things two columns of x,y data display as as an array of shape (n,2) in
>> an ArrayViewEditor.
>>
>> If I change the array (i.e. completely recreate it with new data) then I
>> can't get the view of the data to update even if I resize the
>> window/group it is in (part of an HSplit with a plot of the data to the
>> rhs of the array view).
>>
>> If I change the data in the array, e.g. using something like...
>>
>> def updatexyarray(self):
>>    print 'updatexyarray'
>>    xlist=self.xarray1d.tolist()
>>    vlist=self.yarray1d.tolist()
>>    for index,t in enumerate(xlist):
>>      v=vlist[index]
>>      self.xyarray[index,0]=t
>>      self.xyarray[index,1]=v
>>
>> then I can get the view of the data to update but only if I resize the
>> window/group it is in so it refreshes.
>>
>> I'd like to have both the plot and array view updating automatically as
>> I change the data. What's the best way for me to do that? Something
>> other than ArrayViewEditor?
>>    
>
> Use the comparison_mode=NO_COMPARE trait metadata, then you can assign
> the attribute to itself after you have modified it in-place in order
> to trigger the appropriate trait change notifications.
>
>
> import numpy as np
>
> from enthought.traits.api import Array, HasTraits, NO_COMPARE
>
> class Klass(HasTraits):
>     anarray = Array(comparison_mode = NO_COMPARE)
>
>     def _anarray_changed(self):
>         print 'Array changed!'
>
> k = Klass()
> k.anarray = np.ones(5)
> k.anarray = k.anarray
>
>
>  
Great. Thanks.Worked first time (well second time after I remembered to
add NO_COMPARE to my import).

Doing a google on "Array NO_COMPARE" I found...

http://code.enthought.com/projects/files/ETS31_API/enthought.traits.tests.test_events.html

and I see that in addition to NO_COMPARE there are also
OBJECT_IDENTITY_COMPARE and RICH_COMPARE.
What exactly do these do and how do they differ?

Brennan





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

Re: updating the data in an ArrayViewEditor

Robert Kern
On Wed, Mar 24, 2010 at 4:35 PM, Brennan Williams
<[hidden email]> wrote:

> Robert Kern wrote:
>> On Wed, Mar 24, 2010 at 3:48 PM, Brennan Williams
>> <[hidden email]> wrote:
>>
>>> I have a view that is in a tree editor. The view contains amongst other
>>> things two columns of x,y data display as as an array of shape (n,2) in
>>> an ArrayViewEditor.
>>>
>>> If I change the array (i.e. completely recreate it with new data) then I
>>> can't get the view of the data to update even if I resize the
>>> window/group it is in (part of an HSplit with a plot of the data to the
>>> rhs of the array view).
>>>
>>> If I change the data in the array, e.g. using something like...
>>>
>>> def updatexyarray(self):
>>>    print 'updatexyarray'
>>>    xlist=self.xarray1d.tolist()
>>>    vlist=self.yarray1d.tolist()
>>>    for index,t in enumerate(xlist):
>>>      v=vlist[index]
>>>      self.xyarray[index,0]=t
>>>      self.xyarray[index,1]=v
>>>
>>> then I can get the view of the data to update but only if I resize the
>>> window/group it is in so it refreshes.
>>>
>>> I'd like to have both the plot and array view updating automatically as
>>> I change the data. What's the best way for me to do that? Something
>>> other than ArrayViewEditor?
>>>
>>
>> Use the comparison_mode=NO_COMPARE trait metadata, then you can assign
>> the attribute to itself after you have modified it in-place in order
>> to trigger the appropriate trait change notifications.
>>
>>
>> import numpy as np
>>
>> from enthought.traits.api import Array, HasTraits, NO_COMPARE
>>
>> class Klass(HasTraits):
>>     anarray = Array(comparison_mode = NO_COMPARE)
>>
>>     def _anarray_changed(self):
>>         print 'Array changed!'
>>
>> k = Klass()
>> k.anarray = np.ones(5)
>> k.anarray = k.anarray
>>
>>
>>
> Great. Thanks.Worked first time (well second time after I remembered to
> add NO_COMPARE to my import).
>
> Doing a google on "Array NO_COMPARE" I found...
>
> http://code.enthought.com/projects/files/ETS31_API/enthought.traits.tests.test_events.html
>
> and I see that in addition to NO_COMPARE there are also
> OBJECT_IDENTITY_COMPARE and RICH_COMPARE.
> What exactly do these do and how do they differ?

OBJECT_IDENTITY compares by object identity. RICH_COMPARE is a bit of
a misnomer as it does not actually use rich comparisons. It uses the
standard C API for doing the __eq__ comparison and then casts the
result to a bool. The name derives from the name of the C API function
used.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev