Skip to content

Commit

Permalink
Merge pull request #737 from markotoplak/pca-denoising-orange
Browse files Browse the repository at this point in the history
PCA denoising: extent BaseEditorOrange
  • Loading branch information
markotoplak committed Jul 24, 2024
2 parents b75a3a9 + 1dca781 commit 17b239e
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions orangecontrib/spectroscopy/widgets/preprocessors/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

from AnyQt.QtCore import Qt
from AnyQt.QtWidgets import (
QComboBox, QSpinBox, QVBoxLayout, QHBoxLayout, QFormLayout, QSizePolicy, QLabel
QComboBox, QVBoxLayout, QHBoxLayout, QFormLayout, QLabel
)
from AnyQt.QtGui import QColor

from Orange.widgets import gui
from Orange.widgets.widget import Msg
from Orange.widgets.data.owpreprocess import blocked

from orangecontrib.spectroscopy.data import getx

Expand All @@ -21,7 +20,7 @@
from orangecontrib.spectroscopy.preprocess.transform import SpecTypes
from orangecontrib.spectroscopy.widgets.gui import lineEditFloatRange, MovableVline, \
connect_line, floatornone, round_virtual_pixels
from orangecontrib.spectroscopy.widgets.preprocessors.utils import BaseEditor, BaseEditorOrange, \
from orangecontrib.spectroscopy.widgets.preprocessors.utils import BaseEditorOrange, \
REFERENCE_DATA_PARAM
from orangecontrib.spectroscopy.widgets.preprocessors.registry import preprocess_editors

Expand Down Expand Up @@ -325,47 +324,33 @@ def createinstance(params):
return CurveShift(amount=amount)


class PCADenoisingEditor(BaseEditor):
class PCADenoisingEditor(BaseEditorOrange):
name = "PCA denoising"
qualname = "orangecontrib.infrared.pca_denoising"

def __init__(self, parent=None, **kwargs):
BaseEditor.__init__(self, parent, **kwargs)
self.__components = 5
super().__init__(parent, **kwargs)

self.components = 5

form = QFormLayout()
self.controlArea.setLayout(form)

self.__compspin = compspin = QSpinBox(
minimum=1, maximum=100, value=self.__components)
compspin = gui.spin(self, self, "components", minv=1, maxv=100,
step=1, callback=self._components_edited)

endlabel = QLabel("components.")
hboxLayout = QHBoxLayout()
hboxLayout.addWidget(self.__compspin)
hboxLayout.addWidget(compspin)
hboxLayout.addWidget(endlabel)

form.addRow("Keep", hboxLayout)

self.setLayout(form)

compspin.valueChanged[int].connect(self.setComponents)
compspin.editingFinished.connect(self.edited)
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)

def setComponents(self, components):
if self.__components != components:
self.__components = components
with blocked(self.__compspin):
self.__compspin.setValue(components)
self.changed.emit()

def sd(self):
return self.__components
def _components_edited(self):
self.edited.emit()

def setParameters(self, params):
self.setComponents(params.get("components", 5))

def parameters(self):
return {"components": self.__components}
self.components = params.get("components", 5)

@staticmethod
def createinstance(params):
Expand Down

0 comments on commit 17b239e

Please sign in to comment.