Commit 1ac78122 authored by payno's avatar payno

Add DimensionMapping widget to define dimension. Not linked yet with the Geometry widget

parent eb765344
......@@ -43,6 +43,7 @@ class TestOperationStream(unittest.TestCase):
root_folder = '/nobackup/linazimov/payno/datasets/id06/strain_scan'
data_file_pattern = os.path.join(root_folder, 'reduced_strain/strain_0000.edf')
assert os.path.exists(data_file_pattern)
data_bb_files = []
bb_folder = os.path.join(root_folder, 'bg_ff_5s_1x1')
for _file in os.listdir(bb_folder):
......
......@@ -30,6 +30,7 @@ __date__ = "03/10/2018"
from silx.gui import qt
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from id06workflow.core.experiment import _METADATA_TYPES, _Dim
from id06workflow.gui.utils import _IllustrationWidget
from id06workflow.core.utils.char import THETA_CHAR
import logging
......@@ -191,5 +192,187 @@ class DimensionMapping(qt.QWidget):
Widget used to define the number of dimension and with which values they are
mapped
"""
_V_HEADERS = ['Axis', 'Kind', 'Name', 'Size', 'Is relative', '']
def __init__(self, parent):
pass
qt.QWidget.__init__(self, parent)
self.setLayout(qt.QGridLayout())
self._table = qt.QTableWidget(parent=self)
self._table.setColumnCount(6)
self._table.setHorizontalHeaderLabels(self._V_HEADERS)
self._table.verticalHeader().hide()
self._dims = {}
self.layout().addWidget(self._table, 0, 0, 6, 6)
self._addButton = qt.QPushButton('add dimension', parent=self)
self.layout().addWidget(self._addButton, 6, 5, 1, 1)
@property
def ndim(self):
return len(self._dims)
def addDim(self, axis=None, dim=None):
"""
:param axis: which axis is defining this dimension
:param :class:_Dim dim: definition of the dimension to add
"""
if axis is None:
axis = self._getNextFreeAxis()
row = self._table.rowCount()
self._table.setRowCount(row + 1)
widget = _DimensionItem(parent=self, table=self._table, row=row)
widget.removed.connect(self.removeDim)
if dim is not None:
widget.setDim(dim)
widget.axis = axis
self._dims[row] = widget
return widget
def removeDim(self, row):
"""
:param int or _DimensionItem row: row or item to remove
"""
if isinstance(row, _DimensionItem):
iRow = row._row
else:
iRow = row
self._table.setRowCount(self._table.rowCount() - 1)
self._table.removeRow(iRow)
self._dims[iRow].removed.disconnect(self.removeDim)
self._dims[iRow].setAttribute(qt.Qt.WA_DeleteOnClose)
self._dims[iRow].close()
del self._dims[iRow]
ini_rows = sorted(list(self._dims.keys()))
for row in ini_rows:
if row <= iRow:
continue
widget = self._dims[row]
new_row = row - 1
assert new_row >= 0
widget.embedInTable(table=self._table, row=new_row)
self._dims[new_row] = widget
del self._dims[row]
def _getNextFreeAxis(self):
"""
:return int: next unused axis
"""
res = 0
usedAxis = []
[usedAxis.append(_dim.axis) for _dim in self._dims.values()]
while res in usedAxis:
res = res + 1
return res
class _DimensionItem(qt.QWidget):
"""Widget use to define a dimension"""
removed = qt.Signal(qt.QObject)
"""Signal emitted when the Item should be removed"""
dimValueChanged = qt.Signal()
"""Signal emitted when the dimension definition is changed"""
axisChanged = qt.Signal(int, int)
"""Signal emitted when the axis value is changed: id (row), new_value_value
"""
def __init__(self, parent, table, row):
"""
:param QTableWidget table: if has to be embed in a table the
parent table
:param int row: row position in the QTableWidget. Also used as ID
"""
qt.QWidget.__init__(self, parent)
# axis
self._axis = qt.QSpinBox(parent=self)
self._axis.setMinimum(0)
# kind
self._kind = qt.QComboBox(parent=self)
for _kindName in _METADATA_TYPES:
self._kind.addItem(_kindName)
# name
self._names = qt.QComboBox(parent=self)
# size
self._size = qt.QSpinBox(parent=self)
self._size.setMinimum(0)
# relative
self._relative = qt.QCheckBox(parent=self)
self._relative.setVisible(False)
# rm button
style = qt.QApplication.style()
icon = style.standardIcon(qt.QStyle.SP_BrowserStop)
self._rmButton = qt.QPushButton(icon=icon, parent=self)
# connect Signal/slot
self._rmButton.pressed.connect(self.remove)
self._relative.toggled.connect(self._size.setVisible)
self._axis.valueChanged.connect(self._axisHasChanged)
self._kind.currentIndexChanged.connect(self._dimHasChanged)
self._size.valueChanged.connect(self._dimHasChanged)
self._names.currentIndexChanged.connect(self._dimHasChanged)
self._relative.toggled.connect(self._dimHasChanged)
self.embedInTable(table=table, row=row)
self.__row = row
def _axisHasChanged(self, value):
self.axisChanged.emit(self._row, value)
def _dimHasChanged(self, *args, **kwargs):
self.dimValueChanged.emit()
def remove(self):
self.removed.emit(self)
@property
def _row(self):
return self.__row
@property
def axis(self):
return self._axis.value()
@axis.setter
def axis(self, axis):
assert type(axis) is int
self._axis.setValue(axis)
@property
def kind(self):
return self._kind.currentText()
@property
def dim(self):
return _Dim(name=self.name, kind=self.kind, size=self.dimsize,
relative_prev_val=self.relative)
@property
def dimsize(self):
if self.relative is True:
return self._size.value()
else:
return None
@property
def relative(self):
return self._relative.isChecked()
@property
def name(self):
return self._names.currentText()
def setNames(self, names):
self._names.clear()
for name in names:
self._names.addItem(name)
def embedInTable(self, table, row):
self.__row = row
for column, widget in enumerate((self._axis, self._kind, self._names,
self._size, self._relative, self._rmButton)):
table.setCellWidget(row, column, widget)
......@@ -29,8 +29,9 @@ __date__ = "03/10/2018"
import unittest
from id06workflow.gui.geometry import TwoThetaGeometryWidget
from id06workflow.gui.geometry import TwoThetaGeometryWidget, DimensionMapping
from silx.gui.utils.testutils import TestCaseQt
from silx.gui import qt
class TestTwoThetaExpSetupGUI(TestCaseQt):
......@@ -46,9 +47,42 @@ class TestTwoThetaExpSetupGUI(TestCaseQt):
widget = TwoThetaGeometryWidget
# TODO: look, not orking with the TestCaseQt, has unreleased widgets
class TestDimensionMapping(unittest.TestCase):
"""
Make sure the :class:`DimensionMapping` is correctly adding and removing
dimension items
"""
def setUp(self):
unittest.TestCase.setUp(self)
self._app = qt.QApplication.instance() or qt.QApplication([])
self.widget = DimensionMapping(parent=None)
def tearDown(self):
self.widget.setAttribute(qt.Qt.WA_DeleteOnClose)
self.widget.close()
unittest.TestCase.tearDown(self)
def testAddRmItems(self):
"""
Make sure adding and removing dimension items are correct
"""
dim1 = self.widget.addDim()
dim2 = self.widget.addDim()
self.assertTrue(self.widget.ndim is 2)
self.assertTrue(dim1.axis is 0)
self.assertTrue(dim2.axis is 1)
dim1.axis = 4
self.assertTrue(dim1.axis is 4)
self.widget.removeDim(dim1)
self.assertTrue(self.widget.ndim is 1)
dim2.remove()
self.assertTrue(self.widget.ndim is 0)
def suite():
test_suite = unittest.TestSuite()
for ui in (TestTwoThetaExpSetupGUI, ):
for ui in (TestTwoThetaExpSetupGUI, TestDimensionMapping):
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui))
return test_suite
......
......@@ -100,16 +100,14 @@ class TestTrueData(OrangeWorflowTest):
OrangeWorflowTest.tearDown(self)
def createDataset(self):
data_files = []
dir_data = '/users/payno/datasets/id06/strain_scan/strain/'
for _file in os.listdir(dir_data)[::6]:
data_files.append(os.path.join(dir_data, _file))
data_file_pattern = '/users/payno/datasets/id06/strain_scan/reduced_strain/strain_0000.edf'
assert os.path.exists(data_file_pattern)
ff_files = []
dir_ff = "/users/payno/datasets/id06/strain_scan/bg_ff_5s_1x1/"
[ff_files.append(os.path.join(dir_data, _file)) for _file in os.listdir(dir_ff)]
[ff_files.append(os.path.join(dir_ff, _file)) for _file in os.listdir(dir_ff)]
return Dataset(data_files_pattern=data_files, ff_files=ff_files)
return Dataset(data_files_pattern=data_file_pattern, ff_files=ff_files)
def _moveToNextStep(self):
app.processEvents()
......@@ -147,7 +145,6 @@ class TestTrueData(OrangeWorflowTest):
self._noiseReductionWidget.validate()
self._shiftCorrectionWidget.hide()
self._moveToNextStep()
app.exec_()
# manage shift correction
self.assertTrue(self._shiftCorrectionWidget._editedExperiment is not None)
......
Markdown is supported
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