-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify.py
More file actions
138 lines (115 loc) · 3.41 KB
/
notify.py
File metadata and controls
138 lines (115 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Copyright (C) 2009 www.stani.be
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/
# Follows PEP8
APP_NAME = 'notify.py'
# pynotify (linux)
try:
import pynotify
import gobject
gobject.threads_init()
except ImportError:
pynotify = None
# Growl (Mac Os X)
if pynotify:
Growl = None
else:
try:
import Growl
except ImportError:
Growl = None
# Toasterbox (Windows)
if pynotify or Growl:
TB = None
else:
try:
import wx
#import other.pyWx.toasterbox as TB
import wx.lib.agw.toasterbox as TB
#import ToasterBox as TB
except ImportError:
TB = None
def register(app_name):
global APP_NAME
APP_NAME = app_name
def init(app_name, icon=None):
register(app_name)
if pynotify:
def init(app_name, icon=None):
register(app_name)
pynotify.init(app_name)
def send(title, message, icon='gtk-dialog-info', wxicon=None,
urgency=None, timeout=None):
n = pynotify.Notification(title, message, icon)
if urgency:
n.set_urgency(getattr(pynotify,
'URGENCY_%s' % urgency.upper()))
if timeout:
n.set_timeout(timeout)
n.show()
elif Growl:
def init(app_name, icon=None):
"""Create a growl notifier with appropriate icon if specified.
The notification classes default to [APP_NAME]. The user can
enable/disable notifications based on this class name."""
global growl
register(app_name)
if icon is None:
icon = {}
else:
icon = {'applicationIcon': Growl.Image.imageFromPath(icon)}
growl = Growl.GrowlNotifier(APP_NAME, [APP_NAME], **icon)
def send(title, message, icon='gtk-dialog-info', wxicon=None,
urgency=None, timeout=None):
global growl
growl.notify(APP_NAME, title, message)
elif TB:
def send(title, message, icon='gtk-dialog-info',
wxicon=None, urgency=None, timeout=None):
if wxicon == None:
wxicon = wx.ArtProvider_GetBitmap(wx.ART_INFORMATION,
wx.ART_OTHER, (48, 48))
tb = TB.ToasterBox(wx.GetApp().GetTopWindow(),
TB.TB_COMPLEX, TB.DEFAULT_TB_STYLE, TB.TB_ONTIME)
tb.SetPopupSize((300, 80))
tb.SetPopupPauseTime(5000)
tb.SetPopupScrollSpeed(8)
tb.SetPopupPositionByInt(3)
#wx controls
tbpanel = tb.GetToasterBoxWindow()
panel = wx.Panel(tbpanel, -1)
panel.SetBackgroundColour(wx.WHITE)
wxicon = wx.StaticBitmap(panel, -1, wxicon)
title = wx.StaticText(panel, -1, title)
message = wx.StaticText(panel, -1, message)
# wx layout controls
ver_sizer = wx.BoxSizer(wx.VERTICAL)
ver_sizer.Add(title, 0, wx.ALL, 4)
ver_sizer.Add(message, 0, wx.ALL, 4)
hor_sizer = wx.BoxSizer(wx.HORIZONTAL)
hor_sizer.Add(wxicon, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL \
| wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 4)
hor_sizer.Add(ver_sizer, 1, wx.EXPAND)
hor_sizer.Layout()
panel.SetSizer(hor_sizer)
tb.AddPanel(panel)
tb.Play()
else:
def send(*args, **keyw):
print 'No notification system found.'
pass
app = wx.PySimpleApp()
#frame = ToasterBoxDemo(None)
#frame.Show()
app.MainLoop()