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

Source Code for Module gui.analyses.elements.spin_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 gui.fonts import font 
 32   
 33   
34 -class Spin_ctrl:
35 """The analysis specific spin control.""" 36
37 - 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):
38 """Create a text selection element using a spinner for the frame. 39 40 This consists of a horizontal layout with a static text element and a spin control 41 42 @param box: The box element to pack the structure file selection GUI element into. 43 @type box: wx.BoxSizer instance 44 @param parent: The parent GUI element. 45 @type parent: wx object 46 @keyword text: The static text. 47 @type text: str 48 @keyword default: The default value of the control. 49 @type default: int 50 @keyword min: The minimum value allowed. 51 @type min: int 52 @keyword max: The maximum value allowed. 53 @type max: int 54 @keyword tooltip: The tooltip which appears on hovering over the text or spin control. 55 @type tooltip: str 56 @keyword control: The control class to use. 57 @type control: wx.SpinCtrl derived class 58 @keyword width_text: The width of the text element. 59 @type width_text: int 60 @keyword width_button: The width of the button. 61 @type width_button: int 62 @keyword spacer: The horizontal spacing between the elements. 63 @type spacer: int 64 """ 65 66 # Horizontal packing for this element. 67 sizer = wx.BoxSizer(wx.HORIZONTAL) 68 69 # The label. 70 self.label = wx.StaticText(parent, -1, text) 71 self.label.SetMinSize((width_text, -1)) 72 self.label.SetFont(font.normal) 73 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 74 75 # The size for all elements, based on this text. 76 size = self.label.GetSize() 77 size_horizontal = size[1] + 8 78 79 # Spacer. 80 sizer.AddSpacer((spacer, -1)) 81 82 # The spin control. 83 self.control = control(parent, -1, text, min=min, max=max) 84 self.control.SetMinSize((-1, size_horizontal)) 85 self.control.SetFont(font.normal) 86 sizer.Add(self.control, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 87 self.control.SetValue(default) 88 89 # Spacer. 90 sizer.AddSpacer((spacer, -1)) 91 92 # No button, so add a spacer. 93 sizer.AddSpacer((width_button, -1)) 94 95 # Tooltip. 96 if tooltip: 97 self.label.SetToolTipString(tooltip) 98 self.control.SetToolTipString(tooltip) 99 100 # Add the element to the box. 101 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
102 103
104 - def Enable(self, enable=True):
105 """Enable or disable the window for user input. 106 107 @keyword enable: The flag specifying if the control should be enabled or disabled. 108 @type enable: bool 109 """ 110 111 # Call the control's method. 112 self.control.Enable(enable)
113 114
115 - def GetValue(self):
116 """Set the value of the control. 117 118 @return: The value of the spin control. 119 @rtype: int 120 """ 121 122 # Get the value from the spin control. 123 return self.control.GetValue()
124 125
126 - def SetValue(self, value):
127 """Set the value of the control. 128 129 @param value: The value to set the spin control to. 130 @type value: int 131 """ 132 133 # Set the value of the spin control. 134 return self.control.SetValue(value)
135