[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 |
---|
[db10f97] | 18 | |
---|
[41d466f] | 19 | try: |
---|
| 20 | # Try to find a local config |
---|
| 21 | import imp |
---|
| 22 | path = os.getcwd() |
---|
[cbb2e40] | 23 | if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ |
---|
[32c0841] | 24 | (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): |
---|
| 25 | fObj, path, descr = imp.find_module('local_config', [path]) |
---|
| 26 | config = imp.load_module('local_config', fObj, path, descr) |
---|
[6982833] | 27 | else: |
---|
[cbb2e40] | 28 | # Try simply importing local_config |
---|
| 29 | import local_config as config |
---|
[41d466f] | 30 | except: |
---|
| 31 | # Didn't find local config, load the default |
---|
| 32 | import config |
---|
[4e9583c] | 33 | |
---|
| 34 | import warnings |
---|
| 35 | warnings.simplefilter("ignore") |
---|
[3c44c66] | 36 | |
---|
[4e9583c] | 37 | import logging |
---|
[32c0841] | 38 | |
---|
[f444b20] | 39 | from sans.guiframe.events import EVT_STATUS |
---|
[4e4d3bb] | 40 | from sans.guiframe.events import EVT_APPEND_BOOKMARK |
---|
[a45037aa] | 41 | from sans.guiframe.events import EVT_PANEL_ON_FOCUS |
---|
[f444b20] | 42 | from sans.guiframe.events import StatusEvent |
---|
| 43 | from sans.guiframe.events import NewPlotEvent |
---|
[f036c692] | 44 | from sans.guiframe.gui_style import GUIFRAME |
---|
| 45 | from sans.guiframe.gui_style import GUIFRAME_ID |
---|
[52b8b74] | 46 | from sans.guiframe.events import NewLoadedDataEvent |
---|
[3feed3e] | 47 | from sans.guiframe.data_panel import DataPanel |
---|
[d828481] | 48 | from sans.guiframe.panel_base import PanelBase |
---|
[f036c692] | 49 | from sans.guiframe.gui_toolbar import GUIToolBar |
---|
[75fbd17] | 50 | from DataLoader.loader import Loader |
---|
| 51 | |
---|
[b5ca223] | 52 | |
---|
[957723f] | 53 | #read some constants from config |
---|
| 54 | APPLICATION_STATE_EXTENSION = config.APPLICATION_STATE_EXTENSION |
---|
| 55 | APPLICATION_NAME = config.__appname__ |
---|
| 56 | SPLASH_SCREEN_PATH = config.SPLASH_SCREEN_PATH |
---|
| 57 | DEFAULT_STYLE = config.DEFAULT_STYLE |
---|
| 58 | SPLASH_SCREEN_WIDTH = config.SPLASH_SCREEN_WIDTH |
---|
| 59 | SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT |
---|
| 60 | SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME |
---|
| 61 | PLOPANEL_WIDTH = config.PLOPANEL_WIDTH |
---|
| 62 | PLOPANEL_HEIGTH = config.PLOPANEL_HEIGTH |
---|
| 63 | GUIFRAME_WIDTH = config.GUIFRAME_WIDTH |
---|
| 64 | GUIFRAME_HEIGHT = config.GUIFRAME_HEIGHT |
---|
| 65 | PLUGIN_STATE_EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS |
---|
| 66 | extension_list = [] |
---|
| 67 | if APPLICATION_STATE_EXTENSION is not None: |
---|
| 68 | extension_list.append(APPLICATION_STATE_EXTENSION) |
---|
| 69 | EXTENSIONS = PLUGIN_STATE_EXTENSIONS + extension_list |
---|
| 70 | try: |
---|
[4c01978] | 71 | PLUGINS_WLIST = '|'.join(config.PLUGINS_WLIST) |
---|
[957723f] | 72 | except: |
---|
[4c01978] | 73 | PLUGINS_WLIST = '' |
---|
| 74 | APPLICATION_WLIST = config.APPLICATION_WLIST |
---|
[7681bac] | 75 | |
---|
[41d466f] | 76 | class ViewerFrame(wx.Frame): |
---|
| 77 | """ |
---|
[d955bf19] | 78 | Main application frame |
---|
[41d466f] | 79 | """ |
---|
[f444b20] | 80 | |
---|
[3385795] | 81 | def __init__(self, parent, title, |
---|
[4753fc2] | 82 | size=(GUIFRAME_WIDTH, GUIFRAME_HEIGHT), |
---|
[3385795] | 83 | gui_style=GUIFRAME.DEFAULT_STYLE, |
---|
| 84 | pos=wx.DefaultPosition): |
---|
[41d466f] | 85 | """ |
---|
[d955bf19] | 86 | Initialize the Frame object |
---|
[41d466f] | 87 | """ |
---|
[b7c7a1c] | 88 | |
---|
[3385795] | 89 | wx.Frame.__init__(self, parent=parent, title=title, pos=pos,size=size) |
---|
[1b1bbf9] | 90 | # title |
---|
| 91 | self.title = title |
---|
[d0802c3] | 92 | # Preferred window size |
---|
[3385795] | 93 | self._window_width, self._window_height = size |
---|
[52b8b74] | 94 | self.__gui_style = gui_style |
---|
[41d466f] | 95 | |
---|
[fc2b91a] | 96 | # Logging info |
---|
| 97 | logging.basicConfig(level=logging.DEBUG, |
---|
| 98 | format='%(asctime)s %(levelname)s %(message)s', |
---|
| 99 | filename='sans_app.log', |
---|
| 100 | filemode='w') |
---|
[c44e7cc] | 101 | path = os.path.dirname(__file__) |
---|
[32c0841] | 102 | temp_path = os.path.join(path,'images') |
---|
[c44e7cc] | 103 | ico_file = os.path.join(temp_path,'ball.ico') |
---|
[278cc25] | 104 | if os.path.isfile(ico_file): |
---|
| 105 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
[cbb2e40] | 106 | else: |
---|
[32c0841] | 107 | temp_path = os.path.join(os.getcwd(),'images') |
---|
[c44e7cc] | 108 | ico_file = os.path.join(temp_path,'ball.ico') |
---|
[cbb2e40] | 109 | if os.path.isfile(ico_file): |
---|
| 110 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
[7c7fe67] | 111 | else: |
---|
| 112 | ico_file = os.path.join(os.path.dirname(os.path.sys.path[0]), |
---|
| 113 | 'images', 'ball.ico') |
---|
| 114 | if os.path.isfile(ico_file): |
---|
| 115 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
[41d466f] | 116 | |
---|
| 117 | ## Application manager |
---|
[29ef718] | 118 | self._input_file = None |
---|
[41d466f] | 119 | self.app_manager = None |
---|
[32c0841] | 120 | self._mgr = None |
---|
[f444b20] | 121 | #add current perpsective |
---|
| 122 | self._current_perspective = None |
---|
[52b8b74] | 123 | self._plotting_plugin = None |
---|
| 124 | self._data_plugin = None |
---|
| 125 | #Menu bar and item |
---|
| 126 | self._menubar = None |
---|
| 127 | self._file_menu = None |
---|
| 128 | self._data_menu = None |
---|
[34e3ab3] | 129 | self._view_menu = None |
---|
[52b8b74] | 130 | self._window_menu = None |
---|
[e75b5fa] | 131 | self._data_panel_menu = None |
---|
[c5e84fb] | 132 | self._help_menu = None |
---|
| 133 | self._tool_menu = None |
---|
[95f9cc4] | 134 | self._applications_menu_pos = -1 |
---|
[4c0572f] | 135 | self._applications_menu_name = None |
---|
[95f9cc4] | 136 | self._applications_menu = None |
---|
[d828481] | 137 | self._edit_menu = None |
---|
[a45037aa] | 138 | self._toolbar_menu = None |
---|
[73b3ae2] | 139 | self._save_appl_menu = None |
---|
[f036c692] | 140 | #tool bar |
---|
| 141 | self._toolbar = None |
---|
[1b1bbf9] | 142 | # (un)-focus color |
---|
| 143 | #self.color = '#b3b3b3' |
---|
[41d466f] | 144 | ## Find plug-ins |
---|
| 145 | # Modify this so that we can specify the directory to look into |
---|
[32c0841] | 146 | self.plugins = [] |
---|
[b7c7a1c] | 147 | #add local plugin |
---|
[52b8b74] | 148 | self.plugins += self._get_local_plugins() |
---|
[a88ac04] | 149 | self.plugins += self._find_plugins() |
---|
[41d466f] | 150 | ## List of panels |
---|
| 151 | self.panels = {} |
---|
[0a2fdca] | 152 | # List of plot panels |
---|
| 153 | self.plot_panels = {} |
---|
[41d466f] | 154 | |
---|
[2310d69] | 155 | # Default locations |
---|
| 156 | self._default_save_location = os.getcwd() |
---|
[f444b20] | 157 | |
---|
[f9e803e] | 158 | # Welcome panel |
---|
| 159 | self.defaultPanel = None |
---|
[b91c736] | 160 | #panel on focus |
---|
| 161 | self.panel_on_focus = None |
---|
[0a2fdca] | 162 | #control_panel on focus |
---|
| 163 | self.cpanel_on_focus = None |
---|
[75fbd17] | 164 | self.loader = Loader() |
---|
[6d727ae] | 165 | #data manager |
---|
[213892bc] | 166 | from data_manager import DataManager |
---|
| 167 | self._data_manager = DataManager() |
---|
| 168 | self._data_panel = DataPanel(parent=self) |
---|
| 169 | if self.panel_on_focus is not None: |
---|
[6db811e] | 170 | self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) |
---|
[6d727ae] | 171 | # list of plot panels in schedule to full redraw |
---|
| 172 | self.schedule = False |
---|
| 173 | #self.callback = True |
---|
| 174 | self._idle_count = 0 |
---|
| 175 | self.schedule_full_draw_list = [] |
---|
| 176 | self.idletimer = wx.CallLater(1, self._onDrawIdle) |
---|
| 177 | |
---|
[a0d56d5] | 178 | # Check for update |
---|
[af20f6b] | 179 | #self._check_update(None) |
---|
[278cc25] | 180 | # Register the close event so it calls our own method |
---|
[52725d6] | 181 | wx.EVT_CLOSE(self, self.Close) |
---|
[278cc25] | 182 | # Register to status events |
---|
| 183 | self.Bind(EVT_STATUS, self._on_status_event) |
---|
[b91c736] | 184 | #Register add extra data on the same panel event on load |
---|
[a45037aa] | 185 | self.Bind(EVT_PANEL_ON_FOCUS, self.set_panel_on_focus) |
---|
[4e4d3bb] | 186 | self.Bind(EVT_APPEND_BOOKMARK, self.append_bookmark) |
---|
[1b1bbf9] | 187 | |
---|
| 188 | |
---|
[600eca2] | 189 | def get_current_perspective(self): |
---|
| 190 | """ |
---|
| 191 | return the current perspective |
---|
| 192 | """ |
---|
| 193 | return self._current_perspective |
---|
| 194 | |
---|
[29ef718] | 195 | def set_input_file(self, input_file): |
---|
| 196 | """ |
---|
| 197 | :param input_file: file to read |
---|
| 198 | """ |
---|
| 199 | self._input_file = input_file |
---|
| 200 | |
---|
[4c0572f] | 201 | def get_data_manager(self): |
---|
| 202 | """ |
---|
| 203 | """ |
---|
| 204 | return self._data_manager |
---|
| 205 | |
---|
[03314e7] | 206 | def get_toolbar(self): |
---|
| 207 | """ |
---|
| 208 | """ |
---|
| 209 | return self._toolbar |
---|
| 210 | |
---|
[b91c736] | 211 | def set_panel_on_focus(self, event): |
---|
| 212 | """ |
---|
[d955bf19] | 213 | Store reference to the last panel on focus |
---|
[f036c692] | 214 | update the toolbar if available |
---|
| 215 | update edit menu if available |
---|
[b91c736] | 216 | """ |
---|
[0a2fdca] | 217 | if event != None: |
---|
| 218 | self.panel_on_focus = event.panel |
---|
[a45037aa] | 219 | panel_name = 'No panel on focus' |
---|
[f7e9af2] | 220 | application_name = 'No Selected Analysis' |
---|
[f69b5830] | 221 | if self.panel_on_focus is not None: |
---|
| 222 | for ID in self.panels.keys(): |
---|
| 223 | if self.panel_on_focus != self.panels[ID]: |
---|
| 224 | self.panels[ID].on_kill_focus(None) |
---|
| 225 | |
---|
[168a845] | 226 | if self._data_panel is not None and \ |
---|
| 227 | self.panel_on_focus is not None: |
---|
[f69b5830] | 228 | panel_name = self.panel_on_focus.window_caption |
---|
[48665ed] | 229 | ID = self.panel_on_focus.uid |
---|
| 230 | self._data_panel.set_panel_on_focus(ID) |
---|
[0a2fdca] | 231 | #update combo |
---|
| 232 | if self.panel_on_focus in self.plot_panels.values(): |
---|
| 233 | self._data_panel.cb_plotpanel.SetStringSelection(str\ |
---|
| 234 | (self.panel_on_focus.window_caption)) |
---|
| 235 | elif self.panel_on_focus != self._data_panel: |
---|
| 236 | self.cpanel_on_focus = self.panel_on_focus |
---|
[f69b5830] | 237 | #update toolbar |
---|
| 238 | self._update_toolbar_helper() |
---|
| 239 | #update edit menu |
---|
| 240 | self.enable_edit_menu() |
---|
[1b1bbf9] | 241 | |
---|
[0a2fdca] | 242 | |
---|
[278cc25] | 243 | def build_gui(self): |
---|
[d955bf19] | 244 | """ |
---|
| 245 | """ |
---|
[4d1dce4] | 246 | # set tool bar |
---|
| 247 | self._setup_tool_bar() |
---|
[41d466f] | 248 | # Set up the layout |
---|
| 249 | self._setup_layout() |
---|
| 250 | # Set up the menu |
---|
| 251 | self._setup_menus() |
---|
[4d1dce4] | 252 | |
---|
[29ef718] | 253 | try: |
---|
| 254 | self.load_from_cmd(self._input_file) |
---|
| 255 | except: |
---|
[64e44c1] | 256 | msg = "%s Cannot load file %s\n" %(str(APPLICATION_NAME), |
---|
| 257 | str(self._input_file)) |
---|
| 258 | msg += str(sys.exc_value) + '\n' |
---|
| 259 | print msg |
---|
[600eca2] | 260 | if self._data_panel is not None: |
---|
| 261 | self._data_panel.fill_cbox_analysis(self.plugins) |
---|
[29ef718] | 262 | self.post_init() |
---|
[3b11d0d] | 263 | #self.show_welcome_panel(None) |
---|
[29ef718] | 264 | self.Show(True) |
---|
[64e44c1] | 265 | #self._check_update(None) |
---|
| 266 | |
---|
[41d466f] | 267 | def _setup_layout(self): |
---|
| 268 | """ |
---|
[d955bf19] | 269 | Set up the layout |
---|
[41d466f] | 270 | """ |
---|
| 271 | # Status bar |
---|
[010c251] | 272 | from gui_statusbar import StatusBar |
---|
[db10f97] | 273 | self.sb = StatusBar(self, wx.ID_ANY) |
---|
[dd66fbd] | 274 | self.SetStatusBar(self.sb) |
---|
[41d466f] | 275 | # Add panel |
---|
[f69b5830] | 276 | default_flag = wx.aui.AUI_MGR_DEFAULT#| wx.aui.AUI_MGR_ALLOW_ACTIVE_PANE |
---|
[52b8b74] | 277 | self._mgr = wx.aui.AuiManager(self, flags=default_flag) |
---|
[1b1bbf9] | 278 | self._mgr.SetDockSizeConstraint(0.5, 0.5) |
---|
| 279 | # border color |
---|
| 280 | #self.b_color = wx.aui.AUI_DOCKART_BORDER_COLOUR |
---|
| 281 | #self._mgr.GetArtProvider().SetColor(self.b_color, self.color) |
---|
| 282 | #self._mgr.SetArtProvider(wx.aui.AuiDockArt(wx.AuiDefaultDockArt)) |
---|
| 283 | #print "set", self._dockart.GetColour(13) |
---|
[41d466f] | 284 | # Load panels |
---|
| 285 | self._load_panels() |
---|
[c5e84fb] | 286 | self.set_default_perspective() |
---|
[41d466f] | 287 | self._mgr.Update() |
---|
[db10f97] | 288 | |
---|
| 289 | def SetStatusText(self, *args, **kwds): |
---|
[d955bf19] | 290 | """ |
---|
| 291 | """ |
---|
[db10f97] | 292 | number = self.sb.get_msg_position() |
---|
| 293 | wx.Frame.SetStatusText(number=number, *args, **kwds) |
---|
| 294 | |
---|
| 295 | def PopStatusText(self, *args, **kwds): |
---|
[d955bf19] | 296 | """ |
---|
| 297 | """ |
---|
[db10f97] | 298 | field = self.sb.get_msg_position() |
---|
| 299 | wx.Frame.PopStatusText(field=field) |
---|
| 300 | |
---|
| 301 | def PushStatusText(self, *args, **kwds): |
---|
[d955bf19] | 302 | """ |
---|
| 303 | """ |
---|
[db10f97] | 304 | field = self.sb.get_msg_position() |
---|
[32c0841] | 305 | wx.Frame.PushStatusText(self, field=field, string=string) |
---|
[278cc25] | 306 | |
---|
| 307 | def add_perspective(self, plugin): |
---|
| 308 | """ |
---|
[d955bf19] | 309 | Add a perspective if it doesn't already |
---|
| 310 | exist. |
---|
[278cc25] | 311 | """ |
---|
| 312 | is_loaded = False |
---|
| 313 | for item in self.plugins: |
---|
[32c0841] | 314 | if plugin.__class__ == item.__class__: |
---|
[56681bd] | 315 | msg = "Plugin %s already loaded" % plugin.sub_menu |
---|
[f444b20] | 316 | logging.info(msg) |
---|
[32c0841] | 317 | is_loaded = True |
---|
[278cc25] | 318 | if not is_loaded: |
---|
| 319 | self.plugins.append(plugin) |
---|
[600eca2] | 320 | |
---|
[41d466f] | 321 | |
---|
[52b8b74] | 322 | def _get_local_plugins(self): |
---|
| 323 | """ |
---|
| 324 | get plugins local to guiframe and others |
---|
| 325 | """ |
---|
| 326 | plugins = [] |
---|
| 327 | #import guiframe local plugins |
---|
[7a67e075] | 328 | #check if the style contain guiframe.dataloader |
---|
| 329 | style1 = self.__gui_style & GUIFRAME.DATALOADER_ON |
---|
[3feed3e] | 330 | style2 = self.__gui_style & GUIFRAME.PLOTTING_ON |
---|
[7a67e075] | 331 | if style1 == GUIFRAME.DATALOADER_ON: |
---|
[52b8b74] | 332 | try: |
---|
| 333 | from sans.guiframe.local_perspectives.data_loader import data_loader |
---|
[3feed3e] | 334 | self._data_plugin = data_loader.Plugin() |
---|
[52b8b74] | 335 | plugins.append(self._data_plugin) |
---|
| 336 | except: |
---|
[3feed3e] | 337 | msg = "ViewerFrame._get_local_plugins:" |
---|
[52b8b74] | 338 | msg += "cannot import dataloader plugin.\n %s" % sys.exc_value |
---|
| 339 | logging.error(msg) |
---|
[3feed3e] | 340 | if style2 == GUIFRAME.PLOTTING_ON: |
---|
[52b8b74] | 341 | try: |
---|
| 342 | from sans.guiframe.local_perspectives.plotting import plotting |
---|
| 343 | self._plotting_plugin = plotting.Plugin() |
---|
| 344 | plugins.append(self._plotting_plugin) |
---|
| 345 | except: |
---|
[3feed3e] | 346 | msg = "ViewerFrame._get_local_plugins:" |
---|
[52b8b74] | 347 | msg += "cannot import plotting plugin.\n %s" % sys.exc_value |
---|
| 348 | logging.error(msg) |
---|
[3feed3e] | 349 | |
---|
[52b8b74] | 350 | return plugins |
---|
| 351 | |
---|
[41d466f] | 352 | def _find_plugins(self, dir="perspectives"): |
---|
| 353 | """ |
---|
[d955bf19] | 354 | Find available perspective plug-ins |
---|
| 355 | |
---|
| 356 | :param dir: directory in which to look for plug-ins |
---|
| 357 | |
---|
| 358 | :return: list of plug-ins |
---|
| 359 | |
---|
[41d466f] | 360 | """ |
---|
| 361 | import imp |
---|
| 362 | plugins = [] |
---|
| 363 | # Go through files in panels directory |
---|
| 364 | try: |
---|
| 365 | list = os.listdir(dir) |
---|
[a88ac04] | 366 | ## the default panel is the panel is the last plugin added |
---|
| 367 | for item in list: |
---|
[41d466f] | 368 | toks = os.path.splitext(os.path.basename(item)) |
---|
[c3f697e] | 369 | name = '' |
---|
[41d466f] | 370 | if not toks[0] == '__init__': |
---|
[32c0841] | 371 | if toks[1] == '.py' or toks[1] == '': |
---|
[41d466f] | 372 | name = toks[0] |
---|
[56681bd] | 373 | #check the validity of the module name parsed |
---|
| 374 | #before trying to import it |
---|
| 375 | if name is None or name.strip() == '': |
---|
| 376 | continue |
---|
[41d466f] | 377 | path = [os.path.abspath(dir)] |
---|
[c3f697e] | 378 | file = '' |
---|
[41d466f] | 379 | try: |
---|
[32c0841] | 380 | if toks[1] == '': |
---|
[41d466f] | 381 | mod_path = '.'.join([dir, name]) |
---|
[32c0841] | 382 | module = __import__(mod_path, globals(), |
---|
| 383 | locals(), [name]) |
---|
[41d466f] | 384 | else: |
---|
| 385 | (file, path, info) = imp.find_module(name, path) |
---|
[32c0841] | 386 | module = imp.load_module( name, file, item, info) |
---|
[41d466f] | 387 | if hasattr(module, "PLUGIN_ID"): |
---|
[f444b20] | 388 | try: |
---|
| 389 | plug = module.Plugin() |
---|
| 390 | if plug.set_default_perspective(): |
---|
| 391 | self._current_perspective = plug |
---|
| 392 | plugins.append(plug) |
---|
[32c0841] | 393 | msg = "Found plug-in: %s" % module.PLUGIN_ID |
---|
| 394 | logging.info(msg) |
---|
[41d466f] | 395 | except: |
---|
[32c0841] | 396 | msg = "Error accessing PluginPanel" |
---|
| 397 | msg += " in %s\n %s" % (name, sys.exc_value) |
---|
| 398 | config.printEVT(msg) |
---|
[41d466f] | 399 | except: |
---|
[32c0841] | 400 | msg = "ViewerFrame._find_plugins: %s" % sys.exc_value |
---|
[56681bd] | 401 | #print msg |
---|
[32c0841] | 402 | logging.error(msg) |
---|
[41d466f] | 403 | finally: |
---|
[32c0841] | 404 | if not file == None: |
---|
[41d466f] | 405 | file.close() |
---|
| 406 | except: |
---|
[32c0841] | 407 | # Should raise and catch at a higher level and |
---|
| 408 | # display error on status bar |
---|
[41d466f] | 409 | pass |
---|
| 410 | return plugins |
---|
| 411 | |
---|
[f9e803e] | 412 | def set_welcome_panel(self, panel_class): |
---|
| 413 | """ |
---|
[d955bf19] | 414 | Sets the default panel as the given welcome panel |
---|
| 415 | |
---|
| 416 | :param panel_class: class of the welcome panel to be instantiated |
---|
| 417 | |
---|
[f9e803e] | 418 | """ |
---|
[d955bf19] | 419 | self.defaultPanel = panel_class(self, -1, style=wx.RAISED_BORDER) |
---|
[b28278e] | 420 | |
---|
[3feed3e] | 421 | def _get_panels_size(self, p): |
---|
| 422 | """ |
---|
| 423 | find the proper size of the current panel |
---|
| 424 | get the proper panel width and height |
---|
| 425 | """ |
---|
| 426 | panel_height_min = self._window_height |
---|
| 427 | panel_width_min = self._window_width |
---|
| 428 | style = self.__gui_style & (GUIFRAME.MANAGER_ON) |
---|
| 429 | if self._data_panel is not None and (p == self._data_panel): |
---|
[1b1bbf9] | 430 | panel_width_min = self._window_width * 4/25 |
---|
| 431 | panel_height_min = self._window_height * 0.8 |
---|
[3feed3e] | 432 | return panel_width_min, panel_height_min |
---|
| 433 | if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: |
---|
| 434 | style = self.__gui_style & (GUIFRAME.PLOTTING_ON|GUIFRAME.MANAGER_ON) |
---|
| 435 | if style == (GUIFRAME.PLOTTING_ON|GUIFRAME.MANAGER_ON): |
---|
[18ec684] | 436 | panel_width_min = self._window_width * 15/25 |
---|
[3feed3e] | 437 | return panel_width_min, panel_height_min |
---|
| 438 | return panel_width_min, panel_height_min |
---|
| 439 | |
---|
[41d466f] | 440 | def _load_panels(self): |
---|
| 441 | """ |
---|
[d955bf19] | 442 | Load all panels in the panels directory |
---|
[41d466f] | 443 | """ |
---|
| 444 | |
---|
| 445 | # Look for plug-in panels |
---|
[c1469ebe] | 446 | panels = [] |
---|
[41d466f] | 447 | for item in self.plugins: |
---|
| 448 | if hasattr(item, "get_panels"): |
---|
| 449 | ps = item.get_panels(self) |
---|
| 450 | panels.extend(ps) |
---|
[3feed3e] | 451 | |
---|
[41d466f] | 452 | # Show a default panel with some help information |
---|
| 453 | # It also sets the size of the application windows |
---|
[c9454bb] | 454 | #TODO: Use this for slpash screen |
---|
[f9e803e] | 455 | if self.defaultPanel is None: |
---|
[32c0841] | 456 | self.defaultPanel = DefaultPanel(self, -1, style=wx.RAISED_BORDER) |
---|
[3feed3e] | 457 | # add a blank default panel always present |
---|
[41d466f] | 458 | self.panels["default"] = self.defaultPanel |
---|
| 459 | self._mgr.AddPane(self.defaultPanel, wx.aui.AuiPaneInfo(). |
---|
| 460 | Name("default"). |
---|
[1b1bbf9] | 461 | CenterPane(). |
---|
| 462 | #CloseButton(False). |
---|
| 463 | #MinimizeButton(False). |
---|
[32c0841] | 464 | # This is where we set the size of |
---|
| 465 | # the application window |
---|
| 466 | BestSize(wx.Size(self._window_width, |
---|
| 467 | self._window_height)). |
---|
[41d466f] | 468 | Show()) |
---|
[1b1bbf9] | 469 | |
---|
[3feed3e] | 470 | #add data panel |
---|
| 471 | self.panels["data_panel"] = self._data_panel |
---|
| 472 | w, h = self._get_panels_size(self._data_panel) |
---|
| 473 | self._mgr.AddPane(self._data_panel, wx.aui.AuiPaneInfo(). |
---|
| 474 | Name(self._data_panel.window_name). |
---|
[1b1bbf9] | 475 | Caption(self._data_panel.window_caption). |
---|
[3feed3e] | 476 | Left(). |
---|
| 477 | MinimizeButton(). |
---|
[1b1bbf9] | 478 | CloseButton(True). |
---|
[18ec684] | 479 | TopDockable(False). |
---|
| 480 | BottomDockable(False). |
---|
| 481 | LeftDockable(True). |
---|
| 482 | RightDockable(False). |
---|
| 483 | BestSize(wx.Size(w, h)). |
---|
[d828481] | 484 | Hide()) |
---|
[1b1bbf9] | 485 | |
---|
[3feed3e] | 486 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
[1b1bbf9] | 487 | data_pane = self._mgr.GetPane(self.panels["data_panel"].window_name) |
---|
[3feed3e] | 488 | if style != GUIFRAME.MANAGER_ON: |
---|
[64e44c1] | 489 | self._mgr.GetPane(self.panels["data_panel"].window_name).Hide() |
---|
[d828481] | 490 | else: |
---|
[64e44c1] | 491 | self._mgr.GetPane(self.panels["data_panel"].window_name).Show() |
---|
| 492 | |
---|
[41d466f] | 493 | # Add the panels to the AUI manager |
---|
| 494 | for panel_class in panels: |
---|
| 495 | p = panel_class |
---|
| 496 | id = wx.NewId() |
---|
[1b1bbf9] | 497 | #w, h = self._get_panels_size(p) |
---|
[41d466f] | 498 | # Check whether we need to put this panel |
---|
| 499 | # in the center pane |
---|
[6f59a98] | 500 | if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: |
---|
[1b1bbf9] | 501 | w, h = self._get_panels_size(p) |
---|
[41d466f] | 502 | if p.CENTER_PANE: |
---|
| 503 | self.panels[str(id)] = p |
---|
| 504 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
[1b1bbf9] | 505 | Name(p.window_name). |
---|
| 506 | Caption(p.window_caption). |
---|
| 507 | #CenterPane(). |
---|
| 508 | Center(). |
---|
| 509 | CloseButton(False). |
---|
| 510 | #MinimizeButton(False). |
---|
| 511 | #BestSize(wx.Size(w, h)). |
---|
| 512 | Hide()) |
---|
[41d466f] | 513 | else: |
---|
| 514 | self.panels[str(id)] = p |
---|
| 515 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
| 516 | Name(p.window_name).Caption(p.window_caption). |
---|
| 517 | Right(). |
---|
| 518 | Dock(). |
---|
| 519 | TopDockable(). |
---|
| 520 | BottomDockable(). |
---|
| 521 | LeftDockable(). |
---|
| 522 | RightDockable(). |
---|
| 523 | MinimizeButton(). |
---|
[3feed3e] | 524 | Hide()) |
---|
[b28278e] | 525 | |
---|
[c70eb7c] | 526 | def update_data(self, prev_data, new_data): |
---|
| 527 | """ |
---|
| 528 | """ |
---|
| 529 | prev_id, data_state = self._data_manager.update_data(prev_data=prev_data, |
---|
| 530 | new_data=new_data) |
---|
[e88ebfd] | 531 | |
---|
[c70eb7c] | 532 | self._data_panel.remove_by_id(prev_id) |
---|
| 533 | self._data_panel.load_data_list(data_state) |
---|
[e88ebfd] | 534 | |
---|
| 535 | def update_theory(self, data_id, theory, state=None): |
---|
| 536 | """ |
---|
| 537 | """ |
---|
| 538 | data_state = self._data_manager.update_theory(data_id=data_id, |
---|
| 539 | theory=theory, |
---|
| 540 | state=state) |
---|
| 541 | self._data_panel.load_data_list(data_state) |
---|
[c70eb7c] | 542 | |
---|
[e6a93df] | 543 | def onfreeze(self, theory_id): |
---|
| 544 | """ |
---|
| 545 | """ |
---|
| 546 | data_state_list = self._data_manager.freeze(theory_id) |
---|
| 547 | self._data_panel.load_data_list(list=data_state_list) |
---|
| 548 | for data_state in data_state_list.values(): |
---|
| 549 | new_plot = data_state.get_data() |
---|
[df22224] | 550 | |
---|
[e6a93df] | 551 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
| 552 | title=new_plot.title)) |
---|
| 553 | |
---|
[c70eb7c] | 554 | def freeze(self, data_id, theory_id): |
---|
| 555 | """ |
---|
| 556 | """ |
---|
| 557 | data_state_list = self._data_manager.freeze_theory(data_id=data_id, |
---|
| 558 | theory_id=theory_id) |
---|
| 559 | self._data_panel.load_data_list(list=data_state_list) |
---|
[ee2b492] | 560 | for data_state in data_state_list.values(): |
---|
| 561 | new_plot = data_state.get_data() |
---|
| 562 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
[c70eb7c] | 563 | title=new_plot.title)) |
---|
| 564 | |
---|
| 565 | def delete_data(self, data): |
---|
| 566 | """ |
---|
| 567 | """ |
---|
| 568 | self._current_perspective.delete_data(data) |
---|
| 569 | |
---|
| 570 | |
---|
[a07e72f] | 571 | def get_context_menu(self, plotpanel=None): |
---|
[41d466f] | 572 | """ |
---|
[d955bf19] | 573 | Get the context menu items made available |
---|
| 574 | by the different plug-ins. |
---|
| 575 | This function is used by the plotting module |
---|
[41d466f] | 576 | """ |
---|
[a07e72f] | 577 | if plotpanel is None: |
---|
| 578 | return |
---|
[41d466f] | 579 | menu_list = [] |
---|
| 580 | for item in self.plugins: |
---|
[a07e72f] | 581 | menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) |
---|
[41d466f] | 582 | return menu_list |
---|
| 583 | |
---|
| 584 | def popup_panel(self, p): |
---|
| 585 | """ |
---|
[d955bf19] | 586 | Add a panel object to the AUI manager |
---|
| 587 | |
---|
| 588 | :param p: panel object to add to the AUI manager |
---|
[41d466f] | 589 | |
---|
[d955bf19] | 590 | :return: ID of the event associated with the new panel [int] |
---|
| 591 | |
---|
| 592 | """ |
---|
[41d466f] | 593 | ID = wx.NewId() |
---|
| 594 | self.panels[str(ID)] = p |
---|
| 595 | count = 0 |
---|
| 596 | for item in self.panels: |
---|
[383189f9] | 597 | if self.panels[item].window_name.startswith(p.window_name): |
---|
[41d466f] | 598 | count += 1 |
---|
| 599 | windowname = p.window_name |
---|
| 600 | caption = p.window_caption |
---|
[32c0841] | 601 | if count > 0: |
---|
[41d466f] | 602 | windowname += str(count+1) |
---|
| 603 | caption += (' '+str(count)) |
---|
| 604 | p.window_name = windowname |
---|
| 605 | p.window_caption = caption |
---|
| 606 | |
---|
[7a67e075] | 607 | style1 = self.__gui_style & GUIFRAME.FIXED_PANEL |
---|
| 608 | style2 = self.__gui_style & GUIFRAME.FLOATING_PANEL |
---|
| 609 | if style1 == GUIFRAME.FIXED_PANEL: |
---|
| 610 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
[1b1bbf9] | 611 | Name(windowname). |
---|
| 612 | Caption(caption). |
---|
| 613 | Position(10). |
---|
| 614 | Floatable(). |
---|
| 615 | Right(). |
---|
| 616 | Dock(). |
---|
[7a67e075] | 617 | MinimizeButton(). |
---|
| 618 | Resizable(True). |
---|
[c5e84fb] | 619 | # Use a large best size to make sure the AUI |
---|
| 620 | # manager takes all the available space |
---|
[1b1bbf9] | 621 | BestSize(wx.Size(PLOPANEL_WIDTH, |
---|
| 622 | PLOPANEL_HEIGTH))) |
---|
| 623 | #MinSize(wx.Size(PLOPANEL_WIDTH*0.9, |
---|
| 624 | # PLOPANEL_HEIGTH))) |
---|
[3feed3e] | 625 | self._popup_fixed_panel(p) |
---|
[213892bc] | 626 | |
---|
[0663dfb1] | 627 | elif style2 == GUIFRAME.FLOATING_PANEL: |
---|
[7a67e075] | 628 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
| 629 | Name(windowname).Caption(caption). |
---|
| 630 | MinimizeButton(). |
---|
| 631 | Resizable(True). |
---|
[c5e84fb] | 632 | # Use a large best size to make sure the AUI |
---|
| 633 | # manager takes all the available space |
---|
[1b1bbf9] | 634 | BestSize(wx.Size(PLOPANEL_WIDTH, |
---|
| 635 | PLOPANEL_HEIGTH))) |
---|
[3feed3e] | 636 | self._popup_floating_panel(p) |
---|
[7a67e075] | 637 | |
---|
[d0802c3] | 638 | pane = self._mgr.GetPane(windowname) |
---|
[64e44c1] | 639 | self._mgr.MaximizePane(pane) |
---|
| 640 | self._mgr.RestoreMaximizedPane() |
---|
[41d466f] | 641 | # Register for showing/hiding the panel |
---|
[56d5562] | 642 | wx.EVT_MENU(self, ID, self.on_view) |
---|
[0a2fdca] | 643 | if p not in self.plot_panels.values(): |
---|
| 644 | self.plot_panels[ID] = p |
---|
| 645 | if self._data_panel is not None and \ |
---|
| 646 | self._plotting_plugin is not None: |
---|
| 647 | ind = self._data_panel.cb_plotpanel.FindString('None') |
---|
| 648 | if ind != wx.NOT_FOUND: |
---|
| 649 | self._data_panel.cb_plotpanel.Delete(ind) |
---|
| 650 | self._data_panel.cb_plotpanel.Append(str(caption), p) |
---|
[41d466f] | 651 | self._mgr.Update() |
---|
| 652 | return ID |
---|
| 653 | |
---|
| 654 | def _setup_menus(self): |
---|
| 655 | """ |
---|
[d955bf19] | 656 | Set up the application menus |
---|
[41d466f] | 657 | """ |
---|
| 658 | # Menu |
---|
[b7c7a1c] | 659 | self._menubar = wx.MenuBar() |
---|
[52b8b74] | 660 | self._add_menu_file() |
---|
[f932c02] | 661 | self._add_menu_edit() |
---|
[34e3ab3] | 662 | self._add_menu_view() |
---|
| 663 | #self._add_menu_data() |
---|
[52b8b74] | 664 | self._add_menu_application() |
---|
[c5e84fb] | 665 | self._add_menu_tool() |
---|
[7bc88bf] | 666 | self._add_current_plugin_menu() |
---|
[52b8b74] | 667 | self._add_menu_window() |
---|
[c5e84fb] | 668 | self._add_help_menu() |
---|
| 669 | self.SetMenuBar(self._menubar) |
---|
| 670 | |
---|
[f036c692] | 671 | def _setup_tool_bar(self): |
---|
| 672 | """ |
---|
| 673 | add toolbar to the frame |
---|
| 674 | """ |
---|
| 675 | #set toolbar |
---|
| 676 | self._toolbar = GUIToolBar(self, -1) |
---|
| 677 | self.SetToolBar(self._toolbar) |
---|
[a45037aa] | 678 | self._update_toolbar_helper() |
---|
[3554fd39] | 679 | self._on_toggle_toolbar(event=None) |
---|
[a45037aa] | 680 | |
---|
| 681 | def _update_toolbar_helper(self): |
---|
| 682 | """ |
---|
| 683 | """ |
---|
[f7e9af2] | 684 | application_name = 'No Selected Analysis' |
---|
[a45037aa] | 685 | panel_name = 'No Panel on Focus' |
---|
[3450e7f] | 686 | if self._toolbar is None: |
---|
| 687 | return |
---|
[0a2fdca] | 688 | self._toolbar.update_toolbar(self.cpanel_on_focus) |
---|
[f036c692] | 689 | if self._current_perspective is not None: |
---|
[a45037aa] | 690 | application_name = self._current_perspective.sub_menu |
---|
[0a2fdca] | 691 | if self.cpanel_on_focus is not None: |
---|
| 692 | panel_name = self.cpanel_on_focus.window_caption |
---|
[a45037aa] | 693 | self._toolbar.update_button(application_name=application_name, |
---|
| 694 | panel_name=panel_name) |
---|
| 695 | self._toolbar.Realize() |
---|
| 696 | |
---|
[c5e84fb] | 697 | def _add_menu_tool(self): |
---|
| 698 | """ |
---|
| 699 | Tools menu |
---|
| 700 | Go through plug-ins and find tools to populate the tools menu |
---|
| 701 | """ |
---|
[5342eb8] | 702 | style = self.__gui_style & GUIFRAME.CALCULATOR_ON |
---|
| 703 | if style == GUIFRAME.CALCULATOR_ON: |
---|
[c5e84fb] | 704 | self._tool_menu = None |
---|
| 705 | for item in self.plugins: |
---|
| 706 | if hasattr(item, "get_tools"): |
---|
| 707 | for tool in item.get_tools(): |
---|
| 708 | # Only create a menu if we have at least one tool |
---|
| 709 | if self._tool_menu is None: |
---|
| 710 | self._tool_menu = wx.Menu() |
---|
| 711 | id = wx.NewId() |
---|
| 712 | self._tool_menu.Append(id, tool[0], tool[1]) |
---|
| 713 | wx.EVT_MENU(self, id, tool[2]) |
---|
| 714 | if self._tool_menu is not None: |
---|
[f932c02] | 715 | self._menubar.Append(self._tool_menu, '&Tool') |
---|
[c5e84fb] | 716 | |
---|
| 717 | def _add_current_plugin_menu(self): |
---|
| 718 | """ |
---|
| 719 | add current plugin menu |
---|
[cbf22e5] | 720 | Look for plug-in menus |
---|
| 721 | Add available plug-in sub-menus. |
---|
[c5e84fb] | 722 | """ |
---|
[7bc88bf] | 723 | if (self._menubar is None) or (self._current_perspective is None): |
---|
[cbf22e5] | 724 | return |
---|
[7bc88bf] | 725 | #replace or add a new menu for the current plugin |
---|
[4c0572f] | 726 | |
---|
| 727 | pos = self._menubar.FindMenu(str(self._applications_menu_name)) |
---|
[7bc88bf] | 728 | if pos != -1: |
---|
| 729 | menu_list = self._current_perspective.populate_menu(self) |
---|
| 730 | if menu_list: |
---|
[4c0572f] | 731 | for (menu, name) in menu_list: |
---|
| 732 | hidden_menu = self._menubar.Replace(pos, menu, name) |
---|
| 733 | self._applications_menu_name = name |
---|
| 734 | #self._applications_menu_pos = pos |
---|
[7bc88bf] | 735 | else: |
---|
| 736 | hidden_menu = self._menubar.Remove(pos) |
---|
[4c0572f] | 737 | self._applications_menu_name = None |
---|
[7bc88bf] | 738 | #get the position of the menu when it first added |
---|
[4c0572f] | 739 | self._applications_menu_pos = pos |
---|
| 740 | |
---|
[7bc88bf] | 741 | else: |
---|
| 742 | menu_list = self._current_perspective.populate_menu(self) |
---|
| 743 | if menu_list: |
---|
[4c0572f] | 744 | for (menu,name) in menu_list: |
---|
[95f9cc4] | 745 | if self._applications_menu_pos == -1: |
---|
[7bc88bf] | 746 | self._menubar.Append(menu, name) |
---|
| 747 | else: |
---|
[95f9cc4] | 748 | self._menubar.Insert(self._applications_menu_pos, menu, name) |
---|
[4c0572f] | 749 | self._applications_menu_name = name |
---|
[7bc88bf] | 750 | |
---|
[c5e84fb] | 751 | def _add_help_menu(self): |
---|
| 752 | """ |
---|
| 753 | add help menu |
---|
| 754 | """ |
---|
[41d466f] | 755 | # Help menu |
---|
[c5e84fb] | 756 | self._help_menu = wx.Menu() |
---|
[d828481] | 757 | style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON |
---|
| 758 | if style == GUIFRAME.WELCOME_PANEL_ON: |
---|
| 759 | # add the welcome panel menu item |
---|
| 760 | if self.defaultPanel is not None: |
---|
| 761 | id = wx.NewId() |
---|
| 762 | self._help_menu.Append(id, '&Welcome', '') |
---|
| 763 | self._help_menu.AppendSeparator() |
---|
| 764 | wx.EVT_MENU(self, id, self.show_welcome_panel) |
---|
[fa452e4] | 765 | # Look for help item in plug-ins |
---|
| 766 | for item in self.plugins: |
---|
| 767 | if hasattr(item, "help"): |
---|
| 768 | id = wx.NewId() |
---|
[f7e9af2] | 769 | self._help_menu.Append(id,'&%s Help' % item.sub_menu, '') |
---|
[fa452e4] | 770 | wx.EVT_MENU(self, id, item.help) |
---|
[41d466f] | 771 | if config._do_aboutbox: |
---|
| 772 | id = wx.NewId() |
---|
[c5e84fb] | 773 | self._help_menu.Append(id,'&About', 'Software information') |
---|
[41d466f] | 774 | wx.EVT_MENU(self, id, self._onAbout) |
---|
[c5e84fb] | 775 | |
---|
[af20f6b] | 776 | # Checking for updates needs major refactoring to work with py2exe |
---|
| 777 | # We need to make sure it doesn't hang the application if the server |
---|
| 778 | # is not up. We also need to make sure there's a proper executable to |
---|
| 779 | # run if we spawn a new background process. |
---|
| 780 | #id = wx.NewId() |
---|
[c5e84fb] | 781 | #self._help_menu.Append(id,'&Check for update', |
---|
[32c0841] | 782 | #'Check for the latest version of %s' % config.__appname__) |
---|
[af20f6b] | 783 | #wx.EVT_MENU(self, id, self._check_update) |
---|
[c5e84fb] | 784 | self._menubar.Append(self._help_menu, '&Help') |
---|
| 785 | |
---|
[34e3ab3] | 786 | def _add_menu_view(self): |
---|
| 787 | """ |
---|
| 788 | add menu items under view menu |
---|
| 789 | """ |
---|
| 790 | self._view_menu = wx.Menu() |
---|
| 791 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 792 | id = wx.NewId() |
---|
| 793 | self._data_panel_menu = self._view_menu.Append(id, |
---|
| 794 | '&Data Explorer ON', '') |
---|
| 795 | wx.EVT_MENU(self, id, self.show_data_panel) |
---|
| 796 | if style == GUIFRAME.MANAGER_ON: |
---|
| 797 | self._data_panel_menu.SetText('Data Explorer OFF') |
---|
| 798 | else: |
---|
| 799 | self._data_panel_menu.SetText('Data Explorer ON') |
---|
| 800 | self._view_menu.AppendSeparator() |
---|
[570cb96] | 801 | id = wx.NewId() |
---|
[5342eb8] | 802 | style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
| 803 | if style1 == GUIFRAME.TOOLBAR_ON: |
---|
[570cb96] | 804 | self._toolbar_menu = self._view_menu.Append(id,'&Hide Toolbar', '') |
---|
[3554fd39] | 805 | else: |
---|
| 806 | self._toolbar_menu = self._view_menu.Append(id,'&Show Toolbar', '') |
---|
| 807 | wx.EVT_MENU(self, id, self._on_toggle_toolbar) |
---|
[34e3ab3] | 808 | self._menubar.Append(self._view_menu, '&View') |
---|
| 809 | |
---|
[52b8b74] | 810 | def _add_menu_window(self): |
---|
| 811 | """ |
---|
| 812 | add a menu window to the menu bar |
---|
| 813 | Window menu |
---|
| 814 | Attach a menu item for each panel in our |
---|
| 815 | panel list that also appears in a plug-in. |
---|
| 816 | |
---|
| 817 | Only add the panel menu if there is only one perspective and |
---|
| 818 | it has more than two panels. |
---|
| 819 | Note: the first plug-in is always the plotting plug-in. |
---|
| 820 | The first application |
---|
| 821 | #plug-in is always the second one in the list. |
---|
| 822 | """ |
---|
| 823 | self._window_menu = wx.Menu() |
---|
| 824 | if self._plotting_plugin is not None: |
---|
[bf4402c3] | 825 | for (menu, name) in self._plotting_plugin.populate_menu(self): |
---|
[52b8b74] | 826 | self._window_menu.AppendSubMenu(menu, name) |
---|
[52f3c98] | 827 | self._menubar.Append(self._window_menu, '&Graph') |
---|
| 828 | |
---|
[4753fc2] | 829 | style = self.__gui_style & GUIFRAME.PLOTTING_ON |
---|
| 830 | if style == GUIFRAME.PLOTTING_ON: |
---|
| 831 | self._window_menu.AppendSeparator() |
---|
| 832 | id = wx.NewId() |
---|
| 833 | preferences_menu = wx.Menu() |
---|
[f932c02] | 834 | hint = "All plot panels will floating" |
---|
[52f3c98] | 835 | preferences_menu.Append(id, '&Float', hint) |
---|
[4753fc2] | 836 | wx.EVT_MENU(self, id, self.set_plotpanel_floating) |
---|
| 837 | id = wx.NewId() |
---|
[f932c02] | 838 | hint = "All plot panels will displayed within the frame" |
---|
[52f3c98] | 839 | preferences_menu.Append(id, '&Dock', hint) |
---|
[4753fc2] | 840 | wx.EVT_MENU(self, id, self.set_plotpanel_fixed) |
---|
[52f3c98] | 841 | |
---|
[4753fc2] | 842 | self._window_menu.AppendSubMenu(preferences_menu,'&Preferences') |
---|
[d828481] | 843 | if self._window_menu.GetMenuItemCount() == 0: |
---|
[52f3c98] | 844 | pos = self._menubar.FindMenu('Graph') |
---|
[d828481] | 845 | self._menubar.Remove(pos) |
---|
[7a67e075] | 846 | #wx.EVT_MENU(self, id, self.show_preferences_panel) |
---|
[52b8b74] | 847 | """ |
---|
| 848 | if len(self.plugins) == 2: |
---|
| 849 | plug = self.plugins[1] |
---|
| 850 | pers = plug.get_perspective() |
---|
| 851 | |
---|
| 852 | if len(pers) > 1: |
---|
| 853 | self._window_menu = wx.Menu() |
---|
| 854 | for item in self.panels: |
---|
| 855 | if item == 'default': |
---|
| 856 | continue |
---|
| 857 | panel = self.panels[item] |
---|
| 858 | if panel.window_name in pers: |
---|
| 859 | self._window_menu.Append(int(item), |
---|
| 860 | panel.window_caption, |
---|
| 861 | "Show %s window" % panel.window_caption) |
---|
[56d5562] | 862 | wx.EVT_MENU(self, int(item), self.on_view) |
---|
[52b8b74] | 863 | self._menubar.Append(self._window_menu, '&Window') |
---|
| 864 | """ |
---|
| 865 | |
---|
| 866 | def _add_menu_application(self): |
---|
| 867 | """ |
---|
| 868 | |
---|
| 869 | # Attach a menu item for each defined perspective or application. |
---|
| 870 | # Only add the perspective menu if there are more than one perspectives |
---|
| 871 | add menu application |
---|
| 872 | """ |
---|
[7a67e075] | 873 | style = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS |
---|
| 874 | if style == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
[95f9cc4] | 875 | plug_data_count = False |
---|
| 876 | plug_no_data_count = False |
---|
| 877 | self._applications_menu = wx.Menu() |
---|
[788ff23] | 878 | pos = 0 |
---|
[95f9cc4] | 879 | separator = self._applications_menu.AppendSeparator() |
---|
[52b8b74] | 880 | for plug in self.plugins: |
---|
| 881 | if len(plug.get_perspective()) > 0: |
---|
| 882 | id = wx.NewId() |
---|
[95f9cc4] | 883 | if plug.use_data(): |
---|
[788ff23] | 884 | |
---|
| 885 | self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, |
---|
[f7e9af2] | 886 | "Switch to analysis: %s" % plug.sub_menu) |
---|
[95f9cc4] | 887 | plug_data_count = True |
---|
[788ff23] | 888 | pos += 1 |
---|
[95f9cc4] | 889 | else: |
---|
| 890 | plug_no_data_count = True |
---|
| 891 | self._applications_menu.AppendCheckItem(id, plug.sub_menu, |
---|
[f7e9af2] | 892 | "Switch to analysis: %s" % plug.sub_menu) |
---|
[52b8b74] | 893 | wx.EVT_MENU(self, id, plug.on_perspective) |
---|
[788ff23] | 894 | #self._applications_menu. |
---|
| 895 | if (not plug_data_count or not plug_no_data_count): |
---|
[95f9cc4] | 896 | self._applications_menu.RemoveItem(separator) |
---|
[f7e9af2] | 897 | self._menubar.Append(self._applications_menu, '&Analysis') |
---|
[95f9cc4] | 898 | self._check_applications_menu() |
---|
[52b8b74] | 899 | |
---|
[34e3ab3] | 900 | def _populate_file_menu(self): |
---|
| 901 | """ |
---|
| 902 | Insert menu item under file menu |
---|
| 903 | """ |
---|
| 904 | for plugin in self.plugins: |
---|
| 905 | if len(plugin.populate_file_menu()) > 0: |
---|
| 906 | for item in plugin.populate_file_menu(): |
---|
| 907 | m_name, m_hint, m_handler = item |
---|
| 908 | id = wx.NewId() |
---|
| 909 | self._file_menu.Append(id, m_name, m_hint) |
---|
| 910 | wx.EVT_MENU(self, id, m_handler) |
---|
| 911 | self._file_menu.AppendSeparator() |
---|
| 912 | |
---|
[52b8b74] | 913 | def _add_menu_file(self): |
---|
| 914 | """ |
---|
| 915 | add menu file |
---|
| 916 | """ |
---|
[d828481] | 917 | |
---|
[52b8b74] | 918 | # File menu |
---|
[52725d6] | 919 | self._file_menu = wx.Menu() |
---|
[34e3ab3] | 920 | #append item from plugin under menu file if necessary |
---|
| 921 | self._populate_file_menu() |
---|
[d828481] | 922 | style = self.__gui_style & GUIFRAME.DATALOADER_ON |
---|
[4c01978] | 923 | style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS |
---|
[d828481] | 924 | if style == GUIFRAME.DATALOADER_ON: |
---|
[f7e9af2] | 925 | id = wx.NewId() |
---|
| 926 | hint_load_file = "read all analysis states save previously" |
---|
| 927 | self._save_appl_menu = self._file_menu.Append(id, |
---|
| 928 | '&Open Project', hint_load_file) |
---|
| 929 | wx.EVT_MENU(self, id, self._on_open_state_project) |
---|
| 930 | |
---|
[4c01978] | 931 | if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
| 932 | # some menu of plugin to be seen under file menu |
---|
[f7e9af2] | 933 | hint_load_file = "Read a status files and load" |
---|
| 934 | hint_load_file += " them into the analysis" |
---|
[4c01978] | 935 | id = wx.NewId() |
---|
| 936 | self._save_appl_menu = self._file_menu.Append(id, |
---|
[f7e9af2] | 937 | '&Open Analysis', hint_load_file) |
---|
[4c01978] | 938 | wx.EVT_MENU(self, id, self._on_open_state_application) |
---|
| 939 | |
---|
[f7e9af2] | 940 | self._file_menu.AppendSeparator() |
---|
[d828481] | 941 | id = wx.NewId() |
---|
[f7e9af2] | 942 | self._file_menu.Append(id, '&Save Project', |
---|
| 943 | 'Save the state of the whole analysis') |
---|
| 944 | |
---|
| 945 | wx.EVT_MENU(self, id, self._on_save_project) |
---|
[4c01978] | 946 | if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
[f7e9af2] | 947 | #self._file_menu.AppendSeparator() |
---|
[4c01978] | 948 | id = wx.NewId() |
---|
| 949 | self._save_appl_menu = self._file_menu.Append(id, |
---|
[f7e9af2] | 950 | '&Save Analysis', |
---|
| 951 | 'Save state of the current active analysis panel') |
---|
[4c01978] | 952 | wx.EVT_MENU(self, id, self._on_save_application) |
---|
[f7e9af2] | 953 | |
---|
[d828481] | 954 | self._file_menu.AppendSeparator() |
---|
[52725d6] | 955 | |
---|
| 956 | id = wx.NewId() |
---|
| 957 | self._file_menu.Append(id, '&Quit', 'Exit') |
---|
[52b8b74] | 958 | wx.EVT_MENU(self, id, self.Close) |
---|
| 959 | # Add sub menus |
---|
[52725d6] | 960 | self._menubar.Append(self._file_menu, '&File') |
---|
[52b8b74] | 961 | |
---|
[d828481] | 962 | def _add_menu_edit(self): |
---|
| 963 | """ |
---|
| 964 | add menu edit |
---|
| 965 | """ |
---|
| 966 | # Edit Menu |
---|
| 967 | self._edit_menu = wx.Menu() |
---|
[f036c692] | 968 | self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo', |
---|
| 969 | 'Undo the previous action') |
---|
| 970 | wx.EVT_MENU(self, GUIFRAME_ID.UNDO_ID, self.on_undo_panel) |
---|
| 971 | self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo', |
---|
| 972 | 'Redo the previous action') |
---|
| 973 | wx.EVT_MENU(self, GUIFRAME_ID.REDO_ID, self.on_redo_panel) |
---|
[d828481] | 974 | self._edit_menu.AppendSeparator() |
---|
[783940c] | 975 | self._edit_menu.Append(GUIFRAME_ID.PREVIEW_ID, '&Report', |
---|
[f036c692] | 976 | 'Preview current panel') |
---|
| 977 | wx.EVT_MENU(self, GUIFRAME_ID.PREVIEW_ID, self.on_preview_panel) |
---|
| 978 | self._edit_menu.Append(GUIFRAME_ID.PRINT_ID, '&Print', |
---|
| 979 | 'Print current panel') |
---|
| 980 | wx.EVT_MENU(self, GUIFRAME_ID.PRINT_ID, self.on_print_panel) |
---|
| 981 | self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset', |
---|
| 982 | 'Reset current panel') |
---|
| 983 | wx.EVT_MENU(self, GUIFRAME_ID.RESET_ID, self.on_reset_panel) |
---|
[34e3ab3] | 984 | |
---|
[f036c692] | 985 | self._menubar.Append(self._edit_menu, '&Edit') |
---|
| 986 | self.enable_edit_menu() |
---|
[d828481] | 987 | |
---|
[75fbd17] | 988 | def get_style(self): |
---|
[52b8b74] | 989 | """ |
---|
| 990 | """ |
---|
[75fbd17] | 991 | return self.__gui_style |
---|
| 992 | |
---|
| 993 | def _add_menu_data(self): |
---|
[52b8b74] | 994 | """ |
---|
[75fbd17] | 995 | Add menu item item data to menu bar |
---|
[52b8b74] | 996 | """ |
---|
[75fbd17] | 997 | if self._data_plugin is not None: |
---|
| 998 | menu_list = self._data_plugin.populate_menu(self) |
---|
| 999 | if menu_list: |
---|
| 1000 | for (menu, name) in menu_list: |
---|
| 1001 | self._menubar.Append(menu, name) |
---|
[34e3ab3] | 1002 | |
---|
[f932c02] | 1003 | |
---|
[3554fd39] | 1004 | def _on_toggle_toolbar(self, event=None): |
---|
[a45037aa] | 1005 | """ |
---|
| 1006 | hide or show toolbar |
---|
| 1007 | """ |
---|
| 1008 | if self._toolbar is None: |
---|
| 1009 | return |
---|
| 1010 | if self._toolbar.IsShown(): |
---|
| 1011 | if self._toolbar_menu is not None: |
---|
| 1012 | self._toolbar_menu.SetItemLabel('Show Toolbar') |
---|
| 1013 | self._toolbar.Hide() |
---|
| 1014 | else: |
---|
| 1015 | if self._toolbar_menu is not None: |
---|
| 1016 | self._toolbar_menu.SetItemLabel('Hide Toolbar') |
---|
| 1017 | self._toolbar.Show() |
---|
| 1018 | self._toolbar.Realize() |
---|
| 1019 | |
---|
[41d466f] | 1020 | def _on_status_event(self, evt): |
---|
| 1021 | """ |
---|
[d955bf19] | 1022 | Display status message |
---|
[41d466f] | 1023 | """ |
---|
[db10f97] | 1024 | self.sb.set_status(event=evt) |
---|
[dd66fbd] | 1025 | |
---|
[56d5562] | 1026 | def on_view(self, evt): |
---|
[41d466f] | 1027 | """ |
---|
[d955bf19] | 1028 | A panel was selected to be shown. If it's not already |
---|
| 1029 | shown, display it. |
---|
| 1030 | |
---|
| 1031 | :param evt: menu event |
---|
| 1032 | |
---|
[41d466f] | 1033 | """ |
---|
[6d727ae] | 1034 | self.show_panel(evt.GetId(), 'on') |
---|
| 1035 | wx.CallLater(5, self.set_schedule(True)) |
---|
[c1469ebe] | 1036 | |
---|
[b28278e] | 1037 | def on_close_welcome_panel(self): |
---|
[c1469ebe] | 1038 | """ |
---|
[d955bf19] | 1039 | Close the welcome panel |
---|
[c1469ebe] | 1040 | """ |
---|
[629e8b9] | 1041 | if self.defaultPanel is None: |
---|
| 1042 | return |
---|
[1b1bbf9] | 1043 | default_panel = self._mgr.GetPane(self.panels["default"].window_name) |
---|
| 1044 | if default_panel.IsShown(): |
---|
| 1045 | default_panel.Hide() |
---|
[4d1dce4] | 1046 | # Recover current perspective |
---|
| 1047 | perspective = self._current_perspective |
---|
| 1048 | perspective.on_perspective(event=None) |
---|
[1b1bbf9] | 1049 | self._mgr.Update() |
---|
| 1050 | # Show toolbar |
---|
[5342eb8] | 1051 | style = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
| 1052 | if (style == GUIFRAME.TOOLBAR_ON) & (not self._toolbar.IsShown()): |
---|
[3554fd39] | 1053 | self._on_toggle_toolbar() |
---|
[1b1bbf9] | 1054 | |
---|
[c1469ebe] | 1055 | def show_welcome_panel(self, event): |
---|
| 1056 | """ |
---|
[d955bf19] | 1057 | Display the welcome panel |
---|
[c1469ebe] | 1058 | """ |
---|
[629e8b9] | 1059 | if self.defaultPanel is None: |
---|
| 1060 | return |
---|
[4bee68d] | 1061 | for id, panel in self.panels.iteritems(): |
---|
[c5e84fb] | 1062 | if id == 'default': |
---|
| 1063 | # Show default panel |
---|
| 1064 | if not self._mgr.GetPane(self.panels["default"].window_name).IsShown(): |
---|
| 1065 | self._mgr.GetPane(self.panels["default"].window_name).Show(True) |
---|
| 1066 | elif id == "data_panel": |
---|
| 1067 | flag = self._mgr.GetPane(self.panels["data_panel"].window_name).IsShown() |
---|
| 1068 | self._mgr.GetPane(self.panels["data_panel"].window_name).Show(flag) |
---|
[4bee68d] | 1069 | elif panel not in self.plot_panels.values() : |
---|
[c5e84fb] | 1070 | self._mgr.GetPane(self.panels[id].window_name).IsShown() |
---|
[c1469ebe] | 1071 | self._mgr.GetPane(self.panels[id].window_name).Hide() |
---|
[4bee68d] | 1072 | #if self._toolbar != None and not self._toolbar.IsShown(): |
---|
| 1073 | # self._toolbar.Show(True) |
---|
| 1074 | #self._on_toggle_toolbar() |
---|
[1b1bbf9] | 1075 | |
---|
[c1469ebe] | 1076 | self._mgr.Update() |
---|
[c5e84fb] | 1077 | |
---|
[6d727ae] | 1078 | def show_panel(self, uid, show=None): |
---|
[41d466f] | 1079 | """ |
---|
[d955bf19] | 1080 | Shows the panel with the given id |
---|
| 1081 | |
---|
| 1082 | :param uid: unique ID number of the panel to show |
---|
| 1083 | |
---|
[41d466f] | 1084 | """ |
---|
| 1085 | ID = str(uid) |
---|
| 1086 | config.printEVT("show_panel: %s" % ID) |
---|
| 1087 | if ID in self.panels.keys(): |
---|
[6d727ae] | 1088 | if not self._mgr.GetPane(self.panels[ID].window_name).IsShown(): |
---|
| 1089 | if show == 'on': |
---|
| 1090 | self._mgr.GetPane(self.panels[ID].window_name).Show() |
---|
[52f3c98] | 1091 | elif self.panels[ID].window_caption.split(" ")[0] == \ |
---|
| 1092 | "Residuals": |
---|
[6d727ae] | 1093 | self._mgr.GetPane(self.panels[ID].window_name).Hide() |
---|
| 1094 | else: |
---|
| 1095 | self._mgr.GetPane(self.panels[ID].window_name).Show() |
---|
[383189f9] | 1096 | # Hide default panel |
---|
| 1097 | self._mgr.GetPane(self.panels["default"].window_name).Hide() |
---|
[6d727ae] | 1098 | self._mgr.Update() |
---|
| 1099 | self._redraw_idle() |
---|
| 1100 | |
---|
[ae83ad3] | 1101 | def hide_panel(self, uid): |
---|
| 1102 | """ |
---|
| 1103 | hide panel |
---|
| 1104 | """ |
---|
| 1105 | ID = str(uid) |
---|
[0a2fdca] | 1106 | caption = self.panels[ID].window_caption |
---|
[ae83ad3] | 1107 | config.printEVT("hide_panel: %s" % ID) |
---|
| 1108 | if ID in self.panels.keys(): |
---|
| 1109 | if self._mgr.GetPane(self.panels[ID].window_name).IsShown(): |
---|
| 1110 | self._mgr.GetPane(self.panels[ID].window_name).Hide() |
---|
[0a2fdca] | 1111 | if self._data_panel is not None and \ |
---|
| 1112 | ID in self.plot_panels.keys(): |
---|
| 1113 | self._data_panel.cb_plotpanel.Append(str(caption), p) |
---|
[ae83ad3] | 1114 | # Hide default panel |
---|
| 1115 | self._mgr.GetPane(self.panels["default"].window_name).Hide() |
---|
| 1116 | self._mgr.Update() |
---|
[0a2fdca] | 1117 | |
---|
[c9937c0] | 1118 | def delete_panel(self, uid): |
---|
| 1119 | """ |
---|
| 1120 | delete panel given uid |
---|
| 1121 | """ |
---|
| 1122 | ID = str(uid) |
---|
| 1123 | config.printEVT("delete_panel: %s" % ID) |
---|
[0a2fdca] | 1124 | caption = self.panels[ID].window_caption |
---|
[c9937c0] | 1125 | if ID in self.panels.keys(): |
---|
[f7d0b74] | 1126 | self.panel_on_focus = None |
---|
[df22224] | 1127 | panel = self.panels[ID] |
---|
| 1128 | self._plotting_plugin.delete_panel(panel.group_id) |
---|
| 1129 | self._mgr.DetachPane(panel) |
---|
[f7d0b74] | 1130 | panel.Hide() |
---|
| 1131 | panel.clear() |
---|
| 1132 | panel.Close() |
---|
| 1133 | self._mgr.Update() |
---|
| 1134 | return |
---|
[2a62d5c] | 1135 | if ID in self.panels.keys(): |
---|
| 1136 | del self.panels[ID] |
---|
| 1137 | if ID in self.plot_panels.keys(): |
---|
| 1138 | del self.plot_panels[ID] |
---|
[0a2fdca] | 1139 | if self._data_panel is not None: |
---|
| 1140 | ind = self._data_panel.cb_plotpanel.FindString(str(caption)) |
---|
| 1141 | if ind != wx.NOT_FOUND: |
---|
[2a62d5c] | 1142 | self._data_panel.cb_plotpanel.Delete(ind) |
---|
[f7d0b74] | 1143 | |
---|
[c9937c0] | 1144 | self._mgr.Update() |
---|
[f7d0b74] | 1145 | |
---|
[c9937c0] | 1146 | |
---|
[75fbd17] | 1147 | def clear_panel(self): |
---|
[b3644f3] | 1148 | """ |
---|
| 1149 | """ |
---|
[75fbd17] | 1150 | for item in self.panels: |
---|
| 1151 | try: |
---|
| 1152 | self.panels[item].clear_panel() |
---|
| 1153 | except: |
---|
| 1154 | pass |
---|
| 1155 | |
---|
| 1156 | def create_gui_data(self, data, path=None): |
---|
| 1157 | """ |
---|
[0348245] | 1158 | """ |
---|
| 1159 | return self._data_manager.create_gui_data(data, path) |
---|
| 1160 | |
---|
[03314e7] | 1161 | def get_data(self, path): |
---|
[75fbd17] | 1162 | """ |
---|
| 1163 | """ |
---|
| 1164 | message = "" |
---|
| 1165 | log_msg = '' |
---|
| 1166 | output = [] |
---|
| 1167 | error_message = "" |
---|
| 1168 | basename = os.path.basename(path) |
---|
| 1169 | root, extension = os.path.splitext(basename) |
---|
| 1170 | if extension.lower() not in EXTENSIONS: |
---|
| 1171 | log_msg = "File Loader cannot " |
---|
| 1172 | log_msg += "load: %s\n" % str(basename) |
---|
| 1173 | log_msg += "Try Data opening...." |
---|
| 1174 | logging.info(log_msg) |
---|
| 1175 | self.load_complete(output=output, error_message=error_message, |
---|
| 1176 | message=log_msg, path=path) |
---|
[700f9b4] | 1177 | return |
---|
[75fbd17] | 1178 | |
---|
| 1179 | #reading a state file |
---|
| 1180 | for plug in self.plugins: |
---|
[03314e7] | 1181 | reader, ext = plug.get_extensions() |
---|
| 1182 | if reader is not None: |
---|
| 1183 | #read the state of the single plugin |
---|
| 1184 | if extension == ext: |
---|
| 1185 | reader.read(path) |
---|
| 1186 | return |
---|
[957723f] | 1187 | elif extension == APPLICATION_STATE_EXTENSION: |
---|
[03314e7] | 1188 | reader.read(path) |
---|
| 1189 | |
---|
[75fbd17] | 1190 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 1191 | if style == GUIFRAME.MANAGER_ON: |
---|
| 1192 | if self._data_panel is not None: |
---|
[f7d0b74] | 1193 | #data_state = self._data_manager.get_selected_data() |
---|
| 1194 | #self._data_panel.load_data_list(data_state) |
---|
[75fbd17] | 1195 | self._mgr.GetPane(self._data_panel.window_name).Show(True) |
---|
[976604d] | 1196 | |
---|
| 1197 | def load_from_cmd(self, path): |
---|
| 1198 | """ |
---|
[c3f697e] | 1199 | load data from cmd or application |
---|
[976604d] | 1200 | """ |
---|
[c3f697e] | 1201 | if path is None: |
---|
[976604d] | 1202 | return |
---|
| 1203 | else: |
---|
| 1204 | path = os.path.abspath(path) |
---|
| 1205 | if not os.path.isfile(path): |
---|
| 1206 | return |
---|
| 1207 | basename = os.path.basename(path) |
---|
| 1208 | root, extension = os.path.splitext(basename) |
---|
| 1209 | if extension.lower() not in EXTENSIONS: |
---|
| 1210 | self.load_data(path) |
---|
| 1211 | else: |
---|
| 1212 | self.load_state(path) |
---|
[c3f697e] | 1213 | |
---|
[957723f] | 1214 | def load_state(self, path): |
---|
| 1215 | """ |
---|
[c3f697e] | 1216 | load data from command line or application |
---|
[957723f] | 1217 | """ |
---|
[976604d] | 1218 | if path and (path is not None) and os.path.isfile(path): |
---|
[957723f] | 1219 | basename = os.path.basename(path) |
---|
| 1220 | if APPLICATION_STATE_EXTENSION is not None \ |
---|
| 1221 | and basename.endswith(APPLICATION_STATE_EXTENSION): |
---|
[9c35257] | 1222 | #Hide current plot_panels i |
---|
| 1223 | for ID in self.plot_panels.keys(): |
---|
| 1224 | panel = self._mgr.GetPane(self.plot_panels[ID].window_name) |
---|
| 1225 | if panel.IsShown(): |
---|
| 1226 | panel.Hide() |
---|
[1793cef] | 1227 | self.get_data(path) |
---|
[957723f] | 1228 | if self.defaultPanel is not None and \ |
---|
| 1229 | self._mgr.GetPane(self.panels["default"].window_name).IsShown(): |
---|
| 1230 | self.on_close_welcome_panel() |
---|
| 1231 | |
---|
| 1232 | def load_data(self, path): |
---|
| 1233 | """ |
---|
[c3f697e] | 1234 | load data from command line |
---|
[957723f] | 1235 | """ |
---|
| 1236 | if not os.path.isfile(path): |
---|
| 1237 | return |
---|
| 1238 | basename = os.path.basename(path) |
---|
| 1239 | root, extension = os.path.splitext(basename) |
---|
| 1240 | if extension.lower() in EXTENSIONS: |
---|
| 1241 | log_msg = "Data Loader cannot " |
---|
| 1242 | log_msg += "load: %s\n" % str(path) |
---|
| 1243 | log_msg += "Try File opening ...." |
---|
| 1244 | print log_msg |
---|
| 1245 | return |
---|
[c3f697e] | 1246 | message = "" |
---|
| 1247 | log_msg = '' |
---|
| 1248 | output = {} |
---|
| 1249 | error_message = "" |
---|
[957723f] | 1250 | try: |
---|
[c3f697e] | 1251 | print "Loading Data...:\n" + str(path) + "\n" |
---|
[957723f] | 1252 | temp = self.loader.load(path) |
---|
| 1253 | if temp.__class__.__name__ == "list": |
---|
| 1254 | for item in temp: |
---|
[c3f697e] | 1255 | data = self.create_gui_data(item, path) |
---|
[957723f] | 1256 | output[data.id] = data |
---|
| 1257 | else: |
---|
[c3f697e] | 1258 | data = self.create_gui_data(temp, path) |
---|
[957723f] | 1259 | output[data.id] = data |
---|
| 1260 | |
---|
| 1261 | self.add_data(data_list=output) |
---|
| 1262 | except: |
---|
[c3f697e] | 1263 | error_message = "Error while loading" |
---|
| 1264 | error_message += " Data from cmd:\n %s\n" % str(path) |
---|
[957723f] | 1265 | error_message += str(sys.exc_value) + "\n" |
---|
| 1266 | print error_message |
---|
| 1267 | |
---|
[4c01978] | 1268 | |
---|
| 1269 | def _on_open_state_application(self, event): |
---|
| 1270 | """ |
---|
| 1271 | """ |
---|
| 1272 | path = None |
---|
| 1273 | if self._default_save_location == None: |
---|
| 1274 | self._default_save_location = os.getcwd() |
---|
[d38d0042] | 1275 | |
---|
| 1276 | plug_wlist = self._on_open_state_app_helper() |
---|
[4c01978] | 1277 | dlg = wx.FileDialog(self, |
---|
| 1278 | "Choose a file", |
---|
| 1279 | self._default_save_location, "", |
---|
[32d26da] | 1280 | plug_wlist) |
---|
[4c01978] | 1281 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1282 | path = dlg.GetPath() |
---|
| 1283 | if path is not None: |
---|
| 1284 | self._default_save_location = os.path.dirname(path) |
---|
| 1285 | dlg.Destroy() |
---|
| 1286 | self.load_state(path=path) |
---|
[d38d0042] | 1287 | |
---|
| 1288 | def _on_open_state_app_helper(self): |
---|
| 1289 | """ |
---|
| 1290 | Helps '_on_open_state_application()' to find the extension of |
---|
| 1291 | the current perspective/application |
---|
| 1292 | """ |
---|
| 1293 | # No current perspective or no extension attr |
---|
| 1294 | if self._current_perspective is None: |
---|
| 1295 | return PLUGINS_WLIST |
---|
| 1296 | try: |
---|
| 1297 | # Find the extension of the perspective and get that as 1st item in list |
---|
| 1298 | ind = None |
---|
| 1299 | app_ext = self._current_perspective._extensions |
---|
| 1300 | plug_wlist = config.PLUGINS_WLIST |
---|
| 1301 | for ext in set(plug_wlist): |
---|
| 1302 | if ext.count(app_ext) > 0: |
---|
| 1303 | ind = ext |
---|
| 1304 | break |
---|
| 1305 | # Found the extension |
---|
| 1306 | if ind != None: |
---|
| 1307 | plug_wlist.remove(ind) |
---|
| 1308 | plug_wlist.insert(0, ind) |
---|
| 1309 | try: |
---|
| 1310 | plug_wlist ='|'.join(plug_wlist) |
---|
| 1311 | except: |
---|
| 1312 | plug_wlist = '' |
---|
[32d26da] | 1313 | |
---|
[d38d0042] | 1314 | except: |
---|
| 1315 | plug_wlist = PLUGINS_WLIST |
---|
[957723f] | 1316 | |
---|
[32d26da] | 1317 | return plug_wlist |
---|
| 1318 | |
---|
[4c01978] | 1319 | def _on_open_state_project(self, event): |
---|
[75fbd17] | 1320 | """ |
---|
| 1321 | """ |
---|
| 1322 | path = None |
---|
| 1323 | if self._default_save_location == None: |
---|
| 1324 | self._default_save_location = os.getcwd() |
---|
[d38d0042] | 1325 | |
---|
[75fbd17] | 1326 | dlg = wx.FileDialog(self, |
---|
| 1327 | "Choose a file", |
---|
| 1328 | self._default_save_location, "", |
---|
[4c01978] | 1329 | APPLICATION_WLIST) |
---|
[75fbd17] | 1330 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1331 | path = dlg.GetPath() |
---|
| 1332 | if path is not None: |
---|
| 1333 | self._default_save_location = os.path.dirname(path) |
---|
| 1334 | dlg.Destroy() |
---|
[1793cef] | 1335 | |
---|
| 1336 | #try: |
---|
| 1337 | # os.popen(path) |
---|
| 1338 | # #self.Close() |
---|
| 1339 | #except: |
---|
[957723f] | 1340 | self.load_state(path=path) |
---|
[1793cef] | 1341 | |
---|
[52725d6] | 1342 | def _on_save_application(self, event): |
---|
[b35d3d1] | 1343 | """ |
---|
[52725d6] | 1344 | save the state of the current active application |
---|
[b35d3d1] | 1345 | """ |
---|
[0a2fdca] | 1346 | if self.cpanel_on_focus is not None: |
---|
| 1347 | self.cpanel_on_focus.on_save(event) |
---|
[52725d6] | 1348 | |
---|
| 1349 | def _on_save_project(self, event): |
---|
| 1350 | """ |
---|
| 1351 | save the state of the current active application |
---|
| 1352 | """ |
---|
| 1353 | ## Default file location for save |
---|
| 1354 | self._default_save_location = os.getcwd() |
---|
| 1355 | if self._current_perspective is None: |
---|
| 1356 | return |
---|
| 1357 | reader, ext = self._current_perspective.get_extensions() |
---|
| 1358 | path = None |
---|
[2e3f9e3] | 1359 | extension = '*' + APPLICATION_STATE_EXTENSION |
---|
[75fbd17] | 1360 | dlg = wx.FileDialog(self, "Save Project file", |
---|
[957723f] | 1361 | self._default_save_location, "", |
---|
[2e3f9e3] | 1362 | extension, |
---|
[957723f] | 1363 | wx.SAVE) |
---|
[52725d6] | 1364 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1365 | path = dlg.GetPath() |
---|
| 1366 | self._default_save_location = os.path.dirname(path) |
---|
| 1367 | else: |
---|
| 1368 | return None |
---|
| 1369 | dlg.Destroy() |
---|
| 1370 | if path is None: |
---|
| 1371 | return |
---|
| 1372 | # default cansas xml doc |
---|
| 1373 | doc = None |
---|
| 1374 | for panel in self.panels.values(): |
---|
[6f28e70] | 1375 | temp = panel.save_project(doc) |
---|
| 1376 | if temp is not None: |
---|
| 1377 | doc = temp |
---|
| 1378 | |
---|
[2e3f9e3] | 1379 | # Write the XML document |
---|
| 1380 | if doc != None: |
---|
| 1381 | fd = open(path, 'w') |
---|
| 1382 | fd.write(doc.toprettyxml()) |
---|
| 1383 | fd.close() |
---|
| 1384 | else: |
---|
| 1385 | msg = "%s cannot read %s\n" % (str(APPLICATION_NAME), str(path)) |
---|
[6f28e70] | 1386 | logging.error(msg) |
---|
[2e3f9e3] | 1387 | |
---|
[52725d6] | 1388 | def on_save_helper(self, doc, reader, panel, path): |
---|
| 1389 | """ |
---|
| 1390 | Save state into a file |
---|
| 1391 | """ |
---|
| 1392 | try: |
---|
| 1393 | if reader is not None: |
---|
[2e3f9e3] | 1394 | # case of a panel with multi-pages |
---|
| 1395 | if hasattr(panel, "opened_pages"): |
---|
| 1396 | for uid, page in panel.opened_pages.iteritems(): |
---|
| 1397 | data = page.get_data() |
---|
| 1398 | # state must be cloned |
---|
| 1399 | state = page.get_state().clone() |
---|
| 1400 | if data is not None: |
---|
| 1401 | new_doc = reader.write_toXML(data, state) |
---|
| 1402 | if doc != None and hasattr(doc, "firstChild"): |
---|
| 1403 | child = new_doc.firstChild.firstChild |
---|
| 1404 | doc.firstChild.appendChild(child) |
---|
| 1405 | else: |
---|
| 1406 | doc = new_doc |
---|
| 1407 | # case of only a panel |
---|
| 1408 | else: |
---|
| 1409 | data = panel.get_data() |
---|
| 1410 | state = panel.get_state() |
---|
| 1411 | if data is not None: |
---|
| 1412 | new_doc = reader.write_toXML(data, state) |
---|
| 1413 | if doc != None and hasattr(doc, "firstChild"): |
---|
| 1414 | child = new_doc.firstChild.firstChild |
---|
| 1415 | doc.firstChild.appendChild(child) |
---|
| 1416 | else: |
---|
| 1417 | doc = new_doc |
---|
[52725d6] | 1418 | except: |
---|
| 1419 | raise |
---|
| 1420 | #pass |
---|
[2e3f9e3] | 1421 | |
---|
[52725d6] | 1422 | return doc |
---|
[b35d3d1] | 1423 | |
---|
[b5ca223] | 1424 | def quit_guiframe(self): |
---|
| 1425 | """ |
---|
| 1426 | Pop up message to make sure the user wants to quit the application |
---|
| 1427 | """ |
---|
| 1428 | message = "Do you really want to quit \n" |
---|
| 1429 | message += "this application?" |
---|
| 1430 | dial = wx.MessageDialog(self, message, 'Question', |
---|
| 1431 | wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION) |
---|
| 1432 | if dial.ShowModal() == wx.ID_YES: |
---|
| 1433 | return True |
---|
| 1434 | else: |
---|
| 1435 | return False |
---|
| 1436 | |
---|
[41d466f] | 1437 | def Close(self, event=None): |
---|
| 1438 | """ |
---|
[d955bf19] | 1439 | Quit the application |
---|
[41d466f] | 1440 | """ |
---|
[52725d6] | 1441 | #flag = self.quit_guiframe() |
---|
| 1442 | if True: |
---|
[ba535a6] | 1443 | wx.Exit() |
---|
| 1444 | sys.exit() |
---|
[41d466f] | 1445 | |
---|
| 1446 | def _check_update(self, event=None): |
---|
| 1447 | """ |
---|
[d955bf19] | 1448 | Check with the deployment server whether a new version |
---|
| 1449 | of the application is available. |
---|
| 1450 | A thread is started for the connecting with the server. The thread calls |
---|
| 1451 | a call-back method when the current version number has been obtained. |
---|
[52070a1] | 1452 | """ |
---|
[d68c655] | 1453 | if hasattr(config, "__update_URL__"): |
---|
| 1454 | import version |
---|
[32c0841] | 1455 | checker = version.VersionThread(config.__update_URL__, |
---|
| 1456 | self._process_version, |
---|
| 1457 | baggage=event==None) |
---|
[d68c655] | 1458 | checker.start() |
---|
[52070a1] | 1459 | |
---|
| 1460 | def _process_version(self, version, standalone=True): |
---|
| 1461 | """ |
---|
[d955bf19] | 1462 | Call-back method for the process of checking for updates. |
---|
| 1463 | This methods is called by a VersionThread object once the current |
---|
| 1464 | version number has been obtained. If the check is being done in the |
---|
| 1465 | background, the user will not be notified unless there's an update. |
---|
| 1466 | |
---|
| 1467 | :param version: version string |
---|
| 1468 | :param standalone: True of the update is being checked in |
---|
| 1469 | the background, False otherwise. |
---|
| 1470 | |
---|
[52070a1] | 1471 | """ |
---|
| 1472 | try: |
---|
[32c0841] | 1473 | if cmp(version, config.__version__) > 0: |
---|
| 1474 | msg = "Version %s is available! See the Help " |
---|
| 1475 | msg += "menu to download it." % version |
---|
| 1476 | self.SetStatusText(msg) |
---|
[52070a1] | 1477 | if not standalone: |
---|
| 1478 | import webbrowser |
---|
| 1479 | webbrowser.open(config.__download_page__) |
---|
| 1480 | else: |
---|
| 1481 | if not standalone: |
---|
[32c0841] | 1482 | msg = "You have the latest version" |
---|
| 1483 | msg += " of %s" % config.__appname__ |
---|
| 1484 | self.SetStatusText(msg) |
---|
[41d466f] | 1485 | except: |
---|
[32c0841] | 1486 | msg = "guiframe: could not get latest application" |
---|
| 1487 | msg += " version number\n %s" % sys.exc_value |
---|
| 1488 | logging.error(msg) |
---|
[52070a1] | 1489 | if not standalone: |
---|
[32c0841] | 1490 | msg = "Could not connect to the application server." |
---|
| 1491 | msg += " Please try again later." |
---|
| 1492 | self.SetStatusText(msg) |
---|
[52070a1] | 1493 | |
---|
[41d466f] | 1494 | def _onAbout(self, evt): |
---|
| 1495 | """ |
---|
[d955bf19] | 1496 | Pop up the about dialog |
---|
| 1497 | |
---|
| 1498 | :param evt: menu event |
---|
| 1499 | |
---|
[41d466f] | 1500 | """ |
---|
| 1501 | if config._do_aboutbox: |
---|
| 1502 | import aboutbox |
---|
| 1503 | dialog = aboutbox.DialogAbout(None, -1, "") |
---|
[6ab0ad1] | 1504 | dialog.ShowModal() |
---|
[4e9583c] | 1505 | |
---|
[41d466f] | 1506 | def set_manager(self, manager): |
---|
| 1507 | """ |
---|
[d955bf19] | 1508 | Sets the application manager for this frame |
---|
| 1509 | |
---|
| 1510 | :param manager: frame manager |
---|
[41d466f] | 1511 | """ |
---|
| 1512 | self.app_manager = manager |
---|
| 1513 | |
---|
| 1514 | def post_init(self): |
---|
| 1515 | """ |
---|
[d955bf19] | 1516 | This initialization method is called after the GUI |
---|
| 1517 | has been created and all plug-ins loaded. It calls |
---|
| 1518 | the post_init() method of each plug-in (if it exists) |
---|
| 1519 | so that final initialization can be done. |
---|
[41d466f] | 1520 | """ |
---|
| 1521 | for item in self.plugins: |
---|
| 1522 | if hasattr(item, "post_init"): |
---|
| 1523 | item.post_init() |
---|
| 1524 | |
---|
[b28278e] | 1525 | def set_default_perspective(self): |
---|
| 1526 | """ |
---|
[d955bf19] | 1527 | Choose among the plugin the first plug-in that has |
---|
| 1528 | "set_default_perspective" method and its return value is True will be |
---|
| 1529 | as a default perspective when the welcome page is closed |
---|
[b28278e] | 1530 | """ |
---|
| 1531 | for item in self.plugins: |
---|
| 1532 | if hasattr(item, "set_default_perspective"): |
---|
| 1533 | if item.set_default_perspective(): |
---|
[749eb8a] | 1534 | item.on_perspective(event=None) |
---|
[b28278e] | 1535 | return |
---|
[f444b20] | 1536 | |
---|
[41d466f] | 1537 | def set_perspective(self, panels): |
---|
| 1538 | """ |
---|
[d955bf19] | 1539 | Sets the perspective of the GUI. |
---|
| 1540 | Opens all the panels in the list, and closes |
---|
| 1541 | all the others. |
---|
| 1542 | |
---|
| 1543 | :param panels: list of panels |
---|
[41d466f] | 1544 | """ |
---|
[5342eb8] | 1545 | style = self.__gui_style & GUIFRAME.TOOLBAR_ON |
---|
| 1546 | if (style == GUIFRAME.TOOLBAR_ON) & (not self._toolbar.IsShown()): |
---|
[3554fd39] | 1547 | self._on_toggle_toolbar() |
---|
[41d466f] | 1548 | for item in self.panels: |
---|
| 1549 | # Check whether this is a sticky panel |
---|
| 1550 | if hasattr(self.panels[item], "ALWAYS_ON"): |
---|
| 1551 | if self.panels[item].ALWAYS_ON: |
---|
| 1552 | continue |
---|
[1b1bbf9] | 1553 | |
---|
[41d466f] | 1554 | if self.panels[item].window_name in panels: |
---|
| 1555 | if not self._mgr.GetPane(self.panels[item].window_name).IsShown(): |
---|
| 1556 | self._mgr.GetPane(self.panels[item].window_name).Show() |
---|
| 1557 | else: |
---|
[3feed3e] | 1558 | # always show the data panel if enable |
---|
| 1559 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 1560 | if (style == GUIFRAME.MANAGER_ON) and self.panels[item] == self._data_panel: |
---|
| 1561 | if 'data_panel' in self.panels.keys(): |
---|
| 1562 | flag = self._mgr.GetPane(self.panels['data_panel'].window_name).IsShown() |
---|
| 1563 | self._mgr.GetPane(self.panels['data_panel'].window_name).Show(flag) |
---|
| 1564 | else: |
---|
| 1565 | if self._mgr.GetPane(self.panels[item].window_name).IsShown(): |
---|
| 1566 | self._mgr.GetPane(self.panels[item].window_name).Hide() |
---|
[1b1bbf9] | 1567 | |
---|
[41d466f] | 1568 | self._mgr.Update() |
---|
[4e9583c] | 1569 | |
---|
[1b1bbf9] | 1570 | def show_data_panel(self, event=None, action=True): |
---|
[52b8b74] | 1571 | """ |
---|
[3feed3e] | 1572 | show the data panel |
---|
[52b8b74] | 1573 | """ |
---|
[1b1bbf9] | 1574 | if self._data_panel_menu == None: |
---|
| 1575 | return |
---|
[e75b5fa] | 1576 | label = self._data_panel_menu.GetText() |
---|
| 1577 | if label == 'Data Explorer ON': |
---|
[75fbd17] | 1578 | pane = self._mgr.GetPane(self.panels["data_panel"].window_name) |
---|
| 1579 | #if not pane.IsShown(): |
---|
[1b1bbf9] | 1580 | if action: |
---|
| 1581 | pane.Show(True) |
---|
| 1582 | self._mgr.Update() |
---|
[e75b5fa] | 1583 | self.__gui_style = self.__gui_style | GUIFRAME.MANAGER_ON |
---|
| 1584 | |
---|
| 1585 | self._data_panel_menu.SetText('Data Explorer OFF') |
---|
| 1586 | else: |
---|
| 1587 | pane = self._mgr.GetPane(self.panels["data_panel"].window_name) |
---|
| 1588 | #if not pane.IsShown(): |
---|
[1b1bbf9] | 1589 | if action: |
---|
| 1590 | pane.Show(False) |
---|
| 1591 | self._mgr.Update() |
---|
[e75b5fa] | 1592 | self.__gui_style = self.__gui_style & (~GUIFRAME.MANAGER_ON) |
---|
| 1593 | self._data_panel_menu.SetText('Data Explorer ON') |
---|
[c70eb7c] | 1594 | |
---|
| 1595 | def add_data_helper(self, data_list): |
---|
| 1596 | """ |
---|
| 1597 | """ |
---|
[e88ebfd] | 1598 | if self._data_manager is not None: |
---|
| 1599 | self._data_manager.add_data(data_list) |
---|
[c70eb7c] | 1600 | |
---|
[75fbd17] | 1601 | def add_data(self, data_list): |
---|
[f444b20] | 1602 | """ |
---|
[e88ebfd] | 1603 | receive a dictionary of data from loader |
---|
| 1604 | store them its data manager if possible |
---|
| 1605 | send to data the current active perspective if the data panel |
---|
| 1606 | is not active. |
---|
| 1607 | :param data_list: dictionary of data's ID and value Data |
---|
[f444b20] | 1608 | """ |
---|
[e88ebfd] | 1609 | #Store data into manager |
---|
| 1610 | self.add_data_helper(data_list) |
---|
| 1611 | # set data in the data panel |
---|
| 1612 | if self._data_panel is not None: |
---|
| 1613 | data_state = self._data_manager.get_data_state(data_list.keys()) |
---|
| 1614 | self._data_panel.load_data_list(data_state) |
---|
| 1615 | #if the data panel is shown wait for the user to press a button |
---|
| 1616 | #to send data to the current perspective. if the panel is not |
---|
| 1617 | #show automatically send the data to the current perspective |
---|
[3feed3e] | 1618 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 1619 | if style == GUIFRAME.MANAGER_ON: |
---|
[9c169f4] | 1620 | #wait for button press from the data panel to set_data |
---|
[3feed3e] | 1621 | if self._data_panel is not None: |
---|
| 1622 | self._mgr.GetPane(self._data_panel.window_name).Show(True) |
---|
[9c169f4] | 1623 | self._mgr.Update() |
---|
[3feed3e] | 1624 | else: |
---|
| 1625 | #automatically send that to the current perspective |
---|
[e88ebfd] | 1626 | self.set_data(data_id=data_list.keys()) |
---|
[1b1bbf9] | 1627 | self.on_close_welcome_panel() |
---|
[c70eb7c] | 1628 | |
---|
[0a2fdca] | 1629 | def set_data(self, data_id, theory_id=None): |
---|
[c5e84fb] | 1630 | """ |
---|
[e88ebfd] | 1631 | set data to current perspective |
---|
[c5e84fb] | 1632 | """ |
---|
[e88ebfd] | 1633 | list_data, _ = self._data_manager.get_by_id(data_id) |
---|
| 1634 | if self._current_perspective is not None: |
---|
[52f3c98] | 1635 | for uid, panel in self.plot_panels.iteritems() : |
---|
| 1636 | #panel = self.plot_panels[uid] |
---|
| 1637 | window = self._mgr.GetPane(panel.window_name) |
---|
[38aadd9] | 1638 | # To hide all docked plot panels when set the data |
---|
| 1639 | #if not window.IsFloating(): |
---|
| 1640 | # self.hide_panel(uid) |
---|
[df22224] | 1641 | self._current_perspective.set_data(list_data.values()) |
---|
[1b1bbf9] | 1642 | self.on_close_welcome_panel() |
---|
[584c4c4] | 1643 | else: |
---|
[e88ebfd] | 1644 | msg = "Guiframe does not have a current perspective" |
---|
| 1645 | logging.info(msg) |
---|
| 1646 | |
---|
| 1647 | def set_theory(self, state_id, theory_id=None): |
---|
[c5e84fb] | 1648 | """ |
---|
| 1649 | """ |
---|
[df22224] | 1650 | _, list_theory = self._data_manager.get_by_id(theory_id) |
---|
[c5e84fb] | 1651 | if self._current_perspective is not None: |
---|
| 1652 | try: |
---|
[df22224] | 1653 | self._current_perspective.set_theory(list_theory.values()) |
---|
[c5e84fb] | 1654 | except: |
---|
[e88ebfd] | 1655 | msg = "Guiframe set_theory: \n" + str(sys.exc_value) |
---|
| 1656 | logging.info(msg) |
---|
[c5e84fb] | 1657 | wx.PostEvent(self, StatusEvent(status=msg, info="error")) |
---|
| 1658 | else: |
---|
| 1659 | msg = "Guiframe does not have a current perspective" |
---|
| 1660 | logging.info(msg) |
---|
[3feed3e] | 1661 | |
---|
[e88ebfd] | 1662 | def plot_data(self, state_id, data_id=None, |
---|
| 1663 | theory_id=None, append=False): |
---|
[f444b20] | 1664 | """ |
---|
| 1665 | send a list of data to plot |
---|
| 1666 | """ |
---|
[d7f727d] | 1667 | total_plot_list = [] |
---|
[e88ebfd] | 1668 | data_list, _ = self._data_manager.get_by_id(data_id) |
---|
[df22224] | 1669 | _, temp_list_theory = self._data_manager.get_by_id(theory_id) |
---|
[d7f727d] | 1670 | total_plot_list = data_list.values() |
---|
[df22224] | 1671 | for item in temp_list_theory.values(): |
---|
[e88ebfd] | 1672 | theory_data, theory_state = item |
---|
[d7f727d] | 1673 | total_plot_list.append(theory_data) |
---|
[e88ebfd] | 1674 | GROUP_ID = wx.NewId() |
---|
[d7f727d] | 1675 | for new_plot in total_plot_list: |
---|
[213892bc] | 1676 | if append: |
---|
[ee2b492] | 1677 | if self.panel_on_focus is None: |
---|
[213892bc] | 1678 | message = "cannot append plot. No plot panel on focus!" |
---|
| 1679 | message += "please click on any available plot to set focus" |
---|
| 1680 | wx.PostEvent(self, StatusEvent(status=message, |
---|
| 1681 | info='warning')) |
---|
| 1682 | return |
---|
| 1683 | else: |
---|
[e88ebfd] | 1684 | if self.enable_add_data(new_plot): |
---|
| 1685 | new_plot.group_id = self.panel_on_focus.group_id |
---|
| 1686 | else: |
---|
| 1687 | message = "Only 1D Data can be append to plot panel\n" |
---|
| 1688 | message += "%s will be plot separetly\n" %str(new_plot.name) |
---|
| 1689 | wx.PostEvent(self, StatusEvent(status=message, |
---|
| 1690 | info='warning')) |
---|
[4c0572f] | 1691 | else: |
---|
| 1692 | #if not append then new plot |
---|
[7c7fe67] | 1693 | from sans.guiframe.dataFitting import Data2D |
---|
| 1694 | if (Data2D, new_plot.__class__): |
---|
| 1695 | #for 2 D always plot in a separated new plot |
---|
| 1696 | new_plot.group_id = wx.NewId() |
---|
| 1697 | else: |
---|
| 1698 | # plot all 1D in a new plot |
---|
| 1699 | new_plot.group_id = GROUP_ID |
---|
[e88ebfd] | 1700 | title = "PLOT " + str(new_plot.title) |
---|
[f444b20] | 1701 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
[e88ebfd] | 1702 | title=title)) |
---|
[f444b20] | 1703 | |
---|
[665c083] | 1704 | def remove_data(self, data_id, theory_id=None): |
---|
[213892bc] | 1705 | """ |
---|
| 1706 | Delete data state if data_id is provide |
---|
| 1707 | delete theory created with data of id data_id if theory_id is provide |
---|
| 1708 | if delete all true: delete the all state |
---|
| 1709 | else delete theory |
---|
| 1710 | """ |
---|
[6db811e] | 1711 | for plug in self.plugins: |
---|
| 1712 | plug.delete_data(data_id) |
---|
[3658717e] | 1713 | total_plot_list = [] |
---|
| 1714 | data_list, _ = self._data_manager.get_by_id(data_id) |
---|
| 1715 | _, temp_list_theory = self._data_manager.get_by_id(theory_id) |
---|
| 1716 | total_plot_list = data_list.values() |
---|
| 1717 | for item in temp_list_theory.values(): |
---|
| 1718 | theory_data, theory_state = item |
---|
| 1719 | total_plot_list.append(theory_data) |
---|
| 1720 | for new_plot in total_plot_list: |
---|
| 1721 | id = new_plot.id |
---|
| 1722 | for group_id in new_plot.list_group_id: |
---|
| 1723 | wx.PostEvent(self, NewPlotEvent(id=id, |
---|
| 1724 | group_id=group_id, |
---|
| 1725 | action='remove')) |
---|
| 1726 | self._data_manager.delete_data(data_id=data_id, |
---|
| 1727 | theory_id=theory_id) |
---|
[6db811e] | 1728 | |
---|
[213892bc] | 1729 | |
---|
[f444b20] | 1730 | def set_current_perspective(self, perspective): |
---|
| 1731 | """ |
---|
| 1732 | set the current active perspective |
---|
| 1733 | """ |
---|
| 1734 | self._current_perspective = perspective |
---|
[f7e9af2] | 1735 | name = "No current analysis selected" |
---|
[cbf22e5] | 1736 | if self._current_perspective is not None: |
---|
| 1737 | self._add_current_plugin_menu() |
---|
[a45037aa] | 1738 | for panel in self.panels.values(): |
---|
| 1739 | if hasattr(panel, 'CENTER_PANE') and panel.CENTER_PANE: |
---|
| 1740 | for name in self._current_perspective.get_perspective(): |
---|
| 1741 | if name == panel.window_name: |
---|
| 1742 | panel.on_set_focus(event=None) |
---|
| 1743 | break |
---|
| 1744 | |
---|
[f036c692] | 1745 | name = self._current_perspective.sub_menu |
---|
[cbf22e5] | 1746 | if self._data_panel is not None: |
---|
| 1747 | self._data_panel.set_active_perspective(name) |
---|
[95f9cc4] | 1748 | self._check_applications_menu() |
---|
[1b1bbf9] | 1749 | #Set the SansView title |
---|
| 1750 | self._set_title_name(name) |
---|
[52f3c98] | 1751 | |
---|
[1b1bbf9] | 1752 | |
---|
| 1753 | def _set_title_name(self, name): |
---|
| 1754 | """ |
---|
| 1755 | Set the SansView title w/ the current application name |
---|
| 1756 | |
---|
| 1757 | : param name: application name [string] |
---|
| 1758 | """ |
---|
| 1759 | # Set SanView Window title w/ application anme |
---|
| 1760 | title = self.title + " - " + name + " -" |
---|
| 1761 | self.SetTitle(title) |
---|
| 1762 | |
---|
[95f9cc4] | 1763 | def _check_applications_menu(self): |
---|
| 1764 | """ |
---|
| 1765 | check the menu of the current application |
---|
| 1766 | """ |
---|
| 1767 | if self._applications_menu is not None: |
---|
| 1768 | for menu in self._applications_menu.GetMenuItems(): |
---|
| 1769 | if self._current_perspective is not None: |
---|
| 1770 | name = self._current_perspective.sub_menu |
---|
| 1771 | if menu.IsCheckable(): |
---|
| 1772 | if menu.GetLabel() == name: |
---|
| 1773 | menu.Check(True) |
---|
| 1774 | else: |
---|
| 1775 | menu.Check(False) |
---|
[c5e84fb] | 1776 | |
---|
[213892bc] | 1777 | def set_plotpanel_floating(self, event=None): |
---|
[7a67e075] | 1778 | """ |
---|
| 1779 | make the plot panel floatable |
---|
| 1780 | """ |
---|
[0663dfb1] | 1781 | self.__gui_style &= (~GUIFRAME.FIXED_PANEL) |
---|
[3feed3e] | 1782 | self.__gui_style |= GUIFRAME.FLOATING_PANEL |
---|
| 1783 | for p in self.panels.values(): |
---|
[ae83ad3] | 1784 | plot_panel = self._plotting_plugin.plot_panels.values() |
---|
[3feed3e] | 1785 | for p in self.panels.values(): |
---|
| 1786 | if p in plot_panel: |
---|
| 1787 | self._popup_floating_panel(p) |
---|
| 1788 | |
---|
[213892bc] | 1789 | def set_plotpanel_fixed(self, event=None): |
---|
[7a67e075] | 1790 | """ |
---|
| 1791 | make the plot panel fixed |
---|
| 1792 | """ |
---|
[0663dfb1] | 1793 | self.__gui_style &= (~GUIFRAME.FLOATING_PANEL) |
---|
[3feed3e] | 1794 | self.__gui_style |= GUIFRAME.FIXED_PANEL |
---|
| 1795 | plot_panel = [] |
---|
| 1796 | if self._plotting_plugin is not None: |
---|
[ae83ad3] | 1797 | plot_panel = self._plotting_plugin.plot_panels.values() |
---|
[3feed3e] | 1798 | for p in self.panels.values(): |
---|
| 1799 | if p in plot_panel: |
---|
| 1800 | self._popup_fixed_panel(p) |
---|
| 1801 | |
---|
| 1802 | def _popup_fixed_panel(self, p): |
---|
| 1803 | """ |
---|
| 1804 | """ |
---|
| 1805 | style = self.__gui_style & GUIFRAME.FIXED_PANEL |
---|
| 1806 | if style == GUIFRAME.FIXED_PANEL: |
---|
[52f3c98] | 1807 | self._mgr.GetPane(p.window_name).Dock() |
---|
[3feed3e] | 1808 | self._mgr.GetPane(p.window_name).Floatable() |
---|
| 1809 | self._mgr.GetPane(p.window_name).Right() |
---|
| 1810 | self._mgr.GetPane(p.window_name).TopDockable(False) |
---|
| 1811 | self._mgr.GetPane(p.window_name).BottomDockable(False) |
---|
| 1812 | self._mgr.GetPane(p.window_name).LeftDockable(False) |
---|
| 1813 | self._mgr.GetPane(p.window_name).RightDockable(True) |
---|
| 1814 | flag = self._mgr.GetPane(p.window_name).IsShown() |
---|
| 1815 | self._mgr.GetPane(p.window_name).Show(flag) |
---|
| 1816 | self._mgr.Update() |
---|
| 1817 | |
---|
| 1818 | def _popup_floating_panel(self, p): |
---|
| 1819 | """ |
---|
| 1820 | """ |
---|
| 1821 | style = self.__gui_style & GUIFRAME.FLOATING_PANEL |
---|
| 1822 | if style == GUIFRAME.FLOATING_PANEL: |
---|
| 1823 | self._mgr.GetPane(p.window_name).Floatable(True) |
---|
| 1824 | self._mgr.GetPane(p.window_name).Float() |
---|
| 1825 | self._mgr.GetPane(p.window_name).Dockable(False) |
---|
| 1826 | flag = self._mgr.GetPane(p.window_name).IsShown() |
---|
| 1827 | self._mgr.GetPane(p.window_name).Show(flag) |
---|
| 1828 | self._mgr.Update() |
---|
[213892bc] | 1829 | |
---|
| 1830 | def enable_add_data(self, new_plot): |
---|
| 1831 | """ |
---|
| 1832 | Enable append data on a plot panel |
---|
| 1833 | """ |
---|
[0a2fdca] | 1834 | |
---|
[ee2b492] | 1835 | if self.panel_on_focus not in self._plotting_plugin.plot_panels.values(): |
---|
| 1836 | return |
---|
[213892bc] | 1837 | is_theory = len(self.panel_on_focus.plots) <= 1 and \ |
---|
| 1838 | self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D" |
---|
| 1839 | |
---|
| 1840 | is_data2d = hasattr(new_plot, 'data') |
---|
[0a2fdca] | 1841 | |
---|
[213892bc] | 1842 | is_data1d = self.panel_on_focus.__class__.__name__ == "ModelPanel1D"\ |
---|
| 1843 | and self.panel_on_focus.group_id is not None |
---|
| 1844 | has_meta_data = hasattr(new_plot, 'meta_data') |
---|
| 1845 | |
---|
| 1846 | #disable_add_data if the data is being recovered from a saved state file. |
---|
| 1847 | is_state_data = False |
---|
| 1848 | if has_meta_data: |
---|
| 1849 | if 'invstate' in new_plot.meta_data: is_state_data = True |
---|
| 1850 | if 'prstate' in new_plot.meta_data: is_state_data = True |
---|
| 1851 | if 'fitstate' in new_plot.meta_data: is_state_data = True |
---|
| 1852 | |
---|
| 1853 | return is_data1d and not is_data2d and not is_theory and not is_state_data |
---|
[d828481] | 1854 | |
---|
[f036c692] | 1855 | def enable_edit_menu(self): |
---|
| 1856 | """ |
---|
| 1857 | enable menu item under edit menu depending on the panel on focus |
---|
| 1858 | """ |
---|
[0a2fdca] | 1859 | if self.cpanel_on_focus is not None and self._edit_menu is not None: |
---|
| 1860 | flag = self.cpanel_on_focus.get_undo_flag() |
---|
[f036c692] | 1861 | self._edit_menu.Enable(GUIFRAME_ID.UNDO_ID, flag) |
---|
[0a2fdca] | 1862 | flag = self.cpanel_on_focus.get_redo_flag() |
---|
[f036c692] | 1863 | self._edit_menu.Enable(GUIFRAME_ID.REDO_ID, flag) |
---|
[0a2fdca] | 1864 | flag = self.cpanel_on_focus.get_print_flag() |
---|
[f036c692] | 1865 | self._edit_menu.Enable(GUIFRAME_ID.PRINT_ID, flag) |
---|
[0a2fdca] | 1866 | flag = self.cpanel_on_focus.get_preview_flag() |
---|
[f036c692] | 1867 | self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) |
---|
[0a2fdca] | 1868 | flag = self.cpanel_on_focus.get_reset_flag() |
---|
[f036c692] | 1869 | self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) |
---|
| 1870 | else: |
---|
| 1871 | flag = False |
---|
| 1872 | self._edit_menu.Enable(GUIFRAME_ID.UNDO_ID, flag) |
---|
| 1873 | self._edit_menu.Enable(GUIFRAME_ID.REDO_ID, flag) |
---|
| 1874 | self._edit_menu.Enable(GUIFRAME_ID.PRINT_ID, flag) |
---|
| 1875 | self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) |
---|
| 1876 | self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) |
---|
| 1877 | |
---|
[d828481] | 1878 | def on_undo_panel(self, event=None): |
---|
| 1879 | """ |
---|
| 1880 | undo previous action of the last panel on focus if possible |
---|
| 1881 | """ |
---|
[0a2fdca] | 1882 | if self.cpanel_on_focus is not None: |
---|
| 1883 | self.cpanel_on_focus.on_undo(event) |
---|
[f036c692] | 1884 | |
---|
[d828481] | 1885 | def on_redo_panel(self, event=None): |
---|
| 1886 | """ |
---|
| 1887 | redo the last cancel action done on the last panel on focus |
---|
| 1888 | """ |
---|
[0a2fdca] | 1889 | if self.cpanel_on_focus is not None: |
---|
| 1890 | self.cpanel_on_focus.on_redo(event) |
---|
[f036c692] | 1891 | |
---|
[d828481] | 1892 | def on_bookmark_panel(self, event=None): |
---|
| 1893 | """ |
---|
[4e4d3bb] | 1894 | bookmark panel |
---|
[d828481] | 1895 | """ |
---|
[0a2fdca] | 1896 | if self.cpanel_on_focus is not None: |
---|
| 1897 | self.cpanel_on_focus.on_bookmark(event) |
---|
[f036c692] | 1898 | |
---|
[4e4d3bb] | 1899 | def append_bookmark(self, event=None): |
---|
| 1900 | """ |
---|
| 1901 | Bookmark available information of the panel on focus |
---|
| 1902 | """ |
---|
| 1903 | self._toolbar.append_bookmark(event) |
---|
| 1904 | |
---|
[d828481] | 1905 | def on_save_panel(self, event=None): |
---|
| 1906 | """ |
---|
| 1907 | save possible information on the current panel |
---|
| 1908 | """ |
---|
[0a2fdca] | 1909 | if self.cpanel_on_focus is not None: |
---|
| 1910 | self.cpanel_on_focus.on_save(event) |
---|
[f036c692] | 1911 | |
---|
[d828481] | 1912 | def on_preview_panel(self, event=None): |
---|
| 1913 | """ |
---|
| 1914 | preview information on the panel on focus |
---|
| 1915 | """ |
---|
[0a2fdca] | 1916 | if self.cpanel_on_focus is not None: |
---|
| 1917 | self.cpanel_on_focus.on_preview(event) |
---|
[f036c692] | 1918 | |
---|
[d828481] | 1919 | def on_print_panel(self, event=None): |
---|
| 1920 | """ |
---|
| 1921 | print available information on the last panel on focus |
---|
| 1922 | """ |
---|
[0a2fdca] | 1923 | if self.cpanel_on_focus is not None: |
---|
| 1924 | self.cpanel_on_focus.on_print(event) |
---|
[f036c692] | 1925 | |
---|
[d828481] | 1926 | def on_zoom_panel(self, event=None): |
---|
| 1927 | """ |
---|
| 1928 | zoom on the current panel if possible |
---|
| 1929 | """ |
---|
[0a2fdca] | 1930 | if self.cpanel_on_focus is not None: |
---|
| 1931 | self.cpanel_on_focus.on_zoom(event) |
---|
[f036c692] | 1932 | |
---|
[d828481] | 1933 | def on_zoom_in_panel(self, event=None): |
---|
| 1934 | """ |
---|
| 1935 | zoom in of the panel on focus |
---|
| 1936 | """ |
---|
[0a2fdca] | 1937 | if self.cpanel_on_focus is not None: |
---|
| 1938 | self.cpanel_on_focus.on_zoom_in(event) |
---|
[f036c692] | 1939 | |
---|
[d828481] | 1940 | def on_zoom_out_panel(self, event=None): |
---|
| 1941 | """ |
---|
| 1942 | zoom out on the panel on focus |
---|
| 1943 | """ |
---|
[0a2fdca] | 1944 | if self.cpanel_on_focus is not None: |
---|
| 1945 | self.cpanel_on_focus.on_zoom_out(event) |
---|
[f036c692] | 1946 | |
---|
[d828481] | 1947 | def on_drag_panel(self, event=None): |
---|
| 1948 | """ |
---|
| 1949 | drag apply to the panel on focus |
---|
| 1950 | """ |
---|
[0a2fdca] | 1951 | if self.cpanel_on_focus is not None: |
---|
| 1952 | self.cpanel_on_focus.on_drag(event) |
---|
[f036c692] | 1953 | |
---|
[d828481] | 1954 | def on_reset_panel(self, event=None): |
---|
| 1955 | """ |
---|
| 1956 | reset the current panel |
---|
| 1957 | """ |
---|
[0a2fdca] | 1958 | if self.cpanel_on_focus is not None: |
---|
| 1959 | self.cpanel_on_focus.on_reset(event) |
---|
[03314e7] | 1960 | |
---|
| 1961 | def enable_undo(self): |
---|
| 1962 | """ |
---|
| 1963 | enable undo related control |
---|
| 1964 | """ |
---|
[0a2fdca] | 1965 | if self.cpanel_on_focus is not None: |
---|
| 1966 | self._toolbar.enable_undo(self.cpanel_on_focus) |
---|
[03314e7] | 1967 | |
---|
| 1968 | def enable_redo(self): |
---|
| 1969 | """ |
---|
| 1970 | enable redo |
---|
| 1971 | """ |
---|
[0a2fdca] | 1972 | if self.cpanel_on_focus is not None: |
---|
| 1973 | self._toolbar.enable_redo(self.cpanel_on_focus) |
---|
[03314e7] | 1974 | |
---|
| 1975 | def enable_bookmark(self): |
---|
| 1976 | """ |
---|
| 1977 | Bookmark |
---|
| 1978 | """ |
---|
[0a2fdca] | 1979 | if self.cpanel_on_focus is not None: |
---|
| 1980 | self._toolbar.enable_bookmark(self.cpanel_on_focus) |
---|
[03314e7] | 1981 | |
---|
| 1982 | def enable_save(self): |
---|
| 1983 | """ |
---|
| 1984 | save |
---|
| 1985 | """ |
---|
[0a2fdca] | 1986 | if self.cpanel_on_focus is not None: |
---|
| 1987 | self._toolbar.enable_save(self.cpanel_on_focus) |
---|
[03314e7] | 1988 | |
---|
| 1989 | def enable_preview(self): |
---|
| 1990 | """ |
---|
| 1991 | preview |
---|
| 1992 | """ |
---|
[0a2fdca] | 1993 | if self.cpanel_on_focus is not None: |
---|
| 1994 | self._toolbar.enable_preview(self.cpanel_on_focus) |
---|
[03314e7] | 1995 | |
---|
| 1996 | def enable_print(self): |
---|
| 1997 | """ |
---|
| 1998 | print |
---|
| 1999 | """ |
---|
[0a2fdca] | 2000 | if self.cpanel_on_focus is not None: |
---|
| 2001 | self._toolbar.enable_print(self.cpanel_on_focus) |
---|
[03314e7] | 2002 | |
---|
| 2003 | def enable_zoom(self): |
---|
| 2004 | """ |
---|
| 2005 | zoom |
---|
| 2006 | """ |
---|
[0a2fdca] | 2007 | if self.cpanel_on_focus is not None: |
---|
[03314e7] | 2008 | self._toolbar.enable_zoom(self.panel_on_focus) |
---|
| 2009 | |
---|
| 2010 | def enable_zoom_in(self): |
---|
| 2011 | """ |
---|
| 2012 | zoom in |
---|
| 2013 | """ |
---|
[0a2fdca] | 2014 | if self.cpanel_on_focus is not None: |
---|
[03314e7] | 2015 | self._toolbar.enable_zoom_in(self.panel_on_focus) |
---|
| 2016 | |
---|
| 2017 | def enable_zoom_out(self): |
---|
| 2018 | """ |
---|
| 2019 | zoom out |
---|
| 2020 | """ |
---|
[0a2fdca] | 2021 | if self.cpanel_on_focus is not None: |
---|
[03314e7] | 2022 | self._toolbar.enable_zoom_out(self.panel_on_focus) |
---|
| 2023 | |
---|
| 2024 | def enable_drag(self, event=None): |
---|
| 2025 | """ |
---|
| 2026 | drag |
---|
| 2027 | """ |
---|
[0a2fdca] | 2028 | if self.cpanel_on_focus is not None: |
---|
[03314e7] | 2029 | self._toolbar.enable_drag(self.panel_on_focus) |
---|
| 2030 | |
---|
| 2031 | def enable_reset(self): |
---|
| 2032 | """ |
---|
| 2033 | reset the current panel |
---|
| 2034 | """ |
---|
[0a2fdca] | 2035 | if self.cpanel_on_focus is not None: |
---|
[03314e7] | 2036 | self._toolbar.enable_reset(self.panel_on_focus) |
---|
[6d727ae] | 2037 | |
---|
| 2038 | def set_schedule_full_draw(self, panel=None, func='del'): |
---|
| 2039 | """ |
---|
| 2040 | Add/subtract the schedule full draw list with the panel given |
---|
| 2041 | |
---|
| 2042 | :param panel: plot panel |
---|
| 2043 | :param func: append or del [string] |
---|
| 2044 | """ |
---|
| 2045 | |
---|
| 2046 | # append this panel in the schedule list if not in yet |
---|
| 2047 | if func == 'append': |
---|
| 2048 | if not panel in self.schedule_full_draw_list: |
---|
| 2049 | self.schedule_full_draw_list.append(panel) |
---|
| 2050 | # remove this panel from schedule list |
---|
| 2051 | elif func == 'del': |
---|
| 2052 | if len(self.schedule_full_draw_list) > 0: |
---|
| 2053 | if panel in self.schedule_full_draw_list: |
---|
| 2054 | self.schedule_full_draw_list.remove(panel) |
---|
| 2055 | |
---|
| 2056 | # reset the schdule |
---|
| 2057 | if len(self.schedule_full_draw_list) == 0: |
---|
| 2058 | self.schedule = False |
---|
| 2059 | else: |
---|
| 2060 | self.schedule = True |
---|
| 2061 | |
---|
| 2062 | def full_draw(self): |
---|
| 2063 | """ |
---|
| 2064 | Draw the panels with axes in the schedule to full dwar list |
---|
| 2065 | """ |
---|
| 2066 | count = len(self.schedule_full_draw_list) |
---|
| 2067 | #if not self.schedule: |
---|
| 2068 | if count < 1: |
---|
| 2069 | self.set_schedule(False) |
---|
| 2070 | return |
---|
| 2071 | else: |
---|
| 2072 | ind = 0 |
---|
| 2073 | # if any of the panel is shown do full_draw |
---|
| 2074 | for panel in self.schedule_full_draw_list: |
---|
| 2075 | ind += 1 |
---|
| 2076 | if self._mgr.GetPane(panel.window_name).IsShown(): |
---|
| 2077 | break |
---|
| 2078 | # otherwise, return |
---|
| 2079 | if ind == count: |
---|
| 2080 | return |
---|
| 2081 | |
---|
| 2082 | #Simple redraw only for a panel shown |
---|
| 2083 | def f_draw(panel): |
---|
| 2084 | """ |
---|
| 2085 | Draw A panel in the full dwar list |
---|
| 2086 | """ |
---|
| 2087 | # Check if the panel is shown |
---|
| 2088 | if self._mgr.GetPane(panel.window_name).IsShown(): |
---|
| 2089 | try: |
---|
| 2090 | # This checking of GetCapture is to stop redrawing |
---|
| 2091 | # while any panel is capture. |
---|
| 2092 | if self.GetCapture() == None: |
---|
| 2093 | # draw if possible |
---|
| 2094 | panel.set_resizing(False) |
---|
| 2095 | panel.draw_plot() |
---|
| 2096 | except: |
---|
| 2097 | pass |
---|
| 2098 | #print self.callback,self.schedule,self.schedule_full_draw_list |
---|
| 2099 | |
---|
| 2100 | # Draw all panels |
---|
| 2101 | map(f_draw, self.schedule_full_draw_list) |
---|
| 2102 | |
---|
| 2103 | # Reset the attr |
---|
| 2104 | if len(self.schedule_full_draw_list) == 0: |
---|
| 2105 | self.set_schedule(False) |
---|
| 2106 | else: |
---|
| 2107 | self.set_schedule(True) |
---|
| 2108 | # update mgr |
---|
| 2109 | self._mgr.Update() |
---|
| 2110 | |
---|
| 2111 | def set_schedule(self, schedule=False): |
---|
| 2112 | """ |
---|
| 2113 | Set schedule |
---|
| 2114 | """ |
---|
| 2115 | self.schedule = schedule |
---|
| 2116 | |
---|
| 2117 | def get_schedule(self): |
---|
| 2118 | """ |
---|
| 2119 | Get schedule |
---|
| 2120 | """ |
---|
| 2121 | return self.schedule |
---|
| 2122 | |
---|
[0a2fdca] | 2123 | def on_set_plot_focus(self, panel): |
---|
| 2124 | """ |
---|
| 2125 | Set focus on a plot panel |
---|
| 2126 | """ |
---|
| 2127 | for plot in self.plot_panels.values(): |
---|
| 2128 | # make sure we don't double focus |
---|
| 2129 | if panel != plot: |
---|
| 2130 | plot.on_kill_focus(None) |
---|
[48665ed] | 2131 | |
---|
[0a2fdca] | 2132 | panel.on_set_focus(None) |
---|
| 2133 | # set focusing panel |
---|
| 2134 | self.panel_on_focus = panel |
---|
| 2135 | self.set_panel_on_focus(None) |
---|
[2a62d5c] | 2136 | print " on_set_plot_focus" |
---|
[0a2fdca] | 2137 | |
---|
[6d727ae] | 2138 | def _onDrawIdle(self, *args, **kwargs): |
---|
| 2139 | """ |
---|
| 2140 | ReDraw with axes |
---|
| 2141 | """ |
---|
| 2142 | # check if it is time to redraw |
---|
| 2143 | if self.GetCapture() == None: |
---|
| 2144 | # Draw plot, changes resizing too |
---|
| 2145 | self.full_draw() |
---|
| 2146 | |
---|
| 2147 | # restart idle |
---|
| 2148 | self._redraw_idle(*args, **kwargs) |
---|
| 2149 | |
---|
| 2150 | |
---|
| 2151 | def _redraw_idle(self, *args, **kwargs): |
---|
| 2152 | """ |
---|
| 2153 | Restart Idle |
---|
| 2154 | """ |
---|
| 2155 | # restart idle |
---|
| 2156 | self.idletimer.Restart(55, *args, **kwargs) |
---|
| 2157 | |
---|
[3feed3e] | 2158 | |
---|
[d828481] | 2159 | class DefaultPanel(wx.Panel, PanelBase): |
---|
[41d466f] | 2160 | """ |
---|
[d955bf19] | 2161 | Defines the API for a panels to work with |
---|
| 2162 | the GUI manager |
---|
[41d466f] | 2163 | """ |
---|
| 2164 | ## Internal nickname for the window, used by the AUI manager |
---|
| 2165 | window_name = "default" |
---|
| 2166 | ## Name to appear on the window title bar |
---|
| 2167 | window_caption = "Welcome panel" |
---|
| 2168 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
| 2169 | CENTER_PANE = True |
---|
[1b3a5a9] | 2170 | def __init__(self, parent, *args, **kwds): |
---|
| 2171 | wx.Panel.__init__(self, parent, *args, **kwds) |
---|
| 2172 | PanelBase.__init__(self, parent) |
---|
[d828481] | 2173 | |
---|
[41d466f] | 2174 | |
---|
[4753fc2] | 2175 | |
---|
[41d466f] | 2176 | # Toy application to test this Frame |
---|
| 2177 | class ViewApp(wx.App): |
---|
[d955bf19] | 2178 | """ |
---|
| 2179 | """ |
---|
[41d466f] | 2180 | def OnInit(self): |
---|
[d955bf19] | 2181 | """ |
---|
| 2182 | """ |
---|
[957723f] | 2183 | pos, size = self.window_placement((GUIFRAME_WIDTH, GUIFRAME_HEIGHT)) |
---|
[3385795] | 2184 | self.frame = ViewerFrame(parent=None, |
---|
[957723f] | 2185 | title=APPLICATION_NAME, |
---|
[3385795] | 2186 | pos=pos, |
---|
[957723f] | 2187 | gui_style = DEFAULT_STYLE, |
---|
[3385795] | 2188 | size=size) |
---|
[957723f] | 2189 | self.s_screen = None |
---|
[db6ce6c] | 2190 | try: |
---|
| 2191 | # make sure the current dir is App dir when it starts |
---|
| 2192 | temp_path = os.path.dirname(os.path.sys.path[0]) |
---|
| 2193 | os.chdir(temp_path) |
---|
| 2194 | except: |
---|
| 2195 | pass |
---|
[957723f] | 2196 | # Display a splash screen on top of the frame. |
---|
[3385795] | 2197 | if len(sys.argv) > 1 and '--time' in sys.argv[1:]: |
---|
| 2198 | log_time("Starting to display the splash screen") |
---|
[957723f] | 2199 | |
---|
| 2200 | try: |
---|
| 2201 | if os.path.isfile(SPLASH_SCREEN_PATH): |
---|
| 2202 | self.s_screen = self.display_splash_screen(parent=self.frame, |
---|
| 2203 | path=SPLASH_SCREEN_PATH) |
---|
| 2204 | else: |
---|
| 2205 | self.frame.Show() |
---|
| 2206 | except: |
---|
[cc835cd8] | 2207 | msg = "Cannot display splash screen\n" |
---|
| 2208 | msg += str (sys.exc_value) |
---|
| 2209 | logging.error(msg) |
---|
| 2210 | self.frame.Show() |
---|
| 2211 | |
---|
[41d466f] | 2212 | if hasattr(self.frame, 'special'): |
---|
| 2213 | self.frame.special.SetCurrent() |
---|
| 2214 | self.SetTopWindow(self.frame) |
---|
[c3f697e] | 2215 | try: |
---|
| 2216 | self.open_file() |
---|
| 2217 | except: |
---|
| 2218 | msg = "%s Could not load " % str(APPLICATION_NAME) |
---|
| 2219 | msg += "input file from command line.\n" |
---|
| 2220 | logging.error(msg) |
---|
[41d466f] | 2221 | return True |
---|
[976604d] | 2222 | |
---|
[957723f] | 2223 | def open_file(self): |
---|
| 2224 | """ |
---|
| 2225 | open a state file at the start of the application |
---|
| 2226 | """ |
---|
[c3f697e] | 2227 | input_file = None |
---|
| 2228 | if len(sys.argv) >= 2: |
---|
| 2229 | cmd = sys.argv[0].lower() |
---|
| 2230 | if os.path.isfile(cmd): |
---|
| 2231 | basename = os.path.basename(cmd) |
---|
[64e44c1] | 2232 | app_py = str(APPLICATION_NAME).lower() + '.py' |
---|
| 2233 | app_exe = str(APPLICATION_NAME).lower() + '.exe' |
---|
| 2234 | if basename.lower() in [app_py, app_exe]: |
---|
[c3f697e] | 2235 | input_file = sys.argv[1] |
---|
| 2236 | if input_file is None: |
---|
| 2237 | return |
---|
[976604d] | 2238 | if self.frame is not None: |
---|
[29ef718] | 2239 | self.frame.set_input_file(input_file=input_file) |
---|
[1b1bbf9] | 2240 | |
---|
| 2241 | |
---|
[41d466f] | 2242 | def set_manager(self, manager): |
---|
| 2243 | """ |
---|
[d955bf19] | 2244 | Sets a reference to the application manager |
---|
| 2245 | of the GUI manager (Frame) |
---|
[41d466f] | 2246 | """ |
---|
| 2247 | self.frame.set_manager(manager) |
---|
| 2248 | |
---|
[278cc25] | 2249 | def build_gui(self): |
---|
| 2250 | """ |
---|
[d955bf19] | 2251 | Build the GUI |
---|
[278cc25] | 2252 | """ |
---|
[976604d] | 2253 | #try to load file at the start |
---|
| 2254 | try: |
---|
| 2255 | self.open_file() |
---|
| 2256 | except: |
---|
| 2257 | raise |
---|
[29ef718] | 2258 | self.frame.build_gui() |
---|
[d18e208] | 2259 | if self.s_screen is not None and self.s_screen.IsShown(): |
---|
[957723f] | 2260 | self.s_screen.Close() |
---|
[278cc25] | 2261 | |
---|
[f9e803e] | 2262 | def set_welcome_panel(self, panel_class): |
---|
| 2263 | """ |
---|
[d955bf19] | 2264 | Set the welcome panel |
---|
| 2265 | |
---|
| 2266 | :param panel_class: class of the welcome panel to be instantiated |
---|
| 2267 | |
---|
[f9e803e] | 2268 | """ |
---|
| 2269 | self.frame.set_welcome_panel(panel_class) |
---|
| 2270 | |
---|
[278cc25] | 2271 | def add_perspective(self, perspective): |
---|
| 2272 | """ |
---|
[d955bf19] | 2273 | Manually add a perspective to the application GUI |
---|
[278cc25] | 2274 | """ |
---|
| 2275 | self.frame.add_perspective(perspective) |
---|
[3385795] | 2276 | |
---|
| 2277 | def window_placement(self, size): |
---|
| 2278 | """ |
---|
| 2279 | Determines the position and size of the application frame such that it |
---|
| 2280 | fits on the user's screen without obstructing (or being obstructed by) |
---|
| 2281 | the Windows task bar. The maximum initial size in pixels is bounded by |
---|
| 2282 | WIDTH x HEIGHT. For most monitors, the application |
---|
| 2283 | will be centered on the screen; for very large monitors it will be |
---|
| 2284 | placed on the left side of the screen. |
---|
| 2285 | """ |
---|
| 2286 | window_width, window_height = size |
---|
| 2287 | screen_size = wx.GetDisplaySize() |
---|
| 2288 | window_height = window_height if screen_size[1]>window_height else screen_size[1]-50 |
---|
| 2289 | window_width = window_width if screen_size[0]> window_width else screen_size[0]-50 |
---|
| 2290 | xpos = ypos = 0 |
---|
| 2291 | |
---|
| 2292 | # Note that when running Linux and using an Xming (X11) server on a PC |
---|
| 2293 | # with a dual monitor configuration, the reported display size may be |
---|
| 2294 | # that of both monitors combined with an incorrect display count of 1. |
---|
| 2295 | # To avoid displaying this app across both monitors, we check for |
---|
| 2296 | # screen 'too big'. If so, we assume a smaller width which means the |
---|
| 2297 | # application will be placed towards the left hand side of the screen. |
---|
| 2298 | |
---|
| 2299 | _, _, x, y = wx.Display().GetClientArea() # size excludes task bar |
---|
| 2300 | if len(sys.argv) > 1 and '--platform' in sys.argv[1:]: |
---|
| 2301 | w, h = wx.DisplaySize() # size includes task bar area |
---|
| 2302 | if x > 1920: x = 1280 # display on left side, not centered on screen |
---|
| 2303 | if x > window_width: xpos = (x - window_width)/2 |
---|
| 2304 | if y > window_height: ypos = (y - window_height)/2 |
---|
| 2305 | |
---|
| 2306 | # Return the suggested position and size for the application frame. |
---|
| 2307 | return (xpos, ypos), (min(x, window_width), min(y, window_height)) |
---|
| 2308 | |
---|
[783940c] | 2309 | def display_splash_screen(self, parent, |
---|
[957723f] | 2310 | path=SPLASH_SCREEN_PATH): |
---|
[3385795] | 2311 | """Displays the splash screen. It will exactly cover the main frame.""" |
---|
[957723f] | 2312 | |
---|
[3385795] | 2313 | # Prepare the picture. On a 2GHz intel cpu, this takes about a second. |
---|
| 2314 | x, y = parent.GetSizeTuple() |
---|
| 2315 | image = wx.Image(path, wx.BITMAP_TYPE_PNG) |
---|
[957723f] | 2316 | image.Rescale(SPLASH_SCREEN_WIDTH, |
---|
| 2317 | SPLASH_SCREEN_HEIGHT, wx.IMAGE_QUALITY_HIGH) |
---|
[3385795] | 2318 | bm = image.ConvertToBitmap() |
---|
| 2319 | |
---|
| 2320 | # Create and show the splash screen. It will disappear only when the |
---|
| 2321 | # program has entered the event loop AND either the timeout has expired |
---|
| 2322 | # or the user has left clicked on the screen. Thus any processing |
---|
| 2323 | # performed in this routine (including sleeping) or processing in the |
---|
| 2324 | # calling routine (including doing imports) will prevent the splash |
---|
| 2325 | # screen from disappearing. |
---|
| 2326 | # |
---|
| 2327 | # Note that on Linux, the timeout appears to occur immediately in which |
---|
| 2328 | # case the splash screen disappears upon entering the event loop. |
---|
[783940c] | 2329 | s_screen = wx.SplashScreen(bitmap=bm, |
---|
| 2330 | splashStyle=(wx.SPLASH_TIMEOUT| |
---|
| 2331 | wx.SPLASH_CENTRE_ON_SCREEN), |
---|
| 2332 | style=(wx.SIMPLE_BORDER| |
---|
| 2333 | wx.FRAME_NO_TASKBAR| |
---|
| 2334 | wx.STAY_ON_TOP), |
---|
| 2335 | |
---|
[957723f] | 2336 | milliseconds=SS_MAX_DISPLAY_TIME, |
---|
[3385795] | 2337 | parent=parent, |
---|
| 2338 | id=wx.ID_ANY) |
---|
| 2339 | |
---|
[783940c] | 2340 | s_screen.Bind(wx.EVT_CLOSE, self.on_close_splash_screen) |
---|
| 2341 | s_screen.Show() |
---|
| 2342 | return s_screen |
---|
| 2343 | |
---|
| 2344 | |
---|
| 2345 | def on_close_splash_screen(self, event): |
---|
| 2346 | """ |
---|
| 2347 | """ |
---|
| 2348 | self.frame.Show(True) |
---|
| 2349 | event.Skip() |
---|
| 2350 | |
---|
[41d466f] | 2351 | if __name__ == "__main__": |
---|
| 2352 | app = ViewApp(0) |
---|
[32c0841] | 2353 | app.MainLoop() |
---|
| 2354 | |
---|
| 2355 | |
---|