Example #1
0
    def delete_edge(self, edge, ignore_consequences=False):
        """ remove from scene and remove references from nodes
        :param edge:
        :param ignore_consequences: don't try to fix things like connections,
        just delete.
        """
        # block circular deletion calls
        if edge in self._marked_for_deletion:
            return
        else:
            self._marked_for_deletion.add(edge)

        # -- connections to host nodes --
        start_node = edge.start
        end_node = edge.end
        # -- selections --
        ctrl.remove_from_selection(edge)
        if not ignore_consequences:
            if start_node:
                if edge in start_node.edges_down:
                    start_node.poke('edges_down')
                    start_node.edges_down.remove(edge)
                if edge in start_node.edges_up:  # shouldn't happen
                    start_node.poke('edges_up')
                    start_node.edges_up.remove(edge)
            if end_node:
                if edge in end_node.edges_down:  # shouldn't happen
                    end_node.poke('edges_down')
                    end_node.edges_down.remove(edge)
                if edge in end_node.edges_up:
                    end_node.poke('edges_up')
                    end_node.edges_up.remove(edge)
        # -- ui_support elements --
        ctrl.ui.remove_ui_for(edge)
        # -- dictionaries --
        if edge.uid in self.edges:
            self.poke('edges')
            del self.edges[edge.uid]
        # -- check if it is last of its type --
        found = False
        my_type = edge.edge_type
        if my_type in self.edge_types:
            for e in self.edges.values():
                if e.edge_type == my_type:
                    found = True
                    break
            if not found:
                self.edge_types.remove(my_type)
        # -- make sure that edge is not accidentally restored while fading away
        edge.start = None
        edge.end = None
        # -- scene --
        self.f.remove_from_scene(edge)
        # -- Order update for trees
        self.f.tree_manager.reserve_update_for_trees()
        # -- undo stack --
        edge.announce_deletion()
        # -- remove circularity block
        self._marked_for_deletion.remove(edge)
Example #2
0
 def method(self):
     """ Remove selected node
     :return:
     """
     ctrl.release_editor_focus()
     node = self.get_host()
     ctrl.remove_from_selection(node)
     ctrl.free_drawing.delete_node(node, ignore_consequences=False)
Example #3
0
 def method(self):
     """ Remove selected node
     :return:
     """
     ctrl.release_editor_focus()
     node = self.get_host()
     ctrl.remove_from_selection(node)
     ctrl.free_drawing.delete_node(node, touch_edges=True)
     ctrl.forest.forest_edited()
Example #4
0
    def delete_edge(self, edge, touch_nodes=True, fade=True):
        """ remove from scene and remove references from nodes
        :param edge:
        :param ignore_consequences: don't try to fix things like connections,
        just delete.
        """
        # block circular deletion calls
        if edge in self._marked_for_deletion:
            print('already marked for deletion')
            return
        else:
            self._marked_for_deletion.add(edge)
        # -- connections to host nodes --
        start_node = edge.start
        end_node = edge.end
        # -- remove links to other edges
        if start_node:
            for edge_up in start_node.edges_up:
                if edge_up.end_links_to == edge:
                    edge_up.end_links_to = None
        if end_node:
            for edge_down in end_node.edges_down:
                if edge_down.start_links_to == edge:
                    edge_down.start_links_to = None
                    edge_down.update_start_symbol()
        # -- selections --
        ctrl.remove_from_selection(edge)
        if touch_nodes:
            if start_node:
                if edge in start_node.edges_down:
                    start_node.poke('edges_down')
                    start_node.edges_down.remove(edge)
                if edge in start_node.edges_up:  # shouldn't happen
                    start_node.poke('edges_up')
                    start_node.edges_up.remove(edge)

            if end_node:
                if edge in end_node.edges_down:  # shouldn't happen
                    end_node.poke('edges_down')
                    end_node.edges_down.remove(edge)
                if edge in end_node.edges_up:
                    end_node.poke('edges_up')
                    end_node.edges_up.remove(edge)

        # -- ui_support elements --
        ctrl.ui.remove_ui_for(edge)
        # -- dictionaries --
        if edge.uid in self.edges:
            self.poke('edges')
            del self.edges[edge.uid]
        # -- scene --
        self.forest.remove_from_scene(edge, fade_out=fade)
        # -- undo stack --
        edge.announce_deletion()
        # -- remove circularity block
        self._marked_for_deletion.remove(edge)
Example #5
0
 def method(self, node_uid):
     """ Remove given node
     :param node_uid: int or string, node's unique identifier
     :return:
     """
     ctrl.release_editor_focus()
     node = ctrl.forest.nodes[node_uid]
     ctrl.remove_from_selection(node)
     ctrl.drawing.delete_node(node, touch_edges=True)
     ctrl.forest.forest_edited()
Example #6
0
 def delete_edge(self, edge, touch_nodes=True, fade=True):
     """ remove from scene and remove references from nodes
     :param edge:
     :param ignore_consequences: don't try to fix things like connections,
     just delete.
     """
     # block circular deletion calls
     if edge in self._marked_for_deletion:
         print('already marked for deletion')
         return
     else:
         self._marked_for_deletion.add(edge)
     # -- connections to host nodes --
     start_node = edge.start
     end_node = edge.end
     # -- selections --
     ctrl.remove_from_selection(edge)
     if touch_nodes:
         if start_node:
             if edge in start_node.edges_down:
                 start_node.poke('edges_down')
                 start_node.edges_down.remove(edge)
             if edge in start_node.edges_up:  # shouldn't happen
                 start_node.poke('edges_up')
                 start_node.edges_up.remove(edge)
         if end_node:
             if edge in end_node.edges_down:  # shouldn't happen
                 end_node.poke('edges_down')
                 end_node.edges_down.remove(edge)
             if edge in end_node.edges_up:
                 end_node.poke('edges_up')
                 end_node.edges_up.remove(edge)
     # -- ui_support elements --
     ctrl.ui.remove_ui_for(edge)
     # -- dictionaries --
     if edge.uid in self.edges:
         self.poke('edges')
         del self.edges[edge.uid]
     # -- check if it is last of its type --
     found = False
     my_type = edge.edge_type
     if my_type in self.edge_types:
         for e in self.edges.values():
             if e.edge_type == my_type:
                 found = True
                 break
         if not found:
             self.edge_types.remove(my_type)
     # -- scene --
     self.f.remove_from_scene(edge, fade_out=fade)
     # -- undo stack --
     edge.announce_deletion()
     # -- remove circularity block
     self._marked_for_deletion.remove(edge)
Example #7
0
 def flush_and_rebuild_temporary_items(self):
     """ Clean up temporary stuff that may be invalidated by changes made by undo/redo.
     Notice that draw() does some of this, don't have to do those here.
     :return:
     """
     # Selection and related UI
     ctrl.multiselection_start()
     for item in ctrl.selected:
         if not self.get_object_by_uid(item.uid):
             ctrl.remove_from_selection(item)
     ctrl.multiselection_end()
Example #8
0
 def flush_and_rebuild_temporary_items(self):
     """ Clean up temporary stuff that may be invalidated by changes made by undo/redo.
     Notice that draw() does some of this, don't have to do those here.
     :return:
     """
     # Selection and related UI
     legits = list(self.get_all_objects())
     ctrl.multiselection_start()
     for item in ctrl.selected:
         if item not in legits:
             ctrl.remove_from_selection(item)
     ctrl.multiselection_end()
Example #9
0
 def method(self):
     """ In cases where there another part of binary merge is removed,
     and a stub edge is left dangling,
     there is an option to remove the unnecessary merge -- it is the
     triggering host.
     :return: None
     """
     ctrl.release_editor_focus()
     node = self.get_host()
     if not node:
         return
     ctrl.remove_from_selection(node)
     ctrl.free_drawing.delete_unnecessary_merger(node)
Example #10
0
 def method(self):
     """ In cases where there another part of binary merge is removed,
     and a stub edge is left dangling,
     there is an option to remove the unnecessary merge -- it is the
     triggering host.
     :return: None
     """
     ctrl.release_editor_focus()
     node = self.get_host()
     if not node:
         return
     ctrl.remove_from_selection(node)
     ctrl.free_drawing.delete_unnecessary_merger(node)
     ctrl.forest.forest_edited()
Example #11
0
 def method(self, node_uid):
     """ In cases where there another part of binary merge is removed,
     and a stub edge is left dangling, there is an option to remove the unnecessary
     merge -- this is the triggering host.
     :param node_uid: int or string, node's unique identifier
     :return: None
     """
     ctrl.release_editor_focus()
     node = ctrl.forest.nodes[node_uid]
     children = node.get_children(similar=True)
     if len(children) != 1:
         log.warn('Trying to remove an intermediate monobranch node, but node "%s" '
                  'is not such node.' % node)
     ctrl.remove_from_selection(node)
     ctrl.drawing.delete_unnecessary_merger(node)
     ctrl.forest.forest_edited()
Example #12
0
 def method(self, object_uid):
     """ Add node, edge or other selectable object to selection
     :param object_uid: int or str uid of item to select, or list of uids for adding
      multiple objects. None or empty list does nothingh.
     :return: None
     """
     if not object_uid:
         return
     elif isinstance(object_uid, (list, tuple)):
         objs = []
         for uid in object_uid:
             obj = ctrl.forest.get_object_by_uid(uid)
             if obj:
                 objs.append(obj)
         ctrl.remove_from_selection(objs)
     else:
         obj = ctrl.forest.get_object_by_uid(object_uid)
         ctrl.remove_from_selection(obj)
Example #13
0
 def select(self, event=None, multi=False):
     """ Scene has decided that this node has been clicked
     :param event:
     :param multi: assume multiple selection (append, don't replace)
     """
     if not self.persistent:
         return
     ctrl.multiselection_start()
     if (event and event.modifiers() == QtCore.Qt.ShiftModifier) or multi:
         # multiple selection
         if ctrl.is_selected(self):
             ctrl.remove_from_selection(self)
         else:
             ctrl.add_to_selection(self)
             for item in self.selection:
                 ctrl.add_to_selection(item)
     elif ctrl.is_selected(self):
         ctrl.deselect_objects()
     else:
         ctrl.deselect_objects()
         ctrl.add_to_selection(self)
         for item in self.selection:
             ctrl.add_to_selection(item)
     ctrl.multiselection_end()
Example #14
0
 def select(self, event=None, multi=False):
     """ Scene has decided that this node has been clicked
     :param event:
     :param multi: assume multiple selection (append, don't replace)
     """
     if not self.persistent:
         return
     ctrl.multiselection_start()
     if (event and event.modifiers() == QtCore.Qt.ShiftModifier) or multi:
         # multiple selection
         if ctrl.is_selected(self):
             ctrl.remove_from_selection(self)
         else:
             ctrl.add_to_selection(self)
             for item in self.selection:
                 ctrl.add_to_selection(item)
     elif ctrl.is_selected(self):
         ctrl.deselect_objects()
     else:
         ctrl.deselect_objects()
         ctrl.add_to_selection(self)
         for item in self.selection:
             ctrl.add_to_selection(item)
     ctrl.multiselection_end()
Example #15
0
    def delete_node(self, node, touch_edges=True, fade=True):
        """ Delete given node and its children and fix the trees accordingly
        :param node:
        :param touch_edges: don't try to set edge ends.
        just delete.
        :param fade: fade or disappear instantly
        """
        # block circular deletion calls
        if node in self._marked_for_deletion:
            return
        else:
            self._marked_for_deletion.add(node)

        # -- connections to other nodes --
        if touch_edges:
            for edge in list(node.edges_down):
                if edge.end:
                    if edge.end.node_type == node.node_type:
                        # don't delete children by default, make them their own trees
                        self.disconnect_edge(edge)
                    else:
                        # if deleting node, delete its features, glosses etc. as well
                        self.delete_node(edge.end)
                else:
                    self.disconnect_edge(edge)
            for edge in list(node.edges_up):
                self.disconnect_edge(edge)

        # -- ui_support elements --
        ctrl.ui.remove_ui_for(node)
        # -- groups --
        if ctrl.ui.selection_group and node in ctrl.ui.selection_group:
            ctrl.ui.selection_group.remove_node(node)
        for group in self.groups.values():
            if node in group:
                group.remove_node(node)

        # -- dictionaries --
        if node.uid in self.nodes:
            self.poke('nodes')
            del self.nodes[node.uid]
        if node.syntactic_object:
            if node.syntactic_object.uid in self.f.nodes_from_synobs:
                del self.f.nodes_from_synobs[node.syntactic_object.uid]

        assert (node.uid not in self.f.nodes)
        # -- check if it is last of its type --
        found = False
        my_type = node.node_type
        for n in self.nodes.values():
            if n.node_type == my_type:
                found = True
                break
        if not found:
            if my_type in self.node_types:
                self.node_types.remove(my_type)

        # if fading out, item scene position has to remain same during the fade. If disappear
        # instantly, it doesnt matter
        if node.parentItem():
            if fade:
                scpos = node.scenePos()
                node.setParentItem(None)
                node.set_original_position(scpos)
            else:
                node.setParentItem(None)

        if hasattr(node, 'on_delete'):
            node.on_delete()
        # -- scene --
        self.f.remove_from_scene(node, fade_out=fade)
        # -- undo stack --
        node.announce_deletion()
        # -- remove from selection
        ctrl.remove_from_selection(node)
        # -- remove circularity block
        self._marked_for_deletion.remove(node)
Example #16
0
    def delete_node(self, node, touch_edges=True, fade=True):
        """ Delete given node and its children and fix the trees accordingly
        :param node:
        :param touch_edges: don't try to set edge ends.
        just delete.
        :param fade: fade or disappear instantly
        """
        # block circular deletion calls
        if node in self._marked_for_deletion:
            return
        else:
            self._marked_for_deletion.add(node)

        # -- connections to other nodes --
        if touch_edges:
            for edge in list(node.edges_down):
                if edge.end:
                    if edge.end.node_type == node.node_type:
                        # don't delete children by default, make them their own trees
                        self.disconnect_edge(edge)
                    else:
                        # if deleting node, delete its features, glosses etc. as well
                        self.delete_node(edge.end)
                else:
                    self.disconnect_edge(edge)
            for edge in list(node.edges_up):
                self.disconnect_edge(edge)

        # -- ui_support elements --
        ctrl.ui.remove_ui_for(node)
        # -- groups --
        if ctrl.ui.selection_group and node in ctrl.ui.selection_group:
            ctrl.ui.selection_group.remove_node(node)
        for group in list(self.groups.values()):
            if node in group:
                group.remove_node(node)

        # -- dictionaries --
        if node.uid in self.nodes:
            self.poke('nodes')
            del self.nodes[node.uid]
        if node.syntactic_object:
            if node.syntactic_object.uid in self.forest.nodes_from_synobs:
                del self.forest.nodes_from_synobs[node.syntactic_object.uid]

        assert (node.uid not in self.forest.nodes)

        # if fading out, item scene position has to remain same during the fade. If disappear
        # instantly, it doesnt matter
        if node.parentItem():
            if fade:
                scpos = node.scenePos()
                node.setParentItem(None)
                node.set_original_position(scpos)
            else:
                node.setParentItem(None)

        if hasattr(node, 'on_delete'):
            node.on_delete()
        # -- scene --
        self.forest.remove_from_scene(node, fade_out=fade)
        # -- undo stack --
        node.announce_deletion()
        # -- remove from selection
        ctrl.remove_from_selection(node)
        # -- remove circularity block
        self._marked_for_deletion.remove(node)
Example #17
0
    def delete_node(self, node, ignore_consequences=False):
        """ Delete given node and its children and fix the trees accordingly
        :param node:
        :param ignore_consequences: don't try to fix things like connections,
        just delete.
        Note: This and other complicated revisions assume that the target trees is 'normalized' by
        replacing multidomination with traces. Each node can have only one parent.
        This makes calculation easier, just remember to call multidomination_to_traces and
        traces_to_multidomination after deletions.
        """
        # block circular deletion calls
        if node in self._marked_for_deletion:
            return
        else:
            self._marked_for_deletion.add(node)
        for tree in node.trees:
            tree.deleted_nodes.add(node)

        # -- connections to other nodes --
        if not ignore_consequences:
            for edge in list(node.edges_down):
                if edge.end:
                    if edge.end.node_type == node.node_type:
                        # don't delete children by default, make them their own trees
                        self.disconnect_edge(edge)
                    else:
                        # if deleting node, delete its features, glosses etc. as well
                        self.delete_node(edge.end)
                else:
                    self.disconnect_edge(edge)
            for edge in list(node.edges_up):
                self.disconnect_edge(edge)

        # -- ui_support elements --
        ctrl.ui.remove_ui_for(node)
        # -- groups --
        if ctrl.ui.selection_group and node in ctrl.ui.selection_group:
            ctrl.ui.selection_group.remove_node(node)
        for group in self.groups.values():
            if node in group:
                group.remove_node(node)

        # -- dictionaries --
        if node.uid in self.nodes:
            self.poke('nodes')
            del self.nodes[node.uid]
        # -- check if it is last of its type --
        found = False
        my_type = node.node_type
        for n in self.nodes.values():
            if n.node_type == my_type:
                found = True
                break
        if not found:
            if my_type in self.node_types:
                self.node_types.remove(my_type)
        # -- trees --
        old_trees = set(node.trees)
        for tree in old_trees:
            if tree.top is node:
                tree.remove_node(node, recursive_down=False)
            else:
                tree.update_items()
        if node.parentItem():
            node.setParentItem(None)
        if hasattr(node, 'on_delete'):
            node.on_delete()
        # -- scene --
        self.f.remove_from_scene(node)
        # -- undo stack --
        node.announce_deletion()
        # -- remove from selection
        ctrl.remove_from_selection(node)
        # -- remove circularity block
        self._marked_for_deletion.remove(node)