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