1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module containing the base class for all frames."""
25
26
27 import wx
28 from wx.lib import buttons
29 from wx.lib import scrolledpanel
30
31
32 from graphics import IMAGE_PATH, fetch_icon
33 from gui.analyses.elements.text_element import Text_ctrl
34 from gui.fonts import font
35 from gui.misc import add_border, bitmap_setup
36 from gui.string_conv import str_to_gui
37 from pipe_control.mol_res_spin import count_spins
38 from pipe_control.pipes import cdp_name, has_pipe
39
40
42 """The base class for all frames."""
43
44
45 border = 10
46 size_graphic_panel = 200
47 spacer_horizontal = 5
48 width_text = 240
49 width_button = 100
50 width_main_separator = 40
51
52 - def __init__(self, parent, id=wx.ID_ANY, pos=None, size=None, style=None, name=None, gui=None):
53 """Initialise the scrolled window.
54
55 @param parent: The parent wx element.
56 @type parent: wx object
57 @keyword id: The unique ID number.
58 @type id: int
59 @keyword pos: The position.
60 @type pos: wx.Size object
61 @keyword size: The size.
62 @type size: wx.Size object
63 @keyword style: The style.
64 @type style: int
65 @keyword name: The name for the panel.
66 @type name: unicode
67 """
68
69
70 super(Base_analysis, self).__init__(parent, id=id, pos=pos, size=size, style=style, name=name)
71
72
73 self.width_vscroll = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
74
75
76 box_main = wx.BoxSizer(wx.HORIZONTAL)
77 self.SetSizer(box_main)
78
79
80 box_centre = add_border(box_main, border=self.border, packing=wx.HORIZONTAL)
81
82
83 self.build_main_box(box_centre)
84
85
86 self.SetAutoLayout(True)
87 self.SetupScrolling(scroll_x=False, scroll_y=True)
88
89
90 self.Bind(wx.EVT_SIZE, self.resize)
91
92
130
131
133 """Create and add the analysis execution GUI element to the given box.
134
135 @param box: The box element to pack the analysis execution GUI element into.
136 @type box: wx.BoxSizer instance
137 @param method: The method to execute when the button is clicked.
138 @type method: method
139 @return: The button.
140 @rtype: wx.lib.buttons.ThemedGenBitmapTextButton instance
141 """
142
143
144 sizer = wx.BoxSizer(wx.HORIZONTAL)
145
146
147 id = wx.NewId()
148
149
150 button = buttons.ThemedGenBitmapTextButton(self, id, None, " Execute")
151 button.SetBitmapLabel(wx.Bitmap(IMAGE_PATH+'relax_start.gif', wx.BITMAP_TYPE_ANY))
152 button.SetFont(font.normal)
153 self.gui.Bind(wx.EVT_BUTTON, method, button)
154 sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
155
156
157 box.Add(sizer, 0, wx.ALIGN_RIGHT, 0)
158
159
160 return button
161
162
163 - def add_spin_control(self, box, parent, text='', min=None, max=None, control=wx.SpinCtrl, width=-1, height=-1):
164 """Add a text control field to the box.
165
166 @param box: The box element to pack the control into.
167 @type box: wx.BoxSizer instance
168 @param parent: The parent GUI element.
169 @type parent: wx object
170 @keyword text: The default text of the control.
171 @type text: str
172 @keyword min: The minimum value allowed.
173 @type min: int
174 @keyword max: The maximum value allowed.
175 @type max: int
176 @keyword control: The control class to use.
177 @type control: wx.TextCtrl derived class
178 @keyword width: The minimum width of the control.
179 @type width: int
180 @keyword height: The minimum height of the control.
181 @type height: int
182 @return: The text control object.
183 @rtype: control object
184 """
185
186
187 field = control(parent, -1, text, min=min, max=max)
188
189
190 field.SetMinSize((width, height))
191 field.SetFont(font.normal)
192
193
194 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
195
196
197 return field
198
199
201 """Add a special control for spin systems.
202
203 Only one of these per analysis are allowed.
204
205 @param box: The box element to pack the control into.
206 @type box: wx.BoxSizer instance
207 @param parent: The parent GUI element.
208 @type parent: wx object
209 """
210
211
212 self.spin_systems = Text_ctrl(box, self, text="Spin systems:", button_text=" Spin editor", default=self.spin_count(), tooltip="The currently loaded molecule, residue and spin sequence.", tooltip_button="Launch the spin editor window for modifying the molecule, residue and spin sequence.", icon=fetch_icon('relax.spin', "16x16"), fn=self.launch_spin_editor, editable=False, button=True, width_text=self.width_text, width_button=self.width_button, spacer=self.spacer_horizontal)
213
214
215 - def add_static_text(self, box, parent, text='', width=-1, height=-1):
216 """Add a text control field to the box.
217
218 @param box: The box element to pack the control into.
219 @type box: wx.BoxSizer instance
220 @param parent: The parent GUI element.
221 @type parent: wx object
222 @keyword text: The default text of the control.
223 @type text: str
224 @keyword width: The minimum width of the control.
225 @type width: int
226 @keyword height: The minimum height of the control.
227 @type height: int
228 @return: The label.
229 @rtype: wx.StaticText instance
230 """
231
232
233 label = wx.StaticText(parent, -1, text)
234
235
236 label.SetMinSize((width, height))
237 label.SetFont(font.normal)
238
239
240 box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
241
242
243 return label
244
245
247 """Create and add the subtitle.
248
249 @param box: The box element to pack the subtitle into.
250 @type box: wx.BoxSizer instance
251 @param text: The text of the subtitle.
252 @type text: str
253 """
254
255
256 label = wx.StaticText(self, -1, text)
257
258
259 label.SetFont(font.subtitle)
260
261
262 box.AddSpacer(20)
263 box.Add(label)
264 box.AddSpacer(5)
265
266
268 """Create and add the subsubtitle.
269
270 @param box: The box element to pack the text into.
271 @type box: wx.BoxSizer instance
272 @param text: The text of the subsubtitle.
273 @type text: str
274 """
275
276
277 label = wx.StaticText(self, -1, text)
278
279
280 label.SetFont(font.normal)
281
282
283 box.AddSpacer(10)
284 box.Add(label)
285
286
287 - def add_text_control(self, box, parent, text='', control=wx.TextCtrl, width=-1, height=-1, editable=True):
288 """Add a text control field to the box.
289
290 @param box: The box element to pack the control into.
291 @type box: wx.BoxSizer instance
292 @param parent: The parent GUI element.
293 @type parent: wx object
294 @keyword text: The default text of the control.
295 @type text: str
296 @keyword control: The control class to use.
297 @type control: wx.TextCtrl derived class
298 @keyword width: The minimum width of the control.
299 @type width: int
300 @keyword height: The minimum height of the control.
301 @type height: int
302 @keyword editable: A flag specifying if the control is editable or not.
303 @type editable: bool
304 @return: The text control object.
305 @rtype: control object
306 """
307
308
309 field = control(parent, -1, str_to_gui(text))
310
311
312 field.SetMinSize((width, height))
313 field.SetFont(font.normal)
314
315
316 field.SetEditable(editable)
317 if not editable:
318 colour = self.GetBackgroundColour()
319 field.SetOwnBackgroundColour(colour)
320
321
322 box.Add(field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
323
324
325 return field
326
327
328 - def add_title(self, box, text, top_spacing=10, bottom_spacing=15):
329 """Create and add the frame title.
330
331 @param box: The box element to pack the frame title into.
332 @type box: wx.BoxSizer instance
333 @param text: The text of the title.
334 @type text: str
335 """
336
337
338 label = wx.StaticText(self, -1, text)
339
340
341 label.SetFont(font.roman_title_italic)
342
343
344 box.AddSpacer(top_spacing)
345 box.Add(label)
346 box.AddSpacer(bottom_spacing)
347
348
350 """Construct the left hand box to pack into the automatic Rx analysis frame.
351
352 @return: The left hand box element containing the bitmap.
353 @rtype: wx.BoxSizer instance
354 """
355
356
357 box = wx.BoxSizer(wx.VERTICAL)
358
359
360 if not isinstance(self.bitmap, list):
361 bitmaps = [self.bitmap]
362 else:
363 bitmaps = self.bitmap
364
365
366 for i in range(len(bitmaps)):
367
368 bitmap = wx.StaticBitmap(self, -1, bitmap_setup(bitmaps[i]))
369
370
371 box.Add(bitmap, 0, wx.ADJUST_MINSIZE, 10)
372
373
374 return box
375
376
377 - def build_main_box(self, box):
378 """Construct the highest level box to pack into the automatic analysis frames.
379
380 @param box: The horizontal box element to pack the elements into.
381 @type box: wx.BoxSizer instance
382 """
383
384
385 left_box = self.build_left_box()
386 box.Add(left_box, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
387
388
389 box.AddSpacer(self.width_main_separator)
390
391
392 right_box = self.build_right_box()
393 box.Add(right_box, 1, wx.ALL|wx.EXPAND, 0)
394
395
397 """The spin editor GUI element.
398
399 @param event: The wx event.
400 @type event: wx event
401 """
402
403
404 self.gui.show_tree(None)
405
406
408 """Register and unregister methods with the observer objects.
409
410 This is a dummy method.
411
412
413 @keyword remove: If set to True, then the methods will be unregistered.
414 @type remove: False
415 """
416
417
419 """The spin editor GUI element.
420
421 @param event: The wx event.
422 @type event: wx event
423 """
424
425
426 x = self.GetSize()[0] - self.width_vscroll
427 y = self.GetVirtualSize()[1]
428 self.SetVirtualSize((x, y))
429
430
432 """Count the number of loaded spins, returning a string formatted as 'xxx spins loaded'.
433
434 @return: The number of loaded spins in the format 'xxx spins loaded'.
435 @rtype: str
436 """
437
438
439 if hasattr(self.data, 'pipe_name'):
440 pipe = self.data.pipe_name
441 else:
442 pipe = cdp_name()
443
444
445 if not has_pipe(pipe):
446 num = 0
447 else:
448 num = count_spins(pipe=pipe)
449
450
451 return "%s spins loaded and selected" % num
452
453
459