Created
September 7, 2020 20:54
-
-
Save typoman/fdd0e352a35c704ad52df10d9f561cb6 to your computer and use it in GitHub Desktop.
simple objective C observer inside RoboFont
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| You can use this to get the window name if it has become the key window in | |
| RoboFont. But the same data model can be used to create notifications inside | |
| objc apps. | |
| """ | |
| from objc import python_method | |
| import AppKit | |
| from vanilla import FloatingWindow | |
| from lib.tools.debugTools import ClassNameIncrementer | |
| class _myObserver(AppKit.NSObject, metaclass=ClassNameIncrementer): | |
| @python_method | |
| def _start(self): | |
| self.w = FloatingWindow((300, 90), "KeyEventMonitor Debuggin window") | |
| self.w.bind("close", self._stop) | |
| self.w.open() | |
| nc = AppKit.NSNotificationCenter.defaultCenter() | |
| nc.addObserver_selector_name_object_(self, 'mainWindowChanged:', AppKit.NSWindowDidBecomeKeyNotification, None) | |
| def mainWindowChanged_(self, info): | |
| w = info.object() | |
| if hasattr(w, 'windowName'): | |
| print(w.windowName()) | |
| @python_method | |
| def _stop(self, _): | |
| AppKit.NSNotificationCenter.defaultCenter().removeObserver_(self) | |
| ob = _myObserver.new() | |
| ob._start() | |
| """ | |
| A list of notifications: | |
| AppKit.NSAccessibilityAnnouncementRequestedNotification | |
| AppKit.NSAccessibilityApplicationActivatedNotification | |
| AppKit.NSAccessibilityApplicationDeactivatedNotification | |
| AppKit.NSAccessibilityApplicationHiddenNotification | |
| AppKit.NSAccessibilityApplicationShownNotification | |
| AppKit.NSAccessibilityCreatedNotification | |
| AppKit.NSAccessibilityDrawerCreatedNotification | |
| AppKit.NSAccessibilityFocusedUIElementChangedNotification | |
| AppKit.NSAccessibilityFocusedWindowChangedNotification | |
| AppKit.NSAccessibilityHelpTagCreatedNotification | |
| AppKit.NSAccessibilityLayoutChangedNotification | |
| AppKit.NSAccessibilityMainWindowChangedNotification | |
| AppKit.NSAccessibilityMovedNotification | |
| AppKit.NSAccessibilityPostNotification | |
| AppKit.NSAccessibilityResizedNotification | |
| AppKit.NSAccessibilityRowCollapsedNotification | |
| AppKit.NSAccessibilityRowCountChangedNotification | |
| AppKit.NSAccessibilityRowExpandedNotification | |
| AppKit.NSAccessibilitySelectedCellsChangedNotification | |
| AppKit.NSAccessibilitySelectedChildrenChangedNotification | |
| AppKit.NSAccessibilitySelectedChildrenMovedNotification | |
| AppKit.NSAccessibilitySelectedColumnsChangedNotification | |
| AppKit.NSAccessibilitySelectedRowsChangedNotification | |
| AppKit.NSAccessibilitySelectedTextChangedNotification | |
| AppKit.NSAccessibilitySheetCreatedNotification | |
| AppKit.NSAccessibilityTitleChangedNotification | |
| AppKit.NSAccessibilityUIElementDestroyedNotification | |
| AppKit.NSAccessibilityUnitsChangedNotification | |
| AppKit.NSAccessibilityValueChangedNotification | |
| AppKit.NSAccessibilityWindowCreatedNotification | |
| AppKit.NSAccessibilityWindowDeminiaturizedNotification | |
| AppKit.NSAccessibilityWindowMiniaturizedNotification | |
| AppKit.NSAccessibilityWindowMovedNotification | |
| AppKit.NSAccessibilityWindowResizedNotification | |
| AppKit.NSAnimationProgressMarkNotification | |
| AppKit.NSAntialiasThresholdChangedNotification | |
| AppKit.NSApplication.isRegisteredForRemoteNotification | |
| AppKit.NSApplicationDidBecomeActiveNotification | |
| AppKit.NSApplicationDidChangeOcclusionStateNotification | |
| AppKit.NSApplicationDidChangeScreenParametersNotification | |
| AppKit.NSApplicationDidFinishLaunchingNotification | |
| AppKit.NSApplicationDidFinishRestoringWindowsNotification | |
| AppKit.NSApplicationDidHideNotification | |
| AppKit.NSApplicationDidResignActiveNotification | |
| AppKit.NSApplicationDidUnhideNotification | |
| AppKit.NSApplicationDidUpdateNotification | |
| AppKit.NSApplicationLaunchRemoteNotification | |
| AppKit.NSApplicationLaunchUserNotification | |
| AppKit.NSApplicationWillBecomeActiveNotification | |
| AppKit.NSApplicationWillFinishLaunchingNotification | |
| AppKit.NSApplicationWillHideNotification | |
| AppKit.NSApplicationWillResignActiveNotification | |
| AppKit.NSApplicationWillTerminateNotification | |
| AppKit.NSApplicationWillUnhideNotification | |
| AppKit.NSApplicationWillUpdateNotification | |
| AppKit.NSBrowserColumnConfigurationDidChangeNotification | |
| AppKit.NSBundleDidLoadNotification | |
| AppKit.NSCell.wantsNotification | |
| AppKit.NSColorListDidChangeNotification | |
| AppKit.NSColorPanelColorDidChangeNotification | |
| AppKit.NSComboBoxSelectionDidChangeNotification | |
| AppKit.NSComboBoxSelectionIsChangingNotification | |
| AppKit.NSComboBoxWillDismissNotification | |
| AppKit.NSComboBoxWillPopUpNotification | |
| AppKit.NSContextHelpModeDidActivateNotification | |
| AppKit.NSContextHelpModeDidDeactivateNotification | |
| AppKit.NSControlTextDidBeginEditingNotification | |
| AppKit.NSControlTextDidChangeNotification | |
| AppKit.NSControlTextDidEndEditingNotification | |
| AppKit.NSControlTintDidChangeNotification | |
| AppKit.NSDrawerDidCloseNotification | |
| AppKit.NSDrawerDidOpenNotification | |
| AppKit.NSDrawerWillCloseNotification | |
| AppKit.NSDrawerWillOpenNotification | |
| AppKit.NSFontCollectionDidChangeNotification | |
| AppKit.NSFontSetChangedNotification | |
| AppKit.NSImageRepRegistryChangedNotification | |
| AppKit.NSImageRepRegistryDidChangeNotification | |
| AppKit.NSInputManager.wantsToDelayTextChangeNotification | |
| AppKit.NSMenuDidAddItemNotification | |
| AppKit.NSMenuDidBeginTrackingNotification | |
| AppKit.NSMenuDidChangeItemNotification | |
| AppKit.NSMenuDidEndTrackingNotification | |
| AppKit.NSMenuDidRemoveItemNotification | |
| AppKit.NSMenuDidSendActionNotification | |
| AppKit.NSMenuWillSendActionNotification | |
| AppKit.NSOutlineViewColumnDidMoveNotification | |
| AppKit.NSOutlineViewColumnDidResizeNotification | |
| AppKit.NSOutlineViewItemDidCollapseNotification | |
| AppKit.NSOutlineViewItemDidExpandNotification | |
| AppKit.NSOutlineViewItemWillCollapseNotification | |
| AppKit.NSOutlineViewItemWillExpandNotification | |
| AppKit.NSOutlineViewSelectionDidChangeNotification | |
| AppKit.NSOutlineViewSelectionIsChangingNotification | |
| AppKit.NSPopUpButtonCellWillPopUpNotification | |
| AppKit.NSPopUpButtonWillPopUpNotification | |
| AppKit.NSPopoverDidCloseNotification | |
| AppKit.NSPopoverDidShowNotification | |
| AppKit.NSPopoverWillCloseNotification | |
| AppKit.NSPopoverWillShowNotification | |
| AppKit.NSPreferredScrollerStyleDidChangeNotification | |
| AppKit.NSRemoteNotification | |
| AppKit.NSRuleEditorRowsDidChangeNotification | |
| AppKit.NSScreenColorSpaceDidChangeNotification | |
| AppKit.NSScrollViewDidEndLiveMagnifyNotification | |
| AppKit.NSScrollViewDidEndLiveScrollNotification | |
| AppKit.NSScrollViewDidLiveScrollNotification | |
| AppKit.NSScrollViewWillStartLiveMagnifyNotification | |
| AppKit.NSScrollViewWillStartLiveScrollNotification | |
| AppKit.NSSpellCheckerDidChangeAutomaticCapitalizationNotification | |
| AppKit.NSSpellCheckerDidChangeAutomaticDashSubstitutionNotification | |
| AppKit.NSSpellCheckerDidChangeAutomaticPeriodSubstitutionNotification | |
| AppKit.NSSpellCheckerDidChangeAutomaticQuoteSubstitutionNotification | |
| AppKit.NSSpellCheckerDidChangeAutomaticSpellingCorrectionNotification | |
| AppKit.NSSpellCheckerDidChangeAutomaticTextCompletionNotification | |
| AppKit.NSSpellCheckerDidChangeAutomaticTextReplacementNotification | |
| AppKit.NSSplitViewDidResizeSubviewsNotification | |
| AppKit.NSSplitViewWillResizeSubviewsNotification | |
| AppKit.NSSystemClockDidChangeNotification | |
| AppKit.NSSystemColorsDidChangeNotification | |
| AppKit.NSTableViewColumnDidMoveNotification | |
| AppKit.NSTableViewColumnDidResizeNotification | |
| AppKit.NSTableViewSelectionDidChangeNotification | |
| AppKit.NSTableViewSelectionIsChangingNotification | |
| AppKit.NSTextAlternativesSelectedAlternativeStringNotification | |
| AppKit.NSTextDidBeginEditingNotification | |
| AppKit.NSTextDidChangeNotification | |
| AppKit.NSTextDidEndEditingNotification | |
| AppKit.NSTextFieldCell.setWantsNotification | |
| AppKit.NSTextInputContextKeyboardSelectionDidChangeNotification | |
| AppKit.NSTextStorageDidProcessEditingNotification | |
| AppKit.NSTextStorageWillProcessEditingNotification | |
| AppKit.NSTextViewDidChangeSelectionNotification | |
| AppKit.NSTextViewDidChangeTypingAttributesNotification | |
| AppKit.NSTextViewWillChangeNotifyingTextViewNotification | |
| AppKit.NSToolbarDidRemoveItemNotification | |
| AppKit.NSToolbarWillAddItemNotification | |
| AppKit.NSView.postsBoundsChangedNotification | |
| AppKit.NSView.postsFrameChangedNotification | |
| AppKit.NSView.setPostsBoundsChangedNotification | |
| AppKit.NSView.setPostsFrameChangedNotification | |
| AppKit.NSViewBoundsDidChangeNotification | |
| AppKit.NSViewDidUpdateTrackingAreasNotification | |
| AppKit.NSViewFocusDidChangeNotification | |
| AppKit.NSViewFrameDidChangeNotification | |
| AppKit.NSViewGlobalFrameDidChangeNotification | |
| AppKit.NSWindowDidBecomeKeyNotification | |
| AppKit.NSWindowDidBecomeMainNotification | |
| AppKit.NSWindowDidChangeBackingPropertiesNotification | |
| AppKit.NSWindowDidChangeOcclusionStateNotification | |
| AppKit.NSWindowDidChangeScreenNotification | |
| AppKit.NSWindowDidChangeScreenProfileNotification | |
| AppKit.NSWindowDidDeminiaturizeNotification | |
| AppKit.NSWindowDidEndLiveResizeNotification | |
| AppKit.NSWindowDidEndSheetNotification | |
| AppKit.NSWindowDidEnterFullScreenNotification | |
| AppKit.NSWindowDidEnterVersionBrowserNotification | |
| AppKit.NSWindowDidExitFullScreenNotification | |
| AppKit.NSWindowDidExitVersionBrowserNotification | |
| AppKit.NSWindowDidExposeNotification | |
| AppKit.NSWindowDidMiniaturizeNotification | |
| AppKit.NSWindowDidMoveNotification | |
| AppKit.NSWindowDidResignKeyNotification | |
| AppKit.NSWindowDidResignMainNotification | |
| AppKit.NSWindowDidResizeNotification | |
| AppKit.NSWindowDidUpdateNotification | |
| AppKit.NSWindowWillBeginSheetNotification | |
| AppKit.NSWindowWillCloseNotification | |
| AppKit.NSWindowWillEnterFullScreenNotification | |
| AppKit.NSWindowWillEnterVersionBrowserNotification | |
| AppKit.NSWindowWillExitFullScreenNotification | |
| AppKit.NSWindowWillExitVersionBrowserNotification | |
| AppKit.NSWindowWillMiniaturizeNotification | |
| AppKit.NSWindowWillMoveNotification | |
| AppKit.NSWindowWillStartLiveResizeNotification | |
| AppKit.NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification | |
| AppKit.NSWorkspaceActiveSpaceDidChangeNotification | |
| AppKit.NSWorkspaceDidActivateApplicationNotification | |
| AppKit.NSWorkspaceDidChangeFileLabelsNotification | |
| AppKit.NSWorkspaceDidDeactivateApplicationNotification | |
| AppKit.NSWorkspaceDidHideApplicationNotification | |
| AppKit.NSWorkspaceDidLaunchApplicationNotification | |
| AppKit.NSWorkspaceDidMountNotification | |
| AppKit.NSWorkspaceDidPerformFileOperationNotification | |
| AppKit.NSWorkspaceDidRenameVolumeNotification | |
| AppKit.NSWorkspaceDidTerminateApplicationNotification | |
| AppKit.NSWorkspaceDidUnhideApplicationNotification | |
| AppKit.NSWorkspaceDidUnmountNotification | |
| AppKit.NSWorkspaceDidWakeNotification | |
| AppKit.NSWorkspaceScreensDidSleepNotification | |
| AppKit.NSWorkspaceScreensDidWakeNotification | |
| AppKit.NSWorkspaceSessionDidBecomeActiveNotification | |
| AppKit.NSWorkspaceSessionDidResignActiveNotification | |
| AppKit.NSWorkspaceWillLaunchApplicationNotification | |
| AppKit.NSWorkspaceWillPowerOffNotification | |
| AppKit.NSWorkspaceWillSleepNotification | |
| AppKit.NSWorkspaceWillUnmountNotification | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment