]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - bin/notify.py
bin/notify.py: Minor documentation update.
[config/dotfiles.git] / bin / notify.py
1 #!/usr/bin/python
2
3 # notify.py is a simple notification program displaying a message on the
4 # screen.
5
6 # Copyright (C) 2011-2013  Simon Ruderich
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21
22 import sys
23 import locale
24
25 import pygtk
26 pygtk.require('2.0') # there might be a GTK 1 version installed, ignore it
27 import gtk
28 import pango
29 import gobject
30
31
32 # Pressing the mouse inside the window quits notify.
33 def mouse_press_callback(widget, event):
34     gtk.main_quit()
35
36
37 if __name__ == '__main__':
38     # Display configuration.
39     BOLD     = True
40     FG_COLOR = 'blue'
41     BG_COLOR = 'yellow'
42
43     # We need a popup so the window manager doesn't touch our window.
44     window = gtk.Window(gtk.WINDOW_POPUP)
45     # No window border or close/resize buttons.
46     window.set_decorated(False)
47     # In case set_decorated(False) doesn't work with the used window manager
48     # quit when the window is manually closed.
49     window.connect('delete-event', gtk.main_quit)
50     # Enable mouse click events, by default windows don't receive them.
51     window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
52     window.connect('button-press-event', mouse_press_callback)
53
54     # Background color.
55     window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BG_COLOR))
56
57     string = sys.argv[1].decode(locale.getdefaultlocale()[1])
58
59     # Colored message string.
60     label_message = gtk.Label(string)
61     label_message.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(FG_COLOR))
62     window.add(label_message)
63
64     if BOLD:
65         attributes = pango.AttrList()
66         attributes.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, end_index=-1))
67         label_message.set_attributes(attributes)
68
69     # Display at the top at full screen width.
70     screen = window.get_screen()
71     window.resize(screen.get_width(), 30)
72     window.move(0, 15)
73
74     window.show_all()
75     gtk.main()