home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-gnome2 / examples / popt / popt.py
Encoding:
Python Source  |  2004-06-24  |  1.4 KB  |  38 lines

  1. #!/usr/bin/env python
  2. import pygtk; pygtk.require("2.0")
  3. import gnome
  4. import sys
  5. import gc
  6.  
  7. ## Notice that [] as default value (see --ddd example below) has a
  8. ## special meaning in gnome-python (unlike standard popt).  Usually,
  9. ## when multiple values are passed for the same option in the command
  10. ## line, only the last value is returned to the caller.  In contrast,
  11. ## if the programmer specifies [] as default value, then gnome-python
  12. ## will collect all option values into a list and return this list as
  13. ## value to the caller.
  14.  
  15. # (longName, shortName, type , default, flags, descrip , argDescrip)
  16. table=[("foo"  , 'f'   , int  ,   1     , 0    , "Foobar", "Level"),
  17.        ("aaa"  , 'a'   , str  ,   'a'   , 0    , 'aaa'   , "AAA"),
  18.        ("bbb"  , 'b'   , None ,   None  , 0    , 'bbb'   , "BBB"),
  19.        ("ccc"  , 'c'   , float,   2.5   , 0    , 'ccc'   , "BBB"),
  20.        ("ddd"  , 'd'   , long ,   []    , 0    , 'ddd'   , "DDD"),
  21.        ("eee"  , 'e'   , int,     2     , gnome.POPT_ARGFLAG_OR)
  22.        ]
  23.  
  24. prog = gnome.init ("myprog", "1.0", gnome.libgnome_module_info_get(),
  25.                    sys.argv, table)
  26.  
  27. print "parsing with gnome.init"
  28. leftover_args, argdict = prog.get_popt_args()
  29. print "Leftover: ", leftover_args
  30. print "Argdict: ", argdict
  31.  
  32. del prog; gc.collect()
  33.  
  34. print "parsing with gnome.pop_parse"
  35. leftover_args, argdict = gnome.popt_parse(sys.argv, table)
  36. print "Leftover: ", leftover_args
  37. print "Argdict: ", argdict
  38.