Changeset 1893

Show
Ignore:
Timestamp:
08/09/07 06:15:50 (1 year ago)
Author:
arj..@yirdis.nl
Message:
  • made undo/redo for split/merge_segment work properly. split|merge_segment are no longer observed: special handle insert/remove methods are, ensuring the same handle is added/removed every time.
  • added bit o' doc to state.py.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphas/trunk/gaphas/item.py

    r1883 r1893  
    524524 
    525525    @observed 
     526    def _reversible_insert_handle(self, index, handle): 
     527        self._handles.insert(index, handle) 
     528 
     529    @observed 
     530    def _reversible_remove_handle(self, handle): 
     531        self._handles.remove(handle) 
     532 
     533    reversible_pair(_reversible_insert_handle, _reversible_remove_handle, \ 
     534            bind1={'index': lambda self, handle: self._handles.index(handle)}) 
     535 
     536 
    526537    def split_segment(self, segment, parts=2): 
    527538        """ 
     
    564575            dx, dy = h1.x - h0.x, h1.y - h0.y 
    565576            new_h = Handle(h0.x + dx / parts, h0.y + dy / parts, strength=WEAK) 
    566             self._handles.insert(segment + 1, new_h) 
    567             # TODO: reconnect connected handles. 
     577            self._reversible_insert_handle(segment + 1, new_h) 
    568578            if parts > 2: 
    569579                do_split(segment + 1, parts - 1) 
    570580        do_split(segment, parts) 
    571         # TODO: or reconnect them from here. 
    572581        # Force orthogonal constraints to be recreated 
    573582        self.orthogonal = self.orthogonal 
    574583        return self._handles[segment+1:segment+parts] 
    575584 
    576     @observed 
    577585    def merge_segment(self, segment, parts=2): 
    578586        """ 
     
    611619        if segment == 0: segment = 1 
    612620        deleted_handles = self._handles[segment:segment+parts-1] 
    613         del self._handles[segment] 
     621        self._reversible_remove_handle(self._handles[segment]) 
    614622        if parts > 2: 
    615623            self.merge_segment(segment, parts - 1) 
     
    619627        return deleted_handles 
    620628 
    621     reversible_pair(split_segment, merge_segment) 
    622  
    623      
     629 
    624630    def opposite(self, handle): 
    625631        """ 
  • gaphas/trunk/gaphas/state.py

    r1815 r1893  
    4949    Simple observer, dispatches events to functions registered in the observers 
    5050    list. 
    51     On the function an __observer__ property is set, which references to the 
    52     observer decorator. This is nessesary, since the event handlers expect the 
    53     outer most function to be returned (that's what they see). 
     51 
     52    On the function an ``__observer__`` property is set, which references to 
     53    the observer decorator. This is nessesary, since the event handlers expect 
     54    the outer most function to be returned (that's what they see). 
     55 
     56    Also note that the events are dispatched *before* the function is invoked. 
     57    This is an important feature, esp. for the reverter code. 
    5458    """ 
    5559    def wrapper(func, *args, **kwargs):