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-2013 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 # A unique ID. 147 id = wx.NewId() 148 149 # The button. 150 button = buttons.ThemedGenBitmapTextButton(self, id, None, " Execute") 151 button.SetBitmapLabel(wx.Bitmap(IMAGE_PATH+'relax_start.gif', wx.BITMAP_TYPE_ANY)) 152 button.SetFont(font.normal) 153 self.gui.Bind(wx.EVT_BUTTON, method, button) 154 sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 155 156 # Add the element to the box. 157 box.Add(sizer, 0, wx.ALIGN_RIGHT, 0) 158 159 # Return the button. 160 return button
161 162
163 - def add_spin_control(self, box, parent, text='', min=None, max=None, control=wx.SpinCtrl, width=-1, height=-1):
164 """Add a text control field to the box. 165 166 @param box: The box element to pack the control into. 167 @type box: wx.BoxSizer instance 168 @param parent: The parent GUI element. 169 @type parent: wx object 170 @keyword text: The default text of the control. 171 @type text: str 172 @keyword min: The minimum value allowed. 173 @type min: int 174 @keyword max: The maximum value allowed. 175 @type max: int 176 @keyword control: The control class to use. 177 @type control: wx.TextCtrl derived class 178 @keyword width: The minimum width of the control. 179 @type width: int 180 @keyword height: The minimum height of the control. 181 @type height: int 182 @return: The text control object. 183 @rtype: control object 184 """ 185 186 # The control. 187 field = control(parent, -1, text, min=min, max=max) 188 189 # The font and control properties. 190 field.SetMinSize((width, height)) 191 field.SetFont(font.normal) 192 193 # Add the control to the box. 194 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 195 196 # Return the text field. 197 return field
198 199
200 - def add_spin_systems(self, box, parent):
201 """Add a special control for spin systems. 202 203 Only one of these per analysis are allowed. 204 205 @param box: The box element to pack the control into. 206 @type box: wx.BoxSizer instance 207 @param parent: The parent GUI element. 208 @type parent: wx object 209 """ 210 211 # Add the element. 212 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)
213 214
215 - def add_static_text(self, box, parent, text='', width=-1, height=-1):
216 """Add a text control field to the box. 217 218 @param box: The box element to pack the control into. 219 @type box: wx.BoxSizer instance 220 @param parent: The parent GUI element. 221 @type parent: wx object 222 @keyword text: The default text of the control. 223 @type text: str 224 @keyword width: The minimum width of the control. 225 @type width: int 226 @keyword height: The minimum height of the control. 227 @type height: int 228 @return: The label. 229 @rtype: wx.StaticText instance 230 """ 231 232 # The label. 233 label = wx.StaticText(parent, -1, text) 234 235 # The font and label properties. 236 label.SetMinSize((width, height)) 237 label.SetFont(font.normal) 238 239 # Add the label to the box. 240 box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 241 242 # Return the label. 243 return label
244 245
246 - def add_subtitle(self, box, text):
247 """Create and add the subtitle. 248 249 @param box: The box element to pack the subtitle into. 250 @type box: wx.BoxSizer instance 251 @param text: The text of the subtitle. 252 @type text: str 253 """ 254 255 # The title. 256 label = wx.StaticText(self, -1, text) 257 258 # The font properties. 259 label.SetFont(font.subtitle) 260 261 # Add the subtitle to the box, with spacing. 262 box.AddSpacer(20) 263 box.Add(label) 264 box.AddSpacer(5)
265 266
267 - def add_subsubtitle(self, box, text):
268 """Create and add the subsubtitle. 269 270 @param box: The box element to pack the text into. 271 @type box: wx.BoxSizer instance 272 @param text: The text of the subsubtitle. 273 @type text: str 274 """ 275 276 # The text. 277 label = wx.StaticText(self, -1, text) 278 279 # The font properties. 280 label.SetFont(font.normal) 281 282 # Add the text to the box, with spacing. 283 box.AddSpacer(10) 284 box.Add(label)
285 286
287 - def add_text_control(self, box, parent, text='', control=wx.TextCtrl, width=-1, height=-1, editable=True):
288 """Add a text control field to the box. 289 290 @param box: The box element to pack the control into. 291 @type box: wx.BoxSizer instance 292 @param parent: The parent GUI element. 293 @type parent: wx object 294 @keyword text: The default text of the control. 295 @type text: str 296 @keyword control: The control class to use. 297 @type control: wx.TextCtrl derived class 298 @keyword width: The minimum width of the control. 299 @type width: int 300 @keyword height: The minimum height of the control. 301 @type height: int 302 @keyword editable: A flag specifying if the control is editable or not. 303 @type editable: bool 304 @return: The text control object. 305 @rtype: control object 306 """ 307 308 # The control. 309 field = control(parent, -1, str_to_gui(text)) 310 311 # The font and control properties. 312 field.SetMinSize((width, height)) 313 field.SetFont(font.normal) 314 315 # Editable (change the colour if not). 316 field.SetEditable(editable) 317 if not editable: 318 colour = self.GetBackgroundColour() 319 field.SetOwnBackgroundColour(colour) 320 321 # Add the control to the box. 322 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 323 324 # Return the text field. 325 return field
326 327
328 - def add_title(self, box, text, top_spacing=10, bottom_spacing=15):
329 """Create and add the frame title. 330 331 @param box: The box element to pack the frame title into. 332 @type box: wx.BoxSizer instance 333 @param text: The text of the title. 334 @type text: str 335 """ 336 337 # The title. 338 label = wx.StaticText(self, -1, text) 339 340 # The font properties. 341 label.SetFont(font.roman_title_italic) 342 343 # Pack the title, with spacing. 344 box.AddSpacer(top_spacing) 345 box.Add(label) 346 box.AddSpacer(bottom_spacing)
347 348
349 - def build_left_box(self):
350 """Construct the left hand box to pack into the automatic Rx analysis frame. 351 352 @return: The left hand box element containing the bitmap. 353 @rtype: wx.BoxSizer instance 354 """ 355 356 # Use a vertical packing of elements. 357 box = wx.BoxSizer(wx.VERTICAL) 358 359 # Convert the bitmap names to a list. 360 if not isinstance(self.bitmap, list): 361 bitmaps = [self.bitmap] 362 else: 363 bitmaps = self.bitmap 364 365 # Add the bitmaps. 366 for i in range(len(bitmaps)): 367 # The bitmap. 368 bitmap = wx.StaticBitmap(self, -1, bitmap_setup(bitmaps[i])) 369 370 # Add it. 371 box.Add(bitmap, 0, wx.ADJUST_MINSIZE, 10) 372 373 # Return the box. 374 return box
375 376
377 - def build_main_box(self, box):
378 """Construct the highest level box to pack into the automatic analysis frames. 379 380 @param box: The horizontal box element to pack the elements into. 381 @type box: wx.BoxSizer instance 382 """ 383 384 # Build the left hand box and add to the main box. 385 left_box = self.build_left_box() 386 box.Add(left_box, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 387 388 # Central spacer. 389 box.AddSpacer(self.width_main_separator) 390 391 # Build the right hand box and pack it next to the bitmap. 392 right_box = self.build_right_box() 393 box.Add(right_box, 1, wx.ALL|wx.EXPAND, 0)
394 395
396 - def launch_spin_editor(self, event):
397 """The spin editor GUI element. 398 399 @param event: The wx event. 400 @type event: wx event 401 """ 402 403 # Show the molecule, residue, and spin tree window. 404 self.gui.show_tree(None)
405 406
407 - def observer_register(self, remove=False):
408 """Register and unregister methods with the observer objects. 409 410 This is a dummy method. 411 412 413 @keyword remove: If set to True, then the methods will be unregistered. 414 @type remove: False 415 """
416 417
418 - def resize(self, event):
419 """The spin editor GUI element. 420 421 @param event: The wx event. 422 @type event: wx event 423 """ 424 425 # Set the virtual size to have the width of the visible size and the height of the virtual size. 426 x = self.GetSize()[0] - self.width_vscroll 427 y = self.GetVirtualSize()[1] 428 self.SetVirtualSize((x, y))
429 430
431 - def spin_count(self):
432 """Count the number of loaded spins, returning a string formatted as 'xxx spins loaded'. 433 434 @return: The number of loaded spins in the format 'xxx spins loaded'. 435 @rtype: str 436 """ 437 438 # The data pipe. 439 if hasattr(self.data, 'pipe_name'): 440 pipe = self.data.pipe_name 441 else: 442 pipe = cdp_name() 443 444 # The count. 445 if not has_pipe(pipe): 446 num = 0 447 else: 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