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