Skip to content

Commit

Permalink
Merge pull request #4 from ms7m/dev
Browse files Browse the repository at this point in the history
0.0.8
  • Loading branch information
ms7m authored May 21, 2020
2 parents 18d1bf1 + ef5f5f0 commit aebffad
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,6 @@ dmypy.json

# Cython debug symbols
cython_debug/

# PyCharm
.idea/
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ def super_long_function():

```

```python

import notifypy

notification = notify.Notify()
# Send the notification without blocking.

notification.send(block=False)
```
***


Expand All @@ -93,7 +102,7 @@ def super_long_function():

- As it stands (May 18, 2020), this is simply a notification service. There is *no* support for embedding custom actions (buttons, dialogs) regardless of platform. Other then telling you if the shell command was sent, there is also no confirmation on user action on the notification.

- This is **blocking**. This will block most programs when *sending* the notification. This will be changed in the future. This *may* cause GUI applications to freeze. Do your own testing.
~~- This is **blocking**. This will block most programs when *sending* the notification. This will be changed in the future. This *may* cause GUI applications to freeze. Do your own testing.~~ v0.0.8.

- There is no support for sending custom sounds, and is silent for most platforms. (notable exclusion is windows.). This will be changed in the future.
- macOS does **not** support custom icons OTF. You will need to bundle a customized version of the notifier embedded with your custom icon.
Expand All @@ -106,6 +115,10 @@ def super_long_function():

***


### Contributors
- [Laterax](https://github.com/Leterax)
***
### Special Thanks

- https://github.com/go-toast/toast - Ported their Windows 10 toast notification to Python.
Expand Down
Binary file removed dist/notify_py-0.0.7.tar.gz
Binary file not shown.
Binary file not shown.
Binary file added dist/notify_py-0.0.8.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion notifypy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .notify import Notify

__version__ = "0.0.7"
__version__ = "0.0.8"
32 changes: 26 additions & 6 deletions notifypy/notify.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import platform
import os
import pathlib
import threading


from loguru import logger

Expand Down Expand Up @@ -87,18 +89,36 @@ def application_name(self):
def application_name(self, new_application_name):
self._notification_application_name = new_application_name

def send(self):
def send(self, block=True):
# if block is True, wait for the notification to complete and return if it was successful
# else start the thread and return a threading.Event that will determine when the notification was successful
event = threading.Event()
try:
return self.send_notification(
supplied_title=self._notification_title,
supplied_message=self._notification_message,
supplied_application_name=self._notification_application_name,
supplied_icon_path=self._notification_icon,
thread = threading.Thread(
target=lambda: self.start_notification_thread(event)
)
thread.name = "notify.py"
thread.start()
if block:
thread.join(timeout=35)
return event.is_set()
return event
except Exception:
logger.exception("Exception in running send-Notification.")
raise

def start_notification_thread(self, event):
result = self.send_notification(
supplied_title=self._notification_title,
supplied_message=self._notification_message,
supplied_application_name=self._notification_application_name,
supplied_icon_path=self._notification_icon,
)
if result:
event.set()
else:
event.clear()

def send_notification(
self,
supplied_title,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,12 @@ def test_rtl_language_notification():
n.title = "مرحبا كيف الحال؟"
assert n.send() == True

def test_blocking_notification():
n = notifypy.Notify()
assert n.send(block=True) == True

def test_non_blocking_notification():
n = notifypy.Notify()
thread_notify = n.send(block=False)
assert thread_notify.wait()

0 comments on commit aebffad

Please sign in to comment.