Package gui :: Package input_elements :: Module dir
[hide private]
[frames] | no frames]

Source Code for Module gui.input_elements.dir

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2012-2013 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  from graphics import fetch_icon 
 30  from gui.filedialog import RelaxDirDialog 
 31  from gui.fonts import font 
 32  from gui.string_conv import gui_to_str, str_to_gui 
 33  from lib.errors import RelaxError 
 34  from status import Status; status = Status() 
 35   
 36   
37 -class Selector_dir:
38 """Wizard GUI element for selecting directories.""" 39
40 - 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):
41 """Build the file selection element. 42 43 @keyword name: The name of the element to use in titles, etc. 44 @type name: str 45 @keyword default: The default value of the element. 46 @type default: str 47 @keyword parent: The wizard GUI element. 48 @type parent: wx.Panel instance 49 @keyword sizer: The sizer to put the input field into. 50 @type sizer: wx.Sizer instance 51 @keyword desc: The text description. 52 @type desc: str 53 @keyword message: The file selector prompt string. 54 @type message: String 55 @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. 56 @type style: long 57 @keyword tooltip: The tooltip which appears on hovering over all the GUI elements. 58 @type tooltip: str 59 @keyword divider: The position of the divider. 60 @type divider: int 61 @keyword padding: Spacing to the left and right of the widgets. 62 @type padding: int 63 @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used. 64 @type spacer: None or int 65 @keyword height_element: The height in pixels of the GUI element. 66 @type height_element: int 67 @keyword read_only: A flag which if True means that the text of the element cannot be edited. 68 @type read_only: bool 69 """ 70 71 # Store the args. 72 self.name = name 73 74 # Argument translation. 75 if default == None: 76 default = wx.EmptyString 77 78 # Init. 79 sub_sizer = wx.BoxSizer(wx.HORIZONTAL) 80 81 # Left padding. 82 sub_sizer.AddSpacer(padding) 83 84 # The description. 85 text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT) 86 text.SetFont(font.normal) 87 sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 88 89 # The divider. 90 if not divider: 91 raise RelaxError("The divider position has not been supplied.") 92 93 # Spacing. 94 x, y = text.GetSize() 95 sub_sizer.AddSpacer((divider - x, 0)) 96 97 # The input field. 98 self._field = wx.TextCtrl(parent, -1, default) 99 self._field.SetMinSize((-1, height_element)) 100 self._field.SetFont(font.normal) 101 sub_sizer.Add(self._field, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 102 103 # The directory selection object. 104 obj = RelaxDirDialog(parent, field=self._field, message=message, defaultPath=default, style=style) 105 106 # A little spacing. 107 sub_sizer.AddSpacer(5) 108 109 # The file selection button. 110 button = wx.BitmapButton(parent, -1, wx.Bitmap(fetch_icon('oxygen.actions.document-open-folder'), wx.BITMAP_TYPE_ANY)) 111 button.SetMinSize((height_element, height_element)) 112 button.SetToolTipString("Select the directory.") 113 sub_sizer.Add(button, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 114 parent.Bind(wx.EVT_BUTTON, obj.select_event, button) 115 116 # Right padding. 117 sub_sizer.AddSpacer(padding) 118 119 # Add to the main sizer (followed by stretchable spacing). 120 sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0) 121 122 # Spacing below the widget. 123 if spacer == None: 124 sizer.AddStretchSpacer() 125 else: 126 sizer.AddSpacer(spacer) 127 128 # Tooltip. 129 if tooltip: 130 text.SetToolTipString(tooltip) 131 self._field.SetToolTipString(tooltip)
132 133
134 - def Clear(self):
135 """Special method for clearing or resetting the GUI element.""" 136 137 # Clear the value from the TextCtrl. 138 self._field.Clear()
139 140
141 - def GetValue(self):
142 """Special method for returning the value of the GUI element. 143 144 @return: The string value. 145 @rtype: list of str 146 """ 147 148 # Convert and return the value from a TextCtrl. 149 return gui_to_str(self._field.GetValue())
150 151
152 - def SetValue(self, value):
153 """Special method for setting the value of the GUI element. 154 155 @param value: The value to set. 156 @type value: str 157 """ 158 159 # Convert and set the value for a TextCtrl. 160 self._field.SetValue(str_to_gui(value))
161