def graphicsMouseMoveEvent(self, event, itemId=0): """This function is called by the owned :class:`~ts2.scenery.helper.TrackGraphicsItem` to handle its :meth:`~ts2.scenery.helper.TrackGraphicsItem.mouseMoveEvent`. Reimplemented in the ResizableItem class to begin a drag operation on corners.""" if event.buttons() == Qt.LeftButton and \ self.simulation.context == utils.Context.EDITOR_SCENERY: if QtCore.QLineF(event.scenePos(), event.buttonDownScenePos( Qt.LeftButton)).length() < 3.0: return drag = QtGui.QDrag(event.widget()) mime = QtCore.QMimeData() pos = event.buttonDownScenePos(Qt.LeftButton) - self.origin if QtCore.QRectF(-5, -5, 9, 9).contains(pos): movedEnd = "start" elif QtCore.QRectF(self.end.x() - self.origin.x() - 5, self.end.y() - self.origin.y() - 5, 9, 9).contains(pos): movedEnd = "end" pos -= self.end - self.origin # elif self._gi[itemId].shape().contains(pos): else: movedEnd = "origin" if movedEnd is not None: mime.setText( type(self).__name__ + "#" + str(self.tiId) + "#" + str(pos.x()) + "#" + str(pos.y()) + "#" + movedEnd) drag.setMimeData(mime) drag.exec_()
def addCommentAct(self): mimeData = QtCore.QMimeData() data = 'Comment' mimeData.setText(data) drag = QtGui.QDrag(self) drag.setMimeData(mimeData) drag.exec_(QtCore.Qt.CopyAction)
def _on_copy_to_clipboard(self): all_data = get_all_current_info() all_data_str = json.dumps(all_data, indent=4) mime_data = QtCore.QMimeData() mime_data.setText(all_data_str) QtWidgets.QApplication.instance().clipboard().setMimeData(mime_data)
def mousePressEvent(self, event): super(NodeBoxTreeWidget, self).mousePressEvent(event) item_clicked = self.currentItem() if not item_clicked: event.ignore() return # check if clicked item is a category if item_clicked.bCategory: event.ignore() return # find top level parent rootItem = item_clicked while not rootItem.parent() is None: rootItem = rootItem.parent() packageName = rootItem.text(0) pressed_text = item_clicked.text(0) libName = item_clicked.libName if pressed_text in self.categoryPaths.keys(): event.ignore() return jsonTemplate = NodeBase.jsonTemplate() jsonTemplate['package'] = packageName jsonTemplate['lib'] = libName jsonTemplate['type'] = pressed_text jsonTemplate['name'] = pressed_text jsonTemplate['uuid'] = str(uuid.uuid4()) jsonTemplate['meta']['label'] = pressed_text # TODO: Rewrite self.bGripsEnabled. Node box can be floating window or a tool. # If node box is a tool it onbly can create nodes by dragging and dropping if self.canvas.pressedPin is not None and self.bGripsEnabled: a = self.canvas.mapToScene(self.canvas.mouseReleasePos) jsonTemplate["x"] = a.x() jsonTemplate["y"] = a.y() node = self.canvas.createNode(jsonTemplate) self.canvas.hideNodeBox() pressedPin = self.canvas.pressedPin if pressedPin.direction == PinDirection.Input: for pin in node.UIoutputs.values(): wire = self.canvas.connectPinsInternal(pressedPin, pin) if wire is not None: EditorHistory().saveState("Connect pins", modify=True) break if pressedPin.direction == PinDirection.Output: for pin in node.UIinputs.values(): wire = self.canvas.connectPinsInternal(pin, pressedPin) if wire is not None: EditorHistory().saveState("Connect pins", modify=True) break else: drag = QtGui.QDrag(self) mime_data = QtCore.QMimeData() pressed_text = json.dumps(jsonTemplate) mime_data.setText(pressed_text) drag.setMimeData(mime_data) drag.exec_()
def mouseMoveEvent(self, event): name = self.label drag = QtGui.QDrag(self) ba = bytearray(name, "utf-8") drag_mime_data = QtCore.QMimeData() drag_mime_data.setData(self.QMimeDataType, QtCore.QByteArray(ba)) drag.setMimeData(drag_mime_data) drag.exec_(QtCore.Qt.MoveAction)
def addPinAct(self): mimeData = QtCore.QMimeData() data = 'ipin' mimeData.setText(data) drag = QtGui.QDrag(self) drag.setMimeData(mimeData) drag.exec_(QtCore.Qt.CopyAction)
def lwMousePressEvent(self, event): QListWidget.mousePressEvent(self, event) w = self.itemWidget(self.currentItem()) if w: drag = QtGui.QDrag(self) mime_data = QtCore.QMimeData() mime_data.setText("Var|" + str(w.uid)) drag.setMimeData(mime_data) drag.exec_()
def mouseMoveEvent(self, event): name = self._label print(name) drag = QtGui.QDrag(self) # ba = bytearray(name, 'utf-8') drag_mime_data = QtCore.QMimeData() drag_mime_data.setData(self.QMimeDataType, QtCore.QByteArray(name)) drag.setMimeData(drag_mime_data) drag.exec_(QtCore.Qt.MoveAction)
def clickCell(self): cell = self.cells.currentItem() if (cell): mimeData = QtCore.QMimeData() data = '@'.join([self.libraries.currentItem().text(), cell.text()]) mimeData.setText(data) drag = QtGui.QDrag(self) drag.setMimeData(mimeData) drag.exec_(QtCore.Qt.CopyAction)
def mimeData(self, indexes): mimedata = QtCore.QMimeData() encoded_data = QtCore.QByteArray() stream = QtCore.QDataStream(encoded_data, QtCore.QIODevice.WriteOnly) for index in indexes: if index.isValid(): text = self.data(index, 0) stream << QtCore.QByteArray(text.encode("utf-8")) mimedata.setData("application/vnd.treeviewdragdrop.list", encoded_data) return mimedata
def mousePressEvent(self, event): super(VariablesListWidget, self).mousePressEvent(event) w = self.itemWidget(self.currentItem()) if w: drag = QtGui.QDrag(self) mime_data = QtCore.QMimeData() varJson = w.serialize() dataJson = {VARIABLE_TAG: True, VARIABLE_DATA_TAG: varJson} mime_data.setText(json.dumps(dataJson)) drag.setMimeData(mime_data) drag.exec_()
def mouseMoveEvent(self, event): if event.buttons() == QtCore.Qt.LeftButton and isinstance( self.actComp, Block): mimeData = QtCore.QMimeData() block = self.actComp # attributes = {'name':c.name,'input':c.inp,'output':c.outp,'icon':c.icon,'flip':c.flip,'libname':c.libname,'type':c.type} # data = '@'.join([str(attributes),str(c.parameters),str(c.properties),c.blockname,c.libname]) data = '@'.join([block.libname, block.blockname]) mimeData.setText(data) drag = QtGui.QDrag(self.parent) drag.setMimeData(mimeData) drag.exec_(QtCore.Qt.CopyAction)
def startDrag(self, event): # create mime data object mime = QtCore.QMimeData() mime.setText(self.currentItem().text(self.columnPath)) # start drag drag = QtGui.QDrag(self) drag.setMimeData(mime) if not Qt.USE_QT_PY == Qt.PYQT5: start = drag.start else: start = drag.exec_ start(QtCore.Qt.MoveAction)
def keyPressEvent(self, event): if (event.type() == QtGui.QKeyEvent.KeyPress and event.matches(QtGui.QKeySequence.Copy)): selected_data = self.get_selection_as_dict() selected_str = json.dumps(selected_data, indent=4) mime_data = QtCore.QMimeData() mime_data.setText(selected_str) QtWidgets.QApplication.instance().clipboard().setMimeData( mime_data) event.accept() else: return super(EnvironmentsView, self).keyPressEvent(event)
def mousePressEvent(self, event): super(NodeBoxTreeWidget, self).mousePressEvent(event) canvas = self.parent().canvasRef() item_clicked = self.currentItem() if not item_clicked: event.ignore() return # check if clicked item is a category if item_clicked.bCategory: event.ignore() return # find top level parent rootItem = item_clicked while not rootItem.parent() is None: rootItem = rootItem.parent() packageName = rootItem.text(0) pressed_text = item_clicked.text(0) libName = item_clicked.libName if pressed_text in self.categoryPaths.keys(): event.ignore() return try: mousePos = canvas.mapToScene(canvas.mousePressPose) except: mousePos = canvas.mapToScene(canvas.mousePressPose.toPoint()) jsonTemplate = NodeBase.jsonTemplate() jsonTemplate['package'] = packageName jsonTemplate['lib'] = libName jsonTemplate['type'] = pressed_text jsonTemplate['name'] = pressed_text jsonTemplate['uuid'] = str(uuid.uuid4()) jsonTemplate['x'] = mousePos.x() jsonTemplate['y'] = mousePos.y() jsonTemplate['meta']['label'] = pressed_text if self.bUseDragAndDrop: drag = QtGui.QDrag(self) mime_data = QtCore.QMimeData() pressed_text = json.dumps(jsonTemplate) mime_data.setText(pressed_text) drag.setMimeData(mime_data) drag.exec_() else: canvas.createNode(jsonTemplate)
def mimeData(self, indexes): mimedata = QtCore.QMimeData() text_list = [str(i.internalPointer().id) for i in indexes] csv_data = ",".join(text_list) # IMPORTANT # for some reason if we don't setData # and only setText # the dropIndicator doesn't show! # in fact painting seems to be blocked entirely # TODO maybe the mime data is erroring and failing to show an error? mimedata.setData("id_csv_data", csv_data) # mimedata.setText("test") return mimedata
def mimeData(self, indices): #print("Generate mime Data - len:"+str(len(indices)),flush=True) mimeData = QtCore.QMimeData() encodedData = QtCore.QByteArray() if len(indices) != 1: return None stream = QtCore.QDataStream(encodedData, QtCore.QIODevice.WriteOnly) index=indices[0] item = index.internalPointer() #data=str(id(item))#ukazatel data="AHOJ" self._dragFrom=index mimeData.setData("application/pou.cz", bytes(data, 'utf-8')) mimeData.setText(data) return mimeData
def graphicsMouseMoveEvent(self, event, itemId=0): """This function is called by the owned TrackGraphicsItem to handle its mouseMoveEvent. The implementation in the base class TrackItem begins a drag operation.""" if itemId == 0: if (event.buttons() == Qt.LeftButton and self.simulation.context == utils.Context.EDITOR_SCENERY): if QtCore.QLineF(event.scenePos(), event.buttonDownScenePos( Qt.LeftButton)).length() < 3.0: return drag = QtGui.QDrag(event.widget()) mime = QtCore.QMimeData() pos = event.buttonDownScenePos(Qt.LeftButton) - self.origin mime.setText( type(self).__name__ + "#" + str(self.tiId) + "#" + str(pos.x()) + "#" + str(pos.y()) + "#" + "origin") drag.setMimeData(mime) drag.exec_()
def mimeData(self, indexes): data = QtCore.QMimeData() data.setText(indexes[0].data(QtCore.Qt.ToolTipRole)) return data
def mimeData(self, indexes): """ Get mime data stream. :param indexes: Indexes. :type indexes: collections.abc.Iterable[QtCore.QModelIndex] :return: Mime data stream. :rtype: QtCore.QMimeData or None """ if not indexes: return None obj = self.obj() if obj is None: return None mime_type = self.mimeType() if not mime_type: return None # Force first column only. filtered_indexes = [] for index in indexes: if index.column() != 0: index = index.sibling(index.row(), 0) filtered_indexes.append(index) if not filtered_indexes: return None indexes = filtered_indexes # Only sequential indexes are supported. rows = [] for i, index in enumerate(sorted(indexes, key=lambda x: x.row())): row = index.row() if i > 0: previous_row = rows[-1] if previous_row == row: continue if previous_row + 1 != row: return None rows.append(row) first_row = rows[0] last_row = rows[-1] serialized_objs = [] contents = { "obj_id": id(obj), "first_row": first_row, "last_row": last_row, "serialized_objs": serialized_objs, } with obj.app.read_context(): for row in rows: item = obj[row] if isinstance(item, BaseObject): try: serialized_obj = obj.serialize_value(item) except SerializationError: serialized_obj = item else: serialized_obj = item serialized_objs.append(serialized_obj) # Prepare data stream. try: data_stream = safe_dump(contents) except YAMLError: return None mime_data = QtCore.QMimeData() # noinspection PyTypeChecker mime_data.setData(mime_type, ensure_binary(data_stream)) return mime_data