From b3acb6694708720f61e7848b46ffb5a00f614777 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca <14138589+paskino@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:21:52 +0000 Subject: [PATCH] add docstrings --- Wrappers/Python/ccpi/viewer/CILViewer2D.py | 13 +++++++--- Wrappers/Python/ccpi/viewer/widgets/slider.py | 25 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Wrappers/Python/ccpi/viewer/CILViewer2D.py b/Wrappers/Python/ccpi/viewer/CILViewer2D.py index c291c721..e34421c3 100644 --- a/Wrappers/Python/ccpi/viewer/CILViewer2D.py +++ b/Wrappers/Python/ccpi/viewer/CILViewer2D.py @@ -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') @@ -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 ) @@ -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: diff --git a/Wrappers/Python/ccpi/viewer/widgets/slider.py b/Wrappers/Python/ccpi/viewer/widgets/slider.py index a6fa6fc0..e8af53c2 100644 --- a/Wrappers/Python/ccpi/viewer/widgets/slider.py +++ b/Wrappers/Python/ccpi/viewer/widgets/slider.py @@ -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 @@ -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: ----------- @@ -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) @@ -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):