Package gui :: Package analyses :: Module base
[hide private]
[frames] | no frames]

Source Code for Module gui.analyses.base

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009 Michael Bieri                                            # 
  4  # Copyright (C) 2010-2011 Edward d'Auvergne                                   # 
  5  #                                                                             # 
  6  # This file is part of the program relax.                                     # 
  7  #                                                                             # 
  8  # relax is free software; you can redistribute it and/or modify               # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation; either version 2 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # relax is distributed in the hope that it will be useful,                    # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with relax; if not, write to the Free Software                        # 
 20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 21  #                                                                             # 
 22  ############################################################################### 
 23   
 24  # Module docstring. 
 25  """Module containing the base class for all frames.""" 
 26   
 27  # Python module imports. 
 28  from os import sep 
 29  import wx 
 30  from wx.lib import buttons 
 31   
 32  # relax module imports. 
 33  from generic_fns.mol_res_spin import count_spins 
 34  from generic_fns.pipes import cdp_name 
 35   
 36  # relax GUI module imports. 
 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   
44 -class Base_analysis(wx.lib.scrolledpanel.ScrolledPanel):
45 """The base class for all frames.""" 46 47 # Hard coded variables. 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 # Execute the base class method. 73 super(Base_analysis, self).__init__(parent, id=id, pos=pos, size=size, style=style, name=name) 74 75 # Determine the size of the scrollers. 76 self.width_vscroll = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X) 77 78 # Pack a sizer into the panel. 79 box_main = wx.BoxSizer(wx.HORIZONTAL) 80 self.SetSizer(box_main) 81 82 # Build the central sizer, with borders. 83 box_centre = add_border(box_main, border=self.border, packing=wx.HORIZONTAL) 84 85 # Build and pack the main sizer box, then add it to the automatic model-free analysis frame. 86 self.build_main_box(box_centre) 87 88 # Set up the scrolled panel. 89 self.SetAutoLayout(True) 90 self.SetupScrolling(scroll_x=False, scroll_y=True) 91 92 # Bind resize events. 93 self.Bind(wx.EVT_SIZE, self.resize)
94 95
96 - def add_button_open(self, box, parent, icon=paths.icon_16x16.open, text=" Change", fn=None, width=-1, height=-1):
97 """Add a button for opening and changing files and directories. 98 99 @param box: The box element to pack the control into. 100 @type box: wx.BoxSizer instance 101 @param parent: The parent GUI element. 102 @type parent: wx object 103 @keyword icon: The path of the icon to use for the button. 104 @type icon: str 105 @keyword text: The text to display on the button. 106 @type text: str 107 @keyword fn: The function or method to execute when clicking on the button. 108 @type fn: func 109 @keyword width: The minimum width of the control. 110 @type width: int 111 @keyword height: The minimum height of the control. 112 @type height: int 113 @return: The button. 114 @rtype: wx.lib.buttons.ThemedGenBitmapTextButton instance 115 """ 116 117 # The button. 118 button = buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(text)) 119 button.SetBitmapLabel(wx.Bitmap(icon, wx.BITMAP_TYPE_ANY)) 120 121 # The font and button properties. 122 button.SetMinSize((width, height)) 123 button.SetFont(font.normal) 124 125 # Bind the click. 126 self.gui.Bind(wx.EVT_BUTTON, fn, button) 127 128 # Add the button to the box. 129 box.Add(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 130 131 # Return the button. 132 return button
133 134
135 - def add_execute_relax(self, box, method):
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 # A horizontal sizer for the contents. 147 sizer = wx.BoxSizer(wx.HORIZONTAL) 148 149 # A unique ID. 150 id = wx.NewId() 151 152 # The button. 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 # Add the element to the box. 160 box.Add(sizer, 0, wx.ALIGN_RIGHT, 0) 161 162 # Return the button. 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 # The control. 190 field = control(parent, -1, text, min=min, max=max) 191 192 # The font and control properties. 193 field.SetMinSize((width, height)) 194 field.SetFont(font.normal) 195 196 # Add the control to the box. 197 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 198 199 # Return the text field. 200 return field
201 202
203 - def add_spin_systems(self, box, parent):
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 # Add the element. 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 # The label. 236 label = wx.StaticText(parent, -1, text) 237 238 # The font and label properties. 239 label.SetMinSize((width, height)) 240 label.SetFont(font.normal) 241 242 # Add the label to the box. 243 box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 244 245 # Return the label. 246 return label
247 248
249 - def add_subtitle(self, box, text):
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 # The title. 259 label = wx.StaticText(self, -1, text) 260 261 # The font properties. 262 label.SetFont(font.subtitle) 263 264 # Add the subtitle to the box, with spacing. 265 box.AddSpacer(20) 266 box.Add(label) 267 box.AddSpacer(5)
268 269
270 - def add_subsubtitle(self, box, text):
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 # The text. 280 label = wx.StaticText(self, -1, text) 281 282 # The font properties. 283 label.SetFont(font.normal) 284 285 # Add the text to the box, with spacing. 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 # The control. 312 field = control(parent, -1, str_to_gui(text)) 313 314 # The font and control properties. 315 field.SetMinSize((width, height)) 316 field.SetFont(font.normal) 317 318 # Editable (change the colour if not). 319 field.SetEditable(editable) 320 if not editable: 321 colour = self.GetBackgroundColour() 322 field.SetOwnBackgroundColour(colour) 323 324 # Add the control to the box. 325 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 326 327 # Return the text field. 328 return field
329 330
331 - def add_title(self, box, text):
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 # The title. 341 label = wx.StaticText(self, -1, text) 342 343 # The font properties. 344 label.SetFont(font.title) 345 346 # Pack the title, with spacing. 347 box.AddSpacer(10) 348 box.Add(label) 349 box.AddSpacer(5)
350 351
352 - def build_left_box(self):
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 # Use a vertical packing of elements. 360 box = wx.BoxSizer(wx.VERTICAL) 361 362 # Convert the bitmap names to a list. 363 if not isinstance(self.bitmap, list): 364 bitmaps = [self.bitmap] 365 else: 366 bitmaps = self.bitmap 367 368 # Add the bitmaps. 369 for i in range(len(bitmaps)): 370 # The bitmap. 371 bitmap = wx.StaticBitmap(self, -1, wx.Bitmap(bitmaps[i], wx.BITMAP_TYPE_ANY)) 372 373 # Add it. 374 box.Add(bitmap, 0, wx.ADJUST_MINSIZE, 10) 375 376 # Return the box. 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 # Build the left hand box and add to the main box. 388 left_box = self.build_left_box() 389 box.Add(left_box, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 390 391 # Central spacer. 392 box.AddSpacer(self.width_main_separator) 393 394 # Build the right hand box and pack it next to the bitmap. 395 right_box = self.build_right_box() 396 box.Add(right_box, 1, wx.ALL|wx.EXPAND, 0)
397 398
399 - def launch_spin_editor(self, event):
400 """The spin editor GUI element. 401 402 @param event: The wx event. 403 @type event: wx event 404 """ 405 406 # Show the molecule, residue, and spin tree window. 407 self.gui.show_tree(None)
408 409
410 - def observer_register(self, remove=False):
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
421 - def resize(self, event):
422 """The spin editor GUI element. 423 424 @param event: The wx event. 425 @type event: wx event 426 """ 427 428 # Set the virtual size to have the width of the visible size and the height of the virtual size. 429 x = self.GetSize()[0] - self.width_vscroll 430 y = self.GetVirtualSize()[1] 431 self.SetVirtualSize((x, y))
432 433
434 - def spin_count(self):
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 # The data pipe. 442 if hasattr(self.data, 'pipe_name'): 443 pipe = self.data.pipe_name 444 else: 445 pipe = cdp_name() 446 447 # The count. 448 num = count_spins(pipe=pipe) 449 450 # Return the formatted string. 451 return "%s spins loaded and selected" % num
452 453
454 - def update_spin_count(self):
455 """Update the spin count.""" 456 457 # Set the new value. 458 wx.CallAfter(self.spin_systems.SetValue, str_to_gui(self.spin_count()))
459 460 461
462 -class Spectral_error_type_page(UF_page):
463 """The NOE peak intensity reading wizard page for specifying the type of error to be used.""" 464 465 # Class variables. 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 # Intro text. 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 # Spacing. 484 sizer.AddStretchSpacer() 485 486 # A box sizer for placing the box sizer in. 487 sizer2 = wx.BoxSizer(wx.HORIZONTAL) 488 sizer.Add(sizer2, 1, wx.ALL|wx.EXPAND, 0) 489 490 # Bottom spacing. 491 sizer.AddStretchSpacer() 492 493 # A bit of indentation. 494 sizer2.AddStretchSpacer() 495 496 # A vertical sizer for the radio buttons. 497 sizer_radio = wx.BoxSizer(wx.VERTICAL) 498 sizer2.Add(sizer_radio, 1, wx.ALL|wx.EXPAND, 0) 499 500 # The RMSD radio button. 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 # Spacing. 505 sizer_radio.AddSpacer(10) 506 507 # The replicated spectra radio button. 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 # Bind the buttons. 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 # Right side spacing. 516 sizer2.AddStretchSpacer(3) 517 518 # Bottom spacing. 519 sizer.AddStretchSpacer() 520 521 # Set the default selection. 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 # The button. 533 button = event.GetEventObject() 534 535 # RMSD. 536 if button == self.radio_rmsd: 537 self.selection = 'rmsd' 538 elif button == self.radio_repl: 539 self.selection = 'repl'
540