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

Source Code for Module gui.analyses.base

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-2010 Michael Bieri                                       # 
  4  # Copyright (C) 2009-2012 Edward d'Auvergne                                   # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program 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 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """Module containing the base class for all frames.""" 
 25   
 26  # Python module imports. 
 27  import wx 
 28  from wx.lib import buttons 
 29  from wx.lib import scrolledpanel 
 30    
 31  # relax module imports. 
 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   
41 -class Base_analysis(scrolledpanel.ScrolledPanel):
42 """The base class for all frames.""" 43 44 # Hard coded variables. 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 # Execute the base class method. 70 super(Base_analysis, self).__init__(parent, id=id, pos=pos, size=size, style=style, name=name) 71 72 # Determine the size of the scrollers. 73 self.width_vscroll = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X) 74 75 # Pack a sizer into the panel. 76 box_main = wx.BoxSizer(wx.HORIZONTAL) 77 self.SetSizer(box_main) 78 79 # Build the central sizer, with borders. 80 box_centre = add_border(box_main, border=self.border, packing=wx.HORIZONTAL) 81 82 # Build and pack the main sizer box, then add it to the automatic model-free analysis frame. 83 self.build_main_box(box_centre) 84 85 # Set up the scrolled panel. 86 self.SetAutoLayout(True) 87 self.SetupScrolling(scroll_x=False, scroll_y=True) 88 89 # Bind resize events. 90 self.Bind(wx.EVT_SIZE, self.resize)
91 92
93 - def add_button_open(self, box, parent, icon=fetch_icon('oxygen.actions.document-open', "16x16"), text=" Change", fn=None, width=-1, height=-1):
94 """Add a button for opening and changing files and directories. 95 96 @param box: The box element to pack the control into. 97 @type box: wx.BoxSizer instance 98 @param parent: The parent GUI element. 99 @type parent: wx object 100 @keyword icon: The path of the icon to use for the button. 101 @type icon: str 102 @keyword text: The text to display on the button. 103 @type text: str 104 @keyword fn: The function or method to execute when clicking on the button. 105 @type fn: func 106 @keyword width: The minimum width of the control. 107 @type width: int 108 @keyword height: The minimum height of the control. 109 @type height: int 110 @return: The button. 111 @rtype: wx.lib.buttons.ThemedGenBitmapTextButton instance 112 """ 113 114 # The button. 115 button = buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(text)) 116 button.SetBitmapLabel(wx.Bitmap(icon, wx.BITMAP_TYPE_ANY)) 117 118 # The font and button properties. 119 button.SetMinSize((width, height)) 120 button.SetFont(font.normal) 121 122 # Bind the click. 123 self.gui.Bind(wx.EVT_BUTTON, fn, button) 124 125 # Add the button to the box. 126 box.Add(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 127 128 # Return the button. 129 return button
130 131
132 - def add_execute_analysis(self, box, method):
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 # A horizontal sizer for the contents. 144 sizer = wx.BoxSizer(wx.HORIZONTAL) 145 146 # The button. 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 # Add the element to the box. 154 box.Add(sizer, 0, wx.ALIGN_RIGHT, 0) 155 156 # Return the button. 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 # The control. 184 field = control(parent, -1, text, min=min, max=max) 185 186 # The font and control properties. 187 field.SetMinSize((width, height)) 188 field.SetFont(font.normal) 189 190 # Add the control to the box. 191 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 192 193 # Return the text field. 194 return field
195 196
197 - def add_spin_systems(self, box, parent):
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 # Add the element. 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 # The label. 230 label = wx.StaticText(parent, -1, text) 231 232 # The font and label properties. 233 label.SetMinSize((width, height)) 234 label.SetFont(font.normal) 235 236 # Add the label to the box. 237 box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 238 239 # Return the label. 240 return label
241 242
243 - def add_subtitle(self, box, text):
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 # The title. 253 label = wx.StaticText(self, -1, text) 254 255 # The font properties. 256 label.SetFont(font.subtitle) 257 258 # Add the subtitle to the box, with spacing. 259 box.AddSpacer(20) 260 box.Add(label) 261 box.AddSpacer(5)
262 263
264 - def add_subsubtitle(self, box, text):
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 # The text. 274 label = wx.StaticText(self, -1, text) 275 276 # The font properties. 277 label.SetFont(font.normal) 278 279 # Add the text to the box, with spacing. 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 # The control. 306 field = control(parent, -1, str_to_gui(text)) 307 308 # The font and control properties. 309 field.SetMinSize((width, height)) 310 field.SetFont(font.normal) 311 312 # Editable (change the colour if not). 313 field.SetEditable(editable) 314 if not editable: 315 colour = self.GetBackgroundColour() 316 field.SetOwnBackgroundColour(colour) 317 318 # Add the control to the box. 319 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 320 321 # Return the text field. 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 # The title. 335 label = wx.StaticText(self, -1, text) 336 337 # The font properties. 338 label.SetFont(font.roman_title_italic) 339 340 # Pack the title, with spacing. 341 box.AddSpacer(top_spacing) 342 box.Add(label) 343 box.AddSpacer(bottom_spacing)
344 345
346 - def build_left_box(self):
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 # Use a vertical packing of elements. 354 box = wx.BoxSizer(wx.VERTICAL) 355 356 # Convert the bitmap names to a list. 357 if not isinstance(self.bitmap, list): 358 bitmaps = [self.bitmap] 359 else: 360 bitmaps = self.bitmap 361 362 # Add the bitmaps. 363 for i in range(len(bitmaps)): 364 # The bitmap. 365 bitmap = wx.StaticBitmap(self, -1, bitmap_setup(bitmaps[i])) 366 367 # Add it. 368 box.Add(bitmap, 0, wx.ADJUST_MINSIZE, 10) 369 370 # Return the box. 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 # Build the left hand box and add to the main box. 382 left_box = self.build_left_box() 383 box.Add(left_box, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 384 385 # Central spacer. 386 box.AddSpacer(self.width_main_separator) 387 388 # Build the right hand box and pack it next to the bitmap. 389 right_box = self.build_right_box() 390 box.Add(right_box, 1, wx.ALL|wx.EXPAND, 0)
391 392
393 - def launch_spin_editor(self, event):
394 """The spin editor GUI element. 395 396 @param event: The wx event. 397 @type event: wx event 398 """ 399 400 # Show the molecule, residue, and spin tree window. 401 self.gui.show_tree(None)
402 403
404 - def observer_register(self, remove=False):
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
415 - def resize(self, event):
416 """The spin editor GUI element. 417 418 @param event: The wx event. 419 @type event: wx event 420 """ 421 422 # Set the virtual size to have the width of the visible size and the height of the virtual size. 423 x = self.GetSize()[0] - self.width_vscroll 424 y = self.GetVirtualSize()[1] 425 self.SetVirtualSize((x, y))
426 427
428 - def spin_count(self):
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 # The data pipe. 436 if hasattr(self.data, 'pipe_name'): 437 pipe = self.data.pipe_name 438 else: 439 pipe = cdp_name() 440 441 # The count. 442 if not has_pipe(pipe): 443 num = 0 444 else: 445 num = count_spins(pipe=pipe) 446 447 # Return the formatted string. 448 return "%s spins loaded and selected" % num
449 450
451 - def update_spin_count(self):
452 """Update the spin count.""" 453 454 # Set the new value. 455 wx.CallAfter(self.spin_systems.SetValue, str_to_gui(self.spin_count()))
456