dipy/viz/widget.py
def slider(iren, ren, callback, min_value=0, max_value=255, value=125,
           label="Slider",
           right_normalized_pos=(0.9, 0.5),
           size=(50, 0),
           label_format="%0.0lf",
           color=(0.5, 0.5, 0.5),
           selected_color = (0.9, 0.2, 0.1)):
    """ A 2D slider widget

    Parameters
    ----------
    iren : vtkRenderWindowInteractor
        Used to process events and handle them to the slider. Can also be given
        by the attribute ``ShowManager.iren``.
    ren :  vtkRenderer or Renderer
        Used to update the slider's position when the window changes. Can also
        be given by the ``ShowManager.ren`` attribute.
    callback : function
        Function that has at least ``obj`` and ``event`` as parameters. It will
        be called when the slider's bar has changed.
    min_value : float
        Minimum value of slider.
    max_value : float
        Maximum value of slider.
    value :
        Default value of slider.
    label : str
        Slider's caption.
    right_normalized_pos : tuple
        2d tuple holding the normalized right (X, Y) position of the slider.
    size: tuple
        2d tuple holding the size of the slider in pixels.
    label_format: str
        Formating in which the slider's value will appear for example "%0.2lf"
        allows for 2 decimal values.

    Returns
    -------
    slider : SliderObject
        This object inherits from vtkSliderWidget and has additional method
        called ``place`` which allows to update the position of the slider
        when for example the window is resized.
    """

    slider_rep = vtk.vtkSliderRepresentation2D()
    slider_rep.SetMinimumValue(min_value)
    slider_rep.SetMaximumValue(max_value)
    slider_rep.SetValue(value)
    slider_rep.SetTitleText(label)

    slider_rep.GetPoint2Coordinate().SetCoordinateSystemToNormalizedDisplay()
    slider_rep.GetPoint2Coordinate().SetValue(*right_normalized_pos)

    coord2 = slider_rep.GetPoint2Coordinate().GetComputedDisplayValue(ren)
    slider_rep.GetPoint1Coordinate().SetCoordinateSystemToDisplay()
    slider_rep.GetPoint1Coordinate().SetValue(coord2[0] - size[0],
                                              coord2[1] - size[1])

    initial_window_size = ren.GetSize()
    length = 0.04
    width = 0.04
    cap_length = 0.01
    cap_width = 0.01
    tube_width = 0.005

    slider_rep.SetSliderLength(length)
    slider_rep.SetSliderWidth(width)
    slider_rep.SetEndCapLength(cap_length)
    slider_rep.SetEndCapWidth(cap_width)
    slider_rep.SetTubeWidth(tube_width)
    slider_rep.SetLabelFormat(label_format)

    slider_rep.GetLabelProperty().SetColor(*color)
    slider_rep.GetTubeProperty().SetColor(*color)
    slider_rep.GetCapProperty().SetColor(*color)
    slider_rep.GetTitleProperty().SetColor(*color)
    slider_rep.GetSelectedProperty().SetColor(*selected_color)
    slider_rep.GetSliderProperty().SetColor(*color)

    slider_rep.GetLabelProperty().SetShadow(0)
    slider_rep.GetTitleProperty().SetShadow(0)

    class SliderWidget(vtk.vtkSliderWidget):

        def place(self, ren):

            slider_rep = self.GetRepresentation()
            coord2_norm = slider_rep.GetPoint2Coordinate()
            coord2_norm.SetCoordinateSystemToNormalizedDisplay()
            coord2_norm.SetValue(*right_normalized_pos)

            coord2 = coord2_norm.GetComputedDisplayValue(ren)
            slider_rep.GetPoint1Coordinate().SetCoordinateSystemToDisplay()
            slider_rep.GetPoint1Coordinate().SetValue(coord2[0] - size[0],
                                                      coord2[1] - size[1])

            window_size = ren.GetSize()
            length = initial_window_size[0] * 0.04 / window_size[0]
            width = initial_window_size[1] * 0.04 / window_size[1]

            slider_rep.SetSliderLength(length)
            slider_rep.SetSliderWidth(width)

        def set_value(self, value):
            return self.GetSliderRepresentation().SetValue(value)

        def get_value(self):
            return self.GetSliderRepresentation().GetValue()

    slider = SliderWidget()
    slider.SetInteractor(iren)
    slider.SetRepresentation(slider_rep)
    slider.SetAnimationModeToAnimate()
    slider.KeyPressActivationOff()
    slider.AddObserver("InteractionEvent", callback)
    slider.SetEnabled(True)

    return slider
 A 2D slider widget

    Parameters
    ----------
    iren : vtkRenderWindowInteractor
        Used to process events and handle them to the slider. Can also be given
        by the attribute ``ShowManager.iren``.
    ren :  vtkRenderer or Renderer
        Used to update the slider's position when the window changes. Can also
        be given by the ``ShowManager.ren`` attribute.
    callback : function
        Function that has at least ``obj`` and ``event`` as parameters. It will
        be called when the slider's bar has changed.
    min_value : float
        Minimum value of slider.
    max_value : float
        Maximum value of slider.
    value :
        Default value of slider.
    label : str
        Slider's caption.
    right_normalized_pos : tuple
        2d tuple holding the normalized right (X, Y) position of the slider.
    size: tuple
        2d tuple holding the size of the slider in pixels.
    label_format: str
        Formating in which the slider's value will appear for example "%0.2lf"
        allows for 2 decimal values.

    Returns
    -------
    slider : SliderObject
        This object inherits from vtkSliderWidget and has additional method
        called ``place`` which allows to update the position of the slider
        when for example the window is resized.
    
A 2D slider widget
Parameters

iren : vtkRenderWindowInteractor
Used to process events and handle them to the slider. Can also be given
by the attribute ``ShowManager.iren``.
ren :  vtkRenderer or Renderer
Used to update the slider's position when the window changes. Can also
be given by the ``ShowManager.ren`` attribute.

Returns

slider : SliderObject
This object inherits from vtkSliderWidget and has additional method
called ``place`` which allows to update the position of the slider
when for example the window is resized.
A 2D slider widget Parameters iren : vtkRenderWindowInteractor Used to process events and handle them to the slider . Can also be given by the attribute ` ` ShowManager . iren ` ` . ren : vtkRenderer or Renderer Used to update the slider ' s position when the window changes . Can also be given by the ` ` ShowManager . ren ` ` attribute . Returns slider : SliderObject This object inherits from vtkSliderWidget and has additional method called ` ` place ` ` which allows to update the position of the slider when for example the window is resized .
def slider(iren, ren, callback, min_value=0, max_value=255, value=125,
           label="Slider",
           right_normalized_pos=(0.9, 0.5),
           size=(50, 0),
           label_format="%0.0lf",
           color=(0.5, 0.5, 0.5),
           selected_color = (0.9, 0.2, 0.1)):
    slider_rep = vtk.vtkSliderRepresentation2D()
    slider_rep.SetMinimumValue(min_value)
    slider_rep.SetMaximumValue(max_value)
    slider_rep.SetValue(value)
    slider_rep.SetTitleText(label)
    slider_rep.GetPoint2Coordinate().SetCoordinateSystemToNormalizedDisplay()
    slider_rep.GetPoint2Coordinate().SetValue(*right_normalized_pos)
    coord2 = slider_rep.GetPoint2Coordinate().GetComputedDisplayValue(ren)
    slider_rep.GetPoint1Coordinate().SetCoordinateSystemToDisplay()
    slider_rep.GetPoint1Coordinate().SetValue(coord2[0] - size[0],
                                              coord2[1] - size[1])
    initial_window_size = ren.GetSize()
    length = 0.04
    width = 0.04
    cap_length = 0.01
    cap_width = 0.01
    tube_width = 0.005
    slider_rep.SetSliderLength(length)
    slider_rep.SetSliderWidth(width)
    slider_rep.SetEndCapLength(cap_length)
    slider_rep.SetEndCapWidth(cap_width)
    slider_rep.SetTubeWidth(tube_width)
    slider_rep.SetLabelFormat(label_format)
    slider_rep.GetLabelProperty().SetColor(*color)
    slider_rep.GetTubeProperty().SetColor(*color)
    slider_rep.GetCapProperty().SetColor(*color)
    slider_rep.GetTitleProperty().SetColor(*color)
    slider_rep.GetSelectedProperty().SetColor(*selected_color)
    slider_rep.GetSliderProperty().SetColor(*color)
    slider_rep.GetLabelProperty().SetShadow(0)
    slider_rep.GetTitleProperty().SetShadow(0)
    class SliderWidget(vtk.vtkSliderWidget):
        def place(self, ren):
            slider_rep = self.GetRepresentation()
            coord2_norm = slider_rep.GetPoint2Coordinate()
            coord2_norm.SetCoordinateSystemToNormalizedDisplay()
            coord2_norm.SetValue(*right_normalized_pos)
            coord2 = coord2_norm.GetComputedDisplayValue(ren)
            slider_rep.GetPoint1Coordinate().SetCoordinateSystemToDisplay()
            slider_rep.GetPoint1Coordinate().SetValue(coord2[0] - size[0],
                                                      coord2[1] - size[1])
            window_size = ren.GetSize()
            length = initial_window_size[0] * 0.04 / window_size[0]
            width = initial_window_size[1] * 0.04 / window_size[1]
            slider_rep.SetSliderLength(length)
            slider_rep.SetSliderWidth(width)
        def set_value(self, value):
            return self.GetSliderRepresentation().SetValue(value)
        def get_value(self):
            return self.GetSliderRepresentation().GetValue()
    slider = SliderWidget()
    slider.SetInteractor(iren)
    slider.SetRepresentation(slider_rep)
    slider.SetAnimationModeToAnimate()
    slider.KeyPressActivationOff()
    slider.AddObserver("InteractionEvent", callback)
    slider.SetEnabled(True)
    return slider
def slider ( iren , ren , callback , min_value = 0 , max_value = 255 , value = 125 , label = "Slider" , right_normalized_pos = ( 0.9 , 0.5 ) , size = ( 50 , 0 ) , label_format = "%0.0lf" , color = ( 0.5 , 0.5 , 0.5 ) , selected_color = ( 0.9 , 0.2 , 0.1 ) ) : slider_rep = vtk . vtkSliderRepresentation2D ( ) slider_rep . SetMinimumValue ( min_value ) slider_rep . SetMaximumValue ( max_value ) slider_rep . SetValue ( value ) slider_rep . SetTitleText ( label ) slider_rep . GetPoint2Coordinate ( ) . SetCoordinateSystemToNormalizedDisplay ( ) slider_rep . GetPoint2Coordinate ( ) . SetValue ( * right_normalized_pos ) coord2 = slider_rep . GetPoint2Coordinate ( ) . GetComputedDisplayValue ( ren ) slider_rep . GetPoint1Coordinate ( ) . SetCoordinateSystemToDisplay ( ) slider_rep . GetPoint1Coordinate ( ) . SetValue ( coord2 [ 0 ] - size [ 0 ] , coord2 [ 1 ] - size [ 1 ] ) initial_window_size = ren . GetSize ( ) length = 0.04 width = 0.04 cap_length = 0.01 cap_width = 0.01 tube_width = 0.005 slider_rep . SetSliderLength ( length ) slider_rep . SetSliderWidth ( width ) slider_rep . SetEndCapLength ( cap_length ) slider_rep . SetEndCapWidth ( cap_width ) slider_rep . SetTubeWidth ( tube_width ) slider_rep . SetLabelFormat ( label_format ) slider_rep . GetLabelProperty ( ) . SetColor ( * color ) slider_rep . GetTubeProperty ( ) . SetColor ( * color ) slider_rep . GetCapProperty ( ) . SetColor ( * color ) slider_rep . GetTitleProperty ( ) . SetColor ( * color ) slider_rep . GetSelectedProperty ( ) . SetColor ( * selected_color ) slider_rep . GetSliderProperty ( ) . SetColor ( * color ) slider_rep . GetLabelProperty ( ) . SetShadow ( 0 ) slider_rep . GetTitleProperty ( ) . SetShadow ( 0 ) class SliderWidget ( vtk . vtkSliderWidget ) : def place ( self , ren ) : slider_rep = self . GetRepresentation ( ) coord2_norm = slider_rep . GetPoint2Coordinate ( ) coord2_norm . SetCoordinateSystemToNormalizedDisplay ( ) coord2_norm . SetValue ( * right_normalized_pos ) coord2 = coord2_norm . GetComputedDisplayValue ( ren ) slider_rep . GetPoint1Coordinate ( ) . SetCoordinateSystemToDisplay ( ) slider_rep . GetPoint1Coordinate ( ) . SetValue ( coord2 [ 0 ] - size [ 0 ] , coord2 [ 1 ] - size [ 1 ] ) window_size = ren . GetSize ( ) length = initial_window_size [ 0 ] * 0.04 / window_size [ 0 ] width = initial_window_size [ 1 ] * 0.04 / window_size [ 1 ] slider_rep . SetSliderLength ( length ) slider_rep . SetSliderWidth ( width ) def set_value ( self , value ) : return self . GetSliderRepresentation ( ) . SetValue ( value ) def get_value ( self ) : return self . GetSliderRepresentation ( ) . GetValue ( ) slider = SliderWidget ( ) slider . SetInteractor ( iren ) slider . SetRepresentation ( slider_rep ) slider . SetAnimationModeToAnimate ( ) slider . KeyPressActivationOff ( ) slider . AddObserver ( "InteractionEvent" , callback ) slider . SetEnabled ( True ) return slider
A 2D slider widget
Parameters
A 2D slider widget Parameters
""" A 2D slider widget

    Parameters
    ----------
    iren : vtkRenderWindowInteractor
        Used to process events and handle them to the slider. Can also be given
        by the attribute ``ShowManager.iren``.
    ren :  vtkRenderer or Renderer
        Used to update the slider's position when the window changes. Can also
        be given by the ``ShowManager.ren`` attribute.
    callback : function
        Function that has at least ``obj`` and ``event`` as parameters. It will
        be called when the slider's bar has changed.
    min_value : float
        Minimum value of slider.
    max_value : float
        Maximum value of slider.
    value :
        Default value of slider.
    label : str
        Slider's caption.
    right_normalized_pos : tuple
        2d tuple holding the normalized right (X, Y) position of the slider.
    size: tuple
        2d tuple holding the size of the slider in pixels.
    label_format: str
        Formating in which the slider's value will appear for example "%0.2lf"
        allows for 2 decimal values.

    Returns
    -------
    slider : SliderObject
        This object inherits from vtkSliderWidget and has additional method
        called ``place`` which allows to update the position of the slider
        when for example the window is resized.
    """
iren
ren
callback
min_value
max_value
value
label
right_normalized_pos
size
label_format
color
selected_color