"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/gui/components/free_file_format.py" (2 Dec 2019, 30741 Bytes) of package /linux/privat/relax-5.0.0.src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "free_file_format.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.1.3_vs_5.0.0.

    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
  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         x, y = text.GetSize()
  205         if dep_check.wx_classic:
  206             sub_sizer.AddSpacer((self.divider - x, 0))
  207         else:
  208             sub_sizer.AddSpacer(self.divider - x)
  209 
  210         # Initialise the text input field.
  211         self.field = wx.TextCtrl(self.parent, -1, '')
  212         self.field.SetEditable(False)
  213         colour = self.parent.GetBackgroundColour()
  214         self.field.SetOwnBackgroundColour(colour)
  215         self.field.SetMinSize((50, self.height_element))
  216         self.field.SetFont(font.normal)
  217         sub_sizer.Add(self.field, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
  218 
  219         # A little spacing.
  220         sub_sizer.AddSpacer(5)
  221 
  222         # The edit button.
  223         button = wx.BitmapButton(self.parent, -1, wx.Bitmap(fetch_icon("oxygen.actions.document-properties"), wx.BITMAP_TYPE_ANY))
  224         button.SetMinSize((self.height_element, self.height_element))
  225         button.SetToolTip(wx.ToolTip("Open the free file format editing window."))
  226         sub_sizer.Add(button, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
  227         self.parent.Bind(wx.EVT_BUTTON, self.open_window, button)
  228 
  229         # Right padding.
  230         sub_sizer.AddSpacer(self.padding)
  231 
  232         # Add to the main sizer.
  233         self.sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0)
  234 
  235         # Spacing below the widget.
  236         if self.spacer == None:
  237             self.sizer.AddStretchSpacer()
  238         else:
  239             self.sizer.AddSpacer(self.spacer)
  240 
  241         # Tooltip.
  242         tooltip = "The free file format settings."
  243         text.SetToolTip(wx.ToolTip(tooltip))
  244         self.field.SetToolTip(wx.ToolTip(tooltip))
  245 
  246         # Set the values.
  247         self.set_vals()
  248 
  249 
  250     def GetValue(self):
  251         """Return the free file format settings as a keyword dictionary.
  252 
  253         @return:    The dictionary of free file format settings.
  254         @rtype:     dict
  255         """
  256 
  257         # Initialise.
  258         settings = {}
  259 
  260         # The default GUI element.
  261         if self.element_type == 'default':
  262             # Get the column numbers.
  263             settings['spin_id_col'] =   gui_to_int(self.spin_id_col.GetValue())
  264             settings['mol_name_col'] =  gui_to_int(self.mol_name_col.GetValue())
  265             settings['res_num_col'] =   gui_to_int(self.res_num_col.GetValue())
  266             settings['res_name_col'] =  gui_to_int(self.res_name_col.GetValue())
  267             settings['spin_num_col'] =  gui_to_int(self.spin_num_col.GetValue())
  268             settings['spin_name_col'] = gui_to_int(self.spin_name_col.GetValue())
  269             if self.data_cols:
  270                 settings['data_col'] =  gui_to_int(self.data_col.GetValue())
  271                 settings['error_col'] = gui_to_int(self.error_col.GetValue())
  272 
  273             # The column separator.
  274             settings['sep'] = str(self.sep.GetValue())
  275             if settings['sep'] == 'white space':
  276                 settings['sep'] = None
  277 
  278         # The mini GUI element.
  279         elif self.element_type == 'mini':
  280             # Convert the values.
  281             values = self.from_string(string=gui_to_str(self.field.GetValue()))
  282 
  283             # Store them.
  284             settings['spin_id_col'] = values[0]
  285             settings['mol_name_col'] = values[1]
  286             settings['res_num_col'] = values[2]
  287             settings['res_name_col'] = values[3]
  288             settings['spin_num_col'] = values[4]
  289             settings['spin_name_col'] = values[5]
  290             if self.data_cols:
  291                 settings['data_col'] = values[6]
  292                 settings['error_col'] = values[7]
  293                 settings['sep'] = values[8]
  294             else:
  295                 settings['sep'] = values[6]
  296 
  297         # Return the settings.
  298         return settings
  299 
  300 
  301     def SetValue(self, key, value):
  302         """Special method for setting the value of the GUI element corresponding to the key.
  303 
  304         @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'].
  305         @type key:      str
  306         @param value:   The value that the specific GUI element's SetValue() method expects.
  307         @type value:    unknown
  308         """
  309 
  310         # The default GUI element.
  311         if self.element_type == 'default':
  312             # Get the element.
  313             obj = getattr(self, key)
  314 
  315             # Convert the data.
  316             if key == 'sep':
  317                 value = str_to_gui(value)
  318             else:
  319                 value = int_to_gui(value)
  320 
  321             # Set the value.
  322             obj.SetValue(value)
  323 
  324         # The mini GUI element.
  325         elif self.element_type == 'mini':
  326             # Get the current values.
  327             settings = self.GetValue()
  328 
  329             # Replace the value.
  330             settings[key] = value
  331 
  332             # Set the values.
  333             if self.data_cols:
  334                 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'])
  335             else:
  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'], sep=settings['sep'])
  337             self.field.SetValue(str_to_gui(string))
  338 
  339 
  340     def from_string(self, string=None):
  341         """Convert the free file format variables to string format.
  342 
  343         @keyword string:        The string to convert.
  344         @type string:           str
  345         @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.
  346         @rtype:                 list of str or None
  347         """
  348 
  349         # The number of elements.
  350         num = 6
  351         if self.data_cols:
  352             num = 8
  353 
  354         # Nothing.
  355         if string == None:
  356             return [None] * num
  357 
  358         # Store the columns.
  359         values = []
  360         temp = string.split(',')
  361         for i in range(num):
  362             # No value.
  363             if temp[i] in ['None', ' None']:
  364                 values.append(None)
  365 
  366             # Integer.
  367             else:
  368                 values.append(int(temp[i]))
  369 
  370         # Handle the separator.
  371         temp = string.split('\'')
  372         sep = temp[-2]
  373         if sep == "white space":
  374             values.append(None)
  375         else:
  376             values.append(sep)
  377 
  378         # Return the values.
  379         return values
  380 
  381 
  382     def open_window(self, event):
  383         """Open the free file format editing window.
  384 
  385         @param event:   The wx event.
  386         @type event:    wx event
  387         """
  388 
  389         # Build the window.
  390         win = Free_file_format_window()
  391 
  392         # Show the window.
  393         if status.show_gui:
  394             win.ShowModal()
  395 
  396         # Set the values.
  397         self.set_vals()
  398 
  399 
  400     def reset(self, event):
  401         """Reset the free file format widget contents to the original values.
  402 
  403         @param event:   The wx event.
  404         @type event:    wx event
  405         """
  406 
  407         # Ask a question.
  408         if status.show_gui and Question('Would you really like to reset the free file format settings?', parent=self.parent).ShowModal() == wx.ID_NO:
  409             return
  410 
  411         # First reset.
  412         ds.relax_gui.free_file_format.reset()
  413 
  414         # Then update the values.
  415         self.set_vals()
  416 
  417 
  418     def save(self, event):
  419         """Save the free file format widget contents into the relax data store.
  420 
  421         @param event:   The wx event.
  422         @type event:    wx event
  423         """
  424 
  425         # The default GUI element.
  426         if self.element_type == 'default':
  427             # Get the column numbers.
  428             ds.relax_gui.free_file_format.spin_id_col =   gui_to_int(self.spin_id_col.GetValue())
  429             ds.relax_gui.free_file_format.mol_name_col =  gui_to_int(self.mol_name_col.GetValue())
  430             ds.relax_gui.free_file_format.res_num_col =   gui_to_int(self.res_num_col.GetValue())
  431             ds.relax_gui.free_file_format.res_name_col =  gui_to_int(self.res_name_col.GetValue())
  432             ds.relax_gui.free_file_format.spin_num_col =  gui_to_int(self.spin_num_col.GetValue())
  433             ds.relax_gui.free_file_format.spin_name_col = gui_to_int(self.spin_name_col.GetValue())
  434 
  435             # The data and error.
  436             if hasattr(self, 'data_col'):
  437                 ds.relax_gui.free_file_format.data_col = gui_to_int(self.data_col.GetValue())
  438             if hasattr(self, 'error_col'):
  439                 ds.relax_gui.free_file_format.error_col = gui_to_int(self.error_col.GetValue())
  440 
  441             # The column separator.
  442             ds.relax_gui.free_file_format.sep = str(self.sep.GetValue())
  443             if ds.relax_gui.free_file_format.sep == 'white space':
  444                 ds.relax_gui.free_file_format.sep = None
  445 
  446         # The mini GUI element.
  447         elif self.element_type == 'mini':
  448             # Get the current values.
  449             settings = self.GetValue()
  450 
  451             # Store the values.
  452             ds.relax_gui.free_file_format.spin_id_col =   settings['spin_id_col']
  453             ds.relax_gui.free_file_format.mol_name_col =  settings['mol_name_col']
  454             ds.relax_gui.free_file_format.res_num_col =   settings['res_num_col']
  455             ds.relax_gui.free_file_format.res_name_col =  settings['res_name_col']
  456             ds.relax_gui.free_file_format.spin_num_col =  settings['spin_num_col']
  457             ds.relax_gui.free_file_format.spin_name_col = settings['spin_name_col']
  458             if self.data_cols:
  459                 ds.relax_gui.free_file_format.data_col = settings['data_col']
  460                 ds.relax_gui.free_file_format.error_col = settings['error_col']
  461             ds.relax_gui.free_file_format.sep = settings['sep']
  462 
  463 
  464     def set_vals(self):
  465         """Set the free file format widget contents to the values from the relax data store."""
  466 
  467         # The default GUI element.
  468         if self.element_type == 'default':
  469             # The column numbers.
  470             self.spin_id_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.spin_id_col))
  471             self.mol_name_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.mol_name_col))
  472             self.res_num_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.res_num_col))
  473             self.res_name_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.res_name_col))
  474             self.spin_num_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.spin_num_col))
  475             self.spin_name_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.spin_name_col))
  476             if hasattr(self, 'data_col'):
  477                 self.data_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.data_col))
  478             if hasattr(self, 'error_col'):
  479                 self.error_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.error_col))
  480 
  481             # The column separator.
  482             if not ds.relax_gui.free_file_format.sep:
  483                 self.sep.SetValue(str_to_gui("white space"))
  484             else:
  485                 self.sep.SetValue(str_to_gui(ds.relax_gui.free_file_format.sep))
  486 
  487         # The mini GUI element.
  488         elif self.element_type == 'mini':
  489             # The string.
  490             if self.data_cols:
  491                 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)
  492             else:
  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, sep=ds.relax_gui.free_file_format.sep)
  494             self.field.SetValue(str_to_gui(string))
  495 
  496 
  497     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):
  498         """Convert the free file format variables to string format.
  499 
  500         @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.
  501         @type spin_id_col:      int or None
  502         @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.
  503         @type mol_name_col:     int or None
  504         @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.
  505         @type res_name_col:     int or None
  506         @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.
  507         @type res_num_col:      int or None
  508         @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.
  509         @type spin_name_col:    int or None
  510         @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.
  511         @type spin_num_col:     int or None
  512         @keyword sep:           The column separator which, if None, defaults to whitespace.
  513         @type sep:              str or None
  514         @return:                The string representation of the free file format settings.
  515         @rtype:                 str
  516         """
  517 
  518         # The string.
  519         string = ''
  520         string += repr(spin_id_col)
  521         string += ', ' + repr(mol_name_col)
  522         string += ', ' + repr(res_num_col)
  523         string += ', ' + repr(res_name_col)
  524         string += ', ' + repr(spin_num_col)
  525         string += ', ' + repr(spin_name_col)
  526         if self.data_cols:
  527             string += ', ' + repr(data_col)
  528             string += ', ' + repr(error_col)
  529         if not sep:
  530             string += ', ' + repr("white space")
  531         else:
  532             string += ', ' + repr(sep)
  533 
  534         # Return the string.
  535         return string
  536 
  537 
  538 
  539 class Free_file_format_window(wx.Dialog, Wiz_page):
  540     """The free file format setting window."""
  541 
  542     # The window size.
  543     SIZE = (500, 550)
  544 
  545     # A border.
  546     BORDER = 10
  547 
  548     # Sizes.
  549     SIZE_BUTTON = (100, 33)
  550 
  551     def __init__(self, parent=None):
  552         """Set up the window."""
  553 
  554         # Execute the base __init__() method.
  555         wx.Dialog.__init__(self, parent, id=-1, title="Free file format", style=wx.DEFAULT_FRAME_STYLE)
  556 
  557         # The sizes.
  558         self._main_size = self.SIZE[0] - 2*self.BORDER
  559         self._div_left = self._main_size / 2
  560 
  561         # Set up the window icon.
  562         self.SetIcons(Relax_icons())
  563 
  564         # The main sizer.
  565         self.main_sizer = self.build_frame()
  566 
  567         # The heading.
  568         text = wx.StaticText(self, -1, "Settings for the free file format")
  569         text.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
  570         self.main_sizer.Add(text, 0, wx.ALIGN_CENTER_HORIZONTAL, 5)
  571         self.main_sizer.AddStretchSpacer()
  572 
  573         # The relax logo.
  574         bmp = wx.StaticBitmap(self, -1, bitmap_setup(IMAGE_PATH+'relax.gif'))
  575         self.main_sizer.Add(bmp, 0, wx.ALIGN_CENTER_HORIZONTAL, 5)
  576         self.main_sizer.AddStretchSpacer()
  577 
  578         # The centre section.
  579         self.add_centre(self.main_sizer)
  580 
  581         # The bottom buttons.
  582         self.add_buttons(self.main_sizer)
  583 
  584         # Set the window size.
  585         self.SetSize(self.SIZE)
  586         self.SetMinSize(self.SIZE)
  587 
  588         # Centre the window.
  589         self.Center()
  590 
  591 
  592     def add_buttons(self, sizer):
  593         """Add the buttons to the sizer.
  594 
  595         @param sizer:   A sizer object.
  596         @type sizer:    wx.Sizer instance
  597         """
  598 
  599         # Create a horizontal layout for the buttons.
  600         button_sizer = wx.BoxSizer(wx.HORIZONTAL)
  601         sizer.Add(button_sizer, 0, wx.ALIGN_CENTER|wx.ALL, 0)
  602 
  603         # The save button.
  604         button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, "  Save")
  605         button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.document-save', "22x22"), wx.BITMAP_TYPE_ANY))
  606         button.SetFont(font.normal)
  607         button.SetToolTip(wx.ToolTip("Save the free file format settings within the relax data store."))
  608         button.SetMinSize(self.SIZE_BUTTON)
  609         button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
  610         self.Bind(wx.EVT_BUTTON, self.save, button)
  611 
  612         # Spacer.
  613         button_sizer.AddSpacer(20)
  614 
  615         # The reset button.
  616         button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, "  Reset")
  617         button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.edit-delete', "22x22"), wx.BITMAP_TYPE_ANY))
  618         button.SetFont(font.normal)
  619         button.SetToolTip(wx.ToolTip("Reset the free file format settings to the original values."))
  620         button.SetMinSize(self.SIZE_BUTTON)
  621         button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
  622         self.Bind(wx.EVT_BUTTON, self.reset, button)
  623 
  624         # Spacer.
  625         button_sizer.AddSpacer(20)
  626 
  627         # The cancel button.
  628         button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, "  Cancel")
  629         button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.dialog-cancel', "22x22"), wx.BITMAP_TYPE_ANY))
  630         button.SetFont(font.normal)
  631         button.SetMinSize(self.SIZE_BUTTON)
  632         button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
  633         self.Bind(wx.EVT_BUTTON, self.cancel, button)
  634 
  635 
  636     def add_centre(self, sizer):
  637         """Add the centre of the free file format settings window.
  638 
  639         @param sizer:   A sizer object.
  640         @type sizer:    wx.Sizer instance
  641         """
  642 
  643         # The widget.
  644         self._element = Free_file_format(parent=self, sizer=sizer, data_cols=True, save=False, reset=False)
  645 
  646         # Spacing.
  647         self.main_sizer.AddStretchSpacer()
  648 
  649 
  650     def build_frame(self):
  651         """Create the main part of the frame, returning the central sizer."""
  652 
  653         # The sizers.
  654         sizer1 = wx.BoxSizer(wx.HORIZONTAL)
  655         sizer2 = wx.BoxSizer(wx.VERTICAL)
  656         central_sizer = wx.BoxSizer(wx.VERTICAL)
  657 
  658         # Left and right borders.
  659         sizer1.AddSpacer(self.BORDER)
  660         sizer1.Add(sizer2, 1, wx.EXPAND|wx.ALL, 0)
  661         sizer1.AddSpacer(self.BORDER)
  662 
  663         # Top and bottom borders.
  664         sizer2.AddSpacer(self.BORDER)
  665         sizer2.Add(central_sizer, 1, wx.EXPAND|wx.ALL, 0)
  666         sizer2.AddSpacer(self.BORDER)
  667 
  668         # Set the sizer for the frame.
  669         self.SetSizer(sizer1)
  670 
  671         # Return the central sizer.
  672         return central_sizer
  673 
  674 
  675     def cancel(self, event):
  676         """Close the window.
  677 
  678         @param event:   The wx event.
  679         @type event:    wx event
  680         """
  681 
  682         # Close the window.
  683         self.Close()
  684 
  685 
  686     def reset(self, event):
  687         """Reset the free file format settings.
  688 
  689         @param event:   The wx event.
  690         @type event:    wx event
  691         """
  692 
  693         # Execute the base class method.
  694         self._element.reset(event)
  695 
  696 
  697     def save(self, event):
  698         """Save the free file format widget contents into the relax data store.
  699 
  700         @param event:   The wx event.
  701         @type event:    wx event
  702         """
  703 
  704         # Execute the base class method.
  705         self._element.save(event)
  706 
  707         # Close the window.
  708         self.Close()