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