Changeset 265

Show
Ignore:
Timestamp:
09/16/08 08:02:27 (4 months ago)
Author:
tal
Message:
Various tweaks to handle the popup window better in the cell view.
Files:

Legend:

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

    r264 r265  
    106106        self._allowDrag = False 
    107107 
    108         if detailWindowClass is not None: 
    109             self._glyphDetailWindow = detailWindowClass() 
    110         else: 
    111             self._glyphDetailWindow = None 
     108        self._glyphDetailWindowClass = detailWindowClass 
     109        self._glyphDetailWindow = None 
    112110        self._glyphDetailRequiredModifiers = [NSControlKeyMask] 
    113111        self._glyphDetailOnMouseDown = True 
     
    129127        newSelection = set([glyphs.index(glyph) for glyph in currentSelection if glyph in glyphs]) 
    130128        self._selection = newSelection 
    131         self._unsubscribeFromGlyphs() 
    132129        self._glyphs = glyphs 
    133         self._subscribeToGlyphs() 
    134130        self.recalculateFrame() 
    135131 
     
    202198        self.setNeedsDisplay_(True) 
    203199 
    204     # glyph change notification support 
    205  
    206     def _subscribeToGlyphs(self): 
    207         for glyph in self._glyphs: 
    208             self._notificationObserver.add(self, "_glyphChanged", glyph, "Glyph.Changed") 
    209  
    210     def _unsubscribeFromGlyphs(self): 
    211         done = set() 
    212         for glyph in self._glyphs: 
    213             if glyph in done: 
    214                 continue 
    215             self._notificationObserver.remove(self, glyph, "Glyph.Changed") 
    216             done.add(glyph) 
    217  
    218     def _glyphChanged(self, notification): 
    219         self.setNeedsDisplay_(True) 
    220  
    221200    # window resize notification support 
    222201 
     
    224203        self.recalculateFrame() 
    225204 
    226     def subscribeToScrollViewFrameChange_(self, scrollView): 
     205    def subscribeToScrollViewFrameChange(self): 
     206        scrollView = self.enclosingScrollView() 
     207        if scrollView is not None: 
     208            notificationCenter = NSNotificationCenter.defaultCenter() 
     209            notificationCenter.addObserver_selector_name_object_( 
     210                self, "clipViewFrameChangeNotification:", NSViewFrameDidChangeNotification, scrollView 
     211            ) 
     212            scrollView.setPostsFrameChangedNotifications_(True) 
     213 
     214    def viewDidEndLiveResize(self): 
     215        self.recalculateFrame() 
     216 
     217    # close notification support 
     218 
     219    def windowResignMainNotification_(self, notification): 
     220        self._handleDetailWindow(None, None) 
     221 
     222    def windowCloseNotification_(self, notification): 
     223        if self._glyphDetailWindow is not None: 
     224            if self._glyphDetailWindow.getNSWindow() is not None: 
     225                self._glyphDetailWindow.close() 
     226        notificationCenter = NSNotificationCenter.defaultCenter() 
     227        notificationCenter.removeObserver_(self) 
     228 
     229    def subscribeToWindow(self): 
    227230        notificationCenter = NSNotificationCenter.defaultCenter() 
    228231        notificationCenter.addObserver_selector_name_object_( 
    229             self, "clipViewFrameChangeNotification:", NSViewFrameDidChangeNotification, scrollView 
     232            self, "windowResignMainNotification:", NSWindowDidResignKeyNotification, self.window() 
    230233        ) 
    231         scrollView.setPostsFrameChangedNotifications_(True) 
    232  
    233     def unsubscribeToScrollViewFrameChange_(self, scrollView): 
    234         notificationCenter = NSNotificationCenter.defaultCenter() 
    235         notificationCenter.removeObserver_name_object_( 
    236             self, NSViewFrameDidChangeNotification, scrollView 
     234        notificationCenter.addObserver_selector_name_object_( 
     235            self, "windowCloseNotification:", NSWindowWillCloseNotification, self.window() 
    237236        ) 
    238         scrollView.setPostsFrameChangedNotifications_(False) 
    239  
    240     def viewDidEndLiveResize(self): 
    241         self.recalculateFrame() 
    242237 
    243238    # -------------- 
     
    245240    # -------------- 
    246241 
    247     def dealloc(self): 
    248         self._unsubscribeFromGlyphs() 
    249         if self._glyphDetailWindow is not None: 
    250             self._glyphDetailWindow = None 
    251         super(DefconAppKitGlyphCellNSView, self).dealloc() 
     242    def viewDidMoveToWindow(self): 
     243        # if window() returns an object, open the detail window 
     244        if self.window() is not None: 
     245            if self._glyphDetailWindow is None and self._glyphDetailWindowClass is not None: 
     246                self._glyphDetailWindow = self._glyphDetailWindowClass() 
     247            self.subscribeToWindow() 
     248            self.subscribeToScrollViewFrameChange() 
    252249 
    253250    def isFlipped(self): 
     
    389386        # determine show/hide 
    390387        shouldBeVisible = True 
    391         eventLocation = event.locationInWindow() 
    392         mouseLocation = self.convertPoint_fromView_(eventLocation, None) 
    393         ## drag and drop 
    394         if inDragAndDrop: 
     388        ## event is None 
     389        if event is None: 
    395390            shouldBeVisible = False 
    396         ## modifiers 
    397         modifiers = event.modifierFlags() 
    398         for modifier in self._glyphDetailRequiredModifiers: 
    399             if not modifiers & modifier: 
     391        ## window is not key 
     392        elif NSApp().keyWindow() != self.window(): 
     393            shouldBeVisible = False 
     394        ## event requirements 
     395        else: 
     396            eventLocation = event.locationInWindow() 
     397            mouseLocation = self.convertPoint_fromView_(eventLocation, None) 
     398            ## drag and drop 
     399            if inDragAndDrop: 
    400400                shouldBeVisible = False 
    401                 break 
    402         ## mouse conditions 
    403         haveMouseCondition = False 
    404         requireMouseCondition = True in (self._glyphDetailOnMouseDown, self._glyphDetailOnMouseUp, self._glyphDetailOnMouseMoved, self._glyphDetailOnMouseDragged) 
    405         if not requireMouseCondition: 
    406             haveMouseCondition = True 
    407         else: 
    408             if self._glyphDetailOnMouseDown and mouseDown: 
     401            ## modifiers 
     402            modifiers = event.modifierFlags() 
     403            for modifier in self._glyphDetailRequiredModifiers: 
     404                if not modifiers & modifier: 
     405                    shouldBeVisible = False 
     406                    break 
     407            ## mouse conditions 
     408            haveMouseCondition = False 
     409            requireMouseCondition = True in (self._glyphDetailOnMouseDown, self._glyphDetailOnMouseUp, self._glyphDetailOnMouseMoved, self._glyphDetailOnMouseDragged) 
     410            if not requireMouseCondition: 
    409411                haveMouseCondition = True 
    410             elif self._glyphDetailOnMouseUp and mouseUp: 
    411                 haveMouseCondition = True 
    412             elif self._glyphDetailOnMouseMoved and mouseMoved: 
    413                 haveMouseCondition = True 
    414             elif self._glyphDetailOnMouseDragged and mouseDragged: 
    415                 haveMouseCondition = True 
    416         if not haveMouseCondition: 
    417             shouldBeVisible = False 
    418         ## glyph hit 
    419         if not found: 
    420             shouldBeVisible = False 
    421         ## mouse position is visible 
    422         if not NSPointInRect(mouseLocation, self.visibleRect()): 
    423             shouldBeVisible = False 
     412            else: 
     413                if self._glyphDetailOnMouseDown and mouseDown: 
     414                    haveMouseCondition = True 
     415                elif self._glyphDetailOnMouseUp and mouseUp: 
     416                    haveMouseCondition = True 
     417                elif self._glyphDetailOnMouseMoved and mouseMoved: 
     418                    haveMouseCondition = True 
     419                elif self._glyphDetailOnMouseDragged and mouseDragged: 
     420                    haveMouseCondition = True 
     421            if not haveMouseCondition: 
     422                shouldBeVisible = False 
     423            ## glyph hit 
     424            if not found: 
     425                shouldBeVisible = False 
     426            ## mouse position is visible 
     427            if not NSPointInRect(mouseLocation, self.visibleRect()): 
     428                shouldBeVisible = False 
    424429        # set the position 
    425430        if shouldBeVisible: 
  • packages/defconAppKit/trunk/Lib/defconAppKit/views/glyphCollectionView.py

    r264 r265  
    7272 
    7373    nsScrollViewClass = DefconAppKitPlacardNSScrollView 
     74    glyphCellViewClass = DefconAppKitGlyphCellNSView 
    7475 
    7576    def __init__(self, posSize, initialMode="cell", listColumnDescriptions=None, listShowColumnTitles=False, 
     
    134135            self._orderedListKeys.append(key) 
    135136        ## set up the cell view 
    136         self._glyphCellView = DefconAppKitGlyphCellNSView.alloc().initWithFrame_cellRepresentationName_detailWindowClass_( 
     137        self._glyphCellView = self.glyphCellViewClass.alloc().initWithFrame_cellRepresentationName_detailWindowClass_( 
    137138            ((0, 0), (400, 400)), cellRepresentationName, glyphDetailWindowClass) 
    138139        self._glyphCellView.vanillaWrapper = weakref.ref(self) 
    139         self._glyphCellView.subscribeToScrollViewFrameChange_(self._nsObject) 
    140140        self._glyphCellView.setAllowsDrag_(allowDrag) 
    141141        dropTypes = [] 
     
    161161 
    162162    def _breakCycles(self): 
     163        for glyph in self._wrappedListItems.keys(): 
     164            del self._wrappedListItems[glyph] 
     165            self._unsubscribeFromGlyph(glyph) 
    163166        self._placard = None 
     167        self._glyphCellView = None 
    164168        super(GlyphCollectionView, self)._breakCycles() 
    165169 
     
    267271        for key, attr in self._keyToAttribute.items(): 
    268272            d[key] = getattr(glyph, attr) 
     273        self._glyphCellView.setNeedsDisplay_(True) 
    269274 
    270275    # editing 
  • packages/defconAppKit/trunk/Lib/defconAppKit/windows/popUpWindow.py

    r264 r265  
    7979 
    8080    def close(self): 
     81        self._fadeOut() 
    8182        super(InformationPopUpWindow, self).close() 
    82         self._fadeOut() 
    8383 
    8484    def show(self):