faqts : Computers : Programming : Languages : Python : gnome-python(and PyGTK)

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 10 people (90%) answered Yes
Recently 6 of 6 people (100%) answered Yes

Entry

How do I handle command line args with gnome?

May 31st, 2001 21:41
Fred Drake, Joseph VanAndel, frederic.gedin@free.fr


You need to remove from sys.argv the options you processed before
invoking the command line option parser from gnome.  E.g:
import sys,getopt
usageStr =\
"""-i input_dir [-o output_dir]  -r [-- gnome_args]
   -r specifies real_time mode (default is batch processing)
         """
# we have to parse arguments before importing gnome.ui, which also wants
# to parse arguments.  
if __name__ == "__main__":
    global optlist 
    try:
        optlist, args = getopt.getopt(sys.argv[1:], 'i:o:r')
    except getopt.error, what:
        print what
        print __doc__
        print 'usage : %s %s' % (sys.argv[0], usageStr)
        sys.exit(-1)    
    # pass remaining arguments to gnome.ui
    sys.argv = [sys.argv[0]]
    for a in args:
        sys.argv.append(a)
from gnome.ui  import *
from gtk import * 
from gnome.config import *
# Applications arguments can now be processed from 'optlist'.