示例#1
0
 def mimeData(self, indexes):
     indexes0 = [index for index in indexes if index.column() == 0]
     mimedata = qt.QMimeData()
     items = self.getTopItems(indexes0)
     bstream = pickle.dumps([item.climb_rows() for item in items])
     mimedata.setData(cco.MIME_TYPE_DATA, bstream)
     return mimedata
示例#2
0
 def mimeData(self, indexes, checkValidity=True):
     indexes0 = [index for index in indexes if index.column() == 0]
     nodeTypes = [self.nodeType(index) for index in indexes0]
     if nodeTypes.count(nodeTypes[0]) != len(nodeTypes):  # not all equal
         return
     if nodeTypes[0] in (NODE_HDF5_HEAD, NODE_FS):
         indexesFS = []
         for index in indexes0:
             indexFS = self.mapToFS(index)
             if checkValidity:
                 if self.tryLoadColDataset(indexFS) is None:
                     return
             indexesFS.append(indexFS)
         if ModelBase == qt.QFileSystemModel:
             return super(FileSystemWithHdf5Model, self).mimeData(indexesFS)
         else:
             return self.fsModel.mimeData(indexesFS)
     elif nodeTypes[0] == NODE_HDF5:
         paths = []
         for index in indexes0:
             indexH5 = self.mapToH5(index)
             if checkValidity:
                 if self.tryLoadHDF5Dataset(indexH5) is None:
                     return
             try:
                 path = 'silx:' + '::'.join(
                     (self.h5Model.nodeFromIndex(indexH5).obj.file.filename,
                      self.h5Model.nodeFromIndex(indexH5).obj.name))
                 paths.append(path)
             except:  # noqa
                 return
         mimedata = qt.QMimeData()
         mimedata.setData(cco.MIME_TYPE_HDF5, pickle.dumps(paths))
         return mimedata
示例#3
0
 def mousePressEvent(self, event):
     if event.button() == qt.Qt.LeftButton and self._url is not None:
         mimeData = qt.QMimeData()
         mimeData.setText(self._url.path())
         mimeData.setData("application/x-silx-uri",
                          self._url.path().encode(encoding='utf-8'))
         drag = qt.QDrag(self)
         drag.setMimeData(mimeData)
         dropAction = drag.exec()
示例#4
0
文件: test_hdf5.py 项目: PiRK/silx
 def testDropExternalFile(self):
     with self.h5TempFile() as filename:
         model = hdf5.Hdf5TreeModel()
         mimeData = qt.QMimeData()
         mimeData.setUrls([qt.QUrl.fromLocalFile(filename)])
         model.dropMimeData(mimeData, qt.Qt.CopyAction, 0, 0, qt.QModelIndex())
         self.assertEquals(model.rowCount(qt.QModelIndex()), 1)
         # after sync
         time.sleep(0.1)
         self.qapp.processEvents()
         time.sleep(0.1)
         index = model.index(0, 0, qt.QModelIndex())
         self.assertIsInstance(model.nodeFromIndex(index), hdf5.Hdf5Item.Hdf5Item)
         # clean up
         index = model.index(0, 0, qt.QModelIndex())
         h5File = model.data(index, role=hdf5.Hdf5TreeModel.H5PY_OBJECT_ROLE)
         h5File.close()
示例#5
0
 def testDropExternalFile(self):
     filename = _tmpDirectory + "/data.h5"
     model = hdf5.Hdf5TreeModel()
     mimeData = qt.QMimeData()
     mimeData.setUrls([qt.QUrl.fromLocalFile(filename)])
     model.dropMimeData(mimeData, qt.Qt.CopyAction, 0, 0, qt.QModelIndex())
     self.assertEqual(model.rowCount(qt.QModelIndex()), 1)
     # after sync
     self.waitForPendingOperations(model)
     index = model.index(0, 0, qt.QModelIndex())
     self.assertIsInstance(model.nodeFromIndex(index), hdf5.Hdf5Item.Hdf5Item)
     # clean up
     index = model.index(0, 0, qt.QModelIndex())
     h5File = model.data(index, role=hdf5.Hdf5TreeModel.H5PY_OBJECT_ROLE)
     self.assertIsNotNone(h5File)
     h5File = None
     ref = weakref.ref(model)
     model = None
     self.qWaitForDestroy(ref)