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