"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/gui/analyses/elements/spin_element.py" (2 Dec 2019, 5767 Bytes) of package /linux/privat/relax-5.0.0.src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "spin_element.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.1.3_vs_5.0.0.

    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         size = self.label.GetSize()
   78         size_horizontal = size[1] + 8
   79 
   80         # Spacer.
   81         if dep_check.wx_classic:
   82             sizer.AddSpacer((spacer, -1))
   83         else:
   84             sizer.AddSpacer(spacer)
   85 
   86         # The spin control.
   87         self.control = control(parent, -1, text, min=min, max=max)
   88         self.control.SetMinSize((-1, size_horizontal))
   89         self.control.SetFont(font.normal)
   90         sizer.Add(self.control, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
   91         self.control.SetValue(default)
   92 
   93         # Spacer.
   94         if dep_check.wx_classic:
   95             sizer.AddSpacer((spacer, -1))
   96         else:
   97             sizer.AddSpacer(spacer)
   98 
   99         # No button, so add a spacer.
  100         if dep_check.wx_classic:
  101             sizer.AddSpacer((width_button, -1))
  102         else:
  103             sizer.AddSpacer(width_button)
  104 
  105         # Tooltip.
  106         if tooltip:
  107             self.label.SetToolTip(wx.ToolTip(tooltip))
  108             self.control.SetToolTip(wx.ToolTip(tooltip))
  109 
  110         # Add the element to the box.
  111         box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
  112 
  113 
  114     def Enable(self, enable=True):
  115         """Enable or disable the window for user input.
  116 
  117         @keyword enable:    The flag specifying if the control should be enabled or disabled.
  118         @type enable:       bool
  119         """
  120 
  121         # Call the control's method.
  122         self.control.Enable(enable)
  123 
  124 
  125     def GetValue(self):
  126         """Set the value of the control.
  127 
  128         @return:    The value of the spin control.
  129         @rtype:     int
  130         """
  131 
  132         # Get the value from the spin control.
  133         return self.control.GetValue()
  134 
  135 
  136     def SetValue(self, value):
  137         """Set the value of the control.
  138 
  139         @param value:   The value to set the spin control to.
  140         @type value:    int
  141         """
  142 
  143         # Set the value of the spin control.
  144         return self.control.SetValue(value)