#!/usr/bin/python # notify.py is a simple notification program displaying a message on the # screen. # Copyright (C) 2011-2013 Simon Ruderich # # 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 . import sys import locale import pygtk pygtk.require('2.0') # there might be a GTK 1 version installed, ignore it import gtk import pango import gobject # Pressing the mouse inside the window quits notify. def mouse_press_callback(widget, event): gtk.main_quit() if __name__ == '__main__': if len(sys.argv) != 2: sys.stderr.write("Usage: %s \n" % (sys.argv[0])) sys.exit(1) # Display configuration. BOLD = True FG_COLOR = 'blue' BG_COLOR = 'yellow' # We need a popup so the window manager doesn't touch our window. window = gtk.Window(gtk.WINDOW_POPUP) # No window border or close/resize buttons. window.set_decorated(False) # In case set_decorated(False) doesn't work with the used window manager # quit when the window is manually closed. window.connect('delete-event', gtk.main_quit) # Enable mouse click events, by default windows don't receive them. window.add_events(gtk.gdk.BUTTON_PRESS_MASK) window.connect('button-press-event', mouse_press_callback) # Background color. window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BG_COLOR)) string = sys.argv[1].decode(locale.getdefaultlocale()[1]) # Colored message string. label_message = gtk.Label(string) label_message.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(FG_COLOR)) window.add(label_message) if BOLD: attributes = pango.AttrList() attributes.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, end_index=-1)) label_message.set_attributes(attributes) # Display at the top at full screen width. screen = window.get_screen() window.resize(screen.get_width(), 30) window.move(0, 15) window.show_all() gtk.main()