Updates for changes in injector.
[zeroinstall.git] / properties.py
blob991e3904e12a7ff25bde1765f5eb6a3113f95b04
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 def response(dialog, resp):
39 if resp == gtk.RESPONSE_CANCEL:
40 self.destroy()
41 elif resp == 1:
42 import reader
43 reader.update_from_network(interface)
44 policy.recalculate()
45 elif resp == gtk.RESPONSE_HELP:
46 properties_help.display()
47 self.connect('response', response)
49 swin = gtk.ScrolledWindow(None, None)
50 swin.set_shadow_type(gtk.SHADOW_IN)
51 swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
52 vbox.pack_start(swin, False, True, 0)
53 description = gtk.TextView()
54 description.set_left_margin(4)
55 description.set_right_margin(4)
56 description.set_wrap_mode(gtk.WRAP_WORD)
57 description.set_editable(False)
58 description.set_cursor_visible(False)
59 swin.add(description)
61 buffer = description.get_buffer()
62 heading_style = buffer.create_tag(underline = True, scale = 1.2)
63 iter = buffer.get_start_iter()
64 buffer.insert_with_tags(iter,
65 '%s (%s)' % (interface.get_name(), interface.summary), heading_style)
67 buffer.insert(iter, '\nFull name: %s\n\n' % interface.uri)
69 buffer.insert_with_tags(iter, 'Description\n', heading_style)
71 description.set_size_request(-1, 100)
73 buffer.insert(iter, interface.description or "-")
75 self.use_list = ImplementationList(interface)
76 vbox.pack_start(self.use_list, True, True, 0)
77 self.use_list.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
79 hbox = gtk.HBox(False, 2)
80 vbox.pack_start(hbox, False, True, 0)
82 stability = gtk.combo_box_new_text()
83 stability.append_text('Use default setting')
84 stability.set_active(0)
85 for i, x in enumerate((stable, testing, developer)):
86 stability.append_text(str(x).capitalize())
87 if x is interface.stability_policy:
88 stability.set_active(i + 1)
89 hbox.pack_start(gtk.Label('Preferred stability:'), False, True, 0)
90 hbox.pack_start(stability, False, True, 0)
91 def set_stability_policy(combo):
92 i = stability.get_active()
93 if i == 0:
94 new_stability = None
95 else:
96 name = stability.get_model()[i][0].lower()
97 new_stability = stability_levels[name]
98 interface.set_stability_policy(new_stability)
99 writer.save_interface(interface)
100 policy.recalculate()
101 stability.connect('changed', set_stability_policy)
103 self.update_list()
104 vbox.show_all()
106 self.connect('destroy', lambda s: policy.watchers.remove(self.update_list))
107 policy.watchers.append(self.update_list)
109 def update_list(self):
110 impls = policy.get_ranked_implementations(self.interface)
111 self.use_list.set_items(impls)
113 def edit(interface):
114 assert isinstance(interface, Interface)
115 if interface in _dialogs:
116 _dialogs[interface].destroy()
117 _dialogs[interface] = Properties(interface)
118 _dialogs[interface].show()
120 properties_help = help_box.HelpBox("Injector Properties Help",
121 ('Interface properties', """
122 This window displays information about an interface. At the top is the interface's \
123 short name, unique ID, summary and long description. The unique ID is also the \
124 location which is used to update the information."""),
126 ('Implementations', """
127 The main part of the window is a list of all known implementations of the interface. \
128 The columns have the following meanings:
130 Version gives the version number. High-numbered versions are considered to be \
131 better than low-numbered ones.
133 Stability is 'stable' if the implementation is believed to be stable, 'buggy' if \
134 it is known to contain serious bugs, and 'testing' if its stability is not yet \
135 known. This information is normally supplied and updated by the author of the \
136 software, but you can override their rating (overridden values are shown in upper-case). \
137 You can also use the special level 'preferred'.
139 C(ached) indicates whether the implementation is already stored on your computer. \
140 In off-line mode, only cached implementations are considered for use.
142 Arch indicates what kind of computer system the implementation is for, or 'any' \
143 if it works with all types of system.
145 Location is the path that will be used for the implementation when the program is run.
146 """),
147 ('Sort order', """
148 The implementations are listed in the injector's currently preferred order (the one \
149 at the top will actually be used). Usable implementations all come before unusable \
150 ones.
152 Unusable ones are those for incompatible \
153 architectures, those marked as 'buggy', versions explicitly marked as incompatible with \
154 another interface you are using and, in off-line mode, uncached implementations. Unusable \
155 implementations are shown crossed out.
157 For the usable implementations, the order is as follows:
159 - Preferred implementations come first.
161 - Then, if network use is set to 'Minimal', cached implementations come before \
162 non-cached.
164 - Then, implementations at or above the selected stability level come before all others.
166 - Then, higher-numbered versions come before low-numbered ones.
168 - Then cached come before non-cached (for 'Full' network use mode).
169 """))