Checking box closer to working.
[zeroinstall/zeroinstall-rsl.git] / zeroinstall / 0launch-gui / mainwindow.py
blob3e125893c7fea7dfd8ebf9c675f81c26d96980e2
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")
77 yield task.finished
78 tasks.check(task.finished)
80 if policy.get_uncached_implementations():
81 dialog.alert('Not all downloads succeeded; cannot run program.')
82 else:
83 from zeroinstall.injector import selections
84 sels = selections.Selections(policy)
85 doc = sels.toDOM()
86 reply = doc.toxml('utf-8')
87 sys.stdout.write(('Length:%8x\n' % len(reply)) + reply)
88 self.window.destroy()
89 sys.exit(0) # Success
91 gui_help = help_box.HelpBox("Injector Help",
92 ('Overview', """
93 A program is made up of many different components, typically written by different \
94 groups of people. Each component is available in multiple versions. The injector is \
95 used when starting a program. Its job is to decide which implementation of each required \
96 component to use.
98 An interface describes what a component does. The injector starts with \
99 the interface for the program you want to run (like 'The Gimp') and chooses an \
100 implementation (like 'The Gimp 2.2.0'). However, this implementation \
101 will in turn depend on other interfaces, such as 'GTK' (which draws the menus \
102 and buttons). Thus, the injector must choose implementations of \
103 each dependency (each of which may require further interfaces, and so on)."""),
105 ('List of interfaces', """
106 The main window displays all these interfaces, and the version of each chosen \
107 implementation. The top-most one represents the program you tried to run, and each direct \
108 child is a dependency. The 'Fetch' column shows the amount of data that needs to be \
109 downloaded, or '(cached)' if it is already on this computer.
111 If you are happy with the choices shown, click on the Download (or Run) button to \
112 download (and run) the program."""),
114 ('Choosing different versions', """
115 To control which implementations (versions) are chosen you can click on Preferences \
116 and adjust the network policy and the overall stability policy. These settings affect \
117 all programs run using Zero Install.
119 Alternatively, you can edit the policy of an individual interface by selecting it \
120 and clicking on the 'Interface Properties' button. \
121 See that dialog's help text for more information.
123 Right-click on an interface in the list for a menu.
124 """),
126 ('Reporting bugs', """
127 To report a bug, right-click over the interface which you think contains the problem \
128 and choose 'Report a Bug...' from the menu. If you don't know which one is the cause, \
129 choose the top one (i.e. the program itself). The program's author can reassign the \
130 bug if necessary, or switch to using a different version of the library.
131 """),
133 ('The cache', """
134 Each version of a program that is downloaded is stored in the Zero Install cache. This \
135 means that it won't need to be downloaded again each time you run the program. Click on \
136 the 'Show Cache' button to see what is currently in the cache, or to remove versions \
137 you no longer need to save disk space."""),