1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """The spin viewer frame."""
25
26
27
28 import wx
29
30
31 from generic_fns import structure
32 from generic_fns.pipes import cdp_name, pipe_names
33 from status import Status; status = Status()
34 from relax_errors import RelaxNoPipeError
35
36
37 from gui.paths import icon_32x32, WIZARD_IMAGE_PATH
38 from gui.components.menu import build_menu_item
39 from gui.icons import relax_icons
40 from gui.menu import Uf_menus
41 from gui.misc import gui_raise, gui_to_str, str_to_gui
42 from gui.spin_viewer.splitter import Tree_splitter
43 from gui.user_functions import User_functions, sequence, structure; user_functions = User_functions()
44 from gui.wizard import Wiz_page, Wiz_window
45
46
48 """A window element for the tree view."""
49
51 """Set up the relax prompt."""
52
53
54 self.gui = kwds.pop('parent')
55
56
57 kwds["style"] = wx.DEFAULT_FRAME_STYLE
58 if not status.debug and status.wx_info["os"] != 'darwin':
59 kwds["style"] = kwds["style"] | wx.MAXIMIZE
60 wx.Frame.__init__(self, *args, **kwds)
61
62
63 if not status.debug and status.wx_info["os"] != 'darwin':
64 self.Maximize()
65
66
67 self.SetIcons(relax_icons)
68
69
70 self.size_x = 1000
71 self.size_y = 750
72
73
74 sizer = self.setup_window()
75
76
77 self._create_menu()
78
79
80 self.toolbar()
81
82
83 splitter = Tree_splitter(self.gui, self, -1)
84 sizer.Add(splitter, 1, wx.EXPAND|wx.ALL, 0)
85
86
87 self.name = 'spin viewer'
88
89
91 """Activate or deactivate certain elements in response to the execution lock."""
92
93
94 enable = False
95 if not status.exec_lock.locked():
96 enable = True
97
98
99 for menu, label in self.menubar.GetMenus():
100
101 for item in menu.GetMenuItems():
102 wx.CallAfter(item.Enable, enable)
103
104
105 wx.CallAfter(self.bar.EnableTool, self.spin_loader_id, enable)
106
107
108 wx.CallAfter(self.pipe_name.Enable, enable)
109
110
112 """Build a menu for the window."""
113
114
115 self.menubar = wx.MenuBar()
116 if status.show_gui:
117 self.SetMenuBar(self.menubar)
118
119
120 menu = wx.Menu()
121 uf_menus = Uf_menus(parent=self, menu=menu)
122 title = "&User functions"
123 self.menubar.Append(menu, title)
124
125
126 - def Show(self, show=True):
147
148
150 """Event handler for the refresh action (thread safe).
151
152 @param event: The wx event.
153 @type event: wx event
154 """
155
156
157 wx.CallAfter(self.refresh_safe)
158
159
161 """Refresh the spin viewer window."""
162
163
164 wx.BeginBusyCursor()
165
166
167 self.update_pipes()
168
169
170 self.tree_panel.update()
171
172
173 self.container.display(self.tree_panel.get_info())
174
175
176 if wx.IsBusy():
177 wx.EndBusyCursor()
178
179
181 """Event handler for the close window action.
182
183 @param event: The wx event.
184 @type event: wx event
185 """
186
187
188 status.observers.gui_uf.unregister(self.name)
189 status.observers.pipe_alteration.unregister(self.name)
190 status.observers.exec_lock.unregister(self.name)
191
192
193 self.Hide()
194
195
197 """The spin loading wizard.
198
199 @param event: The wx event.
200 @type event: wx event
201 """
202
203
204 if not cdp_name():
205 gui_raise(RelaxNoPipeError())
206 return
207
208
209 wx.BeginBusyCursor()
210
211
212 self.wizard = Wiz_window(parent=self, size_x=800, size_y=700, title="Load spins")
213 self.page_indices = {}
214
215
216 self.page_method = Load_method_page(self.wizard)
217 self.page_indices['method'] = self.wizard.add_page(self.page_method, apply_button=True, skip_button=False)
218 self.wizard.set_seq_next_fn(self.page_indices['method'], self.wizard_page_after_load_method)
219
220
221 page = sequence.Read_page(self.wizard)
222 self.page_indices['sequence.read'] = self.wizard.add_page(page, skip_button=True)
223 self.wizard.set_seq_next_fn(self.page_indices['sequence.read'], self.wizard_page_after_sequence_read)
224
225
226 page = structure.Read_pdb_page(self.wizard)
227 self.page_indices['structure.read_pdb'] = self.wizard.add_page(page, skip_button=True)
228 self.wizard.set_seq_next_fn(self.page_indices['structure.read_pdb'], self.wizard_page_after_structure_read)
229
230
231 page = structure.Read_xyz_page(self.wizard)
232 self.page_indices['structure.read_xyz'] = self.wizard.add_page(page, skip_button=True)
233 self.wizard.set_seq_next_fn(self.page_indices['structure.read_xyz'], self.wizard_page_after_structure_read)
234
235
236 page = structure.Load_spins_page(self.wizard)
237 self.page_indices['structure.load_spins'] = self.wizard.add_page(page)
238
239
240 page = Finish_page(self.wizard)
241 self.page_indices['fin'] = self.wizard.add_page(page, apply_button=False, skip_button=False)
242
243
244 if wx.IsBusy():
245 wx.EndBusyCursor()
246
247
248 self.wizard.run()
249
250
252 """Set up the window.
253
254 @return: The sizer object.
255 @rtype: wx.Sizer instance
256 """
257
258
259 self.SetTitle("The spin viewer")
260
261
262 sizer = wx.BoxSizer(wx.VERTICAL)
263 self.SetSizer(sizer)
264
265
266 self.Bind(wx.EVT_CLOSE, self.handler_close)
267
268
269 self.SetSize((self.size_x, self.size_y))
270
271
272 return sizer
273
274
308
309
357
358
360 """Set the page after the load method choice.
361
362 @return: The index of the next page.
363 @rtype: int
364 """
365
366
367 if self.page_method.selection == 'sequence':
368 return self.page_indices['sequence.read']
369
370
371 elif self.page_method.selection == 'new pdb':
372 return self.page_indices['structure.read_pdb']
373
374
375 elif self.page_method.selection == 'new xyz':
376 return self.page_indices['structure.read_xyz']
377
378
379 elif self.page_method.selection == 'preload':
380 return self.page_indices['structure.load_spins']
381
382
384 """Set the page after the sequence.read user function page.
385
386 @return: The index of the last page.
387 @rtype: int
388 """
389
390
391 return self.page_indices['fin']
392
393
395 """Set the page after the structure.read_* user function pages.
396
397 @return: The index of the structure.load_spins page.
398 @rtype: int
399 """
400
401
402 return self.page_indices['structure.load_spins']
403
404
405
406 -class Finish_page(Wiz_page):
407 """The terminating wizard page."""
408
409
410 image_path = WIZARD_IMAGE_PATH + 'spin.png'
411 main_text = 'The spin systems should now have been loaded into the relax data store.'
412 title = 'Spin loading complete'
413
414 - def add_contents(self, sizer):
415 """This blank method is needed so that the page shows and does nothing.
416
417 @param sizer: A sizer object.
418 @type sizer: wx.Sizer instance
419 """
420
421
422
423 -class Load_method_page(Wiz_page):
424 """The wizard page for specifying how to load spins."""
425
426
427 image_path = WIZARD_IMAGE_PATH + 'spin.png'
428 main_text = 'Select the method for loading spins into relax. Two options are possible: the first is to read sequence information out of a text file via the sequence.read user function; the second is to read in a 3D structure file via the structure.read_pdb user function and then to load the spins from this structure using the structure.load_spins user function.'
429 title = 'Spin loading'
430
431
432 - def add_contents(self, sizer):
433 """Add the specific GUI elements.
434
435 @param sizer: A sizer object.
436 @type sizer: wx.Sizer instance
437 """
438
439
440 msg = "Please specify by which method spins should be loaded into the relax data store:"
441 text = wx.StaticText(self, -1, msg)
442 text.Wrap(self._main_size)
443 sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
444
445
446 sizer.AddStretchSpacer()
447
448
449 sizer2 = wx.BoxSizer(wx.HORIZONTAL)
450 sizer.Add(sizer2, 1, wx.ALL|wx.EXPAND, 0)
451
452
453 sizer.AddStretchSpacer()
454
455
456 sizer2.AddStretchSpacer()
457
458
459 sizer_radio = wx.BoxSizer(wx.VERTICAL)
460 sizer2.Add(sizer_radio, 1, wx.ALL|wx.EXPAND, 0)
461
462
463 self.preload_flag = False
464 if hasattr(cdp, 'structure') and not cdp.structure.empty():
465 self.preload_flag = True
466
467
468 if self.preload_flag:
469
470 self.radio_preload = wx.RadioButton(self, -1, "From a pre-loaded structure.", style=wx.RB_GROUP)
471 sizer_radio.Add(self.radio_preload, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
472
473
474 sizer_radio.AddSpacer(20)
475
476
477 if self.preload_flag:
478 style = 0
479 else:
480 style = wx.RB_GROUP
481 self.radio_seq = wx.RadioButton(self, -1, "From a file containing sequence data.", style=style)
482 sizer_radio.Add(self.radio_seq, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
483
484
485 sizer_radio.AddSpacer(20)
486
487
488 self.radio_new_pdb = wx.RadioButton(self, -1, "From a new PDB structure file.")
489 sizer_radio.Add(self.radio_new_pdb, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
490
491
492 sizer_radio.AddSpacer(20)
493
494
495 self.radio_new_xyz = wx.RadioButton(self, -1, "From a new XYZ structure file.")
496 sizer_radio.Add(self.radio_new_xyz, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
497
498
499 self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_seq)
500 self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_new_pdb)
501 self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_new_xyz)
502 if self.preload_flag:
503 self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_preload)
504
505
506 sizer2.AddStretchSpacer(3)
507
508
509 sizer.AddStretchSpacer()
510
511
512 if self.preload_flag:
513 self.selection = 'preload'
514 else:
515 self.selection = 'sequence'
516
517
518 - def _on_select(self, event):
519 """Handle the radio button switching.
520
521 @param event: The wx event.
522 @type event: wx event
523 """
524
525
526 button = event.GetEventObject()
527
528
529 if button == self.radio_seq:
530 self.selection = 'sequence'
531 elif button == self.radio_new_pdb:
532 self.selection = 'new pdb'
533 elif button == self.radio_new_xyz:
534 self.selection = 'new xyz'
535 elif self.preload_flag and button == self.radio_preload:
536 self.selection = 'preload'
537