Skip to content

Commit

Permalink
A more general preprocessor widget that allows other kinds of previews
Browse files Browse the repository at this point in the history
  • Loading branch information
markotoplak committed Sep 16, 2024
1 parent 08be0e1 commit fdee6cd
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions orangecontrib/spectroscopy/widgets/owpreprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit fdee6cd

Please sign in to comment.