#!/usr/bin/env python
# -*- coding: utf-8 -*-

###########################################################################
# Show a message using gtk.MessageDialog.
#
# Copyright (C) 2012 Alkis Georgopoulos <alkisg@gmail.com>
#
# 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 FINESS 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 <http://www.gnu.org/licenses/>.
#
# On Debian GNU/Linux systems, the complete text of the GNU General
# Public License can be found in `/usr/share/common-licenses/GPL".
############################################################################

import gtk

def MessageDialog(text, title="Epoptes", markup=True, icon="dialog-information"):
    if icon == "dialog-error":
        type = gtk.MESSAGE_ERROR
    elif icon == "dialog-question":
        type = gtk.MESSAGE_QUESTION
    elif icon == "dialog-warning":
        type = gtk.MESSAGE_WARNING
    else:
        type = gtk.MESSAGE_INFO
    dlg = gtk.MessageDialog(None, 0, type, gtk.BUTTONS_CLOSE, text)
    dlg.set_modal(True)
    dlg.set_title(title)
    dlg.set_property('use-markup', markup)
    dlg.set_property('skip-taskbar-hint', False)
    dlg.set_property('icon-name', icon)
    dlg.run()
    dlg.destroy()


if __name__ == '__main__':
    from sys import argv

    if not (len(argv) >= 1 and len(argv) <= 5):
        print "Usage: message text [title] [markup] [icon]"
        exit(1)

    if len(argv) == 5:
        type = argv[4]
    else:
        type = "dialog-information"

    if len(argv) >= 4:
        markup = argv[3] == "True"
    else:
        markup = "False"

    if len(argv) >= 3:
        title = argv[2]
    else:
        title = 'Epoptes'

    if len(argv) >= 2:
        text = argv[1]

    MessageDialog(text, title, markup, type)
