Commit 3960e2fd authored by Valentin Valls's avatar Valentin Valls
Browse files

Pluginify the filters in the GUI

parent 5eef97a6
......@@ -35,6 +35,9 @@ class DerivativeData(NamedTuple):
class DerivativeItem(ComputedCurveItem, plot_model.IncrementalComputableMixIn):
"""This item use the scan data to process result before displaying it."""
NAME = "Derivative function"
ICON_NAME = "flint:icons/item-func"
EXTRA_POINTS = 5
"""Extra points needed before and after a single point to compute a result"""
......
......@@ -35,6 +35,9 @@ class GaussianFitData(NamedTuple):
class GaussianFitItem(ComputedCurveItem, plot_model.ComputableMixIn):
"""This item use the scan data to process result before displaying it."""
NAME = "Gaussian fit"
ICON_NAME = "flint:icons/item-func"
def __getstate__(self):
state: Dict[str, Any] = {}
state.update(plot_model.ChildItem.__getstate__(self))
......
......@@ -33,6 +33,9 @@ class MaxData(NamedTuple):
class MaxCurveItem(CurveStatisticItem, plot_model.IncrementalComputableMixIn):
"""Statistic identifying the maximum location of a curve."""
NAME = "Max marker"
ICON_NAME = "flint:icons/item-stats"
def name(self) -> str:
return "Max"
......
......@@ -33,6 +33,9 @@ class MinData(NamedTuple):
class MinCurveItem(CurveStatisticItem, plot_model.IncrementalComputableMixIn):
"""Statistic identifying the minimum location of a curve."""
NAME = "Min marker"
ICON_NAME = "flint:icons/item-stats"
def name(self) -> str:
return "Min"
......
......@@ -34,6 +34,9 @@ class NegativeData(NamedTuple):
class NegativeItem(ComputedCurveItem, plot_model.IncrementalComputableMixIn):
"""This item use a curve item to negative it."""
NAME = "Negative function"
ICON_NAME = "flint:icons/item-func"
def __init__(self, parent=None):
ComputedCurveItem.__init__(self, parent=parent)
plot_model.IncrementalComputableMixIn.__init__(self)
......
......@@ -27,6 +27,9 @@ _logger = logging.getLogger(__name__)
class NormalizedCurveItem(plot_model.ChildItem, plot_item_model.CurveMixIn):
"""Curve based on a source item, normalized by a side channel."""
NAME = "Normalized function"
ICON_NAME = "flint:icons/item-func"
def __init__(self, parent=None):
plot_model.ChildItem.__init__(self, parent)
plot_item_model.CurveMixIn.__init__(self)
......
......@@ -62,6 +62,9 @@ class NormalizedZeroOneItem(ComputedCurveItem, plot_model.IncrementalComputableM
and 1.
"""
NAME = "Normalized range"
ICON_NAME = "flint:icons/item-func"
def __init__(self, parent=None):
ComputedCurveItem.__init__(self, parent=parent)
plot_model.IncrementalComputableMixIn.__init__(self)
......
......@@ -270,72 +270,34 @@ class _AddItemAction(qt.QWidgetAction):
menu: qt.QMenu = self.sender()
menu.clear()
availableItemFactory = {
MaxCurveItem: None,
MinCurveItem: None,
DerivativeItem: None,
NegativeItem: None,
GaussianFitItem: None,
NormalizedCurveItem: self.__createNormalized,
NormalizedZeroOneItem: None,
}
item = self.parent().selectedPlotItem()
if isinstance(item, plot_item_model.CurveMixIn):
menu.addSection("Statistics")
action = qt.QAction(self)
action.setText("Max marker")
icon = icons.getQIcon("flint:icons/item-stats")
action.setIcon(icon)
action.triggered.connect(
functools.partial(self.__createChildItem, MaxCurveItem)
)
menu.addAction(action)
action = qt.QAction(self)
action.setText("Min marker")
icon = icons.getQIcon("flint:icons/item-stats")
action.setIcon(icon)
action.triggered.connect(
functools.partial(self.__createChildItem, MinCurveItem)
)
menu.addAction(action)
menu.addSection("Functions")
action = qt.QAction(self)
action.setText("Derivative function")
icon = icons.getQIcon("flint:icons/item-func")
action.setIcon(icon)
action.triggered.connect(
functools.partial(self.__createChildItem, DerivativeItem)
)
menu.addAction(action)
action = qt.QAction(self)
action.setText("Negative function")
icon = icons.getQIcon("flint:icons/item-func")
action.setIcon(icon)
action.triggered.connect(
functools.partial(self.__createChildItem, NegativeItem)
)
menu.addAction(action)
action = qt.QAction(self)
action.setText("Gaussian fit")
icon = icons.getQIcon("flint:icons/item-func")
action.setIcon(icon)
action.triggered.connect(
functools.partial(self.__createChildItem, GaussianFitItem)
)
menu.addAction(action)
action = qt.QAction(self)
action.setText("Normalized function")
icon = icons.getQIcon("flint:icons/item-func")
action.setIcon(icon)
action.triggered.connect(self.__createNormalized)
menu.addAction(action)
action = qt.QAction(self)
action.setText("Normalized range")
icon = icons.getQIcon("flint:icons/item-func")
action.setIcon(icon)
action.triggered.connect(
functools.partial(self.__createChildItem, NormalizedZeroOneItem)
)
menu.addAction(action)
for className, chassFactory in availableItemFactory.items():
try:
name = className.NAME
except Exception:
name = className.__name__
if chassFactory is None:
chassFactory = functools.partial(self.__createChildItem, className)
action = qt.QAction(self)
action.setText(name)
icon = icons.getQIcon("flint:icons/item-stats")
action.setIcon(icon)
action.triggered.connect(chassFactory)
menu.addAction(action)
else:
action = qt.QAction(self)
action.setText("No available items")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment