Added --download-only.
[zeroinstall.git] / properties.py
bloba6c0893fff7908c78299330675e889d24af21560
1 from model import *
2 import gtk
4 import help_box
5 from dialog import Dialog
6 from gui import policy
7 from impl_list import ImplementationList
8 import writer
9 import time
11 _dialogs = {} # Interface -> Properties
13 def enumerate(items):
14 x = 0
15 for i in items:
16 yield x, i
17 x += 1
19 class Properties(Dialog):
20 interface = None
21 use_list = None
23 def __init__(self, interface):
24 Dialog.__init__(self)
25 self.interface = interface
26 self.set_title('Interface ' + interface.get_name())
27 self.set_default_size(gtk.gdk.screen_width() / 2,
28 gtk.gdk.screen_height() / 3)
30 vbox = gtk.VBox(False, 4)
31 vbox.set_border_width(4)
32 self.vbox.pack_start(vbox, True, True, 0)
34 self.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
35 #self.add_button(gtk.STOCK_REFRESH, 1)
36 self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
37 self.set_default_response(gtk.RESPONSE_CANCEL)
39 def response(dialog, resp):
40 if resp == gtk.RESPONSE_CANCEL:
41 self.destroy()
42 #elif resp == 1:
43 # policy.begin_iface_download(interface, True)
44 elif resp == gtk.RESPONSE_HELP:
45 properties_help.display()
46 self.connect('response', response)
48 swin = gtk.ScrolledWindow(None, None)
49 swin.set_shadow_type(gtk.SHADOW_IN)
50 swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
51 vbox.pack_start(swin, False, True, 0)
52 description = gtk.TextView()
53 description.set_left_margin(4)
54 description.set_right_margin(4)
55 description.set_wrap_mode(gtk.WRAP_WORD)
56 description.set_editable(False)
57 description.set_cursor_visible(False)
58 swin.add(description)
60 buffer = description.get_buffer()
61 heading_style = buffer.create_tag(underline = True, scale = 1.2)
63 def set_details():
64 buffer.delete(buffer.get_start_iter(), buffer.get_end_iter())
66 iter = buffer.get_start_iter()
68 buffer.insert_with_tags(iter,
69 '%s (%s)' % (interface.get_name(), interface.summary), heading_style)
71 buffer.insert(iter, '\nFull name: %s' % interface.uri)
73 # (converts to local time)
74 if interface.last_modified:
75 buffer.insert(iter, '\nLast upstream change: %s' % time.ctime(interface.last_modified))
77 if interface.last_local_update:
78 buffer.insert(iter, '\nLast local update: %s' % time.ctime(interface.last_local_update))
80 if interface.last_checked:
81 buffer.insert(iter, '\nLast checked: %s' % time.ctime(interface.last_checked))
83 buffer.insert_with_tags(iter, '\n\nDescription\n', heading_style)
85 buffer.insert(iter, interface.description or "-")
86 set_details()
88 description.set_size_request(-1, 100)
90 self.use_list = ImplementationList(interface)
91 vbox.pack_start(self.use_list, True, True, 0)
92 self.use_list.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
94 hbox = gtk.HBox(False, 2)
95 vbox.pack_start(hbox, False, True, 0)
97 stability = gtk.combo_box_new_text()
98 stability.append_text('Use default setting')
99 stability.set_active(0)
100 for i, x in enumerate((stable, testing, developer)):
101 stability.append_text(str(x).capitalize())
102 if x is interface.stability_policy:
103 stability.set_active(i + 1)
104 hbox.pack_start(gtk.Label('Preferred stability:'), False, True, 0)
105 hbox.pack_start(stability, False, True, 0)
106 def set_stability_policy(combo):
107 i = stability.get_active()
108 if i == 0:
109 new_stability = None
110 else:
111 name = stability.get_model()[i][0].lower()
112 new_stability = stability_levels[name]
113 interface.set_stability_policy(new_stability)
114 writer.save_interface(interface)
115 policy.recalculate()
116 stability.connect('changed', set_stability_policy)
118 self.update_list()
119 vbox.show_all()
121 def updated():
122 self.update_list()
123 set_details()
124 self.connect('destroy', lambda s: policy.watchers.remove(updated))
125 policy.watchers.append(updated)
127 def update_list(self):
128 impls = policy.get_ranked_implementations(self.interface)
129 self.use_list.set_items(impls)
131 def edit(interface):
132 assert isinstance(interface, Interface)
133 if interface in _dialogs:
134 _dialogs[interface].destroy()
135 _dialogs[interface] = Properties(interface)
136 _dialogs[interface].show()
138 properties_help = help_box.HelpBox("Injector Properties Help",
139 ('Interface properties', """
140 This window displays information about an interface. At the top is the interface's \
141 short name, unique ID, summary and long description. The unique ID is also the \
142 location which is used to update the information."""),
144 ('Implementations', """
145 The main part of the window is a list of all known implementations of the interface. \
146 The columns have the following meanings:
148 Version gives the version number. High-numbered versions are considered to be \
149 better than low-numbered ones.
151 Stability is 'stable' if the implementation is believed to be stable, 'buggy' if \
152 it is known to contain serious bugs, and 'testing' if its stability is not yet \
153 known. This information is normally supplied and updated by the author of the \
154 software, but you can override their rating (overridden values are shown in upper-case). \
155 You can also use the special level 'preferred'.
157 C(ached) indicates whether the implementation is already stored on your computer. \
158 In off-line mode, only cached implementations are considered for use.
160 Arch indicates what kind of computer system the implementation is for, or 'any' \
161 if it works with all types of system.
163 Location is the path that will be used for the implementation when the program is run.
164 """),
165 ('Sort order', """
166 The implementations are listed in the injector's currently preferred order (the one \
167 at the top will actually be used). Usable implementations all come before unusable \
168 ones.
170 Unusable ones are those for incompatible \
171 architectures, those marked as 'buggy', versions explicitly marked as incompatible with \
172 another interface you are using and, in off-line mode, uncached implementations. Unusable \
173 implementations are shown crossed out.
175 For the usable implementations, the order is as follows:
177 - Preferred implementations come first.
179 - Then, if network use is set to 'Minimal', cached implementations come before \
180 non-cached.
182 - Then, implementations at or above the selected stability level come before all others.
184 - Then, higher-numbered versions come before low-numbered ones.
186 - Then cached come before non-cached (for 'Full' network use mode).
187 """))