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