#!/usr/bin/env python
# gnome-python/pygobject/examples/option.py

import gobject
import sys
import os

filename = None

class TestController(object):
    def __init__(self):
        self.opts = gobject.OptionGroup("test", "Test Controller Options:", "Show all Test Controller options")
        self.opts.set_parse_hooks(self.pre, self.post)
        self.opts.set_error_hook(self.error)
        
        self.opts.add_entries([
            ("string", "s", 0, gobject.OPTION_ARG_STRING, 'string', "Sets the string to STRING.", "STRING"),
            ("list", "l", 0, gobject.OPTION_ARG_STRING_ARRAY, 'list', "Multiple string arguements", "STRING"),
        ])
        
    def get_option_group(self):
        return self.opts

    def pre(self, group):
        print "TestController.pre"
        
    def post(self, group):
        print "TestController.post"
        print "string", self.opts['string']
        print "list", self.opts['list']
        
    def error(self, group):
        print "TestController.error"

if __name__ == '__main__':
    controller = TestController()

    try:
        ctxt = gobject.OptionContext("- A simple GOptionContext and GOptionGroup example")

        def setFilename(option_name, option_value, group):
            filename = option_value
        
        ctxt.add_main_entries([
            ("file", "f", 0, gobject.OPTION_ARG_CALLBACK, setFilename, "FILE must exist", "FILE"),
            ("number", "n", 0, gobject.OPTION_ARG_INT, 'number', "Sets the integer to NUM", "NUM"),
        ])

        ctxt.add_group(controller.get_option_group())

        ctxt.parse(sys.argv)
        
        print "Number", ctxt.get_main_group()['number']
        print "Filename", filename
    except gobject.GError, err:
        print err
        
