Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xsocs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
22
Issues
22
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kmap
xsocs
Commits
a1ddd730
Commit
a1ddd730
authored
Jan 10, 2017
by
Damien Naudet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FitModel moved to own file.
parent
334327c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
113 deletions
+88
-113
kmap/gui/view/__init__.py
kmap/gui/view/__init__.py
+30
-0
kmap/gui/view/fitview/FitModel.py
kmap/gui/view/fitview/FitModel.py
+58
-113
No files found.
kmap/gui/view/__init__.py
View file @
a1ddd730
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2017 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__
=
"01/01/2017"
kmap/gui/view/fitview/FitModel.py
View file @
a1ddd730
...
...
@@ -33,30 +33,22 @@ __date__ = "01/01/2017"
import
numpy
as
np
from
silx.gui
import
qt
as
Qt
from
silx.gui.plot
import
PlotWindow
,
PlotWidget
from
matplotlib
import
cm
from
kmap.gui.model.Model
import
Model
,
RootNode
from
kmap.gui.project.Hdf5Nodes
import
H5File
from
kmap.gui.model.ModelDef
import
ModelRoles
,
ModelColumns
from
kmap.gui.project.XsocsH5Factory
import
h5NodeToProjectItem
from
kmap.gui.widgets.Containers
import
GroupBox
from
kmap.gui.model.ModelDef
import
ModelRoles
from
kmap.io.FitH5
import
FitH5
from
..widgets.XsocsPlot2D
import
XsocsPlot2D
from
kmap.gui.model.TreeView
import
TreeView
from
kmap.gui.model.NodeEditor
import
EditorMixin
from
kmap.gui.project.Hdf5Nodes
import
H5Base
,
H5NodeClassDef
from
...widgets.XsocsPlot2D
import
XsocsPlot2D
from
...project.Hdf5Nodes
import
H5Base
,
H5NodeClassDef
class
FitResultEditor
(
EditorMixin
,
PlotWidget
):
class
PlotGrabber
(
XsocsPlot2D
):
persistent
=
True
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
FitResultEdito
r
,
self
).
__init__
(
*
args
,
**
kwargs
)
super
(
PlotGrabbe
r
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
_backend
.
_enableAxis
(
'left'
,
False
)
self
.
_backend
.
_enableAxis
(
'right'
,
False
)
self
.
_backend
.
ax
.
get_xaxis
().
set_visible
(
False
)
...
...
@@ -65,34 +57,18 @@ class FitResultEditor(EditorMixin, PlotWidget):
self
.
setActiveCurveHandling
(
False
)
self
.
setKeepDataAspectRatio
(
True
)
self
.
setDataMargins
(
0
,
0
,
0
,
0
)
self
.
setCollaspibleMenuVisible
(
False
)
self
.
setPointWidgetVisible
(
False
)
def
setEditorData
(
self
,
index
):
node
=
index
.
data
(
ModelRoles
.
InternalDataRole
)
if
node
and
not
node
.
setEditorData
(
self
,
index
.
column
()):
value
=
index
.
data
(
Qt
.
Qt
.
EditRole
)
return
self
.
setModelValue
(
value
)
return
True
def
setModelValue
(
self
,
value
):
return
False
def
getEditorData
(
self
):
pass
def
sizeHint
(
self
):
return
Qt
.
QSize
(
100
,
100
)
def
minimumSizeHint
(
self
):
return
Qt
.
QSize
(
100
,
100
)
def
maximumSize
(
self
):
return
Qt
.
QSize
(
100
,
100
)
def
toPixmap
(
self
):
return
Qt
.
QPixmap
.
grabWidget
(
self
)
@
H5NodeClassDef
(
'FitH5'
)
class
FitH5Node
(
H5File
):
"""
Node linked to a FitH5 file.
"""
# TODO : check the file format (make sure that all required
# groups/datasets are there)
...
...
@@ -111,6 +87,9 @@ class FitH5Node(H5File):
@
H5NodeClassDef
(
'FitEntry'
)
class
FitEntryNode
(
H5Base
):
"""
Node linked to an entry in a FitH5 file.
"""
entry
=
property
(
lambda
self
:
self
.
h5Path
.
lstrip
(
'/'
).
split
(
'/'
)[
0
])
...
...
@@ -129,6 +108,9 @@ class FitEntryNode(H5Base):
class
FitProcessNode
(
FitEntryNode
):
"""
Node linked to a process group in a FitH5 file.
"""
process
=
property
(
lambda
self
:
self
.
h5Path
.
split
(
'/'
)[
1
])
def
_loadChildren
(
self
):
...
...
@@ -147,6 +129,9 @@ class FitProcessNode(FitEntryNode):
class
FitResultNode
(
FitProcessNode
):
"""
Node linked to a result group in a FitH5 file.
"""
result
=
property
(
lambda
self
:
self
.
h5Path
.
split
(
'/'
)[
-
1
])
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -154,96 +139,56 @@ class FitResultNode(FitProcessNode):
super
(
FitResultNode
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
_setupNode
(
self
):
self
.
setData
(
1
,
'Qx'
,
Qt
.
Qt
.
DisplayRole
)
self
.
setData
(
1
,
Qt
.
Qt
.
AlignCenter
,
Qt
.
Qt
.
TextAlignmentRole
)
self
.
setData
(
2
,
'Qy'
,
Qt
.
Qt
.
DisplayRole
)
self
.
setData
(
2
,
Qt
.
Qt
.
AlignCenter
,
Qt
.
Qt
.
TextAlignmentRole
)
self
.
setData
(
3
,
'Qz'
,
Qt
.
Qt
.
DisplayRole
)
self
.
setData
(
3
,
Qt
.
Qt
.
AlignCenter
,
Qt
.
Qt
.
TextAlignmentRole
)
def
_loadChildren
(
self
):
return
[
FitThumbnailNode
(
self
.
h5File
,
self
.
h5Path
)]
plot
=
PlotGrabber
()
plot
.
setFixedSize
(
Qt
.
QSize
(
100
,
100
))
plot
.
toPixmap
()
qApp
=
Qt
.
qApp
qApp
.
processEvents
()
class
FitThumbnailNode
(
FitResultNode
):
editors
=
[
None
,
FitResultEditor
,
FitResultEditor
,
FitResultEditor
]
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
dragEnabledColumns
=
[
False
,
True
,
True
,
True
]
super
(
FitThumbnailNode
,
self
).
__init__
(
*
args
,
**
kwargs
)
with
FitH5
(
self
.
h5File
)
as
fitH5
:
x
=
fitH5
.
scan_x
(
self
.
entry
)
y
=
fitH5
.
scan_y
(
self
.
entry
)
def
_setupNode
(
self
):
self
.
setData
(
ModelColumns
.
NameColumn
,
None
,
Qt
.
Qt
.
DisplayRole
)
data
=
fitH5
.
get_qx_result
(
self
.
entry
,
self
.
process
,
self
.
result
)
plot
.
setPlotData
(
x
,
y
,
data
)
pixmap
=
plot
.
toPixmap
()
self
.
setData
(
1
,
pixmap
,
Qt
.
Qt
.
DecorationRole
)
qApp
.
processEvents
()
data
=
fitH5
.
get_qy_result
(
self
.
entry
,
self
.
process
,
self
.
result
)
plot
.
setPlotData
(
x
,
y
,
data
)
pixmap
=
plot
.
toPixmap
()
self
.
setData
(
2
,
pixmap
,
Qt
.
Qt
.
DecorationRole
)
qApp
.
processEvents
()
data
=
fitH5
.
get_qz_result
(
self
.
entry
,
self
.
process
,
self
.
result
)
plot
.
setPlotData
(
x
,
y
,
data
)
pixmap
=
plot
.
toPixmap
()
self
.
setData
(
3
,
pixmap
,
Qt
.
Qt
.
DecorationRole
)
qApp
.
processEvents
()
def
_loadChildren
(
self
):
return
[]
def
sizeHint
(
self
,
column
):
if
column
==
ModelColumns
.
ValueColumn
:
return
Qt
.
QSize
(
100
,
100
)
return
super
(
FitResultNode
,
self
).
sizeHint
(
column
)
def
setEditorData
(
self
,
editor
,
column
):
if
not
isinstance
(
editor
,
FitResultEditor
):
return
False
with
FitH5
(
self
.
h5File
)
as
fitH5
:
x
=
fitH5
.
scan_x
(
self
.
entry
)
y
=
fitH5
.
scan_y
(
self
.
entry
)
if
column
==
1
:
data
=
fitH5
.
get_qx_result
(
self
.
entry
,
self
.
process
,
self
.
result
)
elif
column
==
2
:
data
=
fitH5
.
get_qy_result
(
self
.
entry
,
self
.
process
,
self
.
result
)
else
:
data
=
fitH5
.
get_qz_result
(
self
.
entry
,
self
.
process
,
self
.
result
)
min_
,
max_
=
data
.
min
(),
data
.
max
()
colormap
=
cm
.
jet
colors
=
colormap
(
(
data
.
astype
(
np
.
float64
)
-
min_
)
/
(
max_
-
min_
))
editor
.
addCurve
(
x
,
y
,
color
=
colors
,
symbol
=
's'
,
linestyle
=
''
)
return
True
def
_setModelData
(
self
,
editor
,
column
):
"""
This is called by the View's delegate just before the editor is closed,
it allows this item to update itself with data from the editor.
:param editor:
:return:
"""
return
False
def
_openedEditorEvent
(
self
,
editor
,
column
,
args
=
None
,
kwargs
=
None
):
"""
This is called by custom editors while they're opened in the view.
See ItemDelegate.__notifyView. Defqult implementation calls
_setModelData on this node.
:param editor:
:param column:
:param args: event's args
:param kwargs: event's kwargs
:return:
"""
return
self
.
_setModelData
(
editor
,
column
)
class
FitRootNode
(
RootNode
):
"""
Root node for the FitModel
"""
ColumnNames
=
[
'Param'
,
'Qx'
,
'Qy'
,
'Qz'
]
class
FitModel
(
Model
):
"""
Model displaying a FitH5 file contents.
"""
RootNode
=
FitRootNode
ColumnsWithDelegates
=
[
1
,
2
,
3
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment