Change Range Trait after initialization

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

Change Range Trait after initialization

Alexander Kalinin
Hello!

Is it possible to change Range Trait high value after initialization? Look
at the code:

 class MapView(HasTraits):

frame = Range(1, 400, 1)

scene = Instance(MlabSceneModel, ())

 def __init__(self, mesh, f):

HasTraits.__init__(self)

 self.u = u

self.surf = self.scene.mlab.triangular_mesh(

mesh.v[:, 0], mesh.v[:, 1], mesh.v[:, 2], mesh.f,

scalars = f[:, 0])


# How to change Range high property, like this

# frame.high = u.shape[1]

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

Re: Change Range Trait after initialization

Robert Kern
On Thu, Mar 29, 2012 at 3:24 PM, Alexander Kalinin
<[hidden email]> wrote:
> Hello!
>
> Is it possible to change Range Trait high value after initialization?

class MapView(HasTraits):
    frame_low = Int(1)
    frame_high = Int(400)
    frame = Range(low='frame_low', high='frame_high', value=1)

    def __init__(self, mesh, f):
        ...
        self.frame_high = u.shape[1]

--
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: Change Range Trait after initialization

Alexander Kalinin
Thank you very much, Robert. It works!

Could you, please, explain me one more moment about drawing the scene. The
question is what is the right place to draw a scene? In __init__ method or
during processing the 'scene.activated' event. Look at the code.

class MapView(HasTraits):
    scene = Instance(MlabSceneModel, ())

    def __init__(self, mesh):
        HasTraits.__init__(self)

        # This is OK
        self.surf = self.scene.mlab.triangular_mesh(
            mesh.v[:, 0], mesh.v[:, 1], mesh.v[:, 2], mesh.f)

        # ERROR: The interactor must be set prior to enabling the widget
        #self.legend = self.scene.mlab.colorbar(
        #    orientation = 'vertical',
        #    nb_labels = 10, nb_colors = 10)

    @on_trait_change('scene.activated')
    def sceneActivated(self):
        # This is OK
        self.scene.mlab.colorbar(
            orientation = 'vertical',
            nb_labels = 10, nb_colors = 10)

The 'self.scene.mlab.triangular_mesh' works fine in __init__ method. But
the 'self.scene.mlab.colorbar' does not work in _init__ and cause an error:
'vtkScalarBarWidget: The interactor must be set prior to enabling the
widget'.

But during processing the 'scene.activated' event
'self.scene.mlab.colorbar' works fine. So what is the right place to draw
the whole scene?

Alexander

On Thu, Mar 29, 2012 at 6:29 PM, Robert Kern <[hidden email]> wrote:

> On Thu, Mar 29, 2012 at 3:24 PM, Alexander Kalinin
> <[hidden email]> wrote:
> > Hello!
> >
> > Is it possible to change Range Trait high value after initialization?
>
> class MapView(HasTraits):
>    frame_low = Int(1)
>    frame_high = Int(400)
>    frame = Range(low='frame_low', high='frame_high', value=1)
>
>    def __init__(self, mesh, f):
>        ...
>        self.frame_high = u.shape[1]
>
> --
> Robert Kern
> Enthought
> _______________________________________________
> 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: Change Range Trait after initialization

Gael Varoquaux
On Fri, Mar 30, 2012 at 11:10:48AM +0400, Alexander Kalinin wrote:
> The 'self.scene.mlab.triangular_mesh' works fine in __init__ method. But
> the 'self.scene.mlab.colorbar' does not work in _init__ and cause an error:
> 'vtkScalarBarWidget: The interactor must be set prior to enabling the
> widget'.

> But during processing the 'scene.activated' event
> 'self.scene.mlab.colorbar' works fine. So what is the right place to draw
> the whole scene?

There is no general answer: some components of the scene need to have
access to the display to work properly, so they must be created in the
scene.activated event. Other are purely data description, and can be
created whenever you want.

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

Re: Change Range Trait after initialization

Alexander Kalinin
OK, I see. Thank you.

Alexander.

On Fri, Mar 30, 2012 at 11:44 AM, Gael Varoquaux <
[hidden email]> wrote:

> On Fri, Mar 30, 2012 at 11:10:48AM +0400, Alexander Kalinin wrote:
> > The 'self.scene.mlab.triangular_mesh' works fine in __init__ method. But
> > the 'self.scene.mlab.colorbar' does not work in _init__ and cause an
> error:
> > 'vtkScalarBarWidget: The interactor must be set prior to enabling the
> > widget'.
>
> > But during processing the 'scene.activated' event
> > 'self.scene.mlab.colorbar' works fine. So what is the right place to draw
> > the whole scene?
>
> There is no general answer: some components of the scene need to have
> access to the display to work properly, so they must be created in the
> scene.activated event. Other are purely data description, and can be
> created whenever you want.
>
> G
> _______________________________________________
> 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