def dropEvent(self, event): """ Support dragging of items from their panel containers, e.g. symbols from symbol panel or new nodes from nodes panel. :param event: """ event.ignore() QtWidgets.QGraphicsScene.dropEvent(self, event) message = "" if not event.isAccepted(): data = event.mimeData() event.accept() if data.hasFormat("application/x-qabstractitemmodeldatalist"): data = open_symbol_data(event.mimeData()) if data and 'char' in data: event.acceptProposedAction() text = data['char'] node = ctrl.forest.drawing.create_node_from_text(text) node.current_position = event.scenePos().x(), event.scenePos().y() message = f'Added node "{node}"' elif data.hasFormat("text/plain"): event.acceptProposedAction() command_identifier, *args = data.text().split(':') if command_identifier == 'kataja' and args: command, *args = args if command == "new_node": node_type = args[0] try: node_type = int(node_type) except TypeError: pass node = ctrl.drawing.create_node(pos=event.scenePos(), node_type=node_type) node.current_position = event.scenePos().x(), event.scenePos().y() if node_type != CONSTITUENT_NODE: node.lock() message = 'added %s' % args[0] else: print('received unknown command:', command, args) else: text = data.text().strip() node = ctrl.forest.drawing.create_node_from_text(text) message = f'Added node "{node}"' elif data.hasUrls(): for url in data.urls(): path = url.toString() if path.endswith(('png', 'jpg', 'pdf')): node = ctrl.drawing.create_comment_node(pixmap_path=url.toLocalFile()) message = 'Added image' ctrl.ui.remove_touch_areas() if message: ctrl.forest.forest_edited() ctrl.main.action_finished(message)
def dropEvent(self, event): """ Support regular ascii drops and drops of characters from symbolpanel. :param event: QDropEvent :return: """ if event.mimeData().hasFormat("application/x-qabstractitemmodeldatalist"): data = open_symbol_data(event.mimeData()) if data and 'char' in data: self.insert(data['char']) event.acceptProposedAction() else: return QtWidgets.QPlainTextEdit.dropEvent(self, event)
def dropEvent(self, event): """ Support regular ascii drops and drops of characters from symbolpanel. :param event: QDropEvent :return: """ if event.mimeData().hasFormat( "application/x-qabstractitemmodeldatalist"): data = open_symbol_data(event.mimeData()) if data and 'char' in data: self.insert(data['char']) event.acceptProposedAction() else: return QtWidgets.QPlainTextEdit.dropEvent(self, event)
def dropEvent(self, event): mim = event.mimeData() if mim.hasFormat("application/x-qabstractitemmodeldatalist"): event.accept() data = open_symbol_data(event.mimeData()) if data and 'char' in data: self.editable_part.textCursor().insertText(data['char']) event.acceptProposedAction() elif mim.hasFormat("text/plain"): event.accept() event.acceptProposedAction() self.editable_part.dropEvent(event) else: self.editable_part.dropEvent(event)
def dropEvent(self, event): mim = event.mimeData() if mim.hasFormat("application/x-qabstractitemmodeldatalist"): print('label dropEvent application/x-qabstractitemmodeldatalist') event.accept() data = open_symbol_data(event.mimeData()) if data and 'char' in data: self.editable_part.textCursor().insertText(data['char']) event.acceptProposedAction() elif mim.hasFormat("text/plain"): print('label dropEvent text/plain') event.accept() event.acceptProposedAction() self.editable_part.dropEvent(event) else: print('label dropEvent something') self.editable_part.dropEvent(event)
def dropEvent(self, event): """ Support dragging of items from their panel containers, e.g. symbols from symbol panel or new nodes from nodes panel. :param event: """ event.ignore() QtWidgets.QGraphicsScene.dropEvent(self, event) if not event.isAccepted(): data = event.mimeData() event.accept() if data.hasFormat("application/x-qabstractitemmodeldatalist"): data = open_symbol_data(event.mimeData()) if data and 'char' in data: event.acceptProposedAction() if ctrl.free_drawing_mode: node = ctrl.free_drawing.create_node( pos=event.scenePos(), node_type=g.CONSTITUENT_NODE, label=data['char']) node.current_position = event.scenePos().x( ), event.scenePos().y() node.lock() message = 'Created constituent "%s"' % node else: node = ctrl.free_drawing.create_comment_node( text=data['char']) node.current_position = event.scenePos().x( ), event.scenePos().y() node.lock() message = 'Added "%s" as comment since we are in derivation mode and ' \ 'cannot change trees' % data['char'] elif data.hasFormat("text/plain"): event.acceptProposedAction() command_identifier, *args = data.text().split(':') if command_identifier == 'kataja' and args: command, *args = args if command == "new_node": node_type = args[0] try: node_type = int(node_type) except TypeError: pass node = ctrl.free_drawing.create_node( pos=event.scenePos(), node_type=node_type) node.current_position = event.scenePos().x( ), event.scenePos().y() if node_type != g.CONSTITUENT_NODE: node.lock() message = 'added %s' % args[0] else: print('received unknown command:', command, args) else: text = data.text().strip() if ctrl.free_drawing_mode: node = ctrl.forest.simple_parse(text) message = 'Added tree based on "%s".' % text else: node = ctrl.free_drawing.create_comment_node(text=text) message = 'Added text as comment node since we are in derivation mode ' \ 'and cannot change trees.' elif data.hasUrls(): for url in data.urls(): path = url.toString() if path.endswith(('png', 'jpg', 'pdf')): node = ctrl.free_drawing.create_comment_node( pixmap_path=url.toLocalFile()) message = 'Added image' ctrl.ui.remove_touch_areas() if message: ctrl.forest.forest_edited() ctrl.main.action_finished(message)
def dropEvent(self, event): """ Support dragging of items from their panel containers, e.g. symbols from symbol panel or new nodes from nodes panel. :param event: """ event.ignore() QtWidgets.QGraphicsScene.dropEvent(self, event) if not event.isAccepted(): data = event.mimeData() event.accept() if data.hasFormat("application/x-qabstractitemmodeldatalist"): data = open_symbol_data(event.mimeData()) if data and 'char' in data: event.acceptProposedAction() if ctrl.free_drawing_mode: node = ctrl.free_drawing.create_node(pos=event.scenePos(), node_type=g.CONSTITUENT_NODE, text=data['char']) node.current_position = event.scenePos().x(), event.scenePos().y() node.lock() ctrl.main.action_finished('Created constituent "%s"' % node) else: node = ctrl.free_drawing.create_comment_node(text=data['char']) node.current_position = event.scenePos().x(), event.scenePos().y() node.lock() ctrl.main.action_finished('Added "%s" as comment since we are in ' 'derivation mode and cannot change trees' % data['char']) elif data.hasFormat("text/plain"): event.acceptProposedAction() command_identifier, *args = data.text().split(':') if command_identifier == 'kataja' and args: command, *args = args if command == "new_node": node_type = args[0] try: node_type = int(node_type) except TypeError: pass node = ctrl.free_drawing.create_node(pos=event.scenePos(), node_type=node_type) node.current_position = event.scenePos().x(), event.scenePos().y() if node_type != g.CONSTITUENT_NODE: node.lock() ctrl.main.action_finished('added %s' % args[0]) else: print('received unknown command:', command, args) else: text = data.text().strip() if ctrl.free_drawing_mode: node = ctrl.forest.simple_parse(text) ctrl.main.action_finished('Added tree based on "%s".' % text) else: node = ctrl.free_drawing.create_comment_node(text=text) ctrl.main.action_finished('Added text as comment node since we are in ' 'derivation mode and cannot change trees.') elif data.hasUrls(): for url in data.urls(): path = url.toString() if path.endswith(('png', 'jpg', 'pdf')): node = ctrl.free_drawing.create_comment_node(pixmap_path=url.toLocalFile()) ctrl.main.action_finished('Added image') ctrl.ui.remove_touch_areas()