"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/gui/input_elements/dir.py" (2 Dec 2019, 7097 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 "dir.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) 2012 Edward d'Auvergne                                        #
    4 #                                                                             #
    5 # This file is part of the program relax (http://www.nmr-relax.com).          #
    6 #                                                                             #
    7 # This program is free software: you can redistribute it and/or modify        #
    8 # it under the terms of the GNU General Public License as published by        #
    9 # the Free Software Foundation, either version 3 of the License, or           #
   10 # (at your option) any later version.                                         #
   11 #                                                                             #
   12 # This program is distributed in the hope that it will be useful,             #
   13 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
   14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
   15 # GNU General Public License for more details.                                #
   16 #                                                                             #
   17 # You should have received a copy of the GNU General Public License           #
   18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
   19 #                                                                             #
   20 ###############################################################################
   21 
   22 # Module docstring.
   23 """Module containing a set of special GUI elements to be used in the relax wizards."""
   24 
   25 # Python module imports.
   26 import wx
   27 
   28 # relax module imports.
   29 import dep_check
   30 from graphics import fetch_icon
   31 from gui.filedialog import RelaxDirDialog
   32 from gui.fonts import font
   33 from gui.string_conv import gui_to_str, str_to_gui
   34 from lib.errors import RelaxError
   35 from status import Status; status = Status()
   36 
   37 
   38 class Selector_dir:
   39     """Wizard GUI element for selecting directories."""
   40 
   41     def __init__(self, name=None, default=None, parent=None, sizer=None, desc=None, message='File selection', style=wx.FD_DEFAULT_STYLE, tooltip=None, divider=None, padding=0, spacer=None, height_element=27, read_only=False):
   42         """Build the file selection element.
   43 
   44         @keyword name:              The name of the element to use in titles, etc.
   45         @type name:                 str
   46         @keyword default:           The default value of the element.
   47         @type default:              str
   48         @keyword parent:            The wizard GUI element.
   49         @type parent:               wx.Panel instance
   50         @keyword sizer:             The sizer to put the input field into.
   51         @type sizer:                wx.Sizer instance
   52         @keyword desc:              The text description.
   53         @type desc:                 str
   54         @keyword message:           The file selector prompt string.
   55         @type message:              String
   56         @keyword style:             The dialog style.  To open a single file, set to wx.FD_OPEN.  To open multiple files, set to wx.FD_OPEN|wx.FD_MULTIPLE.  To save a single file, set to wx.FD_SAVE.  To save multiple files, set to wx.FD_SAVE|wx.FD_MULTIPLE.
   57         @type style:                long
   58         @keyword tooltip:           The tooltip which appears on hovering over all the GUI elements.
   59         @type tooltip:              str
   60         @keyword divider:           The position of the divider.
   61         @type divider:              int
   62         @keyword padding:           Spacing to the left and right of the widgets.
   63         @type padding:              int
   64         @keyword spacer:            The amount of spacing to add below the field in pixels.  If None, a stretchable spacer will be used.
   65         @type spacer:               None or int
   66         @keyword height_element:    The height in pixels of the GUI element.
   67         @type height_element:       int
   68         @keyword read_only:         A flag which if True means that the text of the element cannot be edited.
   69         @type read_only:            bool
   70         """
   71 
   72         # Store the args.
   73         self.name = name
   74 
   75         # Argument translation.
   76         if default == None:
   77             default = wx.EmptyString
   78 
   79         # Init.
   80         sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
   81 
   82         # Left padding.
   83         sub_sizer.AddSpacer(padding)
   84 
   85         # The description.
   86         text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT)
   87         text.SetFont(font.normal)
   88         sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
   89 
   90         # The divider.
   91         if not divider:
   92             raise RelaxError("The divider position has not been supplied.")
   93 
   94         # Spacing.
   95         x, y = text.GetSize()
   96         if dep_check.wx_classic:
   97             sub_sizer.AddSpacer((divider - x, 0))
   98         else:
   99             sub_sizer.AddSpacer(divider - x)
  100 
  101         # The input field.
  102         self._field = wx.TextCtrl(parent, -1, default)
  103         self._field.SetMinSize((-1, height_element))
  104         self._field.SetFont(font.normal)
  105         sub_sizer.Add(self._field, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
  106 
  107         # The directory selection object.
  108         obj = RelaxDirDialog(parent, field=self._field, message=message, defaultPath=default, style=style)
  109 
  110         # A little spacing.
  111         sub_sizer.AddSpacer(5)
  112 
  113         # The file selection button.
  114         button = wx.BitmapButton(parent, -1, wx.Bitmap(fetch_icon('oxygen.actions.document-open-folder'), wx.BITMAP_TYPE_ANY))
  115         button.SetMinSize((height_element, height_element))
  116         button.SetToolTip(wx.ToolTip("Select the directory."))
  117         sub_sizer.Add(button, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
  118         parent.Bind(wx.EVT_BUTTON, obj.select_event, button)
  119 
  120         # Right padding.
  121         sub_sizer.AddSpacer(padding)
  122 
  123         # Add to the main sizer (followed by stretchable spacing).
  124         sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0)
  125 
  126         # Spacing below the widget.
  127         if spacer == None:
  128             sizer.AddStretchSpacer()
  129         else:
  130             sizer.AddSpacer(spacer)
  131 
  132         # Tooltip.
  133         if tooltip:
  134             text.SetToolTip(wx.ToolTip(tooltip))
  135             self._field.SetToolTip(wx.ToolTip(tooltip))
  136 
  137 
  138     def Clear(self):
  139         """Special method for clearing or resetting the GUI element."""
  140 
  141         # Clear the value from the TextCtrl.
  142         self._field.Clear()
  143 
  144 
  145     def GetValue(self):
  146         """Special method for returning the value of the GUI element.
  147 
  148         @return:    The string value.
  149         @rtype:     list of str
  150         """
  151 
  152         # Convert and return the value from a TextCtrl.
  153         return gui_to_str(self._field.GetValue())
  154 
  155 
  156     def SetValue(self, value):
  157         """Special method for setting the value of the GUI element.
  158 
  159         @param value:   The value to set.
  160         @type value:    str
  161         """
  162 
  163         # Convert and set the value for a TextCtrl.
  164         self._field.SetValue(str_to_gui(value))