def SetupDoubleSliderControl(self, WidgetName='Set Threshold', SpinBoxStep=5): self.Slider = ctk.ctkDoubleRangeSlider() self.Label = qt.QLabel(WidgetName) self.Slider.orientation = 1 self.SpinBoxL = qt.QSpinBox() self.SpinBoxL.prefix = 'Min: ' self.SpinBoxL.setSingleStep(SpinBoxStep) self.SpinBoxR = qt.QSpinBox() self.SpinBoxR.prefix = 'Max: ' self.SpinBoxR.setSingleStep(SpinBoxStep) ControlHBox = qt.QHBoxLayout() ControlHBox.addWidget(self.Label) ControlHBox.addWidget(self.SpinBoxL) ControlHBox.addWidget(self.Slider) ControlHBox.addWidget(self.SpinBoxR) self.DisplayLayout.addRow(ControlHBox) self.Slider.minimum = 0 self.SpinBoxL.setRange(0, 0) self.Slider.maximum = 0 self.SpinBoxR.setRange(0, 0)
def buildGUI(self): self.scrollArea = qt.QScrollArea() self.widget = qt.QWidget() self.scrollArea.widgetResizable = True self.scrollArea.setVerticalScrollBarPolicy(qt.Qt.ScrollBarAsNeeded) self.layout = qt.QFormLayout() self.widget.setLayout(self.layout) self.scrollArea.setWidget(self.widget) actions = self.logic.getActions(self.animationNode) for action in actions.values(): actionRowLayout = qt.QHBoxLayout() actionLabel = qt.QLabel(action['name']) actionRowLayout.addWidget(actionLabel) editButton = qt.QPushButton('Edit') editButton.connect('clicked()', lambda action=action : self.onEdit(action)) actionRowLayout.addWidget(editButton) deleteButton = qt.QPushButton('Delete') deleteButton.connect('clicked()', lambda action=action : self.onDelete(action)) actionRowLayout.addWidget(deleteButton) self.layout.addRow(actionRowLayout) durationSlider = ctk.ctkDoubleRangeSlider() durationSlider.maximum = self.script['duration'] durationSlider.minimumValue = action['startTime'] durationSlider.maximumValue = action['endTime'] durationSlider.singleStep = 0.001 durationSlider.orientation = qt.Qt.Horizontal self.layout.addRow(durationSlider) def updateDuration(start, end, action): action['startTime'] = start action['endTime'] = end self.logic.setAction(self.animationNode, action) durationSlider.connect('valuesChanged(double,double)', lambda start, end, action=action: updateDuration(start, end, action)) return self.scrollArea
def setup(self): ScriptedLoadableModuleWidget.setup(self) self.logic = MyModuleLogic() # ------ 1. CREATE LAYOUT AND BUTTONS ------ # Layout setup: 3D Only self.layoutManager = slicer.app.layoutManager() self.layoutManager.setLayout( slicer.vtkMRMLLayoutNode.SlicerLayoutOneUp3DView) # # LOAD DATA # # Create layout collapsibleButtonLoad = ctk.ctkCollapsibleButton() collapsibleButtonLoad.text = "LOAD DATA" # title for layout self.layout.addWidget(collapsibleButtonLoad) formLayout_load = qt.QFormLayout(collapsibleButtonLoad) # Segment 1 Selector self.segment1_pathSelector = ctk.ctkPathLineEdit() self.segment1_pathSelector.enabled = True self.segment1_pathSelector.setMaximumWidth(400) self.segment1_pathSelector.currentPath = slicer.modules.mymodule.path.replace( "MyModule.py", "") + 'Data/Liver1.stl' formLayout_load.addRow("Segment 1: ", self.segment1_pathSelector) # Segment 1 Selector self.segment2_pathSelector = ctk.ctkPathLineEdit() self.segment2_pathSelector.enabled = True self.segment2_pathSelector.setMaximumWidth(400) self.segment2_pathSelector.currentPath = slicer.modules.mymodule.path.replace( "MyModule.py", "") + 'Data/Liver1beforeMM.stl' formLayout_load.addRow("Segment 2: ", self.segment2_pathSelector) # Button to load segments self.loadSegmentsButton = qt.QPushButton( "LOAD MODELS AS SEGMENTS") # text in button self.loadSegmentsButton.toolTip = "Load segments as segments" # hint text for button (appears when cursor is above the button for more than one second) self.loadSegmentsButton.enabled = True # if True it can be clicked formLayout_load.addRow( self.loadSegmentsButton) # include button in layout # # ALIGNMENT # # Create Layout collapsibleButtonAlignment = ctk.ctkCollapsibleButton() collapsibleButtonAlignment.text = "ALIGNMENT" self.layout.addWidget(collapsibleButtonAlignment) formLayout_alignment = qt.QFormLayout(collapsibleButtonAlignment) # Button for masks alignment self.alignSegmentsButton = qt.QPushButton( "ALIGN MODELS") # text in button self.alignSegmentsButton.toolTip = "Align segments" # hint text for button (appears when cursor is above the button for more than one second) self.alignSegmentsButton.enabled = True formLayout_alignment.addRow(self.alignSegmentsButton) # COMPARISON BETWEEN MASKS # # SORENSEN-DICE COEFFICIENT & HOUSDORFF DISTANCE BUTTONS # # Create layout collapsibleButtonComparison = ctk.ctkCollapsibleButton() collapsibleButtonComparison.text = "COMPARISON" # title for layout self.layout.addWidget(collapsibleButtonComparison) formLayout_comparison = qt.QFormLayout(collapsibleButtonComparison) # Button to obtain the Sorensen-Dice Coefficient self.diceCoeffButton = qt.QPushButton( "SORENSEN-DICE COEFFICIENT") # text in button self.diceCoeffButton.toolTip = "Sorensen-Dice Coefficient" # hint text for button (appears when the cursor is above the button for more than one second) self.diceCoeffButton.enabled = True # if true it can be clicked formLayout_comparison.addRow( self.diceCoeffButton) # include button in layout #Button to obtain the Hausdorff Distance self.hausDistButton = qt.QPushButton( "HAUSDORFF DISTANCE") # text in button self.hausDistButton.toolTip = qt.QPushButton( "Hausdorff Distance" ) # hint text for button (appears when the cursor is above the button for more than a second) self.hausDistButton.enabled = True # if true it can be clicked formLayout_comparison.addRow( self.hausDistButton) # include button in layout # # VISUALIZATION # # Create layout collapsibleButtonVisualization = ctk.ctkCollapsibleButton() collapsibleButtonVisualization.text = "VISUALIZATION" # title for layout self.layout.addWidget(collapsibleButtonVisualization) formLayout_visualization = qt.QFormLayout( collapsibleButtonVisualization) # # Segment visibility layout # # Create collapsible button inside layout segmentVisibility_GroupBox = ctk.ctkCollapsibleGroupBox() segmentVisibility_GroupBox.setTitle( "MODEL VISIBILITY") # title for collapsible button segmentVisibility_GroupBox.collapsed = False # if True it appears collapsed formLayout_visualization.addRow( segmentVisibility_GroupBox) # add collapsible button to layout # Create layout inside collapsible button segmentVisibility_GroupBox_Layout = qt.QFormLayout( segmentVisibility_GroupBox) # Create horizontal section segmentVisibilityLayout_1 = qt.QHBoxLayout() segmentVisibility_GroupBox_Layout.addRow( segmentVisibilityLayout_1) # insert section in current layout # Show or Hide Segment 1 in 3D scene self.segment1_checkBox = qt.QCheckBox('Segment 1') # text in checkbox self.segment1_checkBox.checked = True # if True it is initially checked self.segment1_checkBox.enabled = True # if True it can be checked segmentVisibilityLayout_1.addWidget( self.segment1_checkBox) # add checkbox to layout # Show or Hide Segment 2 in 3D scene self.segment2_checkBox = qt.QCheckBox('Segment 2') # text in checkbox self.segment2_checkBox.checked = True # if True it is initially checked self.segment2_checkBox.checked = True # if True it can be checked segmentVisibilityLayout_1.addWidget( self.segment2_checkBox) # add checkbox to layout # # Segment transparency layout # # Create collapsible button inside layout segmentOpacity_GroupBox = ctk.ctkCollapsibleGroupBox() segmentOpacity_GroupBox.setTitle( "MODEL OPACITY") # title for collapsible button segmentOpacity_GroupBox.collapsed = False # if True it appears collapsed formLayout_visualization.addRow( segmentOpacity_GroupBox) # add collapsible button to layout # Create layout inside collapsible button segmentOpacity_GroupBox_Layout = qt.QFormLayout( segmentOpacity_GroupBox) # Create an opacity Value Slider - Segment 1 self.opacityValueSliderWidget_1 = ctk.ctkSliderWidget() self.opacityValueSliderWidget_1.singleStep = 5 # step for range of values to be selected self.opacityValueSliderWidget_1.minimum = 0 # minimum value self.opacityValueSliderWidget_1.maximum = 100 # maximum value self.opacityValueSliderWidget_1.value = 100 # initial value segmentOpacity_GroupBox_Layout.addRow( "[%]: ", self.opacityValueSliderWidget_1) # add slider to layout # Create an opacity Value Slider - Segment 2 self.opacityValueSliderWidget_2 = ctk.ctkSliderWidget() self.opacityValueSliderWidget_2.singleStep = 5 # step for range of values to be selected self.opacityValueSliderWidget_2.minimum = 0 # minimum value self.opacityValueSliderWidget_2.maximum = 100 # maximum value self.opacityValueSliderWidget_2.value = 100 # initial value segmentOpacity_GroupBox_Layout.addRow( "[%]: ", self.opacityValueSliderWidget_2) # add slider to layout # # COLOR MAP # collapsibleButtonColorMap = ctk.ctkCollapsibleButton() collapsibleButtonColorMap.text = "COLOR MAP" self.layout.addWidget(collapsibleButtonColorMap) formLayout_colorMap = qt.QFormLayout(collapsibleButtonColorMap) self.showColorMapButton = qt.QPushButton( "SHOW COLOR MAP") # text in button self.showColorMapButton.toolTip = "Align segments" # hint text for button (appears when cursor is above the button for more than one second) self.showColorMapButton.enabled = True formLayout_colorMap.addRow(self.showColorMapButton) # Displayed Range group box self.displayedRange_GroupBox = ctk.ctkCollapsibleGroupBox() self.displayedRange_GroupBox.setTitle("Displayed Range") self.displayedRange_GroupBox.collapsed = False self.displayedRange_GroupBox.enabled = False formLayout_colorMap.addRow(self.displayedRange_GroupBox) displayedRange_GroupBox_Layout = qt.QFormLayout( self.displayedRange_GroupBox) displayedRange_H_Layout = qt.QHBoxLayout() displayedRange_GroupBox_Layout.addRow(displayedRange_H_Layout) ## Minimum value - displayed range self.minDisplayedRange_SpinBox = qt.QDoubleSpinBox() self.minDisplayedRange_SpinBox.setMaximum(40.0) self.minDisplayedRange_SpinBox.setMinimum(-40.0) self.minDisplayedRange_SpinBox.setSingleStep(0.1) self.minDisplayedRange_SpinBox.enabled = True self.minDisplayedRange_SpinBox.value = 0.0 displayedRange_H_Layout.addWidget(self.minDisplayedRange_SpinBox) ## Displayed range Slider self.displayedRange_SliderWidget = ctk.ctkDoubleRangeSlider() self.displayedRange_SliderWidget.setValues(0.0, 10.0) self.displayedRange_SliderWidget.orientation = 1 self.displayedRange_SliderWidget.singleStep = 0.1 self.displayedRange_SliderWidget.minimum = -40.0 self.displayedRange_SliderWidget.maximum = 40.0 displayedRange_H_Layout.addWidget(self.displayedRange_SliderWidget) ## Maximum value - displayed range self.maxDisplayedRange_SpinBox = qt.QDoubleSpinBox() self.maxDisplayedRange_SpinBox.setMaximum(40.0) self.maxDisplayedRange_SpinBox.setMinimum(-40.0) self.maxDisplayedRange_SpinBox.setSingleStep(0.1) self.maxDisplayedRange_SpinBox.enabled = True self.maxDisplayedRange_SpinBox.value = 10.0 displayedRange_H_Layout.addWidget(self.maxDisplayedRange_SpinBox) # Scalar Bar Visibility Checkbox self.ScalarBar_visibility_checkBox = qt.QCheckBox('Scalar Bar Visible') self.ScalarBar_visibility_checkBox.checked = True displayedRange_GroupBox_Layout.addRow( self.ScalarBar_visibility_checkBox) # Add vertical spacing self.layout.addStretch(1) # ------ 2. CONNECT BUTTONS WITH FUNCTIONS ------ # Connect each button with a function self.loadSegmentsButton.connect( 'clicked(bool)', self.onloadSegmentsButton ) # when the button is pressed we call the function onLoadSegment1Button self.segment1_checkBox.connect('stateChanged(int)', self.onupdateSegment1Visibility) self.segment2_checkBox.connect('stateChanged(int)', self.onupdateSegment2Visibility) self.opacityValueSliderWidget_1.connect("valueChanged(double)", self.onupdateSegment1Opacity) self.opacityValueSliderWidget_2.connect("valueChanged(double)", self.onupdateSegment2Opacity) self.alignSegmentsButton.connect('clicked(bool)', self.onAlignSegmentsButton) self.diceCoeffButton.connect('clicked(bool)', self.onDiceCoeffButton) self.hausDistButton.connect('clicked(bool)', self.onHausdorffDistButton) self.showColorMapButton.connect('clicked(bool)', self.onShowColorMapButton) self.displayedRange_SliderWidget.connect( "valuesChanged(double,double)", self.onDisplayedRangeSliderChanged) self.minDisplayedRange_SpinBox.connect( "valueChanged(double)", self.onDisplayedRangeSpinBoxChanged) self.maxDisplayedRange_SpinBox.connect( "valueChanged(double)", self.onDisplayedRangeSpinBoxChanged) self.ScalarBar_visibility_checkBox.connect( 'stateChanged(int)', self.onScalarBarVisibilityChecked)