Commit fd9c53bf authored by Damien Naudet's avatar Damien Naudet

More work on the model.

parent 22b2b6a0
......@@ -7,9 +7,9 @@ from collections import namedtuple
from ..util.id01_spec import Id01DataMerger
from .Widgets import (AcqParamsWidget,
_AdjustedLabel,
_AdjustedLineEdit,
_AdjustedPushButton)
AdjustedLabel,
AdjustedLineEdit,
AdjustedPushButton)
from silx.gui import qt as Qt
......@@ -131,7 +131,7 @@ class _ScansSelectDialog(Qt.QDialog):
table_widget.setColumnHidden(self.M1_END_COL, True)
table_widget.setColumnHidden(self.M1_STEP_COL, True)
more_bn = _AdjustedPushButton('More')
more_bn = AdjustedPushButton('More')
layout.addWidget(more_bn, 1, 0, Qt.Qt.AlignRight)
bn_box = Qt.QDialogButtonBox(Qt.QDialogButtonBox.Ok |
......@@ -412,7 +412,7 @@ class MergeWidget(Qt.QDialog):
spec_file_edit = Qt.QLineEdit()
fm = spec_file_edit.fontMetrics()
spec_file_edit.setMinimumWidth(fm.width(' ' * 100))
spec_file_bn = _AdjustedPushButton('...')
spec_file_bn = AdjustedPushButton('...')
layout.addWidget(lab,
spec_row, label_col,
Qt.Qt.AlignLeft)
......@@ -429,7 +429,7 @@ class MergeWidget(Qt.QDialog):
img_dir_edit = Qt.QLineEdit()
fm = img_dir_edit.fontMetrics()
img_dir_edit.setMinimumWidth(fm.width(' ' * 100))
img_dir_bn = _AdjustedPushButton('...')
img_dir_bn = AdjustedPushButton('...')
layout.addWidget(lab,
img_path_row, label_col,
Qt.Qt.AlignLeft)
......@@ -465,7 +465,7 @@ class MergeWidget(Qt.QDialog):
Qt.QSizePolicy.Expanding))
# last row : apply button
parse_bn = _AdjustedPushButton('Parse file')
parse_bn = AdjustedPushButton('Parse file')
layout.addWidget(parse_bn,
apply_bn_row, 0,
1, last_col - first_col,
......@@ -490,7 +490,7 @@ class MergeWidget(Qt.QDialog):
label = Qt.QLabel('<span style=" font-weight:600; color:#00916a;">'
'Matched scans</span>')
label.setTextFormat(Qt.Qt.RichText)
edit_scans_bn = _AdjustedPushButton('Edit')
edit_scans_bn = AdjustedPushButton('Edit')
h_layout.addWidget(label)
h_layout.addWidget(edit_scans_bn)
scan_layout.addLayout(h_layout, 0, 0, 1, 2)
......@@ -538,7 +538,7 @@ class MergeWidget(Qt.QDialog):
h_layout = Qt.QHBoxLayout()
label = Qt.QLabel('<span style=" font-weight:600; color:#ff6600;">'
'Other scans</span>')
other_scans_bn = _AdjustedPushButton('View')
other_scans_bn = AdjustedPushButton('View')
h_layout.addWidget(label)
h_layout.addWidget(other_scans_bn)
......@@ -609,7 +609,7 @@ class MergeWidget(Qt.QDialog):
master_edit.setMinimumWidth(fm.width(' ' * 50))
h_layout = Qt.QHBoxLayout()
layout.addLayout(h_layout, 0, 1, Qt.Qt.AlignLeft)
reset_bn = _AdjustedPushButton('R')
reset_bn = AdjustedPushButton('R')
layout.addWidget(lab,
0, 0,
Qt.Qt.AlignLeft)
......@@ -627,7 +627,7 @@ class MergeWidget(Qt.QDialog):
outdir_edit = Qt.QLineEdit()
fm = outdir_edit.fontMetrics()
outdir_edit.setMinimumWidth(fm.width(' ' * 100))
outdir_bn = _AdjustedPushButton('...')
outdir_bn = AdjustedPushButton('...')
layout.addWidget(lab,
1, 0,
Qt.Qt.AlignLeft)
......
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
from __future__ import absolute_import
__authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "15/09/2016"
import os
from .view.RealSpaceWidget import RealSpaceWidget, RealSpaceWidgetEvent
from .process.RecipSpaceWidget import RecipSpaceWidget
from .project.XsocsProject import XsocsProject
def viewWidgetFromProjectEvent(project, event):
item = event.item
index = event.index
processLevel = item.processLevel
widget = None
if processLevel == XsocsProject.XsocsInput:
# show raw data
plotData = event.plotData()
x, y, data = plotData
widget = RealSpaceWidget(index)
widget.setPlotData(x, y, data)
elif processLevel == XsocsProject.XsocsQSpace:
# show qspace data
pass
else:
raise ValueError('Unknown process level {0}.'.format(processLevel))
return widget
# TODO : something better!
def nextFileName(root, template, cntMax=10000):
template = os.path.join(root, template)
for fIdx in range(cntMax):
nextFile = template.format(fIdx)
if not os.path.exists(nextFile):
return nextFile
else:
raise ValueError('No available file names.')
# TODO : cache the widget to reuse previous parameters?
def processWidgetFromViewEvent(project, event, parent=None):
widget = None
index = event.index
if isinstance(event, RealSpaceWidgetEvent):
xsocsPrefix = os.path.basename(project.xsocsFile).rpartition('.')[0]
template = '{0}_qspace_{{0:>04}}.h5'.format(xsocsPrefix)
output_f = nextFileName(project.workdir, template)
widget = RecipSpaceWidget(parent=parent,
index=index,
data_h5f=project.xsocsFile,
output_f=output_f,
qspace_size=None,
image_binning=None,
rect_roi=event.data)
return widget
......@@ -5,6 +5,7 @@ _MU_LOWER = u'\u03BC'
_PHI_LOWER = u'\u03C6'
_ETA_LOWER = u'\u03B7'
class AcqParamsWidget(Qt.QWidget):
def __init__(self,
......@@ -33,12 +34,12 @@ class AcqParamsWidget(Qt.QWidget):
return super(DblValidator, self).validate(text, pos)
def dblLineEditWidget(width):
wid = _AdjustedLineEdit(width,
validator_cls=DblValidator,
read_only=read_only,
reset_on_empty=True,
highlight_change=highlight_change,
field_type=float)
wid = AdjustedLineEdit(width,
validator_cls=DblValidator,
read_only=read_only,
reset_on_empty=True,
highlight_change=highlight_change,
field_type=float)
wid.setReadOnly(read_only)
return wid
......@@ -153,7 +154,7 @@ class AcqParamsWidget(Qt.QWidget):
det_mu_rb = Qt.QRadioButton(u'Width is {0}.'.format(_MU_LOWER))
h_layout.addWidget(det_mu_rb)
else:
det_orient_edit = _AdjustedLineEdit(5, read_only=True)
det_orient_edit = AdjustedLineEdit(5, read_only=True)
det_orient_edit.setAlignment(Qt.Qt.AlignCenter)
h_layout.addWidget(det_orient_edit, alignment=Qt.Qt.AlignLeft)
layout.addLayout(h_layout, row, 1)
......@@ -304,14 +305,14 @@ class AcqParamsWidget(Qt.QWidget):
self.__detector_orient = detector_orient
class _AdjustedPushButton(Qt.QPushButton):
class AdjustedPushButton(Qt.QPushButton):
"""
It seems that by default QPushButtons minimum width is 75.
This is a workaround.
For _AdjustedPushButton to work text has to be set at creation time.
"""
def __init__(self, text, padding=None, **kwargs):
super(_AdjustedPushButton, self).__init__(text, **kwargs)
def __init__(self, text, parent=None, padding=None):
super(AdjustedPushButton, self).__init__(text, parent)
fm = self.fontMetrics()
......@@ -322,27 +323,26 @@ class _AdjustedPushButton(Qt.QPushButton):
self.setMaximumWidth(width)
class _AdjustedLineEdit(Qt.QLineEdit):
class AdjustedLineEdit(Qt.QLineEdit):
"""
"""
def __init__(self,
width=None,
parent=None,
padding=None,
alignment=Qt.Qt.AlignRight,
validator_cls=None,
field_type=None,
read_only=False,
reset_on_empty=False,
highlight_change=False,
**kwargs):
super(_AdjustedLineEdit, self).__init__(**kwargs)
highlight_change=False):
super(AdjustedLineEdit, self).__init__(parent)
self.__defaultText = self.text()
self.__highlightChange = highlight_change
self.__resetOnEmpty = reset_on_empty
self.__fieldType = field_type
if width is not None:
fm = self.fontMetrics()
......@@ -385,6 +385,8 @@ class _AdjustedLineEdit(Qt.QLineEdit):
else:
pass
same_txt = False
if len(value) == 0:
if len(self.__defaultText) == 0:
same_txt = True
......@@ -398,6 +400,7 @@ class _AdjustedLineEdit(Qt.QLineEdit):
value = self.__fieldType(value)
default_value = self.__fieldType(self.__defaultText)
except:
# TODO : filter specific exception
same_txt = False
else:
default_value = self.__defaultText
......@@ -439,10 +442,10 @@ class _AdjustedLineEdit(Qt.QLineEdit):
if ev.type() == Qt.QEvent.EnabledChange:
self.style().unpolish(self)
self.style().polish(self)
return super(_AdjustedLineEdit, self).event(ev)
return super(AdjustedLineEdit, self).event(ev)
class _AdjustedLabel(Qt.QLabel):
class AdjustedLabel(Qt.QLabel):
"""
"""
def __init__(self,
......@@ -450,7 +453,7 @@ class _AdjustedLabel(Qt.QLabel):
padding=None,
alignment=Qt.Qt.AlignRight,
**kwargs):
super(_AdjustedLabel, self).__init__(**kwargs)
super(AdjustedLabel, self).__init__(**kwargs)
self.setFrameStyle(Qt.QFrame.Panel | Qt.QFrame.Sunken)
......
......@@ -27,20 +27,16 @@ from __future__ import absolute_import
import os
import numpy as np
from matplotlib import cm
from silx.gui import qt as Qt
from plot3d.IsosurfaceView import IsosurfaceView
from ..io import XsocsH5
from .Utils import (viewWidgetFromProjectEvent,
processWidgetFromViewEvent)
from .MergeWidget import MergeWidget
from .RecipSpaceWidget import RecipSpaceWidget
from .Widgets import (AcqParamsWidget,
_AdjustedLineEdit,
_AdjustedPushButton)
AdjustedLineEdit,
AdjustedPushButton)
from .project.XsocsProject import XsocsProject
from .PlotWidgets import IntensityWindow
from ..io import XsocsH5
_COMPANY_NAME = 'ESRF'
......@@ -71,58 +67,28 @@ class XsocsGui(Qt.QMainWindow):
self.__greeterDiag = None
self.__readSettings()
def __dataDockSlot(self, event):
def __projectViewSlot(self, event):
# TODO : store the plot window in a dictionary + weakref w delete
# callback when object is destroyed
type = event.type
plotData = event.plotData()
x, y, data = plotData
if type == 'scatter':
self.showScatterPlot(x, y, data)
elif type == 'image':
self.showImage(x, y, data)
def showScatterPlot(self, x, y, data):
mdi = self.centralWidget()
min_, max_ = data.min(), data.max()
colormap = cm.jet
colors = colormap((data.astype(np.float64) - min_) / (max_ - min_))
plotWin = IntensityWindow(aspectRatio=True)
plotWin = viewWidgetFromProjectEvent(self.__project, event)
plotWin.setAttribute(Qt.Qt.WA_DeleteOnClose)
plotWin.plot.addCurve(x, y, color=colors, symbol='s', linestyle='')
plotWin.sigRoiApplied.connect(self.__roiApplied)
plotWin.sigProcessApplied.connect(self.__processApplied)
mdi.addSubWindow(plotWin)
plotWin.show()
return plotWin
def showImage(self, x, y, data):
def __processApplied(self, event):
mdi = self.centralWidget()
plotWin = IntensityWindow(aspectRatio=True)
plotWin.setAttribute(Qt.Qt.WA_DeleteOnClose)
min_, max_ = data.min(), data.max()
colormap = {'name': 'temperature',
'normalization': 'linear',
'autoscale':True,
'vmin':min_,
'vmax':max_}
origin = x[0], y[0]
scale = (x[-1] - x[0]) / len(x), (y[-1] - y[0]) / len(y)
plotWin.plot.addImage(data, origin=origin, scale=scale,
colormap=colormap)
plotWin.sigRoiApplied.connect(self.__roiApplied)
mdi.addSubWindow(plotWin)
plotWin.show()
return plotWin
def __roiApplied(self, roiData):
widget = RecipSpaceWidget(data_h5f=self.__workspace.xsocsFile,
output_f=None,
qspace_size=None,
image_binning=None,
rect_roi=roiData)
widget.exec_()
if widget.result() == Qt.QDialog.Accepted:
self.__workspace.addQSpaceH5(widget.qspaceH5)
widget = processWidgetFromViewEvent(self.__project, event, parent=self)
widget.setWindowFlags(Qt.Qt.Dialog)
widget.setWindowModality(Qt.Qt.WindowModal)
widget.sigProcessDone.connect(self.__processDone)
widget.setAttribute(Qt.Qt.WA_DeleteOnClose)
widget.show()
def __processDone(self, event):
print 'event', event
def showEvent(self, event):
super(XsocsGui, self).showEvent(event)
......@@ -187,7 +153,7 @@ class XsocsGui(Qt.QMainWindow):
wkSpace.xsocsFile = xsocsH5
self.__sessionDock.widget().setXsocsWorkspace(wkSpace)
self.__dataDock.widget().setXsocsWorkspace(wkSpace)
self.__workspace = wkSpace
self.__project = wkSpace
self.__closeGreeter()
......@@ -292,7 +258,7 @@ class XsocsGui(Qt.QMainWindow):
plotDataDock.setWidget(PlotDataWidget())
plotDataDock.setObjectName('DataDock')
self.addDockWidget(Qt.Qt.LeftDockWidgetArea, plotDataDock)
plotDataDock.widget().sigItemEvent.connect(self.__dataDockSlot,
plotDataDock.widget().sigViewEvent.connect(self.__projectViewSlot,
Qt.Qt.QueuedConnection)
def __writeSettings(self):
......@@ -347,7 +313,7 @@ class XsocsGui(Qt.QMainWindow):
class PlotDataWidget(Qt.QWidget):
sigItemEvent = Qt.Signal(object)
sigViewEvent = Qt.Signal(object)
def __init__(self, parent=None):
super(PlotDataWidget, self).__init__(parent)
......@@ -369,7 +335,7 @@ class PlotDataWidget(Qt.QWidget):
self.__treeView.deleteLater()
self.__treeView = None
view = self.__xsocsProject.view(parent=self)
view.sigItemEvent.connect(self.sigItemEvent)
view.sigItemEvent.connect(self.sigViewEvent)
self.layout().addWidget(view)
self.__treeView = view
......@@ -392,7 +358,7 @@ class SessionWidget(Qt.QWidget):
# #########
gbox = Qt.QGroupBox('XSocs file')
boxLayout = Qt.QVBoxLayout(gbox)
self.__fileLabel = fileLabel = _AdjustedLineEdit(read_only=True)
self.__fileLabel = fileLabel = AdjustedLineEdit(read_only=True)
fileLabel.setAlignment(Qt.Qt.AlignLeft)
boxLayout.addWidget(fileLabel)
......@@ -406,18 +372,18 @@ class SessionWidget(Qt.QWidget):
# number of angles
rowIdx = 0
self.__anglesText = anglesText = _AdjustedLineEdit(3, read_only=True)
self.__anglesText = anglesText = AdjustedLineEdit(3, read_only=True)
gridLayout.addWidget(Qt.QLabel('# angles :'),
rowIdx, 0, alignment=Qt.Qt.AlignLeft)
gridLayout.addWidget(anglesText,
rowIdx, 1, alignment=Qt.Qt.AlignLeft)
rowIdx += 1
self.__nImgText = nImgText = _AdjustedLineEdit(5, read_only=True)
self.__nImgText = nImgText = AdjustedLineEdit(5, read_only=True)
gridLayout.addWidget(Qt.QLabel('Images :'),
rowIdx, 0, alignment=Qt.Qt.AlignLeft)
gridLayout.addWidget(nImgText, rowIdx, 1, alignment=Qt.Qt.AlignLeft)
self.__imgSizeText = imgSizeText = _AdjustedLineEdit(10, read_only=True)
self.__imgSizeText = imgSizeText = AdjustedLineEdit(10, read_only=True)
gridLayout.addWidget(Qt.QLabel('Size :'),
rowIdx, 2, alignment=Qt.Qt.AlignLeft)
gridLayout.addWidget(imgSizeText, rowIdx, 3, alignment=Qt.Qt.AlignLeft)
......@@ -528,9 +494,9 @@ class _WorkspaceDirDialog(Qt.QDialog):
layout = Qt.QGridLayout(self)
label = Qt.QLabel('Workspace :')
lineEdit = _AdjustedLineEdit(40)
lineEdit = AdjustedLineEdit(40)
lineEdit.setAlignment(Qt.Qt.AlignLeft)
pickButton = _AdjustedPushButton('...')
pickButton = AdjustedPushButton('...')
layout.addWidget(label,
0, 0,
Qt.Qt.AlignLeft)
......
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
from __future__ import absolute_import
__authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "15/09/2016"
import sys
from silx.gui import qt as Qt
print('Using Qt {0}'.format(Qt.qVersion()))
from XsocsGui import XsocsGui
from .XsocsGui import XsocsGui
from .MergeWidget import MergeWidget
from .RecipSpaceWidget import RecipSpaceWidget
from .process.RecipSpaceWidget import RecipSpaceWidget
def merge_window(*args, **kwargs):
app = Qt.QApplication(sys.argv)
......@@ -13,12 +45,14 @@ def merge_window(*args, **kwargs):
mw.show()
app.exec_()
def conversion_window(*args, **kwargs):
app = Qt.QApplication(sys.argv)
mw = RecipSpaceWidget(*args, **kwargs)
mw.show()
app.exec_()
def xsocs_main(*args, **kwargs):
app = Qt.QApplication(sys.argv)
mw = XsocsGui(*args, **kwargs)
......
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
from __future__ import absolute_import
__authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "15/09/2016"
from collections import namedtuple
from silx.gui import qt as Qt
ProcessResult = namedtuple('ProcessResult', ['status', 'data'])
class ProcessWidget(Qt.QMainWindow):
sigProcessDone = Qt.Signal(object)
(StatusUnknown, StatusInit, StatusRunning, StatusCompleted, StatusAborted,
StatusCanceled) = StatusList = range(6)
def __init__(self, index=None, parent=None, **kwargs):
super(ProcessWidget, self).__init__(parent, **kwargs)
self.__index = index
self.__status = ProcessWidget.StatusInit
status = property(lambda self: self.__status)
def _setStatus(self, status):
if status not in ProcessWidget.StatusList:
raise ValueError('Unknown status value : {0}.'
''.format(status))
self.__status = status
def processResult(self):
return ProcessResult(status=self.status, data=self._processData())
def _processData(self):
return None
def _emitEvent(self, event):
self.sigProcessDone.emit(event)
index = property(lambda self: self.__index)
class ProcessWidgetEvent(object):
def __init__(self, widget, data=None):
super(ProcessWidgetEvent, self).__init__()
self.__index = widget.index
self.__data = data
data = property(lambda self: self.__data)
index = property(lambda self: self.__index)
......@@ -75,18 +75,13 @@ class HybridItemDelegate(Qt.QWidget):
def __onClicked(self, checked, type=None):
obj = self.__index.data(Hdf5TreeModel.H5PY_OBJECT_ROLE)
instance = ProjectItem.load(obj.file.filename, obj.name)
event = HybridItemEvent(instance, type)
# TODO : weakref, or make sure persistent.isValid returns False if
# model item is destroyed.
event = HybridItemEvent(instance, type, self.__index)
self.sigEditorEvent.emit(event)
def sizeHint(self):
print super(HybridItem, self).sizeHint()
return Qt.QSize(0, 0)
# def sizeHint(self):
# # TODO connect to cell resize
# if self.__sizeHint:
# return self.parent().sizeHint()
# # return Qt.QSize(self.__sizeHint)
# return super(XsocsProjectDataGroupDelegate, self).sizeHint()
@ItemClassDef('HybridItem', editor=HybridItemDelegate)
......
......@@ -66,32 +66,43 @@ class ProjectItem(object):
viewShowChildren = True
icon = None
XsocsNone, XsocsInput, XsocsQSpace, XsocsFit = range(4)
def __init__(self, h5File, nodePath, processLevel=None):
# TODO : check if parent already has a child with the same name
super(ProjectItem, self).__init__()
self.__nodePath = nodePath
self.__h5File = h5File
self.__processLevel = processLevel or ProjectItem.XsocsNone
self.__processLevel = None
self.__processLevelIn = processLevel
path = property(lambda self: self.__nodePath)
file = property(lambda self: self.__h5File)
dataLevel = property(lambda self: self.__dataLevel)
@property
def processLevel(self):
if self.__processLevel is None:
if self.__processLevelIn is None:
with h5py.File(self.__h5File, 'r') as h5f:
processLevel = h5f[self.__nodePath].attrs.get('XsocsLevel')
self.__processLevel = processLevel
else:
self.__processLevel = self.__processLevelIn
return self.__processLevel
def _commit(self):
with h5py.File(self.file, 'a') as h5f:
grp = h5f.require_group(self.path)
grp.attrs.update({'XsocsType': self.itemName})
grp.attrs.update({'XsocsLevel': self.__processLevel or 'None'})
grp.attrs['XsocsType'] = self.itemName
if self.__processLevelIn is not None:
grp.attrs['XsocsLevel'] = self.__processLevelIn
del grp
@classmethod
def load(cls, h5File, groupPath):
with h5py.File(h5File, 'r') as h5f:
grp = h5f[groupPath]
xsocsType = grp.attrs.get('XsocsType')
del grp
if xsocsType is None:
return None
klass = _registeredItems.get(xsocsType)
......@@ -102,10 +113,11 @@ class ProjectItem(object):
class ItemEvent(object):
def __init__(self, item, eventType):
def __init__(self, item, eventType, index):
super(ItemEvent, self).__init__()
self.__item = item
self.__type = eventType
self.__index = index
def plotData(self):
raise NotImplementedError('')
......@@ -113,3 +125,5 @@ class ItemEvent(object):
type = property(lambda self: self.__type)
item = property(lambda self: self.__item)
index = property(lambda self: self.__index)
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# t