"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/gui/input_elements/bool.py" (2 Dec 2019, 6085 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 "bool.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) 2012 Edward d'Auvergne                                        #
    4 #                                                                             #
    5 # This file is part of the program relax (http://www.nmr-relax.com).          #
    6 #                                                                             #
    7 # This program is free software: you can redistribute it and/or modify        #
    8 # it under the terms of the GNU General Public License as published by        #
    9 # the Free Software Foundation, either version 3 of the License, or           #
   10 # (at your option) any later version.                                         #
   11 #                                                                             #
   12 # This program is distributed in the hope that it will be useful,             #
   13 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
   14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
   15 # GNU General Public License for more details.                                #
   16 #                                                                             #
   17 # You should have received a copy of the GNU General Public License           #
   18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
   19 #                                                                             #
   20 ###############################################################################
   21 
   22 # Module docstring.
   23 """Module containing a set of special GUI elements to be used in the relax wizards."""
   24 
   25 # Python module imports.
   26 import wx
   27 
   28 # relax module imports.
   29 import dep_check
   30 from gui.fonts import font
   31 from gui.string_conv import bool_to_gui, gui_to_bool
   32 from lib.errors import RelaxError
   33 from status import Status; status = Status()
   34 
   35 
   36 class Selector_bool:
   37     """Wizard GUI element for boolean selection."""
   38 
   39     def __init__(self, name=None, parent=None, element_type='default', sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None, height_element=27, default=True):
   40         """Build the boolean selector widget for selecting between True and False.
   41 
   42         @keyword name:              The name of the element to use in titles, etc.
   43         @type name:                 str
   44         @keyword parent:            The wizard GUI element.
   45         @type parent:               wx.Panel instance
   46         @keyword element_type:      The type of GUI element to create.  This is currently unused, but can in the future specify alternative selector widgets.
   47         @type element_type:         str
   48         @keyword sizer:             The sizer to put the combo box widget into.
   49         @type sizer:                wx.Sizer instance
   50         @keyword desc:              The text description.
   51         @type desc:                 str
   52         @keyword tooltip:           The tooltip which appears on hovering over the text or input field.
   53         @type tooltip:              str
   54         @keyword divider:           The position of the divider.
   55         @type divider:              int
   56         @keyword padding:           Spacing to the left and right of the widgets.
   57         @type padding:              int
   58         @keyword spacer:            The amount of spacing to add below the field in pixels.  If None, a stretchable spacer will be used.
   59         @type spacer:               None or int
   60         @keyword height_element:    The height in pixels of the GUI element.
   61         @type height_element:       int
   62         @keyword default:           The default boolean value.
   63         @type default:              bool
   64         """
   65 
   66         # Store the args.
   67         self.default = default
   68         self.name = name
   69         self.element_type = element_type
   70 
   71         # Init.
   72         sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
   73 
   74         # Left padding.
   75         sub_sizer.AddSpacer(padding)
   76 
   77         # The description.
   78         text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT)
   79         text.SetFont(font.normal)
   80         sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
   81 
   82         # The divider.
   83         if not divider:
   84             raise RelaxError("The divider position has not been supplied.")
   85 
   86         # Spacing.
   87         x, y = text.GetSize()
   88         if dep_check.wx_classic:
   89             sub_sizer.AddSpacer((divider - x, 0))
   90         else:
   91             sub_sizer.AddSpacer(divider - x)
   92 
   93         # The combo box element.
   94         style = wx.CB_DROPDOWN | wx.CB_READONLY
   95         self.combo = wx.ComboBox(parent, -1, value=bool_to_gui(default), style=style, choices=['True', 'False'])
   96         self.combo.SetMinSize((50, height_element))
   97         self.combo.SetFont(font.normal)
   98         sub_sizer.Add(self.combo, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
   99 
  100         # Right padding.
  101         sub_sizer.AddSpacer(padding)
  102 
  103         # Add to the main sizer.
  104         sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0)
  105 
  106         # Spacing below the widget.
  107         if spacer == None:
  108             sizer.AddStretchSpacer()
  109         else:
  110             sizer.AddSpacer(spacer)
  111 
  112         # Tooltip.
  113         if tooltip:
  114             text.SetToolTip(wx.ToolTip(tooltip))
  115             self.combo.SetToolTip(wx.ToolTip(tooltip))
  116 
  117 
  118     def Clear(self):
  119         """Special method for clearing or resetting the GUI element."""
  120 
  121         # Reset to the default.
  122         self.combo.SetStringSelection(bool_to_gui(self.default))
  123 
  124 
  125     def GetValue(self):
  126         """Special method for returning the value of the GUI element.
  127 
  128         @return:    The string list value.
  129         @rtype:     list of str
  130         """
  131 
  132         # Convert and return the value from a ComboBox.
  133         return gui_to_bool(self.combo.GetValue())
  134 
  135 
  136     def SetValue(self, value):
  137         """Special method for setting the value of the GUI element.
  138 
  139         @param value:   The value to set.
  140         @type value:    list of str
  141         """
  142 
  143         # Set the selection.
  144         self.combo.SetStringSelection(bool_to_gui(value))