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