56 lines
1.1 KiB
Python
56 lines
1.1 KiB
Python
|
|
import gi
|
|
|
|
try:
|
|
gi.require_version('Notify', '0.7') # gir1.2-notify-0.7
|
|
from gi.repository import Notify
|
|
except:
|
|
Notify = None
|
|
|
|
|
|
class Notification():
|
|
|
|
notify = None
|
|
|
|
def __init__(self, webview):
|
|
self.webview = webview
|
|
|
|
if Notify:
|
|
Notify.init(Notify.get_app_name() or 'webapp')
|
|
self.notify = Notify.Notification()
|
|
|
|
|
|
def create(self, title, summary, icon, progress = 0, urgency = 0, callback = None):
|
|
|
|
if not self.notify:
|
|
raise ImportError('Notify module not found. Need to install gir1.2-notify-0.7 if you use debian.')
|
|
return
|
|
|
|
self.notify.clear_actions()
|
|
self.notify.clear_hints()
|
|
|
|
self.notify.update(title, summary, icon)
|
|
|
|
if progress:
|
|
self.notify.set_hint('value', progress)
|
|
|
|
self.notify.set_urgency(urgency)
|
|
|
|
if callback:
|
|
self.notify.add_action("click", "click", self.action_callback, callback)
|
|
|
|
self.notify.show()
|
|
|
|
|
|
def action_callback(self, instance, action, callback):
|
|
if callback:
|
|
self.webview.call_js(callback)
|
|
instance.close()
|
|
|
|
|
|
def create_notify():
|
|
|
|
def wrapper(app, extra = None):
|
|
Notification(app)
|
|
|
|
return wrapper |
Python
68.1%
JavaScript
30.4%
Shell
1.5%