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  import wx 
 28   
 29   
 30  from graphics import WIZARD_IMAGE_PATH, fetch_icon 
 31  from gui.icons import relax_icons 
 32  from gui.misc import gui_raise 
 33  from gui.spin_viewer.splitter import Tree_splitter 
 34  from gui.string_conv import gui_to_str, str_to_gui 
 35  from gui.wizards.wiz_objects import Wiz_page, Wiz_window 
 36  from gui.uf_objects import build_uf_menus, Uf_storage; uf_store = Uf_storage() 
 37  from lib.errors import RelaxNoPipeError 
 38  from pipe_control.pipes import cdp_name, pipe_names 
 39  from status import Status; status = Status() 
 40   
 41   
 43      """A window element for the tree view.""" 
 44   
 46          """Set up the relax prompt.""" 
 47   
 48           
 49          self.gui = kwds.pop('parent') 
 50   
 51           
 52          kwds["style"] = wx.DEFAULT_FRAME_STYLE 
 53          if not status.debug and status.wx_info["os"] != 'darwin': 
 54              kwds["style"] = kwds["style"] | wx.MAXIMIZE 
 55          wx.Frame.__init__(self, *args, **kwds) 
 56   
 57           
 58          if not status.debug and status.wx_info["os"] != 'darwin': 
 59              self.Maximize() 
 60   
 61           
 62          self.SetIcons(relax_icons) 
 63   
 64           
 65          self.size_x = 1000 
 66          self.size_y = 750 
 67   
 68           
 69          sizer = self.setup_window() 
 70   
 71           
 72          self._create_menu() 
 73   
 74           
 75          self.toolbar() 
 76   
 77           
 78          splitter = Tree_splitter(self.gui, self, -1) 
 79          sizer.Add(splitter, 1, wx.EXPAND|wx.ALL, 0) 
 80   
 81           
 82          self.name = 'spin viewer' 
  83   
 84   
 86          """Activate or deactivate certain elements in response to the execution lock.""" 
 87   
 88           
 89          enable = False 
 90          if not status.exec_lock.locked(): 
 91              enable = True 
 92   
 93           
 94          for menu, label in self.menubar.GetMenus(): 
 95               
 96              for item in menu.GetMenuItems(): 
 97                  wx.CallAfter(item.Enable, enable) 
 98   
 99           
100          wx.CallAfter(self.bar.EnableTool, self.spin_loader_id, enable) 
101   
102           
103          wx.CallAfter(self.pipe_name.Enable, enable) 
 104   
105   
107          """Build a menu for the window.""" 
108   
109           
110          self.menubar = wx.MenuBar() 
111          if status.show_gui: 
112              self.SetMenuBar(self.menubar) 
113   
114           
115          self.menu_uf_ids = build_uf_menus(parent=self, menubar=self.menubar) 
 116   
117   
118 -    def Show(self, show=True): 
 139   
140   
142          """Event handler for the refresh action (thread safe). 
143   
144          @keyword event: The wx event. 
145          @type event:    wx event 
146          """ 
147   
148           
149          wx.CallAfter(self.refresh_safe) 
 150   
151   
153          """Refresh the spin viewer window.""" 
154   
155           
156          wx.BeginBusyCursor() 
157   
158           
159          self.update_pipes() 
160   
161           
162          self.tree_panel.update() 
163   
164           
165          self.container.display(self.tree_panel.get_info()) 
166   
167           
168          if wx.IsBusy(): 
169              wx.EndBusyCursor() 
 170   
171   
173          """Event handler for the close window action. 
174   
175          @keyword event: The wx event. 
176          @type event:    wx event 
177          """ 
178   
179           
180          status.observers.gui_uf.unregister(self.name) 
181          status.observers.pipe_alteration.unregister(self.name) 
182          status.observers.exec_lock.unregister(self.name) 
183   
184           
185          self.Hide() 
 186   
187   
189          """The spin loading wizard. 
190   
191          @keyword event: The wx event. 
192          @type event:    wx event 
193          """ 
194   
195           
196          if not cdp_name(): 
197              gui_raise(RelaxNoPipeError()) 
198              return 
199   
200           
201          wx.BeginBusyCursor() 
202   
203           
204          self.wizard = Wiz_window(parent=self, size_x=1000, size_y=800, title="Load spins") 
205          self.page_indices = {} 
206   
207           
208          self.page_method = Load_method_page(self.wizard) 
209          self.page_indices['method'] = self.wizard.add_page(self.page_method, apply_button=True, skip_button=False) 
210          self.wizard.set_seq_next_fn(self.page_indices['method'], self.wizard_page_after_load_method) 
211   
212           
213          page = uf_store['sequence.read'].create_page(self.wizard) 
214          self.page_indices['sequence.read'] = self.wizard.add_page(page, skip_button=True) 
215          self.wizard.set_seq_next_fn(self.page_indices['sequence.read'], self.wizard_page_after_sequence_read) 
216   
217           
218          page = uf_store['structure.read_pdb'].create_page(self.wizard) 
219          self.page_indices['structure.read_pdb'] = self.wizard.add_page(page, skip_button=True) 
220          self.wizard.set_seq_next_fn(self.page_indices['structure.read_pdb'], self.wizard_page_after_structure_read) 
221   
222           
223          page = uf_store['structure.read_xyz'].create_page(self.wizard) 
224          self.page_indices['structure.read_xyz'] = self.wizard.add_page(page, skip_button=True) 
225          self.wizard.set_seq_next_fn(self.page_indices['structure.read_xyz'], self.wizard_page_after_structure_read) 
226   
227           
228          page = uf_store['spectrum.read_spins'].create_page(self.wizard) 
229          self.page_indices['spectrum.read_spins'] = self.wizard.add_page(page, skip_button=True) 
230          self.wizard.set_seq_next_fn(self.page_indices['spectrum.read_spins'], self.wizard_page_after_sequence_read) 
231   
232           
233          page = uf_store['structure.load_spins'].create_page(self.wizard) 
234          self.page_indices['structure.load_spins'] = self.wizard.add_page(page) 
235   
236           
237          page = Finish_page(self.wizard) 
238          self.page_indices['fin'] = self.wizard.add_page(page, apply_button=False, skip_button=False) 
239   
240           
241          if wx.IsBusy(): 
242              wx.EndBusyCursor() 
243   
244           
245          self.wizard.run() 
 246   
247   
249          """Set up the window. 
250   
251          @return:    The sizer object. 
252          @rtype:     wx.Sizer instance 
253          """ 
254   
255           
256          self.SetTitle("The spin viewer") 
257   
258           
259          sizer = wx.BoxSizer(wx.VERTICAL) 
260          self.SetSizer(sizer) 
261   
262           
263          self.Bind(wx.EVT_CLOSE, self.handler_close) 
264   
265           
266          self.SetSize((self.size_x, self.size_y)) 
267   
268           
269          return sizer 
 270   
271   
307   
308   
310          """Catch the user function call to properly specify the parent window. 
311   
312          @keyword event: The wx event. 
313          @type event:    wx event 
314          """ 
315   
316           
317          uf_id = event.GetId() 
318   
319           
320          name = uf_store.get_uf(uf_id) 
321   
322           
323          uf_store[name](event=event, wx_parent=self) 
 324   
325   
373   
374   
376          """Set the page after the load method choice. 
377   
378          @return:    The index of the next page. 
379          @rtype:     int 
380          """ 
381   
382           
383          if self.page_method.selection == 'sequence': 
384              return self.page_indices['sequence.read'] 
385   
386           
387          elif self.page_method.selection == 'new pdb': 
388              return self.page_indices['structure.read_pdb'] 
389   
390           
391          elif self.page_method.selection == 'new xyz': 
392              return self.page_indices['structure.read_xyz'] 
393   
394           
395          elif self.page_method.selection == 'new spectrum': 
396              return self.page_indices['spectrum.read_spins'] 
397   
398           
399          elif self.page_method.selection == 'preload': 
400              return self.page_indices['structure.load_spins'] 
 401   
402   
404          """Set the page after the sequence.read user function page. 
405   
406          @return:    The index of the last page. 
407          @rtype:     int 
408          """ 
409   
410           
411          return  self.page_indices['fin'] 
 412   
413   
415          """Set the page after the structure.read_* user function pages. 
416   
417          @return:    The index of the structure.load_spins page. 
418          @rtype:     int 
419          """ 
420   
421           
422          return  self.page_indices['structure.load_spins'] 
  423   
424   
425   
426 -class Finish_page(Wiz_page): 
 427      """The terminating wizard page.""" 
428   
429       
430      image_path = WIZARD_IMAGE_PATH + 'spin.png' 
431      main_text = 'The spin systems should now have been loaded into the relax data store.' 
432      title = 'Spin loading complete' 
433   
434 -    def add_contents(self, sizer): 
 435          """This blank method is needed so that the page shows and does nothing. 
436   
437          @param sizer:   A sizer object. 
438          @type sizer:    wx.Sizer instance 
439          """ 
  440   
441   
442   
443 -class Load_method_page(Wiz_page): 
 444      """The wizard page for specifying how to load spins.""" 
445   
446       
447      image_path = WIZARD_IMAGE_PATH + 'spin.png' 
448      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.' 
449      title = 'Spin loading' 
450   
451   
452 -    def add_contents(self, sizer): 
 453          """Add the specific GUI elements. 
454   
455          @param sizer:   A sizer object. 
456          @type sizer:    wx.Sizer instance 
457          """ 
458   
459           
460          msg = "Please specify by which method spins should be loaded into the relax data store:" 
461          text = wx.StaticText(self, -1, msg) 
462          text.Wrap(self._main_size) 
463          sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 
464   
465           
466          sizer.AddStretchSpacer() 
467   
468           
469          sizer2 = wx.BoxSizer(wx.HORIZONTAL) 
470          sizer.Add(sizer2, 1, wx.ALL|wx.EXPAND, 0) 
471   
472           
473          sizer.AddStretchSpacer() 
474   
475           
476          sizer2.AddStretchSpacer() 
477   
478           
479          sizer_radio = wx.BoxSizer(wx.VERTICAL) 
480          sizer2.Add(sizer_radio, 1, wx.ALL|wx.EXPAND, 0) 
481   
482           
483          self.preload_flag = False 
484          if hasattr(cdp, 'structure') and not cdp.structure.empty(): 
485              self.preload_flag = True 
486   
487           
488          if self.preload_flag: 
489               
490              self.radio_preload = wx.RadioButton(self, -1, "From a pre-loaded structure.", style=wx.RB_GROUP) 
491              sizer_radio.Add(self.radio_preload, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 
492   
493               
494              sizer_radio.AddSpacer(20) 
495   
496           
497          if self.preload_flag: 
498              style = 0 
499          else: 
500              style = wx.RB_GROUP 
501          self.radio_seq = wx.RadioButton(self, -1, "From a file containing sequence data.", style=style) 
502          sizer_radio.Add(self.radio_seq, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 
503   
504           
505          sizer_radio.AddSpacer(20) 
506   
507           
508          self.radio_new_pdb = wx.RadioButton(self, -1, "From a new PDB structure file.") 
509          sizer_radio.Add(self.radio_new_pdb, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 
510   
511           
512          sizer_radio.AddSpacer(20) 
513   
514           
515          self.radio_new_xyz = wx.RadioButton(self, -1, "From a new XYZ structure file.") 
516          sizer_radio.Add(self.radio_new_xyz, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 
517   
518           
519          sizer_radio.AddSpacer(20) 
520   
521           
522          self.radio_new_spectrum = wx.RadioButton(self, -1, "From a peak list or spectrum formatted file.") 
523          sizer_radio.Add(self.radio_new_spectrum, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 
524   
525           
526          self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_seq) 
527          self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_new_pdb) 
528          self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_new_xyz) 
529          self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_new_spectrum) 
530          if self.preload_flag: 
531              self.Bind(wx.EVT_RADIOBUTTON, self._on_select, self.radio_preload) 
532   
533           
534          sizer2.AddStretchSpacer(3) 
535   
536           
537          sizer.AddStretchSpacer() 
538   
539           
540          if self.preload_flag: 
541              self.selection = 'preload' 
542          else: 
543              self.selection = 'sequence' 
 544   
545   
546 -    def _on_select(self, event=None): 
 547          """Handle the radio button switching. 
548   
549          @keyword event: The wx event. 
550          @type event:    wx event 
551          """ 
552   
553           
554          button = event.GetEventObject() 
555   
556           
557          if button == self.radio_seq: 
558              self.selection = 'sequence' 
559          elif button == self.radio_new_pdb: 
560              self.selection = 'new pdb' 
561          elif button == self.radio_new_xyz: 
562              self.selection = 'new xyz' 
563          elif button == self.radio_new_spectrum: 
564              self.selection = 'new spectrum' 
565          elif self.preload_flag and button == self.radio_preload: 
566              self.selection = 'preload' 
  567