Package gui :: Package input_elements :: Module bool
[hide private]
[frames] | no frames]

Source Code for Module gui.input_elements.bool

  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  from relax_errors import RelaxError 
 30  from status import Status; status = Status() 
 31   
 32  # relax GUI module imports. 
 33  from gui.fonts import font 
 34  from gui.string_conv import bool_to_gui, gui_to_bool 
 35   
 36   
37 -class Selector_bool:
38 """Wizard GUI element for boolean selection.""" 39
40 - 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):
41 """Build the boolean selector widget for selecting between True and False. 42 43 @keyword name: The name of the element to use in titles, etc. 44 @type name: str 45 @keyword parent: The wizard GUI element. 46 @type parent: wx.Panel instance 47 @keyword element_type: The type of GUI element to create. This is currently unused, but can in the future specify alternative selector widgets. 48 @type element_type: str 49 @keyword sizer: The sizer to put the combo box widget into. 50 @type sizer: wx.Sizer instance 51 @keyword desc: The text description. 52 @type desc: str 53 @keyword tooltip: The tooltip which appears on hovering over the text or input field. 54 @type tooltip: str 55 @keyword divider: The position of the divider. 56 @type divider: int 57 @keyword padding: Spacing to the left and right of the widgets. 58 @type padding: int 59 @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used. 60 @type spacer: None or int 61 @keyword height_element: The height in pixels of the GUI element. 62 @type height_element: int 63 @keyword default: The default boolean value. 64 @type default: bool 65 """ 66 67 # Store the args. 68 self.default = default 69 self.name = name 70 self.element_type = element_type 71 72 # Init. 73 sub_sizer = wx.BoxSizer(wx.HORIZONTAL) 74 75 # Left padding. 76 sub_sizer.AddSpacer(padding) 77 78 # The description. 79 text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT) 80 text.SetFont(font.normal) 81 sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 82 83 # The divider. 84 if not divider: 85 raise RelaxError("The divider position has not been supplied.") 86 87 # Spacing. 88 x, y = text.GetSize() 89 sub_sizer.AddSpacer((divider - x, 0)) 90 91 # The combo box element. 92 style = wx.CB_DROPDOWN | wx.CB_READONLY 93 self.combo = wx.ComboBox(parent, -1, value=bool_to_gui(default), style=style, choices=['True', 'False']) 94 self.combo.SetMinSize((50, height_element)) 95 self.combo.SetFont(font.normal) 96 sub_sizer.Add(self.combo, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 97 98 # Right padding. 99 sub_sizer.AddSpacer(padding) 100 101 # Add to the main sizer. 102 sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0) 103 104 # Spacing below the widget. 105 if spacer == None: 106 sizer.AddStretchSpacer() 107 else: 108 sizer.AddSpacer(spacer) 109 110 # Tooltip. 111 if tooltip: 112 text.SetToolTipString(tooltip) 113 self.combo.SetToolTipString(tooltip)
114 115
116 - def Clear(self):
117 """Special method for clearing or resetting the GUI element.""" 118 119 # Reset to the default. 120 self.combo.SetStringSelection(bool_to_gui(self.default))
121 122
123 - def GetValue(self):
124 """Special method for returning the value of the GUI element. 125 126 @return: The string list value. 127 @rtype: list of str 128 """ 129 130 # Convert and return the value from a ComboBox. 131 return gui_to_bool(self.combo.GetValue())
132 133
134 - def SetValue(self, value):
135 """Special method for setting the value of the GUI element. 136 137 @param value: The value to set. 138 @type value: list of str 139 """ 140 141 # Set the selection. 142 self.combo.SetStringSelection(bool_to_gui(value))
143