def install_global_handler(_id, handler, event_mask, key_mask=None): def key_handler(ev): if (ev.modifierFlags() & NSDeviceIndependentModifierFlagsMask) == key_mask: handler(ev) def simple_handler(ev): handler(ev) if not _id: _id = str(handler) + str(event_mask) + str(key_mask) obs = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_( event_mask, key_handler if key_mask else simple_handler) GLOBAL_HANDLERS[_id] = obs
def show_popover(self): self.on_show_callback() bounds = self.button.bounds() print 'BOUNDS ', bounds print 'show popover' #NSWindow *window = [[[NSApplication sharedApplication] currentEvent] window]; window = NSApplication.sharedApplication().currentEvent().window() x = NSApplication.sharedApplication().currentEvent().window().frame().origin.x y = NSApplication.sharedApplication().currentEvent().window().frame().origin.y x = x - 300 if x < 0: x = 0 y = y - 20 point = NSPoint(x, y) #point.setX_(x) #point.setY_(y) self.window.setFrameOrigin_(point) from Cocoa import NSApp as CocoaNSApp CocoaNSApp.activateIgnoringOtherApps_(True) #NSApp.activateIgnoringOtherApps_(True) self.window.makeKeyAndOrderFront_(self.window) #NSApplication.sharedApplication().activateIgnoringOtherApps(True) self._shown = True #self.popover.showRelativeToRect_ofView_preferredEdge_( # self.button.bounds(), # self.button, # NSMinYEdge #) def global_click(evt): print 'Global click!' self.close_popover() self.monitor = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_( NSLeftMouseDownMask | NSRightMouseDownMask, global_click )
def _observe(self): # Must be called after root.mainloop() so that the app's message loop has been created self.observer = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSKeyDownMask, self._handler)
def _observe(self): # Must be called after root.mainloop() so that the app's message loop has been created self.observer = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_( NSKeyDownMask, self._handler)
def applicationDidFinishLaunching_(self, aNotification): AppDelegate.myMonitor = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_( NSLeftMouseUpMask, self.leftMouseClick) AppDelegate.myMonitor = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_( NSOtherMouseDownMask, self.middleMouseClick)