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