Пример #1
0
 def redo(self):
     """ Move forward in the undo stack
     :return: None
     """
     if self._current < len(self._stack) - 1:
         self._current += 1
     else:
         log.info('redo [%s]: In last action' % self._current)
         return
     ctrl.disable_undo()
     ctrl.multiselection_start()
     ctrl.forest.halt_drawing = True
     msg, snapshot = self._stack[self._current]
     affected = set()
     for obj, transitions, transition_type in snapshot.values():
         obj.move_to_later(transitions)
         if transition_type == CREATED:
             ctrl.forest.add_to_scene(obj)
         elif transition_type == DELETED:
             ctrl.free_drawing.delete_item(obj, ignore_consequences=True)
         affected.add(obj)
     ctrl.forest.edge_visibility_check()
     for obj, transitions, transition_type in snapshot.values():
         obj.after_model_update(transitions.keys(), transition_type)
         if getattr(obj.__class__, 'syntactic_object', False):
             node = ctrl.forest.nodes_from_synobs.get(obj.uid, None)
             if node and node not in affected:
                 node.after_model_update([], transition_type)
     ctrl.forest.flush_and_rebuild_temporary_items()
     log.info('redo [%s]: %s' % (self._current, msg))
     ctrl.multiselection_end()
     ctrl.resume_undo()
     ctrl.forest.halt_drawing = False
     print('------redo finished: ', msg, self._current)
Пример #2
0
 def method(self):
     """ In many contexts this will delete something. Expand this as necessary
     for contexts that don't otherwise grab keyboard.
     :return: None
     """
     print('key_backspace - action')
     ctrl.multiselection_start() # don't update selections until all are removed
     for item in list(ctrl.selected):
         ctrl.free_drawing.delete_item(item)
     ctrl.multiselection_end() # ok go update
Пример #3
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()
Пример #4
0
 def method(self):
     """ In many contexts this will delete something. Expand this as necessary
     for contexts that don't otherwise grab keyboard.
     :return: None
     """
     print('key_backspace - action')
     ctrl.multiselection_start(
     )  # don't update selections until all are removed
     for item in list(ctrl.selected):
         ctrl.free_drawing.delete_item(item)
     ctrl.multiselection_end()  # ok go update
     ctrl.forest.forest_edited()
Пример #5
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()
Пример #6
0
    def undo(self):
        """ Move backward in the undo stack
        :return: None
        """
        if not self._stack:
            return
        if self._current == 0:
            log.info('undo [%s]: Cannot undo further' % self._current)
            return
        ctrl.disable_undo()
        ctrl.multiselection_start()
        ctrl.forest.halt_drawing = True
        msg, snapshot = self._stack[self._current]
        affected = set()
        for obj, transitions, transition_type in snapshot.values():
            obj.revert_to_earlier(transitions)
            if transition_type == CREATED:
                ctrl.free_drawing.delete_item(obj, ignore_consequences=True)
            elif transition_type == DELETED:
                ctrl.forest.add_to_scene(obj)
            affected.add(obj)
            if hasattr(obj, 'update_visibility'):
                obj.update_visibility()
        ctrl.forest.edge_visibility_check()
        for obj, transitions, transition_type in snapshot.values():
            if transition_type == CREATED:
                revtt = DELETED
            elif transition_type == DELETED:
                revtt = CREATED
            else:
                revtt = transition_type
            obj.after_model_update(transitions.keys(), revtt)
            if getattr(obj.__class__, 'syntactic_object', False):
                node = ctrl.forest.nodes_from_synobs.get(obj.uid, None)
                if node and node not in affected:
                    node.after_model_update([], revtt)
        ctrl.forest.flush_and_rebuild_temporary_items()
        log.info('undo [%s]: %s' % (self._current, msg))
        ctrl.multiselection_end()
        ctrl.resume_undo()
        self._current -= 1
        ctrl.forest.halt_drawing = False

        print('-------undo finished', self._current)
Пример #7
0
 def redo(self):
     """ Move forward in the undo stack
     :return: None
     """
     if self._current < len(self._stack) - 1:
         self._current += 1
     else:
         log.info('redo [%s]: In last action' % self._current)
         return
     ctrl.disable_undo()
     ctrl.multiselection_start()
     ctrl.forest.halt_drawing = True
     msg, snapshot = self._stack[self._current]
     for obj, transitions, transition_type in snapshot.values():
         obj.move_to_later(transitions, transition_type)
     ctrl.forest.edge_visibility_check()
     ctrl.forest.flush_and_rebuild_temporary_items()
     log.info('redo [%s]: %s' % (self._current, msg))
     ctrl.multiselection_end()
     ctrl.resume_undo()
     ctrl.forest.halt_drawing = False
     print('------redo finished: ', msg, self._current)
Пример #8
0
 def redo(self):
     """ Move forward in the undo stack
     :return: None
     """
     if self._current < len(self._stack) - 1:
         self._current += 1
     else:
         log.info('redo [%s]: In last action' % self._current)
         return
     ctrl.disable_undo()
     ctrl.multiselection_start()
     self.forest.halt_drawing = True
     msg, snapshot = self._stack[self._current]
     for obj, transitions, transition_type in snapshot.values():
         obj.move_to_later(transitions, transition_type)
     self.forest.edge_visibility_check()
     self.forest.flush_and_rebuild_temporary_items()
     log.info('redo [%s]: %s' % (self._current, msg))
     ctrl.multiselection_end()
     ctrl.resume_undo()
     self.forest.halt_drawing = False
     print('------redo finished: ', msg, self._current)
Пример #9
0
    def mouseReleaseEvent(self, event):
        super().mouseReleaseEvent(event)
        if event.isAccepted():
            return
        # No object was pressed -- either clicking on nothing or ending a selection drag

        # click on empty place means select nothing, unless we are shift+selecting
        if event.modifiers() != Qt.ShiftModifier:
            ctrl.deselect_objects()

        if self.graph_view.selection_mode:
            ctrl.area_selection = True
            ctrl.multiselection_start()
            ctrl.deselect_objects()
            # prioritize nodes in multiple selection. e.g. if there are nodes and edges in
            # selected area, select only nodes. If there are multiple edges and no nodes, then
            # take edges
            for item in self.selectedItems():
                if hasattr(item, 'select'):
                    item.select(event, multi=True)

            ctrl.multiselection_end()
            ctrl.area_selection = False
Пример #10
0
    def mouseReleaseEvent(self, event):
        super().mouseReleaseEvent(event)
        if event.isAccepted():
            return
        # No object was pressed -- either clicking on nothing or ending a selection drag

        # click on empty place means select nothing, unless we are shift+selecting
        if event.modifiers() != Qt.ShiftModifier:
            ctrl.deselect_objects()

        if self.graph_view.selection_mode:
            ctrl.area_selection = True
            ctrl.multiselection_start()
            ctrl.deselect_objects()
            # prioritize nodes in multiple selection. e.g. if there are nodes and edges in
            # selected area, select only nodes. If there are multiple edges and no nodes, then
            # take edges
            for item in self.selectedItems():
                if hasattr(item, 'select'):
                    item.select(event, multi=True)

            ctrl.multiselection_end()
            ctrl.area_selection = False
Пример #11
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()
Пример #12
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()
Пример #13
0
    def undo(self):
        """ Move backward in the undo stack
        :return: None
        """
        if not self._stack:
            return
        #if self._current == 0:
        #    log.info('undo [%s]: Cannot undo further' % self._current)
        #    return
        ctrl.disable_undo()
        ctrl.multiselection_start()
        ctrl.forest.halt_drawing = True
        msg, snapshot = self._stack[self._current]
        for obj, transitions, transition_type in snapshot.values():
            obj.revert_to_earlier(transitions, transition_type)
        ctrl.forest.edge_visibility_check()
        ctrl.forest.flush_and_rebuild_temporary_items()
        log.info('undo [%s]: %s' % (self._current, msg))
        ctrl.multiselection_end()
        ctrl.resume_undo()
        self._current -= 1
        ctrl.forest.halt_drawing = False

        print('-------undo finished', self._current)
Пример #14
0
    def undo(self):
        """ Move backward in the undo stack
        :return: None
        """
        if not self._stack:
            return
        #if self._current == 0:
        #    log.info('undo [%s]: Cannot undo further' % self._current)
        #    return
        ctrl.disable_undo()
        ctrl.multiselection_start()
        self.forest.halt_drawing = True
        msg, snapshot = self._stack[self._current]
        for obj, transitions, transition_type in snapshot.values():
            obj.revert_to_earlier(transitions, transition_type)
        self.forest.edge_visibility_check()
        self.forest.flush_and_rebuild_temporary_items()
        log.info('undo [%s]: %s' % (self._current, msg))
        ctrl.multiselection_end()
        ctrl.resume_undo()
        self._current -= 1
        self.forest.halt_drawing = False

        print('-------undo finished', self._current)