## special meaning in mate-python (unlike standard popt).  Usually,
## when multiple values are passed for the same option in the command
## line, only the last value is returned to the caller.  In contrast,
## if the programmer specifies [] as default value, then mate-python
## will collect all option values into a list and return this list as
## value to the caller.

# (longName, shortName, type , default, flags, descrip , argDescrip)
table=[("foo"  , 'f'   , int  ,   1     , 0    , "Foobar", "Level"),
       ("aaa"  , 'a'   , str  ,   'a'   , 0    , 'aaa'   , "AAA"),
       ("bbb"  , 'b'   , None ,   None  , 0    , 'bbb'   , "BBB"),
       ("ccc"  , 'c'   , float,   2.5   , 0    , 'ccc'   , "BBB"),
       ("ddd"  , 'd'   , long ,   []    , 0    , 'ddd'   , "DDD"),
       ("eee"  , 'e'   , int,     2     , mate.POPT_ARGFLAG_OR)
       ]

prog = mate.init ("myprog", "1.0", mate.libmate_module_info_get(),
                   sys.argv, table)

print "parsing with mate.init"
leftover_args, argdict = prog.get_popt_args()
print "Leftover: ", leftover_args
print "Argdict: ", argdict

del prog; gc.collect()

print "parsing with mate.pop_parse"
leftover_args, argdict = mate.popt_parse(sys.argv, table)
print "Leftover: ", leftover_args
print "Argdict: ", argdict
Exemple #2
0
slowly get rid of popt (even if libmate will still have to depend on it for
compatibility reasons). 

"""

import sys

import glib
import mate


def callback(name, value, group):
    if name == "--example":
        print "example got %s" % value
    elif name in ("-o", "--option"):
        print "option"
    else:
        print "remaining:", value


group = glib.OptionGroup(None, None, None, callback)
group.add_entries([
    ("example", "\0", 0, "An example option", "option"),
    ("option", "o", glib.OPTION_FLAG_NO_ARG, "An option", None),
    (glib.OPTION_REMAINING, "\0", 0, "", None),
])
context = glib.OptionContext("argument")
context.set_main_group(group)

prog = mate.init("myprog", "1.0", argv=sys.argv, option_context=context)
Exemple #3
0
The help output of your program will be much nicer :-) And it will enable us to
slowly get rid of popt (even if libmate will still have to depend on it for
compatibility reasons). 

"""

import sys

import glib
import mate

def callback(name, value, group):
    if name == "--example":
        print "example got %s" % value
    elif name in ("-o", "--option"):
        print "option"
    else:
        print "remaining:", value

group = glib.OptionGroup(None, None, None, callback)
group.add_entries([("example", "\0", 0, "An example option",
                    "option"),
                   ("option", "o", glib.OPTION_FLAG_NO_ARG, "An option",
                    None),
                   (glib.OPTION_REMAINING, "\0", 0, "", None),
                  ])
context = glib.OptionContext("argument")
context.set_main_group(group)

prog = mate.init("myprog", "1.0", argv=sys.argv, option_context=context)