From cebdc9244c019224846cb8d2668080fe386a6adc Mon Sep 17 00:00:00 2001 From: Alexandre Marie Date: Mon, 17 Dec 2018 12:28:24 +0100 Subject: New upstream version 0.9.0+dfsg --- silx/gui/hdf5/Hdf5Item.py | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'silx/gui/hdf5/Hdf5Item.py') diff --git a/silx/gui/hdf5/Hdf5Item.py b/silx/gui/hdf5/Hdf5Item.py index 9804907..b3c313e 100644 --- a/silx/gui/hdf5/Hdf5Item.py +++ b/silx/gui/hdf5/Hdf5Item.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2016-2017 European Synchrotron Radiation Facility +# Copyright (c) 2016-2018 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 @@ -25,7 +25,7 @@ __authors__ = ["V. Valls"] __license__ = "MIT" -__date__ = "10/10/2017" +__date__ = "03/09/2018" import logging @@ -37,9 +37,8 @@ from .Hdf5Node import Hdf5Node import silx.io.utils from silx.gui.data.TextFormatter import TextFormatter from ..hdf5.Hdf5Formatter import Hdf5Formatter - +from ...third_party import six _logger = logging.getLogger(__name__) - _formatter = TextFormatter() _hdf5Formatter = Hdf5Formatter(textFormatter=_formatter) # FIXME: The formatter should be an attribute of the Hdf5Model @@ -63,8 +62,16 @@ class Hdf5Item(Hdf5Node): self.__error = None self.__text = text self.__linkClass = linkClass + self.__nx_class = None Hdf5Node.__init__(self, parent, populateAll=populateAll) + def _getCanonicalName(self): + parent = self.parent + if parent is None: + return self.__text + else: + return "%s/%s" % (parent._getCanonicalName(), self.__text) + @property def obj(self): if self.__key: @@ -152,8 +159,7 @@ class Hdf5Item(Hdf5Node): try: obj = parent_obj.get(self.__key) except Exception as e: - lib_name = self.obj.__class__.__module__.split(".")[0] - _logger.debug("Internal %s error", lib_name, exc_info=True) + _logger.error("Internal error while reaching HDF5 object: %s", str(e)) _logger.debug("Backtrace", exc_info=True) try: self.__obj = parent_obj.get(self.__key, getlink=True) @@ -184,7 +190,7 @@ class Hdf5Item(Hdf5Node): elif class_ == silx.io.utils.H5Type.SOFT_LINK: message = "Soft link broken. Path %s does not exist" % (self.__obj.path) else: - name = self.obj.__class__.__name__.split(".")[-1].capitalize() + name = self.__obj.__class__.__name__.split(".")[-1].capitalize() message = "%s broken" % (name) self.__error = message self.__isBroken = True @@ -293,6 +299,8 @@ class Hdf5Item(Hdf5Node): attributeDict["Data type"] = self._getFormatter().humanReadableType(self.obj, full=True) elif self.h5Class == silx.io.utils.H5Type.GROUP: attributeDict["#Title"] = "HDF5 Group" + if self.nexusClassName: + attributeDict["NX_class"] = self.nexusClassName attributeDict["Name"] = self.basename attributeDict["Path"] = self.obj.name elif self.h5Class == silx.io.utils.H5Type.FILE: @@ -332,6 +340,20 @@ class Hdf5Item(Hdf5Node): return tooltip + @property + def nexusClassName(self): + """Returns the Nexus class name""" + if self.__nx_class is None: + self.__nx_class = self.obj.attrs.get("NX_class", None) + if self.__nx_class is None: + self.__nx_class = "" + else: + if six.PY2: + self.__nx_class = self.__nx_class.decode() + elif not isinstance(self.__nx_class, str): + self.__nx_class = str(self.__nx_class, "UTF-8") + return self.__nx_class + def dataName(self, role): """Data for the name column""" if role == qt.Qt.TextAlignmentRole: @@ -354,12 +376,13 @@ class Hdf5Item(Hdf5Node): if self.__error is not None: return "" class_ = self.h5Class - if class_ == silx.io.utils.H5Type.DATASET: + if self.isGroupObj(): + text = self.nexusClassName + elif class_ == silx.io.utils.H5Type.DATASET: text = self._getFormatter().humanReadableType(self.obj) else: text = "" return text - return None def dataShape(self, role): -- cgit v1.2.3