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