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