From 36ba9b176b46703f03f5a5b32a9ffab70bcfb958 Mon Sep 17 00:00:00 2001 From: Christian Herz Date: Wed, 22 Nov 2017 19:41:33 -0500 Subject: [PATCH 1/2] ENH: instead of overwriting class member plugins, just removing those plugins that are unneeded from instantiated SegmentStatisticsLogic * added class CustomSegmentStatisticsParameterEditorDialog as a workaround --- .../CustomSegmentStatistics.py | 22 ++++++++++++++----- .../QuantitativeReporting.py | 8 ++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/QuantitativeReporting/QRCustomizations/CustomSegmentStatistics.py b/QuantitativeReporting/QRCustomizations/CustomSegmentStatistics.py index 640be15..5cb7af1 100644 --- a/QuantitativeReporting/QRCustomizations/CustomSegmentStatistics.py +++ b/QuantitativeReporting/QRCustomizations/CustomSegmentStatistics.py @@ -1,12 +1,24 @@ import logging import slicer +import qt from SlicerDevelopmentToolboxUtils.mixins import ModuleLogicMixin -from SegmentStatistics import SegmentStatisticsLogic -from SegmentStatisticsPlugins import ScalarVolumeSegmentStatisticsPlugin, ClosedSurfaceSegmentStatisticsPlugin +from SegmentStatistics import SegmentStatisticsLogic, SegmentStatisticsParameterEditorDialog +from SegmentStatisticsPlugins import LabelmapSegmentStatisticsPlugin from DICOMSegmentationPlugin import DICOMSegmentationExporter +class CustomSegmentStatisticsParameterEditorDialog(SegmentStatisticsParameterEditorDialog): + + def __init__(self, logic, parent=None, pluginName=None): + super(qt.QDialog, self).__init__(parent) + self.title = "Edit Segment Statistics Parameters" + self.logic = logic + self.parameterNode = self.logic.getParameterNode() + self.pluginName = pluginName + self.setup() + + class CustomSegmentStatisticsLogic(SegmentStatisticsLogic): @staticmethod @@ -24,11 +36,9 @@ def segmentationNode(self): return slicer.mrmlScene.GetNodeByID(self.getParameterNode().GetParameter("Segmentation")) def __init__(self): - logging.debug("CustomSegmentStatisticsLogic: only using ScalarVolumeSegmentStatisticsPlugin and " - "ClosedSurfaceSegmentStatisticsPlugin") - SegmentStatisticsLogic.registeredPlugins = [ScalarVolumeSegmentStatisticsPlugin, - ClosedSurfaceSegmentStatisticsPlugin] SegmentStatisticsLogic.__init__(self) + self.plugins = [p for p in self.plugins if not isinstance(p,LabelmapSegmentStatisticsPlugin)] + self.reset() self.terminologyLogic = slicer.modules.terminologies.logic() def exportToTable(self, table=None, nonEmptyKeysOnly=True): diff --git a/QuantitativeReporting/QuantitativeReporting.py b/QuantitativeReporting/QuantitativeReporting.py index 61c4baf..047ad35 100644 --- a/QuantitativeReporting/QuantitativeReporting.py +++ b/QuantitativeReporting/QuantitativeReporting.py @@ -9,7 +9,6 @@ import vtkSegmentationCorePython as vtkSegmentationCore from DICOMSegmentationPlugin import DICOMSegmentationExporter -from SegmentStatistics import SegmentStatisticsParameterEditorDialog from SlicerDevelopmentToolboxUtils.buttons import CrosshairButton from SlicerDevelopmentToolboxUtils.buttons import RedSliceLayoutButton, FourUpLayoutButton, FourUpTableViewLayoutButton @@ -23,6 +22,7 @@ from QRUtils.htmlReport import HTMLReportCreator from QRUtils.testdata import TestDataLogic +from QRCustomizations.CustomSegmentStatistics import CustomSegmentStatisticsParameterEditorDialog from QRCustomizations.CustomSegmentEditor import CustomSegmentEditorWidget from QRCustomizations.CustomDICOMDetailsWidget import CustomDICOMDetailsWidget @@ -351,9 +351,11 @@ def setupOtherConnections(): def onEditParameters(self, calculatorName=None): """Open dialog box to edit calculator's parameters""" - pNode = self.segmentEditorWidget.logic.segmentStatisticsLogic.getParameterNode() + segmentStatisticsLogic = self.segmentEditorWidget.logic.segmentStatisticsLogic + pNode = segmentStatisticsLogic.getParameterNode() if pNode: - SegmentStatisticsParameterEditorDialog.editParameters(pNode,calculatorName) + dialog = CustomSegmentStatisticsParameterEditorDialog(segmentStatisticsLogic) + dialog.exec_() self.updateMeasurementsTable(triggered=True) def onExportToHTMLButtonClicked(self): From 13c82f28718a1ec824d3e10c9d0a4e0489a05e40 Mon Sep 17 00:00:00 2001 From: Christian Herz Date: Wed, 22 Nov 2017 23:08:53 -0500 Subject: [PATCH 2/2] ENH: segmentStatisticsParameterEditorDialog as QR member --- QuantitativeReporting/QuantitativeReporting.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/QuantitativeReporting/QuantitativeReporting.py b/QuantitativeReporting/QuantitativeReporting.py index 047ad35..f2bfa52 100644 --- a/QuantitativeReporting/QuantitativeReporting.py +++ b/QuantitativeReporting/QuantitativeReporting.py @@ -63,6 +63,7 @@ def initializeMembers(self): self.tableNode = None self.segmentationObservers = [] self.dicomSegmentationExporter = None + self.segmentStatisticsParameterEditorDialog = None def enter(self): self.measurementReportSelector.setCurrentNode(None) @@ -352,11 +353,10 @@ def setupOtherConnections(): def onEditParameters(self, calculatorName=None): """Open dialog box to edit calculator's parameters""" segmentStatisticsLogic = self.segmentEditorWidget.logic.segmentStatisticsLogic - pNode = segmentStatisticsLogic.getParameterNode() - if pNode: - dialog = CustomSegmentStatisticsParameterEditorDialog(segmentStatisticsLogic) - dialog.exec_() - self.updateMeasurementsTable(triggered=True) + if not self.segmentStatisticsParameterEditorDialog: + self.segmentStatisticsParameterEditorDialog = CustomSegmentStatisticsParameterEditorDialog(segmentStatisticsLogic) + self.segmentStatisticsParameterEditorDialog.exec_() + self.updateMeasurementsTable(triggered=True) def onExportToHTMLButtonClicked(self): creator = HTMLReportCreator(self.segmentEditorWidget.segmentationNode, self.tableNode)