diff --git a/gooey/gui/components.py b/gooey/gui/components.py index 0ff3cc4..07f996a 100644 --- a/gooey/gui/components.py +++ b/gooey/gui/components.py @@ -69,10 +69,16 @@ class AbstractComponent(object): return base_text def HasNargs(self, action): - return action.nargs == '+' or action.nargs == '?' + return action.nargs is not None and action.nargs is not 0 + def CreateNargsMsg(self, action): - return ' (Note: at least 1 or more arguments are required)' + if isinstance(action.nargs, int): + return '\n(Note: exactly {} arguments are required)'.format(action.nargs) + elif action.nargs == '+': + return '\n(Note: at least 1 or more arguments are required)' + return '' + def CreateNameLabelWidget(self, parent, action): label = str(action.dest).title() diff --git a/gooey/mockapplications/mockapp_nargs.py b/gooey/mockapplications/mockapp_nargs.py new file mode 100644 index 0000000..2369171 --- /dev/null +++ b/gooey/mockapplications/mockapp_nargs.py @@ -0,0 +1,22 @@ +import sys +import argparse +from gooey import Gooey + + +sys.argv.extend(['1', '2', '3', '4', '--sum']) + +# @Gooey +def main(): + parser = argparse.ArgumentParser(description='Process some integers.') + parser.add_argument('integers', metavar='N', type=int, nargs="+", + help='an integer for the accumulator') + parser.add_argument('--sum', dest='accumulate', action='store_const', + const=sum, default=max, + help='sum the integers (default: find the max)') + + args = parser.parse_args() + print args.accumulate(args.integers) + + +if __name__ == '__main__': + main()