More refactoring.
[zeroinstall.git] / mainwindow.py
blobc735413561e59471b02731d3adff950af98f9060
1 import gtk
2 from iface_browser import InterfaceBrowser
3 import help_box
4 from gui import policy
5 from dialog import Dialog
6 from model import stable, testing, network_levels, SafeException
8 class MainWindow(Dialog):
9 label = None
10 browser = None
12 def __init__(self, prog, prog_args):
13 Dialog.__init__(self)
14 self.set_title('Dependency Injector')
15 self.set_default_size(400, 300)
17 tips = gtk.Tooltips()
19 # Message
20 self.label = gtk.Label('Initialising...')
21 self.vbox.pack_start(self.label, False, True, 0)
22 self.label.set_padding(8, 8)
23 self.label.show()
25 # Network use
26 hbox = gtk.HBox(False, 2)
27 self.vbox.pack_start(hbox, False, True, 0)
28 hbox.set_border_width(4)
30 network = gtk.combo_box_new_text()
31 for level in network_levels:
32 network.append_text(level.capitalize())
33 network.set_active(list(network_levels).index(policy.network_use))
34 hbox.pack_start(gtk.Label('Network use:'), False, True, 0)
35 hbox.pack_start(network, False, True, 2)
36 def set_network_use(combo):
37 policy.network_use = network_levels[network.get_active()]
38 policy.save_config()
39 policy.recalculate()
40 network.connect('changed', set_network_use)
42 hbox.show_all()
44 # Tree view
45 self.browser = InterfaceBrowser()
46 self.vbox.pack_start(self.browser, True, True, 0)
47 self.browser.show()
49 # Select versions
50 hbox = gtk.HBox(False, 2)
51 self.vbox.pack_start(hbox, False, True, 0)
52 hbox.set_border_width(4)
54 button = gtk.Button()
55 self.browser.edit_properties.connect_proxy(button)
56 hbox.pack_start(button, False, True, 0)
58 stable_toggle = gtk.CheckButton('Help test new versions')
59 hbox.pack_start(stable_toggle, False, True, 0)
60 tips.set_tip(stable_toggle,
61 "Try out new versions as soon as they are available, instead of "
62 "waiting for them to be marked as 'stable'. "
63 "This sets the default policy. Click on 'Interface Properties...' "
64 "to set the policy for an individual interface.")
65 stable_toggle.set_active(policy.help_with_testing)
66 def toggle_stability(toggle):
67 policy.help_with_testing = toggle.get_active()
68 policy.save_config()
69 policy.recalculate()
70 stable_toggle.connect('toggled', toggle_stability)
72 hbox.show_all()
74 # Responses
76 self.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
77 self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
78 self.add_button(gtk.STOCK_EXECUTE, gtk.RESPONSE_OK)
79 self.set_default_response(gtk.RESPONSE_OK)
81 def response(dialog, resp):
82 if resp == gtk.RESPONSE_CANCEL:
83 self.destroy()
84 elif resp == gtk.RESPONSE_OK:
85 import run
86 try:
87 run.execute(policy, prog, prog_args)
88 self.destroy()
89 except SafeException, ex:
90 box = gtk.MessageDialog(self, gtk.DIALOG_MODAL,
91 gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
92 str(ex))
93 box.run()
94 box.destroy()
95 elif resp == gtk.RESPONSE_HELP:
96 gui_help.display()
97 self.connect('response', response)
99 gui_help = help_box.HelpBox("Injector Help",
100 ('Overview', """
101 A program is made up of many different components, typically written by different \
102 groups of people. Each component is available in multiple versions. The injector is \
103 used when starting a program. Its job is to decide which implementation of each required \
104 component to use.
106 An interface describes what a component does. The injector starts with \
107 the interface for the program you want to run (like 'The Gimp') and chooses an \
108 implementation (like 'The Gimp 2.2.0'). However, this implementation \
109 will in turn depend on other interfaces, such as 'GTK' (which draws the menus \
110 and buttons). Thus, the injector must choose implementations of \
111 each dependancy (each of which may require further interfaces, and so on)."""),
113 ('List of interfaces', """
114 The main window displays all these interfaces, and the version of each chosen \
115 implementation. The top-most one represents the program you tried to run, and each direct \
116 child is a dependancy.
118 If you are happy with the choices shown, click on the Execute button to run the \
119 program."""),
121 ('Choosing different versions', """
122 There are three ways to control which implementations are chosen. You can adjust the \
123 network policy and the overall stability policy, which affect all interfaces, or you \
124 can edit the policy of individual interfaces.
126 The 'Network use' option controls how the injector uses the network. If off-line, \
127 the network is not used at all. If 'Minimal' is selected then the injector will use \
128 the network if needed, but only if it has no choice. It will run an out-of-date \
129 version rather than download a newer one. If 'Full' is selected, the injector won't \
130 worry about how much it downloads, but will always pick the version it thinks is best.
132 The overall stability policy can either be to prefer stable versions, or to help test \
133 new versions. Choose whichever suits you. Since different programmers have different \
134 ideas of what 'stable' means, you may wish to override this on a per-interface basis \
135 (see below).
137 To set the policy for an interface individually, select it and click on 'Interface \
138 Properties'. See that dialog's help text for more information."""))