Better error handling.
[zeroinstall/zeroinstall-mseaborn.git] / zeroinstall / 0launch-gui / mainwindow.py
blobe53e1c6345cd62a8d80b4a52180f97e5964c3ef2
1 import gtk
2 from logging import warn
3 import os, sys
4 from zeroinstall import SafeException
5 from zeroinstall.support import tasks
6 from iface_browser import InterfaceBrowser
7 import help_box
8 from gui import policy
9 import dialog
11 tips = gtk.Tooltips()
13 SHOW_PREFERENCES = 0
15 class MainWindow:
16 progress = None
17 browser = None
18 window = None
20 def __init__(self, download_only):
21 widgets = policy.widgets
23 self.window = widgets.get_widget('main')
24 self.window.set_default_size(gtk.gdk.screen_width() * 2 / 5, 300)
26 self.progress = widgets.get_widget('progress')
28 self.window.connect('destroy', lambda w: self.destroyed())
30 cache = widgets.get_widget('show_cache')
31 cache.connect('clicked',
32 lambda b: os.spawnlp(os.P_WAIT, sys.argv[0], sys.argv[0], '-c'))
34 widgets.get_widget('refresh').connect('clicked', lambda b: policy.refresh_all())
36 # Tree view
37 self.browser = InterfaceBrowser(widgets.get_widget('components'))
39 prefs = widgets.get_widget('preferences')
40 self.window.action_area.set_child_secondary(prefs, True)
42 if download_only:
43 unused = widgets.get_widget('run').hide()
44 else:
45 unused = widgets.get_widget('download').hide()
47 self.window.set_default_response(gtk.RESPONSE_OK)
48 self.window.default_widget.grab_focus()
50 def response(dialog, resp):
51 if resp in (gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT):
52 self.window.destroy()
53 sys.exit(1)
54 elif resp == gtk.RESPONSE_OK:
55 task = tasks.Task(self.download_and_run(), "download and run")
56 elif resp == gtk.RESPONSE_HELP:
57 gui_help.display()
58 elif resp == SHOW_PREFERENCES:
59 import preferences
60 preferences.show_preferences()
61 self.window.connect('response', response)
63 def destroy(self):
64 self.window.destroy()
66 def show(self):
67 self.window.show()
69 def set_response_sensitive(self, response, sensitive):
70 self.window.set_response_sensitive(response, sensitive)
72 def destroyed(self):
73 policy.abort_all_downloads()
75 def download_and_run(self):
76 try:
77 task = tasks.Task(policy.download_impls(), "download implementations")
79 yield task.finished
81 tasks.check(task.finished)
83 if policy.get_uncached_implementations():
84 dialog.alert('Not all downloads succeeded; cannot run program.')
85 else:
86 from zeroinstall.injector import selections
87 sels = selections.Selections(policy)
88 doc = sels.toDOM()
89 reply = doc.toxml('utf-8')
90 sys.stdout.write(('Length:%8x\n' % len(reply)) + reply)
91 self.window.destroy()
92 sys.exit(0) # Success
93 except SafeException, ex:
94 policy.handler.report_error(ex)
95 except Exception, ex:
96 import traceback
97 traceback.print_exc()
98 policy.handler.report_error(ex)
100 gui_help = help_box.HelpBox("Injector Help",
101 ('Overview', """
102 A program is made up of many different components, typically written by different \
103 groups of people. Each component is available in multiple versions. The injector is \
104 used when starting a program. Its job is to decide which implementation of each required \
105 component to use.
107 An interface describes what a component does. The injector starts with \
108 the interface for the program you want to run (like 'The Gimp') and chooses an \
109 implementation (like 'The Gimp 2.2.0'). However, this implementation \
110 will in turn depend on other interfaces, such as 'GTK' (which draws the menus \
111 and buttons). Thus, the injector must choose implementations of \
112 each dependency (each of which may require further interfaces, and so on)."""),
114 ('List of interfaces', """
115 The main window displays all these interfaces, and the version of each chosen \
116 implementation. The top-most one represents the program you tried to run, and each direct \
117 child is a dependency. The 'Fetch' column shows the amount of data that needs to be \
118 downloaded, or '(cached)' if it is already on this computer.
120 If you are happy with the choices shown, click on the Download (or Run) button to \
121 download (and run) the program."""),
123 ('Choosing different versions', """
124 To control which implementations (versions) are chosen you can click on Preferences \
125 and adjust the network policy and the overall stability policy. These settings affect \
126 all programs run using Zero Install.
128 Alternatively, you can edit the policy of an individual interface by selecting it \
129 and clicking on the 'Interface Properties' button. \
130 See that dialog's help text for more information.
132 Right-click on an interface in the list for a menu.
133 """),
135 ('Reporting bugs', """
136 To report a bug, right-click over the interface which you think contains the problem \
137 and choose 'Report a Bug...' from the menu. If you don't know which one is the cause, \
138 choose the top one (i.e. the program itself). The program's author can reassign the \
139 bug if necessary, or switch to using a different version of the library.
140 """),
142 ('The cache', """
143 Each version of a program that is downloaded is stored in the Zero Install cache. This \
144 means that it won't need to be downloaded again each time you run the program. Click on \
145 the 'Show Cache' button to see what is currently in the cache, or to remove versions \
146 you no longer need to save disk space."""),