Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 794f100

Browse files
committedNov 6, 2020
First Commit
0 parents  commit 794f100

17 files changed

+605
-0
lines changed
 

‎.gitignore

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
db.sqlite3
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/
105+
106+
doc-errors.txt
107+
.vscode/

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 André P. Santos
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# notify-send
2+
3+
![](header.png)
4+
5+
## Installation
6+
7+
```sh
8+
pip install notify-send
9+
```
10+
11+
## Usage example
12+
13+
```python
14+
from notify import notification
15+
notification('body message', title='optinal')
16+
```
17+
18+
## Development setup
19+
20+
```sh
21+
git clone https://github.com/andreztz/notify-send.git
22+
cd notify-send
23+
virtualenv venv
24+
source venv/bin/activate
25+
pip install -e .
26+
```
27+
28+
## Release History
29+
30+
- 0.0.16 - The first proper release
31+
- Work in progress
32+
33+
## Meta
34+
35+
André P. Santos – [@ztzandre](https://twitter.com/ztzandre)andreztz@gmail.com
36+
37+
Distributed under the MIT license. See `LICENSE` for more information.
38+
39+
[https://github.com/andreztz/notify-send](https://github.com/andreztz/)
40+
41+
## Contributing
42+
43+
1. Fork it (<https://github.com/andreztz/notify-send/fork>)
44+
2. Create your feature branch (`git checkout -b feature/fooBar`)
45+
3. Commit your changes (`git commit -am 'Add some fooBar'`)
46+
4. Push to the branch (`git push origin feature/fooBar`)
47+
5. Create a new Pull Request

‎docs/_config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-architect

‎docs/api.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
## `Notification`
3+
4+
Displays a notification.
5+
6+
7+
**Paramters:**
8+
9+
| Name | type | description |
10+
| ---------|------|--------------------------------------------------------------|
11+
| title | str | The summary text (optional). |
12+
| message | str | The message body |
13+
|\*\*kwargs| | Additional arguments (optional) |
14+
15+
## Linux
16+
17+
This module contains the code for the notification using the Gtk api.
18+
19+
### `LinuxNotification`
20+
21+
Displays a notification using the Gtk API.
22+
23+
**Paramters:**
24+
25+
| Name | Type | Description |
26+
| ---------|-----------|------------------------ |
27+
| app_name | str | The application name to use for this notification. |
28+
| title | str | The summary text |
29+
| message | str | The message body text |
30+
| image | str | The icon filename or icon theme-compliant name |
31+
32+
33+
## Windows
34+
35+
This module contains the code for the notification using the Win32 api.
36+
37+
38+
### `Win32Notification`
39+
40+
41+
Displays a notification using the Win32 API.
42+
43+
**Paramters:**
44+
45+
| Name | Type | Description |
46+
| ---------|-----------|-------------------------------------------------------|
47+
| tip | str | Tooltip text (optional) |
48+
| timeout | int | Timeout for ballon tooltip in milliseconds (optional) |
49+
| title | str | Title for ballon tooltip (optional) |
50+
| message | str | Balloon tooltip text (optional) |
51+
52+
53+

‎docs/index.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Overview
2+
3+
Displays a notification suitable for the platform being run on.
4+
5+
6+
## Installation
7+
8+
```bash
9+
$ pip install notify-send
10+
```
11+
12+
## Example
13+
14+
```python
15+
from notify import notification
16+
notification('what you want said', title=':)')
17+
```
18+
19+
* [Notification](api.md#notification)
20+
* [Notification Linux](api.md#linux)
21+
* [Notification Windows](api.md#windows)
22+
23+
24+
## License
25+
26+
MIT, see LICENSE for more details.

‎mkdocs.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
site_name: Notify-Send
2+
3+
theme:
4+
name: "material"
5+
6+
plugins:
7+
- search
8+
- mkdocstrings

‎notify/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .notification import Notification
2+
from .notification import notification
3+
4+
__version__ = '0.0.16'
5+
6+
__all__ = ["Notification", "notification"]

‎notify/linux/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .notify import LinuxNotification
2+
3+
__all__ = ["LinuxNotification"]

‎notify/linux/notify.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
This module contains the code for the notification using the Gtk api.
3+
4+
https://lazka.github.io/pgi-docs/#Notify-0.7/classes/Notification.html
5+
https://lazka.github.io/pgi-docs/Notify-0.7/classes/Notification.html#Notify.Notification.set_app_name
6+
"""
7+
import sys
8+
import gi
9+
10+
gi.require_version("Notify", "0.7")
11+
12+
from gi.repository import Notify
13+
from gi.repository import GdkPixbuf
14+
15+
16+
class LinuxNotification:
17+
"""Displays a notification using the Gtk API.
18+
19+
Args:
20+
app_name: The application name to use for this notification.
21+
title: The summary text.
22+
message: The message body text.
23+
image: The icon filename or icon theme-compliant name
24+
"""
25+
26+
def __call__(
27+
self,
28+
message,
29+
title="",
30+
image="dialog-information",
31+
app_name=None,
32+
**kwargs
33+
):
34+
35+
app_name = app_name or sys.argv[0]
36+
Notify.init(app_name)
37+
n = Notify.Notification.new(title, message, image)
38+
n.show()

‎notify/notification.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Displays a notification suitable for the platform being run on.
3+
4+
Examples:
5+
```
6+
from notify import notification
7+
notification('what you want said', title=':)')
8+
```
9+
10+
License:
11+
12+
`MIT, see LICENSE for more details.`
13+
14+
"""
15+
import sys
16+
from importlib import import_module
17+
18+
platform = sys.platform
19+
20+
21+
try:
22+
mod = import_module("." + platform, __package__)
23+
except:
24+
raise RuntimeError("Unsupported operating system: {}".format(sys.platform))
25+
else:
26+
send = getattr(mod, "{}Notification".format(platform.title()))()
27+
28+
29+
class Notification:
30+
"""
31+
Displays a notification.
32+
33+
Args:
34+
message: The message body.
35+
title: The summary text (optional).
36+
**kwargs: Additional arguments (optional).
37+
"""
38+
39+
def __init__(self, message, title="", **kwargs):
40+
self.message = message
41+
self.title = title
42+
self.kwargs = kwargs
43+
44+
def __call__(self):
45+
send(self.message, self.title, **self.kwargs)
46+
47+
48+
def notification(message, title="", **kwargs):
49+
n = Notification(message, title, **kwargs)
50+
n()

‎notify/win32/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .notify import Win32Notification
2+
3+
__all__ = ["Win32Notification"]

‎notify/win32/notify.py

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""
2+
This module contains the code for the notification using the Win32 api.
3+
4+
From https://gist.github.com/BoppreH/4000505
5+
http://timgolden.me.uk/pywin32-docs/win32gui__Shell_NotifyIcon_meth.html
6+
http://timgolden.me.uk/pywin32-docs/PyNOTIFYICONDATA.html
7+
"""
8+
from win32api import GetModuleHandle
9+
from win32gui import WNDCLASS
10+
from win32gui import Shell_NotifyIcon
11+
from win32gui import RegisterClass
12+
from win32gui import CreateWindow
13+
from win32gui import UpdateWindow
14+
from win32gui import PostQuitMessage
15+
from win32gui import UnregisterClass
16+
from win32gui import DestroyWindow
17+
from win32gui import LoadIcon
18+
from win32gui import LoadImage
19+
from win32gui import (
20+
NIF_ICON,
21+
NIF_MESSAGE,
22+
NIF_TIP,
23+
NIF_INFO,
24+
NIM_MODIFY,
25+
NIM_ADD,
26+
NIM_DELETE,
27+
)
28+
29+
import win32con
30+
import sys
31+
import os
32+
import struct
33+
import time
34+
35+
36+
class Win32Notification:
37+
"""Displays a notification using the Win32 API.
38+
39+
Paramters:
40+
41+
tip (str): Tooltip text (optional)
42+
timeout (int): Timeout for ballon tooltip in milliseconds (optional)
43+
title (str): Title for ballon tooltip (optional)
44+
message (str): Balloon tooltip text (optional)
45+
"""
46+
47+
def __call__(
48+
self, message="", title="", tip="Balloon tooltip", timeout=200
49+
):
50+
51+
message_map = {win32con.WM_DESTROY: self.OnDestroy}
52+
# Register the Window class.
53+
wc = WNDCLASS()
54+
hinst = wc.hInstance = GetModuleHandle(None)
55+
wc.lpszClassName = "PythonTaskbar"
56+
wc.lpfnWndProc = message_map # could also specify a wndproc.
57+
classAtom = RegisterClass(wc)
58+
# Create the Window.
59+
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
60+
self.hwnd = CreateWindow(
61+
classAtom,
62+
"Taskbar",
63+
style,
64+
0,
65+
0,
66+
win32con.CW_USEDEFAULT,
67+
win32con.CW_USEDEFAULT,
68+
0,
69+
0,
70+
hinst,
71+
None,
72+
)
73+
UpdateWindow(self.hwnd)
74+
iconPathName = os.path.abspath(
75+
os.path.join(sys.path[0], "balloontip.ico")
76+
)
77+
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
78+
try:
79+
hicon = LoadImage(
80+
hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags
81+
)
82+
except:
83+
hicon = LoadIcon(0, win32con.IDI_APPLICATION)
84+
85+
flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
86+
nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon, "tooltip")
87+
Shell_NotifyIcon(NIM_ADD, nid)
88+
Shell_NotifyIcon(
89+
NIM_MODIFY,
90+
(
91+
self.hwnd,
92+
0,
93+
NIF_INFO,
94+
win32con.WM_USER + 20,
95+
hicon,
96+
tip,
97+
message,
98+
timeout,
99+
title,
100+
),
101+
)
102+
time.sleep(10)
103+
DestroyWindow(self.hwnd)
104+
UnregisterClass(classAtom, hinst)
105+
106+
def OnDestroy(self, hwnd, msg, wparam, lparam):
107+
nid = (self.hwnd, 0)
108+
Shell_NotifyIcon(NIM_DELETE, nid)
109+
PostQuitMessage(0) # Terminate the app.
110+
111+
112+
def run_balloon_tip(message, **kwargs):
113+
w = Win32Notification(message, **kwargs)
114+
115+
116+
if __name__ == "__main__":
117+
run_balloon_tip(message="Here is a balloon tip", title="Demonstration")

‎poetry.lock

+80
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[tool.poetry]
2+
name = "notify-send"
3+
version = "0.0.16"
4+
description = "Displays a notification suitable for the platform being run on."
5+
authors = ["André P. Santos <andreztz@gmail.com>"]
6+
license = "MIT"
7+
readme = "README.md"
8+
repository = "https://github.com/andreztz/notify-send"
9+
keywords = ["alert", "notification", "notify-send", "message", "toast"]
10+
packages = [
11+
{ include = "notify" },
12+
]
13+
classifiers = [
14+
"Development Status :: 1 - Planning",
15+
"Programming Language :: Python :: 3",
16+
"Intended Audience :: Developers",
17+
]
18+
19+
[tool.poetry.dependencies]
20+
python = "^3.8"
21+
pypiwin32 = { version = "223", markers = "sys_platform == 'win32'" }
22+
pywin32 = { version = "228", markers = "sys_platform == 'win32'" }
23+
pycairo = { version = "^1.18.1", markers = "sys_platform == 'linux'" }
24+
PyGObject = { version = "^3.34.0", markers = "sys_platform == 'linux'" }
25+
26+
[tool.poetry.dev-dependencies]
27+
28+
[build-system]
29+
requires = ["poetry>=0.12"]
30+
build-backend = "poetry.masonry.api"

‎tests/__init__.py

Whitespace-only changes.

‎tests/test_notification.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from notify import Notification
2+
from notify import notification
3+
4+
5+
def test_if_notification_is_callable():
6+
assert callable(notification)
7+
8+
9+
def test_notification_function():
10+
notification("hello world", title="optinal")
11+
12+
13+
def test_notification_class():
14+
n = Notification("Hello World", title="optional")
15+
n()

0 commit comments

Comments
 (0)
Please sign in to comment.