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