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