1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 """Module containing the base GUI element for listing things."""
26
27
28 import wx
29 import wx.lib.buttons
30
31
32 from status import Status; status = Status()
33 from user_functions.data import Uf_info; uf_info = Uf_info()
34
35
36 from gui.components.menu import build_menu_item
37 from gui.fonts import font
38 from gui.misc import add_border
39 from gui.string_conv import str_to_gui
40 from gui.uf_objects import Uf_storage; uf_store = Uf_storage()
41
42
44 """The GUI element for listing the software used in the analysis."""
45
46 - def __init__(self, gui=None, parent=None, box=None, id=None, proportion=0, button_placement='default'):
47 """Build the base list GUI element.
48
49 @keyword gui: The main GUI object.
50 @type gui: wx.Frame instance
51 @keyword parent: The parent GUI element that this is to be attached to.
52 @type parent: wx object
53 @keyword box: The box sizer to pack this GUI component into.
54 @type box: wx.BoxSizer instance
55 @keyword id: A unique identification string. This is used to register the update method with the GUI user function observer object.
56 @type id: str
57 @keyword proportion: The window proportion parameter.
58 @type proportion: bool
59 @keyword button_placement: Override the button visibility and placement. The value of 'default' will leave the buttons at the default setting. The value of 'top' will place the buttons at the top, 'bottom' will place them at the bottom, and None will turn off the buttons.
60 @type button_placement: str or None
61 """
62
63
64 self.gui = gui
65 self.parent = parent
66 self.proportion = proportion
67
68
69 self.title = ""
70 self.spacing = 5
71 self.border = 5
72 self.observer_base_name = None
73 self.columns = []
74 self.button_placement = None
75 self.button_size = (120, 40)
76 self.button_spacing = 5
77 self.button_info = []
78 self.popup_menus = []
79
80
81 self.setup()
82
83
84 if button_placement != 'default':
85 self.button_placement = button_placement
86
87
88 self.panel = wx.Panel(self.parent)
89 box.Add(self.panel, self.proportion, wx.ALL|wx.EXPAND, 0)
90
91
92 panel_sizer = wx.BoxSizer(wx.VERTICAL)
93 self.panel.SetSizer(panel_sizer)
94
95
96 self.data_box = wx.StaticBox(self.panel, -1)
97 self.set_box_label()
98 self.data_box.SetFont(font.subtitle)
99 sub_sizer = wx.StaticBoxSizer(self.data_box, wx.VERTICAL)
100
101
102 panel_sizer.Add(sub_sizer, self.proportion, wx.ALL|wx.EXPAND, 0)
103
104
105 box_centre = add_border(sub_sizer, border=self.border)
106
107
108 if self.button_placement == 'top':
109 self.add_buttons(box_centre)
110 box_centre.AddSpacer(self.spacing)
111
112
113 self.init_element(box_centre)
114
115
116 self.build_element()
117
118
119 if self.button_placement == 'bottom':
120 box_centre.AddSpacer(self.spacing)
121 self.add_buttons(box_centre)
122
123
124 if self.observer_base_name:
125 self.name = '%s: %s' % (self.observer_base_name, id)
126 else:
127 self.name = id
128
129
130 self.observer_register()
131
132
133 - def Enable(self, enable=True):
134 """Enable or disable the element.
135
136 @keyword enable: The flag specifying if the element should be enabled or disabled.
137 @type enable: bool
138 """
139
140
141 for i in range(len(self.button_info)):
142
143 button = getattr(self, self.button_info[i]['object'])
144
145
146 button.Enable(enable)
147
148
185
186
196
197
199 """Build the spectra listing GUI element in a thread safe wx.CallAfter call."""
200
201
202 self.element.Freeze()
203
204
205 self.set_box_label()
206
207
208 self.element.DeleteAllItems()
209
210
211 self.update_data()
212
213
214 self.size_cols()
215
216
217 event = wx.PyCommandEvent(wx.EVT_SIZE.typeId, self.parent.GetId())
218 wx.PostEvent(self.parent.GetEventHandler(), event)
219
220
221 if not self.proportion:
222
223 n = self.element.GetItemCount()
224
225
226 head = self.height_char + 10
227
228
229 centre = (self.height_char + 6) * n
230
231
232 foot = wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y)
233
234
235 height = head + centre + foot
236
237
238 self.element.SetMinSize((-1, height))
239 self.element.Layout()
240
241
242 self.element.Thaw()
243
244
250
251
253 """Initialise the GUI element.
254
255 @param sizer: The sizer element to pack the element into.
256 @type sizer: wx.BoxSizer instance
257 """
258
259
260 self.element = wx.ListCtrl(self.panel, -1, style=wx.BORDER_SUNKEN|wx.LC_REPORT)
261
262
263 for i in range(len(self.columns)):
264 self.element.InsertColumn(i, str_to_gui(self.columns[i]))
265
266
267 self.element.SetFont(font.normal)
268
269
270 self.height_char = self.element.GetCharHeight()
271
272
273 self.element.Bind(wx.EVT_SIZE, self.resize)
274 self.element.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.on_right_click)
275 self.element.Bind(wx.EVT_RIGHT_UP, self.on_right_click)
276
277
278 sizer.Add(self.element, self.proportion, wx.ALL|wx.EXPAND, 0)
279
280
282 """Base method which always returns True.
283
284 @return: The answer to the question.
285 @rtype: bool
286 """
287
288
289 return True
290
291
308
309
311 """Pop up menu for the right click.
312
313 @param event: The wx event.
314 @type event: wx event
315 """
316
317
318 if self.popup_menus == []:
319 return
320
321
322 if status.exec_lock.locked():
323 return
324
325
326 menu = wx.Menu()
327
328
329 for i in range(len(self.popup_menus)):
330
331 info = self.popup_menus[i]
332
333
334 menu.AppendItem(build_menu_item(menu, id=info['id'], text=info['text'], icon=info['icon']))
335
336
337 self.element.Bind(wx.EVT_MENU, info['method'], id=info['id'])
338
339
340 if status.show_gui:
341 self.element.PopupMenu(menu)
342 menu.Destroy()
343
344
346 """Catch the resize to allow the element to be resized.
347
348 @param event: The wx event.
349 @type event: wx event
350 """
351
352
353 self.size_cols()
354
355
356 event.Skip()
357
358
360 """Set the label of the StaticBox."""
361
362
363 self.data_box.SetLabel(self.title)
364
365
367 """Set the column sizes."""
368
369
370 x, y = self.element.GetSize()
371
372
373 n = self.element.GetColumnCount()
374
375
376 if n == 0:
377 width = x
378 else:
379 width = int(x / n)
380
381
382 for i in range(n):
383 self.element.SetColumnWidth(i, width)
384