Package gui :: Package analyses :: Package elements :: Module bool_element
[hide private]
[frames] | no frames]

Source Code for Module gui.analyses.elements.bool_element

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-2010 Michael Bieri                                       # 
  4  # Copyright (C) 2009-2011,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  # Module docstring. 
 24  """Module containing the base class for all frames.""" 
 25   
 26  # Python module imports. 
 27  import wx 
 28  import wx.lib.buttons 
 29   
 30  # relax module imports. 
 31  from graphics import fetch_icon 
 32  from gui.fonts import font 
 33  from gui.string_conv import str_to_gui 
 34   
 35   
36 -class Boolean_ctrl:
37 """The analysis specific text control. 38 39 This consists of three elements: wx.StaticText, wx.TextCtrl, and wx.Button. 40 """ 41
42 - def __init__(self, box, parent, text="", default=True, tooltip=None, tooltip_button=None, button_text=" Toggle", control=wx.TextCtrl, width_text=200, width_button=80, spacer=0):
43 """Create a text selection element for the frame. 44 45 This consists of a horizontal layout with a static text element, a text control, and an optional button. 46 47 @param box: The box element to pack the structure file selection GUI element into. 48 @type box: wx.BoxSizer instance 49 @param parent: The parent GUI element. 50 @type parent: wx object 51 @keyword text: The static text. 52 @type text: str 53 @keyword default: The default value of the control. 54 @type default: bool 55 @keyword tooltip: The tooltip which appears on hovering over the text or input field. 56 @type tooltip: str 57 @keyword tooltip_button: The separate tooltip for the button. 58 @type tooltip_button: str 59 @keyword button_text: The text to display on the button. 60 @type button_text: str 61 @keyword control: The control class to use. 62 @type control: wx.TextCtrl derived class 63 @keyword width_text: The width of the text element. 64 @type width_text: int 65 @keyword width_button: The width of the button. 66 @type width_button: int 67 @keyword spacer: The horizontal spacing between the elements. 68 @type spacer: int 69 """ 70 71 # Store the state. 72 self.state = default 73 74 # Horizontal packing for this element. 75 sizer = wx.BoxSizer(wx.HORIZONTAL) 76 77 # The label. 78 self.label = wx.StaticText(parent, -1, text) 79 self.label.SetMinSize((width_text, -1)) 80 self.label.SetFont(font.normal) 81 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 82 83 # The size for all elements, based on this text. 84 size = self.label.GetSize() 85 size_horizontal = size[1] + 8 86 87 # Spacer. 88 sizer.AddSpacer((spacer, -1)) 89 90 # The text input field. 91 self.field = control(parent, -1, str_to_gui(default)) 92 self.field.SetMinSize((-1, size_horizontal)) 93 self.field.SetFont(font.normal) 94 colour = parent.GetBackgroundColour() 95 self.field.SetOwnBackgroundColour(colour) 96 sizer.Add(self.field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 97 98 # Spacer. 99 sizer.AddSpacer((spacer, -1)) 100 101 # Add the button. 102 self.button = wx.lib.buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(button_text)) 103 if default == True: 104 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY)) 105 else: 106 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY)) 107 self.button.SetMinSize((width_button, size_horizontal)) 108 self.button.SetFont(font.normal) 109 parent.Bind(wx.EVT_BUTTON, self.toggle, self.button) 110 sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 111 112 # Add the element to the box. 113 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0) 114 115 # Tooltip. 116 if tooltip: 117 self.label.SetToolTipString(tooltip) 118 self.field.SetToolTipString(tooltip) 119 if tooltip_button: 120 self.button.SetToolTipString(tooltip_button)
121 122
123 - def Enable(self, enable=True):
124 """Enable or disable the element for user input. 125 126 @keyword enable: The flag specifying if the element should be enabled or disabled. 127 @type enable: bool 128 """ 129 130 # Call the button method. 131 self.button.Enable(enable)
132 133
134 - def GetValue(self):
135 """Set the value of the control. 136 137 @return: The value of the text control. 138 @rtype: int 139 """ 140 141 # Return the state. 142 return self.state
143 144
145 - def SetValue(self, value):
146 """Set the value of the control. 147 148 @param value: The value to set the boolean control to. 149 @type value: bool 150 """ 151 152 # True. 153 if value == True: 154 self.field.SetValue('True') 155 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY)) 156 self.state = True 157 158 # False: 159 else: 160 self.field.SetValue('False') 161 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY)) 162 self.state = False
163 164
165 - def toggle(self, event=None):
166 """Switch the state.""" 167 168 # From False to True. 169 if self.state == False: 170 self.field.SetValue('True') 171 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY)) 172 self.state = True 173 174 # From True to False. 175 else: 176 self.field.SetValue('False') 177 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY)) 178 self.state = False
179