1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23  """Module containing a set of special GUI elements to be used in the relax wizards.""" 
 24   
 25   
 26  import wx 
 27   
 28   
 29  from relax_errors import RelaxError 
 30  from status import Status; status = Status() 
 31   
 32   
 33  from gui.fonts import font 
 34  from gui.string_conv import bool_to_gui, gui_to_bool 
 35   
 36   
 38      """Wizard GUI element for boolean selection.""" 
 39   
 40 -    def __init__(self, name=None, parent=None, element_type='default', sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None, height_element=27, default=True): 
  41          """Build the boolean selector widget for selecting between True and False. 
 42   
 43          @keyword name:              The name of the element to use in titles, etc. 
 44          @type name:                 str 
 45          @keyword parent:            The wizard GUI element. 
 46          @type parent:               wx.Panel instance 
 47          @keyword element_type:      The type of GUI element to create.  This is currently unused, but can in the future specify alternative selector widgets. 
 48          @type element_type:         str 
 49          @keyword sizer:             The sizer to put the combo box widget into. 
 50          @type sizer:                wx.Sizer instance 
 51          @keyword desc:              The text description. 
 52          @type desc:                 str 
 53          @keyword tooltip:           The tooltip which appears on hovering over the text or input field. 
 54          @type tooltip:              str 
 55          @keyword divider:           The position of the divider. 
 56          @type divider:              int 
 57          @keyword padding:           Spacing to the left and right of the widgets. 
 58          @type padding:              int 
 59          @keyword spacer:            The amount of spacing to add below the field in pixels.  If None, a stretchable spacer will be used. 
 60          @type spacer:               None or int 
 61          @keyword height_element:    The height in pixels of the GUI element. 
 62          @type height_element:       int 
 63          @keyword default:           The default boolean value. 
 64          @type default:              bool 
 65          """ 
 66   
 67           
 68          self.default = default 
 69          self.name = name 
 70          self.element_type = element_type 
 71   
 72           
 73          sub_sizer = wx.BoxSizer(wx.HORIZONTAL) 
 74   
 75           
 76          sub_sizer.AddSpacer(padding) 
 77   
 78           
 79          text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT) 
 80          text.SetFont(font.normal) 
 81          sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 
 82   
 83           
 84          if not divider: 
 85              raise RelaxError("The divider position has not been supplied.") 
 86   
 87           
 88          x, y = text.GetSize() 
 89          sub_sizer.AddSpacer((divider - x, 0)) 
 90   
 91           
 92          style = wx.CB_DROPDOWN | wx.CB_READONLY 
 93          self.combo = wx.ComboBox(parent, -1, value=bool_to_gui(default), style=style, choices=['True', 'False']) 
 94          self.combo.SetMinSize((50, height_element)) 
 95          self.combo.SetFont(font.normal) 
 96          sub_sizer.Add(self.combo, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 
 97   
 98           
 99          sub_sizer.AddSpacer(padding) 
100   
101           
102          sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0) 
103   
104           
105          if spacer == None: 
106              sizer.AddStretchSpacer() 
107          else: 
108              sizer.AddSpacer(spacer) 
109   
110           
111          if tooltip: 
112              text.SetToolTipString(tooltip) 
113              self.combo.SetToolTipString(tooltip) 
 114   
115   
117          """Special method for clearing or resetting the GUI element.""" 
118   
119           
120          self.combo.SetStringSelection(bool_to_gui(self.default)) 
 121   
122   
124          """Special method for returning the value of the GUI element. 
125   
126          @return:    The string list value. 
127          @rtype:     list of str 
128          """ 
129   
130           
131          return gui_to_bool(self.combo.GetValue()) 
 132   
133   
135          """Special method for setting the value of the GUI element. 
136   
137          @param value:   The value to set. 
138          @type value:    list of str 
139          """ 
140   
141           
142          self.combo.SetStringSelection(bool_to_gui(value)) 
  143