From e03c647317bd1861e4e84f59089bc5ebca44e739 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 14 Feb 2012 02:06:53 +0100 Subject: [PATCH] bin/notify.py: Add, displays a message on the screen. --- bin/notify.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 bin/notify.py diff --git a/bin/notify.py b/bin/notify.py new file mode 100755 index 0000000..68c331a --- /dev/null +++ b/bin/notify.py @@ -0,0 +1,74 @@ +#!/usr/bin/python + +# notify.py is a simple notification program displaying a message on the +# screen. + +# Copyright (C) 2011-2012 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__': + # 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. + 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() -- 2.45.2