Skip to content

Commit

Permalink
Merge branch 'master' into macosx
Browse files Browse the repository at this point in the history
  • Loading branch information
dschep committed Jan 4, 2016
2 parents d26f619 + a86b9c1 commit 2977e92
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ it supports multiple backends.
sudo pip install ntfy
```

Note: It is suggested to globally (as indicated above, without a virtualenv) install ntfy. It _can_ be installed in a virtualenv, but Mac OS X notifications won't work.
Note: It is suggested to globally (as indicated above, without a virtualenv) install ntfy. It _can_ be installed in a virtualenv, but Mac OS X & Windows notifications won't work.

## Usage
```
Expand All @@ -35,14 +35,14 @@ ntfy done sleep 10
- [x] [Pushover](https://pushover.net)
- [x] [Pushbullet](https://pushbullet.com)
- [x] Linux Desktop Notifications (notify-send)
- [X] Windows Desktop Notifications (requires [PyWin32](http://sourceforge.net/projects/pywin32/))
- [x] Mac OS X Notification Center
- [ ] [Prowl](http://www.prowlapp.com)
- [ ] [Airgram](http://www.airgramapp.com)
- [ ] [Pushjet](https://pushjet.io)
- [ ] [Pushalot](https://pushalot.com)
- [ ] [Boxcar](https://boxcar.io)
- [ ] [Instapush](https://instapush.im)
- [ ] Windows Desktop Notifications?

## Config
`ntfy` is configured via a json config file stored at `~/.ntfy.json`. It
Expand Down
5 changes: 3 additions & 2 deletions ntfy/backends/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@


def notify(subject, config, message=None, device=None):
for os in ['linux', 'darwin']:
for os in ['linux', 'win32', 'darwin']:
if platform.startswith(os):
module = import_module('ntfy.backends.{}'.format(os))
module.notify(subject, config, message, device)
module.notify(subject=subject, config=config,
message=message, device=device)
break
49 changes: 49 additions & 0 deletions ntfy/backends/win32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -- coding: utf-8 --

from win32api import *
from win32gui import *
import win32con
import os
import struct
import time

def notify(subject, message, config, device=None):
class WindowsBalloonTip:
def __init__(self, title, msg):
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
}
# Register the Window class.
wc = WNDCLASS()
hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbar"
wc.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = CreateWindow( classAtom, "Taskbar", style, \
0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
0, 0, hinst, None)
UpdateWindow(self.hwnd)
iconPathName = os.path.abspath(os.path.join(os.path.split(
os.path.split(__file__)[0])[0], 'icon.ico'))
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
try:
hicon = LoadImage(hinst, iconPathName, \
win32con.IMAGE_ICON, 0, 0, icon_flags)
except:
hicon = LoadIcon(0, win32con.IDI_APPLICATION)
flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, "tooltip")
Shell_NotifyIcon(NIM_ADD, nid)
Shell_NotifyIcon(NIM_MODIFY, \
(self.hwnd, 0, NIF_INFO, win32con.WM_USER+20,\
hicon, "Balloon tooltip",title,200,msg))
DestroyWindow(self.hwnd)
def OnDestroy(self, hwnd, msg, wparam, lparam):
nid = (self.hwnd, 0)
Shell_NotifyIcon(NIM_DELETE, nid)
PostQuitMessage(0) # Terminate the app.


WindowsBalloonTip(message, subject)
Binary file added ntfy/icon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
keywords='push notification',

packages=['ntfy', 'ntfy.backends'],
package_data={'ntfy': ['icon.png']},
package_data={'ntfy': ['icon.png', 'icon.ico']},

install_requires=[
'requests',
Expand Down

0 comments on commit 2977e92

Please sign in to comment.