|
9 | 9 |
|
10 | 10 | Synopsis: <trigger> [[[hours]:][minutes]:]seconds [name]""" |
11 | 11 |
|
12 | | -from albert import * |
| 12 | +from albert import warning, Item, FuncAction |
13 | 13 | from threading import Timer |
14 | 14 | from time import strftime, time, localtime |
15 | 15 | import dbus |
16 | 16 | import os |
| 17 | +from datetime import timedelta |
17 | 18 | import subprocess |
18 | 19 |
|
19 | 20 | __title__ = "Timer" |
20 | | -__version__ = "0.4.2" |
| 21 | +__version__ = "0.4.3" |
21 | 22 | __triggers__ = "timer " |
22 | 23 | __authors__ = ["manuelschneid3r", "googol42"] |
23 | 24 | __py_deps__ = ["dbus-python"] |
|
26 | 27 | soundPath = os.path.dirname(__file__)+"/bing.wav" |
27 | 28 | timers = [] |
28 | 29 |
|
29 | | -dbusItem = "org.freedesktop.Notifications" |
30 | | -dbusPath = "/org/freedesktop/Notifications" |
31 | | -dbusInterface = "org.freedesktop.Notifications" |
32 | | - |
| 30 | +bus_name = "org.freedesktop.Notifications" |
| 31 | +object_path = "/org/freedesktop/Notifications" |
| 32 | +interface = bus_name |
33 | 33 |
|
34 | 34 | class AlbertTimer(Timer): |
35 | 35 |
|
@@ -39,13 +39,10 @@ def timeout(): |
39 | 39 | subprocess.Popen(["aplay", soundPath]) |
40 | 40 | global timers |
41 | 41 | timers.remove(self) |
42 | | - |
43 | 42 | title = 'Timer "%s"' % self.name if self.name else 'Timer' |
44 | 43 | text = "Timed out at %s" % strftime("%X", localtime(self.end)) |
45 | | - |
46 | | - bus = dbus.SessionBus() |
47 | | - notify = dbus.Interface(bus.get_object(dbusItem, dbusPath), dbusInterface) |
48 | | - notify.Notify(__title__, 0, iconPath, title, text, '', '', 0) |
| 44 | + notify = dbus.Interface(dbus.SessionBus().get_object(bus_name, object_path), interface) |
| 45 | + notify.Notify(__title__, 0, iconPath, title, text, [], {"urgency":2}, 0) |
49 | 46 |
|
50 | 47 | super().__init__(interval=interval, function=timeout) |
51 | 48 | self.interval = interval |
@@ -65,13 +62,6 @@ def deleteTimer(timer): |
65 | 62 | timers.remove(timer) |
66 | 63 | timer.cancel() |
67 | 64 |
|
68 | | - |
69 | | -def formatSeconds(seconds): |
70 | | - m, s = divmod(seconds, 60) |
71 | | - h, m = divmod(m, 60) |
72 | | - return "%02d:%02d:%02d" % (h, m, s) |
73 | | - |
74 | | - |
75 | 65 | def handleQuery(query): |
76 | 66 | if query.isTriggered: |
77 | 67 |
|
@@ -94,7 +84,7 @@ def handleQuery(query): |
94 | 84 |
|
95 | 85 | return Item( |
96 | 86 | id=__title__, |
97 | | - text=formatSeconds(seconds), |
| 87 | + text=str(timedelta(seconds=seconds)), |
98 | 88 | subtext='Set a timer with name "%s"' % name if name else 'Set a timer', |
99 | 89 | icon=iconPath, |
100 | 90 | actions=[FuncAction("Set timer", lambda sec=seconds: startTimer(sec, name))] |
|