Skip to content

Commit e4b0865

Browse files
Version 0.0.8 uploaded
0 parents  commit e4b0865

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

notifylinux/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Display desktop notifications on Linux"""
2+
from linuxnotifier import Notifier
3+
4+
__all__ = ["Notifier"]

notifylinux/linuxnotifier.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import shutil
2+
import subprocess
3+
4+
5+
class Notifier():
6+
"""linuxnotifier: Display Notification in linux"""
7+
8+
def __init__(self, title, descriptions="", timeout=5, urgency="normal", iconpath="", appname=""):
9+
"""
10+
Args:
11+
title ([type]): [description]
12+
descriptions (str, optional): [description]. Defaults to "".
13+
timeout (int, optional): [description]. Defaults to 5.
14+
urgency (str, optional): [description]. Defaults to "normal".
15+
[low, normal, critical]
16+
iconpath (str, optional): [description]. Defaults to "".
17+
appname (str, optional): [description]. Defaults to "".
18+
19+
"""
20+
self.__title = title
21+
self.__descriptions = descriptions
22+
self.__timeout = timeout
23+
self.__urgency = urgency
24+
self.__iconpath = iconpath
25+
self.__appname = appname
26+
27+
if title is None or title == "":
28+
raise ValueError("Title can't be empty")
29+
30+
if urgency not in ["normal", "low", "critical", None]:
31+
raise ValueError("Inappropriate urgency given")
32+
33+
def send_notification(self):
34+
"""Display notification"""
35+
# raising error if 'notify-send' command can't be found
36+
if shutil.which("notify-send") is None:
37+
raise SystemError(
38+
"Install libnotify-bin\n run 'sudo apt-get install libnotify-bin'")
39+
40+
else:
41+
# Creating notify-send command into list
42+
notification = ["notify-send", self.__title,
43+
self.__descriptions, "-t", f"{self.__timeout * 1000}", ]
44+
45+
# if urgency level is given
46+
if self.__urgency != "":
47+
notification += ["-u", self.__urgency]
48+
49+
# if iconpath is given
50+
if self.__iconpath != "":
51+
notification += ["-i", self.__iconpath]
52+
# if appname is given
53+
if self.__appname != "":
54+
notification += ["-a", self.__appname]
55+
56+
# Executing Process
57+
subprocess.Popen(notification, shell=False)
58+

setup.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import setuptools
2+
3+
__author__ = "Aashish Sharma"
4+
__license__ = "MIT"
5+
__email__ = "[email protected]"
6+
7+
with open("README.md", "r") as rmd:
8+
long_description = rmd.read()
9+
10+
setuptools.setup(name="notifylinux",
11+
version="0.0.8",
12+
author="Aashish Sharma",
13+
author_email="[email protected]",
14+
description="A python package to send desktop notification in linux",
15+
long_description=long_description,
16+
url="https://github.com/aasis2520c/notifylinux",
17+
packages=setuptools.find_packages(),
18+
classifiers=[
19+
"Programming Language :: Python :: 3",
20+
"License :: OSI Approved :: MIT license",
21+
"Operating System :: Linux"
22+
]
23+
)

0 commit comments

Comments
 (0)