diff options
author | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2019-05-28 08:16:16 +0200 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2019-05-28 08:16:16 +0200 |
commit | a763e5d1b3921b3194f3d4e94ab9de3fbe08bbdd (patch) | |
tree | 45d462ed36a5522e9f3b9fde6c4ec4918c2ae8e3 /silx/gui/hdf5/_utils.py | |
parent | cebdc9244c019224846cb8d2668080fe386a6adc (diff) |
New upstream version 0.10.1+dfsg
Diffstat (limited to 'silx/gui/hdf5/_utils.py')
-rw-r--r-- | silx/gui/hdf5/_utils.py | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/silx/gui/hdf5/_utils.py b/silx/gui/hdf5/_utils.py index 6a34933..aaab228 100644 --- a/silx/gui/hdf5/_utils.py +++ b/silx/gui/hdf5/_utils.py @@ -28,12 +28,15 @@ package `silx.gui.hdf5` package. __authors__ = ["V. Valls"] __license__ = "MIT" -__date__ = "04/05/2018" +__date__ = "17/01/2019" import logging -from .. import qt +import os.path + import silx.io.utils +import silx.io.url +from .. import qt from silx.utils.html import escape _logger = logging.getLogger(__name__) @@ -107,11 +110,22 @@ class Hdf5DatasetMimeData(qt.QMimeData): MIME_TYPE = "application/x-internal-h5py-dataset" - def __init__(self, node=None, dataset=None): + SILX_URI_TYPE = "application/x-silx-uri" + + def __init__(self, node=None, dataset=None, isRoot=False): qt.QMimeData.__init__(self) self.__dataset = dataset self.__node = node + self.__isRoot = isRoot self.setData(self.MIME_TYPE, "".encode(encoding='utf-8')) + if node is not None: + h5Node = H5Node(node) + silxUrl = h5Node.url + self.setText(silxUrl) + self.setData(self.SILX_URI_TYPE, silxUrl.encode(encoding='utf-8')) + + def isRoot(self): + return self.__isRoot def node(self): return self.__node @@ -122,20 +136,6 @@ class Hdf5DatasetMimeData(qt.QMimeData): return self.__dataset -class Hdf5NodeMimeData(qt.QMimeData): - """Mimedata class to identify an internal drag and drop of a Hdf5Node.""" - - MIME_TYPE = "application/x-internal-h5py-node" - - def __init__(self, node=None): - qt.QMimeData.__init__(self) - self.__node = node - self.setData(self.MIME_TYPE, "".encode(encoding='utf-8')) - - def node(self): - return self.__node - - class H5Node(object): """Adapter over an h5py object to provide missing informations from h5py nodes, like internal node path and filename (which are not provided by @@ -419,3 +419,43 @@ class H5Node(object): :rtype: str """ return self.physical_name.split("/")[-1] + + @property + def data_url(self): + """Returns a :class:`silx.io.url.DataUrl` object identify this node in the file + system. + + :rtype: ~silx.io.url.DataUrl + """ + absolute_filename = os.path.abspath(self.local_filename) + return silx.io.url.DataUrl(scheme="silx", + file_path=absolute_filename, + data_path=self.local_name) + + @property + def url(self): + """Returns an URL object identifying this node in the file + system. + + This URL can be used in different ways. + + .. code-block:: python + + # Parsing the URL + import silx.io.url + dataurl = silx.io.url.DataUrl(item.url) + # dataurl provides access to URL fields + + # Open a numpy array + import silx.io + dataset = silx.io.get_data(item.url) + + # Open an hdf5 object (URL targetting a file or a group) + import silx.io + with silx.io.open(item.url) as h5: + ...your stuff... + + :rtype: str + """ + data_url = self.data_url + return data_url.path() |