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 graphics import fetch_icon 
 32  from gui.fonts import font 
 33  from gui.string_conv import str_to_gui 
 34   
 35   
 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           
 80          sizer = wx.BoxSizer(wx.HORIZONTAL) 
 81   
 82           
 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           
 89          size = self.label.GetSize() 
 90          size_horizontal = size[1] + 8 
 91   
 92           
 93          sizer.AddSpacer((spacer, -1)) 
 94   
 95           
 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           
106          sizer.AddSpacer((spacer, -1)) 
107   
108           
109          if button: 
110               
111              if isinstance(fn, str): 
112                   
113                  fn = getattr(field, fn) 
114   
115               
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           
124          else: 
125              sizer.AddSpacer((width_button, -1)) 
126   
127           
128          box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0) 
129   
130           
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           
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           
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           
170          return self.field.SetValue(value) 
  171