summaryrefslogtreecommitdiff
path: root/PyMca5/PyMcaGui/io/hdf5
diff options
context:
space:
mode:
Diffstat (limited to 'PyMca5/PyMcaGui/io/hdf5')
-rw-r--r--PyMca5/PyMcaGui/io/hdf5/HDF5CounterTable.py7
-rw-r--r--PyMca5/PyMcaGui/io/hdf5/HDF5McaTable.py7
-rw-r--r--PyMca5/PyMcaGui/io/hdf5/HDF5Selection.py2
-rw-r--r--PyMca5/PyMcaGui/io/hdf5/HDF5Widget.py12
-rw-r--r--PyMca5/PyMcaGui/io/hdf5/Hdf5NodeView.py103
-rw-r--r--PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py70
-rw-r--r--PyMca5/PyMcaGui/io/hdf5/QNexusWidgetActions.py17
7 files changed, 109 insertions, 109 deletions
diff --git a/PyMca5/PyMcaGui/io/hdf5/HDF5CounterTable.py b/PyMca5/PyMcaGui/io/hdf5/HDF5CounterTable.py
index af1cddd..9ea31b8 100644
--- a/PyMca5/PyMcaGui/io/hdf5/HDF5CounterTable.py
+++ b/PyMca5/PyMcaGui/io/hdf5/HDF5CounterTable.py
@@ -28,10 +28,12 @@ __contact__ = "sole@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
import posixpath
+import logging
from PyMca5.PyMcaGui import PyMcaQt as qt
safe_str = qt.safe_str
-DEBUG = 0
+_logger = logging.getLogger(__name__)
+
class HDF5CounterTable(qt.QTableWidget):
@@ -256,8 +258,7 @@ class HDF5CounterTable(qt.QTableWidget):
return ddict
def setCounterSelection(self, ddict):
- if DEBUG:
- print("HDF5CounterTable.setCounterSelection", ddict)
+ _logger.debug("HDF5CounterTable.setCounterSelection %s", ddict)
keys = ddict.keys()
if 'cntlist' in keys:
cntlist = ddict['cntlist']
diff --git a/PyMca5/PyMcaGui/io/hdf5/HDF5McaTable.py b/PyMca5/PyMcaGui/io/hdf5/HDF5McaTable.py
index d66aafe..4dcc4a2 100644
--- a/PyMca5/PyMcaGui/io/hdf5/HDF5McaTable.py
+++ b/PyMca5/PyMcaGui/io/hdf5/HDF5McaTable.py
@@ -28,10 +28,12 @@ __contact__ = "sole@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
import posixpath
+import logging
from PyMca5.PyMcaGui import PyMcaQt as qt
safe_str = qt.safe_str
-DEBUG = 0
+_logger = logging.getLogger(__name__)
+
class McaSelectionType(qt.QWidget):
sigMcaSelectionTypeSignal = qt.pyqtSignal(object)
@@ -204,8 +206,7 @@ class HDF5McaTable(qt.QTableWidget):
self._update(row, col)
def _mySlot(self, ddict):
- if DEBUG:
- print("HDF5McaTable._mySlot", ddict)
+ _logger.debug("HDF5McaTable._mySlot %s", ddict)
row = ddict["row"]
col = ddict["column"]
if col == 1:
diff --git a/PyMca5/PyMcaGui/io/hdf5/HDF5Selection.py b/PyMca5/PyMcaGui/io/hdf5/HDF5Selection.py
index 78bd6c2..3b10de8 100644
--- a/PyMca5/PyMcaGui/io/hdf5/HDF5Selection.py
+++ b/PyMca5/PyMcaGui/io/hdf5/HDF5Selection.py
@@ -27,10 +27,10 @@ __author__ = "V.A. Sole - ESRF Data Analysis"
__contact__ = "sole@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
+
from PyMca5.PyMcaGui import PyMcaQt as qt
safe_str = qt.safe_str
-DEBUG = 0
class HDF5Selection(qt.QWidget):
def __init__(self, parent=None):
diff --git a/PyMca5/PyMcaGui/io/hdf5/HDF5Widget.py b/PyMca5/PyMcaGui/io/hdf5/HDF5Widget.py
index 6775387..97d10cc 100644
--- a/PyMca5/PyMcaGui/io/hdf5/HDF5Widget.py
+++ b/PyMca5/PyMcaGui/io/hdf5/HDF5Widget.py
@@ -34,6 +34,7 @@ import posixpath
import gc
import re
from operator import itemgetter
+import logging
import h5py
import weakref
@@ -60,7 +61,8 @@ else:
return x
-DEBUG = 0
+_logger = logging.getLogger(__name__)
+
QVERSION = qt.qVersion()
@@ -81,8 +83,7 @@ def h5py_sorting(object_list):
posixNames = [item[1].name for item in object_list]
except AttributeError:
# Typical of broken external links
- if DEBUG:
- print("HDF5Widget: Cannot get posixNames")
+ _logger.debug("HDF5Widget: Cannot get posixNames")
return object_list
# This implementation only sorts entries
@@ -223,7 +224,7 @@ class H5NodeProxy(object):
except:
#one cannot afford any error, so I revert to the old
# method where values where used instead of items
- if DEBUG:
+ if _logger.getEffectiveLevel() == logging.DEBUG:
raise
else:
# tmpList = list(self.getNode(self.name).values())
@@ -581,8 +582,7 @@ class FileModel(qt.QAbstractItemModel):
self.sigFileAppended.emit(ddict)
def clear(self):
- if DEBUG:
- print("Clear called")
+ _logger.debug("Clear called")
# reset is considered obsolete under Qt 5.
if hasattr(self, "reset"):
self.reset()
diff --git a/PyMca5/PyMcaGui/io/hdf5/Hdf5NodeView.py b/PyMca5/PyMcaGui/io/hdf5/Hdf5NodeView.py
index c042515..d1c3c6a 100644
--- a/PyMca5/PyMcaGui/io/hdf5/Hdf5NodeView.py
+++ b/PyMca5/PyMcaGui/io/hdf5/Hdf5NodeView.py
@@ -46,7 +46,7 @@ import silx
from silx.gui.data.DataViewerFrame import DataViewerFrame
from silx.gui.data import DataViews
from silx.gui.data import NXdataWidgets
-from silx.gui.plot import Plot1D
+from silx.gui.plot import Plot1D, Plot2D
from silx.gui import icons
@@ -134,6 +134,35 @@ class Plot1DViewWithPlugins(DataViews._Plot1dView):
return Plot1DWithPlugins(parent=parent)
+class Plot2DWithPlugins(Plot2D):
+ """Add a plugin toolbutton to a Plot2D"""
+ def __init__(self, parent=None):
+ Plot2D.__init__(self, parent)
+
+ self._toolbar = qt.QToolBar(self)
+ self.addToolBar(self._toolbar)
+ pluginsToolButton = PluginsToolButton(plot=self, parent=self,
+ method="getPlugin2DInstance")
+
+ if PLUGINS_DIR:
+ pluginsToolButton.getPlugins(
+ method="getPlugin2DInstance",
+ directoryList=PLUGINS_DIR)
+ self._toolbar.addWidget(pluginsToolButton)
+
+
+class Plot2DViewWithPlugins(DataViews._Plot2dView):
+ def createWidget(self, parent):
+ widget = Plot2DWithPlugins(parent=parent)
+ widget.setDefaultColormap(self.defaultColormap())
+ widget.getColormapAction().setColorDialog(self.defaultColorDialog())
+ widget.getIntensityHistogramAction().setVisible(True)
+ widget.setKeepDataAspectRatio(True)
+ widget.getXAxis().setLabel('X')
+ widget.getYAxis().setLabel('Y')
+ return widget
+
+
class ArrayCurvePlotWithPlugins(NXdataWidgets.ArrayCurvePlot):
"""Adds a plugin toolbutton to an ArrayCurvePlot widget"""
def __init__(self, parent=None):
@@ -159,43 +188,30 @@ class NXdataCurveViewWithPlugins(DataViews._NXdataCurveView):
return ArrayCurvePlotWithPlugins(parent=parent)
-class NXdataViewWithPlugins(DataViews.CompositeDataView):
- """Re-implement DataViews._NXdataView to use the 1D view with
- a plugin toolbutton in the composite view."""
- # This widget is needed only for silx < 0.7.
- def __init__(self, parent):
- super(NXdataViewWithPlugins, self).__init__(
- parent=parent,
- label="NXdata",
- icon=icons.getQIcon("view-nexus"))
-
- if silx.version >= "0.7.0":
- self.addView(DataViews._InvalidNXdataView(parent))
- self.addView(DataViews._NXdataScalarView(parent))
- self.addView(NXdataCurveViewWithPlugins(parent))
- self.addView(DataViews._NXdataXYVScatterView(parent))
- self.addView(DataViews._NXdataImageView(parent))
- self.addView(DataViews._NXdataStackView(parent))
-
-
-class DataViewerFrameWithPlugins(DataViewerFrame):
- """Overloaded DataViewerFrame with the 1D view replaced by
- Plot1DViewWithPlugins"""
- # This widget is needed only for silx < 0.7.
- def createDefaultViews(self, parent=None):
- views = list(DataViewerFrame.createDefaultViews(self, parent=parent))
+class ArrayImagePlotWithPlugins(NXdataWidgets.ArrayImagePlot):
+ """Adds a plugin toolbutton to an ArrayImagePlot widget"""
+ def __init__(self, parent=None):
+ NXdataWidgets.ArrayImagePlot.__init__(self, parent)
- # replace 1d view
- oldView = [v for v in views if v.modeId() == DataViews.PLOT1D_MODE][0]
- newView = Plot1DViewWithPlugins(parent=parent)
- views[views.index(oldView)] = newView
+ self._toolbar = qt.QToolBar(self)
+ self.getPlot().addToolBar(self._toolbar)
+ pluginsToolButton = PluginsToolButton(plot=self.getPlot(),
+ parent=self,
+ method="getPlugin2DInstance")
+ if PLUGINS_DIR:
+ pluginsToolButton.getPlugins(
+ method="getPlugin2DInstance",
+ directoryList=PLUGINS_DIR)
+ self._toolbar.addWidget(pluginsToolButton)
- # replace NXdataView
- oldView = [v for v in views if isinstance(v, DataViews._NXdataView)][0]
- newView = NXdataViewWithPlugins(parent=parent)
- views[views.index(oldView)] = newView
- return views
+class NXdataImageViewWithPlugins(DataViews._NXdataImageView):
+ """Use the widget with a :class:`PluginsToolButton`"""
+ def createWidget(self, parent):
+ widget = ArrayImagePlotWithPlugins(parent)
+ widget.getPlot().setDefaultColormap(self.defaultColormap())
+ widget.getPlot().getColormapAction().setColorDialog(self.defaultColorDialog())
+ return widget
class Hdf5NodeView(CloseEventNotifyingWidget.CloseEventNotifyingWidget):
@@ -213,14 +229,15 @@ class Hdf5NodeView(CloseEventNotifyingWidget.CloseEventNotifyingWidget):
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.mainLayout.setSpacing(0)
- if silx.hexversion >= 0x000700f0: # 0.7.0 final
- self.viewWidget = DataViewerFrame(self)
- self.viewWidget.replaceView(DataViews.PLOT1D_MODE,
- Plot1DViewWithPlugins(self))
- self.viewWidget.replaceView(DataViews.NXDATA_CURVE_MODE,
- NXdataCurveViewWithPlugins(self))
- else:
- self.viewWidget = DataViewerFrameWithPlugins(self)
+ self.viewWidget = DataViewerFrame(self)
+ self.viewWidget.replaceView(DataViews.PLOT1D_MODE,
+ Plot1DViewWithPlugins(self))
+ self.viewWidget.replaceView(DataViews.PLOT2D_MODE,
+ Plot2DViewWithPlugins(self))
+ self.viewWidget.replaceView(DataViews.NXDATA_CURVE_MODE,
+ NXdataCurveViewWithPlugins(self))
+ self.viewWidget.replaceView(DataViews.NXDATA_IMAGE_MODE,
+ NXdataImageViewWithPlugins(self))
self.mainLayout.addWidget(self.viewWidget)
diff --git a/PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py b/PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py
index ba3ddbc..dda5514 100644
--- a/PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py
+++ b/PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py
@@ -33,6 +33,7 @@ import posixpath
import weakref
import gc
import h5py
+import logging
from PyMca5.PyMcaGui import PyMcaQt as qt
from PyMca5.PyMcaCore import NexusTools
@@ -57,7 +58,8 @@ from PyMca5.PyMcaIO import ConfigDict
if "PyMcaDirs" in sys.modules:
from PyMca5 import PyMcaDirs
-DEBUG=0
+_logger = logging.getLogger(__name__)
+
class Buttons(qt.QWidget):
@@ -296,8 +298,7 @@ class QNexusWidget(qt.QWidget):
else:
ddict['HDF5'] ={'WidgetConfiguration':\
self.getWidgetConfiguration()}
- if DEBUG:
- print("TODO - Add selection options")
+ _logger.debug("TODO - Add selection options")
ddict.write(fname)
def _deleteAllCountersFromTable(self):
@@ -401,8 +402,7 @@ class QNexusWidget(qt.QWidget):
if type(self._aliasList) == type(""):
self._aliasList = [ddict['aliases']]
self.cntTable.build(self._cntList, self._aliasList)
- if DEBUG:
- print("TODO - Add selection options")
+ _logger.debug("TODO - Add selection options")
def setDataSource(self, dataSource):
self.data = dataSource
@@ -480,7 +480,7 @@ class QNexusWidget(qt.QWidget):
try:
widget.w.setDataset(dataset)
except:
- print("Error filling table")
+ _logger.error("Error filling table")
widget.addTab(widget.w, 'DataView')
widget.setCurrentWidget(widget.w)
elif Hdf5NodeView is not None:
@@ -661,19 +661,16 @@ class QNexusWidget(qt.QWidget):
self.tableTab.insertTab(2, self.mcaTable, "MCA")
elif (len(mcaList)==0) and (nTabs > 2):
self.tableTab.removeTab(2)
- if DEBUG:
- print("currentTab = ", currentTab)
+ _logger.debug("currentTab = %s", currentTab)
if currentTab != "USER":
if (len(mcaList) > 0) and (len(cntList) == 0):
idx = self.tableTabOrder.index("MCA")
self.tableTab.setCurrentIndex(idx)
- if DEBUG:
- print("setting tab = ", idx, "MCA")
+ _logger.debug("setting tab = %s MCA", idx)
elif (len(mcaList) == 0) and (len(cntList) > 0):
idx = self.tableTabOrder.index("AUTO")
self.tableTab.setCurrentIndex(idx)
- if DEBUG:
- print("setting tab = ", idx, "AUTO")
+ _logger.debug("setting tab = %s AUTO", idx)
self._lastEntry = currentEntry
if ddict['event'] == 'itemClicked':
if ddict['mouse'] == "right":
@@ -697,8 +694,7 @@ class QNexusWidget(qt.QWidget):
else:
self.tableTab.setCurrentIndex(0)
if not self._isNumericType(ddict['dtype']):
- if DEBUG:
- print("string like %s" % ddict['dtype'])
+ _logger.debug("string like %s", ddict['dtype'])
else:
root = ddict['name'].split('/')
root = "/" + root[1]
@@ -737,8 +733,7 @@ class QNexusWidget(qt.QWidget):
root = "/" + root[1]
cnt = ddict['name'].split(root)[-1]
if cnt not in self._cntList:
- if DEBUG:
- print("USING SECOND WAY")
+ _logger.debug("USING SECOND WAY")
self._cntList.append(cnt)
basename = posixpath.basename(cnt)
if basename not in self._aliasList:
@@ -747,36 +742,30 @@ class QNexusWidget(qt.QWidget):
self._aliasList.append(cnt)
self.cntTable.build(self._cntList, self._aliasList)
return
- if DEBUG:
- print("Unhandled item type: %s" % ddict['dtype'])
+ _logger.debug("Unhandled item type: %s", ddict['dtype'])
def _addMcaAction(self):
- if DEBUG:
- print("_addMcaAction received")
+ _logger.debug("_addMcaAction received")
self.mcaAction("ADD")
def _removeMcaAction(self):
- if DEBUG:
- print("_removeMcaAction received")
+ _logger.debug("_removeMcaAction received")
self.mcaAction("REMOVE")
def _replaceMcaAction(self):
- if DEBUG:
- print("_replaceMcaAction received")
+ _logger.debug("_replaceMcaAction received")
self.mcaAction("REPLACE")
def mcaAction(self, action="ADD"):
- if DEBUG:
- print("mcaAction %s" % action)
+ _logger.debug("mcaAction %s", action)
self.mcaTable.getMcaSelection()
ddict = {}
ddict['action'] = "%s MCA" % action
self.buttonsSlot(ddict, emit=True)
def _addAction(self):
- if DEBUG:
- print("_addAction received")
+ _logger.debug("_addAction received")
# formerly we had action and selection type
text = qt.safe_str(self.tableTab.tabText(self.tableTab.currentIndex()))
if text.upper() == "MCA":
@@ -791,8 +780,7 @@ class QNexusWidget(qt.QWidget):
self.buttonsSlot(ddict, emit=True)
def _removeAction(self):
- if DEBUG:
- print("_removeAction received")
+ _logger.debug("_removeAction received")
text = qt.safe_str(self.tableTab.tabText(self.tableTab.currentIndex()))
if text.upper() == "MCA":
self._removeMcaAction()
@@ -806,8 +794,7 @@ class QNexusWidget(qt.QWidget):
self.buttonsSlot(ddict, emit=True)
def _replaceAction(self):
- if DEBUG:
- print("_replaceAction received")
+ _logger.debug("_replaceAction received")
text = qt.safe_str(self.tableTab.tabText(self.tableTab.currentIndex()))
if text.upper() == "MCA":
self._replaceMcaAction()
@@ -821,8 +808,7 @@ class QNexusWidget(qt.QWidget):
self.buttonsSlot(ddict, emit=True)
def _configurationChangedAction(self, ddict):
- if DEBUG:
- print("_configurationChangedAction received", ddict)
+ _logger.debug("_configurationChangedAction received %s", ddict)
if ddict["3d"]:
self.autoTable.set3DEnabled(True, emit=False)
self.cntTable.set3DEnabled(True, emit=False)
@@ -834,8 +820,7 @@ class QNexusWidget(qt.QWidget):
self.cntTable.set2DEnabled(False, emit=False)
def _autoTableUpdated(self, ddict):
- if DEBUG:
- print("_autoTableUpdated(self, ddict) ", ddict)
+ _logger.debug("_autoTableUpdated(self, ddict) %s", ddict)
text = qt.safe_str(self.tableTab.tabText(self.tableTab.currentIndex()))
if text.upper() == "AUTO":
actions = self.actions.getConfiguration()
@@ -846,8 +831,7 @@ class QNexusWidget(qt.QWidget):
self._replaceAction()
def _userTableUpdated(self, ddict):
- if DEBUG:
- print("_userTableUpdated(self, ddict) ", ddict)
+ _logger.debug("_userTableUpdated(self, ddict) %s", ddict)
text = qt.safe_str(self.tableTab.tabText(self.tableTab.currentIndex()))
if text.upper() == "USER":
actions = self.actions.getConfiguration()
@@ -858,8 +842,7 @@ class QNexusWidget(qt.QWidget):
self._replaceAction()
def _mcaTableUpdated(self, ddict):
- if DEBUG:
- print("_mcaTableUpdated(self, ddict) ", ddict)
+ _logger.debug("_mcaTableUpdated(self, ddict) %s", ddict)
text = qt.safe_str(self.tableTab.tabText(self.tableTab.currentIndex()))
if text.upper() == "MCA":
actions = self.actions.getConfiguration()
@@ -870,8 +853,7 @@ class QNexusWidget(qt.QWidget):
self._replaceAction()
def buttonsSlot(self, ddict, emit=True):
- if DEBUG:
- print("buttonsSlot(self, ddict,emit=True)", ddict, "emit = ", emit)
+ _logger.debug("buttonsSlot(self, %s,emit=%s)", ddict, emit)
if self.data is None:
return
action, selectionType = ddict['action'].split()
@@ -1057,10 +1039,10 @@ class QNexusWidget(qt.QWidget):
if 'event' in ddict:
if ddict['event'] == "closeEventSignal":
if ddict['id'] in self._widgetDict:
- if DEBUG:
+ if _logger.getEffectiveLevel() == logging.DEBUG:
try:
widget = self._widgetDict[ddict['id']]
- print("DELETING %s" % widget.windowTitle())
+ _logger.debug("DELETING %s", widget.windowTitle())
except:
pass
del self._widgetDict[ddict['id']]
diff --git a/PyMca5/PyMcaGui/io/hdf5/QNexusWidgetActions.py b/PyMca5/PyMcaGui/io/hdf5/QNexusWidgetActions.py
index 18dda50..178a41c 100644
--- a/PyMca5/PyMcaGui/io/hdf5/QNexusWidgetActions.py
+++ b/PyMca5/PyMcaGui/io/hdf5/QNexusWidgetActions.py
@@ -28,8 +28,11 @@ __contact__ = "sole@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
import sys
+import logging
from PyMca5.PyMcaGui import PyMcaQt as qt
-DEBUG = 0
+
+_logger = logging.getLogger(__name__)
+
class QNexusWidgetActions(qt.QWidget):
sigAddSelection = qt.pyqtSignal()
@@ -173,23 +176,19 @@ class QNexusWidgetActions(qt.QWidget):
self._addClicked()
def _addClicked(self):
- if DEBUG:
- print("_addClicked()")
+ _logger.debug("_addClicked()")
self.sigAddSelection.emit()
def _removeClicked(self):
- if DEBUG:
- print("_removeClicked()")
+ _logger.debug("_removeClicked()")
self.sigRemoveSelection.emit()
def _replaceClicked(self):
- if DEBUG:
- print("_replaceClicked()")
+ _logger.debug("_replaceClicked()")
self.sigReplaceSelection.emit()
def configurationChanged(self):
- if DEBUG:
- print("configurationChanged(object)")
+ _logger.debug("configurationChanged(object)")
ddict = self.getConfiguration()
self.sigActionsConfigurationChanged.emit(ddict)