1
# -*- coding: utf-8 -*-
3
# gPodder - A media aggregator and podcast client
4
# Copyright (c) 2005-2013 Thomas Perl and the gPodder Team
6
# gPodder is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
11
# gPodder is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
# Notification implementation for Windows
21
# Sean Munkel; 2012-12-29
23
__title__ = 'Notification Bubbles for Windows'
24
__description__ = 'Display notification bubbles for different events.'
25
__authors__ = 'Sean Munkel <SeanMunkel@gmail.com>'
26
__category__ = 'desktop-integration'
27
__mandatory_in__ = 'win32'
28
__only_for__ = 'win32'
39
logger = logging.getLogger(__name__)
41
IDI_APPLICATION = 32512
42
WM_TASKBARCREATED = win32gui.RegisterWindowMessage('TaskbarCreated')
45
# based on http://code.activestate.com/recipes/334779/
46
class NotifyIcon(object):
47
def __init__(self, hwnd):
50
self._flags = win32gui.NIF_MESSAGE | win32gui.NIF_ICON
51
self._callbackmessage = WM_TRAYMESSAGE
52
path = os.path.join(os.path.dirname(__file__), '..', '..',
53
'icons', 'hicolor', '16x16', 'apps', 'gpodder.ico')
54
icon_path = os.path.abspath(path)
57
self._hicon = win32gui.LoadImage(None, icon_path, 1, 0, 0, 0x50)
58
except pywintypes.error as e:
59
logger.warn("Couldn't load gpodder icon for tray")
60
self._hicon = win32gui.LoadIcon(0, IDI_APPLICATION)
66
self._infoflags = win32gui.NIIF_NONE
67
win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, self.notify_config_data)
70
def notify_config_data(self):
71
""" Function to retrieve the NOTIFYICONDATA Structure. """
72
return (self._hwnd, self._id, self._flags, self._callbackmessage,
73
self._hicon, self._tip, self._info, self._timeout,
74
self._infotitle, self._infoflags)
77
""" Removes the tray icon. """
78
win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE,
79
self.notify_config_data)
81
def set_tooltip(self, tooltip):
82
""" Sets the tray icon tooltip. """
83
self._flags = self._flags | win32gui.NIF_TIP
84
self._tip = tooltip.encode("mbcs")
85
win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY,
86
self.notify_config_data)
88
def show_balloon(self, title, text, timeout=10,
89
icon=win32gui.NIIF_NONE):
90
""" Shows a balloon tooltip from the tray icon. """
91
self._flags = self._flags | win32gui.NIF_INFO
92
self._infotitle = title.encode("mbcs")
93
self._info = text.encode("mbcs")
94
self._timeout = timeout * 1000
95
self._infoflags = icon
96
win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY,
97
self.notify_config_data)
100
class gPodderExtension(object):
101
def __init__(self, *args):
104
def on_ui_object_available(self, name, ui_object):
105
def callback(self, window, *args):
106
self.notifier = NotifyIcon(window.window.handle)
108
if name == 'gpodder-gtk':
109
ui_object.main_window.connect('realize',
110
functools.partial(callback, self))
112
def on_notification_show(self, title, message):
113
if self.notifier is not None:
114
self.notifier.show_balloon(title, message)
117
if self.notifier is not None:
118
self.notifier.remove()