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