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