Package gui :: Package components :: Module free_file_format
[hide private]
[frames] | no frames]

Source Code for Module gui.components.free_file_format

  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  # Python module imports. 
 24  import wx 
 25  from wx.lib import buttons 
 26   
 27  # relax module imports. 
 28  from data_store import Relax_data_store; ds = Relax_data_store() 
 29  from graphics import IMAGE_PATH, fetch_icon 
 30  from gui.fonts import font 
 31  from gui.icons import relax_icons 
 32  from gui.input_elements.value import Value 
 33  from gui.message import Question 
 34  from gui.misc import bitmap_setup 
 35  from gui.string_conv import gui_to_int, gui_to_str, int_to_gui, str_to_gui 
 36  from gui.wizards.wiz_objects import Wiz_page 
 37  from lib.errors import RelaxError 
 38  from status import Status; status = Status() 
 39   
 40   
41 -class Free_file_format:
42 """GUI element for the free file format. 43 44 This is used for specifying the columns used for the molecule name, residue name and number, spin name and number and data and error columns. 45 """ 46 47 size_square_button = (33, 33) 48
49 - def __init__(self, parent=None, element_type='default', sizer=None, divider=None, padding=10, spacer=3, height_element=27, data_cols=False, save=True, reset=True):
50 """Build the free format file settings widget. 51 52 @keyword parent: The parent wx GUI element. 53 @type parent: wx object 54 @keyword element_type: The type of GUI element to create. The value of 'default' creates the large GUI element with a row for each column and for the separator. If 'mini' is supplied, the single row element will be used. 55 @type element_type: str 56 @keyword sizer: The sizer to put the GUI element into. 57 @type sizer: wx.Sizer instance 58 @keyword divider: The position of the divider. 59 @type divider: int 60 @keyword padding: The size of the padding between the wx.StaticBoxSizer border and the internal elements, in pixels. 61 @type padding: int 62 @keyword spacer: The horizontal spacing between the elements, in pixels. 63 @type spacer: int 64 @keyword height_element: The height in pixels of the GUI element. This is only used for the mini format. 65 @type height_element: int 66 @keyword data_cols: A flag which if True causes the data and error column elements to be displayed. 67 @type data_cols: bool 68 @keyword save: A flag which if True will cause the save button to be displayed. 69 @type save: bool 70 @keyword reset: A flag which if True will cause the reset button to be displayed. 71 @type reset: bool 72 """ 73 74 # Store the args. 75 self.parent = parent 76 self.sizer = sizer 77 self.divider = divider 78 self.element_type = element_type 79 self.padding = padding 80 self.spacer = spacer 81 self.height_element = height_element 82 self.data_cols = data_cols 83 self.save_flag = save 84 self.reset_flag = reset 85 86 # The large GUI element. 87 if self.element_type == 'default': 88 self._build_default() 89 90 # The mini GUI element. 91 elif self.element_type == 'mini': 92 self._build_mini() 93 94 # Unknown type. 95 else: 96 raise RelaxError("Unknown free file format element type '%s'." % element_type)
97 98
99 - def _build_default(self):
100 """Build the default GUI element.""" 101 102 # A static box to hold all the widgets. 103 box = wx.StaticBox(self.parent, -1, "The free file format settings:") 104 box.SetFont(font.subtitle) 105 106 # Init. 107 main_sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL) 108 field_sizer = wx.BoxSizer(wx.VERTICAL) 109 button_sizer = wx.BoxSizer(wx.VERTICAL) 110 111 # The border of the widget. 112 border = wx.BoxSizer() 113 114 # Place the box sizer inside the border. 115 border.Add(main_sizer, 1, wx.ALL|wx.EXPAND, 0) 116 117 # Add to the main sizer (followed by stretchable spacing). 118 self.sizer.Add(border, 0, wx.EXPAND) 119 self.sizer.AddStretchSpacer() 120 121 # Calculate the divider position. 122 divider = self.parent._div_left - border.GetMinSize()[0] / 2 - self.padding 123 124 # The columns. 125 self.spin_id_col = Value(name='spin_id_col', parent=self.parent, value_type='int', sizer=field_sizer, desc="spin ID column", divider=divider, padding=self.padding, spacer=self.spacer, can_be_none=True) 126 self.mol_name_col = Value(name='mol_name_col', parent=self.parent, value_type='int', sizer=field_sizer, desc="Molecule name column:", divider=divider, padding=self.padding, spacer=self.spacer, can_be_none=True) 127 self.res_num_col = Value(name='res_num_col', parent=self.parent, value_type='int', sizer=field_sizer, desc="Residue number column:", divider=divider, padding=self.padding, spacer=self.spacer, can_be_none=True) 128 self.res_name_col = Value(name='res_name_col', parent=self.parent, value_type='int', sizer=field_sizer, desc="Residue name column:", divider=divider, padding=self.padding, spacer=self.spacer, can_be_none=True) 129 self.spin_num_col = Value(name='spin_num_col', parent=self.parent, value_type='int', sizer=field_sizer, desc="Spin number column:", divider=divider, padding=self.padding, spacer=self.spacer, can_be_none=True) 130 self.spin_name_col = Value(name='spin_name_col', parent=self.parent, value_type='int', sizer=field_sizer, desc="Spin name column:", divider=divider, padding=self.padding, spacer=self.spacer, can_be_none=True) 131 if self.data_cols: 132 self.data_col = Value(name='data_col', parent=self.parent, value_type='int', sizer=field_sizer, desc="Data column:", divider=divider, padding=self.padding, spacer=self.spacer, can_be_none=True) 133 self.error_col = Value(name='error_col', parent=self.parent, value_type='int', sizer=field_sizer, desc="Error column:", divider=divider, padding=self.padding, spacer=self.spacer, can_be_none=True) 134 135 # The column separator. 136 self.sep = Value(name='sep', parent=self.parent, element_type='combo', value_type='str', sizer=field_sizer, desc="Column separator:", combo_choices=["white space", ",", ";", ":", ""], divider=divider, padding=self.padding, spacer=self.spacer, read_only=False, can_be_none=True) 137 138 # Add the field sizer to the main sizer. 139 main_sizer.Add(field_sizer, 1, wx.ALL|wx.EXPAND, 0) 140 141 # Set the values. 142 self.set_vals() 143 144 # Buttons! 145 if self.save_flag or self.reset_flag: 146 # Add a save button. 147 if self.save_flag: 148 # Build the button. 149 button = buttons.ThemedGenBitmapTextButton(self.parent, -1, None, "") 150 button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.document-save', "22x22"), wx.BITMAP_TYPE_ANY)) 151 button.SetFont(font.normal) 152 button.SetToolTipString("Save the free file format settings within the relax data store.") 153 button.SetMinSize(self.size_square_button) 154 155 # Add the button. 156 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 157 158 # Padding. 159 button_sizer.AddSpacer(self.padding) 160 161 # Bind the click event. 162 self.parent.Bind(wx.EVT_BUTTON, self.save, button) 163 164 # Add a reset button. 165 if self.reset_flag: 166 # Build the button. 167 button = buttons.ThemedGenBitmapTextButton(self.parent, -1, None, "") 168 button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.edit-delete', "22x22"), wx.BITMAP_TYPE_ANY)) 169 button.SetFont(font.normal) 170 button.SetToolTipString("Reset the free file format settings to the original values.") 171 button.SetMinSize(self.size_square_button) 172 173 # Add the button. 174 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 175 176 # Bind the click event. 177 self.parent.Bind(wx.EVT_BUTTON, self.reset, button) 178 179 # Add the button sizer to the widget (with spacing). 180 main_sizer.AddSpacer(self.padding) 181 main_sizer.Add(button_sizer, 0, wx.ALL, 0)
182 183
184 - def _build_mini(self):
185 """Build the mini GUI element.""" 186 187 # Init. 188 sub_sizer = wx.BoxSizer(wx.HORIZONTAL) 189 190 # Left padding. 191 sub_sizer.AddSpacer(self.padding) 192 193 # The description. 194 text = wx.StaticText(self.parent, -1, "Free format file settings", style=wx.ALIGN_LEFT) 195 text.SetFont(font.normal) 196 sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 197 198 # The divider. 199 if not self.divider: 200 raise RelaxError("The divider position has not been supplied.") 201 202 # Spacing. 203 x, y = text.GetSize() 204 sub_sizer.AddSpacer((self.divider - x, 0)) 205 206 # Initialise the text input field. 207 self.field = wx.TextCtrl(self.parent, -1, '') 208 self.field.SetEditable(False) 209 colour = self.parent.GetBackgroundColour() 210 self.field.SetOwnBackgroundColour(colour) 211 self.field.SetMinSize((50, self.height_element)) 212 self.field.SetFont(font.normal) 213 sub_sizer.Add(self.field, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 214 215 # A little spacing. 216 sub_sizer.AddSpacer(5) 217 218 # The edit button. 219 button = wx.BitmapButton(self.parent, -1, wx.Bitmap(fetch_icon("oxygen.actions.document-properties"), wx.BITMAP_TYPE_ANY)) 220 button.SetMinSize((self.height_element, self.height_element)) 221 button.SetToolTipString("Open the free file format editing window.") 222 sub_sizer.Add(button, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 223 self.parent.Bind(wx.EVT_BUTTON, self.open_window, button) 224 225 # Right padding. 226 sub_sizer.AddSpacer(self.padding) 227 228 # Add to the main sizer. 229 self.sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0) 230 231 # Spacing below the widget. 232 if self.spacer == None: 233 self.sizer.AddStretchSpacer() 234 else: 235 self.sizer.AddSpacer(self.spacer) 236 237 # Tooltip. 238 tooltip = "The free file format settings." 239 text.SetToolTipString(tooltip) 240 self.field.SetToolTipString(tooltip) 241 242 # Set the values. 243 self.set_vals()
244 245
246 - def GetValue(self):
247 """Return the free file format settings as a keyword dictionary. 248 249 @return: The dictionary of free file format settings. 250 @rtype: dict 251 """ 252 253 # Initialise. 254 settings = {} 255 256 # The default GUI element. 257 if self.element_type == 'default': 258 # Get the column numbers. 259 settings['spin_id_col'] = gui_to_int(self.spin_id_col.GetValue()) 260 settings['mol_name_col'] = gui_to_int(self.mol_name_col.GetValue()) 261 settings['res_num_col'] = gui_to_int(self.res_num_col.GetValue()) 262 settings['res_name_col'] = gui_to_int(self.res_name_col.GetValue()) 263 settings['spin_num_col'] = gui_to_int(self.spin_num_col.GetValue()) 264 settings['spin_name_col'] = gui_to_int(self.spin_name_col.GetValue()) 265 if self.data_cols: 266 settings['data_col'] = gui_to_int(self.data_col.GetValue()) 267 settings['error_col'] = gui_to_int(self.error_col.GetValue()) 268 269 # The column separator. 270 settings['sep'] = str(self.sep.GetValue()) 271 if settings['sep'] == 'white space': 272 settings['sep'] = None 273 274 # The mini GUI element. 275 elif self.element_type == 'mini': 276 # Convert the values. 277 values = self.from_string(string=gui_to_str(self.field.GetValue())) 278 279 # Store them. 280 settings['spin_id_col'] = values[0] 281 settings['mol_name_col'] = values[1] 282 settings['res_num_col'] = values[2] 283 settings['res_name_col'] = values[3] 284 settings['spin_num_col'] = values[4] 285 settings['spin_name_col'] = values[5] 286 if self.data_cols: 287 settings['data_col'] = values[6] 288 settings['error_col'] = values[7] 289 settings['sep'] = values[8] 290 else: 291 settings['sep'] = values[6] 292 293 # Return the settings. 294 return settings
295 296
297 - def SetValue(self, key, value):
298 """Special method for setting the value of the GUI element corresponding to the key. 299 300 @param key: The key corresponding to the desired GUI element. This can be one of ['spin_id_col', 'mol_name_col', 'res_num_col', 'res_name_col', 'spin_num_col', 'spin_name_col', 'data_col', 'error_col', 'sep']. 301 @type key: str 302 @param value: The value that the specific GUI element's SetValue() method expects. 303 @type value: unknown 304 """ 305 306 # The default GUI element. 307 if self.element_type == 'default': 308 # Get the element. 309 obj = getattr(self, key) 310 311 # Convert the data. 312 if key == 'sep': 313 value = str_to_gui(value) 314 else: 315 value = int_to_gui(value) 316 317 # Set the value. 318 obj.SetValue(value) 319 320 # The mini GUI element. 321 elif self.element_type == 'mini': 322 # Get the current values. 323 settings = self.GetValue() 324 325 # Replace the value. 326 settings[key] = value 327 328 # Set the values. 329 if self.data_cols: 330 string = self.to_string(spin_id_col=settings['spin_id_col'], mol_name_col=settings['mol_name_col'], res_num_col=settings['res_num_col'], res_name_col=settings['res_name_col'], spin_num_col=settings['spin_num_col'], spin_name_col=settings['spin_name_col'], data_col=settings['data_col'], error_col=settings['error_col'], sep=settings['sep']) 331 else: 332 string = self.to_string(spin_id_col=settings['spin_id_col'], mol_name_col=settings['mol_name_col'], res_num_col=settings['res_num_col'], res_name_col=settings['res_name_col'], spin_num_col=settings['spin_num_col'], spin_name_col=settings['spin_name_col'], sep=settings['sep']) 333 self.field.SetValue(str_to_gui(string))
334 335
336 - def from_string(self, string=None):
337 """Convert the free file format variables to string format. 338 339 @keyword string: The string to convert. 340 @type string: str 341 @return: The spin ID column, molecule name column, residue number column, residue number column, spin number column, spin name column, data column (if active), error column (if active), and column separator. 342 @rtype: list of str or None 343 """ 344 345 # The number of elements. 346 num = 6 347 if self.data_cols: 348 num = 8 349 350 # Nothing. 351 if string == None: 352 return [None] * num 353 354 # Store the columns. 355 values = [] 356 temp = string.split(',') 357 for i in range(num): 358 # No value. 359 if temp[i] in ['None', ' None']: 360 values.append(None) 361 362 # Integer. 363 else: 364 values.append(int(temp[i])) 365 366 # Handle the separator. 367 temp = string.split('\'') 368 sep = temp[-2] 369 if sep == "white space": 370 values.append(None) 371 else: 372 values.append(sep) 373 374 # Return the values. 375 return values
376 377
378 - def open_window(self, event):
379 """Open the free file format editing window. 380 381 @param event: The wx event. 382 @type event: wx event 383 """ 384 385 # Build the window. 386 win = Free_file_format_window() 387 388 # Show the window. 389 if status.show_gui: 390 win.ShowModal() 391 392 # Set the values. 393 self.set_vals()
394 395
396 - def reset(self, event):
397 """Reset the free file format widget contents to the original values. 398 399 @param event: The wx event. 400 @type event: wx event 401 """ 402 403 # Ask a question. 404 if status.show_gui and Question('Would you really like to reset the free file format settings?', parent=self.parent).ShowModal() == wx.ID_NO: 405 return 406 407 # First reset. 408 ds.relax_gui.free_file_format.reset() 409 410 # Then update the values. 411 self.set_vals()
412 413
414 - def save(self, event):
415 """Save the free file format widget contents into the relax data store. 416 417 @param event: The wx event. 418 @type event: wx event 419 """ 420 421 # The default GUI element. 422 if self.element_type == 'default': 423 # Get the column numbers. 424 ds.relax_gui.free_file_format.spin_id_col = gui_to_int(self.spin_id_col.GetValue()) 425 ds.relax_gui.free_file_format.mol_name_col = gui_to_int(self.mol_name_col.GetValue()) 426 ds.relax_gui.free_file_format.res_num_col = gui_to_int(self.res_num_col.GetValue()) 427 ds.relax_gui.free_file_format.res_name_col = gui_to_int(self.res_name_col.GetValue()) 428 ds.relax_gui.free_file_format.spin_num_col = gui_to_int(self.spin_num_col.GetValue()) 429 ds.relax_gui.free_file_format.spin_name_col = gui_to_int(self.spin_name_col.GetValue()) 430 431 # The data and error. 432 if hasattr(self, 'data_col'): 433 ds.relax_gui.free_file_format.data_col = gui_to_int(self.data_col.GetValue()) 434 if hasattr(self, 'error_col'): 435 ds.relax_gui.free_file_format.error_col = gui_to_int(self.error_col.GetValue()) 436 437 # The column separator. 438 ds.relax_gui.free_file_format.sep = str(self.sep.GetValue()) 439 if ds.relax_gui.free_file_format.sep == 'white space': 440 ds.relax_gui.free_file_format.sep = None 441 442 # The mini GUI element. 443 elif self.element_type == 'mini': 444 # Get the current values. 445 settings = self.GetValue() 446 447 # Store the values. 448 ds.relax_gui.free_file_format.spin_id_col = settings['spin_id_col'] 449 ds.relax_gui.free_file_format.mol_name_col = settings['mol_name_col'] 450 ds.relax_gui.free_file_format.res_num_col = settings['res_num_col'] 451 ds.relax_gui.free_file_format.res_name_col = settings['res_name_col'] 452 ds.relax_gui.free_file_format.spin_num_col = settings['spin_num_col'] 453 ds.relax_gui.free_file_format.spin_name_col = settings['spin_name_col'] 454 if self.data_cols: 455 ds.relax_gui.free_file_format.data_col = settings['data_col'] 456 ds.relax_gui.free_file_format.error_col = settings['error_col'] 457 ds.relax_gui.free_file_format.sep = settings['sep']
458 459
460 - def set_vals(self):
461 """Set the free file format widget contents to the values from the relax data store.""" 462 463 # The default GUI element. 464 if self.element_type == 'default': 465 # The column numbers. 466 self.spin_id_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.spin_id_col)) 467 self.mol_name_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.mol_name_col)) 468 self.res_num_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.res_num_col)) 469 self.res_name_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.res_name_col)) 470 self.spin_num_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.spin_num_col)) 471 self.spin_name_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.spin_name_col)) 472 if hasattr(self, 'data_col'): 473 self.data_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.data_col)) 474 if hasattr(self, 'error_col'): 475 self.error_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.error_col)) 476 477 # The column separator. 478 if not ds.relax_gui.free_file_format.sep: 479 self.sep.SetValue(str_to_gui("white space")) 480 else: 481 self.sep.SetValue(str_to_gui(ds.relax_gui.free_file_format.sep)) 482 483 # The mini GUI element. 484 elif self.element_type == 'mini': 485 # The string. 486 if self.data_cols: 487 string = self.to_string(spin_id_col=ds.relax_gui.free_file_format.spin_id_col, mol_name_col=ds.relax_gui.free_file_format.mol_name_col, res_num_col=ds.relax_gui.free_file_format.res_num_col, res_name_col=ds.relax_gui.free_file_format.res_name_col, spin_num_col=ds.relax_gui.free_file_format.spin_num_col, spin_name_col=ds.relax_gui.free_file_format.spin_name_col, data_col=ds.relax_gui.free_file_format.data_col, error_col=ds.relax_gui.free_file_format.error_col, sep=ds.relax_gui.free_file_format.sep) 488 else: 489 string = self.to_string(spin_id_col=ds.relax_gui.free_file_format.spin_id_col, mol_name_col=ds.relax_gui.free_file_format.mol_name_col, res_num_col=ds.relax_gui.free_file_format.res_num_col, res_name_col=ds.relax_gui.free_file_format.res_name_col, spin_num_col=ds.relax_gui.free_file_format.spin_num_col, spin_name_col=ds.relax_gui.free_file_format.spin_name_col, sep=ds.relax_gui.free_file_format.sep) 490 self.field.SetValue(str_to_gui(string))
491 492
493 - def to_string(self, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, data_col=None, error_col=None, sep=None):
494 """Convert the free file format variables to string format. 495 496 @keyword spin_id_col: The column containing the spin ID strings (used by the generic intensity file format). If supplied, the mol_name_col, res_name_col, res_num_col, spin_name_col, and spin_num_col arguments must be none. 497 @type spin_id_col: int or None 498 @keyword mol_name_col: The column containing the molecule name information (used by the generic intensity file format). If supplied, spin_id_col must be None. 499 @type mol_name_col: int or None 500 @keyword res_name_col: The column containing the residue name information (used by the generic intensity file format). If supplied, spin_id_col must be None. 501 @type res_name_col: int or None 502 @keyword res_num_col: The column containing the residue number information (used by the generic intensity file format). If supplied, spin_id_col must be None. 503 @type res_num_col: int or None 504 @keyword spin_name_col: The column containing the spin name information (used by the generic intensity file format). If supplied, spin_id_col must be None. 505 @type spin_name_col: int or None 506 @keyword spin_num_col: The column containing the spin number information (used by the generic intensity file format). If supplied, spin_id_col must be None. 507 @type spin_num_col: int or None 508 @keyword sep: The column separator which, if None, defaults to whitespace. 509 @type sep: str or None 510 @return: The string representation of the free file format settings. 511 @rtype: str 512 """ 513 514 # The string. 515 string = '' 516 string += repr(spin_id_col) 517 string += ', ' + repr(mol_name_col) 518 string += ', ' + repr(res_num_col) 519 string += ', ' + repr(res_name_col) 520 string += ', ' + repr(spin_num_col) 521 string += ', ' + repr(spin_name_col) 522 if self.data_cols: 523 string += ', ' + repr(data_col) 524 string += ', ' + repr(error_col) 525 if not sep: 526 string += ', ' + repr("white space") 527 else: 528 string += ', ' + repr(sep) 529 530 # Return the string. 531 return string
532 533 534
535 -class Free_file_format_window(wx.Dialog, Wiz_page):
536 """The free file format setting window.""" 537 538 # The window size. 539 SIZE = (500, 550) 540 541 # A border. 542 BORDER = 10 543 544 # Sizes. 545 SIZE_BUTTON = (100, 33) 546
547 - def __init__(self, parent=None):
548 """Set up the window.""" 549 550 # Execute the base __init__() method. 551 wx.Dialog.__init__(self, parent, id=-1, title="Free file format", style=wx.DEFAULT_FRAME_STYLE) 552 553 # The sizes. 554 self._main_size = self.SIZE[0] - 2*self.BORDER 555 self._div_left = self._main_size / 2 556 557 # Set up the window icon. 558 self.SetIcons(relax_icons) 559 560 # The main sizer. 561 self.main_sizer = self.build_frame() 562 563 # The heading. 564 text = wx.StaticText(self, -1, "Settings for the free file format") 565 text.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, "")) 566 self.main_sizer.Add(text, 0, wx.ALIGN_CENTER_HORIZONTAL, 5) 567 self.main_sizer.AddStretchSpacer() 568 569 # The relax logo. 570 bmp = wx.StaticBitmap(self, -1, bitmap_setup(IMAGE_PATH+'relax.gif')) 571 self.main_sizer.Add(bmp, 0, wx.ALIGN_CENTER_HORIZONTAL, 5) 572 self.main_sizer.AddStretchSpacer() 573 574 # The centre section. 575 self.add_centre(self.main_sizer) 576 577 # The bottom buttons. 578 self.add_buttons(self.main_sizer) 579 580 # Set the window size. 581 self.SetSize(self.SIZE) 582 self.SetMinSize(self.SIZE) 583 584 # Centre the window. 585 self.Center()
586 587
588 - def add_buttons(self, sizer):
589 """Add the buttons to the sizer. 590 591 @param sizer: A sizer object. 592 @type sizer: wx.Sizer instance 593 """ 594 595 # Create a horizontal layout for the buttons. 596 button_sizer = wx.BoxSizer(wx.HORIZONTAL) 597 sizer.Add(button_sizer, 0, wx.ALIGN_CENTER|wx.ALL, 0) 598 599 # The save button. 600 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Save") 601 button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.document-save', "22x22"), wx.BITMAP_TYPE_ANY)) 602 button.SetFont(font.normal) 603 button.SetToolTipString("Save the free file format settings within the relax data store.") 604 button.SetMinSize(self.SIZE_BUTTON) 605 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 606 self.Bind(wx.EVT_BUTTON, self.save, button) 607 608 # Spacer. 609 button_sizer.AddSpacer(20) 610 611 # The reset button. 612 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Reset") 613 button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.edit-delete', "22x22"), wx.BITMAP_TYPE_ANY)) 614 button.SetFont(font.normal) 615 button.SetToolTipString("Reset the free file format settings to the original values.") 616 button.SetMinSize(self.SIZE_BUTTON) 617 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 618 self.Bind(wx.EVT_BUTTON, self.reset, button) 619 620 # Spacer. 621 button_sizer.AddSpacer(20) 622 623 # The cancel button. 624 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Cancel") 625 button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.dialog-cancel', "22x22"), wx.BITMAP_TYPE_ANY)) 626 button.SetFont(font.normal) 627 button.SetMinSize(self.SIZE_BUTTON) 628 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 629 self.Bind(wx.EVT_BUTTON, self.cancel, button)
630 631
632 - def add_centre(self, sizer):
633 """Add the centre of the free file format settings window. 634 635 @param sizer: A sizer object. 636 @type sizer: wx.Sizer instance 637 """ 638 639 # The widget. 640 self._element = Free_file_format(parent=self, sizer=sizer, data_cols=True, save=False, reset=False) 641 642 # Spacing. 643 self.main_sizer.AddStretchSpacer()
644 645
646 - def build_frame(self):
647 """Create the main part of the frame, returning the central sizer.""" 648 649 # The sizers. 650 sizer1 = wx.BoxSizer(wx.HORIZONTAL) 651 sizer2 = wx.BoxSizer(wx.VERTICAL) 652 central_sizer = wx.BoxSizer(wx.VERTICAL) 653 654 # Left and right borders. 655 sizer1.AddSpacer(self.BORDER) 656 sizer1.Add(sizer2, 1, wx.EXPAND|wx.ALL, 0) 657 sizer1.AddSpacer(self.BORDER) 658 659 # Top and bottom borders. 660 sizer2.AddSpacer(self.BORDER) 661 sizer2.Add(central_sizer, 1, wx.EXPAND|wx.ALL, 0) 662 sizer2.AddSpacer(self.BORDER) 663 664 # Set the sizer for the frame. 665 self.SetSizer(sizer1) 666 667 # Return the central sizer. 668 return central_sizer
669 670
671 - def cancel(self, event):
672 """Close the window. 673 674 @param event: The wx event. 675 @type event: wx event 676 """ 677 678 # Close the window. 679 self.Close()
680 681
682 - def reset(self, event):
683 """Reset the free file format settings. 684 685 @param event: The wx event. 686 @type event: wx event 687 """ 688 689 # Execute the base class method. 690 self._element.reset(event)
691 692
693 - def save(self, event):
694 """Save the free file format widget contents into the relax data store. 695 696 @param event: The wx event. 697 @type event: wx event 698 """ 699 700 # Execute the base class method. 701 self._element.save(event) 702 703 # Close the window. 704 self.Close()
705