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

Source Code for Module gui.analyses.elements

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009 Michael Bieri                                            # 
  4  # Copyright (C) 2010-2012 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 GUI module imports. 
 31  from gui.fonts import font 
 32  from gui.paths import icon_16x16 
 33  from gui.string_conv import str_to_gui 
 34   
 35   
36 -class Spin_ctrl:
37 """The analysis specific spin control.""" 38
39 - def __init__(self, box, parent, text="", default=0, min=0, max=1000, tooltip=None, control=wx.SpinCtrl, width_text=200, width_button=80, spacer=0):
40 """Create a text selection element using a spinner for the frame. 41 42 This consists of a horizontal layout with a static text element and a spin control 43 44 @param box: The box element to pack the structure file selection GUI element into. 45 @type box: wx.BoxSizer instance 46 @param parent: The parent GUI element. 47 @type parent: wx object 48 @keyword text: The static text. 49 @type text: str 50 @keyword default: The default value of the control. 51 @type default: int 52 @keyword min: The minimum value allowed. 53 @type min: int 54 @keyword max: The maximum value allowed. 55 @type max: int 56 @keyword tooltip: The tooltip which appears on hovering over the text or spin control. 57 @type tooltip: str 58 @keyword control: The control class to use. 59 @type control: wx.SpinCtrl derived class 60 @keyword width_text: The width of the text element. 61 @type width_text: int 62 @keyword width_button: The width of the button. 63 @type width_button: int 64 @keyword spacer: The horizontal spacing between the elements. 65 @type spacer: int 66 """ 67 68 # Horizontal packing for this element. 69 sizer = wx.BoxSizer(wx.HORIZONTAL) 70 71 # The label. 72 self.label = wx.StaticText(parent, -1, text) 73 self.label.SetMinSize((width_text, -1)) 74 self.label.SetFont(font.normal) 75 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 76 77 # The size for all elements, based on this text. 78 size = self.label.GetSize() 79 size_horizontal = size[1] + 8 80 81 # Spacer. 82 sizer.AddSpacer((spacer, -1)) 83 84 # The spin control. 85 self.control = control(parent, -1, text, min=min, max=max) 86 self.control.SetMinSize((-1, size_horizontal)) 87 self.control.SetFont(font.normal) 88 sizer.Add(self.control, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 89 self.control.SetValue(default) 90 91 # Spacer. 92 sizer.AddSpacer((spacer, -1)) 93 94 # No button, so add a spacer. 95 sizer.AddSpacer((width_button, -1)) 96 97 # Tooltip. 98 if tooltip: 99 self.label.SetToolTipString(tooltip) 100 self.control.SetToolTipString(tooltip) 101 102 # Add the element to the box. 103 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
104 105
106 - def Enable(self, enable=True):
107 """Enable or disable the window for user input. 108 109 @keyword enable: The flag specifying if the control should be enabled or disabled. 110 @type enable: bool 111 """ 112 113 # Call the control's method. 114 self.control.Enable(enable)
115 116
117 - def GetValue(self):
118 """Set the value of the control. 119 120 @return: The value of the spin control. 121 @rtype: int 122 """ 123 124 # Get the value from the spin control. 125 return self.control.GetValue()
126 127
128 - def SetValue(self, value):
129 """Set the value of the control. 130 131 @param value: The value to set the spin control to. 132 @type value: int 133 """ 134 135 # Set the value of the spin control. 136 return self.control.SetValue(value)
137 138
139 -class Text_ctrl:
140 """The analysis specific text control. 141 142 This consists of three elements: wx.StaticText, wx.TextCtrl, and wx.Button. 143 """ 144
145 - def __init__(self, box, parent, text="", default="", tooltip=None, button_text=" Change", control=wx.TextCtrl, icon=icon_16x16.open, fn=None, editable=True, button=False, width_text=200, width_button=80, spacer=0):
146 """Create a text selection element for the frame. 147 148 This consists of a horizontal layout with a static text element, a text control, and an optional button. 149 150 @param box: The box element to pack the structure file selection GUI element into. 151 @type box: wx.BoxSizer instance 152 @param parent: The parent GUI element. 153 @type parent: wx object 154 @keyword text: The static text. 155 @type text: str 156 @keyword default: The default text of the control. 157 @type default: str 158 @keyword tooltip: The tooltip which appears on hovering over the text or input field. 159 @type tooltip: str 160 @keyword button_text: The text to display on the button. 161 @type button_text: str 162 @keyword control: The control class to use. 163 @type control: wx.TextCtrl derived class 164 @keyword icon: The path of the icon to use for the button. 165 @type icon: str 166 @keyword fn: The function or method to execute when clicking on the button. If this is a string, then an equivalent function will be searched for in the control object. 167 @type fn: func or str 168 @keyword editable: A flag specifying if the control is editable or not. 169 @type editable: bool 170 @keyword button: A flag which if True will cause a button to appear. 171 @type button: bool 172 @keyword width_text: The width of the text element. 173 @type width_text: int 174 @keyword width_button: The width of the button. 175 @type width_button: int 176 @keyword spacer: The horizontal spacing between the elements. 177 @type spacer: int 178 """ 179 180 # Horizontal packing for this element. 181 sizer = wx.BoxSizer(wx.HORIZONTAL) 182 183 # The label. 184 self.label = wx.StaticText(parent, -1, text) 185 self.label.SetMinSize((width_text, -1)) 186 self.label.SetFont(font.normal) 187 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 188 189 # The size for all elements, based on this text. 190 size = self.label.GetSize() 191 size_horizontal = size[1] + 8 192 193 # Spacer. 194 sizer.AddSpacer((spacer, -1)) 195 196 # The text input field. 197 self.field = control(parent, -1, str_to_gui(default)) 198 self.field.SetMinSize((-1, size_horizontal)) 199 self.field.SetFont(font.normal) 200 self.field.SetEditable(editable) 201 if not editable: 202 colour = parent.GetBackgroundColour() 203 self.field.SetOwnBackgroundColour(colour) 204 sizer.Add(self.field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 205 206 # Spacer. 207 sizer.AddSpacer((spacer, -1)) 208 209 # The button. 210 if button: 211 # Function is in the control class. 212 if isinstance(fn, str): 213 # The function. 214 fn = getattr(field, fn) 215 216 # Add the button. 217 self.button = wx.lib.buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(button_text)) 218 self.button.SetBitmapLabel(wx.Bitmap(icon, wx.BITMAP_TYPE_ANY)) 219 self.button.SetMinSize((width_button, size_horizontal)) 220 self.button.SetFont(font.normal) 221 parent.Bind(wx.EVT_BUTTON, fn, self.button) 222 sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 223 224 # No button, so add a spacer. 225 else: 226 sizer.AddSpacer((width_button, -1)) 227 228 # Add the element to the box. 229 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0) 230 231 # Tooltip. 232 if tooltip: 233 self.label.SetToolTipString(tooltip) 234 self.field.SetToolTipString(tooltip) 235 if button: 236 self.button.SetToolTipString(tooltip)
237 238
239 - def Enable(self, enable=True):
240 """Enable or disable the element for user input. 241 242 @keyword enable: The flag specifying if the element should be enabled or disabled. 243 @type enable: bool 244 """ 245 246 # Call the control and button methods. 247 self.field.Enable(enable) 248 if hasattr(self, 'button'): 249 self.button.Enable(enable)
250 251
252 - def GetValue(self):
253 """Set the value of the control. 254 255 @return: The value of the text control. 256 @rtype: int 257 """ 258 259 # Get the value from the text control. 260 return self.field.GetValue()
261 262
263 - def SetValue(self, value):
264 """Set the value of the control. 265 266 @param value: The value to set the text control to. 267 @type value: text 268 """ 269 270 # Set the value of the text control. 271 return self.field.SetValue(value)
272