Commit 969641f8 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[orangecontrib][transformation] Add combobox for changing widget btwn rsm and...

[orangecontrib][transformation] Add combobox for changing widget btwn rsm and magnification (when dim.size=1)
parent 67f8b967
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"] __authors__ = ["J. Garriga"]
__license__ = "MIT" __license__ = "MIT"
__date__ = "16/07/2021" __date__ = "10/08/2021"
from Orange.widgets.settings import Setting from Orange.widgets.settings import Setting
...@@ -55,12 +55,19 @@ class TransformationWidgetOW(OWWidget): ...@@ -55,12 +55,19 @@ class TransformationWidgetOW(OWWidget):
magnification = Setting(float(), schema_only=True) magnification = Setting(float(), schema_only=True)
pixelSize = Setting(str(), schema_only=True) pixelSize = Setting(str(), schema_only=True)
kind = Setting(bool(), schema_only=True)
rotate = Setting(bool(), schema_only=True) rotate = Setting(bool(), schema_only=True)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
qt.QLocale.setDefault(qt.QLocale("en_US")) qt.QLocale.setDefault(qt.QLocale("en_US"))
self._widget = None self._widget = None
# Add combobox to choose between RSM and magnification (in one dimension case)
self._methodCB = qt.QComboBox(self)
self._methodCB.addItems(["RSM", "Magnification"])
self._methodCB.hide()
self.controlArea.layout().addWidget(self._methodCB)
self._methodCB.currentTextChanged.connect(self._changeWidget)
@Inputs.dataset @Inputs.dataset
def setDataset(self, dataset): def setDataset(self, dataset):
...@@ -68,6 +75,7 @@ class TransformationWidgetOW(OWWidget): ...@@ -68,6 +75,7 @@ class TransformationWidgetOW(OWWidget):
self.controlArea.layout().removeWidget(self._widget) self.controlArea.layout().removeWidget(self._widget)
self._widget.hide() self._widget.hide()
if dataset: if dataset:
self._dataset = dataset
if not dataset[0].dims.ndim: if not dataset[0].dims.ndim:
msg = qt.QMessageBox() msg = qt.QMessageBox()
msg.setIcon(qt.QMessageBox.Warning) msg.setIcon(qt.QMessageBox.Warning)
...@@ -76,31 +84,53 @@ class TransformationWidgetOW(OWWidget): ...@@ -76,31 +84,53 @@ class TransformationWidgetOW(OWWidget):
msg.exec_() msg.exec_()
else: else:
if dataset[0].dims.ndim == 1: if dataset[0].dims.ndim == 1:
self._widget = RSMWidget(parent=self) self._methodCB.show()
if self.pixelSize: self._changeWidget("RSM")
self._widget.pixelSize = self.pixelSize
self._widget.rotate = self.rotate
else: else:
self._methodCB.hide()
self._widget = MagnificationWidget(parent=self) self._widget = MagnificationWidget(parent=self)
if self.magnification: if self.magnification:
self._widget.magnification = self.magnification self._widget.magnification = self.magnification
self._widget.sigComputed.connect(self._sendSignal) self._widget.sigComputed.connect(self._sendSignal)
self.controlArea.layout().addWidget(self._widget) self.controlArea.layout().addWidget(self._widget)
self._widget.setDataset(*dataset) self._widget.setDataset(*dataset)
else: else:
# Emit None # Emit None
self.Outputs.dataset.send(dataset) self.Outputs.dataset.send(dataset)
self.open() self.open()
def _changeWidget(self, method):
"""
Change the widget displayed on the window
"""
if self._widget:
self.controlArea.layout().removeWidget(self._widget)
self._widget.hide()
if method == "RSM":
self._widget = RSMWidget(parent=self)
if self.pixelSize:
self._widget.pixelSize = self.pixelSize
self._widget.rotate = self.rotate
else:
self._widget = MagnificationWidget(parent=self)
if self.magnification:
self._widget.magnification = self.magnification
self._widget.sigComputed.connect(self._sendSignal)
self.controlArea.layout().addWidget(self._widget)
self._widget.setDataset(*self._dataset)
def _sendSignal(self): def _sendSignal(self):
""" """
Emits the signal with the new dataset. Emits the signal with the new dataset.
""" """
if hasattr(self._widget, 'magnification'): if hasattr(self._widget, 'magnification'):
self.magnification = self._widget.magnification self.magnification = self._widget.magnification
self.kind=False
elif hasattr(self._widget, 'pixelSize'): elif hasattr(self._widget, 'pixelSize'):
self.pixelSize = self._widget.pixelSize self.pixelSize = self._widget.pixelSize
self.rotate = self._widget.rotate self.rotate = self._widget.rotate
self.kind=True
self.close() self.close()
self.Outputs.dataset.send(self._widget.getDataset()) self.Outputs.dataset.send(self._widget.getDataset())
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