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