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