Changeset 217

Show
Ignore:
Timestamp:
05/11/08 09:47:03 (8 months ago)
Author:
tal
Message:
Added a placard pop up button.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • packages/defconAppKit/trunk/Lib/defconAppKit/views/placardScrollView.py

    r212 r217  
    1717        if self.window() is None: 
    1818            return 
    19         placardWidth = self.placard.frame().size[0] 
    20         scroller = self.horizontalScroller() 
    21         (x, y), (w, h) = scroller.frame() 
    22         if w > 0 and h > 0: 
    23             scroller.setFrame_(((x + placardWidth, y), (w - placardWidth, h))) 
    24         self.placard.setFrame_(((x, y), (placardWidth, h))) 
     19        if hasattr(self, "placard"): 
     20            placardWidth = self.placard.frame().size[0] 
     21            scroller = self.horizontalScroller() 
     22            (x, y), (w, h) = scroller.frame() 
     23            if w > 0 and h > 0: 
     24                scroller.setFrame_(((x + placardWidth, y), (w - placardWidth, h))) 
     25            self.placard.setFrame_(((x, y), (placardWidth, h))) 
    2526 
    2627    def setPlacard_(self, view): 
     
    3839 
    3940    def setPlacard(self, placard): 
     41        if isinstance(placard, vanilla.VanillaBaseObject): 
     42            placard = placard.getNSView() 
    4043        self._nsObject.setPlacard_(placard) 
    4144 
     45 
     46# ------------- 
     47# Button Colors 
     48# ------------- 
     49 
     50placardGradientColor1 = NSColor.whiteColor() 
     51placardGradientColor2 = NSColor.colorWithCalibratedWhite_alpha_(.9, 1) 
     52placardGradientColorFallback = NSColor.colorWithCalibratedWhite_alpha_(.95, 1) 
    4253 
    4354# ---------------- 
     
    5768        # draw background 
    5869        try: 
    59             gray = NSColor.colorWithCalibratedWhite_alpha_(.9, 1) 
    60             white = NSColor.whiteColor() 
    61             gradient = NSGradient.alloc().initWithColors_([white, gray]) 
     70            gradient = NSGradient.alloc().initWithColors_([placardGradientColor1, placardGradientColor2]) 
    6271            gradient.drawInRect_angle_(frame, 90) 
    6372        except NameError: 
    64             NSColor.colorWithCalibratedWhite_alpha_(.95, 1).set() 
     73            placardGradientColorFallback.set() 
     74            NSRectFill(frame) 
    6575        # draw border 
    6676        (x, y), (w, h) = frame 
     
    105115    nsSegmentedCellClass = DefconAppKitPlacardNSSegmentedCell 
    106116 
     117 
     118# ------------ 
     119# PopUp Button 
     120# ------------ 
     121 
     122class DefconAppKitPlacardNSPopUpButtonCell(NSPopUpButtonCell): 
     123 
     124    def drawBorderAndBackgroundWithFrame_inView_(self, frame, view): 
     125        # draw background 
     126        try: 
     127            gradient = NSGradient.alloc().initWithColors_([placardGradientColor1, placardGradientColor2]) 
     128            gradient.drawInRect_angle_(frame, 90) 
     129        except NameError: 
     130            placardGradientColorFallback.set() 
     131            NSRectFill(frame) 
     132        # draw border 
     133        (x, y), (w, h) = frame 
     134        path = NSBezierPath.bezierPath() 
     135        path.moveToPoint_((x + w - .5, h)) 
     136        path.lineToPoint_((x + w - .5, .5)) 
     137        path.lineToPoint_((x, .5)) 
     138        path.setLineWidth_(1.0) 
     139        NSColor.colorWithCalibratedWhite_alpha_(.5, .7).set() 
     140        path.stroke() 
     141        # let the super do the rest 
     142        super(DefconAppKitPlacardNSPopUpButtonCell, self).drawBorderAndBackgroundWithFrame_inView_(frame, view) 
     143 
     144 
     145class PlacardPopUpButton(vanilla.PopUpButton): 
     146 
     147    nsPopUpButtonCellClass = DefconAppKitPlacardNSPopUpButtonCell 
     148 
     149    def __init__(self, posSize, items, **kwargs): 
     150        super(PlacardPopUpButton, self).__init__(posSize, items, **kwargs) 
     151        self._nsObject.setBordered_(False) 
     152        self._nsObject.cell().setGradientType_(NSGradientConvexStrong) 
     153