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  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 dc = wx.ScreenDC() 88 dc.SetFont(font.normal) 89 x, y = dc.GetTextExtent(desc) 90 if dep_check.wx_classic: 91 sub_sizer.AddSpacer((divider - x, 0)) 92 else: 93 sub_sizer.AddSpacer(int(divider - x)) 94 95 # The combo box element. 96 style = wx.CB_DROPDOWN | wx.CB_READONLY 97 self.combo = wx.ComboBox(parent, -1, value=bool_to_gui(default), style=style, choices=['True', 'False']) 98 self.combo.SetMinSize((50, height_element)) 99 self.combo.SetFont(font.normal) 100 sub_sizer.Add(self.combo, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 101 102 # Right padding. 103 sub_sizer.AddSpacer(padding) 104 105 # Add to the main sizer. 106 sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0) 107 108 # Spacing below the widget. 109 if spacer == None: 110 sizer.AddStretchSpacer() 111 else: 112 sizer.AddSpacer(spacer) 113 114 # Tooltip. 115 if tooltip: 116 text.SetToolTip(wx.ToolTip(tooltip)) 117 self.combo.SetToolTip(wx.ToolTip(tooltip))
118 119
120 - def Clear(self):
121 """Special method for clearing or resetting the GUI element.""" 122 123 # Reset to the default. 124 self.combo.SetStringSelection(bool_to_gui(self.default))
125 126
127 - def GetValue(self):
128 """Special method for returning the value of the GUI element. 129 130 @return: The string list value. 131 @rtype: list of str 132 """ 133 134 # Convert and return the value from a ComboBox. 135 return gui_to_bool(self.combo.GetValue())
136 137
138 - def SetValue(self, value):
139 """Special method for setting the value of the GUI element. 140 141 @param value: The value to set. 142 @type value: list of str 143 """ 144 145 # Set the selection. 146 self.combo.SetStringSelection(bool_to_gui(value))
147