1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24  """Module containing the base class for all frames.""" 
 25   
 26   
 27  import wx 
 28  from wx.lib import buttons 
 29  from wx.lib import scrolledpanel 
 30    
 31   
 32  from graphics import IMAGE_PATH, fetch_icon 
 33  from gui.analyses.elements.text_element import Text_ctrl 
 34  from gui.fonts import font 
 35  from gui.misc import add_border, bitmap_setup 
 36  from gui.string_conv import str_to_gui 
 37  from pipe_control.mol_res_spin import count_spins 
 38  from pipe_control.pipes import cdp_name, has_pipe 
 39   
 40   
 42      """The base class for all frames.""" 
 43   
 44       
 45      border = 10 
 46      size_graphic_panel = 200 
 47      spacer_horizontal = 5 
 48      width_text = 240 
 49      width_button = 100 
 50      width_main_separator = 40 
 51   
 52 -    def __init__(self, parent, id=wx.ID_ANY, pos=None, size=None, style=None, name=None, gui=None): 
  53          """Initialise the scrolled window. 
 54   
 55          @param parent:  The parent wx element. 
 56          @type parent:   wx object 
 57          @keyword id:    The unique ID number. 
 58          @type id:       int 
 59          @keyword pos:   The position. 
 60          @type pos:      wx.Size object 
 61          @keyword size:  The size. 
 62          @type size:     wx.Size object 
 63          @keyword style: The style. 
 64          @type style:    int 
 65          @keyword name:  The name for the panel. 
 66          @type name:     unicode 
 67          """ 
 68   
 69           
 70          super(Base_analysis, self).__init__(parent, id=id, pos=pos, size=size, style=style, name=name) 
 71   
 72           
 73          self.width_vscroll = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X) 
 74   
 75           
 76          box_main = wx.BoxSizer(wx.HORIZONTAL) 
 77          self.SetSizer(box_main) 
 78   
 79           
 80          box_centre = add_border(box_main, border=self.border, packing=wx.HORIZONTAL) 
 81   
 82           
 83          self.build_main_box(box_centre) 
 84   
 85           
 86          self.SetAutoLayout(True) 
 87          self.SetupScrolling(scroll_x=False, scroll_y=True) 
 88   
 89           
 90          self.Bind(wx.EVT_SIZE, self.resize) 
  91   
 92   
130   
131   
133          """Create and add the analysis execution GUI element to the given box. 
134   
135          @param box:     The box element to pack the analysis execution GUI element into. 
136          @type box:      wx.BoxSizer instance 
137          @param method:  The method to execute when the button is clicked. 
138          @type method:   method 
139          @return:        The button. 
140          @rtype:         wx.lib.buttons.ThemedGenBitmapTextButton instance 
141          """ 
142   
143           
144          sizer = wx.BoxSizer(wx.HORIZONTAL) 
145   
146           
147          button = buttons.ThemedGenBitmapTextButton(self, -1, None, " Execute") 
148          button.SetBitmapLabel(wx.Bitmap(IMAGE_PATH+'relax_start.gif', wx.BITMAP_TYPE_ANY)) 
149          button.SetFont(font.normal) 
150          self.gui.Bind(wx.EVT_BUTTON, method, button) 
151          sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 
152   
153           
154          box.Add(sizer, 0, wx.ALIGN_RIGHT, 0) 
155   
156           
157          return button 
 158   
159   
160 -    def add_spin_control(self, box, parent, text='', min=None, max=None, control=wx.SpinCtrl, width=-1, height=-1): 
 161          """Add a text control field to the box. 
162   
163          @param box:         The box element to pack the control into. 
164          @type box:          wx.BoxSizer instance 
165          @param parent:      The parent GUI element. 
166          @type parent:       wx object 
167          @keyword text:      The default text of the control. 
168          @type text:         str 
169          @keyword min:       The minimum value allowed. 
170          @type min:          int 
171          @keyword max:       The maximum value allowed. 
172          @type max:          int 
173          @keyword control:   The control class to use. 
174          @type control:      wx.TextCtrl derived class 
175          @keyword width:     The minimum width of the control. 
176          @type width:        int 
177          @keyword height:    The minimum height of the control. 
178          @type height:       int 
179          @return:            The text control object. 
180          @rtype:             control object 
181          """ 
182   
183           
184          field = control(parent, -1, text, min=min, max=max) 
185   
186           
187          field.SetMinSize((width, height)) 
188          field.SetFont(font.normal) 
189   
190           
191          box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 
192   
193           
194          return field 
 195   
196   
198          """Add a special control for spin systems. 
199   
200          Only one of these per analysis are allowed. 
201   
202          @param box:         The box element to pack the control into. 
203          @type box:          wx.BoxSizer instance 
204          @param parent:      The parent GUI element. 
205          @type parent:       wx object 
206          """ 
207   
208           
209          self.spin_systems = Text_ctrl(box, self, text="Spin systems:", button_text=" Spin editor", default=self.spin_count(), tooltip="The currently loaded molecule, residue and spin sequence.", tooltip_button="Launch the spin editor window for modifying the molecule, residue and spin sequence.", icon=fetch_icon('relax.spin', "16x16"), fn=self.launch_spin_editor, editable=False, button=True, width_text=self.width_text, width_button=self.width_button, spacer=self.spacer_horizontal) 
 210   
211   
212 -    def add_static_text(self, box, parent, text='', width=-1, height=-1): 
 213          """Add a text control field to the box. 
214   
215          @param box:         The box element to pack the control into. 
216          @type box:          wx.BoxSizer instance 
217          @param parent:      The parent GUI element. 
218          @type parent:       wx object 
219          @keyword text:      The default text of the control. 
220          @type text:         str 
221          @keyword width:     The minimum width of the control. 
222          @type width:        int 
223          @keyword height:    The minimum height of the control. 
224          @type height:       int 
225          @return:            The label. 
226          @rtype:             wx.StaticText instance 
227          """ 
228   
229           
230          label = wx.StaticText(parent, -1, text) 
231   
232           
233          label.SetMinSize((width, height)) 
234          label.SetFont(font.normal) 
235   
236           
237          box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 
238   
239           
240          return label 
 241   
242   
244          """Create and add the subtitle. 
245   
246          @param box:     The box element to pack the subtitle into. 
247          @type box:      wx.BoxSizer instance 
248          @param text:    The text of the subtitle. 
249          @type text:     str 
250          """ 
251   
252           
253          label = wx.StaticText(self, -1, text) 
254   
255           
256          label.SetFont(font.subtitle) 
257   
258           
259          box.AddSpacer(20) 
260          box.Add(label) 
261          box.AddSpacer(5) 
 262   
263   
265          """Create and add the subsubtitle. 
266   
267          @param box:     The box element to pack the text into. 
268          @type box:      wx.BoxSizer instance 
269          @param text:    The text of the subsubtitle. 
270          @type text:     str 
271          """ 
272   
273           
274          label = wx.StaticText(self, -1, text) 
275   
276           
277          label.SetFont(font.normal) 
278   
279           
280          box.AddSpacer(10) 
281          box.Add(label) 
 282   
283   
284 -    def add_text_control(self, box, parent, text='', control=wx.TextCtrl, width=-1, height=-1, editable=True): 
 285          """Add a text control field to the box. 
286   
287          @param box:         The box element to pack the control into. 
288          @type box:          wx.BoxSizer instance 
289          @param parent:      The parent GUI element. 
290          @type parent:       wx object 
291          @keyword text:      The default text of the control. 
292          @type text:         str 
293          @keyword control:   The control class to use. 
294          @type control:      wx.TextCtrl derived class 
295          @keyword width:     The minimum width of the control. 
296          @type width:        int 
297          @keyword height:    The minimum height of the control. 
298          @type height:       int 
299          @keyword editable:  A flag specifying if the control is editable or not. 
300          @type editable:     bool 
301          @return:            The text control object. 
302          @rtype:             control object 
303          """ 
304   
305           
306          field = control(parent, -1, str_to_gui(text)) 
307   
308           
309          field.SetMinSize((width, height)) 
310          field.SetFont(font.normal) 
311   
312           
313          field.SetEditable(editable) 
314          if not editable: 
315              colour = self.GetBackgroundColour() 
316              field.SetOwnBackgroundColour(colour) 
317   
318           
319          box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 
320   
321           
322          return field 
 323   
324   
325 -    def add_title(self, box, text, top_spacing=10, bottom_spacing=15): 
 326          """Create and add the frame title. 
327   
328          @param box:     The box element to pack the frame title into. 
329          @type box:      wx.BoxSizer instance 
330          @param text:    The text of the title. 
331          @type text:     str 
332          """ 
333   
334           
335          label = wx.StaticText(self, -1, text) 
336   
337           
338          label.SetFont(font.roman_title_italic) 
339   
340           
341          box.AddSpacer(top_spacing) 
342          box.Add(label) 
343          box.AddSpacer(bottom_spacing) 
 344   
345   
347          """Construct the left hand box to pack into the automatic Rx analysis frame. 
348   
349          @return:    The left hand box element containing the bitmap. 
350          @rtype:     wx.BoxSizer instance 
351          """ 
352   
353           
354          box = wx.BoxSizer(wx.VERTICAL) 
355   
356           
357          if not isinstance(self.bitmap, list): 
358              bitmaps = [self.bitmap] 
359          else: 
360              bitmaps = self.bitmap 
361   
362           
363          for i in range(len(bitmaps)): 
364               
365              bitmap = wx.StaticBitmap(self, -1, bitmap_setup(bitmaps[i])) 
366   
367               
368              box.Add(bitmap, 0, wx.ADJUST_MINSIZE, 10) 
369   
370           
371          return box 
 372   
373   
374 -    def build_main_box(self, box): 
 375          """Construct the highest level box to pack into the automatic analysis frames. 
376   
377          @param box: The horizontal box element to pack the elements into. 
378          @type box:  wx.BoxSizer instance 
379          """ 
380   
381           
382          left_box = self.build_left_box() 
383          box.Add(left_box, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
384   
385           
386          box.AddSpacer(self.width_main_separator) 
387   
388           
389          right_box = self.build_right_box() 
390          box.Add(right_box, 1, wx.ALL|wx.EXPAND, 0) 
 391   
392   
394          """The spin editor GUI element. 
395   
396          @param event:   The wx event. 
397          @type event:    wx event 
398          """ 
399   
400           
401          self.gui.show_tree(None) 
 402   
403   
405          """Register and unregister methods with the observer objects. 
406   
407          This is a dummy method. 
408   
409   
410          @keyword remove:    If set to True, then the methods will be unregistered. 
411          @type remove:       False 
412          """ 
 413   
414   
416          """The spin editor GUI element. 
417   
418          @param event:   The wx event. 
419          @type event:    wx event 
420          """ 
421   
422           
423          x = self.GetSize()[0] - self.width_vscroll 
424          y = self.GetVirtualSize()[1] 
425          self.SetVirtualSize((x, y)) 
 426   
427   
429          """Count the number of loaded spins, returning a string formatted as 'xxx spins loaded'. 
430   
431          @return:    The number of loaded spins in the format 'xxx spins loaded'. 
432          @rtype:     str 
433          """ 
434   
435           
436          if hasattr(self.data, 'pipe_name'): 
437              pipe = self.data.pipe_name 
438          else: 
439              pipe = cdp_name() 
440   
441           
442          if not has_pipe(pipe): 
443              num = 0 
444          else: 
445              num = count_spins(pipe=pipe) 
446   
447           
448          return "%s spins loaded and selected" % num 
 449   
450   
 456