Changeset 2258

Show
Ignore:
Timestamp:
03/06/08 00:25:09 (7 months ago)
Author:
arj..@yirdis.nl
Message:

Fixed #107 (again). Now the orthogonal constraints are directly observed and can be undone too (fixes subsequence horizontal/undo/horizontal calls).

Files:

Legend:

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

    r2257 r2258  
    447447        self._line_width = 2 
    448448        self._fuzziness = 0 
    449         self._orthogonal = [] 
     449        self._orthogonal_constraints = [] 
    450450        self._horizontal = False 
    451451        self._head_angle = self._tail_angle = 0 
     
    463463    fuzziness = reversible_property(lambda s: s._fuzziness, _set_fuzziness) 
    464464 
    465     def _set_orthogonal_constraints(self, orthogonal): 
     465    def _update_orthogonal_constraints(self, orthogonal): 
     466        """ 
     467        Update the constraints required to maintain the orthogonal line. 
     468        The actual constraints attribute (``_orthogonal_constraints``) is 
     469        observed, so the undo system will update the contents properly 
     470        """ 
    466471        if not self.canvas: 
    467             self._orthogonal = orthogonal and [ None ] or [] 
     472            self._orthogonal_constraints = orthogonal and [ None ] or [] 
    468473            return 
    469474 
    470         for c in self._orthogonal
     475        for c in self._orthogonal_constraints
    471476            self.canvas.solver.remove_constraint(c) 
    472             self._orthogonal = [] 
    473477 
    474478        if not orthogonal: 
     
    480484        eq = EqualsConstraint #lambda a, b: a - b 
    481485        add = self.canvas.solver.add_constraint 
    482         cons = self._orthogonal 
     486        cons = [] 
    483487        rest = self._horizontal and 1 or 0 
    484488        for pos, (h0, h1) in enumerate(zip(h, h[1:])): 
     
    489493            self.canvas.solver.request_resolve(h1.x) 
    490494            self.canvas.solver.request_resolve(h1.y) 
     495        self._set_orthogonal_constraints(cons) 
    491496        self.request_update() 
     497 
     498    @observed 
     499    def _set_orthogonal_constraints(self, orthogonal_constraints): 
     500        """ 
     501        Setter for the constraints maintained. Required for the undo system. 
     502        """ 
     503        self._orthogonal_constraints = orthogonal_constraints 
     504 
     505    reversible_property(lambda s: s._orthogonal_constraints, _set_orthogonal_constraints) 
    492506 
    493507    @observed 
     
    498512        False 
    499513        """ 
    500         self._set_orthogonal_constraints(orthogonal) 
    501  
    502     orthogonal = reversible_property(lambda s: bool(s._orthogonal), _set_orthogonal) 
     514        self._update_orthogonal_constraints(orthogonal) 
     515 
     516    orthogonal = reversible_property(lambda s: bool(s._orthogonal_constraints), _set_orthogonal) 
    503517 
    504518    @observed 
     
    519533        """ 
    520534        self._inner_set_horizontal(horizontal) 
    521         self._set_orthogonal_constraints(self._orthogonal
     535        self._update_orthogonal_constraints(self._orthogonal_constraints
    522536 
    523537    horizontal = reversible_property(lambda s: s._horizontal, _set_horizontal) 
     
    535549        """ 
    536550        super(Line, self).teardown_canvas() 
    537         for c in self._orthogonal
     551        for c in self._orthogonal_constraints
    538552            self.canvas.solver.remove_constraint(c) 
    539553 
  • gaphas/trunk/gaphas/tests/test_line.py

    r2256 r2258  
    4848        assert len(canvas.solver._constraints) == 2 
    4949 
    50         print 'undo_list:', undo_list 
    5150        undo() 
    5251 
     52        assert not line.horizontal 
    5353        assert len(canvas.solver._constraints) == 2, canvas.solver._constraints 
    5454 
     55        line.horizontal = True 
     56 
     57        assert line.horizontal 
     58        assert len(canvas.solver._constraints) == 2, canvas.solver._constraints 
    5559 
    5660# vim:sw=4:et