1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
from os.path import join, dirname, realpath
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from plyer import notification
from plyer.utils import platform
kivy.require('1.8.0')
class NotificationDemo(BoxLayout):
def do_notify(self, mode='normal'):
title = self.ids.notification_title.text
message = self.ids.notification_text.text
ticker = self.ids.ticker_text.text
kwargs = {'title': title, 'message': message, 'ticker': ticker}
if mode == 'fancy':
kwargs['app_name'] = "Plyer Notification Example"
if platform == "win":
kwargs['app_icon'] = join(dirname(realpath(__file__)),
'plyer-icon.ico')
kwargs['timeout'] = 4
else:
kwargs['app_icon'] = join(dirname(realpath(__file__)),
'plyer-icon.png')
elif mode == 'toast':
kwargs['toast'] = True
notification.notify(**kwargs)
class NotificationDemoApp(App):
def build(self):
return NotificationDemo()
def on_pause(self):
return True
if __name__ == '__main__':
NotificationDemoApp().run()
|