Added non-interactive injector-auto.
[zeroinstall.git] / injector-gui / properties.py
blob0ccce0fa118d6adda1d24c2d135cfb10e1e55981
1 from model import *
2 import gtk
4 import help_box
5 from dialog import Dialog
6 from policy import policy
7 from impl_list import ImplementationList
8 import writer
10 _dialogs = {} # Interface -> Properties
12 def enumerate(items):
13 x = 0
14 for i in items:
15 yield x, i
16 x += 1
18 class Properties(Dialog):
19 interface = None
20 use_list = None
22 def __init__(self, interface):
23 Dialog.__init__(self)
24 self.interface = interface
25 self.set_title('Interface ' + interface.get_name())
26 self.set_default_size(gtk.gdk.screen_width() / 2,
27 gtk.gdk.screen_height() / 3)
29 vbox = gtk.VBox(False, 4)
30 vbox.set_border_width(4)
31 self.vbox.pack_start(vbox, True, True, 0)
33 self.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
34 self.add_button(gtk.STOCK_REFRESH, 1)
35 self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
36 self.set_default_response(gtk.RESPONSE_CANCEL)
38 label = gtk.Label('%s: %s' % (interface.get_name(),
39 interface.summary))
40 vbox.pack_start(label, False, True, 0)
42 vbox.pack_start(gtk.Label('(%s)' % interface.uri),
43 False, True, 0)
45 def response(dialog, resp):
46 if resp == gtk.RESPONSE_CANCEL:
47 self.destroy()
48 elif resp == 1:
49 import reader
50 reader.update_from_network(interface)
51 policy.recalculate()
52 elif resp == gtk.RESPONSE_HELP:
53 properties_help.display()
54 self.connect('response', response)
56 frame = gtk.Frame()
57 frame.set_shadow_type(gtk.SHADOW_IN)
58 vbox.pack_start(frame, False, True, 0)
59 if interface.uptodate:
60 description = gtk.Label(interface.description or "-")
61 else:
62 description = gtk.Label("Information about this interface has not "
63 "yet been downloaded.")
64 description.set_line_wrap(True)
65 frame.add(description)
67 self.use_list = ImplementationList(interface)
68 vbox.pack_start(self.use_list, True, True, 0)
69 self.use_list.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
71 hbox = gtk.HBox(False, 2)
72 vbox.pack_start(hbox, False, True, 0)
74 stability = gtk.combo_box_new_text()
75 stability.append_text('Use default setting')
76 stability.set_active(0)
77 for i, x in enumerate((stable, testing, developer)):
78 stability.append_text(str(x).capitalize())
79 if x is interface.stability_policy:
80 stability.set_active(i + 1)
81 hbox.pack_start(gtk.Label('Preferred stability:'), False, True, 0)
82 hbox.pack_start(stability, False, True, 0)
83 def set_stability_policy(combo):
84 i = stability.get_active()
85 if i == 0:
86 new_stability = None
87 else:
88 name = stability.get_model()[i][0].lower()
89 new_stability = stability_levels[name]
90 interface.set_stability_policy(new_stability)
91 writer.save_interface(interface)
92 policy.recalculate()
93 stability.connect('changed', set_stability_policy)
95 self.update_list()
96 vbox.show_all()
98 self.connect('destroy', lambda s: policy.watchers.remove(self.update_list))
99 policy.watchers.append(self.update_list)
101 def update_list(self):
102 impls = policy.get_ranked_implementations(self.interface)
103 self.use_list.set_items(impls)
105 def edit(interface):
106 assert isinstance(interface, Interface)
107 if interface in _dialogs:
108 _dialogs[interface].destroy()
109 _dialogs[interface] = Properties(interface)
110 _dialogs[interface].show()
112 properties_help = help_box.HelpBox("Injector Properties Help",
113 ('Interface properties', """
114 This window displays information about an interface. At the top is the interface's \
115 short name, unique ID, summary and long description. The unique ID is also the \
116 location which is used to update the information."""),
118 ('Implementations', """
119 The main part of the window is a list of all known implementations of the interface. \
120 The columns have the following meanings:
122 Version gives the version number. High-numbered versions are considered to be \
123 better than low-numbered ones.
125 Stability is 'stable' if the implementation is believed to be stable, 'buggy' if \
126 it is known to contain serious bugs, and 'testing' if its stability is not yet \
127 known. This information is normally supplied and updated by the author of the \
128 software, but you can override their rating (overridden values are shown in upper-case). \
129 You can also use the special level 'preferred'.
131 C(ached) indicates whether the implementation is already stored on your computer. \
132 In off-line mode, only cached implementations are considered for use.
134 Arch indicates what kind of computer system the implementation is for, or 'any' \
135 if it works with all types of system.
137 Location is the path that will be used for the implementation when the program is run.
138 """),
139 ('Sort order', """
140 The implementations are listed in the injector's currently preferred order (the one \
141 at the top will actually be used). Usable implementations all come before unusable \
142 ones.
144 Unusable ones are those for incompatible \
145 architectures, those marked as 'buggy', versions explicitly marked as incompatible with \
146 another interface you are using and, in off-line mode, uncached implementations. Unusable \
147 implementations are shown crossed out.
149 For the usable implementations, the order is as follows:
151 - Preferred implementations come first.
153 - Then, if network use is set to 'Minimal', cached implementations come before \
154 non-cached.
156 - Then, implementations at or above the selected stability level come before all others.
158 - Then, higher-numbered versions come before low-numbered ones.
160 - Then cached come before non-cached (for 'Full' network use mode).
161 """))