1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module containing the classes for GUI components involving spectral data."""
25
26
27 import wx
28 import wx.lib.buttons
29
30
31 from status import Status; status = Status()
32 from generic_fns.spectrum import replicated_flags, replicated_ids
33 from graphics import fetch_icon
34 from user_functions.data import Uf_info; uf_info = Uf_info()
35
36
37 from gui.components.base_list import Base_list
38 from gui.components.menu import build_menu_item
39 from gui.fonts import font
40 from gui.misc import add_border
41 from gui.string_conv import float_to_gui, gui_to_str, str_to_gui
42 from gui.uf_objects import Uf_storage; uf_store = Uf_storage()
43
44
46 """The GUI element for listing loaded spectral data."""
47
48 - def __init__(self, gui=None, parent=None, box=None, id=None, fn_add=None, proportion=0, button_placement='default'):
49 """Build the spectral list GUI element.
50
51 @keyword gui: The main GUI object.
52 @type gui: wx.Frame instance
53 @keyword parent: The parent GUI element that this is to be attached to (the panel object).
54 @type parent: wx object
55 @keyword data: The data storage container.
56 @type data: class instance
57 @keyword box: The vertical box sizer to pack this GUI component into.
58 @type box: wx.BoxSizer instance
59 @keyword id: A unique identification string. This is used to register the update method with the GUI user function observer object.
60 @type id: str
61 @keyword fn_add: The function to execute when clicking on the 'Add' button.
62 @type fn_add: func
63 @keyword proportion: The window proportion parameter.
64 @type proportion: bool
65 @keyword button_placement: Override the button visibility and placement. The value of 'default' will leave the buttons at the default setting. The value of 'top' will place the buttons at the top, 'bottom' will place them at the bottom, and None will turn off the buttons.
66 @type button_placement: str or None
67 """
68
69
70 self.fn_add = fn_add
71
72
73 super(Spectra_list, self).__init__(gui=gui, parent=parent, box=box, id=id, proportion=proportion, button_placement=button_placement)
74
75
77 """Launch the relax_fit.relax_time user function.
78
79 @param event: The wx event.
80 @type event: wx event
81 """
82
83
84 item = self.element.GetFirstSelected()
85
86
87 id = gui_to_str(self.element.GetItemText(item))
88
89
90 time = None
91 if hasattr(cdp, 'relax_times') and id in cdp.relax_times.keys():
92 time = cdp.relax_times[id]
93
94
95 if time == None:
96 uf_store['relax_fit.relax_time'](spectrum_id=id)
97 else:
98 uf_store['relax_fit.relax_time'](time=time, spectrum_id=id)
99
100
102 """Launch the spectrum.baseplane_rmsd user function.
103
104 @param event: The wx event.
105 @type event: wx event
106 """
107
108
109 item = self.element.GetFirstSelected()
110
111
112 id = gui_to_str(self.element.GetItemText(item))
113
114
115 uf_store['spectrum.baseplane_rmsd'](spectrum_id=id)
116
117
119 """Launch the spectrum.delete user function.
120
121 @param event: The wx event.
122 @type event: wx event
123 """
124
125
126 item = self.element.GetFirstSelected()
127
128
129 if item == -1:
130 id = None
131
132
133 else:
134
135 id = gui_to_str(self.element.GetItemText(item))
136
137
138 uf_store['spectrum.delete'](spectrum_id=id)
139
140
142 """Launch the spectrum.integration_points user function.
143
144 @param event: The wx event.
145 @type event: wx event
146 """
147
148
149 item = self.element.GetFirstSelected()
150
151
152 id = gui_to_str(self.element.GetItemText(item))
153
154
155 uf_store['spectrum.integration_points'](spectrum_id=id)
156
157
159 """Launch the spectrum.replicated user function.
160
161 @param event: The wx event.
162 @type event: wx event
163 """
164
165
166 item = self.element.GetFirstSelected()
167
168
169 id = gui_to_str(self.element.GetItemText(item))
170
171
172 replicates = replicated_ids(id)
173
174
175 if replicates == []:
176 uf_store['spectrum.replicated'](spectrum_ids=id)
177 else:
178 uf_store['spectrum.replicated'](spectrum_ids=replicates)
179
180
182 """Add the NOE spectral type info to the element.
183
184 @param index: The column index for the data.
185 @type index: int
186 @return: True if a spectrum type exists, False otherwise.
187 @rtype: bool
188 """
189
190
191 if not hasattr(cdp, 'spectrum_type') or not len(cdp.spectrum_type):
192 return False
193
194
195 self.element.InsertColumn(index, str_to_gui("NOE spectrum type"))
196
197
198 table = {
199 'sat': 'Saturated',
200 'ref': 'Reference'
201 }
202
203
204 for i in range(len(cdp.spectrum_ids)):
205
206 if cdp.spectrum_ids[i] not in cdp.spectrum_type.keys():
207 continue
208
209
210 self.element.SetStringItem(i, index, str_to_gui(table[cdp.spectrum_type[cdp.spectrum_ids[i]]]))
211
212
213 return True
214
215
217 """Add the relaxation delay time info to the element.
218
219 @param index: The column index for the data.
220 @type index: int
221 @return: True if relaxation times exist, False otherwise.
222 @rtype: bool
223 """
224
225
226 if not hasattr(cdp, 'relax_times') or not len(cdp.relax_times):
227 return False
228
229
230 self.element.InsertColumn(index, str_to_gui("Delay times"))
231
232
233 for i in range(len(cdp.spectrum_ids)):
234
235 if cdp.spectrum_ids[i] not in cdp.relax_times.keys():
236 continue
237
238
239 self.element.SetStringItem(i, index, float_to_gui(cdp.relax_times[cdp.spectrum_ids[i]]))
240
241
242 return True
243
244
246 """Add the replicated spectra info to the element.
247
248 @param index: The column index for the data.
249 @type index: int
250 @return: True if relaxation times exist, False otherwise.
251 @rtype: bool
252 """
253
254
255 if not hasattr(cdp, 'replicates') or not len(cdp.replicates):
256 return False
257
258
259 repl = replicated_flags()
260
261
262 self.element.InsertColumn(index, str_to_gui("Replicate IDs"))
263
264
265 for i in range(len(cdp.spectrum_ids)):
266
267 if not repl[cdp.spectrum_ids[i]]:
268 continue
269
270
271 id_list = replicated_ids(cdp.spectrum_ids[i])
272
273
274 text = ''
275 for j in range(len(id_list)):
276
277 text = "%s%s" % (text, id_list[j])
278
279
280 if j < len(id_list)-1:
281 text = "%s, " % text
282
283
284 self.element.SetStringItem(i, index, str_to_gui(text))
285
286
287 return True
288
289
291 """Override the base variables."""
292
293
294 self.title = "Spectra list"
295 self.observer_base_name = "spectra list"
296
297
298 self.columns = []
299
300
301 self.button_placement = 'top'
302 self.button_info = [
303 {
304 'object': 'button_add',
305 'label': ' Add',
306 'icon': fetch_icon('oxygen.actions.list-add-relax-blue', "22x22"),
307 'method': self.fn_add,
308 'tooltip': "Read a spectral data file."
309 }, {
310 'object': 'button_delete',
311 'label': ' Delete',
312 'icon': fetch_icon('oxygen.actions.list-remove', "22x22"),
313 'method': self.action_spectrum_delete,
314 'tooltip': "Delete loaded relaxation data from the relax data store."
315 }
316 ]
317
318
319 self.popup_menus = [
320 {
321 'id': wx.NewId(),
322 'text': "Set the &baseplane RMSD",
323 'icon': fetch_icon(uf_info.get_uf('spectrum.baseplane_rmsd').gui_icon),
324 'method': self.action_relax_fit_relax_time
325 }, {
326 'id': wx.NewId(),
327 'text': "&Delete the peak intensities",
328 'icon': fetch_icon(uf_info.get_uf('spectrum.delete').gui_icon),
329 'method': self.action_spectrum_baseplane_rmsd
330 }, {
331 'id': wx.NewId(),
332 'text': "Set the number of integration &points",
333 'icon': fetch_icon(uf_info.get_uf('spectrum.integration_points').gui_icon),
334 'method': self.action_spectrum_delete
335 }, {
336 'id': wx.NewId(),
337 'text': "Specify which spectra are &replicated",
338 'icon': fetch_icon(uf_info.get_uf('spectrum.replicated').gui_icon),
339 'method': self.action_spectrum_integration_points
340 }, {
341 'id': wx.NewId(),
342 'text': "Set the relaxation &time",
343 'icon': fetch_icon(uf_info.get_uf('relax_fit.relax_time').gui_icon),
344 'method': self.action_spectrum_replicated
345 }
346 ]
347
348
350 """Method called from self.build_element_safe() to update the list data."""
351
352
353 index = 1
354
355
356 self.element.DeleteAllItems()
357 self.element.DeleteAllColumns()
358
359
360 self.element.InsertColumn(0, str_to_gui("Spectrum ID string"))
361
362
363 n = 0
364 if hasattr(cdp, 'spectrum_ids'):
365
366 n = len(cdp.spectrum_ids)
367
368
369 for i in range(n):
370 self.element.InsertStringItem(i, str_to_gui(cdp.spectrum_ids[i]))
371
372
373 if self.noe_spectrum_type(index):
374 index += 1
375
376
377 if self.relax_times(index):
378 index += 1
379
380
381 if self.replicates(index):
382 index += 1
383