core.desktop: make dependency python-gobject optional
This commit is contained in:
parent
f39e4b3684
commit
c3441da72e
@ -1,22 +1,27 @@
|
|||||||
|
|
||||||
from gi.repository import Notify
|
try:
|
||||||
|
from gi.repository import Notify
|
||||||
if not Notify.init("i3pystatus"):
|
except ImportError:
|
||||||
|
def display_notification(title, body, icon, urgency, timeout):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if not Notify.init("i3pystatus"):
|
||||||
raise ImportError("Couldn't initialize libnotify")
|
raise ImportError("Couldn't initialize libnotify")
|
||||||
|
|
||||||
URGENCY_LUT = (
|
URGENCY_LUT = (
|
||||||
Notify.Urgency.LOW,
|
Notify.Urgency.LOW,
|
||||||
Notify.Urgency.NORMAL,
|
Notify.Urgency.NORMAL,
|
||||||
Notify.Urgency.CRITICAL,
|
Notify.Urgency.CRITICAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
# List of some useful icon names:
|
# List of some useful icon names:
|
||||||
# battery, battery-caution, battery-low
|
# battery, battery-caution, battery-low
|
||||||
# …
|
# …
|
||||||
|
|
||||||
def display_notification(title, body, icon="dialog-information", urgency=1, timeout=0):
|
def display_notification(title, body, icon="dialog-information", urgency=1, timeout=0):
|
||||||
notification = Notify.Notification.new(title, body, icon)
|
notification = Notify.Notification.new(title, body, icon)
|
||||||
if timeout:
|
if timeout:
|
||||||
notification.set_timeout(timeout)
|
notification.set_timeout(timeout)
|
||||||
notification.set_urgency(URGENCY_LUT[urgency])
|
notification.set_urgency(URGENCY_LUT[urgency])
|
||||||
return notification.show()
|
return notification.show()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user