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