From fdee6cdc52cce9ae8591d1baa5aa1bf57324968e Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Mon, 16 Sep 2024 13:41:48 +0200 Subject: [PATCH 1/3] A more general preprocessor widget that allows other kinds of previews --- .../spectroscopy/widgets/owpreprocess.py | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/orangecontrib/spectroscopy/widgets/owpreprocess.py b/orangecontrib/spectroscopy/widgets/owpreprocess.py index 496817e82..052254b16 100644 --- a/orangecontrib/spectroscopy/widgets/owpreprocess.py +++ b/orangecontrib/spectroscopy/widgets/owpreprocess.py @@ -418,7 +418,29 @@ def progress_interrupt(i: float): return orig_data, data -class SpectralPreprocess(OWWidget, ConcurrentWidgetMixin, openclass=True): +class SpectraPreviews: + + curveplot = settings.SettingProvider(CurvePlot) + curveplot_after = settings.SettingProvider(CurvePlot) + + def __init__(self): + self.curveplot = CurvePlot(self) + self.curveplot_after = CurvePlot(self) + self.curveplot.plot.vb.x_padding = 0.005 # pad view so that lines are not hidden + self.curveplot_after.plot.vb.x_padding = 0.005 # pad view so that lines are not hidden + + self.curveplot.highlight_changed.connect( + lambda: transfer_highlight(self.curveplot, self.curveplot_after)) + self.curveplot_after.highlight_changed.connect( + lambda: transfer_highlight(self.curveplot_after, self.curveplot)) + + def shutdown(self): + self.curveplot.shutdown() + self.curveplot_after.shutdown() + + +class GeneralPreprocess(OWWidget, ConcurrentWidgetMixin, + openclass=True): class Inputs: data = Input("Data", Orange.data.Table, default=True) @@ -437,9 +459,6 @@ class Outputs: # compatibility for old workflows when reference was not processed process_reference = settings.Setting(True, schema_only=True) - curveplot = settings.SettingProvider(CurvePlot) - curveplot_after = settings.SettingProvider(CurvePlot) - # draw preview on top of current image preview_on_image = False @@ -534,11 +553,6 @@ def mimeData(indexlist): splitter = QSplitter(self) splitter.setOrientation(Qt.Vertical) - self.curveplot = CurvePlot(self) - self.curveplot_after = CurvePlot(self) - self.curveplot.plot.vb.x_padding = 0.005 # pad view so that lines are not hidden - self.curveplot_after.plot.vb.x_padding = 0.005 # pad view so that lines are not hidden - splitter.addWidget(self.curveplot) splitter.addWidget(self.curveplot_after) self.mainArea.layout().addWidget(splitter) @@ -560,11 +574,6 @@ def overlay(widget): self.curveplot_info = overlay(self.curveplot) self.curveplot_after_info = overlay(self.curveplot_after) - self.curveplot.highlight_changed.connect( - lambda: transfer_highlight(self.curveplot, self.curveplot_after)) - self.curveplot_after.highlight_changed.connect( - lambda: transfer_highlight(self.curveplot_after, self.curveplot)) - if not self.preview_on_image: self.curveplot_after.show() else: @@ -815,8 +824,6 @@ def storeSpecificSettings(self): def onDeleteWidget(self): self.shutdown() self.preview_runner.shutdown() - self.curveplot.shutdown() - self.curveplot_after.shutdown() self.data = None self.set_model(None) super().onDeleteWidget() @@ -871,6 +878,18 @@ def migrate_settings(cls, settings_, version): cls.migrate_preprocessors(settings_["storedsettings"]["preprocessors"], version) +class SpectralPreprocess(GeneralPreprocess, + SpectraPreviews, openclass=True): + + def __init__(self): + SpectraPreviews.__init__(self) + super().__init__() + + def onDeleteWidget(self): + super().onDeleteWidget() + SpectraPreviews.shutdown(self) + + class SpectralPreprocessReference(SpectralPreprocess, openclass=True): class Inputs(SpectralPreprocess.Inputs): From eef1500351a84b520276dd1cee7e3314065984a7 Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Thu, 19 Sep 2024 10:31:29 +0200 Subject: [PATCH 2/3] owhyper: read colors from parent data (for consistency) This is only relevant for DiscreteVariables, and thus can be ignored when ImagePlot is used in Preprocess Images. Having it reference the parent makes it not break after transformation. --- orangecontrib/spectroscopy/widgets/owhyper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orangecontrib/spectroscopy/widgets/owhyper.py b/orangecontrib/spectroscopy/widgets/owhyper.py index 1eed69753..e695ac1b7 100644 --- a/orangecontrib/spectroscopy/widgets/owhyper.py +++ b/orangecontrib/spectroscopy/widgets/owhyper.py @@ -408,7 +408,7 @@ def update_color_schema(self): return if self.parent.value_type == 1: - dat = self.data.domain[self.parent.attr_value] + dat = self.parent.data.domain[self.parent.attr_value] if isinstance(dat, DiscreteVariable): # use a defined discrete palette self.img.setLookupTable(dat.colors) From ad9e3279d7794cfe936c483df609e845ff7b9cc9 Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Thu, 19 Sep 2024 10:45:48 +0200 Subject: [PATCH 3/3] Preprocess base: expose preview settings box --- orangecontrib/spectroscopy/widgets/owpreprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orangecontrib/spectroscopy/widgets/owpreprocess.py b/orangecontrib/spectroscopy/widgets/owpreprocess.py index 052254b16..b4098e322 100644 --- a/orangecontrib/spectroscopy/widgets/owpreprocess.py +++ b/orangecontrib/spectroscopy/widgets/owpreprocess.py @@ -584,7 +584,7 @@ def overlay(widget): self.flow_view.installEventFilter(self) - box = gui.widgetBox(self.controlArea, "Preview") + self.preview_settings_box = box = gui.widgetBox(self.controlArea, "Preview") self.final_preview_toggle = False if not self.preview_on_image: self.final_preview = gui.button(