Ejemplo n.º 1
0
    def startDrag(self, supportedActions):
        index = self.getIndex()
        item = self.getItem()
        data = self._model.projectdata(index)
        if data is None:
            return
        category, name = data
        # Check item in src
        # TODO move this part in dragEnterEvent with mimetype
        obj = self._model._project.get(category, name)
        if category in ['src', 'model']:
            # Read file and parse model to get inputs, outputs, doc that may be
            # useful once dropped.
            obj.read()
            text = item.text()

            # name_without_ext = ".".join(text.split(".")[:-1])
            name_without_ext = text
            name_without_space = "_".join(name_without_ext.split())
            for sym in ["-", "+", "*", "/", "\"", "."]:
                name_without_space = "_".join(name_without_space.split(sym))

            python_call_string = '%s = Model("%s")' % (name_without_space,
                                                       name_without_ext)
            icon = item.icon()
            pixmap = icon.pixmap(20, 20)

            itemData = QtCore.QByteArray()
            dataStream = QtCore.QDataStream(itemData,
                                            QtCore.QIODevice.WriteOnly)
            model_id = name_without_ext
            dataStream.writeString(str(python_call_string))
            dataStream.writeString(str(model_id))

            mimeData = QtCore.QMimeData()
            mimeData.setText(python_call_string)
            mimeData.setData("openalealab/model", itemData)

            drag = QtGui.QDrag(self)
            drag.setMimeData(mimeData)
            drag.setHotSpot(
                QtCore.QPoint(pixmap.width() / 2,
                              pixmap.height() / 2))
            drag.setPixmap(pixmap)

            drag.start(QtCore.Qt.CopyAction)

        elif category == 'data':
            p = '%s/%r' % (category, str(obj.filename))
            mimetype, mimedata = encode(obj, mimetype='openalealab/data')
            qmime_data = QtCore.QMimeData()
            qmime_data.setData(mimetype, mimedata)
            qmime_data.setText(p)
            drag = QtGui.QDrag(self)
            drag.setMimeData(qmime_data)
            drag.start()
Ejemplo n.º 2
0
    def startDrag(self, supportedActions):

        item = self.currentIndex()

        itemData = QtCore.QByteArray()
        dataStream = QtCore.QDataStream(itemData, QtCore.QIODevice.WriteOnly)
        pixmap = QtGui.QPixmap(":/icons/ccmime.png")

        l = self.model().datapool.keys()
        l.sort()
        name = l[item.row()]

        dataStream.writeSting(name)

        mimeData = QtCore.QMimeData()
        mimeData.setData("openalea/data_instance", itemData)

        linecode = cli.get_datapool_code(name)
        mimeData.setText(linecode)

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(QtCore.QPoint(pixmap.width()/2, pixmap.height()/2))
        drag.setPixmap(pixmap)

        drag.start(QtCore.Qt.MoveAction)
Ejemplo n.º 3
0
 def mimeData(self, indices):
     for index in indices:
         control = self.control(index)
     mimetype, mimedata = encode(control)
     qmime_data = QtCore.QMimeData()
     qmime_data.setData(mimetype, mimedata)
     qmime_data.setText(control.name)
     return qmime_data
Ejemplo n.º 4
0
def encode_to_qmimedata(data, mimetype):
    _possible_conv = possible_conv(data, mimetype)

    qmimedata = QtCore.QMimeData()
    if mimetype in _possible_conv:
        for mimetype_in, mimetype_out in _possible_conv[mimetype]:
            qmimedata = qtencode(data, qmimedata, mimetype_in, mimetype_out)
    return qmimedata
Ejemplo n.º 5
0
    def mimeData(self, indices):
        for index in indices:
            pass

        category, name = self.projectdata(index)
        if category in ('model', 'data'):
            data = self._project.get_item(category, name)
            return encode_to_qmimedata(data, 'openalealab/%s' % category)
        else:
            # QtGui.QStandardItemModel.mimeData(self, indices)
            return QtCore.QMimeData()