Beispiel #1
0
    def mousePressEvent(self, event):
        QTreeView.mousePressEvent(self, event)
        if self.is_draggable_item_selected():
            index = self.selectedIndexes()[2]
            source_selected = index.model().mapToSource(index)
            selected = self.model().sourceModel().itemFromIndex(
                source_selected)
            if event.button() == QtCore.Qt.LeftButton:
                drag = QDrag(self)
                mime_data = QtCore.QMimeData()
                mime_data.setText(Mime.NEW_ELEMENT)
                selected_class = self.class_mapper.to_class(
                    str(selected.text()))
                self.last_spawned_element = selected_class()
                self.last_spawned_element.setParent(self)
                img = self.last_spawned_element.grab()
                drag.setMimeData(mime_data)
                drag.setPixmap(img)
                drag.setHotSpot(
                    QtCore.QPoint(img.width() / 2,
                                  img.height() / 2))
                drag.exec_()
                if self.last_spawned_element.parent() is self:
                    self.last_spawned_element.setParent(None)
                    self.last_spawned_element.deleteLater()
                else:
                    # todo: move this functionality to elements self logic
                    self.last_spawned_element.recalculate(True, True, True)
        elif event.button() == QtCore.Qt.LeftButton:
            self.setExpanded(self.currentIndex(),
                             not self.isExpanded(self.currentIndex()))

        self.clearSelection()
Beispiel #2
0
 def mouseMoveEvent(self, e):
     mimeData = QtCore.QMimeData()
     drag = QtGui.QDrag(self)
     mimeData.setText(self.currentItem().text(0))
     drag.setMimeData(mimeData)
     drag.setHotSpot(e.pos() - self.rect().topLeft())
     dropAction = drag.exec_(QtCore.Qt.MoveAction)
Beispiel #3
0
 def copy_files(self, objects):
     mimeData = QtCore.QMimeData()
     mimeData.setUrls([
         QtCore.QUrl.fromLocalFile(f.filename)
         for f in (self.get_files_from_objects(objects))
     ])
     self.clipboard().setMimeData(mimeData)
Beispiel #4
0
 def startDrag(self, actions):
     drag = QtGui.QDrag(self)
     mimeData = QtCore.QMimeData()
     bytearray = QtCore.QByteArray()
     stream = QtCore.QDataStream(bytearray, QtCore.QIODevice.WriteOnly)
     fileList = []
     for fileIndex in self.selectionModel().selectedRows():
         filePath = fileIndex.data(FilePathRole)
         fileList.append(filePath)
         stream.writeInt32(fileIndex.row())
         stream.writeInt32(fileIndex.column())
         #field number, might want to implement other roles too
         stream.writeInt32(1)
         #key
         stream.writeInt32(FilePathRole)
         #value
         stream.writeQVariant(filePath)
     mimeData.setData('application/x-qabstractitemmodeldatalist', bytearray)
     mimeData.setUrls(
         [QtCore.QUrl.fromLocalFile(filePath) for filePath in fileList])
     drag.setMimeData(mimeData)
     drag.setPixmap(self.createDragPixmap(fileList))
     drag.setHotSpot(QtCore.QPoint(32, 10))
     #        drag.exec_(actions, QtCore.Qt.CopyAction)
     drag.exec_(QtCore.Qt.CopyAction)
Beispiel #5
0
 def dropEvent(self, e):
     self.insertPlainText(e.mimeData().text())
     mimeData = QtCore.QMimeData()
     mimeData.setText("")
     dummyEvent = QtGui.QDropEvent(e.posF(), e.possibleActions(), mimeData,
                                   e.mouseButtons(), e.keyboardModifiers())
     super(textboxdrag, self).dropEvent(dummyEvent)
Beispiel #6
0
    def _copy(self, indexes=None):
        if not indexes:
            indexes = self.selectedRows()

        textData = []
        pickleData = []
        for index in indexes:
            record = self.model().record(index.row())
            if record.isEmpty():
                continue

            textRecordData = []
            pickleRecordData = []
            for i in range(self.model().columnCount()):
                value = record.value(i)
                if record.isNull(i):
                    textRecordData.append('')
                    pickleRecordData.append(None)
                elif isinstance(value, QtCore.QByteArray):
                    textRecordData.append('')
                    pickleRecordData.append(value.data())
                else:
                    textRecordData.append(textToClipboard(str(value)))
                    pickleRecordData.append(value)

            textData.append('\t'.join(textRecordData))
            pickleData.append(pickleRecordData)

        mime = QtCore.QMimeData()
        mime.setText('\n'.join(textData))
        mime.setData(ListView.MimeType, pickle.dumps(pickleData))

        clipboard = QApplication.clipboard()
        clipboard.setMimeData(mime)
Beispiel #7
0
 def mimeData(self, indexes, QModelIndex=None):
     item = self.getItemFromIndex(indexes[0])
     print(item.itemData)
     mimedata = QtCore.QMimeData()
     mimedata.setData('text', b"t")
     mimedata.setImageData(indexes[0])
     return mimedata
Beispiel #8
0
 def on_actionCopy_triggered(self):
     self._log.debug("actionCopy_triggered")
     #QtWidgets.QApplication.clipboard().setText("just a plain string", QtGui.QClipboard.Clipboard)
     mimedata = QtCore.QMimeData()
     #mimedata.setData(MIME_TYPE_SVG, self.toSvg(onlySelected=True)) # "arg 2 unexpected type 'str'" under CygWin
     mimedata.setData(MIME_TYPE_SVG, self.toSvg(onlySelected=True).encode())
     QtWidgets.QApplication.clipboard().setMimeData(mimedata)
    def mousePressEvent(self, event):
        # retrieve the label
        child = self.childAt(event.pos())

        if not child:
            return

        self.controller.mode = 'selection'
        # update the creation mode to the appropriate subtype
        self.controller.creation_mode = child.subtype

        pixmap = QPixmap(child.pixmap().scaled(QSize(50,
                                                     50), Qt.KeepAspectRatio,
                                               Qt.SmoothTransformation))

        mime_data = QtCore.QMimeData()
        mime_data.setData('application/x-dnditemdata', QtCore.QByteArray())

        drag = QtGui.QDrag(self)
        drag.setMimeData(mime_data)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - child.pos() + QPoint(-3, -10))

        if drag.exec_(Qt.CopyAction | Qt.MoveAction,
                      Qt.CopyAction) == Qt.MoveAction:
            child.close()
        else:
            child.show()
            child.setPixmap(pixmap)
Beispiel #10
0
    def startDrag(self, supportedActions):
        selected_items = self.selectedItems()

        mimeData = QtCore.QMimeData()

        data = []

        for item in selected_items:

            name = item.name.encode('utf-8')
            entry = item.entry

            if entry == (-1, -1):
                info = {
                    "name": name,
                    "computation": {},
                }
                info = json.dumps(info).encode('utf-8')
            else:
                info = name

            data.append(
                pack(f'<3Q{len(info)}s', entry[0], entry[1], len(info), info))

        mimeData.setData('application/octet-stream-asammdf',
                         QtCore.QByteArray(b''.join(data)))

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.exec(QtCore.Qt.CopyAction)
Beispiel #11
0
    def mouseMoveEvent(self, e):
        if self.piece is None:
            return

        mimeData = QtCore.QMimeData()
        drag = QtGui.QDrag(self)

        path = self.getPathToPieceImg()

        drag.setPixmap(QtGui.QPixmap(path))
        drag.setMimeData(mimeData)
        drag.setHotSpot(e.pos() - self.rect().topLeft())

        piece = self.piece
        self.removePiece()
        self.updatePixmap()

        cursor = QtGui.QPixmap(1, 1)
        cursor.fill(QtCore.Qt.transparent)
        drag.setDragCursor(cursor, QtCore.Qt.MoveAction)

        # If event isn't accepted, return the piece back.
        # It can happen, if we drop piece away from the board
        if not drag.exec(QtCore.Qt.MoveAction):
            self.setPiece(piece)
            self.updatePixmap()
Beispiel #12
0
    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.drag_start_position = event.pos()

        if self.objectName() == 'env_button_load':
            icon = QtGui.QIcon(":/Ressources/data.ico")
            identifier = 'data'
        elif self.objectName() == 'env_button_mask':
            icon = QtGui.QIcon(":/Ressources/mask.ico")
            identifier = 'mask'
        elif self.objectName() == 'env_button_scripts':
            icon = QtGui.QIcon(":/Ressources/script.ico")
            identifier = 'scripts'
        elif self.objectName() == 'env_button_results':
            icon = QtGui.QIcon(":/Ressources/plot_result.ico")
            identifier = 'results'

        self.pixmap = icon.pixmap(QtCore.QSize(30, 30))
        self.mimedata = QtCore.QMimeData()
        self.mimedata.setText(self.parent().findChild(
            QtWidgets.QLineEdit, 'env_input_name').text() + '|' + identifier)

        self.drag = QtGui.QDrag(self)
        self.drag.setMimeData(self.mimedata)
        # self.drag.setDragCursor(self.pixmap, QtCore.Qt.DropAction.MoveAction)
        self.drag.setDragCursor(self.pixmap, QtCore.Qt.DropAction.CopyAction)
Beispiel #13
0
    def mimeData(self, index):
        """
         String wrap the index up as a list of rows and columns of each parent, grandparent and so on..
         Q1: are we starting from the lowest leaf (index[0]) and moving upwards toward root (theindex becomes invalid)?
         Q2: Or do we need to work only on the index which is dragged?

        """
        temp_str = ""
        temp_str1 = ""
        temp_str2 = ""
        theIndex = index[0]
        generation_count = 0
        while theIndex.isValid():
            generation_count = generation_count + 1
            temp_str1 = theIndex.internalPointer().name
            if generation_count == 1:
                temp_str2 = temp_str1
            else:
                temp_str2 = temp_str1 + "/" + temp_str2

            theIndex = self.parent(theIndex)

        if generation_count == 3:
            temp_str = temp_str2
        print("temp_str=", temp_str)
        mimeData = QtCore.QMimeData()
        mimeData.setText(temp_str)
        return mimeData
Beispiel #14
0
    def on_itemPressed(self, item):
        # Parse info to (file + sheet + col) name
        colName = item.text()

        keyName = self.parent.comboBox.currentText()
        fileName = ""
        sheetName = ""

        index = keyName.find(" : ")
        if index == -1:
            fileName = keyName
        else:
            fileName = keyName[0:index]
            sheetName = keyName[index + 3:]

        # Create drag object and execute
        drag = QtGui.QDrag(self)
        data = QtCore.QMimeData()
        data.setText(fileName + "," + sheetName + "," + colName)
        drag.setMimeData(data)

        ret = drag.exec(QtCore.Qt.LinkAction)
        statusBar = self.parent.statusBar()
        if ret != 0:
            statusBar.showMessage("成功拖放欄位", msgDuration)
        else:
            statusBar.showMessage("取消拖放欄位", msgDuration)
Beispiel #15
0
    def mimeData(self, indexes):
        """Returns an object that contains serialized items of data
        corresponding to the list of indexes specified.

        When a node is dragged the information required to drop it later
        on is encoded by this method and returned as a QMimeData object.

        :Parameter indexes: a list of indexes
        """

        mime_data = QtCore.QMimeData()
        encoded_data = QtCore.QByteArray()

        stream = QtCore.QDataStream(encoded_data, QtCore.QIODevice.WriteOnly)

        # Only one item selections are allowed in the tree of databases
        # view so indexes contains always one element
        for index in indexes:
            if index.isValid():
                filepath = self.data(index, QtCore.Qt.UserRole)
                nodepath = self.data(index, QtCore.Qt.UserRole+1)
                row = str(index.row())
                stream.writeQString(filepath)
                stream.writeQString(nodepath)
                stream.writeQString(row)

                self.initial_parent = self.parent(index)

        mime_data.setData("application/x-dbstreemodeldatalist", encoded_data)
        return mime_data
Beispiel #16
0
    def mousePressEvent(self, event):
        child = self.childAt(event.pos())
        if not isinstance(child, DragLabel):
            return

        hotSpot = event.pos() - child.pos()

        itemData = QtCore.QByteArray()
        dataStream = QtCore.QDataStream(itemData, QtCore.QIODevice.WriteOnly)
        dataStream.writeQString(child.labelText())
        dataStream << QtCore.QPoint(hotSpot)

        mimeData = QtCore.QMimeData()
        mimeData.setData(fridgetMagnetsMimeType(), itemData)
        mimeData.setText(child.labelText())

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(child.pixmap())
        drag.setHotSpot(hotSpot)

        child.hide()

        if drag.exec_(QtCore.Qt.MoveAction | QtCore.Qt.CopyAction,
                      QtCore.Qt.CopyAction) == QtCore.Qt.MoveAction:
            child.close()
        else:
            child.show()
Beispiel #17
0
 def insertFromMimeData(self, source):
     text = _clean_text(source.text())
     # Create a new data object, as modifying the existing one does not
     # work on Windows if copying from outside the Qt app.
     source = QtCore.QMimeData()
     source.setText(text)
     return super().insertFromMimeData(source)
Beispiel #18
0
 def mimeData(self, indexes):
     assert len(indexes) == 1
     index, = indexes
     path = index.data(PathRole)
     mime_data = QtCore.QMimeData()
     mime_data.setData(self.MIME_TYPE, str(path).encode())
     return mime_data
Beispiel #19
0
 def mouseMoveEvent(self, event):
     if not self.text():
         return
     mimeData = QtCore.QMimeData()
     mimeData.setText(self.mimeText)
     drag = QtGui.QDrag(self)
     drag.setMimeData(mimeData)
     drag.exec_(QtCore.Qt.CopyAction | QtCore.Qt.MoveAction, QtCore.Qt.CopyAction)
Beispiel #20
0
 def mouseMoveEvent(self, event):
     data = QtCore.QMimeData()
     data.setImageData(self.pixmap().toImage()) 
     drag = QtGui.QDrag(self)
     drag.setMimeData(data) 
     drag.setPixmap(self.pixmap()) 
     drag.setHotSpot(event.pos())
     act = drag.exec_(QtCore.Qt.MoveAction)
Beispiel #21
0
    def mimeData(
            self,
            indexes: typing.Iterable[QtCore.QModelIndex]) -> QtCore.QMimeData:
        index_list = [(index.row(), index.internalId()) for index in indexes]

        mime_data = QtCore.QMimeData()
        mime_data.setData(self.mime_type, pickle.dumps(index_list))
        return mime_data
Beispiel #22
0
 def mimeData(self, indexes):
     data = QtCore.QMimeData()
     liste = []
     for index in indexes:
         if index.isValid():
             liste.append(bytes([index.row()]))
     data.setData("application/queue.item.internal.mime", liste[0])
     return data
Beispiel #23
0
 def mimeData(self, indexes):
     mimedata = QtCore.QMimeData()
     encoded_data = QtCore.QByteArray()
     stream = QtCore.QDataStream(encoded_data, QtCore.QIODevice.WriteOnly)
     for item in set([index.internalPointer() for index in indexes]):
         stream << QtCore.QVariant(item.parent_rows())
     mimedata.setData(self.mimeTypeString, encoded_data)
     return mimedata
    def startDragAction(self):
        mimeData = QtCore.QMimeData()
        mimeData.setText(self.allLayersWindow.currentItem().text())

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)

        drag.exec_()
Beispiel #25
0
    def mouseMoveEvent(self, mouseEvent):
        """
        Executed when the mouse if moved while a button is being pressed.
        :type mouseEvent: QMouseEvent
        """
        if mouseEvent.buttons() & QtCore.Qt.LeftButton:
            distance = (mouseEvent.pos() - self.startPos).manhattanLength()
            if distance >= QtWidgets.QApplication.startDragDistance():
                index = first(self.selectedIndexes())
                if index:
                    model = self.model().sourceModel()
                    index = self.model().mapToSource(index)
                    item = model.itemFromIndex(index)
                    data = item.data(OntologyExplorerView.IRIRole)
                    # Pick the first child when dragging an IRI from the explorer
                    if not isinstance(data,
                                      AbstractNode) and item.hasChildren():
                        data = item.child(0).data(OntologyExplorerView.IRIRole)
                    if data:
                        if isinstance(data, (
                                OntologyEntityNode,
                                OntologyEntityResizableNode,
                        )):
                            mimeData = QtCore.QMimeData()
                            mimeData.setText(str(data.Type.value))
                            node_iri = data.iri
                            buf = QtCore.QByteArray()
                            buf.append(str(node_iri))
                            mimeData.setData(str(data.Type.value), buf)
                            drag = QtGui.QDrag(self)
                            drag.setMimeData(mimeData)
                            drag.exec_(QtCore.Qt.CopyAction)
                        # Placeholder for an imported ontology IRI
                        elif isinstance(data, list):
                            iri = data[0]
                            value = data[1]
                            mimeData = QtCore.QMimeData()
                            mimeData.setText(str(value))
                            buf = QtCore.QByteArray()
                            buf.append(str(iri))
                            mimeData.setData(str(value), buf)
                            drag = QtGui.QDrag(self)
                            drag.setMimeData(mimeData)
                            drag.exec_(QtCore.Qt.CopyAction)

        super().mouseMoveEvent(mouseEvent)
Beispiel #26
0
    def copyItem(self):
        path = self.getCurrentFilePath()
        url = QtCore.QUrl.fromLocalFile(path)
        data = QtCore.QMimeData()
        data.setUrls([url])

        clipboard = self.app.clipboard()
        clipboard.setMimeData(data)
Beispiel #27
0
    def startDrag(self, event):
        if not self.parent.pin:
            logger.warning(
                "Please 'pin' an asset before importing something...")
        elif not self.parent.selected_asset.stage:
            logger.warning("Must import a stage...")

        else:
            assets_list = []
            asset = copy.deepcopy(self.parent.selected_asset)
            default_variant = prefs.asset(asset).stage.default_variant
            variants_list = prefs.asset(asset).stage.variants
            variants_list.remove(default_variant)
            asset.variant = default_variant
            exported_assets_list = prefs.asset(
                asset).export_root.exported_assets_list
            if exported_assets_list != []:
                for exported_asset in exported_assets_list:
                    asset.export_asset = exported_asset
                    asset.export_version = prefs.asset(
                        asset).export.last_version
                    asset.software = prefs.asset(asset).export.version_software
                    if asset.export_version:
                        string_asset = utils.asset_to_string(asset)
                        assets_list.append(string_asset)
            if assets_list == []:
                for variant in variants_list:
                    asset.variant = variant
                    exported_assets_list = prefs.asset(
                        asset).export_root.exported_assets_list
                    if exported_assets_list != []:
                        for exported_asset in exported_assets_list:
                            asset.export_asset = exported_asset
                            asset.export_version = prefs.asset(
                                asset).export.last_version
                            asset.software = prefs.asset(
                                asset).export.version_software
                            if asset.export_version:
                                string_asset = utils.asset_to_string(asset)
                                assets_list.append(string_asset)
                        break
            if assets_list != []:
                mimeData = QtCore.QMimeData()
                mimeData.setText((pickle.dumps(assets_list, 0)).decode())
                drag = QtGui.QDrag(self)
                drag.setMimeData(mimeData)
                icon = defaults._nodes_icons_dic_[
                    self.parent.selected_asset.stage]
                pixmap = QtGui.QPixmap(icon).scaled(
                    38, 38, QtCore.Qt.KeepAspectRatio,
                    QtCore.Qt.SmoothTransformation)
                drag.setPixmap(pixmap)
                drag.setHotSpot(
                    QtCore.QPoint(pixmap.width() / 2, pixmap.height()))
                drag.setPixmap(pixmap)
                result = drag.exec_(QtCore.Qt.MoveAction)
            else:
                logger.warning("No publish found...")
Beispiel #28
0
    def mimeData(self, indexes):
        mimeData = QtCore.QMimeData()

        rowString = "|".join([str(i.row()) for i in indexes if i.isValid()])
        print('rowString:', rowString)

        mimeData.setData(ROW_MIME_TYPE, rowString.encode('utf-8'))

        return mimeData
Beispiel #29
0
 def mimeData(self, indexes):
   data = QtCore.QMimeData()
   liste = []
   for index in indexes:
     if index.isValid():
       packet = self.root.getChild(index.row())
       liste.append(packet)
   data.setData("application/queue.item.mime", pickle.dumps(liste))
   return data
    def mouseMoveEvent(self, e):
        if e.buttons() == QtCore.Qt.LeftButton:
            drag = QtGui.QDrag(self)

            mimeData = QtCore.QMimeData()
            mimeData.setText(self.text())
            drag.setMimeData(mimeData)

            dropAction = drag.exec_(QtCore.Qt.MoveAction)