1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23  """Auto-analysis GUI element for the control of lists of models.""" 
 24   
 25   
 26  import wx 
 27  from wx.lib import scrolledpanel 
 28  import wx.lib.mixins.listctrl 
 29   
 30   
 31  from graphics import fetch_icon 
 32  from gui.fonts import font 
 33  from gui.message import Question 
 34  from gui.misc import add_border 
 35  from gui.string_conv import list_to_gui, str_to_gui 
 36  from status import Status; status = Status() 
 37   
 38   
 40      """The model list GUI element.""" 
 41   
 42       
 43      border = 10 
 44      """The border width, in pixels.""" 
 45   
 46      desc = None 
 47      """The short description for the GUI element.""" 
 48   
 49      model_desc = [] 
 50      """The short description for each model.""" 
 51   
 52      models = [] 
 53      """The list of names of the model.""" 
 54   
 55      params = [] 
 56      """The list of parameters of each model in string form.""" 
 57   
 58      warning = None 
 59      """A warning string which if set will present a warning message to the user prior to allowing them to modify the list of models.""" 
 60   
 61      red_flag = False 
 62      """A flag which if True will cause the flag icon to turn red if the model list has been modified.""" 
 63   
 64      size = wx.Size(1024, 750) 
 65      """The initial size of the window.""" 
 66   
 67      tooltip = None 
 68      """The tooltip string to add to the text and field wx GUI elements.""" 
 69   
 70      tooltip_button = None 
 71      """The separate tooltip string to add to the button wx GUI element.""" 
 72   
 73   
 75          """Build the combo box list widget for a list of list selections. 
 76   
 77          @param parent:      The parent GUI element. 
 78          @type parent:       wx object instance 
 79          @param box:         The sizer to put the combo box widget into. 
 80          @type box:          wx.Sizer instance 
 81          """ 
 82   
 83           
 84          self.parent = parent 
 85   
 86           
 87          self.select = [] 
 88          self.models_stripped = [] 
 89          for model in self.models: 
 90              if model != None: 
 91                  self.select.append(True) 
 92                  self.models_stripped.append(model) 
 93   
 94           
 95          self.model_win = Model_sel_window(self.models, self.params, self.model_desc, size=self.size, border=self.border) 
 96   
 97           
 98          sizer = wx.BoxSizer(wx.HORIZONTAL) 
 99   
100           
101          label = self.parent.add_static_text(sizer, self.parent, text=self.desc, width=self.parent.width_text) 
102   
103           
104          sizer.AddSpacer((self.parent.spacer_horizontal, -1)) 
105   
106           
107          self.field = self.parent.add_text_control(sizer, self.parent, text=list_to_gui(self.GetValue()), editable=False) 
108   
109           
110          sizer.AddSpacer((self.parent.spacer_horizontal, -1)) 
111   
112           
113          self.button = self.parent.add_button_open(sizer, self.parent, icon=fetch_icon("oxygen.actions.flag-blue", "16x16"), text="Modify", fn=self.modify, width=self.parent.width_button, height=label.GetSize()[1]+8) 
114   
115           
116          if self.tooltip: 
117              label.SetToolTipString(self.tooltip) 
118              self.field.SetToolTipString(self.tooltip) 
119          if self.tooltip_button: 
120              self.button.SetToolTipString(self.tooltip_button) 
121   
122           
123          box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0) 
 124   
125   
126 -    def Enable(self, enable=True): 
 127          """Enable or disable the element. 
128   
129          @keyword enable:    The flag specifying if the element should be enabled or disabled. 
130          @type enable:       bool 
131          """ 
132   
133           
134          self.field.Enable(enable) 
135          self.button.Enable(enable) 
 136   
137   
139          """Return the list of models. 
140   
141          @return:    The list of models. 
142          @rtype:     list of str 
143          """ 
144   
145           
146          model_list = [] 
147   
148           
149          for i in range(len(self.select)): 
150              if self.select[i]: 
151                  model_list.append(self.models_stripped[i]) 
152   
153           
154          return model_list 
 155   
156   
158          """Store the list of models. 
159   
160          @param value:   The list of models. 
161          @type value:    list of str 
162          """ 
163   
164           
165          for i in range(len(self.select)): 
166              self.select[i] = False 
167   
168           
169          for model in value: 
170               
171              index = self.models_stripped.index(model) 
172   
173               
174              self.select[index] = True 
175   
176           
177          self.update_button() 
178   
179           
180          self.field.SetValue(list_to_gui(self.GetValue())) 
 181   
182   
183 -    def modify(self, event=None): 
 210   
211   
 226   
227   
228   
230      """The model selector window object.""" 
231   
232 -    def __init__(self, models, params, desc, size=None, border=None): 
 233          """Set up the model selector window. 
234   
235          @param models:      The list of models. 
236          @type models:       list of str 
237          @param params:      The list of parameters corresponding to the models. 
238          @type params:       list of str 
239          @param desc:        The description for each model. 
240          @type desc:         list of str 
241          @keyword size:      The initial size of the window. 
242          @type size:         wx.Size instance 
243          @keyword border:    The border width, in pixels. 
244          @type border:       int 
245          """ 
246   
247           
248          wx.Dialog.__init__(self, None, id=-1, title="Model list selector", size=size, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) 
249   
250           
251          desc_flag = False 
252          if len(desc): 
253              desc_flag = True 
254   
255           
256          self.SetFont(font.normal) 
257   
258           
259          main_sizer = wx.BoxSizer(wx.VERTICAL) 
260   
261           
262          self.SetSizer(main_sizer) 
263   
264           
265          sizer = add_border(main_sizer, border=border, packing=wx.VERTICAL) 
266   
267           
268          panel = scrolledpanel.ScrolledPanel(self, -1) 
269          panel.SetAutoLayout(1) 
270          panel.SetupScrolling() 
271          sizer.Add(panel, 1, wx.ALL|wx.EXPAND, 0) 
272   
273           
274          panel_sizer = wx.BoxSizer(wx.HORIZONTAL) 
275          panel.SetSizer(panel_sizer) 
276   
277           
278          cols = 2 
279          if desc_flag: 
280              cols += 1 
281          self.grid_sizer = wx.FlexGridSizer(len(models)+2, cols, 3, 30) 
282   
283           
284          titles = ["Model", "Parameters"] 
285          if desc_flag: 
286              titles.append("Description") 
287          for title in titles: 
288              text = wx.StaticText(panel, -1, str_to_gui(title)) 
289              text.SetFont(font.subtitle) 
290              self.grid_sizer.Add(text, 0, wx.ALIGN_CENTER_VERTICAL) 
291          for i in range(len(titles)): 
292              self.grid_sizer.Add(wx.StaticText(panel, -1, "")) 
293   
294           
295          self.model_selection = [] 
296          for i in range(len(models)): 
297               
298              if models[i] == None: 
299                  for i in range(len(titles)): 
300                      self.grid_sizer.Add(wx.StaticText(panel, -1, "")) 
301                  continue 
302   
303               
304              check_box = wx.CheckBox(panel, -1, str_to_gui(models[i])) 
305              self.model_selection.append(check_box) 
306              self.grid_sizer.Add(check_box, 0, wx.ALIGN_CENTER_VERTICAL) 
307   
308               
309              self.model_selection[-1].SetValue(True) 
310   
311               
312              text = wx.StaticText(panel, -1, str_to_gui(params[i])) 
313              text.SetFont(font.normal) 
314              self.grid_sizer.Add(text, 0, wx.ALIGN_CENTER_VERTICAL) 
315   
316               
317              if desc_flag: 
318                  text = wx.StaticText(panel, -1, str_to_gui(desc[i])) 
319                  text.SetFont(font.normal) 
320                  self.grid_sizer.Add(text, 0, wx.ALIGN_CENTER_VERTICAL) 
321   
322           
323          panel_sizer.Add(self.grid_sizer, 1, wx.ALL|wx.EXPAND, 0) 
324   
325           
326          self.SetMinSize(wx.Size(600, 300)) 
327          self.Centre() 
 328   
329   
346   
347   
 358   
359   
360   
362      """A special list control with checkboxes.""" 
363   
365          """Initialise the control. 
366   
367          @param parent:  The parent window. 
368          @type parent:   wx.Frame instance 
369          """ 
370   
371           
372          wx.ListCtrl.__init__(self, parent, -1, style=wx.BORDER_SUNKEN|wx.LC_REPORT) 
373   
374           
375          wx.lib.mixins.listctrl.CheckListCtrlMixin.__init__(self) 
  376