1 | |
---|
2 | ################################################################################ |
---|
3 | #This software was developed by the University of Tennessee as part of the |
---|
4 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
5 | #project funded by the US National Science Foundation. |
---|
6 | # |
---|
7 | #See the license text in license.txt |
---|
8 | # |
---|
9 | #copyright 2008, University of Tennessee |
---|
10 | ################################################################################ |
---|
11 | |
---|
12 | |
---|
13 | import wx |
---|
14 | import wx.aui |
---|
15 | import os |
---|
16 | import sys |
---|
17 | import xml |
---|
18 | import py_compile |
---|
19 | # Try to find a local config |
---|
20 | import imp |
---|
21 | import warnings |
---|
22 | warnings.simplefilter("ignore") |
---|
23 | import logging |
---|
24 | |
---|
25 | from sans.guiframe.events import EVT_STATUS |
---|
26 | from sans.guiframe.events import EVT_APPEND_BOOKMARK |
---|
27 | from sans.guiframe.events import EVT_PANEL_ON_FOCUS |
---|
28 | from sans.guiframe.events import EVT_NEW_LOAD_DATA |
---|
29 | from sans.guiframe.events import EVT_NEW_COLOR |
---|
30 | from sans.guiframe.events import StatusEvent |
---|
31 | from sans.guiframe.events import NewPlotEvent |
---|
32 | from sans.guiframe.gui_style import GUIFRAME |
---|
33 | from sans.guiframe.gui_style import GUIFRAME_ID |
---|
34 | #from sans.guiframe.events import NewLoadedDataEvent |
---|
35 | from sans.guiframe.data_panel import DataPanel |
---|
36 | from sans.guiframe.panel_base import PanelBase |
---|
37 | from sans.guiframe.gui_toolbar import GUIToolBar |
---|
38 | from sans.guiframe.data_processor import GridFrame |
---|
39 | from sans.guiframe.events import EVT_NEW_BATCH |
---|
40 | from sans.dataloader.loader import Loader |
---|
41 | |
---|
42 | DATAPATH = os.getcwd() |
---|
43 | tem_path = sys.path[0] |
---|
44 | if os.path.isfile(tem_path): |
---|
45 | tem_path = os.path.dirname(tem_path) |
---|
46 | os.chdir(tem_path) |
---|
47 | PATH_APP = os.getcwd() |
---|
48 | |
---|
49 | def _find_local_config(file, path): |
---|
50 | """ |
---|
51 | Find configuration file for the current application |
---|
52 | """ |
---|
53 | |
---|
54 | file_path = os.path.abspath(os.path.join(path, "%s.py" % file)) |
---|
55 | if(os.path.isfile(file_path)): |
---|
56 | py_compile.compile(file=file_path) |
---|
57 | fObj, path_config, descr = imp.find_module(file, [path]) |
---|
58 | try: |
---|
59 | return imp.load_module(file, fObj, path_config, descr) |
---|
60 | except: |
---|
61 | raise |
---|
62 | finally: |
---|
63 | if fObj: |
---|
64 | fObj.close() |
---|
65 | |
---|
66 | |
---|
67 | try: |
---|
68 | path = PATH_APP |
---|
69 | config = _find_local_config('local_config', path) |
---|
70 | if config is None: |
---|
71 | path, _ = os.path.split(PATH_APP) |
---|
72 | config = _find_local_config('local_config', path) |
---|
73 | except: |
---|
74 | # Didn't find local config, load the default |
---|
75 | import sans.guiframe.config as config |
---|
76 | try: |
---|
77 | path = PATH_APP |
---|
78 | custom_config = _find_local_config('custom_config', path) |
---|
79 | if custom_config is None: |
---|
80 | path, _ = os.path.split(PATH_APP) |
---|
81 | custom_config = _find_local_config('custom_config', path) |
---|
82 | except: |
---|
83 | msg = "Custom_config file was not imported" |
---|
84 | logging.info(msg) |
---|
85 | |
---|
86 | |
---|
87 | #read some constants from config |
---|
88 | APPLICATION_STATE_EXTENSION = config.APPLICATION_STATE_EXTENSION |
---|
89 | APPLICATION_NAME = config.__appname__ |
---|
90 | SPLASH_SCREEN_PATH = config.SPLASH_SCREEN_PATH |
---|
91 | |
---|
92 | SPLASH_SCREEN_WIDTH = config.SPLASH_SCREEN_WIDTH |
---|
93 | SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT |
---|
94 | SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME |
---|
95 | |
---|
96 | try: |
---|
97 | DATALOADER_SHOW = custom_config.DATALOADER_SHOW |
---|
98 | TOOLBAR_SHOW = custom_config.TOOLBAR_SHOW |
---|
99 | FIXED_PANEL = custom_config.FIXED_PANEL |
---|
100 | WELCOME_PANEL_SHOW = custom_config.WELCOME_PANEL_SHOW |
---|
101 | PLOPANEL_WIDTH = custom_config.PLOPANEL_WIDTH |
---|
102 | DATAPANEL_WIDTH = custom_config.DATAPANEL_WIDTH |
---|
103 | GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH |
---|
104 | GUIFRAME_HEIGHT = custom_config.GUIFRAME_HEIGHT |
---|
105 | DEFAULT_PERSPECTIVE = custom_config.DEFAULT_PERSPECTIVE |
---|
106 | CLEANUP_PLOT = custom_config.CLEANUP_PLOT |
---|
107 | except: |
---|
108 | DATALOADER_SHOW = True |
---|
109 | TOOLBAR_SHOW = True |
---|
110 | FIXED_PANEL = True |
---|
111 | WELCOME_PANEL_SHOW = False |
---|
112 | PLOPANEL_WIDTH = config.PLOPANEL_WIDTH |
---|
113 | DATAPANEL_WIDTH = config.DATAPANEL_WIDTH |
---|
114 | GUIFRAME_WIDTH = config.GUIFRAME_WIDTH |
---|
115 | GUIFRAME_HEIGHT = config.GUIFRAME_HEIGHT |
---|
116 | DEFAULT_PERSPECTIVE = None |
---|
117 | CLEANUP_PLOT = False |
---|
118 | |
---|
119 | DEFAULT_STYLE = config.DEFAULT_STYLE |
---|
120 | |
---|
121 | |
---|
122 | PLOPANEL_HEIGTH = config.PLOPANEL_HEIGTH |
---|
123 | DATAPANEL_HEIGHT = config.DATAPANEL_HEIGHT |
---|
124 | PLUGIN_STATE_EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS |
---|
125 | OPEN_SAVE_MENU = config.OPEN_SAVE_PROJECT_MENU |
---|
126 | VIEW_MENU = config.VIEW_MENU |
---|
127 | EDIT_MENU = config.EDIT_MENU |
---|
128 | extension_list = [] |
---|
129 | if APPLICATION_STATE_EXTENSION is not None: |
---|
130 | extension_list.append(APPLICATION_STATE_EXTENSION) |
---|
131 | EXTENSIONS = PLUGIN_STATE_EXTENSIONS + extension_list |
---|
132 | try: |
---|
133 | PLUGINS_WLIST = '|'.join(config.PLUGINS_WLIST) |
---|
134 | except: |
---|
135 | PLUGINS_WLIST = '' |
---|
136 | APPLICATION_WLIST = config.APPLICATION_WLIST |
---|
137 | if sys.platform.count("darwin")==0: |
---|
138 | IS_WIN = True |
---|
139 | else: |
---|
140 | IS_WIN = False |
---|
141 | |
---|
142 | class ViewerFrame(wx.Frame): |
---|
143 | """ |
---|
144 | Main application frame |
---|
145 | """ |
---|
146 | |
---|
147 | def __init__(self, parent, title, |
---|
148 | size=(GUIFRAME_WIDTH, GUIFRAME_HEIGHT), |
---|
149 | gui_style=DEFAULT_STYLE, |
---|
150 | pos=wx.DefaultPosition): |
---|
151 | """ |
---|
152 | Initialize the Frame object |
---|
153 | """ |
---|
154 | |
---|
155 | wx.Frame.__init__(self, parent=parent, title=title, pos=pos,size=size) |
---|
156 | # title |
---|
157 | self.title = title |
---|
158 | # Preferred window size |
---|
159 | self._window_width, self._window_height = size |
---|
160 | self.__gui_style = gui_style |
---|
161 | # Logging info |
---|
162 | logging.basicConfig(level=logging.DEBUG, |
---|
163 | format='%(asctime)s %(levelname)s %(message)s', |
---|
164 | filename='sans_app.log', |
---|
165 | filemode='w') |
---|
166 | path = os.path.dirname(__file__) |
---|
167 | temp_path = os.path.join(path,'images') |
---|
168 | ico_file = os.path.join(temp_path,'ball.ico') |
---|
169 | if os.path.isfile(ico_file): |
---|
170 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
171 | else: |
---|
172 | temp_path = os.path.join(os.getcwd(),'images') |
---|
173 | ico_file = os.path.join(temp_path,'ball.ico') |
---|
174 | if os.path.isfile(ico_file): |
---|
175 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
176 | else: |
---|
177 | ico_file = os.path.join(os.path.dirname(os.path.sys.path[0]), |
---|
178 | 'images', 'ball.ico') |
---|
179 | if os.path.isfile(ico_file): |
---|
180 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
181 | self.path = PATH_APP |
---|
182 | ## Application manager |
---|
183 | self._input_file = None |
---|
184 | self.app_manager = None |
---|
185 | self._mgr = None |
---|
186 | #add current perpsective |
---|
187 | self._current_perspective = None |
---|
188 | self._plotting_plugin = None |
---|
189 | self._data_plugin = None |
---|
190 | #Menu bar and item |
---|
191 | self._menubar = None |
---|
192 | self._file_menu = None |
---|
193 | self._data_menu = None |
---|
194 | self._view_menu = None |
---|
195 | self._window_menu = None |
---|
196 | self._data_panel_menu = None |
---|
197 | self._help_menu = None |
---|
198 | self._tool_menu = None |
---|
199 | self._applications_menu_pos = -1 |
---|
200 | self._applications_menu_name = None |
---|
201 | self._applications_menu = None |
---|
202 | self._edit_menu = None |
---|
203 | self._toolbar_menu = None |
---|
204 | self._save_appl_menu = None |
---|
205 | #tool bar |
---|
206 | self._toolbar = None |
---|
207 | # number of plugins |
---|
208 | self._num_perspectives = 0 |
---|
209 | # plot duck cleanup option |
---|
210 | self.cleanup_plots = CLEANUP_PLOT |
---|
211 | # (un)-focus color |
---|
212 | #self.color = '#b3b3b3' |
---|
213 | ## Find plug-ins |
---|
214 | # Modify this so that we can specify the directory to look into |
---|
215 | self.plugins = [] |
---|
216 | #add local plugin |
---|
217 | self.plugins += self._get_local_plugins() |
---|
218 | self.plugins += self._find_plugins() |
---|
219 | ## List of panels |
---|
220 | self.panels = {} |
---|
221 | # List of plot panels |
---|
222 | self.plot_panels = {} |
---|
223 | |
---|
224 | # Default locations |
---|
225 | self._default_save_location = os.getcwd() |
---|
226 | |
---|
227 | # Welcome panel |
---|
228 | self.defaultPanel = None |
---|
229 | #panel on focus |
---|
230 | self.panel_on_focus = None |
---|
231 | #control_panel on focus |
---|
232 | self.cpanel_on_focus = None |
---|
233 | self.loader = Loader() |
---|
234 | #data manager |
---|
235 | from data_manager import DataManager |
---|
236 | self._data_manager = DataManager() |
---|
237 | self._data_panel = DataPanel(parent=self) |
---|
238 | if self.panel_on_focus is not None: |
---|
239 | self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) |
---|
240 | # list of plot panels in schedule to full redraw |
---|
241 | self.schedule = False |
---|
242 | #self.callback = True |
---|
243 | self._idle_count = 0 |
---|
244 | self.schedule_full_draw_list = [] |
---|
245 | self.idletimer = wx.CallLater(1, self._onDrawIdle) |
---|
246 | |
---|
247 | self.batch_frame = GridFrame(parent=self) |
---|
248 | self.batch_frame.Hide() |
---|
249 | # Check for update |
---|
250 | #self._check_update(None) |
---|
251 | # Register the close event so it calls our own method |
---|
252 | wx.EVT_CLOSE(self, self.Close) |
---|
253 | # Register to status events |
---|
254 | self.Bind(EVT_STATUS, self._on_status_event) |
---|
255 | #Register add extra data on the same panel event on load |
---|
256 | self.Bind(EVT_PANEL_ON_FOCUS, self.set_panel_on_focus) |
---|
257 | self.Bind(EVT_APPEND_BOOKMARK, self.append_bookmark) |
---|
258 | self.Bind(EVT_NEW_LOAD_DATA, self.on_load_data) |
---|
259 | self.Bind(EVT_NEW_BATCH, self.on_batch_selection) |
---|
260 | self.Bind(EVT_NEW_COLOR, self.on_color_selection) |
---|
261 | self.setup_custom_conf() |
---|
262 | |
---|
263 | def on_set_batch_result(self, data, name): |
---|
264 | """ |
---|
265 | Display data into a grid in batch mode and show the grid |
---|
266 | """ |
---|
267 | self.batch_frame.set_data(data) |
---|
268 | self.batch_frame.Show(True) |
---|
269 | |
---|
270 | |
---|
271 | def on_batch_selection(self, event): |
---|
272 | """ |
---|
273 | :param event: contains parameter enable . when enable is set to True |
---|
274 | the application is in Batch mode |
---|
275 | else the application is default mode(single mode) |
---|
276 | """ |
---|
277 | self.batch_on = event.enable |
---|
278 | for plug in self.plugins: |
---|
279 | plug.set_batch_selection(self.batch_on) |
---|
280 | |
---|
281 | def on_color_selection(self, event): |
---|
282 | """ |
---|
283 | :param event: contains parameters for id and color |
---|
284 | """ |
---|
285 | color, id = event.color, event.id |
---|
286 | for plug in self.plugins: |
---|
287 | plug.add_color(color, id) |
---|
288 | |
---|
289 | |
---|
290 | def setup_custom_conf(self): |
---|
291 | """ |
---|
292 | Set up custom configuration if exists |
---|
293 | """ |
---|
294 | if custom_config == None: |
---|
295 | return |
---|
296 | |
---|
297 | if not FIXED_PANEL: |
---|
298 | self.__gui_style &= (~GUIFRAME.FIXED_PANEL) |
---|
299 | self.__gui_style |= GUIFRAME.FLOATING_PANEL |
---|
300 | |
---|
301 | if not DATALOADER_SHOW: |
---|
302 | self.__gui_style &= (~GUIFRAME.MANAGER_ON) |
---|
303 | |
---|
304 | if not TOOLBAR_SHOW: |
---|
305 | self.__gui_style &= (~GUIFRAME.TOOLBAR_ON) |
---|
306 | |
---|
307 | if WELCOME_PANEL_SHOW: |
---|
308 | self.__gui_style |= GUIFRAME.WELCOME_PANEL_ON |
---|
309 | |
---|
310 | def set_custom_default_perspective(self): |
---|
311 | """ |
---|
312 | Set default starting perspective |
---|
313 | """ |
---|
314 | if custom_config == None: |
---|
315 | return |
---|
316 | for plugin in self.plugins: |
---|
317 | try: |
---|
318 | if plugin.sub_menu == DEFAULT_PERSPECTIVE: |
---|
319 | |
---|
320 | plugin.on_perspective(event=None) |
---|
321 | #self._check_applications_menu() |
---|
322 | break |
---|
323 | except: |
---|
324 | pass |
---|
325 | return |
---|
326 | |
---|
327 | def on_load_data(self, event): |
---|
328 | """ |
---|
329 | received an event to trigger load from data plugin |
---|
330 | """ |
---|
331 | if self._data_plugin is not None: |
---|
332 | self._data_plugin.load_data(event) |
---|
333 | |
---|
334 | def get_current_perspective(self): |
---|
335 | """ |
---|
336 | return the current perspective |
---|
337 | """ |
---|
338 | return self._current_perspective |
---|
339 | |
---|
340 | def set_input_file(self, input_file): |
---|
341 | """ |
---|
342 | :param input_file: file to read |
---|
343 | """ |
---|
344 | self._input_file = input_file |
---|
345 | |
---|
346 | def get_data_manager(self): |
---|
347 | """ |
---|
348 | """ |
---|
349 | return self._data_manager |
---|
350 | |
---|
351 | def get_toolbar(self): |
---|
352 | """ |
---|
353 | """ |
---|
354 | return self._toolbar |
---|
355 | |
---|
356 | def set_panel_on_focus(self, event): |
---|
357 | """ |
---|
358 | Store reference to the last panel on focus |
---|
359 | update the toolbar if available |
---|
360 | update edit menu if available |
---|
361 | """ |
---|
362 | if event != None: |
---|
363 | self.panel_on_focus = event.panel |
---|
364 | panel_name = 'No panel on focus' |
---|
365 | application_name = 'No Selected Analysis' |
---|
366 | if self.panel_on_focus is not None: |
---|
367 | if self.panel_on_focus not in self.plot_panels.values(): |
---|
368 | for ID in self.panels.keys(): |
---|
369 | if self.panel_on_focus != self.panels[ID]: |
---|
370 | self.panels[ID].on_kill_focus(None) |
---|
371 | |
---|
372 | if self._data_panel is not None and \ |
---|
373 | self.panel_on_focus is not None: |
---|
374 | panel_name = self.panel_on_focus.window_caption |
---|
375 | ID = self.panel_on_focus.uid |
---|
376 | self._data_panel.set_panel_on_focus(ID) |
---|
377 | #update combo |
---|
378 | if self.panel_on_focus in self.plot_panels.values(): |
---|
379 | combo = self._data_panel.cb_plotpanel |
---|
380 | combo_title = str(self.panel_on_focus.window_caption) |
---|
381 | combo.SetStringSelection(combo_title) |
---|
382 | combo.SetToolTip( wx.ToolTip(combo_title )) |
---|
383 | elif self.panel_on_focus != self._data_panel: |
---|
384 | cpanel = self.panel_on_focus |
---|
385 | if self.cpanel_on_focus != cpanel: |
---|
386 | self.cpanel_on_focus = self.panel_on_focus |
---|
387 | #update toolbar |
---|
388 | self._update_toolbar_helper() |
---|
389 | #update edit menu |
---|
390 | self.enable_edit_menu() |
---|
391 | |
---|
392 | def reset_bookmark_menu(self, panel): |
---|
393 | """ |
---|
394 | Reset Bookmark menu list |
---|
395 | |
---|
396 | : param panel: a control panel or tap where the bookmark is |
---|
397 | """ |
---|
398 | cpanel = panel |
---|
399 | if self._toolbar != None and cpanel._bookmark_flag: |
---|
400 | for item in self._toolbar.get_bookmark_items(): |
---|
401 | self._toolbar.remove_bookmark_item(item) |
---|
402 | self._toolbar.add_bookmark_default() |
---|
403 | pos = 0 |
---|
404 | for bitem in cpanel.popUpMenu.GetMenuItems(): |
---|
405 | pos += 1 |
---|
406 | if pos < 3: |
---|
407 | continue |
---|
408 | id = bitem.GetId() |
---|
409 | label = bitem.GetLabel() |
---|
410 | self._toolbar.append_bookmark_item(id, label) |
---|
411 | wx.EVT_MENU(self, id, cpanel._back_to_bookmark) |
---|
412 | self._toolbar.Realize() |
---|
413 | |
---|
414 | |
---|
415 | def build_gui(self): |
---|
416 | """ |
---|
417 | """ |
---|
418 | # set tool bar |
---|
419 | self._setup_tool_bar() |
---|
420 | # Set up the layout |
---|
421 | self._setup_layout() |
---|
422 | |
---|
423 | # Set up the menu |
---|
424 | self._setup_menus() |
---|
425 | |
---|
426 | try: |
---|
427 | self.load_from_cmd(self._input_file) |
---|
428 | except: |
---|
429 | msg = "%s Cannot load file %s\n" %(str(APPLICATION_NAME), |
---|
430 | str(self._input_file)) |
---|
431 | msg += str(sys.exc_value) + '\n' |
---|
432 | print msg |
---|
433 | if self._data_panel is not None: |
---|
434 | self._data_panel.fill_cbox_analysis(self.plugins) |
---|
435 | self.post_init() |
---|
436 | # Set Custom default |
---|
437 | self.set_custom_default_perspective() |
---|
438 | # Set up extra custom tool menu |
---|
439 | self._setup_extra_custom() |
---|
440 | #self.Show(True) |
---|
441 | #self._check_update(None) |
---|
442 | |
---|
443 | def _setup_extra_custom(self): |
---|
444 | """ |
---|
445 | Set up toolbar and welcome view if needed |
---|
446 | """ |
---|
447 | style = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
448 | if (style == GUIFRAME.TOOLBAR_ON) & (not self._toolbar.IsShown()): |
---|
449 | self._on_toggle_toolbar() |
---|
450 | |
---|
451 | # Set Custom deafult start page |
---|
452 | welcome_style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON |
---|
453 | if welcome_style == GUIFRAME.WELCOME_PANEL_ON: |
---|
454 | self.show_welcome_panel(None) |
---|
455 | |
---|
456 | def _setup_layout(self): |
---|
457 | """ |
---|
458 | Set up the layout |
---|
459 | """ |
---|
460 | # Status bar |
---|
461 | from gui_statusbar import StatusBar |
---|
462 | self.sb = StatusBar(self, wx.ID_ANY) |
---|
463 | self.SetStatusBar(self.sb) |
---|
464 | # Add panel |
---|
465 | default_flag = wx.aui.AUI_MGR_DEFAULT#| wx.aui.AUI_MGR_ALLOW_ACTIVE_PANE |
---|
466 | self._mgr = wx.aui.AuiManager(self, flags=default_flag) |
---|
467 | self._mgr.SetDockSizeConstraint(0.5, 0.5) |
---|
468 | # border color |
---|
469 | #self.b_color = wx.aui.AUI_DOCKART_BORDER_COLOUR |
---|
470 | #self._mgr.GetArtProvider().SetColor(self.b_color, self.color) |
---|
471 | #self._mgr.SetArtProvider(wx.aui.AuiDockArt(wx.AuiDefaultDockArt)) |
---|
472 | #print "set", self._dockart.GetColour(13) |
---|
473 | # Load panels |
---|
474 | self._load_panels() |
---|
475 | self.set_default_perspective() |
---|
476 | self._mgr.Update() |
---|
477 | |
---|
478 | def SetStatusText(self, *args, **kwds): |
---|
479 | """ |
---|
480 | """ |
---|
481 | number = self.sb.get_msg_position() |
---|
482 | wx.Frame.SetStatusText(number=number, *args, **kwds) |
---|
483 | |
---|
484 | def PopStatusText(self, *args, **kwds): |
---|
485 | """ |
---|
486 | """ |
---|
487 | field = self.sb.get_msg_position() |
---|
488 | wx.Frame.PopStatusText(field=field) |
---|
489 | |
---|
490 | def PushStatusText(self, *args, **kwds): |
---|
491 | """ |
---|
492 | """ |
---|
493 | field = self.sb.get_msg_position() |
---|
494 | wx.Frame.PushStatusText(self, field=field, string=string) |
---|
495 | |
---|
496 | def add_perspective(self, plugin): |
---|
497 | """ |
---|
498 | Add a perspective if it doesn't already |
---|
499 | exist. |
---|
500 | """ |
---|
501 | self._num_perspectives += 1 |
---|
502 | is_loaded = False |
---|
503 | for item in self.plugins: |
---|
504 | if plugin.__class__ == item.__class__: |
---|
505 | msg = "Plugin %s already loaded" % plugin.sub_menu |
---|
506 | logging.info(msg) |
---|
507 | is_loaded = True |
---|
508 | if not is_loaded: |
---|
509 | |
---|
510 | self.plugins.append(plugin) |
---|
511 | |
---|
512 | |
---|
513 | def _get_local_plugins(self): |
---|
514 | """ |
---|
515 | get plugins local to guiframe and others |
---|
516 | """ |
---|
517 | plugins = [] |
---|
518 | #import guiframe local plugins |
---|
519 | #check if the style contain guiframe.dataloader |
---|
520 | style1 = self.__gui_style & GUIFRAME.DATALOADER_ON |
---|
521 | style2 = self.__gui_style & GUIFRAME.PLOTTING_ON |
---|
522 | if style1 == GUIFRAME.DATALOADER_ON: |
---|
523 | try: |
---|
524 | from sans.guiframe.local_perspectives.data_loader import data_loader |
---|
525 | self._data_plugin = data_loader.Plugin() |
---|
526 | plugins.append(self._data_plugin) |
---|
527 | except: |
---|
528 | msg = "ViewerFrame._get_local_plugins:" |
---|
529 | msg += "cannot import dataloader plugin.\n %s" % sys.exc_value |
---|
530 | logging.error(msg) |
---|
531 | if style2 == GUIFRAME.PLOTTING_ON: |
---|
532 | try: |
---|
533 | from sans.guiframe.local_perspectives.plotting import plotting |
---|
534 | self._plotting_plugin = plotting.Plugin() |
---|
535 | plugins.append(self._plotting_plugin) |
---|
536 | except: |
---|
537 | msg = "ViewerFrame._get_local_plugins:" |
---|
538 | msg += "cannot import plotting plugin.\n %s" % sys.exc_value |
---|
539 | logging.error(msg) |
---|
540 | |
---|
541 | return plugins |
---|
542 | |
---|
543 | def _find_plugins(self, dir="perspectives"): |
---|
544 | """ |
---|
545 | Find available perspective plug-ins |
---|
546 | |
---|
547 | :param dir: directory in which to look for plug-ins |
---|
548 | |
---|
549 | :return: list of plug-ins |
---|
550 | |
---|
551 | """ |
---|
552 | import imp |
---|
553 | plugins = [] |
---|
554 | # Go through files in panels directory |
---|
555 | try: |
---|
556 | list = os.listdir(dir) |
---|
557 | ## the default panel is the panel is the last plugin added |
---|
558 | for item in list: |
---|
559 | toks = os.path.splitext(os.path.basename(item)) |
---|
560 | name = '' |
---|
561 | if not toks[0] == '__init__': |
---|
562 | if toks[1] == '.py' or toks[1] == '': |
---|
563 | name = toks[0] |
---|
564 | #check the validity of the module name parsed |
---|
565 | #before trying to import it |
---|
566 | if name is None or name.strip() == '': |
---|
567 | continue |
---|
568 | path = [os.path.abspath(dir)] |
---|
569 | file = '' |
---|
570 | try: |
---|
571 | if toks[1] == '': |
---|
572 | mod_path = '.'.join([dir, name]) |
---|
573 | module = __import__(mod_path, globals(), |
---|
574 | locals(), [name]) |
---|
575 | else: |
---|
576 | (file, path, info) = imp.find_module(name, path) |
---|
577 | module = imp.load_module( name, file, item, info) |
---|
578 | if hasattr(module, "PLUGIN_ID"): |
---|
579 | try: |
---|
580 | plug = module.Plugin() |
---|
581 | if plug.set_default_perspective(): |
---|
582 | self._current_perspective = plug |
---|
583 | plugins.append(plug) |
---|
584 | |
---|
585 | msg = "Found plug-in: %s" % module.PLUGIN_ID |
---|
586 | logging.info(msg) |
---|
587 | except: |
---|
588 | msg = "Error accessing PluginPanel" |
---|
589 | msg += " in %s\n %s" % (name, sys.exc_value) |
---|
590 | config.printEVT(msg) |
---|
591 | except: |
---|
592 | msg = "ViewerFrame._find_plugins: %s" % sys.exc_value |
---|
593 | #print msg |
---|
594 | logging.error(msg) |
---|
595 | finally: |
---|
596 | if not file == None: |
---|
597 | file.close() |
---|
598 | except: |
---|
599 | # Should raise and catch at a higher level and |
---|
600 | # display error on status bar |
---|
601 | pass |
---|
602 | |
---|
603 | return plugins |
---|
604 | |
---|
605 | def set_welcome_panel(self, panel_class): |
---|
606 | """ |
---|
607 | Sets the default panel as the given welcome panel |
---|
608 | |
---|
609 | :param panel_class: class of the welcome panel to be instantiated |
---|
610 | |
---|
611 | """ |
---|
612 | self.defaultPanel = panel_class(self, -1, style=wx.RAISED_BORDER) |
---|
613 | |
---|
614 | def _get_panels_size(self, p): |
---|
615 | """ |
---|
616 | find the proper size of the current panel |
---|
617 | get the proper panel width and height |
---|
618 | """ |
---|
619 | panel_height_min = self._window_height |
---|
620 | panel_width_min = self._window_width |
---|
621 | style = self.__gui_style & (GUIFRAME.MANAGER_ON) |
---|
622 | if self._data_panel is not None and (p == self._data_panel): |
---|
623 | panel_width_min = DATAPANEL_WIDTH |
---|
624 | panel_height_min = self._window_height * 0.8 |
---|
625 | return panel_width_min, panel_height_min |
---|
626 | if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: |
---|
627 | style = self.__gui_style & (GUIFRAME.PLOTTING_ON|GUIFRAME.MANAGER_ON) |
---|
628 | if style == (GUIFRAME.PLOTTING_ON|GUIFRAME.MANAGER_ON): |
---|
629 | panel_width_min = self._window_width -\ |
---|
630 | (DATAPANEL_WIDTH +config.PLOPANEL_WIDTH) |
---|
631 | return panel_width_min, panel_height_min |
---|
632 | return panel_width_min, panel_height_min |
---|
633 | |
---|
634 | def _load_panels(self): |
---|
635 | """ |
---|
636 | Load all panels in the panels directory |
---|
637 | """ |
---|
638 | |
---|
639 | # Look for plug-in panels |
---|
640 | panels = [] |
---|
641 | for item in self.plugins: |
---|
642 | if hasattr(item, "get_panels"): |
---|
643 | ps = item.get_panels(self) |
---|
644 | panels.extend(ps) |
---|
645 | |
---|
646 | # Show a default panel with some help information |
---|
647 | # It also sets the size of the application windows |
---|
648 | #TODO: Use this for slpash screen |
---|
649 | if self.defaultPanel is None: |
---|
650 | self.defaultPanel = DefaultPanel(self, -1, style=wx.RAISED_BORDER) |
---|
651 | # add a blank default panel always present |
---|
652 | self.panels["default"] = self.defaultPanel |
---|
653 | self._mgr.AddPane(self.defaultPanel, wx.aui.AuiPaneInfo(). |
---|
654 | Name("default"). |
---|
655 | CenterPane(). |
---|
656 | #CloseButton(False). |
---|
657 | #MinimizeButton(False). |
---|
658 | # This is where we set the size of |
---|
659 | # the application window |
---|
660 | BestSize(wx.Size(self._window_width, |
---|
661 | self._window_height)). |
---|
662 | Show()) |
---|
663 | |
---|
664 | #add data panel |
---|
665 | self.panels["data_panel"] = self._data_panel |
---|
666 | w, h = self._get_panels_size(self._data_panel) |
---|
667 | self._mgr.AddPane(self._data_panel, wx.aui.AuiPaneInfo(). |
---|
668 | Name(self._data_panel.window_name). |
---|
669 | Caption(self._data_panel.window_caption). |
---|
670 | Left(). |
---|
671 | MinimizeButton(). |
---|
672 | CloseButton(IS_WIN). |
---|
673 | TopDockable(False). |
---|
674 | BottomDockable(False). |
---|
675 | LeftDockable(True). |
---|
676 | RightDockable(False). |
---|
677 | BestSize(wx.Size(w, h)). |
---|
678 | Hide()) |
---|
679 | |
---|
680 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
681 | data_pane = self._mgr.GetPane(self.panels["data_panel"].window_name) |
---|
682 | if style != GUIFRAME.MANAGER_ON: |
---|
683 | self._mgr.GetPane(self.panels["data_panel"].window_name).Hide() |
---|
684 | else: |
---|
685 | self._mgr.GetPane(self.panels["data_panel"].window_name).Show() |
---|
686 | |
---|
687 | # Add the panels to the AUI manager |
---|
688 | for panel_class in panels: |
---|
689 | p = panel_class |
---|
690 | id = wx.NewId() |
---|
691 | #w, h = self._get_panels_size(p) |
---|
692 | # Check whether we need to put this panel |
---|
693 | # in the center pane |
---|
694 | if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: |
---|
695 | w, h = self._get_panels_size(p) |
---|
696 | if p.CENTER_PANE: |
---|
697 | self.panels[str(id)] = p |
---|
698 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
699 | Name(p.window_name). |
---|
700 | CenterPane(). |
---|
701 | Center(). |
---|
702 | CloseButton(False). |
---|
703 | Hide()) |
---|
704 | else: |
---|
705 | self.panels[str(id)] = p |
---|
706 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
707 | Name(p.window_name).Caption(p.window_caption). |
---|
708 | Right(). |
---|
709 | Dock(). |
---|
710 | TopDockable(). |
---|
711 | BottomDockable(). |
---|
712 | LeftDockable(). |
---|
713 | RightDockable(). |
---|
714 | MinimizeButton(). |
---|
715 | Hide()) |
---|
716 | |
---|
717 | def update_data(self, prev_data, new_data): |
---|
718 | """ |
---|
719 | """ |
---|
720 | prev_id, data_state = self._data_manager.update_data(prev_data=prev_data, |
---|
721 | new_data=new_data) |
---|
722 | |
---|
723 | self._data_panel.remove_by_id(prev_id) |
---|
724 | self._data_panel.load_data_list(data_state) |
---|
725 | |
---|
726 | def update_theory(self, data_id, theory, state=None): |
---|
727 | """ |
---|
728 | """ |
---|
729 | data_state = self._data_manager.update_theory(data_id=data_id, |
---|
730 | theory=theory, |
---|
731 | state=state) |
---|
732 | self._data_panel.load_data_list(data_state) |
---|
733 | |
---|
734 | def onfreeze(self, theory_id): |
---|
735 | """ |
---|
736 | """ |
---|
737 | data_state_list = self._data_manager.freeze(theory_id) |
---|
738 | self._data_panel.load_data_list(list=data_state_list) |
---|
739 | for data_state in data_state_list.values(): |
---|
740 | new_plot = data_state.get_data() |
---|
741 | |
---|
742 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
743 | title=new_plot.title)) |
---|
744 | |
---|
745 | def freeze(self, data_id, theory_id): |
---|
746 | """ |
---|
747 | """ |
---|
748 | data_state_list = self._data_manager.freeze_theory(data_id=data_id, |
---|
749 | theory_id=theory_id) |
---|
750 | self._data_panel.load_data_list(list=data_state_list) |
---|
751 | for data_state in data_state_list.values(): |
---|
752 | new_plot = data_state.get_data() |
---|
753 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
754 | title=new_plot.title)) |
---|
755 | |
---|
756 | def delete_data(self, data): |
---|
757 | """ |
---|
758 | """ |
---|
759 | self._current_perspective.delete_data(data) |
---|
760 | |
---|
761 | |
---|
762 | def get_context_menu(self, plotpanel=None): |
---|
763 | """ |
---|
764 | Get the context menu items made available |
---|
765 | by the different plug-ins. |
---|
766 | This function is used by the plotting module |
---|
767 | """ |
---|
768 | if plotpanel is None: |
---|
769 | return |
---|
770 | menu_list = [] |
---|
771 | for item in self.plugins: |
---|
772 | menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) |
---|
773 | return menu_list |
---|
774 | |
---|
775 | def popup_panel(self, p): |
---|
776 | """ |
---|
777 | Add a panel object to the AUI manager |
---|
778 | |
---|
779 | :param p: panel object to add to the AUI manager |
---|
780 | |
---|
781 | :return: ID of the event associated with the new panel [int] |
---|
782 | |
---|
783 | """ |
---|
784 | ID = wx.NewId() |
---|
785 | self.panels[str(ID)] = p |
---|
786 | count = 0 |
---|
787 | for item in self.panels: |
---|
788 | if self.panels[item].window_name.startswith(p.window_name): |
---|
789 | count += 1 |
---|
790 | windowname = p.window_name |
---|
791 | caption = p.window_caption |
---|
792 | if count > 0: |
---|
793 | windowname += str(count+1) |
---|
794 | caption += (' '+str(count)) |
---|
795 | p.window_name = windowname |
---|
796 | p.window_caption = caption |
---|
797 | |
---|
798 | style1 = self.__gui_style & GUIFRAME.FIXED_PANEL |
---|
799 | style2 = self.__gui_style & GUIFRAME.FLOATING_PANEL |
---|
800 | if style1 == GUIFRAME.FIXED_PANEL: |
---|
801 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
802 | Name(windowname). |
---|
803 | Caption(caption). |
---|
804 | Position(10). |
---|
805 | Floatable(). |
---|
806 | Right(). |
---|
807 | Dock(). |
---|
808 | MinimizeButton(). |
---|
809 | Resizable(True). |
---|
810 | # Use a large best size to make sure the AUI |
---|
811 | # manager takes all the available space |
---|
812 | BestSize(wx.Size(PLOPANEL_WIDTH, |
---|
813 | PLOPANEL_HEIGTH))) |
---|
814 | |
---|
815 | self._popup_fixed_panel(p) |
---|
816 | |
---|
817 | elif style2 == GUIFRAME.FLOATING_PANEL: |
---|
818 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
819 | Name(windowname).Caption(caption). |
---|
820 | MinimizeButton(). |
---|
821 | Resizable(True). |
---|
822 | # Use a large best size to make sure the AUI |
---|
823 | # manager takes all the available space |
---|
824 | BestSize(wx.Size(PLOPANEL_WIDTH, |
---|
825 | PLOPANEL_HEIGTH))) |
---|
826 | |
---|
827 | self._popup_floating_panel(p) |
---|
828 | |
---|
829 | # Register for showing/hiding the panel |
---|
830 | wx.EVT_MENU(self, ID, self.on_view) |
---|
831 | if p not in self.plot_panels.values() and p.group_id != None: |
---|
832 | self.plot_panels[ID] = p |
---|
833 | if len(self.plot_panels) == 1: |
---|
834 | self.panel_on_focus = p |
---|
835 | self.set_panel_on_focus(None) |
---|
836 | if self._data_panel is not None and \ |
---|
837 | self._plotting_plugin is not None: |
---|
838 | ind = self._data_panel.cb_plotpanel.FindString('None') |
---|
839 | if ind != wx.NOT_FOUND: |
---|
840 | self._data_panel.cb_plotpanel.Delete(ind) |
---|
841 | if caption not in self._data_panel.cb_plotpanel.GetItems(): |
---|
842 | self._data_panel.cb_plotpanel.Append(str(caption), p) |
---|
843 | return ID |
---|
844 | |
---|
845 | def _setup_menus(self): |
---|
846 | """ |
---|
847 | Set up the application menus |
---|
848 | """ |
---|
849 | # Menu |
---|
850 | self._menubar = wx.MenuBar() |
---|
851 | self._add_menu_file() |
---|
852 | self._add_menu_edit() |
---|
853 | self._add_menu_view() |
---|
854 | #self._add_menu_data() |
---|
855 | self._add_menu_application() |
---|
856 | self._add_menu_tool() |
---|
857 | self._add_current_plugin_menu() |
---|
858 | self._add_menu_window() |
---|
859 | self._add_help_menu() |
---|
860 | self.SetMenuBar(self._menubar) |
---|
861 | |
---|
862 | def _setup_tool_bar(self): |
---|
863 | """ |
---|
864 | add toolbar to the frame |
---|
865 | """ |
---|
866 | #set toolbar |
---|
867 | self._toolbar = GUIToolBar(self, -1) |
---|
868 | self.SetToolBar(self._toolbar) |
---|
869 | self._update_toolbar_helper() |
---|
870 | self._on_toggle_toolbar(event=None) |
---|
871 | |
---|
872 | def _update_toolbar_helper(self): |
---|
873 | """ |
---|
874 | """ |
---|
875 | application_name = 'No Selected Analysis' |
---|
876 | panel_name = 'No Panel on Focus' |
---|
877 | if self._toolbar is None: |
---|
878 | return |
---|
879 | if self.cpanel_on_focus is not None: |
---|
880 | self.reset_bookmark_menu(self.cpanel_on_focus) |
---|
881 | self._toolbar.update_toolbar(self.cpanel_on_focus) |
---|
882 | if self._current_perspective is not None: |
---|
883 | application_name = self._current_perspective.sub_menu |
---|
884 | if self.cpanel_on_focus is not None: |
---|
885 | panel_name = self.cpanel_on_focus.window_caption |
---|
886 | |
---|
887 | self._toolbar.update_button(application_name=application_name, |
---|
888 | panel_name=panel_name) |
---|
889 | |
---|
890 | self._toolbar.Realize() |
---|
891 | |
---|
892 | def _add_menu_tool(self): |
---|
893 | """ |
---|
894 | Tools menu |
---|
895 | Go through plug-ins and find tools to populate the tools menu |
---|
896 | """ |
---|
897 | style = self.__gui_style & GUIFRAME.CALCULATOR_ON |
---|
898 | if style == GUIFRAME.CALCULATOR_ON: |
---|
899 | self._tool_menu = None |
---|
900 | for item in self.plugins: |
---|
901 | if hasattr(item, "get_tools"): |
---|
902 | for tool in item.get_tools(): |
---|
903 | # Only create a menu if we have at least one tool |
---|
904 | if self._tool_menu is None: |
---|
905 | self._tool_menu = wx.Menu() |
---|
906 | id = wx.NewId() |
---|
907 | self._tool_menu.Append(id, tool[0], tool[1]) |
---|
908 | wx.EVT_MENU(self, id, tool[2]) |
---|
909 | if self._tool_menu is not None: |
---|
910 | self._menubar.Append(self._tool_menu, '&Tool') |
---|
911 | |
---|
912 | def _add_current_plugin_menu(self): |
---|
913 | """ |
---|
914 | add current plugin menu |
---|
915 | Look for plug-in menus |
---|
916 | Add available plug-in sub-menus. |
---|
917 | """ |
---|
918 | if (self._menubar is None) or (self._current_perspective is None): |
---|
919 | return |
---|
920 | #replace or add a new menu for the current plugin |
---|
921 | |
---|
922 | pos = self._menubar.FindMenu(str(self._applications_menu_name)) |
---|
923 | if pos != -1: |
---|
924 | menu_list = self._current_perspective.populate_menu(self) |
---|
925 | if menu_list: |
---|
926 | for (menu, name) in menu_list: |
---|
927 | hidden_menu = self._menubar.Replace(pos, menu, name) |
---|
928 | self._applications_menu_name = name |
---|
929 | #self._applications_menu_pos = pos |
---|
930 | else: |
---|
931 | hidden_menu = self._menubar.Remove(pos) |
---|
932 | self._applications_menu_name = None |
---|
933 | #get the position of the menu when it first added |
---|
934 | self._applications_menu_pos = pos |
---|
935 | |
---|
936 | else: |
---|
937 | menu_list = self._current_perspective.populate_menu(self) |
---|
938 | if menu_list: |
---|
939 | for (menu,name) in menu_list: |
---|
940 | if self._applications_menu_pos == -1: |
---|
941 | self._menubar.Append(menu, name) |
---|
942 | else: |
---|
943 | self._menubar.Insert(self._applications_menu_pos, menu, name) |
---|
944 | self._applications_menu_name = name |
---|
945 | |
---|
946 | def _add_help_menu(self): |
---|
947 | """ |
---|
948 | add help menu |
---|
949 | """ |
---|
950 | # Help menu |
---|
951 | self._help_menu = wx.Menu() |
---|
952 | style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON |
---|
953 | if style == GUIFRAME.WELCOME_PANEL_ON or custom_config != None: |
---|
954 | # add the welcome panel menu item |
---|
955 | if self.defaultPanel is not None: |
---|
956 | id = wx.NewId() |
---|
957 | self._help_menu.Append(id, '&Welcome', '') |
---|
958 | self._help_menu.AppendSeparator() |
---|
959 | wx.EVT_MENU(self, id, self.show_welcome_panel) |
---|
960 | # Look for help item in plug-ins |
---|
961 | for item in self.plugins: |
---|
962 | if hasattr(item, "help"): |
---|
963 | id = wx.NewId() |
---|
964 | self._help_menu.Append(id,'&%s Help' % item.sub_menu, '') |
---|
965 | wx.EVT_MENU(self, id, item.help) |
---|
966 | if config._do_tutorial: |
---|
967 | self._help_menu.AppendSeparator() |
---|
968 | id = wx.NewId() |
---|
969 | self._help_menu.Append(id,'&Tutorial', 'Software tutorial') |
---|
970 | wx.EVT_MENU(self, id, self._onTutorial) |
---|
971 | |
---|
972 | if config._do_aboutbox: |
---|
973 | self._help_menu.AppendSeparator() |
---|
974 | id = wx.NewId() |
---|
975 | self._help_menu.Append(id,'&About', 'Software information') |
---|
976 | wx.EVT_MENU(self, id, self._onAbout) |
---|
977 | |
---|
978 | # Checking for updates needs major refactoring to work with py2exe |
---|
979 | # We need to make sure it doesn't hang the application if the server |
---|
980 | # is not up. We also need to make sure there's a proper executable to |
---|
981 | # run if we spawn a new background process. |
---|
982 | #id = wx.NewId() |
---|
983 | #self._help_menu.Append(id,'&Check for update', |
---|
984 | #'Check for the latest version of %s' % config.__appname__) |
---|
985 | #wx.EVT_MENU(self, id, self._check_update) |
---|
986 | self._menubar.Append(self._help_menu, '&Help') |
---|
987 | |
---|
988 | def _add_menu_view(self): |
---|
989 | """ |
---|
990 | add menu items under view menu |
---|
991 | """ |
---|
992 | if not VIEW_MENU: |
---|
993 | return |
---|
994 | self._view_menu = wx.Menu() |
---|
995 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
996 | id = wx.NewId() |
---|
997 | self._data_panel_menu = self._view_menu.Append(id, |
---|
998 | '&Show Data Explorer', '') |
---|
999 | wx.EVT_MENU(self, id, self.show_data_panel) |
---|
1000 | if style == GUIFRAME.MANAGER_ON: |
---|
1001 | self._data_panel_menu.SetText('Hide Data Explorer') |
---|
1002 | else: |
---|
1003 | self._data_panel_menu.SetText('Show Data Explorer') |
---|
1004 | self._view_menu.AppendSeparator() |
---|
1005 | id = wx.NewId() |
---|
1006 | style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
1007 | if style1 == GUIFRAME.TOOLBAR_ON: |
---|
1008 | self._toolbar_menu = self._view_menu.Append(id,'&Hide Toolbar', '') |
---|
1009 | else: |
---|
1010 | self._toolbar_menu = self._view_menu.Append(id,'&Show Toolbar', '') |
---|
1011 | wx.EVT_MENU(self, id, self._on_toggle_toolbar) |
---|
1012 | |
---|
1013 | if custom_config != None: |
---|
1014 | self._view_menu.AppendSeparator() |
---|
1015 | id = wx.NewId() |
---|
1016 | preference_menu = self._view_menu.Append(id,'Startup Setting', '') |
---|
1017 | wx.EVT_MENU(self, id, self._on_preference_menu) |
---|
1018 | |
---|
1019 | self._menubar.Append(self._view_menu, '&View') |
---|
1020 | |
---|
1021 | def _on_preference_menu(self, event): |
---|
1022 | """ |
---|
1023 | Build a panel to allow to edit Mask |
---|
1024 | """ |
---|
1025 | |
---|
1026 | from sans.guiframe.startup_configuration \ |
---|
1027 | import StartupConfiguration as ConfDialog |
---|
1028 | |
---|
1029 | self.panel = ConfDialog(parent=self, gui=self.__gui_style) |
---|
1030 | self.panel.ShowModal() |
---|
1031 | #wx.PostEvent(self.parent, event) |
---|
1032 | |
---|
1033 | |
---|
1034 | def _add_menu_window(self): |
---|
1035 | """ |
---|
1036 | add a menu window to the menu bar |
---|
1037 | Window menu |
---|
1038 | Attach a menu item for each panel in our |
---|
1039 | panel list that also appears in a plug-in. |
---|
1040 | |
---|
1041 | Only add the panel menu if there is only one perspective and |
---|
1042 | it has more than two panels. |
---|
1043 | Note: the first plug-in is always the plotting plug-in. |
---|
1044 | The first application |
---|
1045 | #plug-in is always the second one in the list. |
---|
1046 | """ |
---|
1047 | self._window_menu = wx.Menu() |
---|
1048 | if self._plotting_plugin is not None: |
---|
1049 | for (menu, name) in self._plotting_plugin.populate_menu(self): |
---|
1050 | self._window_menu.AppendSubMenu(menu, name) |
---|
1051 | self._menubar.Append(self._window_menu, '&Graph') |
---|
1052 | |
---|
1053 | style = self.__gui_style & GUIFRAME.PLOTTING_ON |
---|
1054 | if style == GUIFRAME.PLOTTING_ON: |
---|
1055 | self._window_menu.AppendSeparator() |
---|
1056 | id = wx.NewId() |
---|
1057 | preferences_menu = wx.Menu() |
---|
1058 | hint = "All plot panels will floating" |
---|
1059 | preferences_menu.AppendRadioItem(id, '&Float All', hint) |
---|
1060 | wx.EVT_MENU(self, id, self.set_plotpanel_floating) |
---|
1061 | style = self.__gui_style & GUIFRAME.FLOATING_PANEL |
---|
1062 | f_menu = preferences_menu.FindItemById(id) |
---|
1063 | if style == GUIFRAME.FLOATING_PANEL: |
---|
1064 | f_checked = True |
---|
1065 | else: |
---|
1066 | f_checked = False |
---|
1067 | f_menu.Check(f_checked) |
---|
1068 | |
---|
1069 | id = wx.NewId() |
---|
1070 | hint = "All plot panels will displayed within the frame" |
---|
1071 | preferences_menu.AppendRadioItem(id, '&Dock All', hint) |
---|
1072 | wx.EVT_MENU(self, id, self.set_plotpanel_fixed) |
---|
1073 | if not f_checked: |
---|
1074 | d_menu = preferences_menu.FindItemById(id) |
---|
1075 | d_menu.Check(True) |
---|
1076 | preferences_menu.AppendSeparator() |
---|
1077 | id = wx.NewId() |
---|
1078 | hint = "Clean up the dock area for plots on new-plot" |
---|
1079 | preferences_menu.AppendCheckItem(id, '&CleanUp Dock on NewPlot', hint) |
---|
1080 | wx.EVT_MENU(self, id, self.on_cleanup_dock) |
---|
1081 | flag = self.cleanup_plots |
---|
1082 | if self.cleanup_plots: |
---|
1083 | c_menu = preferences_menu.FindItemById(id) |
---|
1084 | c_menu.Check(True) |
---|
1085 | self._window_menu.AppendSubMenu(preferences_menu,'&Preferences') |
---|
1086 | if self._window_menu.GetMenuItemCount() == 0: |
---|
1087 | pos = self._menubar.FindMenu('Graph') |
---|
1088 | self._menubar.Remove(pos) |
---|
1089 | #wx.EVT_MENU(self, id, self.show_preferences_panel) |
---|
1090 | """ |
---|
1091 | if len(self.plugins) == 2: |
---|
1092 | plug = self.plugins[1] |
---|
1093 | pers = plug.get_perspective() |
---|
1094 | |
---|
1095 | if len(pers) > 1: |
---|
1096 | self._window_menu = wx.Menu() |
---|
1097 | for item in self.panels: |
---|
1098 | if item == 'default': |
---|
1099 | continue |
---|
1100 | panel = self.panels[item] |
---|
1101 | if panel.window_name in pers: |
---|
1102 | self._window_menu.Append(int(item), |
---|
1103 | panel.window_caption, |
---|
1104 | "Show %s window" % panel.window_caption) |
---|
1105 | wx.EVT_MENU(self, int(item), self.on_view) |
---|
1106 | self._menubar.Append(self._window_menu, '&Window') |
---|
1107 | """ |
---|
1108 | |
---|
1109 | |
---|
1110 | def _add_menu_application(self): |
---|
1111 | """ |
---|
1112 | |
---|
1113 | # Attach a menu item for each defined perspective or application. |
---|
1114 | # Only add the perspective menu if there are more than one perspectives |
---|
1115 | add menu application |
---|
1116 | """ |
---|
1117 | #style = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS |
---|
1118 | #if style == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
1119 | if self._num_perspectives > 1: |
---|
1120 | plug_data_count = False |
---|
1121 | plug_no_data_count = False |
---|
1122 | self._applications_menu = wx.Menu() |
---|
1123 | pos = 0 |
---|
1124 | separator = self._applications_menu.AppendSeparator() |
---|
1125 | for plug in self.plugins: |
---|
1126 | if len(plug.get_perspective()) > 0: |
---|
1127 | id = wx.NewId() |
---|
1128 | if plug.use_data(): |
---|
1129 | |
---|
1130 | self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, |
---|
1131 | "Switch to analysis: %s" % plug.sub_menu) |
---|
1132 | plug_data_count = True |
---|
1133 | pos += 1 |
---|
1134 | else: |
---|
1135 | plug_no_data_count = True |
---|
1136 | self._applications_menu.AppendCheckItem(id, plug.sub_menu, |
---|
1137 | "Switch to analysis: %s" % plug.sub_menu) |
---|
1138 | wx.EVT_MENU(self, id, plug.on_perspective) |
---|
1139 | #self._applications_menu. |
---|
1140 | if (not plug_data_count or not plug_no_data_count): |
---|
1141 | self._applications_menu.RemoveItem(separator) |
---|
1142 | self._menubar.Append(self._applications_menu, '&Analysis') |
---|
1143 | self._check_applications_menu() |
---|
1144 | |
---|
1145 | def _populate_file_menu(self): |
---|
1146 | """ |
---|
1147 | Insert menu item under file menu |
---|
1148 | """ |
---|
1149 | for plugin in self.plugins: |
---|
1150 | if len(plugin.populate_file_menu()) > 0: |
---|
1151 | for item in plugin.populate_file_menu(): |
---|
1152 | m_name, m_hint, m_handler = item |
---|
1153 | id = wx.NewId() |
---|
1154 | self._file_menu.Append(id, m_name, m_hint) |
---|
1155 | wx.EVT_MENU(self, id, m_handler) |
---|
1156 | self._file_menu.AppendSeparator() |
---|
1157 | |
---|
1158 | def _add_menu_file(self): |
---|
1159 | """ |
---|
1160 | add menu file |
---|
1161 | """ |
---|
1162 | |
---|
1163 | # File menu |
---|
1164 | self._file_menu = wx.Menu() |
---|
1165 | #append item from plugin under menu file if necessary |
---|
1166 | self._populate_file_menu() |
---|
1167 | style = self.__gui_style & GUIFRAME.DATALOADER_ON |
---|
1168 | style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS |
---|
1169 | if OPEN_SAVE_MENU: |
---|
1170 | id = wx.NewId() |
---|
1171 | hint_load_file = "read all analysis states saved previously" |
---|
1172 | self._save_appl_menu = self._file_menu.Append(id, |
---|
1173 | '&Open Project', hint_load_file) |
---|
1174 | wx.EVT_MENU(self, id, self._on_open_state_project) |
---|
1175 | |
---|
1176 | if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
1177 | # some menu of plugin to be seen under file menu |
---|
1178 | hint_load_file = "Read a status files and load" |
---|
1179 | hint_load_file += " them into the analysis" |
---|
1180 | id = wx.NewId() |
---|
1181 | self._save_appl_menu = self._file_menu.Append(id, |
---|
1182 | '&Open Analysis', hint_load_file) |
---|
1183 | wx.EVT_MENU(self, id, self._on_open_state_application) |
---|
1184 | if OPEN_SAVE_MENU: |
---|
1185 | self._file_menu.AppendSeparator() |
---|
1186 | id = wx.NewId() |
---|
1187 | self._file_menu.Append(id, '&Save Project', |
---|
1188 | 'Save the state of the whole analysis') |
---|
1189 | wx.EVT_MENU(self, id, self._on_save_project) |
---|
1190 | if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
1191 | #self._file_menu.AppendSeparator() |
---|
1192 | id = wx.NewId() |
---|
1193 | self._save_appl_menu = self._file_menu.Append(id, |
---|
1194 | '&Save Analysis', |
---|
1195 | 'Save state of the current active analysis panel') |
---|
1196 | wx.EVT_MENU(self, id, self._on_save_application) |
---|
1197 | self._file_menu.AppendSeparator() |
---|
1198 | |
---|
1199 | id = wx.NewId() |
---|
1200 | self._file_menu.Append(id, '&Quit', 'Exit') |
---|
1201 | wx.EVT_MENU(self, id, self.Close) |
---|
1202 | # Add sub menus |
---|
1203 | self._menubar.Append(self._file_menu, '&File') |
---|
1204 | |
---|
1205 | def _add_menu_edit(self): |
---|
1206 | """ |
---|
1207 | add menu edit |
---|
1208 | """ |
---|
1209 | if not EDIT_MENU: |
---|
1210 | return |
---|
1211 | # Edit Menu |
---|
1212 | self._edit_menu = wx.Menu() |
---|
1213 | self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo', |
---|
1214 | 'Undo the previous action') |
---|
1215 | wx.EVT_MENU(self, GUIFRAME_ID.UNDO_ID, self.on_undo_panel) |
---|
1216 | self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo', |
---|
1217 | 'Redo the previous action') |
---|
1218 | wx.EVT_MENU(self, GUIFRAME_ID.REDO_ID, self.on_redo_panel) |
---|
1219 | self._edit_menu.AppendSeparator() |
---|
1220 | self._edit_menu.Append(GUIFRAME_ID.COPY_ID, '&Copy Params', |
---|
1221 | 'Copy parameter values') |
---|
1222 | wx.EVT_MENU(self, GUIFRAME_ID.COPY_ID, self.on_copy_panel) |
---|
1223 | self._edit_menu.Append(GUIFRAME_ID.PASTE_ID, '&Paste Params', |
---|
1224 | 'Paste parameter values') |
---|
1225 | wx.EVT_MENU(self, GUIFRAME_ID.PASTE_ID, self.on_paste_panel) |
---|
1226 | self._edit_menu.AppendSeparator() |
---|
1227 | |
---|
1228 | self._edit_menu.Append(GUIFRAME_ID.PREVIEW_ID, '&Report Results', |
---|
1229 | 'Preview current panel') |
---|
1230 | wx.EVT_MENU(self, GUIFRAME_ID.PREVIEW_ID, self.on_preview_panel) |
---|
1231 | #self._edit_menu.Append(GUIFRAME_ID.PRINT_ID, '&Print', |
---|
1232 | # 'Print current panel') |
---|
1233 | #wx.EVT_MENU(self, GUIFRAME_ID.PRINT_ID, self.on_print_panel) |
---|
1234 | self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset Page', |
---|
1235 | 'Reset current panel') |
---|
1236 | wx.EVT_MENU(self, GUIFRAME_ID.RESET_ID, self.on_reset_panel) |
---|
1237 | |
---|
1238 | self._menubar.Append(self._edit_menu, '&Edit') |
---|
1239 | self.enable_edit_menu() |
---|
1240 | |
---|
1241 | def get_style(self): |
---|
1242 | """ |
---|
1243 | """ |
---|
1244 | return self.__gui_style |
---|
1245 | |
---|
1246 | def _add_menu_data(self): |
---|
1247 | """ |
---|
1248 | Add menu item item data to menu bar |
---|
1249 | """ |
---|
1250 | if self._data_plugin is not None: |
---|
1251 | menu_list = self._data_plugin.populate_menu(self) |
---|
1252 | if menu_list: |
---|
1253 | for (menu, name) in menu_list: |
---|
1254 | self._menubar.Append(menu, name) |
---|
1255 | |
---|
1256 | |
---|
1257 | def _on_toggle_toolbar(self, event=None): |
---|
1258 | """ |
---|
1259 | hide or show toolbar |
---|
1260 | """ |
---|
1261 | if self._toolbar is None: |
---|
1262 | return |
---|
1263 | if self._toolbar.IsShown(): |
---|
1264 | if self._toolbar_menu is not None: |
---|
1265 | self._toolbar_menu.SetItemLabel('Show Toolbar') |
---|
1266 | self._toolbar.Hide() |
---|
1267 | else: |
---|
1268 | if self._toolbar_menu is not None: |
---|
1269 | self._toolbar_menu.SetItemLabel('Hide Toolbar') |
---|
1270 | self._toolbar.Show() |
---|
1271 | self._toolbar.Realize() |
---|
1272 | |
---|
1273 | def _on_status_event(self, evt): |
---|
1274 | """ |
---|
1275 | Display status message |
---|
1276 | """ |
---|
1277 | # This CallAfter fixes many crashes on MAC. |
---|
1278 | wx.CallAfter(self.sb.set_status, evt) |
---|
1279 | |
---|
1280 | def on_view(self, evt): |
---|
1281 | """ |
---|
1282 | A panel was selected to be shown. If it's not already |
---|
1283 | shown, display it. |
---|
1284 | |
---|
1285 | :param evt: menu event |
---|
1286 | |
---|
1287 | """ |
---|
1288 | panel_id = str(evt.GetId()) |
---|
1289 | self.on_set_plot_focus(self.panels[panel_id]) |
---|
1290 | self.show_panel(evt.GetId(), 'on') |
---|
1291 | wx.CallLater(5, self.set_schedule(True)) |
---|
1292 | self.set_plot_unfocus() |
---|
1293 | |
---|
1294 | def on_close_welcome_panel(self): |
---|
1295 | """ |
---|
1296 | Close the welcome panel |
---|
1297 | """ |
---|
1298 | if self.defaultPanel is None: |
---|
1299 | return |
---|
1300 | default_panel = self._mgr.GetPane(self.panels["default"].window_name) |
---|
1301 | if default_panel.IsShown(): |
---|
1302 | default_panel.Hide() |
---|
1303 | # Recover current perspective |
---|
1304 | perspective = self._current_perspective |
---|
1305 | perspective.on_perspective(event=None) |
---|
1306 | self._mgr.Update() |
---|
1307 | # Show toolbar |
---|
1308 | #style = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
1309 | #if (style == GUIFRAME.TOOLBAR_ON) & (not self._toolbar.IsShown()): |
---|
1310 | # self._on_toggle_toolbar() |
---|
1311 | |
---|
1312 | def show_welcome_panel(self, event): |
---|
1313 | """ |
---|
1314 | Display the welcome panel |
---|
1315 | """ |
---|
1316 | if self.defaultPanel is None: |
---|
1317 | return |
---|
1318 | for id, panel in self.panels.iteritems(): |
---|
1319 | if id == 'default': |
---|
1320 | # Show default panel |
---|
1321 | if not self._mgr.GetPane(self.panels["default"].window_name).IsShown(): |
---|
1322 | self._mgr.GetPane(self.panels["default"].window_name).Show(True) |
---|
1323 | elif id == "data_panel": |
---|
1324 | flag = self._mgr.GetPane(self.panels["data_panel"].window_name).IsShown() |
---|
1325 | self._mgr.GetPane(self.panels["data_panel"].window_name).Show(flag) |
---|
1326 | elif panel not in self.plot_panels.values() : |
---|
1327 | self._mgr.GetPane(self.panels[id].window_name).IsShown() |
---|
1328 | self._mgr.GetPane(self.panels[id].window_name).Hide() |
---|
1329 | #style = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
1330 | #if (style == GUIFRAME.TOOLBAR_ON) & (self._toolbar.IsShown()): |
---|
1331 | # # self._toolbar.Show(True) |
---|
1332 | # self._on_toggle_toolbar() |
---|
1333 | |
---|
1334 | self._mgr.Update() |
---|
1335 | |
---|
1336 | def show_panel(self, uid, show=None): |
---|
1337 | """ |
---|
1338 | Shows the panel with the given id |
---|
1339 | |
---|
1340 | :param uid: unique ID number of the panel to show |
---|
1341 | |
---|
1342 | """ |
---|
1343 | ID = str(uid) |
---|
1344 | config.printEVT("show_panel: %s" % ID) |
---|
1345 | if ID in self.panels.keys(): |
---|
1346 | if not self._mgr.GetPane(self.panels[ID].window_name).IsShown(): |
---|
1347 | if show == 'on': |
---|
1348 | self._mgr.GetPane(self.panels[ID].window_name).Show() |
---|
1349 | elif self.panels[ID].window_caption.split(" ")[0] == \ |
---|
1350 | "Residuals": |
---|
1351 | self._mgr.GetPane(self.panels[ID].window_name).Hide() |
---|
1352 | else: |
---|
1353 | self._mgr.GetPane(self.panels[ID].window_name).Show() |
---|
1354 | # Hide default panel |
---|
1355 | self._mgr.GetPane(self.panels["default"].window_name).Hide() |
---|
1356 | self._mgr.Update() |
---|
1357 | self._redraw_idle() |
---|
1358 | |
---|
1359 | def hide_panel(self, uid): |
---|
1360 | """ |
---|
1361 | hide panel except default panel |
---|
1362 | """ |
---|
1363 | ID = str(uid) |
---|
1364 | caption = self.panels[ID].window_caption |
---|
1365 | config.printEVT("hide_panel: %s" % ID) |
---|
1366 | if ID in self.panels.keys(): |
---|
1367 | if self._mgr.GetPane(self.panels[ID].window_name).IsShown(): |
---|
1368 | self._mgr.GetPane(self.panels[ID].window_name).Hide() |
---|
1369 | if self._data_panel is not None and \ |
---|
1370 | ID in self.plot_panels.keys(): |
---|
1371 | self._data_panel.cb_plotpanel.Append(str(caption), p) |
---|
1372 | # Do not Hide default panel here... |
---|
1373 | #self._mgr.GetPane(self.panels["default"].window_name).Hide() |
---|
1374 | self._mgr.Update() |
---|
1375 | |
---|
1376 | def delete_panel(self, uid): |
---|
1377 | """ |
---|
1378 | delete panel given uid |
---|
1379 | """ |
---|
1380 | ID = str(uid) |
---|
1381 | config.printEVT("delete_panel: %s" % ID) |
---|
1382 | caption = self.panels[ID].window_caption |
---|
1383 | if ID in self.panels.keys(): |
---|
1384 | self.panel_on_focus = None |
---|
1385 | panel = self.panels[ID] |
---|
1386 | self._plotting_plugin.delete_panel(panel.group_id) |
---|
1387 | self._mgr.DetachPane(panel) |
---|
1388 | panel.Hide() |
---|
1389 | panel.clear() |
---|
1390 | panel.Close() |
---|
1391 | self._mgr.Update() |
---|
1392 | #delete uid number not str(uid) |
---|
1393 | if uid in self.plot_panels.keys(): |
---|
1394 | del self.plot_panels[uid] |
---|
1395 | return |
---|
1396 | |
---|
1397 | def clear_panel(self): |
---|
1398 | """ |
---|
1399 | """ |
---|
1400 | for item in self.panels: |
---|
1401 | try: |
---|
1402 | self.panels[item].clear_panel() |
---|
1403 | except: |
---|
1404 | pass |
---|
1405 | |
---|
1406 | def create_gui_data(self, data, path=None): |
---|
1407 | """ |
---|
1408 | """ |
---|
1409 | return self._data_manager.create_gui_data(data, path) |
---|
1410 | |
---|
1411 | def get_data(self, path): |
---|
1412 | """ |
---|
1413 | """ |
---|
1414 | message = "" |
---|
1415 | log_msg = '' |
---|
1416 | output = [] |
---|
1417 | error_message = "" |
---|
1418 | basename = os.path.basename(path) |
---|
1419 | root, extension = os.path.splitext(basename) |
---|
1420 | if extension.lower() not in EXTENSIONS: |
---|
1421 | log_msg = "File Loader cannot " |
---|
1422 | log_msg += "load: %s\n" % str(basename) |
---|
1423 | log_msg += "Try Data opening...." |
---|
1424 | logging.info(log_msg) |
---|
1425 | self.load_complete(output=output, error_message=error_message, |
---|
1426 | message=log_msg, path=path) |
---|
1427 | return |
---|
1428 | |
---|
1429 | #reading a state file |
---|
1430 | for plug in self.plugins: |
---|
1431 | reader, ext = plug.get_extensions() |
---|
1432 | if reader is not None: |
---|
1433 | #read the state of the single plugin |
---|
1434 | if extension == ext: |
---|
1435 | reader.read(path) |
---|
1436 | return |
---|
1437 | elif extension == APPLICATION_STATE_EXTENSION: |
---|
1438 | reader.read(path) |
---|
1439 | |
---|
1440 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
1441 | if style == GUIFRAME.MANAGER_ON: |
---|
1442 | if self._data_panel is not None: |
---|
1443 | #data_state = self._data_manager.get_selected_data() |
---|
1444 | #self._data_panel.load_data_list(data_state) |
---|
1445 | self._mgr.GetPane(self._data_panel.window_name).Show(True) |
---|
1446 | |
---|
1447 | def load_from_cmd(self, path): |
---|
1448 | """ |
---|
1449 | load data from cmd or application |
---|
1450 | """ |
---|
1451 | if path is None: |
---|
1452 | return |
---|
1453 | else: |
---|
1454 | path = os.path.abspath(path) |
---|
1455 | if not os.path.isfile(path) and not os.path.isdir(path): |
---|
1456 | return |
---|
1457 | |
---|
1458 | if os.path.isdir(path): |
---|
1459 | self.load_folder(path) |
---|
1460 | return |
---|
1461 | |
---|
1462 | basename = os.path.basename(path) |
---|
1463 | root, extension = os.path.splitext(basename) |
---|
1464 | if extension.lower() not in EXTENSIONS: |
---|
1465 | self.load_data(path) |
---|
1466 | else: |
---|
1467 | self.load_state(path) |
---|
1468 | |
---|
1469 | self._default_save_location = os.path.dirname(path) |
---|
1470 | |
---|
1471 | def load_state(self, path): |
---|
1472 | """ |
---|
1473 | load data from command line or application |
---|
1474 | """ |
---|
1475 | if path and (path is not None) and os.path.isfile(path): |
---|
1476 | basename = os.path.basename(path) |
---|
1477 | if APPLICATION_STATE_EXTENSION is not None \ |
---|
1478 | and basename.endswith(APPLICATION_STATE_EXTENSION): |
---|
1479 | #Hide current plot_panels i |
---|
1480 | for ID in self.plot_panels.keys(): |
---|
1481 | panel = self._mgr.GetPane(self.plot_panels[ID].window_name) |
---|
1482 | if panel.IsShown(): |
---|
1483 | panel.Hide() |
---|
1484 | self.get_data(path) |
---|
1485 | if self.defaultPanel is not None and \ |
---|
1486 | self._mgr.GetPane(self.panels["default"].window_name).IsShown(): |
---|
1487 | self.on_close_welcome_panel() |
---|
1488 | |
---|
1489 | def load_data(self, path): |
---|
1490 | """ |
---|
1491 | load data from command line |
---|
1492 | """ |
---|
1493 | if not os.path.isfile(path): |
---|
1494 | return |
---|
1495 | basename = os.path.basename(path) |
---|
1496 | root, extension = os.path.splitext(basename) |
---|
1497 | if extension.lower() in EXTENSIONS: |
---|
1498 | log_msg = "Data Loader cannot " |
---|
1499 | log_msg += "load: %s\n" % str(path) |
---|
1500 | log_msg += "Try File opening ...." |
---|
1501 | print log_msg |
---|
1502 | return |
---|
1503 | message = "" |
---|
1504 | log_msg = '' |
---|
1505 | output = {} |
---|
1506 | error_message = "" |
---|
1507 | try: |
---|
1508 | print "Loading Data...:\n" + str(path) + "\n" |
---|
1509 | temp = self.loader.load(path) |
---|
1510 | if temp.__class__.__name__ == "list": |
---|
1511 | for item in temp: |
---|
1512 | data = self.create_gui_data(item, path) |
---|
1513 | output[data.id] = data |
---|
1514 | else: |
---|
1515 | data = self.create_gui_data(temp, path) |
---|
1516 | output[data.id] = data |
---|
1517 | |
---|
1518 | self.add_data(data_list=output) |
---|
1519 | except: |
---|
1520 | error_message = "Error while loading" |
---|
1521 | error_message += " Data from cmd:\n %s\n" % str(path) |
---|
1522 | error_message += str(sys.exc_value) + "\n" |
---|
1523 | print error_message |
---|
1524 | |
---|
1525 | def load_folder(self, path): |
---|
1526 | """ |
---|
1527 | Load entire folder |
---|
1528 | """ |
---|
1529 | if not os.path.isdir(path): |
---|
1530 | return |
---|
1531 | if self._data_plugin is None: |
---|
1532 | return |
---|
1533 | try: |
---|
1534 | if path is not None: |
---|
1535 | self._default_save_location = os.path.dirname(path) |
---|
1536 | file_list = self._data_plugin.get_file_path(path) |
---|
1537 | self._data_plugin.get_data(file_list) |
---|
1538 | else: |
---|
1539 | return |
---|
1540 | except: |
---|
1541 | error_message = "Error while loading" |
---|
1542 | error_message += " Data folder from cmd:\n %s\n" % str(path) |
---|
1543 | error_message += str(sys.exc_value) + "\n" |
---|
1544 | print error_message |
---|
1545 | |
---|
1546 | def _on_open_state_application(self, event): |
---|
1547 | """ |
---|
1548 | """ |
---|
1549 | path = None |
---|
1550 | if self._default_save_location == None: |
---|
1551 | self._default_save_location = os.getcwd() |
---|
1552 | |
---|
1553 | plug_wlist = self._on_open_state_app_helper() |
---|
1554 | dlg = wx.FileDialog(self, |
---|
1555 | "Choose a file", |
---|
1556 | self._default_save_location, "", |
---|
1557 | plug_wlist) |
---|
1558 | if dlg.ShowModal() == wx.ID_OK: |
---|
1559 | path = dlg.GetPath() |
---|
1560 | if path is not None: |
---|
1561 | self._default_save_location = os.path.dirname(path) |
---|
1562 | dlg.Destroy() |
---|
1563 | self.load_state(path=path) |
---|
1564 | |
---|
1565 | def _on_open_state_app_helper(self): |
---|
1566 | """ |
---|
1567 | Helps '_on_open_state_application()' to find the extension of |
---|
1568 | the current perspective/application |
---|
1569 | """ |
---|
1570 | # No current perspective or no extension attr |
---|
1571 | if self._current_perspective is None: |
---|
1572 | return PLUGINS_WLIST |
---|
1573 | try: |
---|
1574 | # Find the extension of the perspective and get that as 1st item in list |
---|
1575 | ind = None |
---|
1576 | app_ext = self._current_perspective._extensions |
---|
1577 | plug_wlist = config.PLUGINS_WLIST |
---|
1578 | for ext in set(plug_wlist): |
---|
1579 | if ext.count(app_ext) > 0: |
---|
1580 | ind = ext |
---|
1581 | break |
---|
1582 | # Found the extension |
---|
1583 | if ind != None: |
---|
1584 | plug_wlist.remove(ind) |
---|
1585 | plug_wlist.insert(0, ind) |
---|
1586 | try: |
---|
1587 | plug_wlist ='|'.join(plug_wlist) |
---|
1588 | except: |
---|
1589 | plug_wlist = '' |
---|
1590 | |
---|
1591 | except: |
---|
1592 | plug_wlist = PLUGINS_WLIST |
---|
1593 | |
---|
1594 | return plug_wlist |
---|
1595 | |
---|
1596 | def _on_open_state_project(self, event): |
---|
1597 | """ |
---|
1598 | """ |
---|
1599 | path = None |
---|
1600 | if self._default_save_location == None: |
---|
1601 | self._default_save_location = os.getcwd() |
---|
1602 | |
---|
1603 | dlg = wx.FileDialog(self, |
---|
1604 | "Choose a file", |
---|
1605 | self._default_save_location, "", |
---|
1606 | APPLICATION_WLIST) |
---|
1607 | if dlg.ShowModal() == wx.ID_OK: |
---|
1608 | path = dlg.GetPath() |
---|
1609 | if path is not None: |
---|
1610 | self._default_save_location = os.path.dirname(path) |
---|
1611 | dlg.Destroy() |
---|
1612 | |
---|
1613 | #try: |
---|
1614 | # os.popen(path) |
---|
1615 | # #self.Close() |
---|
1616 | #except: |
---|
1617 | self.load_state(path=path) |
---|
1618 | |
---|
1619 | def _on_save_application(self, event): |
---|
1620 | """ |
---|
1621 | save the state of the current active application |
---|
1622 | """ |
---|
1623 | if self.cpanel_on_focus is not None: |
---|
1624 | self.cpanel_on_focus.on_save(event) |
---|
1625 | |
---|
1626 | def _on_save_project(self, event): |
---|
1627 | """ |
---|
1628 | save the state of the SansView as *.svs |
---|
1629 | """ |
---|
1630 | ## Default file location for save |
---|
1631 | self._default_save_location = os.getcwd() |
---|
1632 | if self._current_perspective is None: |
---|
1633 | return |
---|
1634 | reader, ext = self._current_perspective.get_extensions() |
---|
1635 | path = None |
---|
1636 | extension = '*' + APPLICATION_STATE_EXTENSION |
---|
1637 | dlg = wx.FileDialog(self, "Save Project file", |
---|
1638 | self._default_save_location, "", |
---|
1639 | extension, |
---|
1640 | wx.SAVE) |
---|
1641 | if dlg.ShowModal() == wx.ID_OK: |
---|
1642 | path = dlg.GetPath() |
---|
1643 | self._default_save_location = os.path.dirname(path) |
---|
1644 | else: |
---|
1645 | return None |
---|
1646 | dlg.Destroy() |
---|
1647 | if path is None: |
---|
1648 | return |
---|
1649 | # default cansas xml doc |
---|
1650 | doc = None |
---|
1651 | for panel in self.panels.values(): |
---|
1652 | temp = panel.save_project(doc) |
---|
1653 | if temp is not None: |
---|
1654 | doc = temp |
---|
1655 | |
---|
1656 | # Write the XML document |
---|
1657 | extens = APPLICATION_STATE_EXTENSION |
---|
1658 | fName = os.path.splitext(path)[0] + extens |
---|
1659 | if doc != None: |
---|
1660 | fd = open(fName, 'w') |
---|
1661 | fd.write(doc.toprettyxml()) |
---|
1662 | fd.close() |
---|
1663 | else: |
---|
1664 | msg = "%s cannot read %s\n" % (str(APPLICATION_NAME), str(path)) |
---|
1665 | logging.error(msg) |
---|
1666 | |
---|
1667 | def on_save_helper(self, doc, reader, panel, path): |
---|
1668 | """ |
---|
1669 | Save state into a file |
---|
1670 | """ |
---|
1671 | try: |
---|
1672 | if reader is not None: |
---|
1673 | # case of a panel with multi-pages |
---|
1674 | if hasattr(panel, "opened_pages"): |
---|
1675 | for uid, page in panel.opened_pages.iteritems(): |
---|
1676 | data = page.get_data() |
---|
1677 | # state must be cloned |
---|
1678 | state = page.get_state().clone() |
---|
1679 | if data is not None: |
---|
1680 | new_doc = reader.write_toXML(data, state) |
---|
1681 | if doc != None and hasattr(doc, "firstChild"): |
---|
1682 | child = new_doc.firstChild.firstChild |
---|
1683 | doc.firstChild.appendChild(child) |
---|
1684 | else: |
---|
1685 | doc = new_doc |
---|
1686 | # case of only a panel |
---|
1687 | else: |
---|
1688 | data = panel.get_data() |
---|
1689 | state = panel.get_state() |
---|
1690 | if data is not None: |
---|
1691 | new_doc = reader.write_toXML(data, state) |
---|
1692 | if doc != None and hasattr(doc, "firstChild"): |
---|
1693 | child = new_doc.firstChild.firstChild |
---|
1694 | doc.firstChild.appendChild(child) |
---|
1695 | else: |
---|
1696 | doc = new_doc |
---|
1697 | except: |
---|
1698 | raise |
---|
1699 | #pass |
---|
1700 | |
---|
1701 | return doc |
---|
1702 | |
---|
1703 | def quit_guiframe(self): |
---|
1704 | """ |
---|
1705 | Pop up message to make sure the user wants to quit the application |
---|
1706 | """ |
---|
1707 | message = "Do you really want to quit \n" |
---|
1708 | message += "this application?" |
---|
1709 | dial = wx.MessageDialog(self, message, 'Question', |
---|
1710 | wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION) |
---|
1711 | if dial.ShowModal() == wx.ID_YES: |
---|
1712 | return True |
---|
1713 | else: |
---|
1714 | return False |
---|
1715 | |
---|
1716 | def Close(self, event=None): |
---|
1717 | """ |
---|
1718 | Quit the application |
---|
1719 | """ |
---|
1720 | flag = self.quit_guiframe() |
---|
1721 | if flag: |
---|
1722 | wx.Exit() |
---|
1723 | sys.exit() |
---|
1724 | |
---|
1725 | def _check_update(self, event=None): |
---|
1726 | """ |
---|
1727 | Check with the deployment server whether a new version |
---|
1728 | of the application is available. |
---|
1729 | A thread is started for the connecting with the server. The thread calls |
---|
1730 | a call-back method when the current version number has been obtained. |
---|
1731 | """ |
---|
1732 | if hasattr(config, "__update_URL__"): |
---|
1733 | import version |
---|
1734 | checker = version.VersionThread(config.__update_URL__, |
---|
1735 | self._process_version, |
---|
1736 | baggage=event==None) |
---|
1737 | checker.start() |
---|
1738 | |
---|
1739 | def _process_version(self, version, standalone=True): |
---|
1740 | """ |
---|
1741 | Call-back method for the process of checking for updates. |
---|
1742 | This methods is called by a VersionThread object once the current |
---|
1743 | version number has been obtained. If the check is being done in the |
---|
1744 | background, the user will not be notified unless there's an update. |
---|
1745 | |
---|
1746 | :param version: version string |
---|
1747 | :param standalone: True of the update is being checked in |
---|
1748 | the background, False otherwise. |
---|
1749 | |
---|
1750 | """ |
---|
1751 | try: |
---|
1752 | if cmp(version, config.__version__) > 0: |
---|
1753 | msg = "Version %s is available! See the Help " |
---|
1754 | msg += "menu to download it." % version |
---|
1755 | self.SetStatusText(msg) |
---|
1756 | if not standalone: |
---|
1757 | import webbrowser |
---|
1758 | webbrowser.open(config.__download_page__) |
---|
1759 | else: |
---|
1760 | if not standalone: |
---|
1761 | msg = "You have the latest version" |
---|
1762 | msg += " of %s" % config.__appname__ |
---|
1763 | self.SetStatusText(msg) |
---|
1764 | except: |
---|
1765 | msg = "guiframe: could not get latest application" |
---|
1766 | msg += " version number\n %s" % sys.exc_value |
---|
1767 | logging.error(msg) |
---|
1768 | if not standalone: |
---|
1769 | msg = "Could not connect to the application server." |
---|
1770 | msg += " Please try again later." |
---|
1771 | self.SetStatusText(msg) |
---|
1772 | |
---|
1773 | def _onAbout(self, evt): |
---|
1774 | """ |
---|
1775 | Pop up the about dialog |
---|
1776 | |
---|
1777 | :param evt: menu event |
---|
1778 | |
---|
1779 | """ |
---|
1780 | if config._do_aboutbox: |
---|
1781 | import aboutbox |
---|
1782 | dialog = aboutbox.DialogAbout(None, -1, "") |
---|
1783 | dialog.ShowModal() |
---|
1784 | |
---|
1785 | def _onTutorial(self, evt): |
---|
1786 | """ |
---|
1787 | Pop up the tutorial dialog |
---|
1788 | |
---|
1789 | :param evt: menu event |
---|
1790 | |
---|
1791 | """ |
---|
1792 | if config._do_tutorial: |
---|
1793 | path = config.TUTORIAL_PATH |
---|
1794 | if IS_WIN: |
---|
1795 | try: |
---|
1796 | from sans.guiframe.pdfview import PDFFrame |
---|
1797 | |
---|
1798 | dialog = PDFFrame(None, -1, "Tutorial", path) |
---|
1799 | #self.SetTopWindow(dialog) |
---|
1800 | dialog.Show(True) |
---|
1801 | except: |
---|
1802 | raise |
---|
1803 | msg = "This feature requires 'Adobe pdf Reader'\n" |
---|
1804 | msg += "Please install it first (Free)..." |
---|
1805 | wx.MessageBox(msg, 'Error') |
---|
1806 | else: |
---|
1807 | try: |
---|
1808 | command = "open " |
---|
1809 | command += path |
---|
1810 | os.system(command) |
---|
1811 | except: |
---|
1812 | msg = "This feature requires 'Preview' Application\n" |
---|
1813 | msg += "Please install it first..." |
---|
1814 | wx.MessageBox(msg, 'Error') |
---|
1815 | |
---|
1816 | |
---|
1817 | def set_manager(self, manager): |
---|
1818 | """ |
---|
1819 | Sets the application manager for this frame |
---|
1820 | |
---|
1821 | :param manager: frame manager |
---|
1822 | """ |
---|
1823 | self.app_manager = manager |
---|
1824 | |
---|
1825 | def post_init(self): |
---|
1826 | """ |
---|
1827 | This initialization method is called after the GUI |
---|
1828 | has been created and all plug-ins loaded. It calls |
---|
1829 | the post_init() method of each plug-in (if it exists) |
---|
1830 | so that final initialization can be done. |
---|
1831 | """ |
---|
1832 | for item in self.plugins: |
---|
1833 | if hasattr(item, "post_init"): |
---|
1834 | item.post_init() |
---|
1835 | |
---|
1836 | def set_default_perspective(self): |
---|
1837 | """ |
---|
1838 | Choose among the plugin the first plug-in that has |
---|
1839 | "set_default_perspective" method and its return value is True will be |
---|
1840 | as a default perspective when the welcome page is closed |
---|
1841 | """ |
---|
1842 | for item in self.plugins: |
---|
1843 | if hasattr(item, "set_default_perspective"): |
---|
1844 | if item.set_default_perspective(): |
---|
1845 | item.on_perspective(event=None) |
---|
1846 | return |
---|
1847 | |
---|
1848 | def set_perspective(self, panels): |
---|
1849 | """ |
---|
1850 | Sets the perspective of the GUI. |
---|
1851 | Opens all the panels in the list, and closes |
---|
1852 | all the others. |
---|
1853 | |
---|
1854 | :param panels: list of panels |
---|
1855 | """ |
---|
1856 | #style = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
1857 | #if (style == GUIFRAME.TOOLBAR_ON) & (not self._toolbar.IsShown()): |
---|
1858 | # self._on_toggle_toolbar() |
---|
1859 | for item in self.panels: |
---|
1860 | # Check whether this is a sticky panel |
---|
1861 | if hasattr(self.panels[item], "ALWAYS_ON"): |
---|
1862 | if self.panels[item].ALWAYS_ON: |
---|
1863 | continue |
---|
1864 | |
---|
1865 | if self.panels[item].window_name in panels: |
---|
1866 | if not self._mgr.GetPane(self.panels[item].window_name).IsShown(): |
---|
1867 | self._mgr.GetPane(self.panels[item].window_name).Show() |
---|
1868 | else: |
---|
1869 | # always show the data panel if enable |
---|
1870 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
1871 | if (style == GUIFRAME.MANAGER_ON) and self.panels[item] == self._data_panel: |
---|
1872 | if 'data_panel' in self.panels.keys(): |
---|
1873 | flag = self._mgr.GetPane(self.panels['data_panel'].window_name).IsShown() |
---|
1874 | self._mgr.GetPane(self.panels['data_panel'].window_name).Show(flag) |
---|
1875 | else: |
---|
1876 | if self._mgr.GetPane(self.panels[item].window_name).IsShown(): |
---|
1877 | self._mgr.GetPane(self.panels[item].window_name).Hide() |
---|
1878 | |
---|
1879 | self._mgr.Update() |
---|
1880 | |
---|
1881 | def show_data_panel(self, event=None, action=True): |
---|
1882 | """ |
---|
1883 | show the data panel |
---|
1884 | """ |
---|
1885 | if self._data_panel_menu == None: |
---|
1886 | return |
---|
1887 | label = self._data_panel_menu.GetText() |
---|
1888 | if label == 'Show Data Explorer': |
---|
1889 | pane = self._mgr.GetPane(self.panels["data_panel"].window_name) |
---|
1890 | #if not pane.IsShown(): |
---|
1891 | if action: |
---|
1892 | pane.Show(True) |
---|
1893 | self._mgr.Update() |
---|
1894 | self.__gui_style = self.__gui_style | GUIFRAME.MANAGER_ON |
---|
1895 | |
---|
1896 | self._data_panel_menu.SetText('Hide Data Explorer') |
---|
1897 | else: |
---|
1898 | pane = self._mgr.GetPane(self.panels["data_panel"].window_name) |
---|
1899 | #if not pane.IsShown(): |
---|
1900 | if action: |
---|
1901 | pane.Show(False) |
---|
1902 | self._mgr.Update() |
---|
1903 | self.__gui_style = self.__gui_style & (~GUIFRAME.MANAGER_ON) |
---|
1904 | self._data_panel_menu.SetText('Show Data Explorer') |
---|
1905 | |
---|
1906 | def add_data_helper(self, data_list): |
---|
1907 | """ |
---|
1908 | """ |
---|
1909 | if self._data_manager is not None: |
---|
1910 | self._data_manager.add_data(data_list) |
---|
1911 | |
---|
1912 | def add_data(self, data_list): |
---|
1913 | """ |
---|
1914 | receive a dictionary of data from loader |
---|
1915 | store them its data manager if possible |
---|
1916 | send to data the current active perspective if the data panel |
---|
1917 | is not active. |
---|
1918 | :param data_list: dictionary of data's ID and value Data |
---|
1919 | """ |
---|
1920 | #Store data into manager |
---|
1921 | self.add_data_helper(data_list) |
---|
1922 | # set data in the data panel |
---|
1923 | if self._data_panel is not None: |
---|
1924 | data_state = self._data_manager.get_data_state(data_list.keys()) |
---|
1925 | self._data_panel.load_data_list(data_state) |
---|
1926 | #if the data panel is shown wait for the user to press a button |
---|
1927 | #to send data to the current perspective. if the panel is not |
---|
1928 | #show automatically send the data to the current perspective |
---|
1929 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
1930 | if style == GUIFRAME.MANAGER_ON: |
---|
1931 | #wait for button press from the data panel to set_data |
---|
1932 | if self._data_panel is not None: |
---|
1933 | self._mgr.GetPane(self._data_panel.window_name).Show(True) |
---|
1934 | self._mgr.Update() |
---|
1935 | else: |
---|
1936 | #automatically send that to the current perspective |
---|
1937 | self.set_data(data_id=data_list.keys()) |
---|
1938 | self.on_close_welcome_panel() |
---|
1939 | |
---|
1940 | def set_data(self, data_id, theory_id=None): |
---|
1941 | """ |
---|
1942 | set data to current perspective |
---|
1943 | """ |
---|
1944 | list_data, _ = self._data_manager.get_by_id(data_id) |
---|
1945 | if self._current_perspective is not None: |
---|
1946 | if self.cleanup_plots: |
---|
1947 | for uid, panel in self.plot_panels.iteritems(): |
---|
1948 | #panel = self.plot_panels[uid] |
---|
1949 | window = self._mgr.GetPane(panel.window_name) |
---|
1950 | # To hide all docked plot panels when set the data |
---|
1951 | if not window.IsFloating(): |
---|
1952 | self.hide_panel(uid) |
---|
1953 | self._current_perspective.set_data(list_data.values()) |
---|
1954 | self.on_close_welcome_panel() |
---|
1955 | else: |
---|
1956 | msg = "Guiframe does not have a current perspective" |
---|
1957 | logging.info(msg) |
---|
1958 | |
---|
1959 | def set_theory(self, state_id, theory_id=None): |
---|
1960 | """ |
---|
1961 | """ |
---|
1962 | _, list_theory = self._data_manager.get_by_id(theory_id) |
---|
1963 | if self._current_perspective is not None: |
---|
1964 | try: |
---|
1965 | self._current_perspective.set_theory(list_theory.values()) |
---|
1966 | except: |
---|
1967 | msg = "Guiframe set_theory: \n" + str(sys.exc_value) |
---|
1968 | logging.info(msg) |
---|
1969 | wx.PostEvent(self, StatusEvent(status=msg, info="error")) |
---|
1970 | else: |
---|
1971 | msg = "Guiframe does not have a current perspective" |
---|
1972 | logging.info(msg) |
---|
1973 | |
---|
1974 | def plot_data(self, state_id, data_id=None, |
---|
1975 | theory_id=None, append=False): |
---|
1976 | """ |
---|
1977 | send a list of data to plot |
---|
1978 | """ |
---|
1979 | total_plot_list = [] |
---|
1980 | data_list, _ = self._data_manager.get_by_id(data_id) |
---|
1981 | _, temp_list_theory = self._data_manager.get_by_id(theory_id) |
---|
1982 | total_plot_list = data_list.values() |
---|
1983 | for item in temp_list_theory.values(): |
---|
1984 | theory_data, theory_state = item |
---|
1985 | total_plot_list.append(theory_data) |
---|
1986 | GROUP_ID = wx.NewId() |
---|
1987 | for new_plot in total_plot_list: |
---|
1988 | if append: |
---|
1989 | if self.panel_on_focus is None: |
---|
1990 | message = "cannot append plot. No plot panel on focus!" |
---|
1991 | message += "please click on any available plot to set focus" |
---|
1992 | wx.PostEvent(self, StatusEvent(status=message, |
---|
1993 | info='warning')) |
---|
1994 | return |
---|
1995 | else: |
---|
1996 | if self.enable_add_data(new_plot): |
---|
1997 | new_plot.group_id = self.panel_on_focus.group_id |
---|
1998 | else: |
---|
1999 | message = "Only 1D Data can be append to" |
---|
2000 | message += " plot panel containing 1D data.\n" |
---|
2001 | message += "%s not be appended.\n" %str(new_plot.name) |
---|
2002 | message += "try new plot option.\n" |
---|
2003 | wx.PostEvent(self, StatusEvent(status=message, |
---|
2004 | info='warning')) |
---|
2005 | else: |
---|
2006 | if self.cleanup_plots: |
---|
2007 | for id, panel in self.plot_panels.iteritems(): |
---|
2008 | window = self._mgr.GetPane(panel.window_name) |
---|
2009 | # To hide all docked plot panels when set the data |
---|
2010 | if not window.IsFloating(): |
---|
2011 | self.hide_panel(id) |
---|
2012 | #if not append then new plot |
---|
2013 | from sans.guiframe.dataFitting import Data2D |
---|
2014 | if issubclass(Data2D, new_plot.__class__): |
---|
2015 | #for 2 D always plot in a separated new plot |
---|
2016 | new_plot.group_id = wx.NewId() |
---|
2017 | else: |
---|
2018 | # plot all 1D in a new plot |
---|
2019 | new_plot.group_id = GROUP_ID |
---|
2020 | title = "PLOT " + str(new_plot.title) |
---|
2021 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
2022 | title=title, |
---|
2023 | group_id = new_plot.group_id)) |
---|
2024 | |
---|
2025 | def remove_data(self, data_id, theory_id=None): |
---|
2026 | """ |
---|
2027 | Delete data state if data_id is provide |
---|
2028 | delete theory created with data of id data_id if theory_id is provide |
---|
2029 | if delete all true: delete the all state |
---|
2030 | else delete theory |
---|
2031 | """ |
---|
2032 | temp = data_id + theory_id |
---|
2033 | """ |
---|
2034 | value = [plug.is_in_use(temp) for plug in self.plugins] |
---|
2035 | if len(value) > 0: |
---|
2036 | print "value" |
---|
2037 | return |
---|
2038 | from data_panel import DataDialog |
---|
2039 | dlg = DataDialog(data_list=data_list, nb_data=MAX_NBR_DATA) |
---|
2040 | if dlg.ShowModal() == wx.ID_OK: |
---|
2041 | selected_data_list = dlg.get_data() |
---|
2042 | dlg.Destroy() |
---|
2043 | """ |
---|
2044 | for plug in self.plugins: |
---|
2045 | plug.delete_data(temp) |
---|
2046 | total_plot_list = [] |
---|
2047 | data_list, _ = self._data_manager.get_by_id(data_id) |
---|
2048 | _, temp_list_theory = self._data_manager.get_by_id(theory_id) |
---|
2049 | total_plot_list = data_list.values() |
---|
2050 | for item in temp_list_theory.values(): |
---|
2051 | theory_data, theory_state = item |
---|
2052 | total_plot_list.append(theory_data) |
---|
2053 | for new_plot in total_plot_list: |
---|
2054 | id = new_plot.id |
---|
2055 | for group_id in new_plot.list_group_id: |
---|
2056 | wx.PostEvent(self, NewPlotEvent(id=id, |
---|
2057 | group_id=group_id, |
---|
2058 | action='remove')) |
---|
2059 | self._data_manager.delete_data(data_id=data_id, |
---|
2060 | theory_id=theory_id) |
---|
2061 | |
---|
2062 | |
---|
2063 | def set_current_perspective(self, perspective): |
---|
2064 | """ |
---|
2065 | set the current active perspective |
---|
2066 | """ |
---|
2067 | self._current_perspective = perspective |
---|
2068 | name = "No current analysis selected" |
---|
2069 | if self._current_perspective is not None: |
---|
2070 | self._add_current_plugin_menu() |
---|
2071 | for panel in self.panels.values(): |
---|
2072 | if hasattr(panel, 'CENTER_PANE') and panel.CENTER_PANE: |
---|
2073 | for name in self._current_perspective.get_perspective(): |
---|
2074 | if name == panel.window_name: |
---|
2075 | panel.on_set_focus(event=None) |
---|
2076 | break |
---|
2077 | name = self._current_perspective.sub_menu |
---|
2078 | if self._data_panel is not None: |
---|
2079 | self._data_panel.set_active_perspective(name) |
---|
2080 | self._check_applications_menu() |
---|
2081 | #Set the SansView title |
---|
2082 | self._set_title_name(name) |
---|
2083 | |
---|
2084 | |
---|
2085 | def _set_title_name(self, name): |
---|
2086 | """ |
---|
2087 | Set the SansView title w/ the current application name |
---|
2088 | |
---|
2089 | : param name: application name [string] |
---|
2090 | """ |
---|
2091 | # Set SanView Window title w/ application anme |
---|
2092 | title = self.title + " - " + name + " -" |
---|
2093 | self.SetTitle(title) |
---|
2094 | |
---|
2095 | def _check_applications_menu(self): |
---|
2096 | """ |
---|
2097 | check the menu of the current application |
---|
2098 | """ |
---|
2099 | if self._applications_menu is not None: |
---|
2100 | for menu in self._applications_menu.GetMenuItems(): |
---|
2101 | if self._current_perspective is not None: |
---|
2102 | name = self._current_perspective.sub_menu |
---|
2103 | if menu.IsCheckable(): |
---|
2104 | if menu.GetLabel() == name: |
---|
2105 | menu.Check(True) |
---|
2106 | else: |
---|
2107 | menu.Check(False) |
---|
2108 | |
---|
2109 | def set_plotpanel_floating(self, event=None): |
---|
2110 | """ |
---|
2111 | make the plot panel floatable |
---|
2112 | """ |
---|
2113 | |
---|
2114 | self.__gui_style &= (~GUIFRAME.FIXED_PANEL) |
---|
2115 | self.__gui_style |= GUIFRAME.FLOATING_PANEL |
---|
2116 | plot_panel = [] |
---|
2117 | id = event.GetId() |
---|
2118 | menu = self._window_menu.FindItemById(id) |
---|
2119 | if self._plotting_plugin is not None: |
---|
2120 | plot_panel = self._plotting_plugin.plot_panels.values() |
---|
2121 | for p in plot_panel: |
---|
2122 | self._popup_floating_panel(p) |
---|
2123 | menu.Check(True) |
---|
2124 | |
---|
2125 | def set_plotpanel_fixed(self, event=None): |
---|
2126 | """ |
---|
2127 | make the plot panel fixed |
---|
2128 | """ |
---|
2129 | self.__gui_style &= (~GUIFRAME.FLOATING_PANEL) |
---|
2130 | self.__gui_style |= GUIFRAME.FIXED_PANEL |
---|
2131 | plot_panel = [] |
---|
2132 | id = event.GetId() |
---|
2133 | menu = self._window_menu.FindItemById(id) |
---|
2134 | if self._plotting_plugin is not None: |
---|
2135 | plot_panel = self._plotting_plugin.plot_panels.values() |
---|
2136 | for p in plot_panel: |
---|
2137 | self._popup_fixed_panel(p) |
---|
2138 | menu.Check(True) |
---|
2139 | |
---|
2140 | def on_cleanup_dock(self, event=None): |
---|
2141 | """ |
---|
2142 | Set Cleanup Dock option |
---|
2143 | """ |
---|
2144 | if event == None: |
---|
2145 | return |
---|
2146 | id = event.GetId() |
---|
2147 | menu = self._window_menu.FindItemById(id) |
---|
2148 | Flag = self.cleanup_plots |
---|
2149 | if not Flag: |
---|
2150 | menu.Check(True) |
---|
2151 | self.cleanup_plots = True |
---|
2152 | msg = "Cleanup-Dock option set to 'ON'." |
---|
2153 | else: |
---|
2154 | menu.Check(False) |
---|
2155 | self.cleanup_plots = False |
---|
2156 | msg = "Cleanup-Dock option set to 'OFF'." |
---|
2157 | |
---|
2158 | wx.PostEvent(self, StatusEvent(status= msg)) |
---|
2159 | |
---|
2160 | def _popup_fixed_panel(self, p): |
---|
2161 | """ |
---|
2162 | """ |
---|
2163 | style = self.__gui_style & GUIFRAME.FIXED_PANEL |
---|
2164 | if style == GUIFRAME.FIXED_PANEL: |
---|
2165 | self._mgr.GetPane(p.window_name).Dock() |
---|
2166 | self._mgr.GetPane(p.window_name).Floatable() |
---|
2167 | self._mgr.GetPane(p.window_name).Right() |
---|
2168 | self._mgr.GetPane(p.window_name).TopDockable(False) |
---|
2169 | self._mgr.GetPane(p.window_name).BottomDockable(False) |
---|
2170 | self._mgr.GetPane(p.window_name).LeftDockable(False) |
---|
2171 | self._mgr.GetPane(p.window_name).RightDockable(True) |
---|
2172 | self._mgr.Update() |
---|
2173 | |
---|
2174 | def _popup_floating_panel(self, p): |
---|
2175 | """ |
---|
2176 | """ |
---|
2177 | style = self.__gui_style & GUIFRAME.FLOATING_PANEL |
---|
2178 | if style == GUIFRAME.FLOATING_PANEL: |
---|
2179 | self._mgr.GetPane(p.window_name).Floatable(True) |
---|
2180 | self._mgr.GetPane(p.window_name).Float() |
---|
2181 | self._mgr.GetPane(p.window_name).Dockable(False) |
---|
2182 | self._mgr.Update() |
---|
2183 | |
---|
2184 | def enable_add_data(self, new_plot): |
---|
2185 | """ |
---|
2186 | Enable append data on a plot panel |
---|
2187 | """ |
---|
2188 | |
---|
2189 | if self.panel_on_focus not in self._plotting_plugin.plot_panels.values(): |
---|
2190 | return |
---|
2191 | is_theory = len(self.panel_on_focus.plots) <= 1 and \ |
---|
2192 | self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D" |
---|
2193 | |
---|
2194 | is_data2d = hasattr(new_plot, 'data') |
---|
2195 | |
---|
2196 | is_data1d = self.panel_on_focus.__class__.__name__ == "ModelPanel1D"\ |
---|
2197 | and self.panel_on_focus.group_id is not None |
---|
2198 | has_meta_data = hasattr(new_plot, 'meta_data') |
---|
2199 | |
---|
2200 | #disable_add_data if the data is being recovered from a saved state file. |
---|
2201 | is_state_data = False |
---|
2202 | if has_meta_data: |
---|
2203 | if 'invstate' in new_plot.meta_data: is_state_data = True |
---|
2204 | if 'prstate' in new_plot.meta_data: is_state_data = True |
---|
2205 | if 'fitstate' in new_plot.meta_data: is_state_data = True |
---|
2206 | |
---|
2207 | return is_data1d and not is_data2d and not is_theory and not is_state_data |
---|
2208 | |
---|
2209 | def enable_edit_menu(self): |
---|
2210 | """ |
---|
2211 | enable menu item under edit menu depending on the panel on focus |
---|
2212 | """ |
---|
2213 | if self.cpanel_on_focus is not None and self._edit_menu is not None: |
---|
2214 | flag = self.cpanel_on_focus.get_undo_flag() |
---|
2215 | self._edit_menu.Enable(GUIFRAME_ID.UNDO_ID, flag) |
---|
2216 | flag = self.cpanel_on_focus.get_redo_flag() |
---|
2217 | self._edit_menu.Enable(GUIFRAME_ID.REDO_ID, flag) |
---|
2218 | flag = self.cpanel_on_focus.get_copy_flag() |
---|
2219 | self._edit_menu.Enable(GUIFRAME_ID.COPY_ID, flag) |
---|
2220 | flag = self.cpanel_on_focus.get_paste_flag() |
---|
2221 | self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) |
---|
2222 | #flag = self.cpanel_on_focus.get_print_flag() |
---|
2223 | #self._edit_menu.Enable(GUIFRAME_ID.PRINT_ID, flag) |
---|
2224 | flag = self.cpanel_on_focus.get_preview_flag() |
---|
2225 | self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) |
---|
2226 | flag = self.cpanel_on_focus.get_reset_flag() |
---|
2227 | self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) |
---|
2228 | else: |
---|
2229 | flag = False |
---|
2230 | self._edit_menu.Enable(GUIFRAME_ID.UNDO_ID, flag) |
---|
2231 | self._edit_menu.Enable(GUIFRAME_ID.REDO_ID, flag) |
---|
2232 | self._edit_menu.Enable(GUIFRAME_ID.COPY_ID, flag) |
---|
2233 | self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) |
---|
2234 | #self._edit_menu.Enable(GUIFRAME_ID.PRINT_ID, flag) |
---|
2235 | self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) |
---|
2236 | self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) |
---|
2237 | |
---|
2238 | def on_undo_panel(self, event=None): |
---|
2239 | """ |
---|
2240 | undo previous action of the last panel on focus if possible |
---|
2241 | """ |
---|
2242 | if self.cpanel_on_focus is not None: |
---|
2243 | self.cpanel_on_focus.on_undo(event) |
---|
2244 | |
---|
2245 | def on_redo_panel(self, event=None): |
---|
2246 | """ |
---|
2247 | redo the last cancel action done on the last panel on focus |
---|
2248 | """ |
---|
2249 | if self.cpanel_on_focus is not None: |
---|
2250 | self.cpanel_on_focus.on_redo(event) |
---|
2251 | |
---|
2252 | def on_copy_panel(self, event=None): |
---|
2253 | """ |
---|
2254 | copy the last panel on focus if possible |
---|
2255 | """ |
---|
2256 | if self.cpanel_on_focus is not None: |
---|
2257 | self.cpanel_on_focus.on_copy(event) |
---|
2258 | |
---|
2259 | def on_paste_panel(self, event=None): |
---|
2260 | """ |
---|
2261 | paste clipboard to the last panel on focus |
---|
2262 | """ |
---|
2263 | if self.cpanel_on_focus is not None: |
---|
2264 | self.cpanel_on_focus.on_paste(event) |
---|
2265 | |
---|
2266 | def on_bookmark_panel(self, event=None): |
---|
2267 | """ |
---|
2268 | bookmark panel |
---|
2269 | """ |
---|
2270 | if self.cpanel_on_focus is not None: |
---|
2271 | self.cpanel_on_focus.on_bookmark(event) |
---|
2272 | |
---|
2273 | def append_bookmark(self, event=None): |
---|
2274 | """ |
---|
2275 | Bookmark available information of the panel on focus |
---|
2276 | """ |
---|
2277 | self._toolbar.append_bookmark(event) |
---|
2278 | |
---|
2279 | def on_save_panel(self, event=None): |
---|
2280 | """ |
---|
2281 | save possible information on the current panel |
---|
2282 | """ |
---|
2283 | if self.cpanel_on_focus is not None: |
---|
2284 | self.cpanel_on_focus.on_save(event) |
---|
2285 | |
---|
2286 | def on_preview_panel(self, event=None): |
---|
2287 | """ |
---|
2288 | preview information on the panel on focus |
---|
2289 | """ |
---|
2290 | if self.cpanel_on_focus is not None: |
---|
2291 | self.cpanel_on_focus.on_preview(event) |
---|
2292 | |
---|
2293 | def on_print_panel(self, event=None): |
---|
2294 | """ |
---|
2295 | print available information on the last panel on focus |
---|
2296 | """ |
---|
2297 | if self.cpanel_on_focus is not None: |
---|
2298 | self.cpanel_on_focus.on_print(event) |
---|
2299 | |
---|
2300 | def on_zoom_panel(self, event=None): |
---|
2301 | """ |
---|
2302 | zoom on the current panel if possible |
---|
2303 | """ |
---|
2304 | if self.cpanel_on_focus is not None: |
---|
2305 | self.cpanel_on_focus.on_zoom(event) |
---|
2306 | |
---|
2307 | def on_zoom_in_panel(self, event=None): |
---|
2308 | """ |
---|
2309 | zoom in of the panel on focus |
---|
2310 | """ |
---|
2311 | if self.cpanel_on_focus is not None: |
---|
2312 | self.cpanel_on_focus.on_zoom_in(event) |
---|
2313 | |
---|
2314 | def on_zoom_out_panel(self, event=None): |
---|
2315 | """ |
---|
2316 | zoom out on the panel on focus |
---|
2317 | """ |
---|
2318 | if self.cpanel_on_focus is not None: |
---|
2319 | self.cpanel_on_focus.on_zoom_out(event) |
---|
2320 | |
---|
2321 | def on_drag_panel(self, event=None): |
---|
2322 | """ |
---|
2323 | drag apply to the panel on focus |
---|
2324 | """ |
---|
2325 | if self.cpanel_on_focus is not None: |
---|
2326 | self.cpanel_on_focus.on_drag(event) |
---|
2327 | |
---|
2328 | def on_reset_panel(self, event=None): |
---|
2329 | """ |
---|
2330 | reset the current panel |
---|
2331 | """ |
---|
2332 | if self.cpanel_on_focus is not None: |
---|
2333 | self.cpanel_on_focus.on_reset(event) |
---|
2334 | |
---|
2335 | def enable_undo(self): |
---|
2336 | """ |
---|
2337 | enable undo related control |
---|
2338 | """ |
---|
2339 | if self.cpanel_on_focus is not None: |
---|
2340 | self._toolbar.enable_undo(self.cpanel_on_focus) |
---|
2341 | |
---|
2342 | def enable_redo(self): |
---|
2343 | """ |
---|
2344 | enable redo |
---|
2345 | """ |
---|
2346 | if self.cpanel_on_focus is not None: |
---|
2347 | self._toolbar.enable_redo(self.cpanel_on_focus) |
---|
2348 | |
---|
2349 | def enable_copy(self): |
---|
2350 | """ |
---|
2351 | enable copy related control |
---|
2352 | """ |
---|
2353 | if self.cpanel_on_focus is not None: |
---|
2354 | self._toolbar.enable_copy(self.cpanel_on_focus) |
---|
2355 | |
---|
2356 | def enable_paste(self): |
---|
2357 | """ |
---|
2358 | enable paste |
---|
2359 | """ |
---|
2360 | if self.cpanel_on_focus is not None: |
---|
2361 | self._toolbar.enable_paste(self.cpanel_on_focus) |
---|
2362 | |
---|
2363 | def enable_bookmark(self): |
---|
2364 | """ |
---|
2365 | Bookmark |
---|
2366 | """ |
---|
2367 | if self.cpanel_on_focus is not None: |
---|
2368 | self._toolbar.enable_bookmark(self.cpanel_on_focus) |
---|
2369 | |
---|
2370 | def enable_save(self): |
---|
2371 | """ |
---|
2372 | save |
---|
2373 | """ |
---|
2374 | if self.cpanel_on_focus is not None: |
---|
2375 | self._toolbar.enable_save(self.cpanel_on_focus) |
---|
2376 | |
---|
2377 | def enable_preview(self): |
---|
2378 | """ |
---|
2379 | preview |
---|
2380 | """ |
---|
2381 | if self.cpanel_on_focus is not None: |
---|
2382 | self._toolbar.enable_preview(self.cpanel_on_focus) |
---|
2383 | |
---|
2384 | def enable_print(self): |
---|
2385 | """ |
---|
2386 | print |
---|
2387 | """ |
---|
2388 | if self.cpanel_on_focus is not None: |
---|
2389 | self._toolbar.enable_print(self.cpanel_on_focus) |
---|
2390 | |
---|
2391 | def enable_zoom(self): |
---|
2392 | """ |
---|
2393 | zoom |
---|
2394 | """ |
---|
2395 | if self.cpanel_on_focus is not None: |
---|
2396 | self._toolbar.enable_zoom(self.panel_on_focus) |
---|
2397 | |
---|
2398 | def enable_zoom_in(self): |
---|
2399 | """ |
---|
2400 | zoom in |
---|
2401 | """ |
---|
2402 | if self.cpanel_on_focus is not None: |
---|
2403 | self._toolbar.enable_zoom_in(self.panel_on_focus) |
---|
2404 | |
---|
2405 | def enable_zoom_out(self): |
---|
2406 | """ |
---|
2407 | zoom out |
---|
2408 | """ |
---|
2409 | if self.cpanel_on_focus is not None: |
---|
2410 | self._toolbar.enable_zoom_out(self.panel_on_focus) |
---|
2411 | |
---|
2412 | def enable_drag(self, event=None): |
---|
2413 | """ |
---|
2414 | drag |
---|
2415 | """ |
---|
2416 | if self.cpanel_on_focus is not None: |
---|
2417 | self._toolbar.enable_drag(self.panel_on_focus) |
---|
2418 | |
---|
2419 | def enable_reset(self): |
---|
2420 | """ |
---|
2421 | reset the current panel |
---|
2422 | """ |
---|
2423 | if self.cpanel_on_focus is not None: |
---|
2424 | self._toolbar.enable_reset(self.panel_on_focus) |
---|
2425 | |
---|
2426 | def set_schedule_full_draw(self, panel=None, func='del'): |
---|
2427 | """ |
---|
2428 | Add/subtract the schedule full draw list with the panel given |
---|
2429 | |
---|
2430 | :param panel: plot panel |
---|
2431 | :param func: append or del [string] |
---|
2432 | """ |
---|
2433 | |
---|
2434 | # append this panel in the schedule list if not in yet |
---|
2435 | if func == 'append': |
---|
2436 | if not panel in self.schedule_full_draw_list: |
---|
2437 | self.schedule_full_draw_list.append(panel) |
---|
2438 | # remove this panel from schedule list |
---|
2439 | elif func == 'del': |
---|
2440 | if len(self.schedule_full_draw_list) > 0: |
---|
2441 | if panel in self.schedule_full_draw_list: |
---|
2442 | self.schedule_full_draw_list.remove(panel) |
---|
2443 | |
---|
2444 | # reset the schdule |
---|
2445 | if len(self.schedule_full_draw_list) == 0: |
---|
2446 | self.schedule = False |
---|
2447 | else: |
---|
2448 | self.schedule = True |
---|
2449 | |
---|
2450 | def full_draw(self): |
---|
2451 | """ |
---|
2452 | Draw the panels with axes in the schedule to full dwar list |
---|
2453 | """ |
---|
2454 | count = len(self.schedule_full_draw_list) |
---|
2455 | #if not self.schedule: |
---|
2456 | if count < 1: |
---|
2457 | self.set_schedule(False) |
---|
2458 | return |
---|
2459 | else: |
---|
2460 | ind = 0 |
---|
2461 | # if any of the panel is shown do full_draw |
---|
2462 | for panel in self.schedule_full_draw_list: |
---|
2463 | ind += 1 |
---|
2464 | if self._mgr.GetPane(panel.window_name).IsShown(): |
---|
2465 | break |
---|
2466 | # otherwise, return |
---|
2467 | if ind == count: |
---|
2468 | return |
---|
2469 | |
---|
2470 | #Simple redraw only for a panel shown |
---|
2471 | def f_draw(panel): |
---|
2472 | """ |
---|
2473 | Draw A panel in the full dwar list |
---|
2474 | """ |
---|
2475 | try: |
---|
2476 | # This checking of GetCapture is to stop redrawing |
---|
2477 | # while any panel is capture. |
---|
2478 | if self.GetCapture() == None: |
---|
2479 | # draw if possible |
---|
2480 | panel.set_resizing(False) |
---|
2481 | panel.Show(False) |
---|
2482 | panel.draw_plot() |
---|
2483 | |
---|
2484 | # Check if the panel is not shown |
---|
2485 | if not self._mgr.GetPane(panel.window_name).IsShown(): |
---|
2486 | self._mgr.GetPane(panel.window_name).Hide() |
---|
2487 | else: |
---|
2488 | panel.Show(True) |
---|
2489 | except: |
---|
2490 | pass |
---|
2491 | #print self.callback,self.schedule,self.schedule_full_draw_list |
---|
2492 | |
---|
2493 | # Draw all panels |
---|
2494 | map(f_draw, self.schedule_full_draw_list) |
---|
2495 | |
---|
2496 | # Reset the attr |
---|
2497 | if len(self.schedule_full_draw_list) == 0: |
---|
2498 | self.set_schedule(False) |
---|
2499 | else: |
---|
2500 | self.set_schedule(True) |
---|
2501 | # do not update mgr |
---|
2502 | #self._mgr.Update() |
---|
2503 | |
---|
2504 | def set_schedule(self, schedule=False): |
---|
2505 | """ |
---|
2506 | Set schedule |
---|
2507 | """ |
---|
2508 | self.schedule = schedule |
---|
2509 | |
---|
2510 | def get_schedule(self): |
---|
2511 | """ |
---|
2512 | Get schedule |
---|
2513 | """ |
---|
2514 | return self.schedule |
---|
2515 | |
---|
2516 | def on_set_plot_focus(self, panel): |
---|
2517 | """ |
---|
2518 | Set focus on a plot panel |
---|
2519 | """ |
---|
2520 | self.set_plot_unfocus() |
---|
2521 | panel.on_set_focus(None) |
---|
2522 | # set focusing panel |
---|
2523 | self.panel_on_focus = panel |
---|
2524 | self.set_panel_on_focus(None) |
---|
2525 | |
---|
2526 | def set_plot_unfocus(self): |
---|
2527 | """ |
---|
2528 | Un focus all plot panels |
---|
2529 | """ |
---|
2530 | for plot in self.plot_panels.values(): |
---|
2531 | plot.on_kill_focus(None) |
---|
2532 | |
---|
2533 | def _onDrawIdle(self, *args, **kwargs): |
---|
2534 | """ |
---|
2535 | ReDraw with axes |
---|
2536 | """ |
---|
2537 | try: |
---|
2538 | # check if it is time to redraw |
---|
2539 | if self.GetCapture() == None: |
---|
2540 | # Draw plot, changes resizing too |
---|
2541 | self.full_draw() |
---|
2542 | except: |
---|
2543 | pass |
---|
2544 | |
---|
2545 | # restart idle |
---|
2546 | self._redraw_idle(*args, **kwargs) |
---|
2547 | |
---|
2548 | |
---|
2549 | def _redraw_idle(self, *args, **kwargs): |
---|
2550 | """ |
---|
2551 | Restart Idle |
---|
2552 | """ |
---|
2553 | # restart idle |
---|
2554 | self.idletimer.Restart(55, *args, **kwargs) |
---|
2555 | |
---|
2556 | |
---|
2557 | class DefaultPanel(wx.Panel, PanelBase): |
---|
2558 | """ |
---|
2559 | Defines the API for a panels to work with |
---|
2560 | the GUI manager |
---|
2561 | """ |
---|
2562 | ## Internal nickname for the window, used by the AUI manager |
---|
2563 | window_name = "default" |
---|
2564 | ## Name to appear on the window title bar |
---|
2565 | window_caption = "Welcome panel" |
---|
2566 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
2567 | CENTER_PANE = True |
---|
2568 | def __init__(self, parent, *args, **kwds): |
---|
2569 | wx.Panel.__init__(self, parent, *args, **kwds) |
---|
2570 | PanelBase.__init__(self, parent) |
---|
2571 | |
---|
2572 | |
---|
2573 | |
---|
2574 | # Toy application to test this Frame |
---|
2575 | class ViewApp(wx.App): |
---|
2576 | """ |
---|
2577 | """ |
---|
2578 | def OnInit(self): |
---|
2579 | """ |
---|
2580 | """ |
---|
2581 | pos, size = self.window_placement((GUIFRAME_WIDTH, GUIFRAME_HEIGHT)) |
---|
2582 | self.frame = ViewerFrame(parent=None, |
---|
2583 | title=APPLICATION_NAME, |
---|
2584 | pos=pos, |
---|
2585 | gui_style = DEFAULT_STYLE, |
---|
2586 | size=size) |
---|
2587 | self.frame.Hide() |
---|
2588 | self.s_screen = None |
---|
2589 | temp_path = None |
---|
2590 | try: |
---|
2591 | # make sure the current dir is App dir when it starts |
---|
2592 | temp_path = os.path.dirname(sys.path[0]) |
---|
2593 | os.chdir(temp_path) |
---|
2594 | except: |
---|
2595 | pass |
---|
2596 | try: |
---|
2597 | self.open_file() |
---|
2598 | except: |
---|
2599 | msg = "%s Could not load " % str(APPLICATION_NAME) |
---|
2600 | msg += "input file from command line.\n" |
---|
2601 | logging.error(msg) |
---|
2602 | # Display a splash screen on top of the frame. |
---|
2603 | if len(sys.argv) > 1 and '--time' in sys.argv[1:]: |
---|
2604 | log_time("Starting to display the splash screen") |
---|
2605 | try: |
---|
2606 | if os.path.isfile(SPLASH_SCREEN_PATH): |
---|
2607 | self.s_screen = self.display_splash_screen(parent=self.frame, |
---|
2608 | path=SPLASH_SCREEN_PATH) |
---|
2609 | else: |
---|
2610 | self.frame.Show() |
---|
2611 | except: |
---|
2612 | if self.s_screen is not None: |
---|
2613 | self.s_screen.Close() |
---|
2614 | msg = "Cannot display splash screen\n" |
---|
2615 | msg += str (sys.exc_value) |
---|
2616 | logging.error(msg) |
---|
2617 | self.frame.Show() |
---|
2618 | |
---|
2619 | if hasattr(self.frame, 'special'): |
---|
2620 | self.frame.special.SetCurrent() |
---|
2621 | self.SetTopWindow(self.frame) |
---|
2622 | |
---|
2623 | return True |
---|
2624 | |
---|
2625 | def open_file(self): |
---|
2626 | """ |
---|
2627 | open a state file at the start of the application |
---|
2628 | """ |
---|
2629 | input_file = None |
---|
2630 | if len(sys.argv) >= 2: |
---|
2631 | cmd = sys.argv[0].lower() |
---|
2632 | basename = os.path.basename(cmd) |
---|
2633 | app_base = str(APPLICATION_NAME).lower() |
---|
2634 | if os.path.isfile(cmd) or basename.lower() == app_base: |
---|
2635 | app_py = app_base + '.py' |
---|
2636 | app_exe = app_base + '.exe' |
---|
2637 | app_app = app_base + '.app' |
---|
2638 | if basename.lower() in [app_py, app_exe, app_app, app_base]: |
---|
2639 | data_base = sys.argv[1] |
---|
2640 | input_file = os.path.normpath(os.path.join(DATAPATH, |
---|
2641 | data_base)) |
---|
2642 | if input_file is None: |
---|
2643 | return |
---|
2644 | if self.frame is not None: |
---|
2645 | self.frame.set_input_file(input_file=input_file) |
---|
2646 | |
---|
2647 | |
---|
2648 | def set_manager(self, manager): |
---|
2649 | """ |
---|
2650 | Sets a reference to the application manager |
---|
2651 | of the GUI manager (Frame) |
---|
2652 | """ |
---|
2653 | self.frame.set_manager(manager) |
---|
2654 | |
---|
2655 | def build_gui(self): |
---|
2656 | """ |
---|
2657 | Build the GUI |
---|
2658 | """ |
---|
2659 | #try to load file at the start |
---|
2660 | try: |
---|
2661 | self.open_file() |
---|
2662 | except: |
---|
2663 | raise |
---|
2664 | self.frame.build_gui() |
---|
2665 | #if self.s_screen is not None and self.s_screen.IsShown(): |
---|
2666 | # self.s_screen.Close() |
---|
2667 | |
---|
2668 | def set_welcome_panel(self, panel_class): |
---|
2669 | """ |
---|
2670 | Set the welcome panel |
---|
2671 | |
---|
2672 | :param panel_class: class of the welcome panel to be instantiated |
---|
2673 | |
---|
2674 | """ |
---|
2675 | self.frame.set_welcome_panel(panel_class) |
---|
2676 | |
---|
2677 | def add_perspective(self, perspective): |
---|
2678 | """ |
---|
2679 | Manually add a perspective to the application GUI |
---|
2680 | """ |
---|
2681 | self.frame.add_perspective(perspective) |
---|
2682 | |
---|
2683 | def window_placement(self, size): |
---|
2684 | """ |
---|
2685 | Determines the position and size of the application frame such that it |
---|
2686 | fits on the user's screen without obstructing (or being obstructed by) |
---|
2687 | the Windows task bar. The maximum initial size in pixels is bounded by |
---|
2688 | WIDTH x HEIGHT. For most monitors, the application |
---|
2689 | will be centered on the screen; for very large monitors it will be |
---|
2690 | placed on the left side of the screen. |
---|
2691 | """ |
---|
2692 | window_width, window_height = size |
---|
2693 | screen_size = wx.GetDisplaySize() |
---|
2694 | window_height = window_height if screen_size[1]>window_height else screen_size[1]-10 |
---|
2695 | window_width = window_width if screen_size[0]> window_width else screen_size[0]-10 |
---|
2696 | xpos = ypos = 0 |
---|
2697 | |
---|
2698 | # Note that when running Linux and using an Xming (X11) server on a PC |
---|
2699 | # with a dual monitor configuration, the reported display size may be |
---|
2700 | # that of both monitors combined with an incorrect display count of 1. |
---|
2701 | # To avoid displaying this app across both monitors, we check for |
---|
2702 | # screen 'too big'. If so, we assume a smaller width which means the |
---|
2703 | # application will be placed towards the left hand side of the screen. |
---|
2704 | |
---|
2705 | _, _, x, y = wx.Display().GetClientArea() # size excludes task bar |
---|
2706 | if len(sys.argv) > 1 and '--platform' in sys.argv[1:]: |
---|
2707 | w, h = wx.DisplaySize() # size includes task bar area |
---|
2708 | # display on left side, not centered on screen |
---|
2709 | if x > 1920 and x > (2*y): x = x / 2 |
---|
2710 | if x > window_width: xpos = (x - window_width)/2 |
---|
2711 | if y > window_height: ypos = (y - window_height)/2 |
---|
2712 | |
---|
2713 | # Return the suggested position and size for the application frame. |
---|
2714 | return (xpos, ypos), (min(x, window_width), min(y, window_height)) |
---|
2715 | |
---|
2716 | def display_splash_screen(self, parent, |
---|
2717 | path=SPLASH_SCREEN_PATH): |
---|
2718 | """Displays the splash screen. It will exactly cover the main frame.""" |
---|
2719 | |
---|
2720 | # Prepare the picture. On a 2GHz intel cpu, this takes about a second. |
---|
2721 | x, y = parent.GetSizeTuple() |
---|
2722 | image = wx.Image(path, wx.BITMAP_TYPE_PNG) |
---|
2723 | image.Rescale(SPLASH_SCREEN_WIDTH, |
---|
2724 | SPLASH_SCREEN_HEIGHT, wx.IMAGE_QUALITY_HIGH) |
---|
2725 | bm = image.ConvertToBitmap() |
---|
2726 | |
---|
2727 | # Create and show the splash screen. It will disappear only when the |
---|
2728 | # program has entered the event loop AND either the timeout has expired |
---|
2729 | # or the user has left clicked on the screen. Thus any processing |
---|
2730 | # performed in this routine (including sleeping) or processing in the |
---|
2731 | # calling routine (including doing imports) will prevent the splash |
---|
2732 | # screen from disappearing. |
---|
2733 | # |
---|
2734 | # Note that on Linux, the timeout appears to occur immediately in which |
---|
2735 | # case the splash screen disappears upon entering the event loop. |
---|
2736 | s_screen = wx.SplashScreen(bitmap=bm, |
---|
2737 | splashStyle=(wx.SPLASH_TIMEOUT| |
---|
2738 | wx.SPLASH_CENTRE_ON_SCREEN), |
---|
2739 | style=(wx.SIMPLE_BORDER| |
---|
2740 | wx.FRAME_NO_TASKBAR| |
---|
2741 | wx.STAY_ON_TOP), |
---|
2742 | |
---|
2743 | milliseconds=SS_MAX_DISPLAY_TIME, |
---|
2744 | parent=parent, |
---|
2745 | id=wx.ID_ANY) |
---|
2746 | from gui_statusbar import SPageStatusbar |
---|
2747 | statusBar = SPageStatusbar(s_screen) |
---|
2748 | s_screen.SetStatusBar(statusBar) |
---|
2749 | s_screen.Bind(wx.EVT_CLOSE, self.on_close_splash_screen) |
---|
2750 | s_screen.Show() |
---|
2751 | return s_screen |
---|
2752 | |
---|
2753 | |
---|
2754 | def on_close_splash_screen(self, event): |
---|
2755 | """ |
---|
2756 | """ |
---|
2757 | self.frame.Show(True) |
---|
2758 | event.Skip() |
---|
2759 | |
---|
2760 | if __name__ == "__main__": |
---|
2761 | app = ViewApp(0) |
---|
2762 | app.MainLoop() |
---|
2763 | |
---|
2764 | |
---|