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