[f53cd30] | 1 | """ |
---|
| 2 | Gui manager: manages the widgets making up an application |
---|
| 3 | """ |
---|
| 4 | ################################################################################ |
---|
| 5 | #This software was developed by the University of Tennessee as part of the |
---|
| 6 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
[091e71a2] | 7 | #project funded by the US National Science Foundation. |
---|
[f53cd30] | 8 | # |
---|
| 9 | #See the license text in license.txtz |
---|
| 10 | # |
---|
| 11 | #copyright 2008, University of Tennessee |
---|
| 12 | ################################################################################ |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | import wx |
---|
| 16 | import wx.aui |
---|
| 17 | import os |
---|
| 18 | import sys |
---|
| 19 | import time |
---|
| 20 | import imp |
---|
| 21 | import warnings |
---|
| 22 | import re |
---|
| 23 | warnings.simplefilter("ignore") |
---|
| 24 | import logging |
---|
| 25 | import httplib |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | from sas.guiframe.events import EVT_CATEGORY |
---|
| 29 | from sas.guiframe.events import EVT_STATUS |
---|
| 30 | from sas.guiframe.events import EVT_APPEND_BOOKMARK |
---|
| 31 | from sas.guiframe.events import EVT_PANEL_ON_FOCUS |
---|
| 32 | from sas.guiframe.events import EVT_NEW_LOAD_DATA |
---|
| 33 | from sas.guiframe.events import EVT_NEW_COLOR |
---|
| 34 | from sas.guiframe.events import StatusEvent |
---|
| 35 | from sas.guiframe.events import NewPlotEvent |
---|
| 36 | from sas.guiframe.gui_style import GUIFRAME |
---|
| 37 | from sas.guiframe.gui_style import GUIFRAME_ID |
---|
| 38 | from sas.guiframe.data_panel import DataPanel |
---|
| 39 | from sas.guiframe.panel_base import PanelBase |
---|
| 40 | from sas.guiframe.gui_toolbar import GUIToolBar |
---|
| 41 | from sas.guiframe.data_processor import GridFrame |
---|
| 42 | from sas.guiframe.events import EVT_NEW_BATCH |
---|
| 43 | from sas.guiframe.CategoryManager import CategoryManager |
---|
| 44 | from sas.dataloader.loader import Loader |
---|
| 45 | from matplotlib import _pylab_helpers |
---|
| 46 | |
---|
| 47 | def get_app_dir(): |
---|
| 48 | """ |
---|
| 49 | The application directory is the one where the default custom_config.py |
---|
| 50 | file resides. |
---|
| 51 | """ |
---|
| 52 | # First, try the directory of the executable we are running |
---|
| 53 | app_path = sys.path[0] |
---|
| 54 | if os.path.isfile(app_path): |
---|
| 55 | app_path = os.path.dirname(app_path) |
---|
| 56 | if os.path.isfile(os.path.join(app_path, "custom_config.py")): |
---|
| 57 | app_path = os.path.abspath(app_path) |
---|
| 58 | logging.info("Using application path: %s", app_path) |
---|
| 59 | return app_path |
---|
[091e71a2] | 60 | |
---|
[f53cd30] | 61 | # Next, try the current working directory |
---|
| 62 | if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")): |
---|
| 63 | logging.info("Using application path: %s", os.getcwd()) |
---|
| 64 | return os.path.abspath(os.getcwd()) |
---|
[091e71a2] | 65 | |
---|
[f53cd30] | 66 | # Finally, try the directory of the sasview module |
---|
| 67 | #TODO: gui_manager will have to know about sasview until we |
---|
| 68 | # clean all these module variables and put them into a config class |
---|
| 69 | # that can be passed by sasview.py. |
---|
| 70 | logging.info(sys.executable) |
---|
| 71 | logging.info(str(sys.argv)) |
---|
| 72 | from sas import sasview as sasview |
---|
| 73 | app_path = os.path.dirname(sasview.__file__) |
---|
| 74 | logging.info("Using application path: %s", app_path) |
---|
| 75 | return app_path |
---|
| 76 | |
---|
| 77 | def get_user_directory(): |
---|
| 78 | """ |
---|
| 79 | Returns the user's home directory |
---|
| 80 | """ |
---|
[091e71a2] | 81 | userdir = os.path.join(os.path.expanduser("~"), ".sasview") |
---|
[f53cd30] | 82 | if not os.path.isdir(userdir): |
---|
| 83 | os.makedirs(userdir) |
---|
| 84 | return userdir |
---|
[091e71a2] | 85 | |
---|
[f53cd30] | 86 | def _find_local_config(file, path): |
---|
| 87 | """ |
---|
| 88 | Find configuration file for the current application |
---|
[091e71a2] | 89 | """ |
---|
[f53cd30] | 90 | config_module = None |
---|
| 91 | fObj = None |
---|
| 92 | try: |
---|
| 93 | fObj, path_config, descr = imp.find_module(file, [path]) |
---|
[091e71a2] | 94 | config_module = imp.load_module(file, fObj, path_config, descr) |
---|
[f53cd30] | 95 | except: |
---|
| 96 | logging.error("Error loading %s/%s: %s" % (path, file, sys.exc_value)) |
---|
| 97 | finally: |
---|
| 98 | if fObj is not None: |
---|
| 99 | fObj.close() |
---|
| 100 | logging.info("GuiManager loaded %s/%s" % (path, file)) |
---|
| 101 | return config_module |
---|
| 102 | |
---|
| 103 | # Get APP folder |
---|
[091e71a2] | 104 | PATH_APP = get_app_dir() |
---|
[f53cd30] | 105 | DATAPATH = PATH_APP |
---|
| 106 | |
---|
[091e71a2] | 107 | # GUI always starts from the App folder |
---|
[f53cd30] | 108 | #os.chdir(PATH_APP) |
---|
| 109 | # Read in the local config, which can either be with the main |
---|
| 110 | # application or in the installation directory |
---|
| 111 | config = _find_local_config('local_config', PATH_APP) |
---|
| 112 | if config is None: |
---|
| 113 | config = _find_local_config('local_config', os.getcwd()) |
---|
| 114 | if config is None: |
---|
[091e71a2] | 115 | # Didn't find local config, load the default |
---|
[f53cd30] | 116 | import sas.guiframe.config as config |
---|
[091e71a2] | 117 | logging.info("using default local_config") |
---|
[f53cd30] | 118 | else: |
---|
[091e71a2] | 119 | logging.info("found local_config in %s" % os.getcwd()) |
---|
[f53cd30] | 120 | else: |
---|
[091e71a2] | 121 | logging.info("found local_config in %s" % PATH_APP) |
---|
| 122 | |
---|
[f53cd30] | 123 | from sas.guiframe.customdir import SetupCustom |
---|
| 124 | c_conf_dir = SetupCustom().setup_dir(PATH_APP) |
---|
| 125 | custom_config = _find_local_config('custom_config', c_conf_dir) |
---|
| 126 | if custom_config is None: |
---|
| 127 | custom_config = _find_local_config('custom_config', os.getcwd()) |
---|
| 128 | if custom_config is None: |
---|
| 129 | msgConfig = "Custom_config file was not imported" |
---|
| 130 | logging.info(msgConfig) |
---|
| 131 | else: |
---|
| 132 | logging.info("using custom_config in %s" % os.getcwd()) |
---|
| 133 | else: |
---|
| 134 | logging.info("using custom_config from %s" % c_conf_dir) |
---|
| 135 | |
---|
| 136 | #read some constants from config |
---|
| 137 | APPLICATION_STATE_EXTENSION = config.APPLICATION_STATE_EXTENSION |
---|
| 138 | APPLICATION_NAME = config.__appname__ |
---|
| 139 | SPLASH_SCREEN_PATH = config.SPLASH_SCREEN_PATH |
---|
| 140 | WELCOME_PANEL_ON = config.WELCOME_PANEL_ON |
---|
| 141 | SPLASH_SCREEN_WIDTH = config.SPLASH_SCREEN_WIDTH |
---|
| 142 | SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT |
---|
| 143 | SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME |
---|
| 144 | if not WELCOME_PANEL_ON: |
---|
| 145 | WELCOME_PANEL_SHOW = False |
---|
| 146 | else: |
---|
| 147 | WELCOME_PANEL_SHOW = True |
---|
| 148 | try: |
---|
| 149 | DATALOADER_SHOW = custom_config.DATALOADER_SHOW |
---|
| 150 | TOOLBAR_SHOW = custom_config.TOOLBAR_SHOW |
---|
| 151 | FIXED_PANEL = custom_config.FIXED_PANEL |
---|
| 152 | if WELCOME_PANEL_ON: |
---|
| 153 | WELCOME_PANEL_SHOW = custom_config.WELCOME_PANEL_SHOW |
---|
| 154 | PLOPANEL_WIDTH = custom_config.PLOPANEL_WIDTH |
---|
| 155 | DATAPANEL_WIDTH = custom_config.DATAPANEL_WIDTH |
---|
[091e71a2] | 156 | GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH |
---|
[f53cd30] | 157 | GUIFRAME_HEIGHT = custom_config.GUIFRAME_HEIGHT |
---|
[091e71a2] | 158 | CONTROL_WIDTH = custom_config.CONTROL_WIDTH |
---|
[f53cd30] | 159 | CONTROL_HEIGHT = custom_config.CONTROL_HEIGHT |
---|
| 160 | DEFAULT_PERSPECTIVE = custom_config.DEFAULT_PERSPECTIVE |
---|
| 161 | CLEANUP_PLOT = custom_config.CLEANUP_PLOT |
---|
| 162 | # custom open_path |
---|
| 163 | open_folder = custom_config.DEFAULT_OPEN_FOLDER |
---|
| 164 | if open_folder != None and os.path.isdir(open_folder): |
---|
| 165 | DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) |
---|
| 166 | else: |
---|
| 167 | DEFAULT_OPEN_FOLDER = PATH_APP |
---|
| 168 | except: |
---|
| 169 | DATALOADER_SHOW = True |
---|
| 170 | TOOLBAR_SHOW = True |
---|
| 171 | FIXED_PANEL = True |
---|
| 172 | WELCOME_PANEL_SHOW = False |
---|
| 173 | PLOPANEL_WIDTH = config.PLOPANEL_WIDTH |
---|
| 174 | DATAPANEL_WIDTH = config.DATAPANEL_WIDTH |
---|
[091e71a2] | 175 | GUIFRAME_WIDTH = config.GUIFRAME_WIDTH |
---|
[f53cd30] | 176 | GUIFRAME_HEIGHT = config.GUIFRAME_HEIGHT |
---|
[091e71a2] | 177 | CONTROL_WIDTH = -1 |
---|
[f53cd30] | 178 | CONTROL_HEIGHT = -1 |
---|
| 179 | DEFAULT_PERSPECTIVE = None |
---|
| 180 | CLEANUP_PLOT = False |
---|
| 181 | DEFAULT_OPEN_FOLDER = PATH_APP |
---|
| 182 | |
---|
| 183 | DEFAULT_STYLE = config.DEFAULT_STYLE |
---|
| 184 | |
---|
[091e71a2] | 185 | PLUGIN_STATE_EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS |
---|
[f53cd30] | 186 | OPEN_SAVE_MENU = config.OPEN_SAVE_PROJECT_MENU |
---|
| 187 | VIEW_MENU = config.VIEW_MENU |
---|
| 188 | EDIT_MENU = config.EDIT_MENU |
---|
| 189 | extension_list = [] |
---|
| 190 | if APPLICATION_STATE_EXTENSION is not None: |
---|
| 191 | extension_list.append(APPLICATION_STATE_EXTENSION) |
---|
| 192 | EXTENSIONS = PLUGIN_STATE_EXTENSIONS + extension_list |
---|
| 193 | try: |
---|
| 194 | PLUGINS_WLIST = '|'.join(config.PLUGINS_WLIST) |
---|
| 195 | except: |
---|
| 196 | PLUGINS_WLIST = '' |
---|
| 197 | APPLICATION_WLIST = config.APPLICATION_WLIST |
---|
| 198 | IS_WIN = True |
---|
| 199 | IS_LINUX = False |
---|
| 200 | CLOSE_SHOW = True |
---|
| 201 | TIME_FACTOR = 2 |
---|
| 202 | MDI_STYLE = wx.DEFAULT_FRAME_STYLE |
---|
| 203 | NOT_SO_GRAPH_LIST = ["BoxSum"] |
---|
| 204 | PARENT_FRAME = wx.MDIParentFrame |
---|
| 205 | CHILD_FRAME = wx.MDIChildFrame |
---|
| 206 | if sys.platform.count("win32") < 1: |
---|
| 207 | IS_WIN = False |
---|
| 208 | TIME_FACTOR = 2 |
---|
| 209 | if int(str(wx.__version__).split('.')[0]) == 2: |
---|
| 210 | if int(str(wx.__version__).split('.')[1]) < 9: |
---|
| 211 | CLOSE_SHOW = False |
---|
| 212 | if sys.platform.count("darwin") < 1: |
---|
| 213 | IS_LINUX = True |
---|
| 214 | PARENT_FRAME = wx.Frame |
---|
| 215 | CHILD_FRAME = wx.Frame |
---|
[091e71a2] | 216 | |
---|
[f53cd30] | 217 | class ViewerFrame(PARENT_FRAME): |
---|
| 218 | """ |
---|
| 219 | Main application frame |
---|
| 220 | """ |
---|
[091e71a2] | 221 | |
---|
| 222 | def __init__(self, parent, title, |
---|
[f53cd30] | 223 | size=(GUIFRAME_WIDTH, GUIFRAME_HEIGHT), |
---|
[091e71a2] | 224 | gui_style=DEFAULT_STYLE, |
---|
[f53cd30] | 225 | style=wx.DEFAULT_FRAME_STYLE, |
---|
| 226 | pos=wx.DefaultPosition): |
---|
| 227 | """ |
---|
| 228 | Initialize the Frame object |
---|
| 229 | """ |
---|
| 230 | |
---|
| 231 | PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size) |
---|
| 232 | # title |
---|
| 233 | self.title = title |
---|
[091e71a2] | 234 | self.__gui_style = gui_style |
---|
[f53cd30] | 235 | path = os.path.dirname(__file__) |
---|
[091e71a2] | 236 | temp_path = os.path.join(path, 'images') |
---|
| 237 | ico_file = os.path.join(temp_path, 'ball.ico') |
---|
[f53cd30] | 238 | if os.path.isfile(ico_file): |
---|
| 239 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
| 240 | else: |
---|
[091e71a2] | 241 | temp_path = os.path.join(os.getcwd(), 'images') |
---|
| 242 | ico_file = os.path.join(temp_path, 'ball.ico') |
---|
[f53cd30] | 243 | if os.path.isfile(ico_file): |
---|
| 244 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
| 245 | else: |
---|
| 246 | ico_file = os.path.join(os.path.dirname(os.path.sys.path[0]), |
---|
[091e71a2] | 247 | 'images', 'ball.ico') |
---|
[f53cd30] | 248 | if os.path.isfile(ico_file): |
---|
| 249 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
| 250 | self.path = PATH_APP |
---|
[091e71a2] | 251 | self.application_name = APPLICATION_NAME |
---|
[f53cd30] | 252 | ## Application manager |
---|
| 253 | self._input_file = None |
---|
| 254 | self.app_manager = None |
---|
| 255 | self._mgr = None |
---|
| 256 | #add current perpsective |
---|
| 257 | self._current_perspective = None |
---|
| 258 | self._plotting_plugin = None |
---|
| 259 | self._data_plugin = None |
---|
| 260 | #Menu bar and item |
---|
| 261 | self._menubar = None |
---|
| 262 | self._file_menu = None |
---|
| 263 | self._data_menu = None |
---|
| 264 | self._view_menu = None |
---|
| 265 | self._data_panel_menu = None |
---|
| 266 | self._help_menu = None |
---|
| 267 | self._tool_menu = None |
---|
| 268 | self._applications_menu_pos = -1 |
---|
| 269 | self._applications_menu_name = None |
---|
| 270 | self._applications_menu = None |
---|
| 271 | self._edit_menu = None |
---|
| 272 | self._toolbar_menu = None |
---|
| 273 | self._save_appl_menu = None |
---|
| 274 | #tool bar |
---|
| 275 | self._toolbar = None |
---|
| 276 | # Status bar |
---|
| 277 | self.sb = None |
---|
| 278 | # number of plugins |
---|
| 279 | self._num_perspectives = 0 |
---|
| 280 | # plot duck cleanup option |
---|
| 281 | self.cleanup_plots = CLEANUP_PLOT |
---|
| 282 | ## Find plug-ins |
---|
| 283 | # Modify this so that we can specify the directory to look into |
---|
| 284 | self.plugins = [] |
---|
| 285 | #add local plugin |
---|
| 286 | self.plugins += self._get_local_plugins() |
---|
| 287 | self.plugins += self._find_plugins() |
---|
| 288 | ## List of panels |
---|
| 289 | self.panels = {} |
---|
| 290 | # List of plot panels |
---|
| 291 | self.plot_panels = {} |
---|
| 292 | # default Graph number fot the plotpanel caption |
---|
| 293 | self.graph_num = 0 |
---|
| 294 | |
---|
| 295 | # Default locations |
---|
[091e71a2] | 296 | self._default_save_location = DEFAULT_OPEN_FOLDER |
---|
[f53cd30] | 297 | # Welcome panel |
---|
| 298 | self.defaultPanel = None |
---|
| 299 | self.welcome_panel_class = None |
---|
| 300 | #panel on focus |
---|
| 301 | self.panel_on_focus = None |
---|
| 302 | #control_panel on focus |
---|
| 303 | self.cpanel_on_focus = None |
---|
| 304 | |
---|
[091e71a2] | 305 | self.loader = Loader() |
---|
[f53cd30] | 306 | #data manager |
---|
| 307 | self.batch_on = False |
---|
| 308 | from sas.guiframe.data_manager import DataManager |
---|
| 309 | self._data_manager = DataManager() |
---|
| 310 | self._data_panel = None#DataPanel(parent=self) |
---|
| 311 | if self.panel_on_focus is not None: |
---|
[091e71a2] | 312 | self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) |
---|
[f53cd30] | 313 | # list of plot panels in schedule to full redraw |
---|
| 314 | self.schedule = False |
---|
| 315 | #self.callback = True |
---|
| 316 | self._idle_count = 0 |
---|
| 317 | self.schedule_full_draw_list = [] |
---|
| 318 | self.idletimer = wx.CallLater(TIME_FACTOR, self._onDrawIdle) |
---|
[091e71a2] | 319 | |
---|
[f53cd30] | 320 | self.batch_frame = GridFrame(parent=self) |
---|
| 321 | self.batch_frame.Hide() |
---|
| 322 | self.on_batch_selection(event=None) |
---|
| 323 | self.add_icon() |
---|
[091e71a2] | 324 | |
---|
[f53cd30] | 325 | # Register the close event so it calls our own method |
---|
| 326 | wx.EVT_CLOSE(self, self.WindowClose) |
---|
| 327 | # Register to status events |
---|
| 328 | self.Bind(EVT_STATUS, self._on_status_event) |
---|
| 329 | #Register add extra data on the same panel event on load |
---|
| 330 | self.Bind(EVT_PANEL_ON_FOCUS, self.set_panel_on_focus) |
---|
| 331 | self.Bind(EVT_APPEND_BOOKMARK, self.append_bookmark) |
---|
| 332 | self.Bind(EVT_NEW_LOAD_DATA, self.on_load_data) |
---|
| 333 | self.Bind(EVT_NEW_BATCH, self.on_batch_selection) |
---|
| 334 | self.Bind(EVT_NEW_COLOR, self.on_color_selection) |
---|
| 335 | self.Bind(EVT_CATEGORY, self.on_change_categories) |
---|
| 336 | self.setup_custom_conf() |
---|
| 337 | # Preferred window size |
---|
| 338 | self._window_width, self._window_height = size |
---|
[091e71a2] | 339 | |
---|
[f53cd30] | 340 | def add_icon(self): |
---|
| 341 | """ |
---|
[091e71a2] | 342 | get list of child and attempt to add the default icon |
---|
[f53cd30] | 343 | """ |
---|
[091e71a2] | 344 | |
---|
| 345 | list_children = self.GetChildren() |
---|
[f53cd30] | 346 | for frame in list_children: |
---|
| 347 | self.put_icon(frame) |
---|
[091e71a2] | 348 | |
---|
| 349 | def put_icon(self, frame): |
---|
[f53cd30] | 350 | """ |
---|
| 351 | Put icon on the tap of a panel |
---|
| 352 | """ |
---|
| 353 | if hasattr(frame, "IsIconized"): |
---|
| 354 | if not frame.IsIconized(): |
---|
| 355 | try: |
---|
| 356 | icon = self.GetIcon() |
---|
| 357 | frame.SetIcon(icon) |
---|
| 358 | except: |
---|
[091e71a2] | 359 | pass |
---|
| 360 | |
---|
[f53cd30] | 361 | def get_client_size(self): |
---|
| 362 | """ |
---|
| 363 | return client size tuple |
---|
| 364 | """ |
---|
| 365 | width, height = self.GetClientSizeTuple() |
---|
| 366 | height -= 45 |
---|
| 367 | # Adjust toolbar height |
---|
| 368 | toolbar = self.GetToolBar() |
---|
| 369 | if toolbar != None: |
---|
| 370 | _, tb_h = toolbar.GetSizeTuple() |
---|
[091e71a2] | 371 | height -= tb_h |
---|
[f53cd30] | 372 | return width, height |
---|
[091e71a2] | 373 | |
---|
[f53cd30] | 374 | def on_change_categories(self, evt): |
---|
| 375 | # ILL |
---|
| 376 | fitpanel = None |
---|
| 377 | for item in self.plugins: |
---|
| 378 | if hasattr(item, "get_panels"): |
---|
| 379 | if hasattr(item, "fit_panel"): |
---|
| 380 | fitpanel = item.fit_panel |
---|
| 381 | |
---|
| 382 | if fitpanel != None: |
---|
[091e71a2] | 383 | for i in range(0, fitpanel.GetPageCount()): |
---|
[f53cd30] | 384 | fitpanel.GetPage(i)._populate_listbox() |
---|
| 385 | |
---|
| 386 | def on_set_batch_result(self, data_outputs, data_inputs=None, |
---|
[091e71a2] | 387 | plugin_name=""): |
---|
[f53cd30] | 388 | """ |
---|
| 389 | Display data into a grid in batch mode and show the grid |
---|
| 390 | """ |
---|
| 391 | t = time.localtime(time.time()) |
---|
| 392 | time_str = time.strftime("%b %d %H;%M of %Y", t) |
---|
| 393 | details = "File Generated by %s : %s" % (APPLICATION_NAME, |
---|
[091e71a2] | 394 | str(plugin_name)) |
---|
| 395 | details += "on %s.\n" % time_str |
---|
[f53cd30] | 396 | ext = ".csv" |
---|
[091e71a2] | 397 | file_name = "Batch_" + str(plugin_name) + "_" + time_str + ext |
---|
[f53cd30] | 398 | file_name = self._default_save_location + str(file_name) |
---|
[091e71a2] | 399 | |
---|
[f53cd30] | 400 | self.open_with_localapp(file_name=file_name, |
---|
| 401 | details=details, |
---|
| 402 | data_inputs=data_inputs, |
---|
[091e71a2] | 403 | data_outputs=data_outputs) |
---|
| 404 | |
---|
[f53cd30] | 405 | def open_with_localapp(self, data_inputs=None, details="", file_name=None, |
---|
| 406 | data_outputs=None): |
---|
| 407 | """ |
---|
| 408 | Display value of data into the application grid |
---|
| 409 | :param data: dictionary of string and list of items |
---|
| 410 | """ |
---|
[091e71a2] | 411 | self.batch_frame.set_data(data_inputs=data_inputs, |
---|
[f53cd30] | 412 | data_outputs=data_outputs, |
---|
| 413 | details=details, |
---|
| 414 | file_name=file_name) |
---|
| 415 | self.show_batch_frame(None) |
---|
[091e71a2] | 416 | |
---|
[f53cd30] | 417 | def on_read_batch_tofile(self, base): |
---|
| 418 | """ |
---|
| 419 | Open a file dialog , extract the file to read and display values |
---|
| 420 | into a grid |
---|
| 421 | """ |
---|
| 422 | path = None |
---|
| 423 | if self._default_save_location == None: |
---|
| 424 | self._default_save_location = os.getcwd() |
---|
| 425 | wildcard = "(*.csv; *.txt)|*.csv; *.txt" |
---|
[091e71a2] | 426 | dlg = wx.FileDialog(base, |
---|
| 427 | "Choose a file", |
---|
[f53cd30] | 428 | self._default_save_location, "", |
---|
[091e71a2] | 429 | wildcard) |
---|
[f53cd30] | 430 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 431 | path = dlg.GetPath() |
---|
| 432 | if path is not None: |
---|
| 433 | self._default_save_location = os.path.dirname(path) |
---|
| 434 | dlg.Destroy() |
---|
| 435 | try: |
---|
| 436 | self.read_batch_tofile(file_name=path) |
---|
| 437 | except: |
---|
[091e71a2] | 438 | msg = "Error occurred when reading the file; %s\n" % path |
---|
| 439 | msg += "%s\n" % sys.exc_value |
---|
[f53cd30] | 440 | wx.PostEvent(self, StatusEvent(status=msg, |
---|
[091e71a2] | 441 | info="error")) |
---|
| 442 | |
---|
[f53cd30] | 443 | def read_batch_tofile(self, file_name): |
---|
| 444 | """ |
---|
| 445 | Extract value from file name and Display them into a grid |
---|
| 446 | """ |
---|
| 447 | if file_name is None or file_name.strip() == "": |
---|
| 448 | return |
---|
| 449 | data = {} |
---|
| 450 | fd = open(file_name, 'r') |
---|
| 451 | _, ext = os.path.splitext(file_name) |
---|
| 452 | separator = None |
---|
| 453 | if ext.lower() == ".csv": |
---|
| 454 | separator = "," |
---|
[091e71a2] | 455 | fd_buffer = fd.read() |
---|
| 456 | lines = fd_buffer.split('\n') |
---|
[f53cd30] | 457 | fd.close() |
---|
[091e71a2] | 458 | column_names_line = "" |
---|
[f53cd30] | 459 | index = None |
---|
| 460 | details = "" |
---|
| 461 | for index in range(len(lines)): |
---|
| 462 | line = lines[index] |
---|
| 463 | line.strip() |
---|
| 464 | count = 0 |
---|
| 465 | if separator == None: |
---|
| 466 | line.replace('\t', ' ') |
---|
| 467 | #found the first line containing the label |
---|
| 468 | col_name_toks = line.split() |
---|
| 469 | for item in col_name_toks: |
---|
| 470 | if item.strip() != "": |
---|
| 471 | count += 1 |
---|
| 472 | else: |
---|
| 473 | line = " " |
---|
| 474 | elif line.find(separator) != -1: |
---|
| 475 | if line.count(separator) >= 2: |
---|
| 476 | #found the first line containing the label |
---|
| 477 | col_name_toks = line.split(separator) |
---|
| 478 | for item in col_name_toks: |
---|
| 479 | if item.strip() != "": |
---|
| 480 | count += 1 |
---|
| 481 | else: |
---|
| 482 | details += line |
---|
| 483 | if count >= 2: |
---|
| 484 | column_names_line = line |
---|
[091e71a2] | 485 | break |
---|
| 486 | |
---|
[f53cd30] | 487 | if column_names_line.strip() == "" or index is None: |
---|
[091e71a2] | 488 | return |
---|
[f53cd30] | 489 | |
---|
| 490 | col_name_toks = column_names_line.split(separator) |
---|
| 491 | c_index = 0 |
---|
| 492 | for col_index in range(len(col_name_toks)): |
---|
| 493 | c_name = col_name_toks[col_index] |
---|
| 494 | if c_name.strip() != "": |
---|
| 495 | # distinguish between column name and value |
---|
| 496 | try: |
---|
| 497 | float(c_name) |
---|
[091e71a2] | 498 | col_name = "Column %s" % str(col_index + 1) |
---|
[f53cd30] | 499 | index_min = index |
---|
| 500 | except: |
---|
| 501 | col_name = c_name |
---|
| 502 | index_min = index + 1 |
---|
[091e71a2] | 503 | data[col_name] = [lines[row].split(separator)[c_index] |
---|
| 504 | for row in range(index_min, len(lines) - 1)] |
---|
[f53cd30] | 505 | c_index += 1 |
---|
[091e71a2] | 506 | |
---|
[f53cd30] | 507 | self.open_with_localapp(data_outputs=data, data_inputs=None, |
---|
| 508 | file_name=file_name, details=details) |
---|
[091e71a2] | 509 | |
---|
[f53cd30] | 510 | def write_batch_tofile(self, data, file_name, details=""): |
---|
| 511 | """ |
---|
| 512 | Helper to write result from batch into cvs file |
---|
| 513 | """ |
---|
| 514 | self._default_save_location = os.path.dirname(file_name) |
---|
| 515 | name = os.path.basename(file_name) |
---|
| 516 | if data is None or file_name is None or file_name.strip() == "": |
---|
| 517 | return |
---|
| 518 | _, ext = os.path.splitext(name) |
---|
| 519 | try: |
---|
| 520 | fd = open(file_name, 'w') |
---|
| 521 | except: |
---|
| 522 | # On Permission denied: IOError |
---|
| 523 | temp_dir = get_user_directory() |
---|
| 524 | temp_file_name = os.path.join(temp_dir, name) |
---|
| 525 | fd = open(temp_file_name, 'w') |
---|
| 526 | separator = "\t" |
---|
| 527 | if ext.lower() == ".csv": |
---|
| 528 | separator = "," |
---|
| 529 | fd.write(str(details)) |
---|
| 530 | for col_name in data.keys(): |
---|
| 531 | fd.write(str(col_name)) |
---|
| 532 | fd.write(separator) |
---|
| 533 | fd.write('\n') |
---|
| 534 | max_list = [len(value) for value in data.values()] |
---|
| 535 | if len(max_list) == 0: |
---|
| 536 | return |
---|
| 537 | max_index = max(max_list) |
---|
| 538 | index = 0 |
---|
[091e71a2] | 539 | while index < max_index: |
---|
[f53cd30] | 540 | for value_list in data.values(): |
---|
| 541 | if index < len(value_list): |
---|
| 542 | fd.write(str(value_list[index])) |
---|
| 543 | fd.write(separator) |
---|
| 544 | else: |
---|
| 545 | fd.write('') |
---|
| 546 | fd.write(separator) |
---|
| 547 | fd.write('\n') |
---|
| 548 | index += 1 |
---|
| 549 | fd.close() |
---|
[091e71a2] | 550 | |
---|
[f53cd30] | 551 | def open_with_externalapp(self, data, file_name, details=""): |
---|
| 552 | """ |
---|
| 553 | Display data in the another application , by default Excel |
---|
| 554 | """ |
---|
| 555 | if not os.path.exists(file_name): |
---|
| 556 | self.write_batch_tofile(data=data, file_name=file_name, |
---|
[091e71a2] | 557 | details=details) |
---|
[f53cd30] | 558 | try: |
---|
| 559 | from win32com.client import Dispatch |
---|
[091e71a2] | 560 | excel_app = Dispatch('Excel.Application') |
---|
| 561 | excel_app.Workbooks.Open(file_name) |
---|
[f53cd30] | 562 | excel_app.Visible = 1 |
---|
| 563 | except: |
---|
| 564 | msg = "Error occured when calling Excel.\n" |
---|
| 565 | msg += "Check that Excel installed in this machine or \n" |
---|
| 566 | msg += "check that %s really exists.\n" % str(file_name) |
---|
| 567 | wx.PostEvent(self, StatusEvent(status=msg, |
---|
[091e71a2] | 568 | info="error")) |
---|
| 569 | |
---|
[f53cd30] | 570 | def on_batch_selection(self, event=None): |
---|
| 571 | """ |
---|
[ac7be54] | 572 | :param event: contains parameter enable. When enable is set to True |
---|
| 573 | the application is in Batch mode otherwise the application is |
---|
| 574 | in Single mode. |
---|
[f53cd30] | 575 | """ |
---|
| 576 | if event is not None: |
---|
| 577 | self.batch_on = event.enable |
---|
| 578 | for plug in self.plugins: |
---|
| 579 | plug.set_batch_selection(self.batch_on) |
---|
[091e71a2] | 580 | |
---|
[f53cd30] | 581 | def on_color_selection(self, event): |
---|
| 582 | """ |
---|
| 583 | :param event: contains parameters for id and color |
---|
[091e71a2] | 584 | """ |
---|
| 585 | color, event_id = event.color, event.id |
---|
[f53cd30] | 586 | for plug in self.plugins: |
---|
[091e71a2] | 587 | plug.add_color(color, event_id) |
---|
| 588 | |
---|
[f53cd30] | 589 | def setup_custom_conf(self): |
---|
| 590 | """ |
---|
| 591 | Set up custom configuration if exists |
---|
| 592 | """ |
---|
| 593 | if custom_config == None: |
---|
| 594 | return |
---|
[091e71a2] | 595 | |
---|
[f53cd30] | 596 | if not FIXED_PANEL: |
---|
| 597 | self.__gui_style &= (~GUIFRAME.FIXED_PANEL) |
---|
| 598 | self.__gui_style |= GUIFRAME.FLOATING_PANEL |
---|
| 599 | |
---|
| 600 | if not DATALOADER_SHOW: |
---|
| 601 | self.__gui_style &= (~GUIFRAME.MANAGER_ON) |
---|
| 602 | |
---|
| 603 | if not TOOLBAR_SHOW: |
---|
| 604 | self.__gui_style &= (~GUIFRAME.TOOLBAR_ON) |
---|
| 605 | |
---|
| 606 | if WELCOME_PANEL_SHOW: |
---|
[091e71a2] | 607 | self.__gui_style |= GUIFRAME.WELCOME_PANEL_ON |
---|
| 608 | |
---|
[f53cd30] | 609 | def set_custom_default_perspective(self): |
---|
| 610 | """ |
---|
| 611 | Set default starting perspective |
---|
| 612 | """ |
---|
| 613 | if custom_config == None: |
---|
| 614 | return |
---|
| 615 | for plugin in self.plugins: |
---|
| 616 | try: |
---|
| 617 | if plugin.sub_menu == DEFAULT_PERSPECTIVE: |
---|
[091e71a2] | 618 | |
---|
[f53cd30] | 619 | plugin.on_perspective(event=None) |
---|
| 620 | frame = plugin.get_frame() |
---|
| 621 | frame.Show(True) |
---|
| 622 | #break |
---|
| 623 | else: |
---|
| 624 | frame = plugin.get_frame() |
---|
[091e71a2] | 625 | frame.Show(False) |
---|
[f53cd30] | 626 | except: |
---|
[091e71a2] | 627 | pass |
---|
| 628 | return |
---|
| 629 | |
---|
[f53cd30] | 630 | def on_load_data(self, event): |
---|
| 631 | """ |
---|
| 632 | received an event to trigger load from data plugin |
---|
| 633 | """ |
---|
| 634 | if self._data_plugin is not None: |
---|
| 635 | self._data_plugin.load_data(event) |
---|
[091e71a2] | 636 | |
---|
[f53cd30] | 637 | def get_current_perspective(self): |
---|
| 638 | """ |
---|
| 639 | return the current perspective |
---|
| 640 | """ |
---|
| 641 | return self._current_perspective |
---|
| 642 | |
---|
| 643 | def get_save_location(self): |
---|
| 644 | """ |
---|
| 645 | return the _default_save_location |
---|
| 646 | """ |
---|
| 647 | return self._default_save_location |
---|
[091e71a2] | 648 | |
---|
[f53cd30] | 649 | def set_input_file(self, input_file): |
---|
| 650 | """ |
---|
| 651 | :param input_file: file to read |
---|
| 652 | """ |
---|
| 653 | self._input_file = input_file |
---|
[091e71a2] | 654 | |
---|
[f53cd30] | 655 | def get_data_manager(self): |
---|
| 656 | """ |
---|
| 657 | return the data manager. |
---|
| 658 | """ |
---|
| 659 | return self._data_manager |
---|
[091e71a2] | 660 | |
---|
[f53cd30] | 661 | def get_toolbar(self): |
---|
| 662 | """ |
---|
| 663 | return the toolbar. |
---|
| 664 | """ |
---|
| 665 | return self._toolbar |
---|
[091e71a2] | 666 | |
---|
[f53cd30] | 667 | def set_panel_on_focus(self, event): |
---|
| 668 | """ |
---|
| 669 | Store reference to the last panel on focus |
---|
| 670 | update the toolbar if available |
---|
| 671 | update edit menu if available |
---|
| 672 | """ |
---|
| 673 | if event != None: |
---|
| 674 | self.panel_on_focus = event.panel |
---|
| 675 | if self.panel_on_focus is not None: |
---|
| 676 | #Disable save application if the current panel is in batch mode |
---|
| 677 | flag = self.panel_on_focus.get_save_flag() |
---|
| 678 | if self._save_appl_menu != None: |
---|
| 679 | self._save_appl_menu.Enable(flag) |
---|
| 680 | |
---|
| 681 | if self.panel_on_focus not in self.plot_panels.values(): |
---|
| 682 | for ID in self.panels.keys(): |
---|
| 683 | if self.panel_on_focus != self.panels[ID]: |
---|
| 684 | self.panels[ID].on_kill_focus(None) |
---|
| 685 | |
---|
| 686 | if self._data_panel is not None and \ |
---|
| 687 | self.panel_on_focus is not None: |
---|
| 688 | self.set_panel_on_focus_helper() |
---|
| 689 | #update toolbar |
---|
| 690 | self._update_toolbar_helper() |
---|
| 691 | #update edit menu |
---|
| 692 | self.enable_edit_menu() |
---|
| 693 | |
---|
[091e71a2] | 694 | def disable_app_menu(self, p_panel=None): |
---|
[f53cd30] | 695 | """ |
---|
| 696 | Disables all menus in the menubar |
---|
| 697 | """ |
---|
| 698 | return |
---|
[091e71a2] | 699 | |
---|
| 700 | def send_focus_to_datapanel(self, name): |
---|
[f53cd30] | 701 | """ |
---|
| 702 | Send focusing on ID to data explorer |
---|
| 703 | """ |
---|
| 704 | if self._data_panel != None: |
---|
| 705 | self._data_panel.set_panel_on_focus(name) |
---|
[091e71a2] | 706 | |
---|
[f53cd30] | 707 | def set_panel_on_focus_helper(self): |
---|
| 708 | """ |
---|
| 709 | Helper for panel on focus with data_panel |
---|
| 710 | """ |
---|
| 711 | caption = self.panel_on_focus.window_caption |
---|
| 712 | self.send_focus_to_datapanel(caption) |
---|
| 713 | #update combo |
---|
| 714 | if self.panel_on_focus in self.plot_panels.values(): |
---|
| 715 | combo = self._data_panel.cb_plotpanel |
---|
| 716 | combo_title = str(self.panel_on_focus.window_caption) |
---|
| 717 | combo.SetStringSelection(combo_title) |
---|
[091e71a2] | 718 | combo.SetToolTip(wx.ToolTip(combo_title)) |
---|
[f53cd30] | 719 | elif self.panel_on_focus != self._data_panel: |
---|
| 720 | cpanel = self.panel_on_focus |
---|
| 721 | if self.cpanel_on_focus != cpanel: |
---|
| 722 | cpanel.on_tap_focus() |
---|
| 723 | self.cpanel_on_focus = self.panel_on_focus |
---|
[091e71a2] | 724 | |
---|
[f53cd30] | 725 | def reset_bookmark_menu(self, panel): |
---|
| 726 | """ |
---|
| 727 | Reset Bookmark menu list |
---|
[091e71a2] | 728 | |
---|
[f53cd30] | 729 | : param panel: a control panel or tap where the bookmark is |
---|
| 730 | """ |
---|
| 731 | cpanel = panel |
---|
| 732 | if self._toolbar != None and cpanel._bookmark_flag: |
---|
| 733 | for item in self._toolbar.get_bookmark_items(): |
---|
| 734 | self._toolbar.remove_bookmark_item(item) |
---|
| 735 | self._toolbar.add_bookmark_default() |
---|
| 736 | pos = 0 |
---|
| 737 | for bitem in cpanel.popUpMenu.GetMenuItems(): |
---|
| 738 | pos += 1 |
---|
| 739 | if pos < 3: |
---|
| 740 | continue |
---|
[091e71a2] | 741 | id = bitem.GetId() |
---|
[f53cd30] | 742 | label = bitem.GetLabel() |
---|
| 743 | self._toolbar.append_bookmark_item(id, label) |
---|
| 744 | wx.EVT_MENU(self, id, cpanel._back_to_bookmark) |
---|
| 745 | self._toolbar.Realize() |
---|
[091e71a2] | 746 | |
---|
[f53cd30] | 747 | |
---|
| 748 | def build_gui(self): |
---|
| 749 | """ |
---|
| 750 | Build the GUI by setting up the toolbar, menu and layout. |
---|
| 751 | """ |
---|
| 752 | # set tool bar |
---|
| 753 | self._setup_tool_bar() |
---|
| 754 | |
---|
| 755 | # Create the menu bar. To be filled later. |
---|
| 756 | # WX 3.0 needs us to create the menu bar first. |
---|
| 757 | self._menubar = wx.MenuBar() |
---|
| 758 | if wx.VERSION_STRING >= '3.0.0.0': |
---|
| 759 | self.SetMenuBar(self._menubar) |
---|
| 760 | self._add_menu_file() |
---|
| 761 | self._add_menu_edit() |
---|
| 762 | self._add_menu_view() |
---|
| 763 | self._add_menu_tool() |
---|
| 764 | # Set up the layout |
---|
| 765 | self._setup_layout() |
---|
| 766 | self._add_menu_application() |
---|
[091e71a2] | 767 | |
---|
[f53cd30] | 768 | # Set up the menu |
---|
| 769 | self._add_current_plugin_menu() |
---|
| 770 | self._add_help_menu() |
---|
| 771 | # Append item from plugin under menu file if necessary |
---|
| 772 | self._populate_file_menu() |
---|
| 773 | |
---|
| 774 | |
---|
| 775 | if not wx.VERSION_STRING >= '3.0.0.0': |
---|
| 776 | self.SetMenuBar(self._menubar) |
---|
[091e71a2] | 777 | |
---|
[f53cd30] | 778 | try: |
---|
| 779 | self.load_from_cmd(self._input_file) |
---|
| 780 | except: |
---|
[091e71a2] | 781 | msg = "%s Cannot load file %s\n" % (str(APPLICATION_NAME), |
---|
| 782 | str(self._input_file)) |
---|
[f53cd30] | 783 | msg += str(sys.exc_value) + '\n' |
---|
| 784 | logging.error(msg) |
---|
| 785 | if self._data_panel is not None and len(self.plugins) > 0: |
---|
| 786 | self._data_panel.fill_cbox_analysis(self.plugins) |
---|
| 787 | self.post_init() |
---|
| 788 | # Set Custom default |
---|
| 789 | self.set_custom_default_perspective() |
---|
| 790 | # Set up extra custom tool menu |
---|
| 791 | self._setup_extra_custom() |
---|
| 792 | self._check_update(None) |
---|
| 793 | |
---|
[091e71a2] | 794 | def _setup_extra_custom(self): |
---|
[f53cd30] | 795 | """ |
---|
| 796 | Set up toolbar and welcome view if needed |
---|
| 797 | """ |
---|
| 798 | style = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
| 799 | if (style == GUIFRAME.TOOLBAR_ON) & (not self._toolbar.IsShown()): |
---|
[091e71a2] | 800 | self._on_toggle_toolbar() |
---|
| 801 | |
---|
[f53cd30] | 802 | # Set Custom deafult start page |
---|
| 803 | welcome_style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON |
---|
| 804 | if welcome_style == GUIFRAME.WELCOME_PANEL_ON: |
---|
| 805 | self.show_welcome_panel(None) |
---|
[091e71a2] | 806 | |
---|
[f53cd30] | 807 | def _setup_layout(self): |
---|
| 808 | """ |
---|
| 809 | Set up the layout |
---|
| 810 | """ |
---|
| 811 | # Status bar |
---|
| 812 | from sas.guiframe.gui_statusbar import StatusBar |
---|
| 813 | self.sb = StatusBar(self, wx.ID_ANY) |
---|
| 814 | self.SetStatusBar(self.sb) |
---|
| 815 | # Load panels |
---|
| 816 | self._load_panels() |
---|
| 817 | self.set_default_perspective() |
---|
[091e71a2] | 818 | |
---|
[f53cd30] | 819 | def SetStatusText(self, *args, **kwds): |
---|
| 820 | """ |
---|
| 821 | """ |
---|
| 822 | number = self.sb.get_msg_position() |
---|
| 823 | wx.Frame.SetStatusText(self, number=number, *args, **kwds) |
---|
[091e71a2] | 824 | |
---|
[f53cd30] | 825 | def PopStatusText(self, *args, **kwds): |
---|
| 826 | """ |
---|
| 827 | """ |
---|
| 828 | field = self.sb.get_msg_position() |
---|
| 829 | wx.Frame.PopStatusText(self, field=field) |
---|
[091e71a2] | 830 | |
---|
[f53cd30] | 831 | def PushStatusText(self, *args, **kwds): |
---|
| 832 | """ |
---|
[091e71a2] | 833 | FIXME: No message is passed. What is this supposed to do? |
---|
[f53cd30] | 834 | """ |
---|
| 835 | field = self.sb.get_msg_position() |
---|
[091e71a2] | 836 | wx.Frame.PushStatusText(self, field=field, |
---|
| 837 | string="FIXME: PushStatusText called without text") |
---|
[f53cd30] | 838 | |
---|
| 839 | def add_perspective(self, plugin): |
---|
| 840 | """ |
---|
| 841 | Add a perspective if it doesn't already |
---|
| 842 | exist. |
---|
| 843 | """ |
---|
| 844 | self._num_perspectives += 1 |
---|
| 845 | is_loaded = False |
---|
| 846 | for item in self.plugins: |
---|
| 847 | item.set_batch_selection(self.batch_on) |
---|
| 848 | if plugin.__class__ == item.__class__: |
---|
| 849 | msg = "Plugin %s already loaded" % plugin.sub_menu |
---|
| 850 | logging.info(msg) |
---|
[091e71a2] | 851 | is_loaded = True |
---|
[f53cd30] | 852 | if not is_loaded: |
---|
[091e71a2] | 853 | self.plugins.append(plugin) |
---|
[f53cd30] | 854 | msg = "Plugin %s appended" % plugin.sub_menu |
---|
| 855 | logging.info(msg) |
---|
[091e71a2] | 856 | |
---|
[f53cd30] | 857 | def _get_local_plugins(self): |
---|
| 858 | """ |
---|
[091e71a2] | 859 | get plugins local to guiframe and others |
---|
[f53cd30] | 860 | """ |
---|
| 861 | plugins = [] |
---|
| 862 | #import guiframe local plugins |
---|
| 863 | #check if the style contain guiframe.dataloader |
---|
| 864 | style1 = self.__gui_style & GUIFRAME.DATALOADER_ON |
---|
| 865 | style2 = self.__gui_style & GUIFRAME.PLOTTING_ON |
---|
| 866 | if style1 == GUIFRAME.DATALOADER_ON: |
---|
| 867 | try: |
---|
| 868 | from sas.guiframe.local_perspectives.data_loader import data_loader |
---|
| 869 | self._data_plugin = data_loader.Plugin() |
---|
| 870 | plugins.append(self._data_plugin) |
---|
| 871 | except: |
---|
| 872 | msg = "ViewerFrame._get_local_plugins:" |
---|
| 873 | msg += "cannot import dataloader plugin.\n %s" % sys.exc_value |
---|
| 874 | logging.error(msg) |
---|
| 875 | if style2 == GUIFRAME.PLOTTING_ON: |
---|
| 876 | try: |
---|
| 877 | from sas.guiframe.local_perspectives.plotting import plotting |
---|
| 878 | self._plotting_plugin = plotting.Plugin() |
---|
| 879 | plugins.append(self._plotting_plugin) |
---|
| 880 | except: |
---|
| 881 | msg = "ViewerFrame._get_local_plugins:" |
---|
| 882 | msg += "cannot import plotting plugin.\n %s" % sys.exc_value |
---|
| 883 | logging.error(msg) |
---|
[091e71a2] | 884 | |
---|
[f53cd30] | 885 | return plugins |
---|
[091e71a2] | 886 | |
---|
[f53cd30] | 887 | def _find_plugins(self, dir="perspectives"): |
---|
| 888 | """ |
---|
| 889 | Find available perspective plug-ins |
---|
[091e71a2] | 890 | |
---|
[f53cd30] | 891 | :param dir: directory in which to look for plug-ins |
---|
[091e71a2] | 892 | |
---|
[f53cd30] | 893 | :return: list of plug-ins |
---|
[091e71a2] | 894 | |
---|
[f53cd30] | 895 | """ |
---|
| 896 | plugins = [] |
---|
| 897 | # Go through files in panels directory |
---|
| 898 | try: |
---|
[415fb82] | 899 | if os.path.isdir(dir): |
---|
| 900 | file_list = os.listdir(dir) |
---|
| 901 | else: |
---|
| 902 | file_list = [] |
---|
[f53cd30] | 903 | ## the default panel is the panel is the last plugin added |
---|
[091e71a2] | 904 | for item in file_list: |
---|
[f53cd30] | 905 | toks = os.path.splitext(os.path.basename(item)) |
---|
| 906 | name = '' |
---|
| 907 | if not toks[0] == '__init__': |
---|
| 908 | if toks[1] == '.py' or toks[1] == '': |
---|
| 909 | name = toks[0] |
---|
| 910 | #check the validity of the module name parsed |
---|
| 911 | #before trying to import it |
---|
| 912 | if name is None or name.strip() == '': |
---|
| 913 | continue |
---|
| 914 | path = [os.path.abspath(dir)] |
---|
| 915 | file = None |
---|
| 916 | try: |
---|
| 917 | if toks[1] == '': |
---|
| 918 | mod_path = '.'.join([dir, name]) |
---|
| 919 | module = __import__(mod_path, globals(), |
---|
| 920 | locals(), [name]) |
---|
| 921 | else: |
---|
| 922 | (file, path, info) = imp.find_module(name, path) |
---|
[091e71a2] | 923 | module = imp.load_module(name, file, item, info) |
---|
[f53cd30] | 924 | if hasattr(module, "PLUGIN_ID"): |
---|
[091e71a2] | 925 | try: |
---|
[f53cd30] | 926 | plug = module.Plugin() |
---|
| 927 | if plug.set_default_perspective(): |
---|
| 928 | self._current_perspective = plug |
---|
| 929 | plugins.append(plug) |
---|
[091e71a2] | 930 | |
---|
[f53cd30] | 931 | msg = "Found plug-in: %s" % module.PLUGIN_ID |
---|
| 932 | logging.info(msg) |
---|
| 933 | except: |
---|
| 934 | msg = "Error accessing PluginPanel" |
---|
| 935 | msg += " in %s\n %s" % (name, sys.exc_value) |
---|
| 936 | config.printEVT(msg) |
---|
| 937 | except: |
---|
| 938 | msg = "ViewerFrame._find_plugins: %s" % sys.exc_value |
---|
| 939 | logging.error(msg) |
---|
| 940 | finally: |
---|
| 941 | if not file == None: |
---|
| 942 | file.close() |
---|
| 943 | except: |
---|
| 944 | # Should raise and catch at a higher level and |
---|
| 945 | # display error on status bar |
---|
[091e71a2] | 946 | logging.error(sys.exc_value) |
---|
[f53cd30] | 947 | |
---|
| 948 | return plugins |
---|
| 949 | |
---|
| 950 | def _get_panels_size(self, p): |
---|
| 951 | """ |
---|
| 952 | find the proper size of the current panel |
---|
| 953 | get the proper panel width and height |
---|
| 954 | """ |
---|
| 955 | self._window_width, self._window_height = self.get_client_size() |
---|
| 956 | ## Default size |
---|
| 957 | if DATAPANEL_WIDTH < 0: |
---|
| 958 | panel_width = int(self._window_width * 0.25) |
---|
| 959 | else: |
---|
| 960 | panel_width = DATAPANEL_WIDTH |
---|
| 961 | panel_height = int(self._window_height) |
---|
| 962 | if self._data_panel is not None and (p == self._data_panel): |
---|
| 963 | return panel_width, panel_height |
---|
| 964 | if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: |
---|
| 965 | panel_width = self._window_width * 0.45 |
---|
| 966 | if CONTROL_WIDTH > 0: |
---|
| 967 | panel_width = CONTROL_WIDTH |
---|
| 968 | if CONTROL_HEIGHT > 0: |
---|
| 969 | panel_height = CONTROL_HEIGHT |
---|
| 970 | return panel_width, panel_height |
---|
| 971 | elif p == self.defaultPanel: |
---|
| 972 | return self._window_width, panel_height |
---|
| 973 | return panel_width, panel_height |
---|
[091e71a2] | 974 | |
---|
[f53cd30] | 975 | def _load_panels(self): |
---|
| 976 | """ |
---|
| 977 | Load all panels in the panels directory |
---|
| 978 | """ |
---|
| 979 | # Look for plug-in panels |
---|
| 980 | panels = [] |
---|
| 981 | if wx.VERSION_STRING >= '3.0.0.0': |
---|
| 982 | mac_pos_y = 85 |
---|
| 983 | else: |
---|
| 984 | mac_pos_y = 40 |
---|
| 985 | for item in self.plugins: |
---|
| 986 | if hasattr(item, "get_panels"): |
---|
| 987 | ps = item.get_panels(self) |
---|
| 988 | panels.extend(ps) |
---|
[091e71a2] | 989 | |
---|
[f53cd30] | 990 | # Set up welcome panel |
---|
| 991 | #TODO: this needs serious simplification |
---|
| 992 | if self.welcome_panel_class is not None: |
---|
| 993 | welcome_panel = MDIFrame(self, None, 'None', (100, 200)) |
---|
| 994 | self.defaultPanel = self.welcome_panel_class(welcome_panel, -1, style=wx.RAISED_BORDER) |
---|
| 995 | welcome_panel.set_panel(self.defaultPanel) |
---|
| 996 | self.defaultPanel.set_frame(welcome_panel) |
---|
| 997 | welcome_panel.Show(False) |
---|
[091e71a2] | 998 | |
---|
[f53cd30] | 999 | self.panels["default"] = self.defaultPanel |
---|
| 1000 | size_t_bar = 70 |
---|
| 1001 | if IS_LINUX: |
---|
| 1002 | size_t_bar = 115 |
---|
| 1003 | if self.defaultPanel is not None: |
---|
| 1004 | w, h = self._get_panels_size(self.defaultPanel) |
---|
| 1005 | frame = self.defaultPanel.get_frame() |
---|
| 1006 | frame.SetSize((self._window_width, self._window_height)) |
---|
| 1007 | if not IS_WIN: |
---|
| 1008 | frame.SetPosition((0, mac_pos_y + size_t_bar)) |
---|
| 1009 | frame.Show(True) |
---|
[091e71a2] | 1010 | #add data panel |
---|
[f53cd30] | 1011 | win = MDIFrame(self, None, 'None', (100, 200)) |
---|
[091e71a2] | 1012 | data_panel = DataPanel(parent=win, id=-1) |
---|
[f53cd30] | 1013 | win.set_panel(data_panel) |
---|
| 1014 | self.panels["data_panel"] = data_panel |
---|
| 1015 | self._data_panel = data_panel |
---|
| 1016 | d_panel_width, h = self._get_panels_size(self._data_panel) |
---|
| 1017 | win.SetSize((d_panel_width, h)) |
---|
| 1018 | is_visible = self.__gui_style & GUIFRAME.MANAGER_ON == GUIFRAME.MANAGER_ON |
---|
| 1019 | if IS_WIN: |
---|
| 1020 | win.SetPosition((0, 0)) |
---|
| 1021 | else: |
---|
| 1022 | win.SetPosition((0, mac_pos_y + size_t_bar)) |
---|
| 1023 | win.Show(is_visible) |
---|
| 1024 | # Add the panels to the AUI manager |
---|
| 1025 | for panel_class in panels: |
---|
| 1026 | frame = panel_class.get_frame() |
---|
[091e71a2] | 1027 | wx_id = wx.NewId() |
---|
[f53cd30] | 1028 | # Check whether we need to put this panel in the center pane |
---|
| 1029 | if hasattr(panel_class, "CENTER_PANE") and panel_class.CENTER_PANE: |
---|
| 1030 | w, h = self._get_panels_size(panel_class) |
---|
| 1031 | if panel_class.CENTER_PANE: |
---|
[091e71a2] | 1032 | self.panels[str(wx_id)] = panel_class |
---|
[f53cd30] | 1033 | _, pos_y = frame.GetPositionTuple() |
---|
| 1034 | frame.SetPosition((d_panel_width + 1, pos_y)) |
---|
| 1035 | frame.SetSize((w, h)) |
---|
| 1036 | frame.Show(False) |
---|
| 1037 | elif panel_class == self._data_panel: |
---|
| 1038 | panel_class.frame.Show(is_visible) |
---|
| 1039 | continue |
---|
| 1040 | else: |
---|
[091e71a2] | 1041 | self.panels[str(wx_id)] = panel_class |
---|
[f53cd30] | 1042 | frame.SetSize((w, h)) |
---|
| 1043 | frame.Show(False) |
---|
| 1044 | if IS_WIN: |
---|
| 1045 | frame.SetPosition((d_panel_width + 1, 0)) |
---|
| 1046 | else: |
---|
| 1047 | frame.SetPosition((d_panel_width + 1, mac_pos_y + size_t_bar)) |
---|
| 1048 | |
---|
| 1049 | if not IS_WIN: |
---|
| 1050 | win_height = mac_pos_y |
---|
| 1051 | if IS_LINUX: |
---|
| 1052 | if wx.VERSION_STRING >= '3.0.0.0': |
---|
| 1053 | win_height = mac_pos_y + 10 |
---|
| 1054 | else: |
---|
| 1055 | win_height = mac_pos_y + 55 |
---|
| 1056 | self.SetMaxSize((-1, win_height)) |
---|
| 1057 | else: |
---|
| 1058 | self.SetSize((self._window_width, win_height)) |
---|
[091e71a2] | 1059 | |
---|
[f53cd30] | 1060 | def update_data(self, prev_data, new_data): |
---|
| 1061 | """ |
---|
| 1062 | Update the data. |
---|
| 1063 | """ |
---|
[091e71a2] | 1064 | prev_id, data_state = self._data_manager.update_data( \ |
---|
[f53cd30] | 1065 | prev_data=prev_data, new_data=new_data) |
---|
[091e71a2] | 1066 | |
---|
[f53cd30] | 1067 | self._data_panel.remove_by_id(prev_id) |
---|
| 1068 | self._data_panel.load_data_list(data_state) |
---|
[091e71a2] | 1069 | |
---|
[f53cd30] | 1070 | def update_theory(self, data_id, theory, state=None): |
---|
| 1071 | """ |
---|
| 1072 | Update the theory |
---|
[091e71a2] | 1073 | """ |
---|
| 1074 | data_state = self._data_manager.update_theory(data_id=data_id, |
---|
| 1075 | theory=theory, |
---|
| 1076 | state=state) |
---|
[f53cd30] | 1077 | wx.CallAfter(self._data_panel.load_data_list, data_state) |
---|
[091e71a2] | 1078 | |
---|
[f53cd30] | 1079 | def onfreeze(self, theory_id): |
---|
| 1080 | """ |
---|
| 1081 | """ |
---|
| 1082 | data_state_list = self._data_manager.freeze(theory_id) |
---|
| 1083 | self._data_panel.load_data_list(list=data_state_list) |
---|
| 1084 | for data_state in data_state_list.values(): |
---|
| 1085 | new_plot = data_state.get_data() |
---|
[091e71a2] | 1086 | |
---|
[f53cd30] | 1087 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
[091e71a2] | 1088 | title=new_plot.title)) |
---|
| 1089 | |
---|
[f53cd30] | 1090 | def freeze(self, data_id, theory_id): |
---|
| 1091 | """ |
---|
| 1092 | """ |
---|
[091e71a2] | 1093 | data_state_list = self._data_manager.freeze_theory(data_id=data_id, |
---|
| 1094 | theory_id=theory_id) |
---|
[f53cd30] | 1095 | self._data_panel.load_data_list(list=data_state_list) |
---|
| 1096 | for data_state in data_state_list.values(): |
---|
| 1097 | new_plot = data_state.get_data() |
---|
| 1098 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
[091e71a2] | 1099 | title=new_plot.title)) |
---|
| 1100 | |
---|
[f53cd30] | 1101 | def delete_data(self, data): |
---|
| 1102 | """ |
---|
| 1103 | Delete the data. |
---|
| 1104 | """ |
---|
| 1105 | self._current_perspective.delete_data(data) |
---|
[091e71a2] | 1106 | |
---|
| 1107 | |
---|
[f53cd30] | 1108 | def get_context_menu(self, plotpanel=None): |
---|
| 1109 | """ |
---|
[091e71a2] | 1110 | Get the context menu items made available |
---|
| 1111 | by the different plug-ins. |
---|
[f53cd30] | 1112 | This function is used by the plotting module |
---|
| 1113 | """ |
---|
| 1114 | if plotpanel is None: |
---|
| 1115 | return |
---|
| 1116 | menu_list = [] |
---|
| 1117 | for item in self.plugins: |
---|
| 1118 | menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) |
---|
| 1119 | return menu_list |
---|
[091e71a2] | 1120 | |
---|
[f53cd30] | 1121 | def get_current_context_menu(self, plotpanel=None): |
---|
| 1122 | """ |
---|
[091e71a2] | 1123 | Get the context menu items made available |
---|
| 1124 | by the current plug-in. |
---|
[f53cd30] | 1125 | This function is used by the plotting module |
---|
| 1126 | """ |
---|
| 1127 | if plotpanel is None: |
---|
| 1128 | return |
---|
| 1129 | menu_list = [] |
---|
| 1130 | item = self._current_perspective |
---|
| 1131 | if item != None: |
---|
| 1132 | menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) |
---|
| 1133 | return menu_list |
---|
[091e71a2] | 1134 | |
---|
[f53cd30] | 1135 | def on_panel_close(self, event): |
---|
| 1136 | """ |
---|
| 1137 | Gets called when the close event for a panel runs. |
---|
| 1138 | This will check which panel has been closed and |
---|
| 1139 | delete it. |
---|
| 1140 | """ |
---|
| 1141 | frame = event.GetEventObject() |
---|
| 1142 | for ID in self.plot_panels.keys(): |
---|
| 1143 | if self.plot_panels[ID].window_name == frame.name: |
---|
| 1144 | self.disable_app_menu(self.plot_panels[ID]) |
---|
| 1145 | self.delete_panel(ID) |
---|
| 1146 | break |
---|
| 1147 | self.cpanel_on_focus.SetFocus() |
---|
[091e71a2] | 1148 | |
---|
| 1149 | |
---|
[f53cd30] | 1150 | def popup_panel(self, p): |
---|
| 1151 | """ |
---|
| 1152 | Add a panel object to the AUI manager |
---|
[091e71a2] | 1153 | |
---|
[f53cd30] | 1154 | :param p: panel object to add to the AUI manager |
---|
[091e71a2] | 1155 | |
---|
[f53cd30] | 1156 | :return: ID of the event associated with the new panel [int] |
---|
[091e71a2] | 1157 | |
---|
[f53cd30] | 1158 | """ |
---|
| 1159 | ID = wx.NewId() |
---|
| 1160 | self.panels[str(ID)] = p |
---|
| 1161 | ## Check and set the size |
---|
| 1162 | if PLOPANEL_WIDTH < 0: |
---|
| 1163 | p_panel_width = int(self._window_width * 0.45) |
---|
| 1164 | else: |
---|
| 1165 | p_panel_width = PLOPANEL_WIDTH |
---|
| 1166 | p_panel_height = int(p_panel_width * 0.76) |
---|
| 1167 | p.frame.SetSize((p_panel_width, p_panel_height)) |
---|
| 1168 | self.graph_num += 1 |
---|
| 1169 | if p.window_caption.split()[0] in NOT_SO_GRAPH_LIST: |
---|
| 1170 | windowcaption = p.window_caption |
---|
| 1171 | else: |
---|
| 1172 | windowcaption = 'Graph' |
---|
| 1173 | windowname = p.window_name |
---|
| 1174 | |
---|
| 1175 | # Append nummber |
---|
| 1176 | captions = self._get_plotpanel_captions() |
---|
[091e71a2] | 1177 | #FIXME: Fix this aweful loop |
---|
[f53cd30] | 1178 | while (1): |
---|
[091e71a2] | 1179 | caption = windowcaption + '%s' % str(self.graph_num) |
---|
[f53cd30] | 1180 | if caption not in captions: |
---|
| 1181 | break |
---|
| 1182 | self.graph_num += 1 |
---|
| 1183 | # protection from forever-loop: max num = 1000 |
---|
| 1184 | if self.graph_num > 1000: |
---|
| 1185 | break |
---|
| 1186 | if p.window_caption.split()[0] not in NOT_SO_GRAPH_LIST: |
---|
[091e71a2] | 1187 | p.window_caption = caption |
---|
[f53cd30] | 1188 | p.window_name = windowname + str(self.graph_num) |
---|
[091e71a2] | 1189 | |
---|
[f53cd30] | 1190 | p.frame.SetTitle(p.window_caption) |
---|
| 1191 | p.frame.name = p.window_name |
---|
| 1192 | if not IS_WIN: |
---|
| 1193 | p.frame.Center() |
---|
| 1194 | x_pos, _ = p.frame.GetPositionTuple() |
---|
| 1195 | p.frame.SetPosition((x_pos, 112)) |
---|
| 1196 | p.frame.Show(True) |
---|
| 1197 | |
---|
| 1198 | # Register for showing/hiding the panel |
---|
| 1199 | wx.EVT_MENU(self, ID, self.on_view) |
---|
| 1200 | if p not in self.plot_panels.values() and p.group_id != None: |
---|
| 1201 | self.plot_panels[ID] = p |
---|
| 1202 | if len(self.plot_panels) == 1: |
---|
| 1203 | self.panel_on_focus = p |
---|
| 1204 | self.set_panel_on_focus(None) |
---|
| 1205 | if self._data_panel is not None and \ |
---|
| 1206 | self._plotting_plugin is not None: |
---|
| 1207 | ind = self._data_panel.cb_plotpanel.FindString('None') |
---|
| 1208 | if ind != wx.NOT_FOUND: |
---|
| 1209 | self._data_panel.cb_plotpanel.Delete(ind) |
---|
| 1210 | if caption not in self._data_panel.cb_plotpanel.GetItems(): |
---|
| 1211 | self._data_panel.cb_plotpanel.Append(str(caption), p) |
---|
| 1212 | return ID |
---|
[091e71a2] | 1213 | |
---|
[f53cd30] | 1214 | def _get_plotpanel_captions(self): |
---|
| 1215 | """ |
---|
| 1216 | Get all the plotpanel cations |
---|
[091e71a2] | 1217 | |
---|
[f53cd30] | 1218 | : return: list of captions |
---|
| 1219 | """ |
---|
| 1220 | captions = [] |
---|
| 1221 | for Id in self.plot_panels.keys(): |
---|
| 1222 | captions.append(self.plot_panels[Id].window_caption) |
---|
[091e71a2] | 1223 | |
---|
[f53cd30] | 1224 | return captions |
---|
[091e71a2] | 1225 | |
---|
[f53cd30] | 1226 | def _setup_tool_bar(self): |
---|
| 1227 | """ |
---|
| 1228 | add toolbar to the frame |
---|
| 1229 | """ |
---|
| 1230 | self._toolbar = GUIToolBar(self) |
---|
| 1231 | # The legacy code doesn't work well for wx 3.0 |
---|
| 1232 | # but the old code produces better results with wx 2.8 |
---|
| 1233 | if not IS_WIN and wx.VERSION_STRING >= '3.0.0.0': |
---|
| 1234 | sizer = wx.BoxSizer(wx.VERTICAL) |
---|
| 1235 | sizer.Add(self._toolbar, 0, wx.EXPAND) |
---|
| 1236 | self.SetSizer(sizer) |
---|
| 1237 | else: |
---|
| 1238 | self.SetToolBar(self._toolbar) |
---|
| 1239 | self._update_toolbar_helper() |
---|
| 1240 | self._on_toggle_toolbar(event=None) |
---|
[091e71a2] | 1241 | |
---|
[f53cd30] | 1242 | def _update_toolbar_helper(self): |
---|
| 1243 | """ |
---|
| 1244 | Helping to update the toolbar |
---|
| 1245 | """ |
---|
| 1246 | application_name = 'No Selected Analysis' |
---|
| 1247 | panel_name = 'No Panel on Focus' |
---|
[091e71a2] | 1248 | c_panel = self.cpanel_on_focus |
---|
[f53cd30] | 1249 | if self._toolbar is None: |
---|
| 1250 | return |
---|
| 1251 | if c_panel is not None: |
---|
| 1252 | self.reset_bookmark_menu(self.cpanel_on_focus) |
---|
| 1253 | if self._current_perspective is not None: |
---|
| 1254 | application_name = self._current_perspective.sub_menu |
---|
| 1255 | c_panel_state = c_panel |
---|
| 1256 | if c_panel is not None: |
---|
| 1257 | panel_name = c_panel.window_caption |
---|
| 1258 | if not c_panel.IsShownOnScreen(): |
---|
| 1259 | c_panel_state = None |
---|
| 1260 | self._toolbar.update_toolbar(c_panel_state) |
---|
[091e71a2] | 1261 | self._toolbar.update_button(application_name=application_name, |
---|
| 1262 | panel_name=panel_name) |
---|
[f53cd30] | 1263 | self._toolbar.Realize() |
---|
[091e71a2] | 1264 | |
---|
[f53cd30] | 1265 | def _add_menu_tool(self): |
---|
| 1266 | """ |
---|
| 1267 | Tools menu |
---|
| 1268 | Go through plug-ins and find tools to populate the tools menu |
---|
| 1269 | """ |
---|
| 1270 | style = self.__gui_style & GUIFRAME.CALCULATOR_ON |
---|
| 1271 | if style == GUIFRAME.CALCULATOR_ON: |
---|
| 1272 | self._tool_menu = None |
---|
| 1273 | for item in self.plugins: |
---|
| 1274 | if hasattr(item, "get_tools"): |
---|
| 1275 | for tool in item.get_tools(): |
---|
| 1276 | # Only create a menu if we have at least one tool |
---|
| 1277 | if self._tool_menu is None: |
---|
| 1278 | self._tool_menu = wx.Menu() |
---|
| 1279 | if tool[0].lower().count('python') > 0: |
---|
| 1280 | self._tool_menu.AppendSeparator() |
---|
| 1281 | id = wx.NewId() |
---|
| 1282 | self._tool_menu.Append(id, tool[0], tool[1]) |
---|
| 1283 | wx.EVT_MENU(self, id, tool[2]) |
---|
| 1284 | if self._tool_menu is not None: |
---|
| 1285 | self._menubar.Append(self._tool_menu, '&Tool') |
---|
[091e71a2] | 1286 | |
---|
[f53cd30] | 1287 | def _add_current_plugin_menu(self): |
---|
| 1288 | """ |
---|
| 1289 | add current plugin menu |
---|
| 1290 | Look for plug-in menus |
---|
[091e71a2] | 1291 | Add available plug-in sub-menus. |
---|
[f53cd30] | 1292 | """ |
---|
| 1293 | if self._menubar is None or self._current_perspective is None \ |
---|
[091e71a2] | 1294 | or self._menubar.GetMenuCount() == 0: |
---|
[f53cd30] | 1295 | return |
---|
| 1296 | #replace or add a new menu for the current plugin |
---|
| 1297 | pos = self._menubar.FindMenu(str(self._applications_menu_name)) |
---|
[3c2011e] | 1298 | if pos == -1 and self._applications_menu_pos > 0: |
---|
| 1299 | pos = self._applications_menu_pos |
---|
[f53cd30] | 1300 | if pos != -1: |
---|
| 1301 | menu_list = self._current_perspective.populate_menu(self) |
---|
| 1302 | if menu_list: |
---|
| 1303 | for (menu, name) in menu_list: |
---|
[3c2011e] | 1304 | print "[%s]" % name |
---|
[091e71a2] | 1305 | self._menubar.Replace(pos, menu, name) |
---|
| 1306 | self._applications_menu_name = name |
---|
[3c2011e] | 1307 | self._applications_menu_pos = pos |
---|
[f53cd30] | 1308 | else: |
---|
[091e71a2] | 1309 | self._menubar.Remove(pos) |
---|
[f53cd30] | 1310 | self._applications_menu_name = None |
---|
[3c2011e] | 1311 | self._applications_menu_pos = -1 |
---|
[f53cd30] | 1312 | else: |
---|
| 1313 | menu_list = self._current_perspective.populate_menu(self) |
---|
| 1314 | if menu_list: |
---|
| 1315 | for (menu, name) in menu_list: |
---|
| 1316 | if self._applications_menu_pos == -1: |
---|
[765e47c] | 1317 | # Find the Help position and insert just before it if possible |
---|
| 1318 | help_pos = self._menubar.FindMenu("Help") |
---|
| 1319 | if help_pos == -1: |
---|
| 1320 | self._menubar.Append(menu, name) |
---|
[3c2011e] | 1321 | self._applications_menu_pos = -1 |
---|
[765e47c] | 1322 | else: |
---|
| 1323 | self._menubar.Insert(help_pos-1, menu, name) |
---|
[3c2011e] | 1324 | self._applications_menu_pos = help_pos - 1 |
---|
[f53cd30] | 1325 | else: |
---|
[765e47c] | 1326 | self._menubar.Insert(self._applications_menu_pos, menu, name) |
---|
[f53cd30] | 1327 | self._applications_menu_name = name |
---|
[091e71a2] | 1328 | |
---|
[f53cd30] | 1329 | def _add_help_menu(self): |
---|
| 1330 | """ |
---|
| 1331 | add help menu to menu bar. Includes welcome page, about page, |
---|
[091e71a2] | 1332 | tutorial PDF and documentation pages. |
---|
[f53cd30] | 1333 | """ |
---|
| 1334 | # Help menu |
---|
| 1335 | self._help_menu = wx.Menu() |
---|
| 1336 | style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON |
---|
| 1337 | |
---|
| 1338 | if style == GUIFRAME.WELCOME_PANEL_ON or custom_config != None: |
---|
| 1339 | # add the welcome panel menu item |
---|
| 1340 | if config.WELCOME_PANEL_ON and self.defaultPanel is not None: |
---|
[091e71a2] | 1341 | wx_id = wx.NewId() |
---|
| 1342 | self._help_menu.Append(wx_id, '&Welcome', '') |
---|
| 1343 | wx.EVT_MENU(self, wx_id, self.show_welcome_panel) |
---|
[f53cd30] | 1344 | |
---|
| 1345 | self._help_menu.AppendSeparator() |
---|
[091e71a2] | 1346 | wx_id = wx.NewId() |
---|
| 1347 | self._help_menu.Append(wx_id, '&Documentation', '') |
---|
| 1348 | wx.EVT_MENU(self, wx_id, self._onSphinxDocs) |
---|
[f53cd30] | 1349 | |
---|
[091e71a2] | 1350 | if config._do_tutorial and (IS_WIN or sys.platform == 'darwin'): |
---|
[f53cd30] | 1351 | self._help_menu.AppendSeparator() |
---|
[091e71a2] | 1352 | wx_id = wx.NewId() |
---|
| 1353 | self._help_menu.Append(wx_id, '&Tutorial', 'Software tutorial') |
---|
| 1354 | wx.EVT_MENU(self, wx_id, self._onTutorial) |
---|
| 1355 | |
---|
[f53cd30] | 1356 | if config._do_acknowledge: |
---|
| 1357 | self._help_menu.AppendSeparator() |
---|
[091e71a2] | 1358 | wx_id = wx.NewId() |
---|
| 1359 | self._help_menu.Append(wx_id, '&Acknowledge', 'Acknowledging SasView') |
---|
| 1360 | wx.EVT_MENU(self, wx_id, self._onAcknowledge) |
---|
| 1361 | |
---|
[f53cd30] | 1362 | if config._do_aboutbox: |
---|
| 1363 | self._help_menu.AppendSeparator() |
---|
| 1364 | self._help_menu.Append(wx.ID_ABOUT, '&About', 'Software information') |
---|
| 1365 | wx.EVT_MENU(self, wx.ID_ABOUT, self._onAbout) |
---|
[091e71a2] | 1366 | |
---|
[f53cd30] | 1367 | # Checking for updates |
---|
[091e71a2] | 1368 | wx_id = wx.NewId() |
---|
| 1369 | self._help_menu.Append(wx_id, '&Check for update', |
---|
| 1370 | 'Check for the latest version of %s' % config.__appname__) |
---|
| 1371 | wx.EVT_MENU(self, wx_id, self._check_update) |
---|
[f53cd30] | 1372 | self._menubar.Append(self._help_menu, '&Help') |
---|
[091e71a2] | 1373 | |
---|
[f53cd30] | 1374 | def _add_menu_view(self): |
---|
| 1375 | """ |
---|
| 1376 | add menu items under view menu |
---|
| 1377 | """ |
---|
| 1378 | if not VIEW_MENU: |
---|
| 1379 | return |
---|
| 1380 | self._view_menu = wx.Menu() |
---|
[091e71a2] | 1381 | |
---|
| 1382 | wx_id = wx.NewId() |
---|
[f53cd30] | 1383 | hint = "Display the Grid Window for batch results etc." |
---|
[091e71a2] | 1384 | self._view_menu.Append(wx_id, '&Show Grid Window', hint) |
---|
| 1385 | wx.EVT_MENU(self, wx_id, self.show_batch_frame) |
---|
| 1386 | |
---|
[f53cd30] | 1387 | self._view_menu.AppendSeparator() |
---|
| 1388 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
[091e71a2] | 1389 | wx_id = wx.NewId() |
---|
| 1390 | self._data_panel_menu = self._view_menu.Append(wx_id, |
---|
| 1391 | '&Show Data Explorer', '') |
---|
| 1392 | wx.EVT_MENU(self, wx_id, self.show_data_panel) |
---|
[f53cd30] | 1393 | if style == GUIFRAME.MANAGER_ON: |
---|
| 1394 | self._data_panel_menu.SetText('Hide Data Explorer') |
---|
| 1395 | else: |
---|
| 1396 | self._data_panel_menu.SetText('Show Data Explorer') |
---|
[091e71a2] | 1397 | |
---|
[f53cd30] | 1398 | self._view_menu.AppendSeparator() |
---|
[091e71a2] | 1399 | wx_id = wx.NewId() |
---|
[f53cd30] | 1400 | style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
| 1401 | if style1 == GUIFRAME.TOOLBAR_ON: |
---|
[091e71a2] | 1402 | self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', '') |
---|
[f53cd30] | 1403 | else: |
---|
[091e71a2] | 1404 | self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', '') |
---|
| 1405 | wx.EVT_MENU(self, wx_id, self._on_toggle_toolbar) |
---|
[f53cd30] | 1406 | |
---|
| 1407 | if custom_config != None: |
---|
| 1408 | self._view_menu.AppendSeparator() |
---|
[091e71a2] | 1409 | wx_id = wx.NewId() |
---|
[f53cd30] | 1410 | hint_ss = "Select the current/default configuration " |
---|
| 1411 | hint_ss += "as a startup setting" |
---|
[091e71a2] | 1412 | preference_menu = self._view_menu.Append(wx_id, 'Startup Setting', |
---|
[f53cd30] | 1413 | hint_ss) |
---|
[091e71a2] | 1414 | wx.EVT_MENU(self, wx_id, self._on_preference_menu) |
---|
| 1415 | |
---|
| 1416 | wx_id = wx.NewId() |
---|
[f53cd30] | 1417 | self._view_menu.AppendSeparator() |
---|
[091e71a2] | 1418 | self._view_menu.Append(wx_id, 'Category Manager', 'Edit model categories') |
---|
| 1419 | wx.EVT_MENU(self, wx_id, self._on_category_manager) |
---|
| 1420 | |
---|
| 1421 | self._menubar.Append(self._view_menu, '&View') |
---|
[f53cd30] | 1422 | |
---|
| 1423 | def show_batch_frame(self, event=None): |
---|
| 1424 | """ |
---|
| 1425 | show the grid of result |
---|
| 1426 | """ |
---|
| 1427 | # Show(False) before Show(True) in order to bring it to the front |
---|
| 1428 | self.batch_frame.Show(False) |
---|
| 1429 | self.batch_frame.Show(True) |
---|
[091e71a2] | 1430 | |
---|
| 1431 | def on_category_panel(self, event): |
---|
[f53cd30] | 1432 | """ |
---|
| 1433 | On cat panel |
---|
| 1434 | """ |
---|
| 1435 | self._on_category_manager(event) |
---|
[091e71a2] | 1436 | |
---|
[f53cd30] | 1437 | def _on_category_manager(self, event): |
---|
| 1438 | """ |
---|
| 1439 | Category manager frame |
---|
| 1440 | """ |
---|
| 1441 | frame = CategoryManager(self, -1, 'Model Category Manager') |
---|
| 1442 | icon = self.GetIcon() |
---|
| 1443 | frame.SetIcon(icon) |
---|
| 1444 | |
---|
[091e71a2] | 1445 | def _on_preference_menu(self, event): |
---|
[f53cd30] | 1446 | """ |
---|
| 1447 | Build a panel to allow to edit Mask |
---|
| 1448 | """ |
---|
| 1449 | from sas.guiframe.startup_configuration \ |
---|
| 1450 | import StartupConfiguration as ConfDialog |
---|
[091e71a2] | 1451 | |
---|
[f53cd30] | 1452 | dialog = ConfDialog(parent=self, gui=self.__gui_style) |
---|
| 1453 | result = dialog.ShowModal() |
---|
| 1454 | if result == wx.ID_OK: |
---|
| 1455 | dialog.write_custom_config() |
---|
| 1456 | # post event for info |
---|
| 1457 | wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", info='info')) |
---|
| 1458 | dialog.Destroy() |
---|
[091e71a2] | 1459 | |
---|
[f53cd30] | 1460 | def _add_menu_application(self): |
---|
| 1461 | """ |
---|
| 1462 | # Attach a menu item for each defined perspective or application. |
---|
| 1463 | # Only add the perspective menu if there are more than one perspectives |
---|
| 1464 | add menu application |
---|
| 1465 | """ |
---|
[091e71a2] | 1466 | if self._num_perspectives > 1: |
---|
[f53cd30] | 1467 | plug_data_count = False |
---|
| 1468 | plug_no_data_count = False |
---|
| 1469 | self._applications_menu = wx.Menu() |
---|
| 1470 | pos = 0 |
---|
| 1471 | separator = self._applications_menu.AppendSeparator() |
---|
| 1472 | for plug in self.plugins: |
---|
| 1473 | if len(plug.get_perspective()) > 0: |
---|
| 1474 | id = wx.NewId() |
---|
| 1475 | if plug.use_data(): |
---|
[091e71a2] | 1476 | self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, \ |
---|
| 1477 | "Switch to analysis: %s" % plug.sub_menu) |
---|
[f53cd30] | 1478 | plug_data_count = True |
---|
| 1479 | pos += 1 |
---|
| 1480 | else: |
---|
| 1481 | plug_no_data_count = True |
---|
[091e71a2] | 1482 | self._applications_menu.AppendCheckItem(id, plug.sub_menu, \ |
---|
| 1483 | "Switch to analysis: %s" % plug.sub_menu) |
---|
[f53cd30] | 1484 | wx.EVT_MENU(self, id, plug.on_perspective) |
---|
| 1485 | |
---|
[091e71a2] | 1486 | if not plug_data_count or not plug_no_data_count: |
---|
[f53cd30] | 1487 | self._applications_menu.RemoveItem(separator) |
---|
| 1488 | self._menubar.Append(self._applications_menu, '&Analysis') |
---|
| 1489 | self._check_applications_menu() |
---|
[091e71a2] | 1490 | |
---|
[f53cd30] | 1491 | def _populate_file_menu(self): |
---|
| 1492 | """ |
---|
| 1493 | Insert menu item under file menu |
---|
| 1494 | """ |
---|
| 1495 | for plugin in self.plugins: |
---|
| 1496 | if len(plugin.populate_file_menu()) > 0: |
---|
| 1497 | for item in plugin.populate_file_menu(): |
---|
| 1498 | m_name, m_hint, m_handler = item |
---|
| 1499 | id = wx.NewId() |
---|
| 1500 | self._file_menu.Append(id, m_name, m_hint) |
---|
| 1501 | wx.EVT_MENU(self, id, m_handler) |
---|
| 1502 | self._file_menu.AppendSeparator() |
---|
[091e71a2] | 1503 | |
---|
[f53cd30] | 1504 | style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS |
---|
| 1505 | if OPEN_SAVE_MENU: |
---|
| 1506 | id = wx.NewId() |
---|
| 1507 | hint_load_file = "read all analysis states saved previously" |
---|
[091e71a2] | 1508 | self._save_appl_menu = self._file_menu.Append(id, '&Open Project', hint_load_file) |
---|
[f53cd30] | 1509 | wx.EVT_MENU(self, id, self._on_open_state_project) |
---|
[091e71a2] | 1510 | |
---|
[f53cd30] | 1511 | if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
| 1512 | # some menu of plugin to be seen under file menu |
---|
| 1513 | hint_load_file = "Read a status files and load" |
---|
| 1514 | hint_load_file += " them into the analysis" |
---|
| 1515 | id = wx.NewId() |
---|
[091e71a2] | 1516 | self._save_appl_menu = self._file_menu.Append(id, |
---|
| 1517 | '&Open Analysis', hint_load_file) |
---|
[f53cd30] | 1518 | wx.EVT_MENU(self, id, self._on_open_state_application) |
---|
[091e71a2] | 1519 | if OPEN_SAVE_MENU: |
---|
[f53cd30] | 1520 | self._file_menu.AppendSeparator() |
---|
| 1521 | id = wx.NewId() |
---|
| 1522 | self._file_menu.Append(id, '&Save Project', |
---|
[091e71a2] | 1523 | 'Save the state of the whole analysis') |
---|
[f53cd30] | 1524 | wx.EVT_MENU(self, id, self._on_save_project) |
---|
| 1525 | if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
| 1526 | id = wx.NewId() |
---|
[091e71a2] | 1527 | self._save_appl_menu = self._file_menu.Append(id, \ |
---|
| 1528 | '&Save Analysis', 'Save state of the current active analysis panel') |
---|
[f53cd30] | 1529 | wx.EVT_MENU(self, id, self._on_save_application) |
---|
[091e71a2] | 1530 | if not sys.platform == 'darwin': |
---|
[f53cd30] | 1531 | self._file_menu.AppendSeparator() |
---|
| 1532 | id = wx.NewId() |
---|
[091e71a2] | 1533 | self._file_menu.Append(id, '&Quit', 'Exit') |
---|
[f53cd30] | 1534 | wx.EVT_MENU(self, id, self.Close) |
---|
[091e71a2] | 1535 | |
---|
[f53cd30] | 1536 | def _add_menu_file(self): |
---|
| 1537 | """ |
---|
| 1538 | add menu file |
---|
| 1539 | """ |
---|
| 1540 | # File menu |
---|
| 1541 | self._file_menu = wx.Menu() |
---|
| 1542 | # Add sub menus |
---|
| 1543 | self._menubar.Append(self._file_menu, '&File') |
---|
[091e71a2] | 1544 | |
---|
[f53cd30] | 1545 | def _add_menu_edit(self): |
---|
| 1546 | """ |
---|
| 1547 | add menu edit |
---|
| 1548 | """ |
---|
| 1549 | if not EDIT_MENU: |
---|
| 1550 | return |
---|
| 1551 | # Edit Menu |
---|
| 1552 | self._edit_menu = wx.Menu() |
---|
[091e71a2] | 1553 | self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo', |
---|
[f53cd30] | 1554 | 'Undo the previous action') |
---|
| 1555 | wx.EVT_MENU(self, GUIFRAME_ID.UNDO_ID, self.on_undo_panel) |
---|
[091e71a2] | 1556 | self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo', |
---|
[f53cd30] | 1557 | 'Redo the previous action') |
---|
| 1558 | wx.EVT_MENU(self, GUIFRAME_ID.REDO_ID, self.on_redo_panel) |
---|
| 1559 | self._edit_menu.AppendSeparator() |
---|
[091e71a2] | 1560 | self._edit_menu.Append(GUIFRAME_ID.COPY_ID, '&Copy Params', |
---|
[f53cd30] | 1561 | 'Copy parameter values') |
---|
| 1562 | wx.EVT_MENU(self, GUIFRAME_ID.COPY_ID, self.on_copy_panel) |
---|
[091e71a2] | 1563 | self._edit_menu.Append(GUIFRAME_ID.PASTE_ID, '&Paste Params', |
---|
[f53cd30] | 1564 | 'Paste parameter values') |
---|
| 1565 | wx.EVT_MENU(self, GUIFRAME_ID.PASTE_ID, self.on_paste_panel) |
---|
| 1566 | |
---|
| 1567 | self._edit_menu.AppendSeparator() |
---|
| 1568 | |
---|
| 1569 | self._edit_menu_copyas = wx.Menu() |
---|
| 1570 | #Sub menu for Copy As... |
---|
| 1571 | self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 'Copy current tab to Excel', |
---|
[091e71a2] | 1572 | 'Copy parameter values in tabular format') |
---|
[f53cd30] | 1573 | wx.EVT_MENU(self, GUIFRAME_ID.COPYEX_ID, self.on_copy_panel) |
---|
| 1574 | |
---|
| 1575 | self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 'Copy current tab to LaTeX', |
---|
[091e71a2] | 1576 | 'Copy parameter values in tabular format') |
---|
[f53cd30] | 1577 | wx.EVT_MENU(self, GUIFRAME_ID.COPYLAT_ID, self.on_copy_panel) |
---|
| 1578 | |
---|
| 1579 | |
---|
[091e71a2] | 1580 | self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', |
---|
| 1581 | self._edit_menu_copyas, |
---|
| 1582 | 'Copy parameter values in various formats') |
---|
[f53cd30] | 1583 | |
---|
| 1584 | self._edit_menu.AppendSeparator() |
---|
[091e71a2] | 1585 | |
---|
[f53cd30] | 1586 | self._edit_menu.Append(GUIFRAME_ID.PREVIEW_ID, '&Report Results', |
---|
| 1587 | 'Preview current panel') |
---|
| 1588 | wx.EVT_MENU(self, GUIFRAME_ID.PREVIEW_ID, self.on_preview_panel) |
---|
| 1589 | |
---|
[091e71a2] | 1590 | self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset Page', |
---|
[f53cd30] | 1591 | 'Reset current panel') |
---|
| 1592 | wx.EVT_MENU(self, GUIFRAME_ID.RESET_ID, self.on_reset_panel) |
---|
[091e71a2] | 1593 | |
---|
| 1594 | self._menubar.Append(self._edit_menu, '&Edit') |
---|
[f53cd30] | 1595 | self.enable_edit_menu() |
---|
[091e71a2] | 1596 | |
---|
[f53cd30] | 1597 | def get_style(self): |
---|
| 1598 | """ |
---|
| 1599 | Return the gui style |
---|
| 1600 | """ |
---|
| 1601 | return self.__gui_style |
---|
[091e71a2] | 1602 | |
---|
[f53cd30] | 1603 | def _add_menu_data(self): |
---|
| 1604 | """ |
---|
| 1605 | Add menu item item data to menu bar |
---|
| 1606 | """ |
---|
| 1607 | if self._data_plugin is not None: |
---|
| 1608 | menu_list = self._data_plugin.populate_menu(self) |
---|
| 1609 | if menu_list: |
---|
| 1610 | for (menu, name) in menu_list: |
---|
| 1611 | self._menubar.Append(menu, name) |
---|
[091e71a2] | 1612 | |
---|
[f53cd30] | 1613 | def _on_toggle_toolbar(self, event=None): |
---|
| 1614 | """ |
---|
| 1615 | hide or show toolbar |
---|
| 1616 | """ |
---|
| 1617 | if self._toolbar is None: |
---|
| 1618 | return |
---|
| 1619 | if self._toolbar.IsShown(): |
---|
| 1620 | if self._toolbar_menu is not None: |
---|
| 1621 | self._toolbar_menu.SetItemLabel('Show Toolbar') |
---|
| 1622 | self._toolbar.Hide() |
---|
| 1623 | else: |
---|
| 1624 | if self._toolbar_menu is not None: |
---|
| 1625 | self._toolbar_menu.SetItemLabel('Hide Toolbar') |
---|
| 1626 | self._toolbar.Show() |
---|
| 1627 | self._toolbar.Realize() |
---|
[091e71a2] | 1628 | |
---|
[f53cd30] | 1629 | def _on_status_event(self, evt): |
---|
| 1630 | """ |
---|
| 1631 | Display status message |
---|
| 1632 | """ |
---|
| 1633 | # This CallAfter fixes many crashes on MAC. |
---|
| 1634 | wx.CallAfter(self.sb.set_status, evt) |
---|
[091e71a2] | 1635 | |
---|
[f53cd30] | 1636 | def on_view(self, evt): |
---|
| 1637 | """ |
---|
| 1638 | A panel was selected to be shown. If it's not already |
---|
| 1639 | shown, display it. |
---|
[091e71a2] | 1640 | |
---|
[f53cd30] | 1641 | :param evt: menu event |
---|
[091e71a2] | 1642 | |
---|
[f53cd30] | 1643 | """ |
---|
| 1644 | panel_id = str(evt.GetId()) |
---|
| 1645 | self.on_set_plot_focus(self.panels[panel_id]) |
---|
[091e71a2] | 1646 | wx.CallLater(5 * TIME_FACTOR, self.set_schedule(True)) |
---|
[f53cd30] | 1647 | self.set_plot_unfocus() |
---|
[091e71a2] | 1648 | |
---|
[f53cd30] | 1649 | def show_welcome_panel(self, event): |
---|
[091e71a2] | 1650 | """ |
---|
[f53cd30] | 1651 | Display the welcome panel |
---|
| 1652 | """ |
---|
| 1653 | if self.defaultPanel is None: |
---|
[091e71a2] | 1654 | return |
---|
[f53cd30] | 1655 | frame = self.panels['default'].get_frame() |
---|
| 1656 | if frame == None: |
---|
| 1657 | return |
---|
| 1658 | # Show default panel |
---|
| 1659 | if not frame.IsShown(): |
---|
| 1660 | frame.Show(True) |
---|
[091e71a2] | 1661 | |
---|
[f53cd30] | 1662 | def on_close_welcome_panel(self): |
---|
| 1663 | """ |
---|
| 1664 | Close the welcome panel |
---|
| 1665 | """ |
---|
| 1666 | if self.defaultPanel is None: |
---|
[091e71a2] | 1667 | return |
---|
[f53cd30] | 1668 | default_panel = self.panels["default"].frame |
---|
| 1669 | if default_panel.IsShown(): |
---|
[091e71a2] | 1670 | default_panel.Show(False) |
---|
| 1671 | |
---|
[f53cd30] | 1672 | def delete_panel(self, uid): |
---|
| 1673 | """ |
---|
| 1674 | delete panel given uid |
---|
| 1675 | """ |
---|
| 1676 | ID = str(uid) |
---|
| 1677 | config.printEVT("delete_panel: %s" % ID) |
---|
| 1678 | if ID in self.panels.keys(): |
---|
| 1679 | self.panel_on_focus = None |
---|
| 1680 | panel = self.panels[ID] |
---|
| 1681 | |
---|
| 1682 | if hasattr(panel, "connect"): |
---|
| 1683 | panel.connect.disconnect() |
---|
| 1684 | self._plotting_plugin.delete_panel(panel.group_id) |
---|
| 1685 | |
---|
| 1686 | if panel in self.schedule_full_draw_list: |
---|
[091e71a2] | 1687 | self.schedule_full_draw_list.remove(panel) |
---|
| 1688 | |
---|
[f53cd30] | 1689 | #delete uid number not str(uid) |
---|
| 1690 | if ID in self.plot_panels.keys(): |
---|
| 1691 | del self.plot_panels[ID] |
---|
| 1692 | if ID in self.panels.keys(): |
---|
| 1693 | del self.panels[ID] |
---|
[091e71a2] | 1694 | else: |
---|
| 1695 | logging.error("delete_panel: No such plot id as %s" % ID) |
---|
| 1696 | |
---|
[f53cd30] | 1697 | def create_gui_data(self, data, path=None): |
---|
| 1698 | """ |
---|
| 1699 | """ |
---|
| 1700 | return self._data_manager.create_gui_data(data, path) |
---|
[091e71a2] | 1701 | |
---|
[f53cd30] | 1702 | def get_data(self, path): |
---|
| 1703 | """ |
---|
| 1704 | """ |
---|
| 1705 | message = "" |
---|
| 1706 | log_msg = '' |
---|
| 1707 | output = [] |
---|
| 1708 | error_message = "" |
---|
[091e71a2] | 1709 | basename = os.path.basename(path) |
---|
[f53cd30] | 1710 | root, extension = os.path.splitext(basename) |
---|
| 1711 | if extension.lower() not in EXTENSIONS: |
---|
| 1712 | log_msg = "File Loader cannot " |
---|
| 1713 | log_msg += "load: %s\n" % str(basename) |
---|
| 1714 | log_msg += "Try Data opening...." |
---|
| 1715 | logging.error(log_msg) |
---|
| 1716 | return |
---|
[091e71a2] | 1717 | |
---|
[f53cd30] | 1718 | #reading a state file |
---|
| 1719 | for plug in self.plugins: |
---|
| 1720 | reader, ext = plug.get_extensions() |
---|
| 1721 | if reader is not None: |
---|
| 1722 | #read the state of the single plugin |
---|
| 1723 | if extension == ext: |
---|
| 1724 | reader.read(path) |
---|
| 1725 | return |
---|
| 1726 | elif extension == APPLICATION_STATE_EXTENSION: |
---|
| 1727 | try: |
---|
| 1728 | reader.read(path) |
---|
| 1729 | except: |
---|
| 1730 | msg = "DataLoader Error: Encounted Non-ASCII character" |
---|
[091e71a2] | 1731 | msg += "\n(%s)" % sys.exc_value |
---|
| 1732 | wx.PostEvent(self, StatusEvent(status=msg, |
---|
| 1733 | info="error", type="stop")) |
---|
[f53cd30] | 1734 | return |
---|
[091e71a2] | 1735 | |
---|
[f53cd30] | 1736 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 1737 | if style == GUIFRAME.MANAGER_ON: |
---|
| 1738 | if self._data_panel is not None: |
---|
| 1739 | self._data_panel.frame.Show(True) |
---|
[091e71a2] | 1740 | |
---|
| 1741 | def load_from_cmd(self, path): |
---|
[f53cd30] | 1742 | """ |
---|
| 1743 | load data from cmd or application |
---|
[091e71a2] | 1744 | """ |
---|
[f53cd30] | 1745 | if path is None: |
---|
| 1746 | return |
---|
| 1747 | else: |
---|
| 1748 | path = os.path.abspath(path) |
---|
| 1749 | if not os.path.isfile(path) and not os.path.isdir(path): |
---|
| 1750 | return |
---|
[091e71a2] | 1751 | |
---|
[f53cd30] | 1752 | if os.path.isdir(path): |
---|
| 1753 | self.load_folder(path) |
---|
| 1754 | return |
---|
| 1755 | |
---|
[091e71a2] | 1756 | basename = os.path.basename(path) |
---|
| 1757 | _, extension = os.path.splitext(basename) |
---|
[f53cd30] | 1758 | if extension.lower() not in EXTENSIONS: |
---|
| 1759 | self.load_data(path) |
---|
| 1760 | else: |
---|
| 1761 | self.load_state(path) |
---|
| 1762 | |
---|
| 1763 | self._default_save_location = os.path.dirname(path) |
---|
[091e71a2] | 1764 | |
---|
| 1765 | def load_state(self, path, is_project=False): |
---|
[f53cd30] | 1766 | """ |
---|
| 1767 | load data from command line or application |
---|
| 1768 | """ |
---|
| 1769 | if path and (path is not None) and os.path.isfile(path): |
---|
[091e71a2] | 1770 | basename = os.path.basename(path) |
---|
[f53cd30] | 1771 | if APPLICATION_STATE_EXTENSION is not None \ |
---|
| 1772 | and basename.endswith(APPLICATION_STATE_EXTENSION): |
---|
| 1773 | if is_project: |
---|
| 1774 | for ID in self.plot_panels.keys(): |
---|
| 1775 | panel = self.plot_panels[ID] |
---|
| 1776 | panel.on_close(None) |
---|
| 1777 | self.get_data(path) |
---|
| 1778 | wx.PostEvent(self, StatusEvent(status="Completed loading.")) |
---|
| 1779 | else: |
---|
| 1780 | wx.PostEvent(self, StatusEvent(status=" ")) |
---|
[091e71a2] | 1781 | |
---|
[f53cd30] | 1782 | def load_data(self, path): |
---|
| 1783 | """ |
---|
| 1784 | load data from command line |
---|
| 1785 | """ |
---|
| 1786 | if not os.path.isfile(path): |
---|
| 1787 | return |
---|
[091e71a2] | 1788 | basename = os.path.basename(path) |
---|
| 1789 | _, extension = os.path.splitext(basename) |
---|
[f53cd30] | 1790 | if extension.lower() in EXTENSIONS: |
---|
| 1791 | log_msg = "Data Loader cannot " |
---|
| 1792 | log_msg += "load: %s\n" % str(path) |
---|
| 1793 | log_msg += "Try File opening ...." |
---|
| 1794 | logging.error(log_msg) |
---|
| 1795 | return |
---|
| 1796 | log_msg = '' |
---|
| 1797 | output = {} |
---|
| 1798 | error_message = "" |
---|
| 1799 | try: |
---|
| 1800 | logging.info("Loading Data...:\n" + str(path) + "\n") |
---|
[091e71a2] | 1801 | temp = self.loader.load(path) |
---|
[f53cd30] | 1802 | if temp.__class__.__name__ == "list": |
---|
| 1803 | for item in temp: |
---|
| 1804 | data = self.create_gui_data(item, path) |
---|
| 1805 | output[data.id] = data |
---|
| 1806 | else: |
---|
| 1807 | data = self.create_gui_data(temp, path) |
---|
| 1808 | output[data.id] = data |
---|
[091e71a2] | 1809 | |
---|
[f53cd30] | 1810 | self.add_data(data_list=output) |
---|
| 1811 | except: |
---|
| 1812 | error_message = "Error while loading" |
---|
| 1813 | error_message += " Data from cmd:\n %s\n" % str(path) |
---|
| 1814 | error_message += str(sys.exc_value) + "\n" |
---|
| 1815 | logging.error(error_message) |
---|
[091e71a2] | 1816 | |
---|
[f53cd30] | 1817 | def load_folder(self, path): |
---|
| 1818 | """ |
---|
| 1819 | Load entire folder |
---|
[091e71a2] | 1820 | """ |
---|
[f53cd30] | 1821 | if not os.path.isdir(path): |
---|
| 1822 | return |
---|
| 1823 | if self._data_plugin is None: |
---|
| 1824 | return |
---|
| 1825 | try: |
---|
| 1826 | if path is not None: |
---|
| 1827 | self._default_save_location = os.path.dirname(path) |
---|
| 1828 | file_list = self._data_plugin.get_file_path(path) |
---|
| 1829 | self._data_plugin.get_data(file_list) |
---|
| 1830 | else: |
---|
[091e71a2] | 1831 | return |
---|
[f53cd30] | 1832 | except: |
---|
| 1833 | error_message = "Error while loading" |
---|
| 1834 | error_message += " Data folder from cmd:\n %s\n" % str(path) |
---|
| 1835 | error_message += str(sys.exc_value) + "\n" |
---|
| 1836 | logging.error(error_message) |
---|
[091e71a2] | 1837 | |
---|
[f53cd30] | 1838 | def _on_open_state_application(self, event): |
---|
| 1839 | """ |
---|
| 1840 | """ |
---|
| 1841 | path = None |
---|
| 1842 | if self._default_save_location == None: |
---|
| 1843 | self._default_save_location = os.getcwd() |
---|
| 1844 | wx.PostEvent(self, StatusEvent(status="Loading Analysis file...")) |
---|
| 1845 | plug_wlist = self._on_open_state_app_helper() |
---|
[091e71a2] | 1846 | dlg = wx.FileDialog(self, |
---|
| 1847 | "Choose a file", |
---|
[f53cd30] | 1848 | self._default_save_location, "", |
---|
| 1849 | plug_wlist) |
---|
| 1850 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1851 | path = dlg.GetPath() |
---|
| 1852 | if path is not None: |
---|
| 1853 | self._default_save_location = os.path.dirname(path) |
---|
| 1854 | dlg.Destroy() |
---|
[091e71a2] | 1855 | self.load_state(path=path) |
---|
| 1856 | |
---|
[f53cd30] | 1857 | def _on_open_state_app_helper(self): |
---|
| 1858 | """ |
---|
[091e71a2] | 1859 | Helps '_on_open_state_application()' to find the extension of |
---|
[f53cd30] | 1860 | the current perspective/application |
---|
| 1861 | """ |
---|
| 1862 | # No current perspective or no extension attr |
---|
| 1863 | if self._current_perspective is None: |
---|
[091e71a2] | 1864 | return PLUGINS_WLIST |
---|
[f53cd30] | 1865 | try: |
---|
[091e71a2] | 1866 | # Find the extension of the perspective |
---|
[f53cd30] | 1867 | # and get that as 1st item in list |
---|
| 1868 | ind = None |
---|
| 1869 | app_ext = self._current_perspective._extensions |
---|
| 1870 | plug_wlist = config.PLUGINS_WLIST |
---|
| 1871 | for ext in set(plug_wlist): |
---|
| 1872 | if ext.count(app_ext) > 0: |
---|
| 1873 | ind = ext |
---|
| 1874 | break |
---|
| 1875 | # Found the extension |
---|
| 1876 | if ind != None: |
---|
| 1877 | plug_wlist.remove(ind) |
---|
| 1878 | plug_wlist.insert(0, ind) |
---|
| 1879 | try: |
---|
| 1880 | plug_wlist = '|'.join(plug_wlist) |
---|
| 1881 | except: |
---|
| 1882 | plug_wlist = '' |
---|
| 1883 | |
---|
| 1884 | except: |
---|
[091e71a2] | 1885 | plug_wlist = PLUGINS_WLIST |
---|
| 1886 | |
---|
[f53cd30] | 1887 | return plug_wlist |
---|
[091e71a2] | 1888 | |
---|
[f53cd30] | 1889 | def _on_open_state_project(self, event): |
---|
| 1890 | """ |
---|
| 1891 | """ |
---|
| 1892 | path = None |
---|
| 1893 | if self._default_save_location == None: |
---|
| 1894 | self._default_save_location = os.getcwd() |
---|
| 1895 | wx.PostEvent(self, StatusEvent(status="Loading Project file...")) |
---|
[091e71a2] | 1896 | dlg = wx.FileDialog(self, |
---|
| 1897 | "Choose a file", |
---|
[f53cd30] | 1898 | self._default_save_location, "", |
---|
[091e71a2] | 1899 | APPLICATION_WLIST) |
---|
[f53cd30] | 1900 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1901 | path = dlg.GetPath() |
---|
| 1902 | if path is not None: |
---|
| 1903 | self._default_save_location = os.path.dirname(path) |
---|
| 1904 | dlg.Destroy() |
---|
[091e71a2] | 1905 | |
---|
[f53cd30] | 1906 | self.load_state(path=path, is_project=True) |
---|
[091e71a2] | 1907 | |
---|
[f53cd30] | 1908 | def _on_save_application(self, event): |
---|
| 1909 | """ |
---|
| 1910 | save the state of the current active application |
---|
| 1911 | """ |
---|
| 1912 | if self.cpanel_on_focus is not None: |
---|
| 1913 | try: |
---|
[091e71a2] | 1914 | wx.PostEvent(self, |
---|
[f53cd30] | 1915 | StatusEvent(status="Saving Analysis file...")) |
---|
| 1916 | self.cpanel_on_focus.on_save(event) |
---|
[091e71a2] | 1917 | wx.PostEvent(self, |
---|
[f53cd30] | 1918 | StatusEvent(status="Completed saving.")) |
---|
| 1919 | except: |
---|
| 1920 | msg = "Error occurred while saving: " |
---|
| 1921 | msg += "To save, the application panel should have a data set.." |
---|
[091e71a2] | 1922 | wx.PostEvent(self, StatusEvent(status=msg)) |
---|
| 1923 | |
---|
[f53cd30] | 1924 | def _on_save_project(self, event): |
---|
| 1925 | """ |
---|
| 1926 | save the state of the SasView as *.svs |
---|
| 1927 | """ |
---|
| 1928 | if self._current_perspective is None: |
---|
| 1929 | return |
---|
| 1930 | wx.PostEvent(self, StatusEvent(status="Saving Project file...")) |
---|
| 1931 | path = None |
---|
| 1932 | extension = '*' + APPLICATION_STATE_EXTENSION |
---|
| 1933 | dlg = wx.FileDialog(self, "Save Project file", |
---|
| 1934 | self._default_save_location, "sasview_proj", |
---|
[091e71a2] | 1935 | extension, |
---|
| 1936 | wx.SAVE) |
---|
[f53cd30] | 1937 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1938 | path = dlg.GetPath() |
---|
| 1939 | self._default_save_location = os.path.dirname(path) |
---|
| 1940 | else: |
---|
| 1941 | return None |
---|
| 1942 | dlg.Destroy() |
---|
| 1943 | try: |
---|
| 1944 | if path is None: |
---|
| 1945 | return |
---|
| 1946 | # default cansas xml doc |
---|
| 1947 | doc = None |
---|
| 1948 | for panel in self.panels.values(): |
---|
| 1949 | temp = panel.save_project(doc) |
---|
| 1950 | if temp is not None: |
---|
| 1951 | doc = temp |
---|
[091e71a2] | 1952 | |
---|
[f53cd30] | 1953 | # Write the XML document |
---|
| 1954 | extens = APPLICATION_STATE_EXTENSION |
---|
| 1955 | fName = os.path.splitext(path)[0] + extens |
---|
| 1956 | if doc != None: |
---|
| 1957 | fd = open(fName, 'w') |
---|
| 1958 | fd.write(doc.toprettyxml()) |
---|
| 1959 | fd.close() |
---|
| 1960 | wx.PostEvent(self, StatusEvent(status="Completed Saving.")) |
---|
| 1961 | else: |
---|
| 1962 | msg = "Error occurred while saving the project: " |
---|
| 1963 | msg += "To save, at least one application panel " |
---|
| 1964 | msg += "should have a data set " |
---|
| 1965 | msg += "and model selected. " |
---|
| 1966 | msg += "No project was saved to %s" % (str(path)) |
---|
[5276eeb] | 1967 | logging.warning(msg) |
---|
| 1968 | wx.PostEvent(self, StatusEvent(status=msg, info="error")) |
---|
[f53cd30] | 1969 | except: |
---|
| 1970 | msg = "Error occurred while saving: " |
---|
| 1971 | msg += "To save, at least one application panel " |
---|
| 1972 | msg += "should have a data set.." |
---|
[5276eeb] | 1973 | wx.PostEvent(self, StatusEvent(status=msg, info="error")) |
---|
[091e71a2] | 1974 | |
---|
[f53cd30] | 1975 | def on_save_helper(self, doc, reader, panel, path): |
---|
| 1976 | """ |
---|
| 1977 | Save state into a file |
---|
| 1978 | """ |
---|
[091e71a2] | 1979 | if reader is not None: |
---|
| 1980 | # case of a panel with multi-pages |
---|
| 1981 | if hasattr(panel, "opened_pages"): |
---|
| 1982 | for _, page in panel.opened_pages.iteritems(): |
---|
| 1983 | data = page.get_data() |
---|
| 1984 | # state must be cloned |
---|
| 1985 | state = page.get_state().clone() |
---|
[f53cd30] | 1986 | if data is not None: |
---|
| 1987 | new_doc = reader.write_toXML(data, state) |
---|
| 1988 | if doc != None and hasattr(doc, "firstChild"): |
---|
| 1989 | child = new_doc.firstChild.firstChild |
---|
[091e71a2] | 1990 | doc.firstChild.appendChild(child) |
---|
[f53cd30] | 1991 | else: |
---|
[091e71a2] | 1992 | doc = new_doc |
---|
| 1993 | # case of only a panel |
---|
| 1994 | else: |
---|
| 1995 | data = panel.get_data() |
---|
| 1996 | state = panel.get_state() |
---|
| 1997 | if data is not None: |
---|
| 1998 | new_doc = reader.write_toXML(data, state) |
---|
| 1999 | if doc != None and hasattr(doc, "firstChild"): |
---|
| 2000 | child = new_doc.firstChild.firstChild |
---|
| 2001 | doc.firstChild.appendChild(child) |
---|
| 2002 | else: |
---|
| 2003 | doc = new_doc |
---|
[f53cd30] | 2004 | return doc |
---|
| 2005 | |
---|
| 2006 | def quit_guiframe(self): |
---|
| 2007 | """ |
---|
| 2008 | Pop up message to make sure the user wants to quit the application |
---|
| 2009 | """ |
---|
| 2010 | message = "\nDo you really want to exit this application? \n\n" |
---|
| 2011 | dial = wx.MessageDialog(self, message, 'Confirm Exit', |
---|
[091e71a2] | 2012 | wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION) |
---|
[f53cd30] | 2013 | if dial.ShowModal() == wx.ID_YES: |
---|
| 2014 | return True |
---|
| 2015 | else: |
---|
[091e71a2] | 2016 | return False |
---|
| 2017 | |
---|
[f53cd30] | 2018 | def WindowClose(self, event=None): |
---|
| 2019 | """ |
---|
| 2020 | Quit the application from x icon |
---|
| 2021 | """ |
---|
| 2022 | flag = self.quit_guiframe() |
---|
| 2023 | if flag: |
---|
| 2024 | _pylab_helpers.Gcf.figs = {} |
---|
| 2025 | self.Close() |
---|
[091e71a2] | 2026 | |
---|
[f53cd30] | 2027 | def Close(self, event=None): |
---|
| 2028 | """ |
---|
| 2029 | Quit the application |
---|
| 2030 | """ |
---|
[415fb82] | 2031 | logging.info(" --- SasView session was closed --- \n") |
---|
[f53cd30] | 2032 | wx.Exit() |
---|
| 2033 | sys.exit() |
---|
[091e71a2] | 2034 | |
---|
| 2035 | def _check_update(self, event=None): |
---|
[f53cd30] | 2036 | """ |
---|
| 2037 | Check with the deployment server whether a new version |
---|
| 2038 | of the application is available. |
---|
| 2039 | A thread is started for the connecting with the server. The thread calls |
---|
| 2040 | a call-back method when the current version number has been obtained. |
---|
| 2041 | """ |
---|
| 2042 | try: |
---|
[091e71a2] | 2043 | conn = httplib.HTTPConnection(config.__update_URL__[0], |
---|
| 2044 | timeout=3.0) |
---|
[f53cd30] | 2045 | conn.request("GET", config.__update_URL__[1]) |
---|
| 2046 | res = conn.getresponse() |
---|
| 2047 | content = res.read() |
---|
| 2048 | conn.close() |
---|
| 2049 | except: |
---|
| 2050 | content = "0.0.0" |
---|
[091e71a2] | 2051 | |
---|
[f53cd30] | 2052 | version = content.strip() |
---|
| 2053 | if len(re.findall('\d+\.\d+\.\d+$', version)) < 0: |
---|
| 2054 | content = "0.0.0" |
---|
[091e71a2] | 2055 | self._process_version(content, standalone=event == None) |
---|
| 2056 | |
---|
[f53cd30] | 2057 | def _process_version(self, version, standalone=True): |
---|
| 2058 | """ |
---|
| 2059 | Call-back method for the process of checking for updates. |
---|
| 2060 | This methods is called by a VersionThread object once the current |
---|
| 2061 | version number has been obtained. If the check is being done in the |
---|
| 2062 | background, the user will not be notified unless there's an update. |
---|
[091e71a2] | 2063 | |
---|
[f53cd30] | 2064 | :param version: version string |
---|
[091e71a2] | 2065 | :param standalone: True of the update is being checked in |
---|
[f53cd30] | 2066 | the background, False otherwise. |
---|
[091e71a2] | 2067 | |
---|
[f53cd30] | 2068 | """ |
---|
| 2069 | try: |
---|
| 2070 | if version == "0.0.0": |
---|
| 2071 | msg = "Could not connect to the application server." |
---|
| 2072 | msg += " Please try again later." |
---|
| 2073 | self.SetStatusText(msg) |
---|
| 2074 | elif cmp(version, config.__version__) > 0: |
---|
| 2075 | msg = "Version %s is available! " % str(version) |
---|
| 2076 | if not standalone: |
---|
| 2077 | import webbrowser |
---|
| 2078 | webbrowser.open(config.__download_page__) |
---|
| 2079 | else: |
---|
[091e71a2] | 2080 | msg += "See the help menu to download it." |
---|
[f53cd30] | 2081 | self.SetStatusText(msg) |
---|
| 2082 | else: |
---|
| 2083 | if not standalone: |
---|
| 2084 | msg = "You have the latest version" |
---|
| 2085 | msg += " of %s" % str(config.__appname__) |
---|
| 2086 | self.SetStatusText(msg) |
---|
| 2087 | except: |
---|
| 2088 | msg = "guiframe: could not get latest application" |
---|
| 2089 | msg += " version number\n %s" % sys.exc_value |
---|
| 2090 | logging.error(msg) |
---|
| 2091 | if not standalone: |
---|
| 2092 | msg = "Could not connect to the application server." |
---|
| 2093 | msg += " Please try again later." |
---|
| 2094 | self.SetStatusText(msg) |
---|
[091e71a2] | 2095 | |
---|
[f53cd30] | 2096 | def _onAcknowledge(self, evt): |
---|
| 2097 | """ |
---|
| 2098 | Pop up the acknowledge dialog |
---|
[091e71a2] | 2099 | |
---|
[f53cd30] | 2100 | :param evt: menu event |
---|
[091e71a2] | 2101 | |
---|
[f53cd30] | 2102 | """ |
---|
| 2103 | if config._do_acknowledge: |
---|
| 2104 | import sas.guiframe.acknowledgebox as AcknowledgeBox |
---|
| 2105 | dialog = AcknowledgeBox.DialogAcknowledge(None, -1, "") |
---|
| 2106 | dialog.ShowModal() |
---|
[091e71a2] | 2107 | |
---|
[f53cd30] | 2108 | def _onAbout(self, evt): |
---|
| 2109 | """ |
---|
| 2110 | Pop up the about dialog |
---|
[091e71a2] | 2111 | |
---|
[f53cd30] | 2112 | :param evt: menu event |
---|
[091e71a2] | 2113 | |
---|
[f53cd30] | 2114 | """ |
---|
| 2115 | if config._do_aboutbox: |
---|
| 2116 | import sas.guiframe.aboutbox as AboutBox |
---|
| 2117 | dialog = AboutBox.DialogAbout(None, -1, "") |
---|
[091e71a2] | 2118 | dialog.ShowModal() |
---|
| 2119 | |
---|
[f53cd30] | 2120 | def _onTutorial(self, evt): |
---|
| 2121 | """ |
---|
| 2122 | Pop up the tutorial dialog |
---|
[091e71a2] | 2123 | |
---|
[f53cd30] | 2124 | :param evt: menu event |
---|
[091e71a2] | 2125 | |
---|
[f53cd30] | 2126 | """ |
---|
[091e71a2] | 2127 | if config._do_tutorial: |
---|
[f53cd30] | 2128 | path = config.TUTORIAL_PATH |
---|
| 2129 | if IS_WIN: |
---|
| 2130 | try: |
---|
| 2131 | from sas.guiframe.pdfview import PDFFrame |
---|
| 2132 | dialog = PDFFrame(None, -1, "Tutorial", path) |
---|
| 2133 | # put icon |
---|
[091e71a2] | 2134 | self.put_icon(dialog) |
---|
| 2135 | dialog.Show(True) |
---|
[f53cd30] | 2136 | except: |
---|
| 2137 | logging.error("Error in _onTutorial: %s" % sys.exc_value) |
---|
| 2138 | try: |
---|
| 2139 | # Try an alternate method |
---|
| 2140 | logging.error("Could not open the tutorial pdf, trying xhtml2pdf") |
---|
| 2141 | from xhtml2pdf import pisa |
---|
| 2142 | pisa.startViewer(path) |
---|
| 2143 | except: |
---|
| 2144 | logging.error("Could not open the tutorial pdf with xhtml2pdf") |
---|
| 2145 | msg = "This feature requires 'PDF Viewer'\n" |
---|
| 2146 | wx.MessageBox(msg, 'Error') |
---|
| 2147 | else: |
---|
| 2148 | try: |
---|
| 2149 | command = "open '%s'" % path |
---|
| 2150 | os.system(command) |
---|
| 2151 | except: |
---|
| 2152 | try: |
---|
| 2153 | # Try an alternate method |
---|
| 2154 | logging.error("Could not open the tutorial pdf, trying xhtml2pdf") |
---|
| 2155 | from xhtml2pdf import pisa |
---|
| 2156 | pisa.startViewer(path) |
---|
| 2157 | except: |
---|
| 2158 | logging.error("Could not open the tutorial pdf with xhtml2pdf") |
---|
| 2159 | msg = "This feature requires the 'Preview' application\n" |
---|
| 2160 | wx.MessageBox(msg, 'Error') |
---|
| 2161 | |
---|
| 2162 | def _onSphinxDocs(self, evt): |
---|
| 2163 | """ |
---|
| 2164 | Bring up Sphinx Documentation at top level whenever the menu item |
---|
| 2165 | 'documentation' is clicked. Calls DocumentationWindow with the top |
---|
| 2166 | level path of "index.html" |
---|
[091e71a2] | 2167 | |
---|
[f53cd30] | 2168 | :param evt: menu event |
---|
| 2169 | """ |
---|
| 2170 | # Running SasView "in-place" using run.py means the docs will be in a |
---|
| 2171 | # different place than they would otherwise. |
---|
[7801df8] | 2172 | from documentation_window import DocumentationWindow |
---|
[3db44fb] | 2173 | DocumentationWindow(self, -1, "index.html", "", "SasView Documentation") |
---|
[f53cd30] | 2174 | |
---|
| 2175 | def set_manager(self, manager): |
---|
| 2176 | """ |
---|
| 2177 | Sets the application manager for this frame |
---|
[091e71a2] | 2178 | |
---|
[f53cd30] | 2179 | :param manager: frame manager |
---|
| 2180 | """ |
---|
| 2181 | self.app_manager = manager |
---|
[091e71a2] | 2182 | |
---|
[f53cd30] | 2183 | def post_init(self): |
---|
| 2184 | """ |
---|
[091e71a2] | 2185 | This initialization method is called after the GUI |
---|
[f53cd30] | 2186 | has been created and all plug-ins loaded. It calls |
---|
| 2187 | the post_init() method of each plug-in (if it exists) |
---|
| 2188 | so that final initialization can be done. |
---|
| 2189 | """ |
---|
| 2190 | for item in self.plugins: |
---|
| 2191 | if hasattr(item, "post_init"): |
---|
| 2192 | item.post_init() |
---|
[091e71a2] | 2193 | |
---|
[f53cd30] | 2194 | def set_default_perspective(self): |
---|
| 2195 | """ |
---|
[091e71a2] | 2196 | Choose among the plugin the first plug-in that has |
---|
[f53cd30] | 2197 | "set_default_perspective" method and its return value is True will be |
---|
| 2198 | as a default perspective when the welcome page is closed |
---|
| 2199 | """ |
---|
| 2200 | for item in self.plugins: |
---|
| 2201 | if hasattr(item, "set_default_perspective"): |
---|
| 2202 | if item.set_default_perspective(): |
---|
| 2203 | item.on_perspective(event=None) |
---|
[091e71a2] | 2204 | return |
---|
| 2205 | |
---|
[f53cd30] | 2206 | def set_perspective(self, panels): |
---|
| 2207 | """ |
---|
| 2208 | Sets the perspective of the GUI. |
---|
| 2209 | Opens all the panels in the list, and closes |
---|
| 2210 | all the others. |
---|
[091e71a2] | 2211 | |
---|
[f53cd30] | 2212 | :param panels: list of panels |
---|
| 2213 | """ |
---|
| 2214 | for item in self.panels.keys(): |
---|
| 2215 | # Check whether this is a sticky panel |
---|
| 2216 | if hasattr(self.panels[item], "ALWAYS_ON"): |
---|
| 2217 | if self.panels[item].ALWAYS_ON: |
---|
[091e71a2] | 2218 | continue |
---|
[f53cd30] | 2219 | if self.panels[item] == None: |
---|
| 2220 | continue |
---|
| 2221 | if self.panels[item].window_name in panels: |
---|
| 2222 | frame = self.panels[item].get_frame() |
---|
| 2223 | if not frame.IsShown(): |
---|
| 2224 | frame.Show(True) |
---|
| 2225 | else: |
---|
| 2226 | # always show the data panel if enable |
---|
| 2227 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 2228 | if (style == GUIFRAME.MANAGER_ON) and self.panels[item] == self._data_panel: |
---|
| 2229 | if 'data_panel' in self.panels.keys(): |
---|
| 2230 | frame = self.panels['data_panel'].get_frame() |
---|
| 2231 | if frame == None: |
---|
| 2232 | continue |
---|
| 2233 | flag = frame.IsShown() |
---|
| 2234 | frame.Show(flag) |
---|
| 2235 | else: |
---|
| 2236 | frame = self.panels[item].get_frame() |
---|
| 2237 | if frame == None: |
---|
| 2238 | continue |
---|
| 2239 | |
---|
| 2240 | if frame.IsShown(): |
---|
| 2241 | frame.Show(False) |
---|
[091e71a2] | 2242 | |
---|
[f53cd30] | 2243 | def show_data_panel(self, event=None, action=True): |
---|
| 2244 | """ |
---|
| 2245 | show the data panel |
---|
| 2246 | """ |
---|
| 2247 | if self._data_panel_menu == None: |
---|
| 2248 | return |
---|
| 2249 | label = self._data_panel_menu.GetText() |
---|
| 2250 | pane = self.panels["data_panel"] |
---|
| 2251 | frame = pane.get_frame() |
---|
| 2252 | if label == 'Show Data Explorer': |
---|
[091e71a2] | 2253 | if action: |
---|
[f53cd30] | 2254 | frame.Show(True) |
---|
| 2255 | self.__gui_style = self.__gui_style | GUIFRAME.MANAGER_ON |
---|
| 2256 | self._data_panel_menu.SetText('Hide Data Explorer') |
---|
| 2257 | else: |
---|
| 2258 | if action: |
---|
| 2259 | frame.Show(False) |
---|
| 2260 | self.__gui_style = self.__gui_style & (~GUIFRAME.MANAGER_ON) |
---|
| 2261 | self._data_panel_menu.SetText('Show Data Explorer') |
---|
| 2262 | |
---|
| 2263 | def add_data_helper(self, data_list): |
---|
| 2264 | """ |
---|
| 2265 | """ |
---|
| 2266 | if self._data_manager is not None: |
---|
| 2267 | self._data_manager.add_data(data_list) |
---|
[091e71a2] | 2268 | |
---|
[f53cd30] | 2269 | def add_data(self, data_list): |
---|
| 2270 | """ |
---|
| 2271 | receive a dictionary of data from loader |
---|
| 2272 | store them its data manager if possible |
---|
[091e71a2] | 2273 | send to data the current active perspective if the data panel |
---|
| 2274 | is not active. |
---|
[f53cd30] | 2275 | :param data_list: dictionary of data's ID and value Data |
---|
| 2276 | """ |
---|
| 2277 | #Store data into manager |
---|
| 2278 | self.add_data_helper(data_list) |
---|
| 2279 | # set data in the data panel |
---|
| 2280 | if self._data_panel is not None: |
---|
| 2281 | data_state = self._data_manager.get_data_state(data_list.keys()) |
---|
| 2282 | self._data_panel.load_data_list(data_state) |
---|
[091e71a2] | 2283 | #if the data panel is shown wait for the user to press a button |
---|
[f53cd30] | 2284 | #to send data to the current perspective. if the panel is not |
---|
| 2285 | #show automatically send the data to the current perspective |
---|
| 2286 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 2287 | if style == GUIFRAME.MANAGER_ON: |
---|
[091e71a2] | 2288 | #wait for button press from the data panel to set_data |
---|
[f53cd30] | 2289 | if self._data_panel is not None: |
---|
| 2290 | self._data_panel.frame.Show(True) |
---|
| 2291 | else: |
---|
| 2292 | #automatically send that to the current perspective |
---|
| 2293 | self.set_data(data_id=data_list.keys()) |
---|
[091e71a2] | 2294 | |
---|
| 2295 | def set_data(self, data_id, theory_id=None): |
---|
[f53cd30] | 2296 | """ |
---|
| 2297 | set data to current perspective |
---|
| 2298 | """ |
---|
| 2299 | list_data, _ = self._data_manager.get_by_id(data_id) |
---|
| 2300 | if self._current_perspective is not None: |
---|
| 2301 | self._current_perspective.set_data(list_data.values()) |
---|
| 2302 | |
---|
| 2303 | else: |
---|
| 2304 | msg = "Guiframe does not have a current perspective" |
---|
| 2305 | logging.info(msg) |
---|
[091e71a2] | 2306 | |
---|
[f53cd30] | 2307 | def set_theory(self, state_id, theory_id=None): |
---|
| 2308 | """ |
---|
| 2309 | """ |
---|
| 2310 | _, list_theory = self._data_manager.get_by_id(theory_id) |
---|
| 2311 | if self._current_perspective is not None: |
---|
| 2312 | try: |
---|
| 2313 | self._current_perspective.set_theory(list_theory.values()) |
---|
| 2314 | except: |
---|
| 2315 | msg = "Guiframe set_theory: \n" + str(sys.exc_value) |
---|
| 2316 | logging.info(msg) |
---|
| 2317 | wx.PostEvent(self, StatusEvent(status=msg, info="error")) |
---|
| 2318 | else: |
---|
| 2319 | msg = "Guiframe does not have a current perspective" |
---|
| 2320 | logging.info(msg) |
---|
[091e71a2] | 2321 | |
---|
| 2322 | def plot_data(self, state_id, data_id=None, |
---|
[f53cd30] | 2323 | theory_id=None, append=False): |
---|
| 2324 | """ |
---|
| 2325 | send a list of data to plot |
---|
| 2326 | """ |
---|
| 2327 | data_list, _ = self._data_manager.get_by_id(data_id) |
---|
| 2328 | _, temp_list_theory = self._data_manager.get_by_id(theory_id) |
---|
| 2329 | total_plot_list = data_list.values() |
---|
| 2330 | for item in temp_list_theory.values(): |
---|
| 2331 | theory_data, theory_state = item |
---|
| 2332 | total_plot_list.append(theory_data) |
---|
| 2333 | GROUP_ID = wx.NewId() |
---|
| 2334 | for new_plot in total_plot_list: |
---|
| 2335 | if append: |
---|
| 2336 | if self.panel_on_focus is None: |
---|
| 2337 | message = "cannot append plot. No plot panel on focus!" |
---|
| 2338 | message += "please click on any available plot to set focus" |
---|
[091e71a2] | 2339 | wx.PostEvent(self, StatusEvent(status=message, |
---|
[f53cd30] | 2340 | info='warning')) |
---|
[091e71a2] | 2341 | return |
---|
[f53cd30] | 2342 | else: |
---|
| 2343 | if self.enable_add_data(new_plot): |
---|
| 2344 | new_plot.group_id = self.panel_on_focus.group_id |
---|
| 2345 | else: |
---|
| 2346 | message = "Only 1D Data can be append to" |
---|
| 2347 | message += " plot panel containing 1D data.\n" |
---|
[091e71a2] | 2348 | message += "%s not be appended.\n" % str(new_plot.name) |
---|
[f53cd30] | 2349 | message += "try new plot option.\n" |
---|
[091e71a2] | 2350 | wx.PostEvent(self, StatusEvent(status=message, |
---|
| 2351 | info='warning')) |
---|
[f53cd30] | 2352 | else: |
---|
| 2353 | #if not append then new plot |
---|
| 2354 | from sas.guiframe.dataFitting import Data2D |
---|
| 2355 | if issubclass(Data2D, new_plot.__class__): |
---|
| 2356 | #for 2 D always plot in a separated new plot |
---|
| 2357 | new_plot.group_id = wx.NewId() |
---|
| 2358 | else: |
---|
| 2359 | # plot all 1D in a new plot |
---|
| 2360 | new_plot.group_id = GROUP_ID |
---|
| 2361 | title = "PLOT " + str(new_plot.title) |
---|
| 2362 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
[091e71a2] | 2363 | title=title, |
---|
| 2364 | group_id=new_plot.group_id)) |
---|
| 2365 | |
---|
[f53cd30] | 2366 | def remove_data(self, data_id, theory_id=None): |
---|
| 2367 | """ |
---|
| 2368 | Delete data state if data_id is provide |
---|
| 2369 | delete theory created with data of id data_id if theory_id is provide |
---|
| 2370 | if delete all true: delete the all state |
---|
| 2371 | else delete theory |
---|
| 2372 | """ |
---|
| 2373 | temp = data_id + theory_id |
---|
| 2374 | for plug in self.plugins: |
---|
| 2375 | plug.delete_data(temp) |
---|
| 2376 | data_list, _ = self._data_manager.get_by_id(data_id) |
---|
| 2377 | _, temp_list_theory = self._data_manager.get_by_id(theory_id) |
---|
| 2378 | total_plot_list = data_list.values() |
---|
| 2379 | for item in temp_list_theory.values(): |
---|
| 2380 | theory_data, theory_state = item |
---|
| 2381 | total_plot_list.append(theory_data) |
---|
| 2382 | for new_plot in total_plot_list: |
---|
| 2383 | id = new_plot.id |
---|
| 2384 | for group_id in new_plot.list_group_id: |
---|
| 2385 | wx.PostEvent(self, NewPlotEvent(id=id, |
---|
[091e71a2] | 2386 | group_id=group_id, |
---|
| 2387 | action='remove')) |
---|
[f53cd30] | 2388 | #remove res plot: Todo: improve |
---|
| 2389 | wx.CallAfter(self._remove_res_plot, id) |
---|
[091e71a2] | 2390 | self._data_manager.delete_data(data_id=data_id, |
---|
[f53cd30] | 2391 | theory_id=theory_id) |
---|
[091e71a2] | 2392 | |
---|
[f53cd30] | 2393 | def _remove_res_plot(self, id): |
---|
| 2394 | """ |
---|
| 2395 | Try to remove corresponding res plot |
---|
[091e71a2] | 2396 | |
---|
[f53cd30] | 2397 | : param id: id of the data |
---|
| 2398 | """ |
---|
| 2399 | try: |
---|
[091e71a2] | 2400 | wx.PostEvent(self, NewPlotEvent(id=("res" + str(id)), |
---|
| 2401 | group_id=("res" + str(id)), |
---|
| 2402 | action='remove')) |
---|
[f53cd30] | 2403 | except: |
---|
[091e71a2] | 2404 | logging.error(sys.exc_value) |
---|
| 2405 | |
---|
[f53cd30] | 2406 | def save_data1d(self, data, fname): |
---|
| 2407 | """ |
---|
| 2408 | Save data dialog |
---|
| 2409 | """ |
---|
| 2410 | default_name = fname |
---|
| 2411 | wildcard = "Text files (*.txt)|*.txt|"\ |
---|
[091e71a2] | 2412 | "CanSAS 1D files(*.xml)|*.xml" |
---|
[f53cd30] | 2413 | path = None |
---|
| 2414 | dlg = wx.FileDialog(self, "Choose a file", |
---|
| 2415 | self._default_save_location, |
---|
[091e71a2] | 2416 | default_name, wildcard, wx.SAVE) |
---|
| 2417 | |
---|
[f53cd30] | 2418 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 2419 | path = dlg.GetPath() |
---|
| 2420 | # ext_num = 0 for .txt, ext_num = 1 for .xml |
---|
| 2421 | # This is MAC Fix |
---|
| 2422 | ext_num = dlg.GetFilterIndex() |
---|
| 2423 | if ext_num == 0: |
---|
| 2424 | format = '.txt' |
---|
| 2425 | else: |
---|
| 2426 | format = '.xml' |
---|
| 2427 | path = os.path.splitext(path)[0] + format |
---|
| 2428 | mypath = os.path.basename(path) |
---|
[091e71a2] | 2429 | |
---|
| 2430 | #Instantiate a loader |
---|
| 2431 | loader = Loader() |
---|
[f53cd30] | 2432 | format = ".txt" |
---|
| 2433 | if os.path.splitext(mypath)[1].lower() == format: |
---|
| 2434 | # Make sure the ext included in the file name |
---|
| 2435 | # especially on MAC |
---|
| 2436 | fName = os.path.splitext(path)[0] + format |
---|
| 2437 | self._onsaveTXT(data, fName) |
---|
| 2438 | format = ".xml" |
---|
| 2439 | if os.path.splitext(mypath)[1].lower() == format: |
---|
| 2440 | # Make sure the ext included in the file name |
---|
| 2441 | # especially on MAC |
---|
| 2442 | fName = os.path.splitext(path)[0] + format |
---|
| 2443 | loader.save(fName, data, format) |
---|
| 2444 | try: |
---|
| 2445 | self._default_save_location = os.path.dirname(path) |
---|
| 2446 | except: |
---|
[091e71a2] | 2447 | pass |
---|
[f53cd30] | 2448 | dlg.Destroy() |
---|
[091e71a2] | 2449 | |
---|
| 2450 | |
---|
[f53cd30] | 2451 | def _onsaveTXT(self, data, path): |
---|
| 2452 | """ |
---|
[091e71a2] | 2453 | Save file as txt |
---|
[f53cd30] | 2454 | :TODO: Refactor and remove this method. See TODO in _onSave. |
---|
| 2455 | """ |
---|
| 2456 | if not path == None: |
---|
| 2457 | out = open(path, 'w') |
---|
| 2458 | has_errors = True |
---|
| 2459 | if data.dy == None or data.dy == []: |
---|
| 2460 | has_errors = False |
---|
| 2461 | # Sanity check |
---|
| 2462 | if has_errors: |
---|
| 2463 | try: |
---|
| 2464 | if len(data.y) != len(data.dy): |
---|
| 2465 | has_errors = False |
---|
| 2466 | except: |
---|
| 2467 | has_errors = False |
---|
| 2468 | if has_errors: |
---|
| 2469 | if data.dx != None and data.dx != []: |
---|
| 2470 | out.write("<X> <Y> <dY> <dX>\n") |
---|
| 2471 | else: |
---|
| 2472 | out.write("<X> <Y> <dY>\n") |
---|
| 2473 | else: |
---|
| 2474 | out.write("<X> <Y>\n") |
---|
[091e71a2] | 2475 | |
---|
[f53cd30] | 2476 | for i in range(len(data.x)): |
---|
| 2477 | if has_errors: |
---|
| 2478 | if data.dx != None and data.dx != []: |
---|
| 2479 | if data.dx[i] != None: |
---|
[091e71a2] | 2480 | out.write("%g %g %g %g\n" % (data.x[i], |
---|
| 2481 | data.y[i], |
---|
| 2482 | data.dy[i], |
---|
| 2483 | data.dx[i])) |
---|
[f53cd30] | 2484 | else: |
---|
[091e71a2] | 2485 | out.write("%g %g %g\n" % (data.x[i], |
---|
[f53cd30] | 2486 | data.y[i], |
---|
| 2487 | data.dy[i])) |
---|
| 2488 | else: |
---|
[091e71a2] | 2489 | out.write("%g %g %g\n" % (data.x[i], |
---|
[f53cd30] | 2490 | data.y[i], |
---|
| 2491 | data.dy[i])) |
---|
| 2492 | else: |
---|
[091e71a2] | 2493 | out.write("%g %g\n" % (data.x[i], |
---|
[f53cd30] | 2494 | data.y[i])) |
---|
[091e71a2] | 2495 | out.close() |
---|
| 2496 | |
---|
[f53cd30] | 2497 | def show_data1d(self, data, name): |
---|
| 2498 | """ |
---|
| 2499 | Show data dialog |
---|
[091e71a2] | 2500 | """ |
---|
[f53cd30] | 2501 | try: |
---|
| 2502 | xmin = min(data.x) |
---|
| 2503 | ymin = min(data.y) |
---|
| 2504 | except: |
---|
[091e71a2] | 2505 | msg = "Unable to find min/max of \n data named %s" % \ |
---|
| 2506 | data.filename |
---|
[f53cd30] | 2507 | wx.PostEvent(self, StatusEvent(status=msg, |
---|
[091e71a2] | 2508 | info="error")) |
---|
[f53cd30] | 2509 | raise ValueError, msg |
---|
| 2510 | ## text = str(data) |
---|
| 2511 | text = data.__str__() |
---|
| 2512 | text += 'Data Min Max:\n' |
---|
[091e71a2] | 2513 | text += 'X_min = %s: X_max = %s\n' % (xmin, max(data.x)) |
---|
| 2514 | text += 'Y_min = %s: Y_max = %s\n' % (ymin, max(data.y)) |
---|
[f53cd30] | 2515 | if data.dy != None: |
---|
[091e71a2] | 2516 | text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy)) |
---|
[f53cd30] | 2517 | text += '\nData Points:\n' |
---|
| 2518 | x_st = "X" |
---|
| 2519 | for index in range(len(data.x)): |
---|
| 2520 | if data.dy != None and len(data.dy) > index: |
---|
| 2521 | dy_val = data.dy[index] |
---|
| 2522 | else: |
---|
| 2523 | dy_val = 0.0 |
---|
| 2524 | if data.dx != None and len(data.dx) > index: |
---|
| 2525 | dx_val = data.dx[index] |
---|
| 2526 | else: |
---|
| 2527 | dx_val = 0.0 |
---|
| 2528 | if data.dxl != None and len(data.dxl) > index: |
---|
[091e71a2] | 2529 | if index == 0: |
---|
[f53cd30] | 2530 | x_st = "Xl" |
---|
| 2531 | dx_val = data.dxl[index] |
---|
| 2532 | elif data.dxw != None and len(data.dxw) > index: |
---|
[091e71a2] | 2533 | if index == 0: |
---|
[f53cd30] | 2534 | x_st = "Xw" |
---|
| 2535 | dx_val = data.dxw[index] |
---|
[091e71a2] | 2536 | |
---|
[f53cd30] | 2537 | if index == 0: |
---|
[091e71a2] | 2538 | text += "<index> \t<X> \t<Y> \t<dY> \t<d%s>\n" % x_st |
---|
[f53cd30] | 2539 | text += "%s \t%s \t%s \t%s \t%s\n" % (index, |
---|
[091e71a2] | 2540 | data.x[index], |
---|
| 2541 | data.y[index], |
---|
| 2542 | dy_val, |
---|
| 2543 | dx_val) |
---|
[f53cd30] | 2544 | from pdfview import TextFrame |
---|
[091e71a2] | 2545 | frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) |
---|
[f53cd30] | 2546 | # put icon |
---|
[091e71a2] | 2547 | self.put_icon(frame) |
---|
| 2548 | frame.Show(True) |
---|
| 2549 | |
---|
| 2550 | def save_data2d(self, data, fname): |
---|
[f53cd30] | 2551 | """ |
---|
| 2552 | Save data2d dialog |
---|
| 2553 | """ |
---|
| 2554 | default_name = fname |
---|
| 2555 | wildcard = "IGOR/DAT 2D file in Q_map (*.dat)|*.DAT" |
---|
| 2556 | dlg = wx.FileDialog(self, "Choose a file", |
---|
| 2557 | self._default_save_location, |
---|
[091e71a2] | 2558 | default_name, wildcard, wx.SAVE) |
---|
| 2559 | |
---|
[f53cd30] | 2560 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 2561 | path = dlg.GetPath() |
---|
| 2562 | # ext_num = 0 for .txt, ext_num = 1 for .xml |
---|
| 2563 | # This is MAC Fix |
---|
| 2564 | ext_num = dlg.GetFilterIndex() |
---|
| 2565 | if ext_num == 0: |
---|
| 2566 | format = '.dat' |
---|
| 2567 | else: |
---|
| 2568 | format = '' |
---|
| 2569 | path = os.path.splitext(path)[0] + format |
---|
| 2570 | mypath = os.path.basename(path) |
---|
[091e71a2] | 2571 | |
---|
| 2572 | #Instantiate a loader |
---|
| 2573 | loader = Loader() |
---|
[f53cd30] | 2574 | |
---|
| 2575 | format = ".dat" |
---|
| 2576 | if os.path.splitext(mypath)[1].lower() == format: |
---|
| 2577 | # Make sure the ext included in the file name |
---|
| 2578 | # especially on MAC |
---|
| 2579 | fileName = os.path.splitext(path)[0] + format |
---|
| 2580 | loader.save(fileName, data, format) |
---|
| 2581 | try: |
---|
| 2582 | self._default_save_location = os.path.dirname(path) |
---|
| 2583 | except: |
---|
[091e71a2] | 2584 | pass |
---|
| 2585 | dlg.Destroy() |
---|
| 2586 | |
---|
[f53cd30] | 2587 | def show_data2d(self, data, name): |
---|
| 2588 | """ |
---|
| 2589 | Show data dialog |
---|
[091e71a2] | 2590 | """ |
---|
| 2591 | wx.PostEvent(self, StatusEvent(status="Gathering Data2D Info.", |
---|
| 2592 | type='start')) |
---|
| 2593 | text = data.__str__() |
---|
[f53cd30] | 2594 | text += 'Data Min Max:\n' |
---|
[091e71a2] | 2595 | text += 'I_min = %s\n' % min(data.data) |
---|
| 2596 | text += 'I_max = %s\n\n' % max(data.data) |
---|
[f53cd30] | 2597 | text += 'Data (First 2501) Points:\n' |
---|
| 2598 | text += 'Data columns include err(I).\n' |
---|
| 2599 | text += 'ASCII data starts here.\n' |
---|
| 2600 | text += "<index> \t<Qx> \t<Qy> \t<I> \t<dI> \t<dQparal> \t<dQperp>\n" |
---|
| 2601 | di_val = 0.0 |
---|
| 2602 | dx_val = 0.0 |
---|
| 2603 | dy_val = 0.0 |
---|
| 2604 | len_data = len(data.qx_data) |
---|
| 2605 | for index in xrange(0, len_data): |
---|
| 2606 | x_val = data.qx_data[index] |
---|
| 2607 | y_val = data.qy_data[index] |
---|
| 2608 | i_val = data.data[index] |
---|
[091e71a2] | 2609 | if data.err_data != None: |
---|
[f53cd30] | 2610 | di_val = data.err_data[index] |
---|
[091e71a2] | 2611 | if data.dqx_data != None: |
---|
[f53cd30] | 2612 | dx_val = data.dqx_data[index] |
---|
[091e71a2] | 2613 | if data.dqy_data != None: |
---|
[f53cd30] | 2614 | dy_val = data.dqy_data[index] |
---|
[091e71a2] | 2615 | |
---|
[f53cd30] | 2616 | text += "%s \t%s \t%s \t%s \t%s \t%s \t%s\n" % (index, |
---|
[091e71a2] | 2617 | x_val, |
---|
| 2618 | y_val, |
---|
| 2619 | i_val, |
---|
| 2620 | di_val, |
---|
| 2621 | dx_val, |
---|
| 2622 | dy_val) |
---|
[f53cd30] | 2623 | # Takes too long time for typical data2d: Break here |
---|
| 2624 | if index >= 2500: |
---|
| 2625 | text += ".............\n" |
---|
| 2626 | break |
---|
| 2627 | |
---|
| 2628 | from pdfview import TextFrame |
---|
[091e71a2] | 2629 | frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) |
---|
[f53cd30] | 2630 | # put icon |
---|
| 2631 | self.put_icon(frame) |
---|
[091e71a2] | 2632 | frame.Show(True) |
---|
| 2633 | wx.PostEvent(self, StatusEvent(status="Data2D Info Displayed", |
---|
| 2634 | type='stop')) |
---|
| 2635 | |
---|
[f53cd30] | 2636 | def set_current_perspective(self, perspective): |
---|
| 2637 | """ |
---|
[091e71a2] | 2638 | set the current active perspective |
---|
[f53cd30] | 2639 | """ |
---|
| 2640 | self._current_perspective = perspective |
---|
| 2641 | name = "No current analysis selected" |
---|
| 2642 | if self._current_perspective is not None: |
---|
| 2643 | self._add_current_plugin_menu() |
---|
| 2644 | for panel in self.panels.values(): |
---|
| 2645 | if hasattr(panel, 'CENTER_PANE') and panel.CENTER_PANE: |
---|
| 2646 | for name in self._current_perspective.get_perspective(): |
---|
| 2647 | frame = panel.get_frame() |
---|
| 2648 | if frame != None: |
---|
| 2649 | if name == panel.window_name: |
---|
| 2650 | panel.on_set_focus(event=None) |
---|
| 2651 | frame.Show(True) |
---|
| 2652 | else: |
---|
| 2653 | frame.Show(False) |
---|
| 2654 | name = self._current_perspective.sub_menu |
---|
| 2655 | if self._data_panel is not None: |
---|
| 2656 | self._data_panel.set_active_perspective(name) |
---|
| 2657 | self._check_applications_menu() |
---|
| 2658 | #Set the SasView title |
---|
| 2659 | self._set_title_name(name) |
---|
[091e71a2] | 2660 | |
---|
[f53cd30] | 2661 | def _set_title_name(self, name): |
---|
| 2662 | """ |
---|
| 2663 | Set the SasView title w/ the current application name |
---|
[091e71a2] | 2664 | |
---|
[f53cd30] | 2665 | : param name: application name [string] |
---|
| 2666 | """ |
---|
| 2667 | # Set SanView Window title w/ application anme |
---|
| 2668 | title = self.title + " - " + name + " -" |
---|
| 2669 | self.SetTitle(title) |
---|
[091e71a2] | 2670 | |
---|
[f53cd30] | 2671 | def _check_applications_menu(self): |
---|
| 2672 | """ |
---|
| 2673 | check the menu of the current application |
---|
| 2674 | """ |
---|
| 2675 | if self._applications_menu is not None: |
---|
| 2676 | for menu in self._applications_menu.GetMenuItems(): |
---|
| 2677 | if self._current_perspective is not None: |
---|
| 2678 | name = self._current_perspective.sub_menu |
---|
| 2679 | if menu.IsCheckable(): |
---|
| 2680 | if menu.GetLabel() == name: |
---|
| 2681 | menu.Check(True) |
---|
| 2682 | else: |
---|
[091e71a2] | 2683 | menu.Check(False) |
---|
| 2684 | |
---|
[f53cd30] | 2685 | def enable_add_data(self, new_plot): |
---|
| 2686 | """ |
---|
| 2687 | Enable append data on a plot panel |
---|
| 2688 | """ |
---|
| 2689 | |
---|
| 2690 | if self.panel_on_focus not in self._plotting_plugin.plot_panels.values(): |
---|
| 2691 | return |
---|
| 2692 | is_theory = len(self.panel_on_focus.plots) <= 1 and \ |
---|
| 2693 | self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D" |
---|
[091e71a2] | 2694 | |
---|
[f53cd30] | 2695 | is_data2d = hasattr(new_plot, 'data') |
---|
[091e71a2] | 2696 | |
---|
[f53cd30] | 2697 | is_data1d = self.panel_on_focus.__class__.__name__ == "ModelPanel1D"\ |
---|
| 2698 | and self.panel_on_focus.group_id is not None |
---|
| 2699 | has_meta_data = hasattr(new_plot, 'meta_data') |
---|
[091e71a2] | 2700 | |
---|
[f53cd30] | 2701 | #disable_add_data if the data is being recovered from a saved state file. |
---|
| 2702 | is_state_data = False |
---|
| 2703 | if has_meta_data: |
---|
[091e71a2] | 2704 | if 'invstate' in new_plot.meta_data: |
---|
[f53cd30] | 2705 | is_state_data = True |
---|
[091e71a2] | 2706 | if 'prstate' in new_plot.meta_data: |
---|
[f53cd30] | 2707 | is_state_data = True |
---|
[091e71a2] | 2708 | if 'fitstate' in new_plot.meta_data: |
---|
[f53cd30] | 2709 | is_state_data = True |
---|
[091e71a2] | 2710 | |
---|
[f53cd30] | 2711 | return is_data1d and not is_data2d and not is_theory and not is_state_data |
---|
[091e71a2] | 2712 | |
---|
[f53cd30] | 2713 | def check_multimode(self, perspective=None): |
---|
| 2714 | """ |
---|
| 2715 | Check the perspective have batch mode capablitity |
---|
| 2716 | """ |
---|
| 2717 | if perspective == None or self._data_panel == None: |
---|
| 2718 | return |
---|
| 2719 | flag = perspective.get_batch_capable() |
---|
| 2720 | flag_on = perspective.batch_on |
---|
| 2721 | if flag: |
---|
| 2722 | self._data_panel.rb_single_mode.SetValue(not flag_on) |
---|
| 2723 | self._data_panel.rb_batch_mode.SetValue(flag_on) |
---|
| 2724 | else: |
---|
| 2725 | self._data_panel.rb_single_mode.SetValue(True) |
---|
| 2726 | self._data_panel.rb_batch_mode.SetValue(False) |
---|
| 2727 | self._data_panel.rb_single_mode.Enable(flag) |
---|
| 2728 | self._data_panel.rb_batch_mode.Enable(flag) |
---|
| 2729 | |
---|
| 2730 | def enable_edit_menu(self): |
---|
| 2731 | """ |
---|
| 2732 | enable menu item under edit menu depending on the panel on focus |
---|
| 2733 | """ |
---|
| 2734 | if self.cpanel_on_focus is not None and self._edit_menu is not None: |
---|
| 2735 | flag = self.cpanel_on_focus.get_undo_flag() |
---|
| 2736 | self._edit_menu.Enable(GUIFRAME_ID.UNDO_ID, flag) |
---|
| 2737 | flag = self.cpanel_on_focus.get_redo_flag() |
---|
| 2738 | self._edit_menu.Enable(GUIFRAME_ID.REDO_ID, flag) |
---|
| 2739 | flag = self.cpanel_on_focus.get_copy_flag() |
---|
| 2740 | self._edit_menu.Enable(GUIFRAME_ID.COPY_ID, flag) |
---|
| 2741 | flag = self.cpanel_on_focus.get_paste_flag() |
---|
| 2742 | self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) |
---|
| 2743 | |
---|
| 2744 | #Copy menu |
---|
| 2745 | flag = self.cpanel_on_focus.get_copy_flag() |
---|
| 2746 | self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYEX_ID, flag) |
---|
| 2747 | self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYLAT_ID, flag) |
---|
| 2748 | |
---|
| 2749 | flag = self.cpanel_on_focus.get_preview_flag() |
---|
| 2750 | self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) |
---|
| 2751 | flag = self.cpanel_on_focus.get_reset_flag() |
---|
| 2752 | self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) |
---|
| 2753 | else: |
---|
| 2754 | flag = False |
---|
| 2755 | self._edit_menu.Enable(GUIFRAME_ID.UNDO_ID, flag) |
---|
| 2756 | self._edit_menu.Enable(GUIFRAME_ID.REDO_ID, flag) |
---|
| 2757 | self._edit_menu.Enable(GUIFRAME_ID.COPY_ID, flag) |
---|
| 2758 | self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) |
---|
| 2759 | self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) |
---|
| 2760 | self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) |
---|
[091e71a2] | 2761 | |
---|
[f53cd30] | 2762 | def on_undo_panel(self, event=None): |
---|
| 2763 | """ |
---|
| 2764 | undo previous action of the last panel on focus if possible |
---|
| 2765 | """ |
---|
| 2766 | if self.cpanel_on_focus is not None: |
---|
| 2767 | self.cpanel_on_focus.on_undo(event) |
---|
[091e71a2] | 2768 | |
---|
[f53cd30] | 2769 | def on_redo_panel(self, event=None): |
---|
| 2770 | """ |
---|
| 2771 | redo the last cancel action done on the last panel on focus |
---|
| 2772 | """ |
---|
| 2773 | if self.cpanel_on_focus is not None: |
---|
| 2774 | self.cpanel_on_focus.on_redo(event) |
---|
[091e71a2] | 2775 | |
---|
[f53cd30] | 2776 | def on_copy_panel(self, event=None): |
---|
| 2777 | """ |
---|
| 2778 | copy the last panel on focus if possible |
---|
| 2779 | """ |
---|
| 2780 | if self.cpanel_on_focus is not None: |
---|
| 2781 | self.cpanel_on_focus.on_copy(event) |
---|
[091e71a2] | 2782 | |
---|
[f53cd30] | 2783 | def on_paste_panel(self, event=None): |
---|
| 2784 | """ |
---|
| 2785 | paste clipboard to the last panel on focus |
---|
| 2786 | """ |
---|
| 2787 | if self.cpanel_on_focus is not None: |
---|
| 2788 | self.cpanel_on_focus.on_paste(event) |
---|
[091e71a2] | 2789 | |
---|
[f53cd30] | 2790 | def on_bookmark_panel(self, event=None): |
---|
| 2791 | """ |
---|
| 2792 | bookmark panel |
---|
| 2793 | """ |
---|
| 2794 | if self.cpanel_on_focus is not None: |
---|
| 2795 | self.cpanel_on_focus.on_bookmark(event) |
---|
[091e71a2] | 2796 | |
---|
[f53cd30] | 2797 | def append_bookmark(self, event=None): |
---|
| 2798 | """ |
---|
| 2799 | Bookmark available information of the panel on focus |
---|
| 2800 | """ |
---|
| 2801 | self._toolbar.append_bookmark(event) |
---|
[091e71a2] | 2802 | |
---|
[f53cd30] | 2803 | def on_save_panel(self, event=None): |
---|
| 2804 | """ |
---|
| 2805 | save possible information on the current panel |
---|
| 2806 | """ |
---|
| 2807 | if self.cpanel_on_focus is not None: |
---|
| 2808 | self.cpanel_on_focus.on_save(event) |
---|
[091e71a2] | 2809 | |
---|
[f53cd30] | 2810 | def on_preview_panel(self, event=None): |
---|
| 2811 | """ |
---|
| 2812 | preview information on the panel on focus |
---|
| 2813 | """ |
---|
| 2814 | if self.cpanel_on_focus is not None: |
---|
| 2815 | self.cpanel_on_focus.on_preview(event) |
---|
[091e71a2] | 2816 | |
---|
[f53cd30] | 2817 | def on_print_panel(self, event=None): |
---|
| 2818 | """ |
---|
| 2819 | print available information on the last panel on focus |
---|
| 2820 | """ |
---|
| 2821 | if self.cpanel_on_focus is not None: |
---|
| 2822 | self.cpanel_on_focus.on_print(event) |
---|
[091e71a2] | 2823 | |
---|
[f53cd30] | 2824 | def on_zoom_panel(self, event=None): |
---|
| 2825 | """ |
---|
| 2826 | zoom on the current panel if possible |
---|
| 2827 | """ |
---|
| 2828 | if self.cpanel_on_focus is not None: |
---|
| 2829 | self.cpanel_on_focus.on_zoom(event) |
---|
[091e71a2] | 2830 | |
---|
[f53cd30] | 2831 | def on_zoom_in_panel(self, event=None): |
---|
| 2832 | """ |
---|
| 2833 | zoom in of the panel on focus |
---|
| 2834 | """ |
---|
| 2835 | if self.cpanel_on_focus is not None: |
---|
| 2836 | self.cpanel_on_focus.on_zoom_in(event) |
---|
[091e71a2] | 2837 | |
---|
[f53cd30] | 2838 | def on_zoom_out_panel(self, event=None): |
---|
| 2839 | """ |
---|
| 2840 | zoom out on the panel on focus |
---|
| 2841 | """ |
---|
| 2842 | if self.cpanel_on_focus is not None: |
---|
| 2843 | self.cpanel_on_focus.on_zoom_out(event) |
---|
[091e71a2] | 2844 | |
---|
[f53cd30] | 2845 | def on_drag_panel(self, event=None): |
---|
| 2846 | """ |
---|
| 2847 | drag apply to the panel on focus |
---|
| 2848 | """ |
---|
| 2849 | if self.cpanel_on_focus is not None: |
---|
| 2850 | self.cpanel_on_focus.on_drag(event) |
---|
[091e71a2] | 2851 | |
---|
[f53cd30] | 2852 | def on_reset_panel(self, event=None): |
---|
| 2853 | """ |
---|
| 2854 | reset the current panel |
---|
| 2855 | """ |
---|
| 2856 | if self.cpanel_on_focus is not None: |
---|
| 2857 | self.cpanel_on_focus.on_reset(event) |
---|
[091e71a2] | 2858 | |
---|
| 2859 | def on_change_caption(self, name, old_caption, new_caption): |
---|
[f53cd30] | 2860 | """ |
---|
| 2861 | Change the panel caption |
---|
[091e71a2] | 2862 | |
---|
[f53cd30] | 2863 | :param name: window_name of the pane |
---|
| 2864 | :param old_caption: current caption [string] |
---|
| 2865 | :param new_caption: new caption [string] |
---|
| 2866 | """ |
---|
| 2867 | # wx.aui.AuiPaneInfo |
---|
[091e71a2] | 2868 | pane_info = self.get_paneinfo(old_caption) |
---|
[f53cd30] | 2869 | # update the data_panel.cb_plotpanel |
---|
| 2870 | if 'data_panel' in self.panels.keys(): |
---|
| 2871 | # remove from data_panel combobox |
---|
| 2872 | data_panel = self.panels["data_panel"] |
---|
| 2873 | if data_panel.cb_plotpanel is not None: |
---|
| 2874 | # Check if any panel has the same caption |
---|
| 2875 | has_newstring = data_panel.cb_plotpanel.FindString\ |
---|
[091e71a2] | 2876 | (str(new_caption)) |
---|
[f53cd30] | 2877 | caption = new_caption |
---|
| 2878 | if has_newstring != wx.NOT_FOUND: |
---|
| 2879 | captions = self._get_plotpanel_captions() |
---|
| 2880 | # Append nummber |
---|
| 2881 | inc = 1 |
---|
[091e71a2] | 2882 | #FIXME: fix this terrible loop |
---|
[f53cd30] | 2883 | while (1): |
---|
[091e71a2] | 2884 | caption = new_caption + '_%s' % str(inc) |
---|
[f53cd30] | 2885 | if caption not in captions: |
---|
| 2886 | break |
---|
| 2887 | inc += 1 |
---|
| 2888 | # notify to users |
---|
[091e71a2] | 2889 | msg = "Found Same Title: Added '_%s'" % str(inc) |
---|
[f53cd30] | 2890 | wx.PostEvent(self, StatusEvent(status=msg)) |
---|
| 2891 | # update data_panel cb |
---|
[091e71a2] | 2892 | pos = data_panel.cb_plotpanel.FindString(str(old_caption)) |
---|
[f53cd30] | 2893 | if pos != wx.NOT_FOUND: |
---|
| 2894 | data_panel.cb_plotpanel.SetString(pos, caption) |
---|
| 2895 | data_panel.cb_plotpanel.SetStringSelection(caption) |
---|
| 2896 | # New Caption |
---|
| 2897 | pane_info.SetTitle(caption) |
---|
| 2898 | return caption |
---|
[091e71a2] | 2899 | |
---|
[f53cd30] | 2900 | def get_paneinfo(self, name): |
---|
| 2901 | """ |
---|
| 2902 | Get pane Caption from window_name |
---|
[091e71a2] | 2903 | |
---|
[f53cd30] | 2904 | :param name: window_name in AuiPaneInfo |
---|
[ac7be54] | 2905 | :return: AuiPaneInfo of the name |
---|
[f53cd30] | 2906 | """ |
---|
| 2907 | for panel in self.plot_panels.values(): |
---|
| 2908 | if panel.frame.GetTitle() == name: |
---|
| 2909 | return panel.frame |
---|
| 2910 | return None |
---|
[091e71a2] | 2911 | |
---|
[f53cd30] | 2912 | def enable_undo(self): |
---|
| 2913 | """ |
---|
| 2914 | enable undo related control |
---|
| 2915 | """ |
---|
| 2916 | if self.cpanel_on_focus is not None: |
---|
| 2917 | self._toolbar.enable_undo(self.cpanel_on_focus) |
---|
[091e71a2] | 2918 | |
---|
[f53cd30] | 2919 | def enable_redo(self): |
---|
| 2920 | """ |
---|
[091e71a2] | 2921 | enable redo |
---|
[f53cd30] | 2922 | """ |
---|
| 2923 | if self.cpanel_on_focus is not None: |
---|
| 2924 | self._toolbar.enable_redo(self.cpanel_on_focus) |
---|
[091e71a2] | 2925 | |
---|
[f53cd30] | 2926 | def enable_copy(self): |
---|
| 2927 | """ |
---|
| 2928 | enable copy related control |
---|
| 2929 | """ |
---|
| 2930 | if self.cpanel_on_focus is not None: |
---|
| 2931 | self._toolbar.enable_copy(self.cpanel_on_focus) |
---|
[091e71a2] | 2932 | |
---|
[f53cd30] | 2933 | def enable_paste(self): |
---|
| 2934 | """ |
---|
[091e71a2] | 2935 | enable paste |
---|
[f53cd30] | 2936 | """ |
---|
| 2937 | if self.cpanel_on_focus is not None: |
---|
| 2938 | self._toolbar.enable_paste(self.cpanel_on_focus) |
---|
[091e71a2] | 2939 | |
---|
[f53cd30] | 2940 | def enable_bookmark(self): |
---|
| 2941 | """ |
---|
[091e71a2] | 2942 | Bookmark |
---|
[f53cd30] | 2943 | """ |
---|
| 2944 | if self.cpanel_on_focus is not None: |
---|
| 2945 | self._toolbar.enable_bookmark(self.cpanel_on_focus) |
---|
[091e71a2] | 2946 | |
---|
[f53cd30] | 2947 | def enable_save(self): |
---|
| 2948 | """ |
---|
[091e71a2] | 2949 | save |
---|
[f53cd30] | 2950 | """ |
---|
| 2951 | if self.cpanel_on_focus is not None: |
---|
| 2952 | self._toolbar.enable_save(self.cpanel_on_focus) |
---|
[091e71a2] | 2953 | |
---|
[f53cd30] | 2954 | def enable_preview(self): |
---|
| 2955 | """ |
---|
[091e71a2] | 2956 | preview |
---|
[f53cd30] | 2957 | """ |
---|
| 2958 | if self.cpanel_on_focus is not None: |
---|
| 2959 | self._toolbar.enable_preview(self.cpanel_on_focus) |
---|
[091e71a2] | 2960 | |
---|
[f53cd30] | 2961 | def enable_print(self): |
---|
| 2962 | """ |
---|
[091e71a2] | 2963 | print |
---|
[f53cd30] | 2964 | """ |
---|
| 2965 | if self.cpanel_on_focus is not None: |
---|
| 2966 | self._toolbar.enable_print(self.cpanel_on_focus) |
---|
[091e71a2] | 2967 | |
---|
[f53cd30] | 2968 | def enable_zoom(self): |
---|
| 2969 | """ |
---|
[091e71a2] | 2970 | zoom |
---|
[f53cd30] | 2971 | """ |
---|
| 2972 | if self.cpanel_on_focus is not None: |
---|
| 2973 | self._toolbar.enable_zoom(self.panel_on_focus) |
---|
[091e71a2] | 2974 | |
---|
[f53cd30] | 2975 | def enable_zoom_in(self): |
---|
| 2976 | """ |
---|
[091e71a2] | 2977 | zoom in |
---|
[f53cd30] | 2978 | """ |
---|
| 2979 | if self.cpanel_on_focus is not None: |
---|
| 2980 | self._toolbar.enable_zoom_in(self.panel_on_focus) |
---|
[091e71a2] | 2981 | |
---|
[f53cd30] | 2982 | def enable_zoom_out(self): |
---|
| 2983 | """ |
---|
[091e71a2] | 2984 | zoom out |
---|
[f53cd30] | 2985 | """ |
---|
| 2986 | if self.cpanel_on_focus is not None: |
---|
| 2987 | self._toolbar.enable_zoom_out(self.panel_on_focus) |
---|
[091e71a2] | 2988 | |
---|
[f53cd30] | 2989 | def enable_drag(self, event=None): |
---|
| 2990 | """ |
---|
[091e71a2] | 2991 | drag |
---|
[f53cd30] | 2992 | """ |
---|
| 2993 | #Not implemeted |
---|
[091e71a2] | 2994 | |
---|
[f53cd30] | 2995 | def enable_reset(self): |
---|
| 2996 | """ |
---|
| 2997 | reset the current panel |
---|
| 2998 | """ |
---|
| 2999 | if self.cpanel_on_focus is not None: |
---|
| 3000 | self._toolbar.enable_reset(self.panel_on_focus) |
---|
[091e71a2] | 3001 | |
---|
[f53cd30] | 3002 | def get_toolbar_height(self): |
---|
| 3003 | """ |
---|
| 3004 | """ |
---|
| 3005 | size_y = 0 |
---|
| 3006 | if self.GetToolBar() != None and self.GetToolBar().IsShown(): |
---|
| 3007 | if not IS_LINUX: |
---|
| 3008 | _, size_y = self.GetToolBar().GetSizeTuple() |
---|
| 3009 | return size_y |
---|
[091e71a2] | 3010 | |
---|
[f53cd30] | 3011 | def set_schedule_full_draw(self, panel=None, func='del'): |
---|
| 3012 | """ |
---|
| 3013 | Add/subtract the schedule full draw list with the panel given |
---|
[091e71a2] | 3014 | |
---|
[f53cd30] | 3015 | :param panel: plot panel |
---|
| 3016 | :param func: append or del [string] |
---|
| 3017 | """ |
---|
| 3018 | |
---|
| 3019 | # append this panel in the schedule list if not in yet |
---|
| 3020 | if func == 'append': |
---|
| 3021 | if not panel in self.schedule_full_draw_list: |
---|
[091e71a2] | 3022 | self.schedule_full_draw_list.append(panel) |
---|
[f53cd30] | 3023 | # remove this panel from schedule list |
---|
| 3024 | elif func == 'del': |
---|
| 3025 | if len(self.schedule_full_draw_list) > 0: |
---|
| 3026 | if panel in self.schedule_full_draw_list: |
---|
| 3027 | self.schedule_full_draw_list.remove(panel) |
---|
| 3028 | |
---|
| 3029 | # reset the schdule |
---|
| 3030 | if len(self.schedule_full_draw_list) == 0: |
---|
| 3031 | self.schedule = False |
---|
| 3032 | else: |
---|
[091e71a2] | 3033 | self.schedule = True |
---|
| 3034 | |
---|
[f53cd30] | 3035 | def full_draw(self): |
---|
| 3036 | """ |
---|
| 3037 | Draw the panels with axes in the schedule to full dwar list |
---|
| 3038 | """ |
---|
[091e71a2] | 3039 | |
---|
[f53cd30] | 3040 | count = len(self.schedule_full_draw_list) |
---|
| 3041 | #if not self.schedule: |
---|
| 3042 | if count < 1: |
---|
| 3043 | self.set_schedule(False) |
---|
| 3044 | return |
---|
| 3045 | |
---|
| 3046 | else: |
---|
| 3047 | ind = 0 |
---|
| 3048 | # if any of the panel is shown do full_draw |
---|
| 3049 | for panel in self.schedule_full_draw_list: |
---|
| 3050 | ind += 1 |
---|
| 3051 | if panel.frame.IsShown(): |
---|
| 3052 | break |
---|
| 3053 | # otherwise, return |
---|
| 3054 | if ind == count: |
---|
| 3055 | return |
---|
| 3056 | #Simple redraw only for a panel shown |
---|
| 3057 | def f_draw(panel): |
---|
| 3058 | """ |
---|
| 3059 | Draw A panel in the full draw list |
---|
| 3060 | """ |
---|
| 3061 | try: |
---|
| 3062 | # This checking of GetCapture is to stop redrawing |
---|
| 3063 | # while any panel is capture. |
---|
| 3064 | frame = panel.frame |
---|
[091e71a2] | 3065 | |
---|
[f53cd30] | 3066 | if not frame.GetCapture(): |
---|
| 3067 | # draw if possible |
---|
| 3068 | panel.set_resizing(False) |
---|
| 3069 | #panel.Show(True) |
---|
| 3070 | panel.draw_plot() |
---|
| 3071 | # Check if the panel is not shown |
---|
| 3072 | flag = frame.IsShown() |
---|
[091e71a2] | 3073 | frame.Show(flag) |
---|
[f53cd30] | 3074 | except: |
---|
| 3075 | pass |
---|
[091e71a2] | 3076 | |
---|
[f53cd30] | 3077 | # Draw all panels |
---|
| 3078 | if count == 1: |
---|
[091e71a2] | 3079 | f_draw(self.schedule_full_draw_list[0]) |
---|
[f53cd30] | 3080 | else: |
---|
| 3081 | map(f_draw, self.schedule_full_draw_list) |
---|
| 3082 | # Reset the attr |
---|
| 3083 | if len(self.schedule_full_draw_list) == 0: |
---|
| 3084 | self.set_schedule(False) |
---|
| 3085 | else: |
---|
| 3086 | self.set_schedule(True) |
---|
[091e71a2] | 3087 | |
---|
| 3088 | def set_schedule(self, schedule=False): |
---|
[f53cd30] | 3089 | """ |
---|
| 3090 | Set schedule |
---|
| 3091 | """ |
---|
| 3092 | self.schedule = schedule |
---|
[091e71a2] | 3093 | |
---|
| 3094 | def get_schedule(self): |
---|
[f53cd30] | 3095 | """ |
---|
| 3096 | Get schedule |
---|
| 3097 | """ |
---|
| 3098 | return self.schedule |
---|
[091e71a2] | 3099 | |
---|
[f53cd30] | 3100 | def on_set_plot_focus(self, panel): |
---|
| 3101 | """ |
---|
| 3102 | Set focus on a plot panel |
---|
| 3103 | """ |
---|
| 3104 | if panel == None: |
---|
| 3105 | return |
---|
| 3106 | #self.set_plot_unfocus() |
---|
[091e71a2] | 3107 | panel.on_set_focus(None) |
---|
[f53cd30] | 3108 | # set focusing panel |
---|
[091e71a2] | 3109 | self.panel_on_focus = panel |
---|
[f53cd30] | 3110 | self.set_panel_on_focus(None) |
---|
| 3111 | |
---|
[091e71a2] | 3112 | def set_plot_unfocus(self): |
---|
[f53cd30] | 3113 | """ |
---|
| 3114 | Un focus all plot panels |
---|
| 3115 | """ |
---|
| 3116 | for plot in self.plot_panels.values(): |
---|
| 3117 | plot.on_kill_focus(None) |
---|
[091e71a2] | 3118 | |
---|
[f53cd30] | 3119 | def get_window_size(self): |
---|
| 3120 | """ |
---|
[091e71a2] | 3121 | Get window size |
---|
| 3122 | |
---|
[f53cd30] | 3123 | :return size: tuple |
---|
| 3124 | """ |
---|
| 3125 | width, height = self.GetSizeTuple() |
---|
| 3126 | if not IS_WIN: |
---|
| 3127 | # Subtract toolbar height to get real window side |
---|
| 3128 | if self._toolbar.IsShown(): |
---|
| 3129 | height -= 45 |
---|
| 3130 | return (width, height) |
---|
[091e71a2] | 3131 | |
---|
[f53cd30] | 3132 | def _onDrawIdle(self, *args, **kwargs): |
---|
| 3133 | """ |
---|
| 3134 | ReDraw with axes |
---|
| 3135 | """ |
---|
| 3136 | try: |
---|
| 3137 | # check if it is time to redraw |
---|
| 3138 | if self.GetCapture() == None: |
---|
| 3139 | # Draw plot, changes resizing too |
---|
| 3140 | self.full_draw() |
---|
| 3141 | except: |
---|
| 3142 | pass |
---|
[091e71a2] | 3143 | |
---|
[f53cd30] | 3144 | # restart idle |
---|
| 3145 | self._redraw_idle(*args, **kwargs) |
---|
| 3146 | |
---|
[091e71a2] | 3147 | |
---|
[f53cd30] | 3148 | def _redraw_idle(self, *args, **kwargs): |
---|
| 3149 | """ |
---|
| 3150 | Restart Idle |
---|
| 3151 | """ |
---|
| 3152 | # restart idle |
---|
[091e71a2] | 3153 | self.idletimer.Restart(100 * TIME_FACTOR, *args, **kwargs) |
---|
| 3154 | |
---|
[f53cd30] | 3155 | |
---|
| 3156 | class DefaultPanel(wx.Panel, PanelBase): |
---|
| 3157 | """ |
---|
| 3158 | Defines the API for a panels to work with |
---|
| 3159 | the GUI manager |
---|
| 3160 | """ |
---|
| 3161 | ## Internal nickname for the window, used by the AUI manager |
---|
| 3162 | window_name = "default" |
---|
| 3163 | ## Name to appear on the window title bar |
---|
| 3164 | window_caption = "Welcome panel" |
---|
| 3165 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
| 3166 | CENTER_PANE = True |
---|
| 3167 | def __init__(self, parent, *args, **kwds): |
---|
| 3168 | wx.Panel.__init__(self, parent, *args, **kwds) |
---|
| 3169 | PanelBase.__init__(self, parent) |
---|
[091e71a2] | 3170 | |
---|
[f53cd30] | 3171 | |
---|
| 3172 | |
---|
| 3173 | class ViewApp(wx.App): |
---|
| 3174 | """ |
---|
| 3175 | Toy application to test this Frame |
---|
| 3176 | """ |
---|
| 3177 | def OnInit(self): |
---|
| 3178 | """ |
---|
| 3179 | When initialised |
---|
| 3180 | """ |
---|
[091e71a2] | 3181 | pos, size, self.is_max = self.window_placement((GUIFRAME_WIDTH, |
---|
| 3182 | GUIFRAME_HEIGHT)) |
---|
| 3183 | self.frame = ViewerFrame(parent=None, |
---|
| 3184 | title=APPLICATION_NAME, |
---|
| 3185 | pos=pos, |
---|
| 3186 | gui_style=DEFAULT_STYLE, |
---|
| 3187 | size=size) |
---|
[f53cd30] | 3188 | self.frame.Hide() |
---|
| 3189 | if not IS_WIN: |
---|
| 3190 | self.frame.EnableCloseButton(False) |
---|
| 3191 | self.s_screen = None |
---|
| 3192 | |
---|
| 3193 | try: |
---|
| 3194 | self.open_file() |
---|
| 3195 | except: |
---|
| 3196 | msg = "%s Could not load " % str(APPLICATION_NAME) |
---|
| 3197 | msg += "input file from command line.\n" |
---|
| 3198 | logging.error(msg) |
---|
| 3199 | # Display a splash screen on top of the frame. |
---|
| 3200 | try: |
---|
| 3201 | if os.path.isfile(SPLASH_SCREEN_PATH): |
---|
[091e71a2] | 3202 | self.s_screen = self.display_splash_screen(parent=self.frame, |
---|
| 3203 | path=SPLASH_SCREEN_PATH) |
---|
[f53cd30] | 3204 | else: |
---|
[091e71a2] | 3205 | self.frame.Show() |
---|
[f53cd30] | 3206 | except: |
---|
| 3207 | if self.s_screen is not None: |
---|
| 3208 | self.s_screen.Close() |
---|
| 3209 | msg = "Cannot display splash screen\n" |
---|
[091e71a2] | 3210 | msg += str(sys.exc_value) |
---|
[f53cd30] | 3211 | logging.error(msg) |
---|
| 3212 | self.frame.Show() |
---|
| 3213 | |
---|
| 3214 | self.SetTopWindow(self.frame) |
---|
[091e71a2] | 3215 | |
---|
[f53cd30] | 3216 | return True |
---|
[091e71a2] | 3217 | |
---|
[f53cd30] | 3218 | def maximize_win(self): |
---|
| 3219 | """ |
---|
| 3220 | Maximize the window after the frame shown |
---|
| 3221 | """ |
---|
| 3222 | if self.is_max: |
---|
| 3223 | if self.frame.IsShown(): |
---|
| 3224 | # Max window size |
---|
| 3225 | self.frame.Maximize(self.is_max) |
---|
| 3226 | |
---|
| 3227 | def open_file(self): |
---|
| 3228 | """ |
---|
| 3229 | open a state file at the start of the application |
---|
| 3230 | """ |
---|
| 3231 | input_file = None |
---|
| 3232 | if len(sys.argv) >= 2: |
---|
| 3233 | cmd = sys.argv[0].lower() |
---|
[091e71a2] | 3234 | basename = os.path.basename(cmd) |
---|
[f53cd30] | 3235 | app_base = str(APPLICATION_NAME).lower() |
---|
| 3236 | if os.path.isfile(cmd) or basename.lower() == app_base: |
---|
| 3237 | app_py = app_base + '.py' |
---|
| 3238 | app_exe = app_base + '.exe' |
---|
| 3239 | app_app = app_base + '.app' |
---|
| 3240 | if basename.lower() in [app_py, app_exe, app_app, app_base]: |
---|
| 3241 | data_base = sys.argv[1] |
---|
[091e71a2] | 3242 | input_file = os.path.normpath(os.path.join(DATAPATH, |
---|
[f53cd30] | 3243 | data_base)) |
---|
| 3244 | if input_file is None: |
---|
| 3245 | return |
---|
| 3246 | if self.frame is not None: |
---|
| 3247 | self.frame.set_input_file(input_file=input_file) |
---|
[091e71a2] | 3248 | |
---|
| 3249 | def clean_plugin_models(self, path): |
---|
[f53cd30] | 3250 | """ |
---|
| 3251 | Delete plugin models in app folder |
---|
[091e71a2] | 3252 | |
---|
[f53cd30] | 3253 | :param path: path of the plugin_models folder in app |
---|
| 3254 | """ |
---|
| 3255 | # do it only the first time app loaded |
---|
[091e71a2] | 3256 | # delete unused model folder |
---|
[f53cd30] | 3257 | model_folder = os.path.join(PATH_APP, path) |
---|
| 3258 | if os.path.exists(model_folder) and os.path.isdir(model_folder): |
---|
| 3259 | if len(os.listdir(model_folder)) > 0: |
---|
| 3260 | try: |
---|
| 3261 | for file in os.listdir(model_folder): |
---|
| 3262 | file_path = os.path.join(model_folder, file) |
---|
| 3263 | if os.path.isfile(file_path): |
---|
| 3264 | os.remove(file_path) |
---|
| 3265 | except: |
---|
| 3266 | logging.error("gui_manager.clean_plugin_models:\n %s" \ |
---|
| 3267 | % sys.exc_value) |
---|
[091e71a2] | 3268 | |
---|
[f53cd30] | 3269 | def set_manager(self, manager): |
---|
| 3270 | """ |
---|
| 3271 | Sets a reference to the application manager |
---|
[091e71a2] | 3272 | of the GUI manager (Frame) |
---|
[f53cd30] | 3273 | """ |
---|
| 3274 | self.frame.set_manager(manager) |
---|
[091e71a2] | 3275 | |
---|
[f53cd30] | 3276 | def build_gui(self): |
---|
| 3277 | """ |
---|
| 3278 | Build the GUI |
---|
| 3279 | """ |
---|
| 3280 | #try to load file at the start |
---|
| 3281 | try: |
---|
| 3282 | self.open_file() |
---|
| 3283 | except: |
---|
| 3284 | raise |
---|
| 3285 | self.frame.build_gui() |
---|
[091e71a2] | 3286 | |
---|
[f53cd30] | 3287 | def set_welcome_panel(self, panel_class): |
---|
| 3288 | """ |
---|
| 3289 | Set the welcome panel |
---|
[091e71a2] | 3290 | |
---|
[f53cd30] | 3291 | :param panel_class: class of the welcome panel to be instantiated |
---|
[091e71a2] | 3292 | |
---|
[f53cd30] | 3293 | """ |
---|
| 3294 | self.frame.welcome_panel_class = panel_class |
---|
[091e71a2] | 3295 | |
---|
[f53cd30] | 3296 | def add_perspective(self, perspective): |
---|
| 3297 | """ |
---|
| 3298 | Manually add a perspective to the application GUI |
---|
| 3299 | """ |
---|
| 3300 | self.frame.add_perspective(perspective) |
---|
[091e71a2] | 3301 | |
---|
[f53cd30] | 3302 | def window_placement(self, size): |
---|
| 3303 | """ |
---|
| 3304 | Determines the position and size of the application frame such that it |
---|
| 3305 | fits on the user's screen without obstructing (or being obstructed by) |
---|
| 3306 | the Windows task bar. The maximum initial size in pixels is bounded by |
---|
| 3307 | WIDTH x HEIGHT. For most monitors, the application |
---|
| 3308 | will be centered on the screen; for very large monitors it will be |
---|
| 3309 | placed on the left side of the screen. |
---|
| 3310 | """ |
---|
| 3311 | is_maximized = False |
---|
| 3312 | # Get size of screen without |
---|
| 3313 | for screenCount in range(wx.Display().GetCount()): |
---|
| 3314 | screen = wx.Display(screenCount) |
---|
| 3315 | if screen.IsPrimary(): |
---|
| 3316 | displayRect = screen.GetClientArea() |
---|
| 3317 | break |
---|
[091e71a2] | 3318 | |
---|
| 3319 | posX, posY, displayWidth, displayHeight = displayRect |
---|
[f53cd30] | 3320 | customWidth, customHeight = size |
---|
[091e71a2] | 3321 | |
---|
[f53cd30] | 3322 | # If the custom size is default, set 90% of the screen size |
---|
| 3323 | if customWidth <= 0 and customHeight <= 0: |
---|
| 3324 | if customWidth == 0 and customHeight == 0: |
---|
| 3325 | is_maximized = True |
---|
| 3326 | customWidth = displayWidth * 0.9 |
---|
| 3327 | customHeight = displayHeight * 0.9 |
---|
| 3328 | else: |
---|
| 3329 | # If the custom screen is bigger than the |
---|
| 3330 | # window screen than make maximum size |
---|
| 3331 | if customWidth > displayWidth: |
---|
| 3332 | customWidth = displayWidth |
---|
| 3333 | if customHeight > displayHeight: |
---|
| 3334 | customHeight = displayHeight |
---|
[091e71a2] | 3335 | |
---|
[f53cd30] | 3336 | # Note that when running Linux and using an Xming (X11) server on a PC |
---|
| 3337 | # with a dual monitor configuration, the reported display size may be |
---|
| 3338 | # that of both monitors combined with an incorrect display count of 1. |
---|
| 3339 | # To avoid displaying this app across both monitors, we check for |
---|
| 3340 | # screen 'too big'. If so, we assume a smaller width which means the |
---|
| 3341 | # application will be placed towards the left hand side of the screen. |
---|
[091e71a2] | 3342 | |
---|
[f53cd30] | 3343 | # If dual screen registered as 1 screen. Make width half. |
---|
| 3344 | # MAC just follows the default behavior of pos |
---|
| 3345 | if IS_WIN: |
---|
[091e71a2] | 3346 | if displayWidth > (displayHeight * 2): |
---|
| 3347 | if customWidth == displayWidth: |
---|
| 3348 | customWidth = displayWidth / 2 |
---|
[f53cd30] | 3349 | # and set the position to be the corner of the screen. |
---|
| 3350 | posX = 0 |
---|
| 3351 | posY = 0 |
---|
[091e71a2] | 3352 | |
---|
[f53cd30] | 3353 | # Make the position the middle of the screen. (Not 0,0) |
---|
| 3354 | else: |
---|
[091e71a2] | 3355 | posX = (displayWidth - customWidth) / 2 |
---|
| 3356 | posY = (displayHeight - customHeight) / 2 |
---|
| 3357 | # Return the suggested position and size for the application frame. |
---|
[f53cd30] | 3358 | return (posX, posY), (customWidth, customHeight), is_maximized |
---|
| 3359 | |
---|
[091e71a2] | 3360 | |
---|
| 3361 | def display_splash_screen(self, parent, |
---|
[f53cd30] | 3362 | path=SPLASH_SCREEN_PATH): |
---|
| 3363 | """Displays the splash screen. It will exactly cover the main frame.""" |
---|
[091e71a2] | 3364 | |
---|
[f53cd30] | 3365 | # Prepare the picture. On a 2GHz intel cpu, this takes about a second. |
---|
| 3366 | image = wx.Image(path, wx.BITMAP_TYPE_PNG) |
---|
[091e71a2] | 3367 | image.Rescale(SPLASH_SCREEN_WIDTH, |
---|
[f53cd30] | 3368 | SPLASH_SCREEN_HEIGHT, wx.IMAGE_QUALITY_HIGH) |
---|
| 3369 | bm = image.ConvertToBitmap() |
---|
| 3370 | |
---|
| 3371 | # Create and show the splash screen. It will disappear only when the |
---|
| 3372 | # program has entered the event loop AND either the timeout has expired |
---|
| 3373 | # or the user has left clicked on the screen. Thus any processing |
---|
| 3374 | # performed in this routine (including sleeping) or processing in the |
---|
| 3375 | # calling routine (including doing imports) will prevent the splash |
---|
| 3376 | # screen from disappearing. |
---|
| 3377 | # |
---|
| 3378 | # Note that on Linux, the timeout appears to occur immediately in which |
---|
| 3379 | # case the splash screen disappears upon entering the event loop. |
---|
| 3380 | s_screen = wx.SplashScreen(bitmap=bm, |
---|
[091e71a2] | 3381 | splashStyle=(wx.SPLASH_TIMEOUT | |
---|
[f53cd30] | 3382 | wx.SPLASH_CENTRE_ON_SCREEN), |
---|
[091e71a2] | 3383 | style=(wx.SIMPLE_BORDER | |
---|
| 3384 | wx.FRAME_NO_TASKBAR | |
---|
[f53cd30] | 3385 | wx.FRAME_FLOAT_ON_PARENT), |
---|
| 3386 | milliseconds=SS_MAX_DISPLAY_TIME, |
---|
| 3387 | parent=parent, |
---|
| 3388 | id=wx.ID_ANY) |
---|
| 3389 | from sas.guiframe.gui_statusbar import SPageStatusbar |
---|
| 3390 | statusBar = SPageStatusbar(s_screen) |
---|
| 3391 | s_screen.SetStatusBar(statusBar) |
---|
| 3392 | s_screen.Bind(wx.EVT_CLOSE, self.on_close_splash_screen) |
---|
| 3393 | s_screen.Show() |
---|
| 3394 | return s_screen |
---|
[091e71a2] | 3395 | |
---|
| 3396 | |
---|
[f53cd30] | 3397 | def on_close_splash_screen(self, event): |
---|
| 3398 | """ |
---|
| 3399 | When the splash screen is closed. |
---|
| 3400 | """ |
---|
| 3401 | self.frame.Show(True) |
---|
| 3402 | event.Skip() |
---|
| 3403 | self.maximize_win() |
---|
| 3404 | |
---|
| 3405 | |
---|
| 3406 | class MDIFrame(CHILD_FRAME): |
---|
| 3407 | """ |
---|
| 3408 | Frame for panels |
---|
| 3409 | """ |
---|
[091e71a2] | 3410 | def __init__(self, parent, panel, title="Untitled", size=(300, 200)): |
---|
[f53cd30] | 3411 | """ |
---|
| 3412 | comment |
---|
| 3413 | :param parent: parent panel/container |
---|
| 3414 | """ |
---|
| 3415 | # Initialize the Frame object |
---|
| 3416 | CHILD_FRAME.__init__(self, parent=parent, id=wx.ID_ANY, title=title, size=size) |
---|
| 3417 | self.parent = parent |
---|
| 3418 | self.name = "Untitled" |
---|
| 3419 | self.batch_on = self.parent.batch_on |
---|
| 3420 | self.panel = panel |
---|
| 3421 | if panel != None: |
---|
| 3422 | self.set_panel(panel) |
---|
| 3423 | self.Show(False) |
---|
[091e71a2] | 3424 | |
---|
[f53cd30] | 3425 | def show_data_panel(self, action): |
---|
| 3426 | """ |
---|
| 3427 | """ |
---|
| 3428 | self.parent.show_data_panel(action) |
---|
[091e71a2] | 3429 | |
---|
[f53cd30] | 3430 | def set_panel(self, panel): |
---|
| 3431 | """ |
---|
| 3432 | """ |
---|
| 3433 | self.panel = panel |
---|
| 3434 | self.name = panel.window_name |
---|
| 3435 | self.SetTitle(panel.window_caption) |
---|
| 3436 | self.SetHelpText(panel.help_string) |
---|
| 3437 | width, height = self.parent._get_panels_size(panel) |
---|
| 3438 | if hasattr(panel, "CENTER_PANE") and panel.CENTER_PANE: |
---|
[091e71a2] | 3439 | width *= 0.6 |
---|
[f53cd30] | 3440 | self.SetSize((width, height)) |
---|
| 3441 | self.parent.put_icon(self) |
---|
| 3442 | self.Bind(wx.EVT_SET_FOCUS, self.set_panel_focus) |
---|
| 3443 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
---|
| 3444 | self.Show(False) |
---|
[091e71a2] | 3445 | |
---|
[f53cd30] | 3446 | def set_panel_focus(self, event): |
---|
| 3447 | """ |
---|
| 3448 | """ |
---|
| 3449 | if self.parent.panel_on_focus != self.panel: |
---|
| 3450 | self.panel.SetFocus() |
---|
| 3451 | self.parent.panel_on_focus = self.panel |
---|
[091e71a2] | 3452 | |
---|
[f53cd30] | 3453 | def OnClose(self, event): |
---|
| 3454 | """ |
---|
| 3455 | On Close event |
---|
| 3456 | """ |
---|
| 3457 | self.panel.on_close(event) |
---|
[091e71a2] | 3458 | |
---|
| 3459 | if __name__ == "__main__": |
---|
[f53cd30] | 3460 | app = ViewApp(0) |
---|
| 3461 | app.MainLoop() |
---|