1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24  """Module containing the base class for all frames.""" 
 25   
 26   
 27  import wx 
 28  import wx.lib.buttons 
 29   
 30   
 31  from gui.fonts import font 
 32  from gui.string_conv import str_to_gui 
 33   
 34   
 36      """The analysis specific floating point number control. 
 37   
 38      This consists of two elements:  wx.StaticText and wx.TextCtrl. 
 39      """ 
 40   
 41 -    def __init__(self, box, parent, text="", default="", tooltip=None, editable=True, width_text=200, width_button=80, spacer=0): 
  42          """Create a text selection element for the frame. 
 43   
 44          This consists of a horizontal layout with a static text element, a text control, and an optional button. 
 45   
 46          @param box:                 The box element to pack the structure file selection GUI element into. 
 47          @type box:                  wx.BoxSizer instance 
 48          @param parent:              The parent GUI element. 
 49          @type parent:               wx object 
 50          @keyword text:              The static text. 
 51          @type text:                 str 
 52          @keyword default:           The default text of the control. 
 53          @type default:              str 
 54          @keyword tooltip:           The tooltip which appears on hovering over the text or input field. 
 55          @type tooltip:              str 
 56          @keyword editable:          A flag specifying if the control is editable or not. 
 57          @type editable:             bool 
 58          @keyword width_text:        The width of the text element. 
 59          @type width_text:           int 
 60          @keyword width_button:      The width of the standard button used in the other elements. 
 61          @type width_button:         int 
 62          @keyword spacer:            The horizontal spacing between the elements. 
 63          @type spacer:               int 
 64          """ 
 65   
 66           
 67          sizer = wx.BoxSizer(wx.HORIZONTAL) 
 68   
 69           
 70          self.label = wx.StaticText(parent, -1, text) 
 71          self.label.SetMinSize((width_text, -1)) 
 72          self.label.SetFont(font.normal) 
 73          sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 
 74   
 75           
 76          size = self.label.GetSize() 
 77          size_horizontal = size[1] + 8 
 78   
 79           
 80          sizer.AddSpacer((spacer, -1)) 
 81   
 82           
 83          self.field = wx.TextCtrl(parent, -1, str_to_gui(default)) 
 84          self.field.SetMinSize((-1, size_horizontal)) 
 85          self.field.SetFont(font.normal) 
 86          self.field.SetEditable(editable) 
 87          if not editable: 
 88              colour = parent.GetBackgroundColour() 
 89              self.field.SetOwnBackgroundColour(colour) 
 90          sizer.Add(self.field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) 
 91   
 92           
 93          self.field.Bind(wx.EVT_KEY_DOWN, self.pre_input) 
 94          self.field.Bind(wx.EVT_TEXT, self.post_input) 
 95          self.field.Bind(wx.EVT_KEY_UP, self.end_input) 
 96   
 97           
 98          sizer.AddSpacer((spacer, -1)) 
 99   
100           
101          sizer.AddSpacer((width_button, -1)) 
102   
103           
104          box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0) 
105   
106           
107          if tooltip: 
108              self.label.SetToolTipString(tooltip) 
109              self.field.SetToolTipString(tooltip) 
 110   
111   
112 -    def Enable(self, enable=True): 
 113          """Enable or disable the element for user input. 
114   
115          @keyword enable:    The flag specifying if the element should be enabled or disabled. 
116          @type enable:       bool 
117          """ 
118   
119           
120          self.field.Enable(enable) 
 121   
122   
124          """Set the value of the control. 
125   
126          @return:    The value of the text control. 
127          @rtype:     int 
128          """ 
129   
130           
131          return self.field.GetValue() 
 132   
133   
135          """Set the value of the control. 
136   
137          @param value:   The value to set the text control to. 
138          @type value:    text 
139          """ 
140   
141           
142          return self.field.SetValue(value) 
 143   
144   
160   
161   
181   
182   
184          """Check that the user input is a float when the text changes, restoring the value if not. 
185   
186          @param event:   The wx event. 
187          @type event:    wx event 
188          """ 
189   
190           
191          value = self.field.GetValue() 
192   
193           
194          flag = False 
195   
196           
197          try: 
198              float(value) 
199          except ValueError: 
200              flag = True 
201   
202           
203          if ' ' in value: 
204              flag = True 
205   
206           
207          if 'e' in value or 'E' in value: 
208              flag = True 
209   
210           
211          if flag: 
212              self.field.SetValue(self._value) 
213              self._restore_pos_flag = True 
214   
215           
216          event.Skip() 
  217