Use iface_cache interface directly.
[zeroinstall.git] / mainwindow.py
blob96ffd9ee03113cf3eb03db4f5af8964ffe5ce302
1 import gtk
2 import sys
3 from iface_browser import InterfaceBrowser
4 import help_box
5 from gui import policy
6 from dialog import Dialog
7 from zeroinstall.injector.model import stable, testing, network_levels, SafeException
8 from freshness import freshness_levels, Freshness
10 class MainWindow(Dialog):
11 progress = None
12 browser = None
14 def __init__(self, prog_args, download_only):
15 Dialog.__init__(self)
16 self.set_title('Dependency Injector')
17 self.set_default_size(gtk.gdk.screen_width() / 3, 300)
19 tips = gtk.Tooltips()
21 # Network use
22 hbox = gtk.HBox(False, 2)
23 self.vbox.pack_start(hbox, False, True, 0)
24 hbox.set_border_width(4)
26 network = gtk.combo_box_new_text()
27 for level in network_levels:
28 network.append_text(level.capitalize())
29 network.set_active(list(network_levels).index(policy.network_use))
30 hbox.pack_start(gtk.Label('Network use:'), False, True, 0)
31 hbox.pack_start(network, True, True, 2)
32 def set_network_use(combo):
33 policy.network_use = network_levels[network.get_active()]
34 policy.save_config()
35 policy.recalculate()
36 network.connect('changed', set_network_use)
38 hbox.show_all()
40 # Freshness
41 hbox = gtk.HBox(False, 2)
42 self.vbox.pack_start(hbox, False, True, 0)
43 hbox.set_border_width(4)
45 times = [x.time for x in freshness_levels]
46 if policy.freshness not in times:
47 freshness_levels.append(Freshness(policy.freshness,
48 '%d seconds' % policy.freshness))
49 times.append(policy.freshness)
50 freshness = gtk.combo_box_new_text()
51 for level in freshness_levels:
52 freshness.append_text(str(level))
53 freshness.set_active(times.index(policy.freshness))
54 hbox.pack_start(gtk.Label('Freshness:'), False, True, 0)
55 hbox.pack_start(freshness, True, True, 2)
56 def set_freshness(combo):
57 policy.freshness = freshness_levels[freshness.get_active()].time
58 policy.save_config()
59 policy.recalculate()
60 freshness.connect('changed', set_freshness)
62 button = gtk.Button('Refresh all now')
63 button.connect('clicked', lambda b: policy.refresh_all())
64 hbox.pack_start(button, False, True, 2)
66 hbox.show_all()
68 # Tree view
69 self.browser = InterfaceBrowser()
70 self.vbox.pack_start(self.browser, True, True, 0)
71 self.browser.show()
73 # Select versions
74 hbox = gtk.HBox(False, 2)
75 self.vbox.pack_start(hbox, False, True, 0)
76 hbox.set_border_width(4)
78 button = gtk.Button('Interface Properties...')
79 self.browser.edit_properties.connect_proxy(button)
80 hbox.pack_start(button, False, True, 0)
82 stable_toggle = gtk.CheckButton('Help test new versions')
83 hbox.pack_start(stable_toggle, False, True, 0)
84 tips.set_tip(stable_toggle,
85 "Try out new versions as soon as they are available, instead of "
86 "waiting for them to be marked as 'stable'. "
87 "This sets the default policy. Click on 'Interface Properties...' "
88 "to set the policy for an individual interface.")
89 stable_toggle.set_active(policy.help_with_testing)
90 def toggle_stability(toggle):
91 policy.help_with_testing = toggle.get_active()
92 policy.save_config()
93 policy.recalculate()
94 stable_toggle.connect('toggled', toggle_stability)
96 hbox.show_all()
98 # Progress bar
99 self.progress = gtk.ProgressBar()
100 self.vbox.pack_start(self.progress, False, True, 0)
102 # Responses
104 self.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
105 self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
106 if download_only:
107 self.add_mixed_button('Download', gtk.STOCK_NETWORK, gtk.RESPONSE_OK)
108 else:
109 self.add_button(gtk.STOCK_EXECUTE, gtk.RESPONSE_OK)
110 self.set_default_response(gtk.RESPONSE_OK)
112 def response(dialog, resp):
113 import download_box
114 if resp == gtk.RESPONSE_CANCEL:
115 self.destroy()
116 sys.exit(1)
117 elif resp == gtk.RESPONSE_OK:
118 download_box.download_with_gui(self, prog_args,
119 run_afterwards = not download_only)
120 elif resp == gtk.RESPONSE_HELP:
121 gui_help.display()
122 self.connect('response', response)
124 gui_help = help_box.HelpBox("Injector Help",
125 ('Overview', """
126 A program is made up of many different components, typically written by different \
127 groups of people. Each component is available in multiple versions. The injector is \
128 used when starting a program. Its job is to decide which implementation of each required \
129 component to use.
131 An interface describes what a component does. The injector starts with \
132 the interface for the program you want to run (like 'The Gimp') and chooses an \
133 implementation (like 'The Gimp 2.2.0'). However, this implementation \
134 will in turn depend on other interfaces, such as 'GTK' (which draws the menus \
135 and buttons). Thus, the injector must choose implementations of \
136 each dependancy (each of which may require further interfaces, and so on)."""),
138 ('List of interfaces', """
139 The main window displays all these interfaces, and the version of each chosen \
140 implementation. The top-most one represents the program you tried to run, and each direct \
141 child is a dependancy. The 'Fetch' column shows amount of data that needs to be \
142 downloaded, or '(cached)' if it is already on this computer.
144 If you are happy with the choices shown, click on the Download (or Execute) button to \
145 download (and run) the program."""),
147 ('Choosing different versions', """
148 There are three ways to control which implementations are chosen. You can adjust the \
149 network policy and the overall stability policy, which affect all interfaces, or you \
150 can edit the policy of individual interfaces.
152 The 'Network use' option controls how the injector uses the network. If off-line, \
153 the network is not used at all. If 'Minimal' is selected then the injector will use \
154 the network if needed, but only if it has no choice. It will run an out-of-date \
155 version rather than download a newer one. If 'Full' is selected, the injector won't \
156 worry about how much it downloads, but will always pick the version it thinks is best.
158 The overall stability policy can either be to prefer stable versions, or to help test \
159 new versions. Choose whichever suits you. Since different programmers have different \
160 ideas of what 'stable' means, you may wish to override this on a per-interface basis \
161 (see below).
163 To set the policy for an interface individually, select it and click on 'Interface \
164 Properties'. See that dialog's help text for more information."""),
166 ('Freshness', """
167 The interface files, which provide the information about which versions are \
168 available, are also cached. To update them, click on 'Refresh all now'. You can also \
169 get the injector to check for new versions automatically from time to time using \
170 the Freshness setting."""))