diff options
Diffstat (limited to 'silx/gui/data/Hdf5TableView.py')
-rw-r--r-- | silx/gui/data/Hdf5TableView.py | 76 |
1 files changed, 62 insertions, 14 deletions
diff --git a/silx/gui/data/Hdf5TableView.py b/silx/gui/data/Hdf5TableView.py index 5d79907..ba737e3 100644 --- a/silx/gui/data/Hdf5TableView.py +++ b/silx/gui/data/Hdf5TableView.py @@ -30,7 +30,7 @@ from __future__ import division __authors__ = ["V. Valls"] __license__ = "MIT" -__date__ = "07/04/2017" +__date__ = "29/09/2017" import functools import os.path @@ -40,6 +40,13 @@ import silx.io from .TextFormatter import TextFormatter import silx.gui.hdf5 from silx.gui.widgets import HierarchicalTableView +from ..hdf5.Hdf5Formatter import Hdf5Formatter + +try: + import h5py +except ImportError: + h5py = None + _logger = logging.getLogger(__name__) @@ -177,6 +184,7 @@ class Hdf5TableModel(HierarchicalTableView.HierarchicalTableModel): self.__obj = None self.__data = _TableData(columnCount=4) self.__formatter = None + self.__hdf5Formatter = Hdf5Formatter(self) formatter = TextFormatter(self) self.setFormatter(formatter) self.setObject(data) @@ -207,7 +215,7 @@ class Hdf5TableModel(HierarchicalTableView.HierarchicalTableModel): value = cell.value() if callable(value): value = value(self.__obj) - return str(value) + return value return None def flags(self, index): @@ -248,6 +256,22 @@ class Hdf5TableModel(HierarchicalTableView.HierarchicalTableModel): else: self.reset() + def __formatHdf5Type(self, dataset): + """Format the HDF5 type""" + return self.__hdf5Formatter.humanReadableHdf5Type(dataset) + + def __formatDType(self, dataset): + """Format the numpy dtype""" + return self.__hdf5Formatter.humanReadableType(dataset, full=True) + + def __formatShape(self, dataset): + """Format the shape""" + if dataset.shape is None or len(dataset.shape) <= 1: + return self.__hdf5Formatter.humanReadableShape(dataset) + size = dataset.size + shape = self.__hdf5Formatter.humanReadableShape(dataset) + return u"%s = %s" % (shape, size) + def __initProperties(self): """Initialize the list of available properties according to the defined h5py-like object.""" @@ -270,26 +294,48 @@ class Hdf5TableModel(HierarchicalTableView.HierarchicalTableModel): else: objectType = obj.__class__.__name__ self.__data.addHeaderRow(headerLabel="HDF5 %s" % objectType) - self.__data.addHeaderRow(headerLabel="Path info") - self.__data.addHeaderValueRow("basename", lambda x: os.path.basename(x.name)) - self.__data.addHeaderValueRow("name", lambda x: x.name) - if silx.io.is_file(obj): - self.__data.addHeaderValueRow("filename", lambda x: x.filename) + SEPARATOR = "::" + self.__data.addHeaderRow(headerLabel="Path info") if isinstance(obj, silx.gui.hdf5.H5Node): # helpful informations if the object come from an HDF5 tree - self.__data.addHeaderValueRow("local_basename", lambda x: x.local_basename) - self.__data.addHeaderValueRow("local_name", lambda x: x.local_name) - self.__data.addHeaderValueRow("local_filename", lambda x: x.local_file.filename) + self.__data.addHeaderValueRow("Basename", lambda x: x.local_basename) + self.__data.addHeaderValueRow("Name", lambda x: x.local_name) + local = lambda x: x.local_filename + SEPARATOR + x.local_name + self.__data.addHeaderValueRow("Local", local) + physical = lambda x: x.physical_filename + SEPARATOR + x.physical_name + self.__data.addHeaderValueRow("Physical", physical) + else: + # it's a real H5py object + self.__data.addHeaderValueRow("Basename", lambda x: os.path.basename(x.name)) + self.__data.addHeaderValueRow("Name", lambda x: x.name) + self.__data.addHeaderValueRow("File", lambda x: x.file.filename) + + if hasattr(obj, "path"): + # That's a link + if hasattr(obj, "filename"): + link = lambda x: x.filename + SEPARATOR + x.path + else: + link = lambda x: x.path + self.__data.addHeaderValueRow("Link", link) + else: + if silx.io.is_file(obj): + physical = lambda x: x.filename + SEPARATOR + x.name + else: + physical = lambda x: x.file.filename + SEPARATOR + x.name + self.__data.addHeaderValueRow("Physical", physical) if hasattr(obj, "dtype"): + self.__data.addHeaderRow(headerLabel="Data info") - self.__data.addHeaderValueRow("dtype", lambda x: x.dtype) + + if h5py is not None and hasattr(obj, "id"): + # display the HDF5 type + self.__data.addHeaderValueRow("HDF5 type", self.__formatHdf5Type) + self.__data.addHeaderValueRow("dtype", self.__formatDType) if hasattr(obj, "shape"): - self.__data.addHeaderValueRow("shape", lambda x: x.shape) - if hasattr(obj, "size"): - self.__data.addHeaderValueRow("size", lambda x: x.size) + self.__data.addHeaderValueRow("shape", self.__formatShape) if hasattr(obj, "chunks") and obj.chunks is not None: self.__data.addHeaderValueRow("chunks", lambda x: x.chunks) @@ -354,6 +400,8 @@ class Hdf5TableModel(HierarchicalTableView.HierarchicalTableModel): if formatter is self.__formatter: return + self.__hdf5Formatter.setTextFormatter(formatter) + if qt.qVersion() > "4.6": self.beginResetModel() |