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 base class for all frames."""
26
27
28 from os import sep
29 import wx
30 from wx.lib import buttons
31
32
33 from generic_fns.mol_res_spin import count_spins
34 from generic_fns.pipes import cdp_name
35
36
37 from gui import paths
38 from gui.analyses.elements import Text_ctrl
39 from gui.fonts import font
40 from gui.misc import add_border, int_to_gui, str_to_gui
41 from gui.user_functions.base import UF_page
42
43
45 """The base class for all frames."""
46
47
48 border = 10
49 size_graphic_panel = 200
50 spacer_horizontal = 5
51 width_text = 240
52 width_button = 100
53 width_main_separator = 40
54
55 - def __init__(self, parent, id=wx.ID_ANY, pos=None, size=None, style=None, name=None, gui=None):
56 """Initialise the scrolled window.
57
58 @param parent: The parent wx element.
59 @type parent: wx object
60 @keyword id: The unique ID number.
61 @type id: int
62 @keyword pos: The position.
63 @type pos: wx.Size object
64 @keyword size: The size.
65 @type size: wx.Size object
66 @keyword style: The style.
67 @type style: int
68 @keyword name: The name for the panel.
69 @type name: unicode
70 """
71
72
73 super(Base_analysis, self).__init__(parent, id=id, pos=pos, size=size, style=style, name=name)
74
75
76 self.width_vscroll = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
77
78
79 box_main = wx.BoxSizer(wx.HORIZONTAL)
80 self.SetSizer(box_main)
81
82
83 box_centre = add_border(box_main, border=self.border, packing=wx.HORIZONTAL)
84
85
86 self.build_main_box(box_centre)
87
88
89 self.SetAutoLayout(True)
90 self.SetupScrolling(scroll_x=False, scroll_y=True)
91
92
93 self.Bind(wx.EVT_SIZE, self.resize)
94
95
133
134
136 """Create and add the relax execution GUI element to the given box.
137
138 @param box: The box element to pack the relax execution GUI element into.
139 @type box: wx.BoxSizer instance
140 @param method: The method to execute when the button is clicked.
141 @type method: method
142 @return: The button.
143 @rtype: wx.lib.buttons.ThemedGenBitmapTextButton instance
144 """
145
146
147 sizer = wx.BoxSizer(wx.HORIZONTAL)
148
149
150 id = wx.NewId()
151
152
153 button = buttons.ThemedGenBitmapTextButton(self, id, None, " Execute relax")
154 button.SetBitmapLabel(wx.Bitmap(paths.IMAGE_PATH+'relax_start.gif', wx.BITMAP_TYPE_ANY))
155 button.SetFont(font.normal)
156 self.gui.Bind(wx.EVT_BUTTON, method, button)
157 sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
158
159
160 box.Add(sizer, 0, wx.ALIGN_RIGHT, 0)
161
162
163 return button
164
165
166 - def add_spin_control(self, box, parent, text='', min=None, max=None, control=wx.SpinCtrl, width=-1, height=-1):
167 """Add a text control field to the box.
168
169 @param box: The box element to pack the control into.
170 @type box: wx.BoxSizer instance
171 @param parent: The parent GUI element.
172 @type parent: wx object
173 @keyword text: The default text of the control.
174 @type text: str
175 @keyword min: The minimum value allowed.
176 @type min: int
177 @keyword max: The maximum value allowed.
178 @type max: int
179 @keyword control: The control class to use.
180 @type control: wx.TextCtrl derived class
181 @keyword width: The minimum width of the control.
182 @type width: int
183 @keyword height: The minimum height of the control.
184 @type height: int
185 @return: The text control object.
186 @rtype: control object
187 """
188
189
190 field = control(parent, -1, text, min=min, max=max)
191
192
193 field.SetMinSize((width, height))
194 field.SetFont(font.normal)
195
196
197 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
198
199
200 return field
201
202
204 """Add a special control for spin systems.
205
206 Only one of these per analysis are allowed.
207
208 @param box: The box element to pack the control into.
209 @type box: wx.BoxSizer instance
210 @param parent: The parent GUI element.
211 @type parent: wx object
212 """
213
214
215 self.spin_systems = Text_ctrl(box, self, text="Spin systems", button_text=" Spin editor", default=self.spin_count(), icon=paths.icon_16x16.spin, fn=self.launch_spin_editor, editable=False, button=True, width_text=self.width_text, width_button=self.width_button, spacer=self.spacer_horizontal)
216
217
218 - def add_static_text(self, box, parent, text='', width=-1, height=-1):
219 """Add a text control field to the box.
220
221 @param box: The box element to pack the control into.
222 @type box: wx.BoxSizer instance
223 @param parent: The parent GUI element.
224 @type parent: wx object
225 @keyword text: The default text of the control.
226 @type text: str
227 @keyword width: The minimum width of the control.
228 @type width: int
229 @keyword height: The minimum height of the control.
230 @type height: int
231 @return: The label.
232 @rtype: wx.StaticText instance
233 """
234
235
236 label = wx.StaticText(parent, -1, text)
237
238
239 label.SetMinSize((width, height))
240 label.SetFont(font.normal)
241
242
243 box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
244
245
246 return label
247
248
250 """Create and add the subtitle.
251
252 @param box: The box element to pack the subtitle into.
253 @type box: wx.BoxSizer instance
254 @param text: The text of the subtitle.
255 @type text: str
256 """
257
258
259 label = wx.StaticText(self, -1, text)
260
261
262 label.SetFont(font.subtitle)
263
264
265 box.AddSpacer(20)
266 box.Add(label)
267 box.AddSpacer(5)
268
269
271 """Create and add the subsubtitle.
272
273 @param box: The box element to pack the text into.
274 @type box: wx.BoxSizer instance
275 @param text: The text of the subsubtitle.
276 @type text: str
277 """
278
279
280 label = wx.StaticText(self, -1, text)
281
282
283 label.SetFont(font.normal)
284
285
286 box.AddSpacer(10)
287 box.Add(label)
288
289
290 - def add_text_control(self, box, parent, text='', control=wx.TextCtrl, width=-1, height=-1, editable=True):
291 """Add a text control field to the box.
292
293 @param box: The box element to pack the control into.
294 @type box: wx.BoxSizer instance
295 @param parent: The parent GUI element.
296 @type parent: wx object
297 @keyword text: The default text of the control.
298 @type text: str
299 @keyword control: The control class to use.
300 @type control: wx.TextCtrl derived class
301 @keyword width: The minimum width of the control.
302 @type width: int
303 @keyword height: The minimum height of the control.
304 @type height: int
305 @keyword editable: A flag specifying if the control is editable or not.
306 @type editable: bool
307 @return: The text control object.
308 @rtype: control object
309 """
310
311
312 field = control(parent, -1, str_to_gui(text))
313
314
315 field.SetMinSize((width, height))
316 field.SetFont(font.normal)
317
318
319 field.SetEditable(editable)
320 if not editable:
321 colour = self.GetBackgroundColour()
322 field.SetOwnBackgroundColour(colour)
323
324
325 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
326
327
328 return field
329
330
332 """Create and add the frame title.
333
334 @param box: The box element to pack the frame title into.
335 @type box: wx.BoxSizer instance
336 @param text: The text of the title.
337 @type text: str
338 """
339
340
341 label = wx.StaticText(self, -1, text)
342
343
344 label.SetFont(font.title)
345
346
347 box.AddSpacer(10)
348 box.Add(label)
349 box.AddSpacer(5)
350
351
353 """Construct the left hand box to pack into the automatic Rx analysis frame.
354
355 @return: The left hand box element containing the bitmap.
356 @rtype: wx.BoxSizer instance
357 """
358
359
360 box = wx.BoxSizer(wx.VERTICAL)
361
362
363 if not isinstance(self.bitmap, list):
364 bitmaps = [self.bitmap]
365 else:
366 bitmaps = self.bitmap
367
368
369 for i in range(len(bitmaps)):
370
371 bitmap = wx.StaticBitmap(self, -1, wx.Bitmap(bitmaps[i], wx.BITMAP_TYPE_ANY))
372
373
374 box.Add(bitmap, 0, wx.ADJUST_MINSIZE, 10)
375
376
377 return box
378
379
380 - def build_main_box(self, box):
381 """Construct the highest level box to pack into the automatic analysis frames.
382
383 @param box: The horizontal box element to pack the elements into.
384 @type box: wx.BoxSizer instance
385 """
386
387
388 left_box = self.build_left_box()
389 box.Add(left_box, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
390
391
392 box.AddSpacer(self.width_main_separator)
393
394
395 right_box = self.build_right_box()
396 box.Add(right_box, 1, wx.ALL|wx.EXPAND, 0)
397
398
400 """The spin editor GUI element.
401
402 @param event: The wx event.
403 @type event: wx event
404 """
405
406
407 self.gui.show_tree(None)
408
409
411 """Register and unregister methods with the observer objects.
412
413 This is a dummy method.
414
415
416 @keyword remove: If set to True, then the methods will be unregistered.
417 @type remove: False
418 """
419
420
422 """The spin editor GUI element.
423
424 @param event: The wx event.
425 @type event: wx event
426 """
427
428
429 x = self.GetSize()[0] - self.width_vscroll
430 y = self.GetVirtualSize()[1]
431 self.SetVirtualSize((x, y))
432
433
435 """Count the number of loaded spins, returning a string formatted as 'xxx spins loaded'.
436
437 @return: The number of loaded spins in the format 'xxx spins loaded'.
438 @rtype: str
439 """
440
441
442 if hasattr(self.data, 'pipe_name'):
443 pipe = self.data.pipe_name
444 else:
445 pipe = cdp_name()
446
447
448 num = count_spins(pipe=pipe)
449
450
451 return "%s spins loaded and selected" % num
452
453
459
460
461
463 """The NOE peak intensity reading wizard page for specifying the type of error to be used."""
464
465
466 image_path = paths.WIZARD_IMAGE_PATH + 'spectrum' + sep + 'spectrum_200.png'
467 uf_path = ['spectrum', 'error_analysis']
468 height_desc = 450
469
470 - def add_contents(self, sizer):
471 """Add the specific GUI elements.
472
473 @param sizer: A sizer object.
474 @type sizer: wx.Sizer instance
475 """
476
477
478 msg = "Please specify from where the peak intensity errors will be obtained. The execution of the spectrum.error_analysis user function, as described above, will be postponed until after clicking on the 'Execute relax' button at the end of the automatic NOE analysis page."
479 text = wx.StaticText(self, -1, msg)
480 text.Wrap(self._main_size)
481 sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
482
483
484 sizer.AddStretchSpacer()
485
486
487 sizer2 = wx.BoxSizer(wx.HORIZONTAL)
488 sizer.Add(sizer2, 1, wx.ALL|wx.EXPAND, 0)
489
490
491 sizer.AddStretchSpacer()
492
493
494 sizer2.AddStretchSpacer()
495
496
497 sizer_radio = wx.BoxSizer(wx.VERTICAL)
498 sizer2.Add(sizer_radio, 1, wx.ALL|wx.EXPAND, 0)
499
500
501 self.radio_rmsd = wx.RadioButton(self, -1, "Baseplane RMSD.", style=wx.RB_GROUP)
502 sizer_radio.Add(self.radio_rmsd, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
503
504
505 sizer_radio.AddSpacer(10)
506
507
508 self.radio_repl = wx.RadioButton(self, -1, "Replicated spectra.")
509 sizer_radio.Add(self.radio_repl, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
510
511
512 self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_rmsd)
513 self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_repl)
514
515
516 sizer2.AddStretchSpacer(3)
517
518
519 sizer.AddStretchSpacer()
520
521
522 self.selection = 'rmsd'
523
524
525 - def _on_select(self, event):
526 """Handle the radio button switching.
527
528 @param event: The wx event.
529 @type event: wx event
530 """
531
532
533 button = event.GetEventObject()
534
535
536 if button == self.radio_rmsd:
537 self.selection = 'rmsd'
538 elif button == self.radio_repl:
539 self.selection = 'repl'
540