Changeset 1620

Show
Ignore:
Timestamp:
07/11/07 14:22:15 (1 year ago)
Author:
wrobe..@pld-linux.org
Message:

- reimplemented minimal Element's size using constraints

Files:

Legend:

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

    r1618 r1620  
    239239        self._handles = [ h(strength=VERY_STRONG) for h in [Handle]*4 ] 
    240240        self._constraints = [] 
    241         self._min_width = 10 
    242         self._min_height = 10 
     241 
     242        # create minimal size constraints 
     243        handles = self._handles 
     244        h_nw = handles[NW] 
     245        h_se = handles[SE] 
     246        self._c_min_w = LessThanConstraint(smaller=h_nw.y, bigger=h_se.y, delta=10) 
     247        self._c_min_h = LessThanConstraint(smaller=h_nw.x, bigger=h_se.x, delta=10) 
     248 
     249        # set width/height when minimal size constraints exist 
    243250        self.width = width 
    244251        self.height = height 
     252 
    245253 
    246254    def _set_width(self, width): 
     
    301309    def _set_min_width(self, min_width): 
    302310        """ 
    303         """ 
    304         self._min_width = max(0, min_width) 
     311        Set minimal width. 
     312        """ 
     313        if min_width < 0: 
     314            raise ValueError, 'Minimal width cannot be less than 0' 
     315 
     316        self._c_min_w.delta = min_width 
     317 
    305318        if min_width > self.width: 
    306319            self.width = min_width 
    307320 
    308     min_width = reversible_property(lambda s: s._min_width, _set_min_width) 
     321    min_width = reversible_property(lambda s: s._c_min_w.delta, _set_min_width) 
    309322 
    310323    @observed 
    311324    def _set_min_height(self, min_height): 
    312325        """ 
    313         """ 
    314         self._min_height = max(0, min_height) 
     326        Set minimal height. 
     327        """ 
     328        if min_height < 0: 
     329            raise ValueError, 'Minimal height cannot be less than 0' 
     330 
     331        self._c_min_h.delta = min_height 
     332 
    315333        if min_height > self.height: 
    316334            self.height = min_height 
    317335 
    318     min_height = reversible_property(lambda s: s._min_height, _set_min_height) 
     336    min_height = reversible_property(lambda s: s._c_min_h.delta, _set_min_height) 
    319337 
    320338    def setup_canvas(self): 
     
    361379            add(eq(a=h_se.y, b=h_sw.y)), 
    362380            add(eq(a=h_se.x, b=h_ne.x)), 
    363             # set h_nw < h_se constraint 
     381            # set h_nw < h_se constraints 
    364382            # with minimal size functionality 
    365             add(lt(smaller=h_nw.y, bigger=h_se.y, delta=10)), 
    366             add(lt(smaller=h_nw.x, bigger=h_se.x, delta=10)), 
     383            add(self._c_min_w), 
     384            add(self._c_min_h), 
    367385        ] 
    368386