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