Skip to content

Commit

Permalink
add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
paskino committed Feb 27, 2024
1 parent 33083cb commit b3acb66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
13 changes: 9 additions & 4 deletions Wrappers/Python/ccpi/viewer/CILViewer2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,11 @@ def installRectilinearWipePipeline(self):
self.AddActor(wipeSlice, WIPE_ACTOR)

def installSliceSliderWidgetPipeline(self):

'''Create the pipeline for the slice slider widget
The slider widget and representation are created if not already present.
Currently the slider widget enabled flag is not used.
'''
if self.sliderWidget is not None:
# reset the values to the appropriate ones of the new loaded image
self.sliderCallback.update_orientation(self.style, 'reset')
Expand All @@ -1490,8 +1494,10 @@ def installSliceSliderWidgetPipeline(self):
cb = SliderCallback(self, sw)

# Add interaction observers
# propagate events from the slider to the viewer
sw.AddObserver(vtk.vtkCommand.InteractionEvent, cb)

# propagate events from the viewer to the slider
self.style.AddObserver("MouseWheelForwardEvent", cb.update_from_viewer, 0.9 )
self.style.AddObserver("MouseWheelBackwardEvent", cb.update_from_viewer, 0.9 )
self.style.AddObserver("CharEvent", cb.update_orientation, 0.9 )
Expand All @@ -1502,10 +1508,9 @@ def installSliceSliderWidgetPipeline(self):
# save references
self.sliderWidget = sw
self.sliderCallback = cb
# self.sliderMinMaxLabels = (mtw, Mtw)

def uninstallSliderWidget(self):

def uninstallSliderWidget(self):
'''remove the slider widget from the viewer'''
if self.sliderWidget is not None:
sr = self.sliderWidget.GetRepresentation()
if sr is not None:
Expand Down
25 changes: 19 additions & 6 deletions Wrappers/Python/ccpi/viewer/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SliceSliderRepresentation(vtk.vtkSliderRepresentation2D):

def __init__(self, orientation='horizontal', offset=0.12):
self.tube_width = 0.004
self.slider_length = 0.025
self.slider_length = 0.015
self.slider_width = 0.015
self.end_cap_length = 0.008
self.end_cap_width = 0.02
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self, orientation='horizontal', offset=0.12):
class SliderCallback:
'''
Class to propagate the effects of interaction between the slider widget and the viewer
the slider is embedded into.
the slider is embedded into, and viceversa.
Parameters:
-----------
Expand All @@ -85,13 +85,26 @@ def __init__(self, viewer, slider_widget):
self.slider_widget = slider_widget

def __call__(self, caller, ev):
'''Update the slice displayed by the viewer when the slider is moved
Parameters:
-----------
- caller, the slider widget
- ev, the event that triggered the update
'''
slider_widget = caller
value = slider_widget.GetRepresentation().GetValue()
self.viewer.displaySlice(int(value))
self.update_label(slider_widget, value)
self.update_label(value)

def update_label(self, slider_widget, value):
rep = slider_widget.GetRepresentation()
def update_label(self, value):
'''Update the text label on the slider. This is called by update_from_viewer
Parameters:
-----------
- value, the value to be displayed on text label the slider
'''
rep = self.slider_widget.GetRepresentation()
maxval = rep.GetMaximumValue()
txt = "Slice {}/{}".format(int(value), int(maxval))
rep.SetLabelFormat(txt)
Expand All @@ -108,7 +121,7 @@ def update_from_viewer(self, caller, ev):
logger.info(f"Updating for event {ev}")
value = caller.GetActiveSlice()
self.slider_widget.GetRepresentation().SetValue(value)
self.update_label(self.slider_widget, value)
self.update_label(value)
caller.GetRenderWindow().Render()

def update_orientation(self, caller, ev):
Expand Down

0 comments on commit b3acb66

Please sign in to comment.