Added "0install apps"
[zeroinstall.git] / zeroinstall / gtkui / desktop.py
blob7b480c6d22eb8c3bc72e355dfa6ac677e204acf7
1 """Code for the B{0desktop} command."""
3 # Copyright (C) 2009, Thomas Leonard
4 # See the README file for details, or visit http://0install.net.
6 from __future__ import print_function
8 from zeroinstall import _, logger
9 import sys
10 from optparse import OptionParser
11 import logging
13 def main(command_args):
14 """Implements the logic of the 0desktop command.
15 @param command_args: the command-line arguments"""
16 parser = OptionParser(usage=_("usage: %prog [options] [URI]"))
17 parser.add_option("-m", "--manage", help=_("manage added applications"), action='store_true')
18 parser.add_option("-v", "--verbose", help=_("more verbose output"), action='count')
19 parser.add_option("-V", "--version", help=_("display version information"), action='store_true')
21 (options, args) = parser.parse_args(command_args)
23 if options.verbose:
24 if options.verbose == 1:
25 logger.setLevel(logging.INFO)
26 else:
27 logger.setLevel(logging.DEBUG)
28 hdlr = logging.StreamHandler()
29 fmt = logging.Formatter("%(levelname)s:%(message)s")
30 hdlr.setFormatter(fmt)
31 logger.addHandler(hdlr)
33 if options.version:
34 import zeroinstall
35 print("0desktop (zero-install) " + zeroinstall.version)
36 print("Copyright (C) 2012 Thomas Leonard")
37 print(_("This program comes with ABSOLUTELY NO WARRANTY,"
38 "\nto the extent permitted by law."
39 "\nYou may redistribute copies of this program"
40 "\nunder the terms of the GNU Lesser General Public License."
41 "\nFor more information about these matters, see the file named COPYING."))
42 sys.exit(0)
44 if not args:
45 interface_uri = None
46 elif len(args) == 1:
47 interface_uri = args[0]
48 else:
49 parser.print_help()
50 sys.exit(1)
52 import pygtk; pygtk.require('2.0')
53 import gtk
55 if options.manage:
56 from zeroinstall.gtkui.applistbox import AppListBox, AppList
57 from zeroinstall.injector.iface_cache import iface_cache
58 box = AppListBox(iface_cache, AppList())
59 else:
60 from zeroinstall.gtkui.addbox import AddBox
61 box = AddBox(interface_uri)
63 box.window.connect('destroy', gtk.main_quit)
64 box.window.show()
65 gtk.main()