Debian Codegraph @

plyer/platforms/macosx/notification.py

raw symbols SCIP
1 '''
2 Module of MacOS API for plyer.notification.
3 '''
4
5 from plyer.facades import Notification
6
7 from pyobjus import (
8 autoclass, protocol, objc_str, ObjcBOOL
9 )
10 from pyobjus.dylib_manager import (
11 load_framework, INCLUDE
12 )
13
14 load_framework(INCLUDE.AppKit)
15 load_framework(INCLUDE.Foundation)
16
17 NSUserNotification = autoclass('NSUserNotification')
18 NSUserNotificationCenter = autoclass('NSUserNotificationCenter')
19
20
21 class OSXNotification(Notification):
22 '''
23 Implementation of MacOS notification API.
24 '''
25
26 def _notify(self, **kwargs):
27 title = kwargs.get('title', '')
28 message = kwargs.get('message', '')
29 app_name = kwargs.get('app_name', '')
30 # app_icon, timeout, ticker are not supported (yet)
31
32 notification = NSUserNotification.alloc().init()
33 notification.setTitle_(objc_str(title))
34 notification.setSubtitle_(objc_str(app_name))
35 notification.setInformativeText_(objc_str(message))
36
37 usrnotifctr = NSUserNotificationCenter.defaultUserNotificationCenter()
38 usrnotifctr.setDelegate_(self)
39 usrnotifctr.deliverNotification_(notification)
40
41 @protocol('NSUserNotificationCenterDelegate')
42 def userNotificationCenter_shouldPresentNotification_(
43 self, center, notification):
44 return ObjcBOOL(True)
45
46
47 def instance():
48 '''
49 Instance for facade proxy.
50 '''
51 return OSXNotification()