#! @PYTHON@ ### -*-python-*- ### ### Report a message to the user ### ### (c) 2008 Straylight/Edgeware ### ###----- Licensing notice --------------------------------------------------- ### ### This file is part of the Edgeware X tools collection. ### ### X tools 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 2 of the License, or ### (at your option) any later version. ### ### X tools 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 X tools; if not, write to the Free Software Foundation, ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. VERSION = '@VERSION@' ###-------------------------------------------------------------------------- ### External dependencies. import optparse as O from sys import stdin, stdout, stderr, exit import os as OS import errno as E import xtoys as XT GTK = XT.GTK ###-------------------------------------------------------------------------- ### Option parsing. def parse_args(): """ Parse the command line, returning a triple (PARSER, OPTS, ARGS). """ op = XT.make_optparse \ ([('E', 'error', {'action': 'store_const', 'dest': 'type', 'const': 'error', 'help': "Mark the window as reporting an error."}), ('I', 'informational', {'action': 'store_const', 'dest': 'type', 'const': 'info', 'help': "Mark the window as providing information."}), ('Q', 'question', {'action': 'store_const', 'dest': 'type', 'const': 'question', 'help': "Mark the window as asking a question."}), ('W', 'warning', {'action': 'store_const', 'dest': 'type', 'const': 'warning', 'help': "Mark the window as giving a warning."}), ('d', 'headline', {'dest': 'headline', 'help': "Set the window's headline message."}), ('m', 'markup', {'action': 'store_true', 'dest': 'markupp', 'help': "Parse message strings for Pango markup."}), ('t', 'title', {'dest': 'title', 'help': "Set the window's title string."})], version = VERSION, usage = '%prog [-EIQWm] [-t TITLE] [-d HEADLINE] ' 'MESSAGE [BUTTONS...]') op.set_defaults(title = 'xmsg', type = 'info', headline = None, markupp = False) opts, args = op.parse_args() return op, opts, args ###-------------------------------------------------------------------------- ### Main program. def main(): op, opts, args = parse_args() if len(args) == 0: op.print_usage(stderr) exit(1) ## Sort out the message. message = args[0] buttons = args[1:] if message.startswith('!'): message = message[1:] elif message == '-': message = stdin.read() ## Display it and retrieve and answer. try: msg = XT.Message(title = opts.title, type = opts.type, message = message, headline = opts.headline, buttons = buttons, markupp = opts.markupp) except ValueError, err: op.error(err[0]) result = msg.ask() ## Done. if result != True: print result exit(0) if __name__ == '__main__': main() ###----- That's all, folks --------------------------------------------------