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