home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / gnome-applets / invest-applet < prev    next >
Encoding:
Text File  |  2007-03-12  |  2.5 KB  |  99 lines

  1. #!/usr/bin/env python
  2. #
  3.  
  4. import gobject
  5. import gtk, gnomeapplet
  6.  
  7. import getopt, sys
  8. from os.path import *
  9.  
  10. # Allow to use uninstalled
  11. def _check(path):
  12.     return exists(path) and isdir(path) and isfile(path+"/ChangeLog")
  13.  
  14. name = join(dirname(__file__), '..')
  15. if _check(name):
  16.     print 'Running uninstalled invest, modifying PYTHONPATH'
  17.     sys.path.insert(0, abspath(name))
  18. else:
  19.     sys.path.insert(0, abspath("/usr/lib/python2.5/site-packages/"))
  20.     print "Running installed invest, using [/usr/lib/python2.5/site-packages/:$PYTHONPATH]"
  21.  
  22. # Now the path is set, import our applet
  23. import invest, invest.applet, invest.defs
  24.  
  25. # Prepare i18n
  26. import gettext, locale
  27. gettext.bindtextdomain(invest.defs.GETTEXT_PACKAGE, invest.defs.GNOMELOCALEDIR)
  28. gettext.textdomain(invest.defs.GETTEXT_PACKAGE)
  29. locale.bindtextdomain(invest.defs.GETTEXT_PACKAGE, invest.defs.GNOMELOCALEDIR)
  30. locale.textdomain(invest.defs.GETTEXT_PACKAGE)
  31. gtk.glade.bindtextdomain(invest.defs.GETTEXT_PACKAGE, invest.defs.GNOMELOCALEDIR)
  32. gtk.glade.textdomain(invest.defs.GETTEXT_PACKAGE)
  33.  
  34. from gettext import gettext as _
  35.  
  36. def applet_factory(applet, iid):
  37.     print 'Starting invest instance:', applet, iid
  38.     invest.applet.InvestApplet(applet)
  39.     return True
  40.  
  41. # Return a standalone window that holds the applet
  42. def build_window():
  43.     app = gtk.Window(gtk.WINDOW_TOPLEVEL)
  44.     app.set_title(_("Invest Applet"))
  45.     app.connect("destroy", gtk.main_quit)
  46.     app.set_property('resizable', False)
  47.     
  48.     applet = gnomeapplet.Applet()
  49.     applet_factory(applet, None)
  50.     applet.reparent(app)
  51.         
  52.     app.show_all()
  53.     
  54.     return app
  55.         
  56.         
  57. def usage():
  58.     print """=== Invest applet: Usage
  59. $ invest-applet [OPTIONS]
  60.  
  61. OPTIONS:
  62.     -h, --help            Print this help notice.
  63.     -d, --debug            Enable debug output (default=off).
  64.     -w, --window        Launch the applet in a standalone window for test purposes (default=no).
  65.     """
  66.     sys.exit()
  67.     
  68. if __name__ == "__main__":    
  69.     standalone = False
  70.     
  71.     try:
  72.         opts, args = getopt.getopt(sys.argv[1:], "hdw", ["help", "debug", "window"])
  73.     except getopt.GetoptError:
  74.         # Unknown args were passed, we fallback to bahave as if
  75.         # no options were passed
  76.         opts = []
  77.         args = sys.argv[1:]
  78.     
  79.     for o, a in opts:
  80.         if o in ("-h", "--help"):
  81.             usage()
  82.         elif o in ("-d", "--debug"):
  83.             print "No problems so far."
  84.         elif o in ("-w", "--window"):
  85.             standalone = True
  86.             
  87.     if standalone:
  88.         import gnome
  89.         gnome.init(invest.defs.PACKAGE, invest.defs.VERSION)
  90.         build_window()
  91.         gtk.main()
  92.     else:
  93.         gnomeapplet.bonobo_factory(
  94.             "OAFIID:Invest_Applet_Factory",
  95.             gnomeapplet.Applet.__gtype__,
  96.             invest.defs.PACKAGE,
  97.             invest.defs.VERSION,
  98.             applet_factory)
  99.