Package gui :: Package analyses :: Package elements :: Module text_element
[hide private]
[frames] | no frames]

Source Code for Module gui.analyses.elements.text_element

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009 Michael Bieri                                            # 
  4  # Copyright (C) 2010-2013 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  from graphics import fetch_icon 
 32  from gui.fonts import font 
 33  from gui.string_conv import str_to_gui 
 34   
 35   
36 -class Text_ctrl:
37 """The analysis specific text control. 38 39 This consists of three elements: wx.StaticText, wx.TextCtrl, and wx.Button. 40 """ 41
42 - def __init__(self, box, parent, text="", default="", tooltip=None, tooltip_button=None, button_text=" Change", control=wx.TextCtrl, icon=fetch_icon('oxygen.actions.document-open', "16x16"), fn=None, editable=True, button=False, width_text=200, width_button=80, spacer=0):
43 """Create a text selection element for the frame. 44 45 This consists of a horizontal layout with a static text element, a text control, and an optional button. 46 47 @param box: The box element to pack the structure file selection GUI element into. 48 @type box: wx.BoxSizer instance 49 @param parent: The parent GUI element. 50 @type parent: wx object 51 @keyword text: The static text. 52 @type text: str 53 @keyword default: The default text of the control. 54 @type default: str 55 @keyword tooltip: The tooltip which appears on hovering over the text or input field. 56 @type tooltip: str 57 @keyword tooltip_button: The separate tooltip for the button. 58 @type tooltip_button: str 59 @keyword button_text: The text to display on the button. 60 @type button_text: str 61 @keyword control: The control class to use. 62 @type control: wx.TextCtrl derived class 63 @keyword icon: The path of the icon to use for the button. 64 @type icon: str 65 @keyword fn: The function or method to execute when clicking on the button. If this is a string, then an equivalent function will be searched for in the control object. 66 @type fn: func or str 67 @keyword editable: A flag specifying if the control is editable or not. 68 @type editable: bool 69 @keyword button: A flag which if True will cause a button to appear. 70 @type button: bool 71 @keyword width_text: The width of the text element. 72 @type width_text: int 73 @keyword width_button: The width of the button. 74 @type width_button: int 75 @keyword spacer: The horizontal spacing between the elements. 76 @type spacer: int 77 """ 78 79 # Horizontal packing for this element. 80 sizer = wx.BoxSizer(wx.HORIZONTAL) 81 82 # The label. 83 self.label = wx.StaticText(parent, -1, text) 84 self.label.SetMinSize((width_text, -1)) 85 self.label.SetFont(font.normal) 86 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 87 88 # The size for all elements, based on this text. 89 size = self.label.GetSize() 90 size_horizontal = size[1] + 8 91 92 # Spacer. 93 sizer.AddSpacer((spacer, -1)) 94 95 # The text input field. 96 self.field = control(parent, -1, str_to_gui(default)) 97 self.field.SetMinSize((-1, size_horizontal)) 98 self.field.SetFont(font.normal) 99 self.field.SetEditable(editable) 100 if not editable: 101 colour = parent.GetBackgroundColour() 102 self.field.SetOwnBackgroundColour(colour) 103 sizer.Add(self.field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 104 105 # Spacer. 106 sizer.AddSpacer((spacer, -1)) 107 108 # The button. 109 if button: 110 # Function is in the control class. 111 if isinstance(fn, str): 112 # The function. 113 fn = getattr(field, fn) 114 115 # Add the button. 116 self.button = wx.lib.buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(button_text)) 117 self.button.SetBitmapLabel(wx.Bitmap(icon, wx.BITMAP_TYPE_ANY)) 118 self.button.SetMinSize((width_button, size_horizontal)) 119 self.button.SetFont(font.normal) 120 parent.Bind(wx.EVT_BUTTON, fn, self.button) 121 sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 122 123 # No button, so add a spacer. 124 else: 125 sizer.AddSpacer((width_button, -1)) 126 127 # Add the element to the box. 128 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0) 129 130 # Tooltip. 131 if tooltip: 132 self.label.SetToolTipString(tooltip) 133 self.field.SetToolTipString(tooltip) 134 if button and tooltip_button: 135 self.button.SetToolTipString(tooltip_button)
136 137
138 - def Enable(self, enable=True):
139 """Enable or disable the element for user input. 140 141 @keyword enable: The flag specifying if the element should be enabled or disabled. 142 @type enable: bool 143 """ 144 145 # Call the control and button methods. 146 self.field.Enable(enable) 147 if hasattr(self, 'button'): 148 self.button.Enable(enable)
149 150
151 - def GetValue(self):
152 """Set the value of the control. 153 154 @return: The value of the text control. 155 @rtype: int 156 """ 157 158 # Get the value from the text control. 159 return self.field.GetValue()
160 161
162 - def SetValue(self, value):
163 """Set the value of the control. 164 165 @param value: The value to set the text control to. 166 @type value: text 167 """ 168 169 # Set the value of the text control. 170 return self.field.SetValue(value)
171