]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - bin/notify.py
68c331a86483ec8144592fd73a81ec6e6407bc79
[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-2012  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     window.connect('delete-event', gtk.main_quit)
49     # Enable mouse click events, by default windows don't receive them.
50     window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
51     window.connect('button-press-event', mouse_press_callback)
52
53     # Background color.
54     window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BG_COLOR))
55
56     string = sys.argv[1].decode(locale.getdefaultlocale()[1])
57
58     # Colored message string.
59     label_message = gtk.Label(string)
60     label_message.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(FG_COLOR))
61     window.add(label_message)
62
63     if BOLD:
64         attributes = pango.AttrList()
65         attributes.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, end_index=-1))
66         label_message.set_attributes(attributes)
67
68     # Display at the top at full screen width.
69     screen = window.get_screen()
70     window.resize(screen.get_width(), 30)
71     window.move(0, 15)
72
73     window.show_all()
74     gtk.main()