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 from wx.lib import scrolledpanel
32
33
34 from generic_fns.mol_res_spin import count_spins
35 from generic_fns.pipes import cdp_name
36 from user_functions.data import Uf_info; uf_info = Uf_info()
37 from user_functions.data import Uf_tables; uf_tables = Uf_tables()
38
39
40 from gui import paths
41 from gui.analyses.elements import Text_ctrl
42 from gui.fonts import font
43 from gui.misc import add_border, format_table
44 from gui.string_conv import int_to_gui, str_to_gui
45 from gui.wizard import Wiz_page
46
47
49 """The base class for all frames."""
50
51
52 border = 10
53 size_graphic_panel = 200
54 spacer_horizontal = 5
55 width_text = 240
56 width_button = 100
57 width_main_separator = 40
58
59 - def __init__(self, parent, id=wx.ID_ANY, pos=None, size=None, style=None, name=None, gui=None):
60 """Initialise the scrolled window.
61
62 @param parent: The parent wx element.
63 @type parent: wx object
64 @keyword id: The unique ID number.
65 @type id: int
66 @keyword pos: The position.
67 @type pos: wx.Size object
68 @keyword size: The size.
69 @type size: wx.Size object
70 @keyword style: The style.
71 @type style: int
72 @keyword name: The name for the panel.
73 @type name: unicode
74 """
75
76
77 super(Base_analysis, self).__init__(parent, id=id, pos=pos, size=size, style=style, name=name)
78
79
80 self.width_vscroll = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
81
82
83 box_main = wx.BoxSizer(wx.HORIZONTAL)
84 self.SetSizer(box_main)
85
86
87 box_centre = add_border(box_main, border=self.border, packing=wx.HORIZONTAL)
88
89
90 self.build_main_box(box_centre)
91
92
93 self.SetAutoLayout(True)
94 self.SetupScrolling(scroll_x=False, scroll_y=True)
95
96
97 self.Bind(wx.EVT_SIZE, self.resize)
98
99
137
138
140 """Create and add the relax execution GUI element to the given box.
141
142 @param box: The box element to pack the relax execution GUI element into.
143 @type box: wx.BoxSizer instance
144 @param method: The method to execute when the button is clicked.
145 @type method: method
146 @return: The button.
147 @rtype: wx.lib.buttons.ThemedGenBitmapTextButton instance
148 """
149
150
151 sizer = wx.BoxSizer(wx.HORIZONTAL)
152
153
154 id = wx.NewId()
155
156
157 button = buttons.ThemedGenBitmapTextButton(self, id, None, " Execute relax")
158 button.SetBitmapLabel(wx.Bitmap(paths.IMAGE_PATH+'relax_start.gif', wx.BITMAP_TYPE_ANY))
159 button.SetFont(font.normal)
160 self.gui.Bind(wx.EVT_BUTTON, method, button)
161 sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
162
163
164 box.Add(sizer, 0, wx.ALIGN_RIGHT, 0)
165
166
167 return button
168
169
170 - def add_spin_control(self, box, parent, text='', min=None, max=None, control=wx.SpinCtrl, width=-1, height=-1):
171 """Add a text control field to the box.
172
173 @param box: The box element to pack the control into.
174 @type box: wx.BoxSizer instance
175 @param parent: The parent GUI element.
176 @type parent: wx object
177 @keyword text: The default text of the control.
178 @type text: str
179 @keyword min: The minimum value allowed.
180 @type min: int
181 @keyword max: The maximum value allowed.
182 @type max: int
183 @keyword control: The control class to use.
184 @type control: wx.TextCtrl derived class
185 @keyword width: The minimum width of the control.
186 @type width: int
187 @keyword height: The minimum height of the control.
188 @type height: int
189 @return: The text control object.
190 @rtype: control object
191 """
192
193
194 field = control(parent, -1, text, min=min, max=max)
195
196
197 field.SetMinSize((width, height))
198 field.SetFont(font.normal)
199
200
201 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
202
203
204 return field
205
206
208 """Add a special control for spin systems.
209
210 Only one of these per analysis are allowed.
211
212 @param box: The box element to pack the control into.
213 @type box: wx.BoxSizer instance
214 @param parent: The parent GUI element.
215 @type parent: wx object
216 """
217
218
219 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)
220
221
222 - def add_static_text(self, box, parent, text='', width=-1, height=-1):
223 """Add a text control field to the box.
224
225 @param box: The box element to pack the control into.
226 @type box: wx.BoxSizer instance
227 @param parent: The parent GUI element.
228 @type parent: wx object
229 @keyword text: The default text of the control.
230 @type text: str
231 @keyword width: The minimum width of the control.
232 @type width: int
233 @keyword height: The minimum height of the control.
234 @type height: int
235 @return: The label.
236 @rtype: wx.StaticText instance
237 """
238
239
240 label = wx.StaticText(parent, -1, text)
241
242
243 label.SetMinSize((width, height))
244 label.SetFont(font.normal)
245
246
247 box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
248
249
250 return label
251
252
254 """Create and add the subtitle.
255
256 @param box: The box element to pack the subtitle into.
257 @type box: wx.BoxSizer instance
258 @param text: The text of the subtitle.
259 @type text: str
260 """
261
262
263 label = wx.StaticText(self, -1, text)
264
265
266 label.SetFont(font.subtitle)
267
268
269 box.AddSpacer(20)
270 box.Add(label)
271 box.AddSpacer(5)
272
273
275 """Create and add the subsubtitle.
276
277 @param box: The box element to pack the text into.
278 @type box: wx.BoxSizer instance
279 @param text: The text of the subsubtitle.
280 @type text: str
281 """
282
283
284 label = wx.StaticText(self, -1, text)
285
286
287 label.SetFont(font.normal)
288
289
290 box.AddSpacer(10)
291 box.Add(label)
292
293
294 - def add_text_control(self, box, parent, text='', control=wx.TextCtrl, width=-1, height=-1, editable=True):
295 """Add a text control field to the box.
296
297 @param box: The box element to pack the control into.
298 @type box: wx.BoxSizer instance
299 @param parent: The parent GUI element.
300 @type parent: wx object
301 @keyword text: The default text of the control.
302 @type text: str
303 @keyword control: The control class to use.
304 @type control: wx.TextCtrl derived class
305 @keyword width: The minimum width of the control.
306 @type width: int
307 @keyword height: The minimum height of the control.
308 @type height: int
309 @keyword editable: A flag specifying if the control is editable or not.
310 @type editable: bool
311 @return: The text control object.
312 @rtype: control object
313 """
314
315
316 field = control(parent, -1, str_to_gui(text))
317
318
319 field.SetMinSize((width, height))
320 field.SetFont(font.normal)
321
322
323 field.SetEditable(editable)
324 if not editable:
325 colour = self.GetBackgroundColour()
326 field.SetOwnBackgroundColour(colour)
327
328
329 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
330
331
332 return field
333
334
336 """Create and add the frame title.
337
338 @param box: The box element to pack the frame title into.
339 @type box: wx.BoxSizer instance
340 @param text: The text of the title.
341 @type text: str
342 """
343
344
345 label = wx.StaticText(self, -1, text)
346
347
348 label.SetFont(font.title)
349
350
351 box.AddSpacer(10)
352 box.Add(label)
353 box.AddSpacer(5)
354
355
357 """Construct the left hand box to pack into the automatic Rx analysis frame.
358
359 @return: The left hand box element containing the bitmap.
360 @rtype: wx.BoxSizer instance
361 """
362
363
364 box = wx.BoxSizer(wx.VERTICAL)
365
366
367 if not isinstance(self.bitmap, list):
368 bitmaps = [self.bitmap]
369 else:
370 bitmaps = self.bitmap
371
372
373 for i in range(len(bitmaps)):
374
375 bitmap = wx.StaticBitmap(self, -1, wx.Bitmap(bitmaps[i], wx.BITMAP_TYPE_ANY))
376
377
378 box.Add(bitmap, 0, wx.ADJUST_MINSIZE, 10)
379
380
381 return box
382
383
384 - def build_main_box(self, box):
385 """Construct the highest level box to pack into the automatic analysis frames.
386
387 @param box: The horizontal box element to pack the elements into.
388 @type box: wx.BoxSizer instance
389 """
390
391
392 left_box = self.build_left_box()
393 box.Add(left_box, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
394
395
396 box.AddSpacer(self.width_main_separator)
397
398
399 right_box = self.build_right_box()
400 box.Add(right_box, 1, wx.ALL|wx.EXPAND, 0)
401
402
404 """The spin editor GUI element.
405
406 @param event: The wx event.
407 @type event: wx event
408 """
409
410
411 self.gui.show_tree(None)
412
413
415 """Register and unregister methods with the observer objects.
416
417 This is a dummy method.
418
419
420 @keyword remove: If set to True, then the methods will be unregistered.
421 @type remove: False
422 """
423
424
426 """The spin editor GUI element.
427
428 @param event: The wx event.
429 @type event: wx event
430 """
431
432
433 x = self.GetSize()[0] - self.width_vscroll
434 y = self.GetVirtualSize()[1]
435 self.SetVirtualSize((x, y))
436
437
439 """Count the number of loaded spins, returning a string formatted as 'xxx spins loaded'.
440
441 @return: The number of loaded spins in the format 'xxx spins loaded'.
442 @rtype: str
443 """
444
445
446 if hasattr(self.data, 'pipe_name'):
447 pipe = self.data.pipe_name
448 else:
449 pipe = cdp_name()
450
451
452 num = count_spins(pipe=pipe)
453
454
455 return "%s spins loaded and selected" % num
456
457
463
464
465
467 """The NOE peak intensity reading wizard page for specifying the type of error to be used."""
468
469
470 image_path = paths.WIZARD_IMAGE_PATH + 'spectrum' + sep + 'spectrum_200.png'
471 title = "Specify the type of error to be used"
472 main_text = "Please specify from where the peak intensity errors will be obtained. The is required for the execution of the spectrum.error_analysis user function which will be postponed until after clicking on the 'Execute relax' button at the end of the automatic analysis page. To understand how the errors will be propagated and analysed, the main parts of the spectrum.error_analysis user function description are given below."
473 uf_path = ['spectrum', 'error_analysis']
474
475 - def _on_select(self, event):
476 """Handle the radio button switching.
477
478 @param event: The wx event.
479 @type event: wx event
480 """
481
482
483 button = event.GetEventObject()
484
485
486 if button == self.radio_rmsd:
487 self.selection = 'rmsd'
488 elif button == self.radio_repl:
489 self.selection = 'repl'
490
491
492 - def add_contents(self, sizer):
493 """Add the specific GUI elements.
494
495 @param sizer: A sizer object.
496 @type sizer: wx.Sizer instance
497 """
498
499
500 sizer2 = wx.BoxSizer(wx.HORIZONTAL)
501 sizer.Add(sizer2, 1, wx.ALL|wx.EXPAND, 0)
502
503
504 sizer.AddStretchSpacer()
505
506
507 sizer2.AddStretchSpacer()
508
509
510 sizer_radio = wx.BoxSizer(wx.VERTICAL)
511 sizer2.Add(sizer_radio, 1, wx.ALL|wx.EXPAND, 0)
512
513
514 self.radio_rmsd = wx.RadioButton(self, -1, "Baseplane RMSD.", style=wx.RB_GROUP)
515 sizer_radio.Add(self.radio_rmsd, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
516
517
518 sizer_radio.AddSpacer(10)
519
520
521 self.radio_repl = wx.RadioButton(self, -1, "Replicated spectra.")
522 sizer_radio.Add(self.radio_repl, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
523
524
525 self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_rmsd)
526 self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_repl)
527
528
529 sizer2.AddStretchSpacer(3)
530
531
532 sizer.AddStretchSpacer()
533
534
535 self.selection = 'rmsd'
536
537
538 - def add_desc(self, sizer, max_y=520):
539 """Add the description to the dialog.
540
541 @param sizer: A sizer object.
542 @type sizer: wx.Sizer instance
543 @keyword max_y: The maximum height, in number of pixels, for the description.
544 @type max_y: int
545 """
546
547
548 spacing = 15
549
550
551 sizer.AddSpacer(5)
552 sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.ALL, 0)
553 sizer.AddSpacer(5)
554
555
556 panel = scrolledpanel.ScrolledPanel(self, -1, name="desc")
557
558
559 panel_sizer = wx.BoxSizer(wx.VERTICAL)
560
561
562 tot_y = 0
563 text_elements = []
564 text_types = []
565
566
567 text = wx.StaticText(panel, -1, self.main_text, style=wx.TE_MULTILINE)
568 text.SetFont(font.normal)
569 text.Wrap(self._main_size - 20)
570 text_elements.append(text)
571 text_types.append('title')
572
573
574 x, y = text.GetSizeTuple()
575 tot_y += y
576 tot_y += spacing
577
578
579 uf_data = uf_info.get_uf('spectrum.error_analysis')
580
581
582 if uf_data.desc != None:
583
584 for i in range(len(uf_data.desc)):
585
586 desc = uf_data.desc[i]
587
588
589 if desc.get_title() == 'Prompt examples':
590 continue
591
592
593 for type, element in desc.element_loop(title=True):
594
595 text = ''
596 if isinstance(element, str):
597 text = element
598
599
600 if type == 'table':
601 text = format_table(uf_tables.get_table(element))
602
603
604 elif type == 'list':
605
606 for j in range(len(element)):
607 text += " - %s\n" % element[j]
608
609
610 elif type == 'item list':
611
612 for j in range(len(element)):
613
614 if element[j][0] in [None, '']:
615 text += " %s\n" % element[j][1]
616 else:
617 text += " %s: %s\n" % (element[j][0], element[j][1])
618
619
620 text_obj = wx.StaticText(panel, -1, text, style=wx.TE_MULTILINE)
621
622
623 if type == 'title':
624 text_obj.SetFont(font.subtitle)
625 elif type == 'paragraph':
626 text_obj.SetFont(font.normal)
627 elif type in ['table', 'verbatim']:
628 text_obj.SetFont(font.modern_small)
629 else:
630 text_obj.SetFont(font.normal)
631
632
633 if type in ['paragraph', 'list', 'item list']:
634 text_obj.Wrap(self._main_size - 20)
635
636
637 x, y = text_obj.GetSizeTuple()
638 tot_y += y
639
640
641 tot_y += spacing
642
643
644 if i != 0 and type == 'title':
645 tot_y += spacing
646
647
648 text_elements.append(text_obj)
649 text_types.append(type)
650
651
652 tot_y -= spacing
653 tot_y += 20
654
655
656 if tot_y > max_y:
657 panel.SetInitialSize((self._main_size, max_y))
658
659
660 else:
661 panel.SetInitialSize((self._main_size, tot_y))
662
663
664 n = len(text_elements)
665 for i in range(n):
666
667 if i > 1 and text_types[i] == 'title':
668 panel_sizer.AddSpacer(spacing)
669
670
671 panel_sizer.Add(text_elements[i], 0, wx.ALIGN_LEFT, 0)
672
673
674 if i != n - 1:
675 panel_sizer.AddSpacer(spacing)
676
677
678 panel.SetSizer(panel_sizer)
679 panel.SetAutoLayout(1)
680 panel.SetupScrolling(scroll_x=False, scroll_y=True)
681 sizer.Add(panel, 0, wx.ALL|wx.EXPAND)
682
683
684 sizer.AddSpacer(5)
685 sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.ALL, 0)
686 sizer.AddSpacer(5)
687