|
|
Welcome to optparse_gui!
What is optparse_gui?
optparse_gui is a python module which can be described simply by: import optparse_gui as optparse
optparse_gui is a drop-in replacement for optparse. It allows entering command line arguments in a dynamically generated wx-based dialog.
optparse is a great built-in python module for parsing command line arguments. see http://docs.python.org/lib/module-optparse.html for more info.
Features
| optparse_gui generates the dialog depending on the provided optparse options: CheckBox for boolean options, ComboBox for "choice" options, TextCtrl for all other options. An extra TextCtrl for entering non-option command line arguments. Also, the dialog contains context-sensitive help for every option. |
Ever wanted to transparently add a GUI to your command-line driven python scripts? This is the module for you.
How to use it?
Like the title says - simply "import optparse_gui as optparse"
A more elaborate use case might be to use optparse_gui when the application is ran with no command line arguments ( i.e. a double-click on the module's icon ), but use the original optparse to handle the command line arguments if they are given.
That way, a user can drive your app using a GUI, and yet - the app can be automated by passing command line arguments.
Here is a sample( this is what you see in the screen-shot above ):
import sys
import optparse
import optparse_gui
def main():
usage = "usage: %prog [options] args"
if 1 == len( sys.argv ):
option_parser_class = optparse_gui.OptionParser
else:
option_parser_class = optparse.OptionParser
parser = option_parser_class( usage = usage, version='0.1' )
parser.add_option("-f", "--file", dest="filename", default = r'c:\sample.txt',
help="read data from FILENAME")
parser.add_option("-a", "--action", dest="action",
choices = ['delete', 'copy', 'move'],
help="Which action do you wish to take?!")
parser.add_option("-n", "--number", dest="number", default = 23,
type = 'int',
help="Just a number")
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose",
help = 'To be or not to be? ( verbose )')
options, args = parser.parse_args()
print 'args: %s' % args
print 'options: %s' % options
if '__main__' == __name__:
main()
