3 # notify.py is a simple notification program displaying a message on the
6 # Copyright (C) 2011-2013 Simon Ruderich
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.
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.
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/>.
26 pygtk.require('2.0') # there might be a GTK 1 version installed, ignore it
32 # Pressing the mouse inside the window quits notify.
33 def mouse_press_callback(widget, event):
37 if __name__ == '__main__':
38 if len(sys.argv) != 2:
39 sys.stderr.write("Usage: %s <message>\n" % (sys.argv[0]))
42 # Display configuration.
47 # We need a popup so the window manager doesn't touch our window.
48 window = gtk.Window(gtk.WINDOW_POPUP)
49 # No window border or close/resize buttons.
50 window.set_decorated(False)
51 # In case set_decorated(False) doesn't work with the used window manager
52 # quit when the window is manually closed.
53 window.connect('delete-event', gtk.main_quit)
54 # Enable mouse click events, by default windows don't receive them.
55 window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
56 window.connect('button-press-event', mouse_press_callback)
59 window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BG_COLOR))
61 string = sys.argv[1].decode(locale.getdefaultlocale()[1])
63 # Colored message string.
64 label_message = gtk.Label(string)
65 label_message.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(FG_COLOR))
66 window.add(label_message)
69 attributes = pango.AttrList()
70 attributes.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, end_index=-1))
71 label_message.set_attributes(attributes)
73 # Display at the top at full screen width.
74 screen = window.get_screen()
75 window.resize(screen.get_width(), 30)