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