diff --git a/gooey/examples/TODO.py b/gooey/examples/TODO.py deleted file mode 100644 index a0e0e9c..0000000 --- a/gooey/examples/TODO.py +++ /dev/null @@ -1,173 +0,0 @@ -#!/usr/local/bin/python2.7 -# encoding: utf-8 -''' - -TODO: Fix this. Currently breaks parser - - -bin.example_argparse_souce -- shortdesc - -bin.example_argparse_souce is a description - -It defines classes_and_methods - -@author: user_name - -@copyright: 2013 organization_name. All rights reserved. - -@license: license - -@contact: user_email -@deffield updated: Updated -''' - -import sys -import os -from argparse import ArgumentParser -from argparse import RawDescriptionHelpFormatter - -from gooey.python_bindings.gooey_decorator import Gooey - - -__all__ = [] -__version__ = 0.1 -__date__ = '2013-12-13' -__updated__ = '2013-12-13' - -DEBUG = 0 -TESTRUN = 0 -PROFILE = 0 - - -class CLIError(Exception): - '''Generic exception to raise and log different fatal errors.''' - - def __init__(self, msg): - super(CLIError).__init__(type(self)) - self.msg = "E: %s" % msg - - def __str__(self): - return self.msg - - def __unicode__(self): - return self.msg - -raise NotImplementedError("This one doesn't work just yet. Please run any of the other apps in the examples directory. :) Sorry!") - -@Gooey -def main(argv=None): # IGNORE:C0111 - '''Command line options.''' - - if argv is None: - argv = sys.argv - else: - sys.argv.extend(argv) - - program_name = os.path.basename(sys.argv[0]) - program_version = "v%s" % __version__ - program_build_date = str(__updated__) - program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) - program_shortdesc = __import__('__main__').__doc__.split("\n")[1] - program_license = '''%s - - Created by user_name on %s. - Copyright 2013 organization_name. All rights reserved. - - Licensed under the Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0 - - Distributed on an "AS IS" basis without warranties - or conditions of any kind, either express or implied. - -USAGE -''' % (program_shortdesc, str(__date__)) - - try: - # Setup argument parser - parser = ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter) - - parser.add_argument("filename", help="filename") - - parser.add_argument("-r", "--recursive", dest="recurse", action="store_true", - help="recurse into subfolders [default: %(default)s]") - - parser.add_argument("-v", "--verbose", dest="verbose", action="count", - help="set verbosity level [default: %(default)s]") - - parser.add_argument("-i", "--include", action="append", nargs='+', - help="only include paths matching this regex pattern. Note: exclude is given preference over include. ", - metavar="RE") - - parser.add_argument("-m", "--mycoolargument", help="mycoolargument") - - parser.add_argument("-e", "--exclude", dest="exclude", - help="exclude paths matching this regex pattern. [default: %(default)s]", metavar="RE") - - parser.add_argument('-V', '--version', action='version') - - parser.add_argument('-T', '--tester', choices=['yes', 'no']) - - parser.add_argument(dest="paths", help="paths to folder(s) with source file(s) [default: %(default)s]", - metavar="path", nargs='+') - - # for i in parser._actions: - # print i - # Process arguments - args = parser.parse_args() - - paths = args.paths - verbose = args.verbose - recurse = args.recurse - inpat = args.include - expat = args.exclude - - if verbose > 0: - print("Verbose mode on") - if recurse: - print("Recursive mode on") - else: - print("Recursive mode off") - - if inpat and expat and inpat == expat: - raise CLIError("include and exclude pattern are equal! Nothing will be processed.") - - for inpath in paths: - ### do something with inpath ### - print(inpath) - return 0 - except KeyboardInterrupt: - ### handle keyboard interrupt ### - return 0 - except Exception, e: - if DEBUG or TESTRUN: - raise (e) - indent = len(program_name) * " " - sys.stderr.write(program_name + ": " + repr(e) + "\n") - sys.stderr.write(indent + " for help use --help") - return 2 - - -if __name__ == "__main__": - if DEBUG: - sys.argv.append("-h") - # sys.argv.append("-v") - sys.argv.append("-r") - main() - sys.exit() - if TESTRUN: - import doctest - - doctest.testmod() - if PROFILE: - import cProfile - import pstats - - profile_filename = 'bin.example_argparse_souce_profile.txt' - cProfile.run('main()', profile_filename) - statsfile = open("profile_stats.txt", "wb") - p = pstats.Stats(profile_filename, stream=statsfile) - stats = p.strip_dirs().sort_stats('cumulative') - stats.print_stats() - statsfile.close() - sys.exit(0) - sys.exit(main()) diff --git a/gooey/examples/deleteme.py b/gooey/examples/deleteme.py deleted file mode 100644 index eb1a9d5..0000000 --- a/gooey/examples/deleteme.py +++ /dev/null @@ -1,25 +0,0 @@ -import sys, argparse - -from gooey import Gooey - -@Gooey -def main(): - parser = argparse.ArgumentParser(description='The program displays the video.') - parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file', required = True) - parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', default = 0, type = int) - parser.add_argument('--fps', dest = 'frameRate', help = 'approximate frame rate to replay', type = float) - parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float) - - args = parser.parse_args() - - firstFrameNum = 0 - if args.firstFrameNum is not None: - firstFrameNum = args.firstFrameNum - - frameRate = -1 - if args.frameRate is not None: - frameRate = args.frameRate - - print('{} {} {} {}'.format(args.videoFilename, firstFrameNum, frameRate, rescale = args.rescale)) - -main() diff --git a/gooey/examples/responding_to_error.py b/gooey/examples/error_demo.py similarity index 100% rename from gooey/examples/responding_to_error.py rename to gooey/examples/error_demo.py diff --git a/gooey/examples/module_with_no_argparse.py b/gooey/examples/force_start_demo.py similarity index 71% rename from gooey/examples/module_with_no_argparse.py rename to gooey/examples/force_start_demo.py index f8809f3..eb7b140 100644 --- a/gooey/examples/module_with_no_argparse.py +++ b/gooey/examples/force_start_demo.py @@ -8,9 +8,9 @@ from gooey import Gooey @Gooey def main(): - end = time.time() + 10 + end = time.time() + 3 while end > time.time(): - print 'Jello!', time.time() + print 'Hello!', time.time() time.sleep(.8) diff --git a/gooey/examples/gooey_config.json b/gooey/examples/gooey_config.json index 5e56610..841f19f 100644 --- a/gooey/examples/gooey_config.json +++ b/gooey/examples/gooey_config.json @@ -1,41 +1,208 @@ { + "num_optional_cols": 2, + "num_required_cols": 2, "show_advanced": true, + "program_name": "widget_demo", + "target": "python c:\\users\\chris\\appdata\\local\\temp\\tmpwkcm2q.py", "language": "english", "manual_start": false, - "optionals_cols": 3, - "required": [ + "show_config": true, + "default_size": [ + 610, + 530 + ], + "widgets": [ + { + "data": { + "nargs": "", + "commands": [], + "display_name": "FileChooser", + "help": "Name of the file you want to process", + "choices": [] + }, + "required": true, + "type": "FileChooser" + }, { "data": { - "nargs": "+", + "nargs": "", "commands": [], - "display_name": "integers", - "help": "an integer for the accumulator", + "display_name": "MultiFileSaver", + "help": "Name of the file you want to process", + "choices": [] + }, + "required": true, + "type": "MultiFileChooser" + }, + { + "data": { + "nargs": "", + "commands": [ + "-d", + "--duration" + ], + "display_name": "duration", + "help": "Duration (in seconds) of the program output", "choices": [] }, + "required": false, "type": "TextField" - } - ], - "requireds_cols": 1, - "show_config": true, - "default_size": [ - 610, - 530 - ], - "optional": [ + }, + { + "data": { + "nargs": "", + "commands": [ + "-s", + "--cron-schedule" + ], + "display_name": "cron_schedule", + "help": "datetime when the cron should begin", + "choices": [] + }, + "required": false, + "type": "DateChooser" + }, { "data": { "nargs": "", "commands": [ - "--sum" + "-c", + "--showtime" ], - "display_name": "accumulate", - "help": "sum the integers (default: find the max)", + "display_name": "showtime", + "help": "display the countdown timer", "choices": [] }, + "required": false, "type": "CheckBox" + }, + { + "data": { + "nargs": "", + "commands": [ + "-p", + "--pause" + ], + "display_name": "pause", + "help": "Pause execution", + "choices": [] + }, + "required": false, + "type": "CheckBox" + }, + { + "data": { + "nargs": "", + "commands": [ + "-v", + "--verbose" + ], + "display_name": "verbose", + "help": null, + "choices": [] + }, + "required": false, + "type": "Dropdown", + "choices": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10 + ] + }, + { + "data": { + "nargs": "", + "commands": [ + "-o", + "--overwrite" + ], + "display_name": "overwrite", + "help": "Overwrite output file (if present)", + "choices": [] + }, + "required": false, + "type": "CheckBox" + }, + { + "data": { + "nargs": "", + "commands": [ + "-r", + "--recursive" + ], + "display_name": "recursive", + "help": "Recurse into subfolders", + "choices": [ + "yes", + "no" + ] + }, + "required": false, + "type": "Dropdown" + }, + { + "data": { + "nargs": "", + "commands": [ + "-w", + "--writelog" + ], + "display_name": "writelog", + "help": "Dump output to local file", + "choices": [] + }, + "required": false, + "type": "TextField" + }, + { + "data": { + "nargs": "", + "commands": [ + "-e", + "--error" + ], + "display_name": "error", + "help": "Stop process on error (default: No)", + "choices": [] + }, + "required": false, + "type": "CheckBox" + }, + { + "data": [ + { + "nargs": "", + "commands": [ + "-t", + "--verbozze" + ], + "display_name": "verbose", + "help": "Show more details", + "choices": null + }, + { + "nargs": "", + "commands": [ + "-q", + "--quiet" + ], + "display_name": "quiet", + "help": "Only output on error", + "choices": null + } + ], + "required": false, + "type": "RadioGroup", + "group_name": "Choose Option" } ], - "program_name": "tmpewuheq", - "program_description": "Process some integers.", - "target": "python c:\\users\\chris\\appdata\\local\\temp\\tmpewuheq.py" + "layout_type": "standard", + "program_description": "Example application to show Gooey's various widgets" } \ No newline at end of file diff --git a/gooey/examples/mock_argparse_example.py b/gooey/examples/minimal_demo.py similarity index 100% rename from gooey/examples/mock_argparse_example.py rename to gooey/examples/minimal_demo.py diff --git a/gooey/examples/mockapp_import_argparse.py b/gooey/examples/mockapp_import_argparse.py deleted file mode 100644 index 844b4ba..0000000 --- a/gooey/examples/mockapp_import_argparse.py +++ /dev/null @@ -1,51 +0,0 @@ -''' -Created on Dec 21, 2013 - -@author: Chris -''' -import sys -import hashlib -from time import time as _time -from time import sleep as _sleep -import argparse - -from gooey import Gooey - - -@Gooey -def main(): - my_cool_parser = argparse.ArgumentParser(description="Mock application to test Gooey's functionality") - my_cool_parser.add_argument("filename", help="Name of the file you want to read") # positional - my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output") # positional - my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from') - my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer") - my_cool_parser.add_argument("-d", "--delay", action="store_true", help="Delay execution for a bit") - my_cool_parser.add_argument('--verbose', '-v', action='count') - my_cool_parser.add_argument("-o", "--obfuscate", action="store_true", help="obfuscate the countdown timer!") - my_cool_parser.add_argument('-r', '--recursive', choices=['yes', 'no'], help='Recurse into subfolders') - my_cool_parser.add_argument("-w", "--writelog", default="No, NOT whatevs", help="write log to some file or something") - my_cool_parser.add_argument("-e", "--expandAll", action="store_true", help="expand all processes") - - print 'inside of main(), my_cool_parser =', my_cool_parser - args = my_cool_parser.parse_args() - - print sys.argv - print args.countdown - print args.showtime - - start_time = _time() - print 'Counting down from %s' % args.countdown - while _time() - start_time < args.countdown: - if args.showtime: - print 'printing message at: %s' % _time() - else: - print 'printing message at: %s' % hashlib.md5(str(_time())).hexdigest() - _sleep(.5) - print 'Finished running the program. Byeeeeesss!' - -# raise ValueError("Something has gone wrong! AHHHHHHHHHHH") - -if __name__ == '__main__': - # sys.argv.extend('asdf -c 5 -s'.split()) - # print sys.argv - main() \ No newline at end of file diff --git a/gooey/examples/subparser_demo.py b/gooey/examples/subparser_demo.py new file mode 100644 index 0000000..6b2448d --- /dev/null +++ b/gooey/examples/subparser_demo.py @@ -0,0 +1,92 @@ +""" +Example program to demonstrate Gooey's presentation of subparsers +""" + +import argparse + +from gooey import Gooey, GooeyParser + +running = True + + +@Gooey(optional_cols=2) +def main(): + settings_msg = 'Subparser example demonstating bundled configurations ' \ + 'for Siege, Curl, and FFMPEG' + parser = GooeyParser(description=settings_msg) + parser.add_argument('--verbose', help='be verbose', dest='verbose', + action='store_true', default=False) + subs = parser.add_subparsers(help='commands', dest='command') + + curl_parser = subs.add_parser('curl', help='curl is a tool to transfer data from or to a server') + curl_parser.add_argument('Path', + help='URL to the remote server', + type=str, widget='FileChooser') + curl_parser.add_argument('--connect-timeout', + help='Maximum time in seconds that you allow curl\'s connection to take') + curl_parser.add_argument('--user-agent', + help='Specify the User-Agent string ') + curl_parser.add_argument('--cookie', + help='Pass the data to the HTTP server as a cookie') + curl_parser.add_argument('--dump-header', type=argparse.FileType, + help='Write the protocol headers to the specified file') + curl_parser.add_argument('--progress-bar', action="store_true", + help='Make curl display progress as a simple progress bar') + curl_parser.add_argument('--http2', action="store_true", + help='Tells curl to issue its requests using HTTP 2') + curl_parser.add_argument('--ipv4', action="store_true", + help=' resolve names to IPv4 addresses only') + + + + # ######################################################## + siege_parser = subs.add_parser('siege', help='Siege is an http/https regression testing and benchmarking utility') + siege_parser.add_argument('--get', + help='Pull down headers from the server and display HTTP transaction', + type=str) + siege_parser.add_argument('--concurrent', + help='Stress the web server with NUM number of simulated users', + type=int) + siege_parser.add_argument('--time', + help='allows you to run the test for a selected period of time', + type=int) + siege_parser.add_argument('--delay', + help='simulated user is delayed for a random number of seconds between one and NUM', + type=int) + siege_parser.add_argument('--message', + help='mark the log file with a separator', + type=int) + + + # ######################################################## + ffmpeg_parser = subs.add_parser('ffmpeg', help='Siege is an http/https regression testing and benchmarking utility') + ffmpeg_parser.add_argument('Output', + help='Pull down headers from the server and display HTTP transaction', + widget='FileSaver') + ffmpeg_parser.add_argument('--bitrate', + help='set the video bitrate in kbit/s (default = 200 kb/s)', + type=str) + ffmpeg_parser.add_argument('--fps', + help='set frame rate (default = 25)', + type=str) + ffmpeg_parser.add_argument('--size', + help='set frame size. The format is WxH (default 160x128)', + type=str) + ffmpeg_parser.add_argument('--aspect', + help='set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)', + type=str) + ffmpeg_parser.add_argument('--tolerance', + help='set video bitrate tolerance (in kbit/s)', + type=str) + ffmpeg_parser.add_argument('--maxrate', + help='set min video bitrate tolerance (in kbit/s)', + type=str) + ffmpeg_parser.add_argument('--bufsize', + help='set ratecontrol buffere size (in kbit)', + type=str) + + parser.parse_args() + + +if __name__ == '__main__': + main() diff --git a/gooey/examples/widget_demo.py b/gooey/examples/widget_demo.py index e0e8e5e..2d53d57 100644 --- a/gooey/examples/widget_demo.py +++ b/gooey/examples/widget_demo.py @@ -3,6 +3,7 @@ Created on Dec 21, 2013 @author: Chris ''' + import sys import hashlib from time import time as _time @@ -11,52 +12,67 @@ from time import sleep as _sleep from gooey import Gooey from gooey import GooeyParser +welcome_message = \ +r''' + __ __ _ + \ \ / / | | + \ \ /\ / /__| | ___ ___ _ __ ___ ___ + \ \/ \/ / _ \ |/ __/ _ \| '_ ` _ \ / _ \ + \ /\ / __/ | (_| (_) | | | | | | __/ + ___\/__\/ \___|_|\___\___/|_| |_| |_|\___| + |__ __| + | | ___ + | |/ _ \ + | | (_) | + _|_|\___/ _ _ + / ____| | | | + | | __ ___ ___ ___ _ _| | | + | | |_ |/ _ \ / _ \ / _ \ | | | | | + | |__| | (_) | (_) | __/ |_| |_|_| + \_____|\___/ \___/ \___|\__, (_|_) + __/ | + |___/ +''' - -@Gooey +@Gooey(dump_build_config=True) def arbitrary_function(): desc = "Example application to show Gooey's various widgets" file_help_msg = "Name of the file you want to process" my_cool_parser = GooeyParser(description=desc) my_cool_parser.add_argument("FileChooser", help=file_help_msg, widget="FileChooser") # positional - my_cool_parser.add_argument("DirectoryChooser", help=file_help_msg, widget="DirChooser") # positional - my_cool_parser.add_argument("FileSaver", help=file_help_msg, widget="FileSaver") # positional + # my_cool_parser.add_argument("DirectoryChooser", help=file_help_msg, widget="DirChooser") # positional + # my_cool_parser.add_argument("FileSaver", help=file_help_msg, widget="FileSaver") # positional my_cool_parser.add_argument("MultiFileSaver", help=file_help_msg, widget="MultiFileChooser") # positional - my_cool_parser.add_argument("directory", help="Directory to store output") # positional + # my_cool_parser.add_argument("directory", help="Directory to store output") # positional - my_cool_parser.add_argument('-c', '--countdown', default=2, type=int, help='sets the time to count down from you see its quite simple!') - my_cool_parser.add_argument('-j', '--cron-schedule', type=int, help='Set the datetime when the cron should begin', widget='DateChooser') - my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer") - my_cool_parser.add_argument("-d", "--delay", action="store_true", help="Delay execution for a bit") + my_cool_parser.add_argument('-d', '--duration', default=2, type=int, help='Duration (in seconds) of the program output') + my_cool_parser.add_argument('-s', '--cron-schedule', type=int, help='datetime when the cron should begin', widget='DateChooser') + my_cool_parser.add_argument("-c", "--showtime", action="store_true", help="display the countdown timer") + my_cool_parser.add_argument("-p", "--pause", action="store_true", help="Pause execution") my_cool_parser.add_argument('-v', '--verbose', action='count') - my_cool_parser.add_argument("-o", "--obfuscate", action="store_true", help="obfuscate the countdown timer!") + my_cool_parser.add_argument("-o", "--overwrite", action="store_true", help="Overwrite output file (if present)") my_cool_parser.add_argument('-r', '--recursive', choices=['yes', 'no'], help='Recurse into subfolders') - my_cool_parser.add_argument("-w", "--writelog", default="No, NOT whatevs", help="write log to some file or something") - my_cool_parser.add_argument("-e", "--expandAll", action="store_true", help="expand all processes") + my_cool_parser.add_argument("-w", "--writelog", default="writelogs", help="Dump output to local file") + my_cool_parser.add_argument("-e", "--error", action="store_true", help="Stop process on error (default: No)") verbosity = my_cool_parser.add_mutually_exclusive_group() verbosity.add_argument('-t', '--verbozze', dest='verbose', action="store_true", help="Show more details") verbosity.add_argument('-q', '--quiet', dest='quiet', action="store_true", help="Only output on error") - print my_cool_parser._actions - print 'inside of main(), my_cool_parser =', my_cool_parser + # print my_cool_parser._actions + # print 'inside of main(), my_cool_parser =', my_cool_parser args = my_cool_parser.parse_args() main(args) def main(args): - print sys.argv - print args.countdown - print args.showtime + message = welcome_message.split('\n') - start_time = _time() - print 'Counting down from %s' % args.countdown - while _time() - start_time < args.countdown: - if args.showtime: - print 'printing message at: %s' % _time() - else: - print 'printing message at: %s' % hashlib.md5(str(_time())).hexdigest() - _sleep(.5) - print 'Finished running the program. Byeeeeesss!' + delay = float(args.duration) / len(message) + print('Printing welcome message over a period of %s seconds' % args.duration) + for line in message: + print line + _sleep(delay) + print('All done!') def here_is_smore(): pass