-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
import dbus | ||
|
||
|
||
class NotificationManager: | ||
"""Manages DBus notifications and action dispatching""" | ||
|
||
def __init__(self, app_name, bus): | ||
item = "org.freedesktop.Notifications" | ||
path = "/"+item.replace(".", "/") | ||
path = "/" + item.replace(".", "/") | ||
self._app_name = app_name | ||
self._actions = [] | ||
self._notify_interface = dbus.Interface( | ||
bus.get_object(item, path), | ||
item | ||
) | ||
bus.add_signal_receiver(self._on_action,"ActionInvoked") | ||
self._notify_interface = dbus.Interface(self._bus.get_object(item, path), item) | ||
bus.add_signal_receiver(self._on_action, "ActionInvoked") | ||
|
||
def get_action_list(self, actions): | ||
dbus_actions = [] | ||
for action in actions: | ||
dbus_actions.append(action['key']) | ||
dbus_actions.append(action['text']) | ||
dbus_actions.append(action["key"]) | ||
dbus_actions.append(action["text"]) | ||
return dbus_actions | ||
|
||
def add_action(self, action): | ||
self._actions.append(action) | ||
|
||
def _on_action(self, id, action_key): | ||
triggered_action = [action for action in self._actions if action['key'] == action_key][0] | ||
triggered_action['handler']() | ||
triggered_action = [ | ||
action for action in self._actions if action["key"] == action_key | ||
][0] | ||
triggered_action["handler"]() | ||
|
||
def notify(self, id, title, body, timeout): | ||
actions = self.get_action_list(self._actions) | ||
self._notify_interface.Notify( | ||
self._app_name, | ||
id, | ||
"weather-clear", # not sure what this is | ||
"weather-clear", # not sure what this is | ||
title, | ||
body, | ||
actions, | ||
{ "urgency": 1 }, | ||
timeout * 1000 | ||
{"urgency": 1}, | ||
timeout * 1000, | ||
) | ||
|