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 class for the results frame."""
26
27
28 from string import lower, upper
29 import wx
30 from wx.lib import buttons
31
32
33 from data import Relax_data_store; ds = Relax_data_store()
34 from generic_fns.pipes import cdp_name, pipe_names
35 from status import Status; status = Status()
36
37
38 from gui.fonts import font
39 from gui.icons import relax_icons
40 from gui.interpreter import Interpreter; interpreter = Interpreter()
41 from gui.misc import add_border, open_file
42 from gui.paths import icon_22x22
43 from gui.string_conv import gui_to_str, str_to_gui
44 from gui.uf_objects import Uf_storage; uf_store = Uf_storage()
45
46
48 """The results viewer frame."""
49
50
51 border = 10
52 size = (800, 400)
53
55 """Build the results frame.
56
57 @param parent: The parent wx object.
58 @type parent: wx object
59 """
60
61
62 wx.Frame.__init__(self, parent=parent, style=wx.DEFAULT_FRAME_STYLE)
63
64
65 self.SetIcons(relax_icons)
66
67
68 self.SetTitle("Results viewer")
69 self.SetSize(self.size)
70
71
72 self.main_panel = wx.Panel(self, -1)
73
74
75 box_main = wx.BoxSizer(wx.HORIZONTAL)
76 self.main_panel.SetSizer(box_main)
77
78
79 box_centre = add_border(box_main, border=self.border, packing=wx.VERTICAL)
80
81
82 self.build_pipe_sel(box_centre)
83
84
85 box_centre.AddSpacer(self.border)
86
87
88 self.add_files(box_centre)
89
90
91 box_centre.AddSpacer(self.border)
92
93
94 self.button_open = buttons.ThemedGenBitmapTextButton(self.main_panel, -1, None, " Open")
95 self.button_open.SetBitmapLabel(wx.Bitmap(icon_22x22.document_open, wx.BITMAP_TYPE_ANY))
96 self.button_open.SetFont(font.normal)
97 self.button_open.SetMinSize((103, 33))
98 self.Bind(wx.EVT_BUTTON, self.open_result_file, self.button_open)
99 box_centre.Add(self.button_open, 0, wx.ALIGN_RIGHT|wx.ADJUST_MINSIZE, 5)
100
101
102 self.main_panel.Layout()
103 self.main_panel.Refresh()
104
105
106 self.Bind(wx.EVT_COMBOBOX, self.switch_pipes, self.pipe_name)
107 self.Bind(wx.EVT_CLOSE, self.handler_close)
108
109
110 self.name = 'results viewer'
111
112
113 - def Show(self, show=True):
135
136
138 """Activate or deactivate certain elements in response to the execution lock."""
139
140
141 enable = False
142 if not status.exec_lock.locked():
143 enable = True
144
145
146 wx.CallAfter(self.pipe_name.Enable, enable)
147
148
149 wx.CallAfter(self.button_open.Enable, enable)
150
151
153 """Create the list of results files.
154
155 @param box: The box sizer to pack the box into.
156 @type box: wx.BoxSizer instance
157 @return: The list box element.
158 @rtype: wx.ListBox element
159 """
160
161
162 self.file_list = wx.ListCtrl(self.main_panel, -1, style=wx.BORDER_SUNKEN|wx.LC_REPORT)
163
164
165 self.file_list.SetFont(font.normal)
166
167
168 self.height_char = self.file_list.GetCharHeight()
169
170
171 self.file_list.InsertColumn(0, "File type")
172 self.file_list.InsertColumn(1, "File path")
173
174
175 box.Add(self.file_list, 1, wx.ALL|wx.EXPAND, 0)
176
177
178 self.file_list.Bind(wx.EVT_SIZE, self.resize)
179 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.open_result_file, self.file_list)
180
181
183 """Create the data pipe selection element.
184
185 @param box: The horizontal box element to pack the elements into.
186 @type box: wx.BoxSizer instance
187 """
188
189
190 sizer = wx.BoxSizer(wx.HORIZONTAL)
191
192
193 label = wx.StaticText(self.main_panel, -1, "Data pipe selection")
194
195
196 label.SetFont(font.subtitle)
197
198
199 sizer.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
200
201
202 sizer.AddSpacer(self.border)
203
204
205 self.pipe_name = wx.ComboBox(self.main_panel, -1, value='', style=wx.CB_DROPDOWN|wx.CB_READONLY, choices=[])
206 self.pipe_name.SetMinSize((50, 27))
207 sizer.Add(self.pipe_name, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
208
209
210 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
211
212
228
229
231 """Open the results in the appropriate program.
232
233 @param event: The wx event.
234 @type event: wx event
235 """
236
237
238 for i in range(self.file_list.GetItemCount()):
239
240 if not self.file_list.IsSelected(i):
241 continue
242
243
244 type = self.file_data[i]
245 file = gui_to_str(self.file_list.GetItem(i, 1).GetText())
246
247
248 if type == 'grace':
249 uf_store['grace.view'](file=file, wx_parent=self)
250
251
252 elif type == 'pymol':
253 uf_store['pymol.macro_run'](file=file, wx_parent=self)
254
255
256 elif type == 'molmol':
257 uf_store['molmol.macro_run'](file=file, wx_parent=self)
258
259
260 elif type == 'diff_tensor_pdb':
261
262 if not interpreter.apply('pymol.view'):
263 return
264
265
266 interpreter.apply('pymol.cartoon')
267 interpreter.apply('pymol.tensor_pdb', file=file)
268
269
270 elif type == 'Table_of_Results':
271
272 model_result = [ds.relax_gui.table_residue, ds.relax_gui.table_model, ds.relax_gui.table_s2, ds.relax_gui.table_rex, ds.relax_gui.table_te]
273
274
275 elif type == 'text':
276 open_file(file, force_text=True)
277
278
279 else:
280 open_file(file)
281
282
284 """Update the list of result files."""
285
286
287 wx.CallAfter(self.refresh_safe)
288
289
291 """Update the list of result files (thread safe)."""
292
293
294 status.pipe_lock.acquire('results viewer window')
295 try:
296
297 self.update_pipes()
298
299
300 self.file_list.DeleteAllItems()
301 self.file_data = []
302
303
304 if not hasattr(cdp, 'result_files'):
305 return
306
307
308 for i in range(len(cdp.result_files)):
309 self.file_list.Append((str_to_gui(cdp.result_files[i][1]), str_to_gui(cdp.result_files[i][2])))
310 self.file_data.append(cdp.result_files[i][0])
311
312
313 finally:
314 status.pipe_lock.release('results viewer window')
315
316
318 """Catch the resize to allow the element to be resized.
319
320 @param event: The wx event.
321 @type event: wx event
322 """
323
324
325 self.size_cols()
326
327
328 event.Skip()
329
330
332 """Switch data pipes.
333
334 @param event: The wx event.
335 @type event: wx event
336 """
337
338
339 pipe = gui_to_str(self.pipe_name.GetString(event.GetSelection()))
340
341
342 if pipe == cdp_name():
343 return
344
345
346 interpreter.queue('pipe.switch', pipe)
347 interpreter.flush()
348
349
350 self.refresh()
351
352
353 wx.CallAfter(self.Raise)
354
355
368
369
371 """Set the column sizes."""
372
373
374 x, y = self.file_list.GetSize()
375
376
377 x = x - 10
378
379
380 self.file_list.SetColumnWidth(0, int(x/3))
381 self.file_list.SetColumnWidth(1, int(2*x/3))
382