| 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 | | |
|---|
| 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): |
|---|
| 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() |
|---|
| 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() |
|---|
| 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: |
|---|
| 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 |
|---|