"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/gui/analyses/elements/bool_element.py" (2 Dec 2019, 7639 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 "bool_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 graphics import fetch_icon
   33 from gui.fonts import font
   34 from gui.string_conv import str_to_gui
   35 
   36 
   37 class Boolean_ctrl:
   38     """The analysis specific text control.
   39 
   40     This consists of three elements:  wx.StaticText, wx.TextCtrl, and wx.Button.
   41     """
   42 
   43     def __init__(self, box, parent, text="", default=True, tooltip=None, tooltip_button=None, button_text=" Toggle", control=wx.TextCtrl, width_text=200, width_button=80, spacer=0):
   44         """Create a text selection element for the frame.
   45 
   46         This consists of a horizontal layout with a static text element, a text control, and an optional button.
   47 
   48         @param box:                 The box element to pack the structure file selection GUI element into.
   49         @type box:                  wx.BoxSizer instance
   50         @param parent:              The parent GUI element.
   51         @type parent:               wx object
   52         @keyword text:              The static text.
   53         @type text:                 str
   54         @keyword default:           The default value of the control.
   55         @type default:              bool
   56         @keyword tooltip:           The tooltip which appears on hovering over the text or input field.
   57         @type tooltip:              str
   58         @keyword tooltip_button:    The separate tooltip for the button.
   59         @type tooltip_button:       str
   60         @keyword button_text:       The text to display on the button.
   61         @type button_text:          str
   62         @keyword control:           The control class to use.
   63         @type control:              wx.TextCtrl derived class
   64         @keyword width_text:        The width of the text element.
   65         @type width_text:           int
   66         @keyword width_button:      The width of the button.
   67         @type width_button:         int
   68         @keyword spacer:            The horizontal spacing between the elements.
   69         @type spacer:               int
   70         """
   71 
   72         # Store the state.
   73         self.state = default
   74 
   75         # Horizontal packing for this element.
   76         sizer = wx.BoxSizer(wx.HORIZONTAL)
   77 
   78         # The label.
   79         self.label = wx.StaticText(parent, -1, text)
   80         self.label.SetMinSize((width_text, -1))
   81         self.label.SetFont(font.normal)
   82         sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
   83 
   84         # The size for all elements, based on this text.
   85         size = self.label.GetSize()
   86         size_horizontal = size[1] + 8
   87 
   88         # Spacer.
   89         if dep_check.wx_classic:
   90             sizer.AddSpacer((spacer, -1))
   91         else:
   92             sizer.AddSpacer(spacer)
   93 
   94         # The text input field.
   95         self.field = control(parent, -1, str_to_gui(default))
   96         self.field.SetMinSize((-1, size_horizontal))
   97         self.field.SetFont(font.normal)
   98         colour = parent.GetBackgroundColour()
   99         self.field.SetOwnBackgroundColour(colour)
  100         sizer.Add(self.field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
  101 
  102         # Spacer.
  103         if dep_check.wx_classic:
  104             sizer.AddSpacer((spacer, -1))
  105         else:
  106             sizer.AddSpacer(spacer)
  107 
  108         # Add the button.
  109         self.button = wx.lib.buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(button_text))
  110         if default == True:
  111             self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY))
  112         else:
  113             self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY))
  114         self.button.SetMinSize((width_button, size_horizontal))
  115         self.button.SetFont(font.normal)
  116         parent.Bind(wx.EVT_BUTTON, self.toggle, self.button)
  117         sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
  118 
  119         # Add the element to the box.
  120         box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
  121 
  122         # Tooltip.
  123         if tooltip:
  124             self.label.SetToolTip(wx.ToolTip(tooltip))
  125             self.field.SetToolTip(wx.ToolTip(tooltip))
  126         if tooltip_button:
  127             self.button.SetToolTip(wx.ToolTip(tooltip_button))
  128 
  129 
  130     def Enable(self, enable=True):
  131         """Enable or disable the element for user input.
  132 
  133         @keyword enable:    The flag specifying if the element should be enabled or disabled.
  134         @type enable:       bool
  135         """
  136 
  137         # Call the button method.
  138         self.button.Enable(enable)
  139 
  140 
  141     def GetValue(self):
  142         """Set the value of the control.
  143 
  144         @return:    The value of the text control.
  145         @rtype:     int
  146         """
  147 
  148         # Return the state.
  149         return self.state
  150 
  151 
  152     def SetValue(self, value):
  153         """Set the value of the control.
  154 
  155         @param value:   The value to set the boolean control to.
  156         @type value:    bool
  157         """
  158 
  159         # True.
  160         if value == True:
  161             self.field.SetValue('True')
  162             self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY))
  163             self.state = True
  164 
  165         # False:
  166         else:
  167             self.field.SetValue('False')
  168             self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY))
  169             self.state = False
  170 
  171 
  172     def toggle(self, event=None):
  173         """Switch the state."""
  174 
  175         # From False to True.
  176         if self.state == False:
  177             self.field.SetValue('True')
  178             self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY))
  179             self.state = True
  180 
  181         # From True to False.
  182         else:
  183             self.field.SetValue('False')
  184             self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY))
  185             self.state = False