[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) |
---|
[278cc25] | 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 | |
---|
[3feed3e] | 53 | PLOPANEL_WIDTH = 400 |
---|
| 54 | PLOPANEL_HEIGTH = 400 |
---|
[3385795] | 55 | GUIFRAME_WIDTH = 1000 |
---|
| 56 | GUIFRAME_HEIGHT = 800 |
---|
[4753fc2] | 57 | PROG_SPLASH_SCREEN = "images/danse_logo.png" |
---|
[75fbd17] | 58 | EXTENSIONS = ['.inv', '.fitv', '.prv', '.svs'] |
---|
[7681bac] | 59 | |
---|
[41d466f] | 60 | class ViewerFrame(wx.Frame): |
---|
| 61 | """ |
---|
[d955bf19] | 62 | Main application frame |
---|
[41d466f] | 63 | """ |
---|
[f444b20] | 64 | |
---|
[3385795] | 65 | def __init__(self, parent, title, |
---|
[4753fc2] | 66 | size=(GUIFRAME_WIDTH, GUIFRAME_HEIGHT), |
---|
[3385795] | 67 | gui_style=GUIFRAME.DEFAULT_STYLE, |
---|
| 68 | pos=wx.DefaultPosition): |
---|
[41d466f] | 69 | """ |
---|
[d955bf19] | 70 | Initialize the Frame object |
---|
[41d466f] | 71 | """ |
---|
[b7c7a1c] | 72 | |
---|
[3385795] | 73 | wx.Frame.__init__(self, parent=parent, title=title, pos=pos,size=size) |
---|
[d0802c3] | 74 | # Preferred window size |
---|
[3385795] | 75 | self._window_width, self._window_height = size |
---|
[52b8b74] | 76 | self.__gui_style = gui_style |
---|
[41d466f] | 77 | |
---|
[fc2b91a] | 78 | # Logging info |
---|
| 79 | logging.basicConfig(level=logging.DEBUG, |
---|
| 80 | format='%(asctime)s %(levelname)s %(message)s', |
---|
| 81 | filename='sans_app.log', |
---|
| 82 | filemode='w') |
---|
[c44e7cc] | 83 | path = os.path.dirname(__file__) |
---|
[32c0841] | 84 | temp_path = os.path.join(path,'images') |
---|
[c44e7cc] | 85 | ico_file = os.path.join(temp_path,'ball.ico') |
---|
[278cc25] | 86 | if os.path.isfile(ico_file): |
---|
| 87 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
[cbb2e40] | 88 | else: |
---|
[32c0841] | 89 | temp_path = os.path.join(os.getcwd(),'images') |
---|
[c44e7cc] | 90 | ico_file = os.path.join(temp_path,'ball.ico') |
---|
[cbb2e40] | 91 | if os.path.isfile(ico_file): |
---|
| 92 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
[41d466f] | 93 | |
---|
| 94 | ## Application manager |
---|
| 95 | self.app_manager = None |
---|
[32c0841] | 96 | self._mgr = None |
---|
[f444b20] | 97 | #add current perpsective |
---|
| 98 | self._current_perspective = None |
---|
[52b8b74] | 99 | self._plotting_plugin = None |
---|
| 100 | self._data_plugin = None |
---|
| 101 | #Menu bar and item |
---|
| 102 | self._menubar = None |
---|
| 103 | self._file_menu = None |
---|
| 104 | self._data_menu = None |
---|
| 105 | self._window_menu = None |
---|
[e75b5fa] | 106 | self._data_panel_menu = None |
---|
[c5e84fb] | 107 | self._help_menu = None |
---|
| 108 | self._tool_menu = None |
---|
[95f9cc4] | 109 | self._applications_menu_pos = -1 |
---|
[4c0572f] | 110 | self._applications_menu_name = None |
---|
[95f9cc4] | 111 | self._applications_menu = None |
---|
[d828481] | 112 | self._edit_menu = None |
---|
[a45037aa] | 113 | self._toolbar_menu = None |
---|
[73b3ae2] | 114 | self._save_appl_menu = None |
---|
[f036c692] | 115 | #tool bar |
---|
| 116 | self._toolbar = None |
---|
[41d466f] | 117 | ## Find plug-ins |
---|
| 118 | # Modify this so that we can specify the directory to look into |
---|
[32c0841] | 119 | self.plugins = [] |
---|
[b7c7a1c] | 120 | #add local plugin |
---|
[52b8b74] | 121 | self.plugins += self._get_local_plugins() |
---|
[a88ac04] | 122 | self.plugins += self._find_plugins() |
---|
[41d466f] | 123 | ## List of panels |
---|
| 124 | self.panels = {} |
---|
| 125 | |
---|
[2310d69] | 126 | # Default locations |
---|
| 127 | self._default_save_location = os.getcwd() |
---|
[f444b20] | 128 | |
---|
[f9e803e] | 129 | # Welcome panel |
---|
| 130 | self.defaultPanel = None |
---|
[b91c736] | 131 | #panel on focus |
---|
| 132 | self.panel_on_focus = None |
---|
[75fbd17] | 133 | self.loader = Loader() |
---|
[213892bc] | 134 | #data manager |
---|
| 135 | from data_manager import DataManager |
---|
| 136 | self._data_manager = DataManager() |
---|
| 137 | self._data_panel = DataPanel(parent=self) |
---|
| 138 | if self.panel_on_focus is not None: |
---|
[6db811e] | 139 | self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) |
---|
[a0d56d5] | 140 | # Check for update |
---|
[af20f6b] | 141 | #self._check_update(None) |
---|
[278cc25] | 142 | # Register the close event so it calls our own method |
---|
[52725d6] | 143 | wx.EVT_CLOSE(self, self.Close) |
---|
[278cc25] | 144 | # Register to status events |
---|
| 145 | self.Bind(EVT_STATUS, self._on_status_event) |
---|
[b91c736] | 146 | #Register add extra data on the same panel event on load |
---|
[a45037aa] | 147 | self.Bind(EVT_PANEL_ON_FOCUS, self.set_panel_on_focus) |
---|
[4e4d3bb] | 148 | self.Bind(EVT_APPEND_BOOKMARK, self.append_bookmark) |
---|
[03314e7] | 149 | |
---|
[4c0572f] | 150 | def get_data_manager(self): |
---|
| 151 | """ |
---|
| 152 | """ |
---|
| 153 | return self._data_manager |
---|
| 154 | |
---|
[03314e7] | 155 | def get_toolbar(self): |
---|
| 156 | """ |
---|
| 157 | """ |
---|
| 158 | return self._toolbar |
---|
| 159 | |
---|
[b91c736] | 160 | def set_panel_on_focus(self, event): |
---|
| 161 | """ |
---|
[d955bf19] | 162 | Store reference to the last panel on focus |
---|
[f036c692] | 163 | update the toolbar if available |
---|
| 164 | update edit menu if available |
---|
[b91c736] | 165 | """ |
---|
| 166 | self.panel_on_focus = event.panel |
---|
[a45037aa] | 167 | panel_name = 'No panel on focus' |
---|
| 168 | application_name = 'No Selected Application' |
---|
[213892bc] | 169 | if self.panel_on_focus is not None and self._data_panel is not None: |
---|
[a45037aa] | 170 | panel_name = self.panel_on_focus.window_caption |
---|
| 171 | self._data_panel.set_panel_on_focus(panel_name) |
---|
[03314e7] | 172 | #update toolbar |
---|
| 173 | self._update_toolbar_helper() |
---|
| 174 | #update edit menu |
---|
| 175 | self.enable_edit_menu() |
---|
[73b3ae2] | 176 | |
---|
[278cc25] | 177 | def build_gui(self): |
---|
[d955bf19] | 178 | """ |
---|
| 179 | """ |
---|
[41d466f] | 180 | # Set up the layout |
---|
| 181 | self._setup_layout() |
---|
| 182 | # Set up the menu |
---|
| 183 | self._setup_menus() |
---|
[f036c692] | 184 | # set tool bar |
---|
| 185 | self._setup_tool_bar() |
---|
[c9454bb] | 186 | #self.Fit() |
---|
[af20f6b] | 187 | #self._check_update(None) |
---|
[41d466f] | 188 | |
---|
| 189 | def _setup_layout(self): |
---|
| 190 | """ |
---|
[d955bf19] | 191 | Set up the layout |
---|
[41d466f] | 192 | """ |
---|
| 193 | # Status bar |
---|
[010c251] | 194 | from gui_statusbar import StatusBar |
---|
[db10f97] | 195 | self.sb = StatusBar(self, wx.ID_ANY) |
---|
[dd66fbd] | 196 | self.SetStatusBar(self.sb) |
---|
[41d466f] | 197 | # Add panel |
---|
[4c0572f] | 198 | default_flag = wx.aui.AUI_MGR_DEFAULT| wx.aui.AUI_MGR_ALLOW_ACTIVE_PANE |
---|
[52b8b74] | 199 | self._mgr = wx.aui.AuiManager(self, flags=default_flag) |
---|
[7a67e075] | 200 | |
---|
[41d466f] | 201 | # Load panels |
---|
| 202 | self._load_panels() |
---|
[c5e84fb] | 203 | self.set_default_perspective() |
---|
[41d466f] | 204 | self._mgr.Update() |
---|
[db10f97] | 205 | |
---|
| 206 | def SetStatusText(self, *args, **kwds): |
---|
[d955bf19] | 207 | """ |
---|
| 208 | """ |
---|
[db10f97] | 209 | number = self.sb.get_msg_position() |
---|
| 210 | wx.Frame.SetStatusText(number=number, *args, **kwds) |
---|
| 211 | |
---|
| 212 | def PopStatusText(self, *args, **kwds): |
---|
[d955bf19] | 213 | """ |
---|
| 214 | """ |
---|
[db10f97] | 215 | field = self.sb.get_msg_position() |
---|
| 216 | wx.Frame.PopStatusText(field=field) |
---|
| 217 | |
---|
| 218 | def PushStatusText(self, *args, **kwds): |
---|
[d955bf19] | 219 | """ |
---|
| 220 | """ |
---|
[db10f97] | 221 | field = self.sb.get_msg_position() |
---|
[32c0841] | 222 | wx.Frame.PushStatusText(self, field=field, string=string) |
---|
[278cc25] | 223 | |
---|
| 224 | def add_perspective(self, plugin): |
---|
| 225 | """ |
---|
[d955bf19] | 226 | Add a perspective if it doesn't already |
---|
| 227 | exist. |
---|
[278cc25] | 228 | """ |
---|
| 229 | is_loaded = False |
---|
| 230 | for item in self.plugins: |
---|
[32c0841] | 231 | if plugin.__class__ == item.__class__: |
---|
[f444b20] | 232 | msg = "Plugin %s already loaded" % plugin.__class__.__name__ |
---|
| 233 | logging.info(msg) |
---|
[32c0841] | 234 | is_loaded = True |
---|
[278cc25] | 235 | if not is_loaded: |
---|
| 236 | self.plugins.append(plugin) |
---|
[41d466f] | 237 | |
---|
[52b8b74] | 238 | def _get_local_plugins(self): |
---|
| 239 | """ |
---|
| 240 | get plugins local to guiframe and others |
---|
| 241 | """ |
---|
| 242 | plugins = [] |
---|
| 243 | #import guiframe local plugins |
---|
[7a67e075] | 244 | #check if the style contain guiframe.dataloader |
---|
| 245 | style1 = self.__gui_style & GUIFRAME.DATALOADER_ON |
---|
[3feed3e] | 246 | style2 = self.__gui_style & GUIFRAME.PLOTTING_ON |
---|
[7a67e075] | 247 | if style1 == GUIFRAME.DATALOADER_ON: |
---|
[52b8b74] | 248 | try: |
---|
| 249 | from sans.guiframe.local_perspectives.data_loader import data_loader |
---|
[3feed3e] | 250 | self._data_plugin = data_loader.Plugin() |
---|
[52b8b74] | 251 | plugins.append(self._data_plugin) |
---|
| 252 | except: |
---|
[3feed3e] | 253 | msg = "ViewerFrame._get_local_plugins:" |
---|
[52b8b74] | 254 | msg += "cannot import dataloader plugin.\n %s" % sys.exc_value |
---|
| 255 | logging.error(msg) |
---|
[3feed3e] | 256 | if style2 == GUIFRAME.PLOTTING_ON: |
---|
[52b8b74] | 257 | try: |
---|
| 258 | from sans.guiframe.local_perspectives.plotting import plotting |
---|
| 259 | self._plotting_plugin = plotting.Plugin() |
---|
| 260 | plugins.append(self._plotting_plugin) |
---|
| 261 | except: |
---|
[3feed3e] | 262 | msg = "ViewerFrame._get_local_plugins:" |
---|
[52b8b74] | 263 | msg += "cannot import plotting plugin.\n %s" % sys.exc_value |
---|
| 264 | logging.error(msg) |
---|
[3feed3e] | 265 | |
---|
[52b8b74] | 266 | return plugins |
---|
| 267 | |
---|
[41d466f] | 268 | def _find_plugins(self, dir="perspectives"): |
---|
| 269 | """ |
---|
[d955bf19] | 270 | Find available perspective plug-ins |
---|
| 271 | |
---|
| 272 | :param dir: directory in which to look for plug-ins |
---|
| 273 | |
---|
| 274 | :return: list of plug-ins |
---|
| 275 | |
---|
[41d466f] | 276 | """ |
---|
| 277 | import imp |
---|
| 278 | plugins = [] |
---|
| 279 | # Go through files in panels directory |
---|
| 280 | try: |
---|
| 281 | list = os.listdir(dir) |
---|
[a88ac04] | 282 | ## the default panel is the panel is the last plugin added |
---|
| 283 | for item in list: |
---|
[41d466f] | 284 | toks = os.path.splitext(os.path.basename(item)) |
---|
| 285 | name = None |
---|
| 286 | if not toks[0] == '__init__': |
---|
| 287 | |
---|
[32c0841] | 288 | if toks[1] == '.py' or toks[1] == '': |
---|
[41d466f] | 289 | name = toks[0] |
---|
| 290 | |
---|
| 291 | path = [os.path.abspath(dir)] |
---|
| 292 | file = None |
---|
| 293 | try: |
---|
[32c0841] | 294 | if toks[1] == '': |
---|
[41d466f] | 295 | mod_path = '.'.join([dir, name]) |
---|
[32c0841] | 296 | module = __import__(mod_path, globals(), |
---|
| 297 | locals(), [name]) |
---|
[41d466f] | 298 | else: |
---|
| 299 | (file, path, info) = imp.find_module(name, path) |
---|
[32c0841] | 300 | module = imp.load_module( name, file, item, info) |
---|
[41d466f] | 301 | if hasattr(module, "PLUGIN_ID"): |
---|
[f444b20] | 302 | try: |
---|
| 303 | plug = module.Plugin() |
---|
| 304 | if plug.set_default_perspective(): |
---|
| 305 | self._current_perspective = plug |
---|
| 306 | plugins.append(plug) |
---|
[32c0841] | 307 | msg = "Found plug-in: %s" % module.PLUGIN_ID |
---|
| 308 | logging.info(msg) |
---|
[41d466f] | 309 | except: |
---|
[32c0841] | 310 | msg = "Error accessing PluginPanel" |
---|
| 311 | msg += " in %s\n %s" % (name, sys.exc_value) |
---|
| 312 | config.printEVT(msg) |
---|
[41d466f] | 313 | except: |
---|
[3feed3e] | 314 | print sys.exc_value |
---|
[32c0841] | 315 | msg = "ViewerFrame._find_plugins: %s" % sys.exc_value |
---|
| 316 | logging.error(msg) |
---|
[41d466f] | 317 | finally: |
---|
[32c0841] | 318 | if not file == None: |
---|
[41d466f] | 319 | file.close() |
---|
| 320 | except: |
---|
[32c0841] | 321 | # Should raise and catch at a higher level and |
---|
| 322 | # display error on status bar |
---|
[41d466f] | 323 | pass |
---|
| 324 | return plugins |
---|
| 325 | |
---|
[f9e803e] | 326 | def set_welcome_panel(self, panel_class): |
---|
| 327 | """ |
---|
[d955bf19] | 328 | Sets the default panel as the given welcome panel |
---|
| 329 | |
---|
| 330 | :param panel_class: class of the welcome panel to be instantiated |
---|
| 331 | |
---|
[f9e803e] | 332 | """ |
---|
[d955bf19] | 333 | self.defaultPanel = panel_class(self, -1, style=wx.RAISED_BORDER) |
---|
[b28278e] | 334 | |
---|
[3feed3e] | 335 | def _get_panels_size(self, p): |
---|
| 336 | """ |
---|
| 337 | find the proper size of the current panel |
---|
| 338 | get the proper panel width and height |
---|
| 339 | """ |
---|
| 340 | panel_height_min = self._window_height |
---|
| 341 | panel_width_min = self._window_width |
---|
| 342 | style = self.__gui_style & (GUIFRAME.MANAGER_ON) |
---|
| 343 | if self._data_panel is not None and (p == self._data_panel): |
---|
[18ec684] | 344 | panel_width_min = self._window_width * 5/25 |
---|
[3feed3e] | 345 | return panel_width_min, panel_height_min |
---|
| 346 | if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: |
---|
| 347 | style = self.__gui_style & (GUIFRAME.PLOTTING_ON|GUIFRAME.MANAGER_ON) |
---|
| 348 | if style == (GUIFRAME.PLOTTING_ON|GUIFRAME.MANAGER_ON): |
---|
[18ec684] | 349 | panel_width_min = self._window_width * 15/25 |
---|
[3feed3e] | 350 | return panel_width_min, panel_height_min |
---|
| 351 | return panel_width_min, panel_height_min |
---|
| 352 | |
---|
[41d466f] | 353 | def _load_panels(self): |
---|
| 354 | """ |
---|
[d955bf19] | 355 | Load all panels in the panels directory |
---|
[41d466f] | 356 | """ |
---|
| 357 | |
---|
| 358 | # Look for plug-in panels |
---|
[c1469ebe] | 359 | panels = [] |
---|
[41d466f] | 360 | for item in self.plugins: |
---|
| 361 | if hasattr(item, "get_panels"): |
---|
| 362 | ps = item.get_panels(self) |
---|
| 363 | panels.extend(ps) |
---|
[3feed3e] | 364 | |
---|
[41d466f] | 365 | # Show a default panel with some help information |
---|
| 366 | # It also sets the size of the application windows |
---|
[c9454bb] | 367 | #TODO: Use this for slpash screen |
---|
[f9e803e] | 368 | if self.defaultPanel is None: |
---|
[32c0841] | 369 | self.defaultPanel = DefaultPanel(self, -1, style=wx.RAISED_BORDER) |
---|
[3feed3e] | 370 | # add a blank default panel always present |
---|
[41d466f] | 371 | self.panels["default"] = self.defaultPanel |
---|
| 372 | self._mgr.AddPane(self.defaultPanel, wx.aui.AuiPaneInfo(). |
---|
| 373 | Name("default"). |
---|
[3feed3e] | 374 | Center(). |
---|
[a45037aa] | 375 | CloseButton(False). |
---|
| 376 | MinimizeButton(False). |
---|
[32c0841] | 377 | # This is where we set the size of |
---|
| 378 | # the application window |
---|
| 379 | BestSize(wx.Size(self._window_width, |
---|
| 380 | self._window_height)). |
---|
[41d466f] | 381 | Show()) |
---|
[3feed3e] | 382 | #add data panel |
---|
| 383 | self.panels["data_panel"] = self._data_panel |
---|
| 384 | w, h = self._get_panels_size(self._data_panel) |
---|
| 385 | self._mgr.AddPane(self._data_panel, wx.aui.AuiPaneInfo(). |
---|
| 386 | Name(self._data_panel.window_name). |
---|
| 387 | Left(). |
---|
| 388 | MinimizeButton(). |
---|
[e75b5fa] | 389 | CloseButton(False). |
---|
[18ec684] | 390 | TopDockable(False). |
---|
| 391 | BottomDockable(False). |
---|
| 392 | LeftDockable(True). |
---|
| 393 | RightDockable(False). |
---|
| 394 | BestSize(wx.Size(w, h)). |
---|
[d828481] | 395 | Hide()) |
---|
[3feed3e] | 396 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 397 | if style != GUIFRAME.MANAGER_ON: |
---|
| 398 | self._mgr.GetPane(self.panels["data_panel"].window_name).Hide() |
---|
[d828481] | 399 | else: |
---|
| 400 | self._mgr.GetPane(self.panels["data_panel"].window_name).Show() |
---|
[3feed3e] | 401 | |
---|
[41d466f] | 402 | # Add the panels to the AUI manager |
---|
| 403 | for panel_class in panels: |
---|
| 404 | p = panel_class |
---|
| 405 | id = wx.NewId() |
---|
[3feed3e] | 406 | w, h = self._get_panels_size(p) |
---|
[41d466f] | 407 | # Check whether we need to put this panel |
---|
| 408 | # in the center pane |
---|
[6f59a98] | 409 | if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: |
---|
[41d466f] | 410 | if p.CENTER_PANE: |
---|
| 411 | self.panels[str(id)] = p |
---|
| 412 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
| 413 | Name(p.window_name).Caption(p.window_caption). |
---|
[a45037aa] | 414 | #CenterPane(). |
---|
| 415 | Center(). |
---|
| 416 | CloseButton(False). |
---|
| 417 | MinimizeButton(False). |
---|
[3feed3e] | 418 | MinSize(wx.Size(w, h)). |
---|
| 419 | Hide()) |
---|
[41d466f] | 420 | else: |
---|
| 421 | self.panels[str(id)] = p |
---|
| 422 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
| 423 | Name(p.window_name).Caption(p.window_caption). |
---|
| 424 | Right(). |
---|
| 425 | Dock(). |
---|
| 426 | TopDockable(). |
---|
| 427 | BottomDockable(). |
---|
| 428 | LeftDockable(). |
---|
| 429 | RightDockable(). |
---|
| 430 | MinimizeButton(). |
---|
[3feed3e] | 431 | Hide()) |
---|
[b28278e] | 432 | |
---|
[c70eb7c] | 433 | def update_data(self, prev_data, new_data): |
---|
| 434 | """ |
---|
| 435 | """ |
---|
| 436 | prev_id, data_state = self._data_manager.update_data(prev_data=prev_data, |
---|
| 437 | new_data=new_data) |
---|
[e88ebfd] | 438 | |
---|
[c70eb7c] | 439 | self._data_panel.remove_by_id(prev_id) |
---|
| 440 | self._data_panel.load_data_list(data_state) |
---|
[e88ebfd] | 441 | |
---|
| 442 | def update_theory(self, data_id, theory, state=None): |
---|
| 443 | """ |
---|
| 444 | """ |
---|
| 445 | data_state = self._data_manager.update_theory(data_id=data_id, |
---|
| 446 | theory=theory, |
---|
| 447 | state=state) |
---|
| 448 | self._data_panel.load_data_list(data_state) |
---|
[c70eb7c] | 449 | |
---|
[e6a93df] | 450 | def onfreeze(self, theory_id): |
---|
| 451 | """ |
---|
| 452 | """ |
---|
| 453 | data_state_list = self._data_manager.freeze(theory_id) |
---|
| 454 | self._data_panel.load_data_list(list=data_state_list) |
---|
| 455 | for data_state in data_state_list.values(): |
---|
| 456 | new_plot = data_state.get_data() |
---|
[df22224] | 457 | |
---|
[e6a93df] | 458 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
| 459 | title=new_plot.title)) |
---|
| 460 | |
---|
[c70eb7c] | 461 | def freeze(self, data_id, theory_id): |
---|
| 462 | """ |
---|
| 463 | """ |
---|
| 464 | data_state_list = self._data_manager.freeze_theory(data_id=data_id, |
---|
| 465 | theory_id=theory_id) |
---|
| 466 | self._data_panel.load_data_list(list=data_state_list) |
---|
[ee2b492] | 467 | for data_state in data_state_list.values(): |
---|
| 468 | new_plot = data_state.get_data() |
---|
| 469 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
[c70eb7c] | 470 | title=new_plot.title)) |
---|
| 471 | |
---|
| 472 | def delete_data(self, data): |
---|
| 473 | """ |
---|
| 474 | """ |
---|
| 475 | self._current_perspective.delete_data(data) |
---|
| 476 | |
---|
| 477 | |
---|
[a07e72f] | 478 | def get_context_menu(self, plotpanel=None): |
---|
[41d466f] | 479 | """ |
---|
[d955bf19] | 480 | Get the context menu items made available |
---|
| 481 | by the different plug-ins. |
---|
| 482 | This function is used by the plotting module |
---|
[41d466f] | 483 | """ |
---|
[a07e72f] | 484 | if plotpanel is None: |
---|
| 485 | return |
---|
[41d466f] | 486 | menu_list = [] |
---|
| 487 | for item in self.plugins: |
---|
[a07e72f] | 488 | menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) |
---|
[41d466f] | 489 | return menu_list |
---|
| 490 | |
---|
| 491 | def popup_panel(self, p): |
---|
| 492 | """ |
---|
[d955bf19] | 493 | Add a panel object to the AUI manager |
---|
| 494 | |
---|
| 495 | :param p: panel object to add to the AUI manager |
---|
[41d466f] | 496 | |
---|
[d955bf19] | 497 | :return: ID of the event associated with the new panel [int] |
---|
| 498 | |
---|
| 499 | """ |
---|
[41d466f] | 500 | ID = wx.NewId() |
---|
| 501 | self.panels[str(ID)] = p |
---|
| 502 | count = 0 |
---|
| 503 | for item in self.panels: |
---|
[383189f9] | 504 | if self.panels[item].window_name.startswith(p.window_name): |
---|
[41d466f] | 505 | count += 1 |
---|
| 506 | windowname = p.window_name |
---|
| 507 | caption = p.window_caption |
---|
[32c0841] | 508 | if count > 0: |
---|
[41d466f] | 509 | windowname += str(count+1) |
---|
| 510 | caption += (' '+str(count)) |
---|
| 511 | p.window_name = windowname |
---|
| 512 | p.window_caption = caption |
---|
| 513 | |
---|
[7a67e075] | 514 | style1 = self.__gui_style & GUIFRAME.FIXED_PANEL |
---|
| 515 | style2 = self.__gui_style & GUIFRAME.FLOATING_PANEL |
---|
| 516 | if style1 == GUIFRAME.FIXED_PANEL: |
---|
| 517 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
| 518 | Name(windowname).Caption(caption). |
---|
| 519 | MinimizeButton(). |
---|
| 520 | Resizable(True). |
---|
[c5e84fb] | 521 | # Use a large best size to make sure the AUI |
---|
| 522 | # manager takes all the available space |
---|
[3feed3e] | 523 | BestSize(wx.Size(PLOPANEL_WIDTH, PLOPANEL_HEIGTH))) |
---|
| 524 | self._popup_fixed_panel(p) |
---|
[213892bc] | 525 | |
---|
[0663dfb1] | 526 | elif style2 == GUIFRAME.FLOATING_PANEL: |
---|
[7a67e075] | 527 | self._mgr.AddPane(p, wx.aui.AuiPaneInfo(). |
---|
| 528 | Name(windowname).Caption(caption). |
---|
| 529 | MinimizeButton(). |
---|
| 530 | Resizable(True). |
---|
[c5e84fb] | 531 | # Use a large best size to make sure the AUI |
---|
| 532 | # manager takes all the available space |
---|
[3feed3e] | 533 | BestSize(wx.Size(PLOPANEL_WIDTH, PLOPANEL_HEIGTH))) |
---|
| 534 | self._popup_floating_panel(p) |
---|
[7a67e075] | 535 | |
---|
[d0802c3] | 536 | pane = self._mgr.GetPane(windowname) |
---|
| 537 | self._mgr.MaximizePane(pane) |
---|
| 538 | self._mgr.RestoreMaximizedPane() |
---|
[41d466f] | 539 | # Register for showing/hiding the panel |
---|
| 540 | wx.EVT_MENU(self, ID, self._on_view) |
---|
| 541 | |
---|
| 542 | self._mgr.Update() |
---|
| 543 | return ID |
---|
| 544 | |
---|
| 545 | def _setup_menus(self): |
---|
| 546 | """ |
---|
[d955bf19] | 547 | Set up the application menus |
---|
[41d466f] | 548 | """ |
---|
| 549 | # Menu |
---|
[b7c7a1c] | 550 | self._menubar = wx.MenuBar() |
---|
[52b8b74] | 551 | self._add_menu_file() |
---|
| 552 | self._add_menu_data() |
---|
| 553 | self._add_menu_application() |
---|
[f036c692] | 554 | self._add_menu_edit() |
---|
[c5e84fb] | 555 | self._add_menu_tool() |
---|
[7bc88bf] | 556 | self._add_current_plugin_menu() |
---|
[52b8b74] | 557 | self._add_menu_window() |
---|
[c5e84fb] | 558 | self._add_help_menu() |
---|
| 559 | self.SetMenuBar(self._menubar) |
---|
| 560 | |
---|
[f036c692] | 561 | def _setup_tool_bar(self): |
---|
| 562 | """ |
---|
| 563 | add toolbar to the frame |
---|
| 564 | """ |
---|
| 565 | #set toolbar |
---|
| 566 | self._toolbar = GUIToolBar(self, -1) |
---|
| 567 | self.SetToolBar(self._toolbar) |
---|
[a45037aa] | 568 | self._update_toolbar_helper() |
---|
| 569 | #self._on_hide_toolbar(event=None) |
---|
| 570 | |
---|
| 571 | def _update_toolbar_helper(self): |
---|
| 572 | """ |
---|
| 573 | """ |
---|
| 574 | application_name = 'No Selected Application' |
---|
| 575 | panel_name = 'No Panel on Focus' |
---|
| 576 | self._toolbar.update_toolbar(self.panel_on_focus) |
---|
[f036c692] | 577 | if self._current_perspective is not None: |
---|
[a45037aa] | 578 | application_name = self._current_perspective.sub_menu |
---|
| 579 | if self.panel_on_focus is not None: |
---|
| 580 | panel_name = self.panel_on_focus.window_caption |
---|
| 581 | self._toolbar.update_button(application_name=application_name, |
---|
| 582 | panel_name=panel_name) |
---|
| 583 | self._toolbar.Realize() |
---|
| 584 | |
---|
[c5e84fb] | 585 | def _add_menu_tool(self): |
---|
| 586 | """ |
---|
| 587 | Tools menu |
---|
| 588 | Go through plug-ins and find tools to populate the tools menu |
---|
| 589 | """ |
---|
| 590 | style = self.__gui_style & GUIFRAME.TOOL_ON |
---|
| 591 | if style == GUIFRAME.TOOL_ON: |
---|
| 592 | self._tool_menu = None |
---|
| 593 | for item in self.plugins: |
---|
| 594 | if hasattr(item, "get_tools"): |
---|
| 595 | for tool in item.get_tools(): |
---|
| 596 | # Only create a menu if we have at least one tool |
---|
| 597 | if self._tool_menu is None: |
---|
| 598 | self._tool_menu = wx.Menu() |
---|
| 599 | id = wx.NewId() |
---|
| 600 | self._tool_menu.Append(id, tool[0], tool[1]) |
---|
| 601 | wx.EVT_MENU(self, id, tool[2]) |
---|
| 602 | if self._tool_menu is not None: |
---|
| 603 | self._menubar.Append(self._tool_menu, '&Tools') |
---|
| 604 | |
---|
| 605 | def _add_current_plugin_menu(self): |
---|
| 606 | """ |
---|
| 607 | add current plugin menu |
---|
[cbf22e5] | 608 | Look for plug-in menus |
---|
| 609 | Add available plug-in sub-menus. |
---|
[c5e84fb] | 610 | """ |
---|
[7bc88bf] | 611 | if (self._menubar is None) or (self._current_perspective is None): |
---|
[cbf22e5] | 612 | return |
---|
[7bc88bf] | 613 | #replace or add a new menu for the current plugin |
---|
[4c0572f] | 614 | |
---|
| 615 | pos = self._menubar.FindMenu(str(self._applications_menu_name)) |
---|
[7bc88bf] | 616 | if pos != -1: |
---|
| 617 | menu_list = self._current_perspective.populate_menu(self) |
---|
| 618 | if menu_list: |
---|
[4c0572f] | 619 | for (menu, name) in menu_list: |
---|
| 620 | hidden_menu = self._menubar.Replace(pos, menu, name) |
---|
| 621 | self._applications_menu_name = name |
---|
| 622 | #self._applications_menu_pos = pos |
---|
[7bc88bf] | 623 | else: |
---|
| 624 | hidden_menu = self._menubar.Remove(pos) |
---|
[4c0572f] | 625 | self._applications_menu_name = None |
---|
[7bc88bf] | 626 | #get the position of the menu when it first added |
---|
[4c0572f] | 627 | self._applications_menu_pos = pos |
---|
| 628 | |
---|
[7bc88bf] | 629 | else: |
---|
| 630 | menu_list = self._current_perspective.populate_menu(self) |
---|
| 631 | if menu_list: |
---|
[4c0572f] | 632 | for (menu,name) in menu_list: |
---|
[95f9cc4] | 633 | if self._applications_menu_pos == -1: |
---|
[7bc88bf] | 634 | self._menubar.Append(menu, name) |
---|
| 635 | else: |
---|
[95f9cc4] | 636 | self._menubar.Insert(self._applications_menu_pos, menu, name) |
---|
[4c0572f] | 637 | self._applications_menu_name = name |
---|
[7bc88bf] | 638 | |
---|
[c5e84fb] | 639 | def _add_help_menu(self): |
---|
| 640 | """ |
---|
| 641 | add help menu |
---|
| 642 | """ |
---|
[41d466f] | 643 | # Help menu |
---|
[c5e84fb] | 644 | self._help_menu = wx.Menu() |
---|
[d828481] | 645 | style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON |
---|
| 646 | if style == GUIFRAME.WELCOME_PANEL_ON: |
---|
| 647 | # add the welcome panel menu item |
---|
| 648 | if self.defaultPanel is not None: |
---|
| 649 | id = wx.NewId() |
---|
| 650 | self._help_menu.Append(id, '&Welcome', '') |
---|
| 651 | self._help_menu.AppendSeparator() |
---|
| 652 | wx.EVT_MENU(self, id, self.show_welcome_panel) |
---|
[fa452e4] | 653 | # Look for help item in plug-ins |
---|
| 654 | for item in self.plugins: |
---|
| 655 | if hasattr(item, "help"): |
---|
| 656 | id = wx.NewId() |
---|
[c5e84fb] | 657 | self._help_menu.Append(id,'&%s help' % item.sub_menu, '') |
---|
[fa452e4] | 658 | wx.EVT_MENU(self, id, item.help) |
---|
[41d466f] | 659 | if config._do_aboutbox: |
---|
| 660 | id = wx.NewId() |
---|
[c5e84fb] | 661 | self._help_menu.Append(id,'&About', 'Software information') |
---|
[41d466f] | 662 | wx.EVT_MENU(self, id, self._onAbout) |
---|
[c5e84fb] | 663 | |
---|
[af20f6b] | 664 | # Checking for updates needs major refactoring to work with py2exe |
---|
| 665 | # We need to make sure it doesn't hang the application if the server |
---|
| 666 | # is not up. We also need to make sure there's a proper executable to |
---|
| 667 | # run if we spawn a new background process. |
---|
| 668 | #id = wx.NewId() |
---|
[c5e84fb] | 669 | #self._help_menu.Append(id,'&Check for update', |
---|
[32c0841] | 670 | #'Check for the latest version of %s' % config.__appname__) |
---|
[af20f6b] | 671 | #wx.EVT_MENU(self, id, self._check_update) |
---|
[c5e84fb] | 672 | self._menubar.Append(self._help_menu, '&Help') |
---|
| 673 | |
---|
[52b8b74] | 674 | def _add_menu_window(self): |
---|
| 675 | """ |
---|
| 676 | add a menu window to the menu bar |
---|
| 677 | Window menu |
---|
| 678 | Attach a menu item for each panel in our |
---|
| 679 | panel list that also appears in a plug-in. |
---|
| 680 | |
---|
| 681 | Only add the panel menu if there is only one perspective and |
---|
| 682 | it has more than two panels. |
---|
| 683 | Note: the first plug-in is always the plotting plug-in. |
---|
| 684 | The first application |
---|
| 685 | #plug-in is always the second one in the list. |
---|
| 686 | """ |
---|
| 687 | self._window_menu = wx.Menu() |
---|
| 688 | if self._plotting_plugin is not None: |
---|
[bf4402c3] | 689 | for (menu, name) in self._plotting_plugin.populate_menu(self): |
---|
[52b8b74] | 690 | self._window_menu.AppendSubMenu(menu, name) |
---|
| 691 | self._menubar.Append(self._window_menu, '&Window') |
---|
[c5e84fb] | 692 | |
---|
[7a67e075] | 693 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
[e75b5fa] | 694 | id = wx.NewId() |
---|
| 695 | self._data_panel_menu = self._window_menu.Append(id, |
---|
| 696 | '&Data Explorer ON', '') |
---|
| 697 | wx.EVT_MENU(self, id, self.show_data_panel) |
---|
[7a67e075] | 698 | if style == GUIFRAME.MANAGER_ON: |
---|
[e75b5fa] | 699 | self._data_panel_menu.SetText('Data Explorer OFF') |
---|
| 700 | else: |
---|
| 701 | self._data_panel_menu.SetText('Data Explorer ON') |
---|
[52b8b74] | 702 | |
---|
[4753fc2] | 703 | style = self.__gui_style & GUIFRAME.PLOTTING_ON |
---|
| 704 | if style == GUIFRAME.PLOTTING_ON: |
---|
| 705 | self._window_menu.AppendSeparator() |
---|
| 706 | id = wx.NewId() |
---|
| 707 | preferences_menu = wx.Menu() |
---|
| 708 | hint = "Plot panels will floating" |
---|
| 709 | preferences_menu.Append(id, '&Floating Plot Panel', hint) |
---|
| 710 | wx.EVT_MENU(self, id, self.set_plotpanel_floating) |
---|
| 711 | id = wx.NewId() |
---|
| 712 | hint = "Plot panels will displayed within the frame" |
---|
| 713 | preferences_menu.Append(id, '&Fixed Plot Panel', hint) |
---|
| 714 | wx.EVT_MENU(self, id, self.set_plotpanel_fixed) |
---|
| 715 | id = wx.NewId() |
---|
[a45037aa] | 716 | style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS |
---|
| 717 | if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
| 718 | id = wx.NewId() |
---|
| 719 | self._toolbar_menu = preferences_menu.Append(id,'&Hide Toolbar', '') |
---|
| 720 | wx.EVT_MENU(self, id, self._on_hide_toolbar) |
---|
[4753fc2] | 721 | self._window_menu.AppendSubMenu(preferences_menu,'&Preferences') |
---|
[d828481] | 722 | if self._window_menu.GetMenuItemCount() == 0: |
---|
| 723 | pos = self._menubar.FindMenu('Window') |
---|
| 724 | self._menubar.Remove(pos) |
---|
[7a67e075] | 725 | #wx.EVT_MENU(self, id, self.show_preferences_panel) |
---|
[52b8b74] | 726 | """ |
---|
| 727 | if len(self.plugins) == 2: |
---|
| 728 | plug = self.plugins[1] |
---|
| 729 | pers = plug.get_perspective() |
---|
| 730 | |
---|
| 731 | if len(pers) > 1: |
---|
| 732 | self._window_menu = wx.Menu() |
---|
| 733 | for item in self.panels: |
---|
| 734 | if item == 'default': |
---|
| 735 | continue |
---|
| 736 | panel = self.panels[item] |
---|
| 737 | if panel.window_name in pers: |
---|
| 738 | self._window_menu.Append(int(item), |
---|
| 739 | panel.window_caption, |
---|
| 740 | "Show %s window" % panel.window_caption) |
---|
| 741 | wx.EVT_MENU(self, int(item), self._on_view) |
---|
| 742 | self._menubar.Append(self._window_menu, '&Window') |
---|
| 743 | """ |
---|
| 744 | |
---|
| 745 | def _add_menu_application(self): |
---|
| 746 | """ |
---|
| 747 | |
---|
| 748 | # Attach a menu item for each defined perspective or application. |
---|
| 749 | # Only add the perspective menu if there are more than one perspectives |
---|
| 750 | add menu application |
---|
| 751 | """ |
---|
[7a67e075] | 752 | style = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS |
---|
| 753 | if style == GUIFRAME.MULTIPLE_APPLICATIONS: |
---|
[95f9cc4] | 754 | plug_data_count = False |
---|
| 755 | plug_no_data_count = False |
---|
| 756 | self._applications_menu = wx.Menu() |
---|
| 757 | separator = self._applications_menu.AppendSeparator() |
---|
[52b8b74] | 758 | for plug in self.plugins: |
---|
| 759 | if len(plug.get_perspective()) > 0: |
---|
| 760 | id = wx.NewId() |
---|
[95f9cc4] | 761 | if plug.use_data(): |
---|
| 762 | self._applications_menu.InsertCheckItem(0, id, plug.sub_menu, |
---|
| 763 | "Switch to application: %s" % plug.sub_menu) |
---|
| 764 | plug_data_count = True |
---|
| 765 | else: |
---|
| 766 | plug_no_data_count = True |
---|
| 767 | self._applications_menu.AppendCheckItem(id, plug.sub_menu, |
---|
| 768 | "Switch to application: %s" % plug.sub_menu) |
---|
[52b8b74] | 769 | wx.EVT_MENU(self, id, plug.on_perspective) |
---|
[95f9cc4] | 770 | if not (plug_data_count and plug_no_data_count): |
---|
| 771 | self._applications_menu.RemoveItem(separator) |
---|
| 772 | self._menubar.Append(self._applications_menu, '&Applications') |
---|
| 773 | self._check_applications_menu() |
---|
[52b8b74] | 774 | |
---|
| 775 | def _add_menu_file(self): |
---|
| 776 | """ |
---|
| 777 | add menu file |
---|
| 778 | """ |
---|
[d828481] | 779 | |
---|
[52b8b74] | 780 | # File menu |
---|
[52725d6] | 781 | self._file_menu = wx.Menu() |
---|
[d828481] | 782 | style = self.__gui_style & GUIFRAME.DATALOADER_ON |
---|
| 783 | if style == GUIFRAME.DATALOADER_ON: |
---|
| 784 | # some menu of plugin to be seen under file menu |
---|
[75fbd17] | 785 | hint_load_file = "Read state's files and load" |
---|
| 786 | hint_load_file += " them into the application" |
---|
| 787 | id = wx.NewId() |
---|
| 788 | self._save_appl_menu = self._file_menu.Append(id, |
---|
| 789 | '&Open State from File', hint_load_file) |
---|
| 790 | wx.EVT_MENU(self, id, self._on_open_state) |
---|
[d828481] | 791 | id = wx.NewId() |
---|
[73b3ae2] | 792 | self._save_appl_menu = self._file_menu.Append(id, |
---|
| 793 | '&Save Application', |
---|
[d828481] | 794 | 'Save state of the current active application') |
---|
| 795 | wx.EVT_MENU(self, id, self._on_save_application) |
---|
| 796 | id = wx.NewId() |
---|
| 797 | self._file_menu.Append(id, '&Save Project', |
---|
| 798 | 'Save the state of the whole application') |
---|
| 799 | wx.EVT_MENU(self, id, self._on_save_project) |
---|
| 800 | self._file_menu.AppendSeparator() |
---|
[52725d6] | 801 | |
---|
| 802 | id = wx.NewId() |
---|
| 803 | self._file_menu.Append(id, '&Quit', 'Exit') |
---|
[52b8b74] | 804 | wx.EVT_MENU(self, id, self.Close) |
---|
| 805 | # Add sub menus |
---|
[52725d6] | 806 | self._menubar.Append(self._file_menu, '&File') |
---|
[52b8b74] | 807 | |
---|
[d828481] | 808 | def _add_menu_edit(self): |
---|
| 809 | """ |
---|
| 810 | add menu edit |
---|
| 811 | """ |
---|
| 812 | # Edit Menu |
---|
| 813 | self._edit_menu = wx.Menu() |
---|
[f036c692] | 814 | self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo', |
---|
| 815 | 'Undo the previous action') |
---|
| 816 | wx.EVT_MENU(self, GUIFRAME_ID.UNDO_ID, self.on_undo_panel) |
---|
| 817 | self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo', |
---|
| 818 | 'Redo the previous action') |
---|
| 819 | wx.EVT_MENU(self, GUIFRAME_ID.REDO_ID, self.on_redo_panel) |
---|
[d828481] | 820 | self._edit_menu.AppendSeparator() |
---|
[783940c] | 821 | self._edit_menu.Append(GUIFRAME_ID.PREVIEW_ID, '&Report', |
---|
[f036c692] | 822 | 'Preview current panel') |
---|
| 823 | wx.EVT_MENU(self, GUIFRAME_ID.PREVIEW_ID, self.on_preview_panel) |
---|
| 824 | self._edit_menu.Append(GUIFRAME_ID.PRINT_ID, '&Print', |
---|
| 825 | 'Print current panel') |
---|
| 826 | wx.EVT_MENU(self, GUIFRAME_ID.PRINT_ID, self.on_print_panel) |
---|
| 827 | self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset', |
---|
| 828 | 'Reset current panel') |
---|
| 829 | wx.EVT_MENU(self, GUIFRAME_ID.RESET_ID, self.on_reset_panel) |
---|
| 830 | self._menubar.Append(self._edit_menu, '&Edit') |
---|
| 831 | self.enable_edit_menu() |
---|
[d828481] | 832 | |
---|
[75fbd17] | 833 | def get_style(self): |
---|
[52b8b74] | 834 | """ |
---|
| 835 | """ |
---|
[75fbd17] | 836 | return self.__gui_style |
---|
| 837 | |
---|
| 838 | def _add_menu_data(self): |
---|
[52b8b74] | 839 | """ |
---|
[75fbd17] | 840 | Add menu item item data to menu bar |
---|
[52b8b74] | 841 | """ |
---|
[75fbd17] | 842 | if self._data_plugin is not None: |
---|
| 843 | menu_list = self._data_plugin.populate_menu(self) |
---|
| 844 | if menu_list: |
---|
| 845 | for (menu, name) in menu_list: |
---|
| 846 | self._menubar.Append(menu, name) |
---|
| 847 | |
---|
[a45037aa] | 848 | def _on_hide_toolbar(self, event=None): |
---|
| 849 | """ |
---|
| 850 | hide or show toolbar |
---|
| 851 | """ |
---|
| 852 | if self._toolbar is None: |
---|
| 853 | return |
---|
| 854 | if self._toolbar.IsShown(): |
---|
| 855 | if self._toolbar_menu is not None: |
---|
| 856 | self._toolbar_menu.SetItemLabel('Show Toolbar') |
---|
| 857 | self._toolbar.Hide() |
---|
| 858 | else: |
---|
| 859 | if self._toolbar_menu is not None: |
---|
| 860 | self._toolbar_menu.SetItemLabel('Hide Toolbar') |
---|
| 861 | self._toolbar.Show() |
---|
| 862 | self._toolbar.Realize() |
---|
| 863 | |
---|
[41d466f] | 864 | def _on_status_event(self, evt): |
---|
| 865 | """ |
---|
[d955bf19] | 866 | Display status message |
---|
[41d466f] | 867 | """ |
---|
[db10f97] | 868 | self.sb.set_status(event=evt) |
---|
[dd66fbd] | 869 | |
---|
[41d466f] | 870 | def _on_view(self, evt): |
---|
| 871 | """ |
---|
[d955bf19] | 872 | A panel was selected to be shown. If it's not already |
---|
| 873 | shown, display it. |
---|
| 874 | |
---|
| 875 | :param evt: menu event |
---|
| 876 | |
---|
[41d466f] | 877 | """ |
---|
| 878 | self.show_panel(evt.GetId()) |
---|
[c1469ebe] | 879 | |
---|
[b28278e] | 880 | def on_close_welcome_panel(self): |
---|
[c1469ebe] | 881 | """ |
---|
[d955bf19] | 882 | Close the welcome panel |
---|
[c1469ebe] | 883 | """ |
---|
[629e8b9] | 884 | if self.defaultPanel is None: |
---|
| 885 | return |
---|
[c1469ebe] | 886 | self._mgr.GetPane(self.panels["default"].window_name).Hide() |
---|
| 887 | self._mgr.Update() |
---|
[b28278e] | 888 | # set a default perspective |
---|
| 889 | self.set_default_perspective() |
---|
[c1469ebe] | 890 | |
---|
| 891 | def show_welcome_panel(self, event): |
---|
| 892 | """ |
---|
[d955bf19] | 893 | Display the welcome panel |
---|
[c1469ebe] | 894 | """ |
---|
[629e8b9] | 895 | if self.defaultPanel is None: |
---|
| 896 | return |
---|
[c1469ebe] | 897 | for id in self.panels.keys(): |
---|
[c5e84fb] | 898 | if id == 'default': |
---|
| 899 | # Show default panel |
---|
| 900 | if not self._mgr.GetPane(self.panels["default"].window_name).IsShown(): |
---|
| 901 | self._mgr.GetPane(self.panels["default"].window_name).Show(True) |
---|
| 902 | elif id == "data_panel": |
---|
| 903 | flag = self._mgr.GetPane(self.panels["data_panel"].window_name).IsShown() |
---|
| 904 | self._mgr.GetPane(self.panels["data_panel"].window_name).Show(flag) |
---|
| 905 | else: |
---|
| 906 | self._mgr.GetPane(self.panels[id].window_name).IsShown() |
---|
[c1469ebe] | 907 | self._mgr.GetPane(self.panels[id].window_name).Hide() |
---|
| 908 | self._mgr.Update() |
---|
[c5e84fb] | 909 | |
---|
[41d466f] | 910 | def show_panel(self, uid): |
---|
| 911 | """ |
---|
[d955bf19] | 912 | Shows the panel with the given id |
---|
| 913 | |
---|
| 914 | :param uid: unique ID number of the panel to show |
---|
| 915 | |
---|
[41d466f] | 916 | """ |
---|
| 917 | ID = str(uid) |
---|
| 918 | config.printEVT("show_panel: %s" % ID) |
---|
| 919 | if ID in self.panels.keys(): |
---|
| 920 | if not self._mgr.GetPane(self.panels[ID].window_name).IsShown(): |
---|
| 921 | self._mgr.GetPane(self.panels[ID].window_name).Show() |
---|
[383189f9] | 922 | # Hide default panel |
---|
| 923 | self._mgr.GetPane(self.panels["default"].window_name).Hide() |
---|
[41d466f] | 924 | self._mgr.Update() |
---|
[ae83ad3] | 925 | |
---|
| 926 | def hide_panel(self, uid): |
---|
| 927 | """ |
---|
| 928 | hide panel |
---|
| 929 | """ |
---|
| 930 | ID = str(uid) |
---|
| 931 | config.printEVT("hide_panel: %s" % ID) |
---|
| 932 | if ID in self.panels.keys(): |
---|
| 933 | if self._mgr.GetPane(self.panels[ID].window_name).IsShown(): |
---|
| 934 | self._mgr.GetPane(self.panels[ID].window_name).Hide() |
---|
| 935 | # Hide default panel |
---|
| 936 | self._mgr.GetPane(self.panels["default"].window_name).Hide() |
---|
| 937 | self._mgr.Update() |
---|
| 938 | |
---|
[c9937c0] | 939 | def delete_panel(self, uid): |
---|
| 940 | """ |
---|
| 941 | delete panel given uid |
---|
| 942 | """ |
---|
| 943 | ID = str(uid) |
---|
| 944 | config.printEVT("delete_panel: %s" % ID) |
---|
[df22224] | 945 | |
---|
[c9937c0] | 946 | if ID in self.panels.keys(): |
---|
[df22224] | 947 | panel = self.panels[ID] |
---|
| 948 | self._plotting_plugin.delete_panel(panel.group_id) |
---|
| 949 | self._mgr.DetachPane(panel) |
---|
| 950 | panel.Destroy() |
---|
[c9937c0] | 951 | del self.panels[ID] |
---|
| 952 | self._mgr.Update() |
---|
| 953 | |
---|
[75fbd17] | 954 | def clear_panel(self): |
---|
[b3644f3] | 955 | """ |
---|
| 956 | """ |
---|
[75fbd17] | 957 | for item in self.panels: |
---|
| 958 | try: |
---|
| 959 | self.panels[item].clear_panel() |
---|
| 960 | except: |
---|
| 961 | pass |
---|
| 962 | |
---|
| 963 | def create_gui_data(self, data, path=None): |
---|
| 964 | """ |
---|
[0348245] | 965 | """ |
---|
| 966 | return self._data_manager.create_gui_data(data, path) |
---|
| 967 | |
---|
[03314e7] | 968 | def get_data(self, path): |
---|
[75fbd17] | 969 | """ |
---|
| 970 | """ |
---|
| 971 | message = "" |
---|
| 972 | log_msg = '' |
---|
| 973 | output = [] |
---|
| 974 | error_message = "" |
---|
| 975 | basename = os.path.basename(path) |
---|
| 976 | root, extension = os.path.splitext(basename) |
---|
| 977 | if extension.lower() not in EXTENSIONS: |
---|
| 978 | log_msg = "File Loader cannot " |
---|
| 979 | log_msg += "load: %s\n" % str(basename) |
---|
| 980 | log_msg += "Try Data opening...." |
---|
| 981 | logging.info(log_msg) |
---|
| 982 | self.load_complete(output=output, error_message=error_message, |
---|
| 983 | message=log_msg, path=path) |
---|
[700f9b4] | 984 | return |
---|
[75fbd17] | 985 | |
---|
| 986 | #reading a state file |
---|
| 987 | for plug in self.plugins: |
---|
[03314e7] | 988 | reader, ext = plug.get_extensions() |
---|
| 989 | if reader is not None: |
---|
| 990 | #read the state of the single plugin |
---|
| 991 | if extension == ext: |
---|
| 992 | reader.read(path) |
---|
| 993 | return |
---|
| 994 | elif extension == '.svs': |
---|
| 995 | reader.read(path) |
---|
| 996 | |
---|
[75fbd17] | 997 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 998 | if style == GUIFRAME.MANAGER_ON: |
---|
| 999 | if self._data_panel is not None: |
---|
| 1000 | data_state = self._data_manager.get_selected_data() |
---|
| 1001 | self._data_panel.load_data_list(data_state) |
---|
| 1002 | self._mgr.GetPane(self._data_panel.window_name).Show(True) |
---|
[03314e7] | 1003 | |
---|
[75fbd17] | 1004 | def _on_open_state(self, event): |
---|
| 1005 | """ |
---|
| 1006 | """ |
---|
| 1007 | path = None |
---|
| 1008 | if self._default_save_location == None: |
---|
| 1009 | self._default_save_location = os.getcwd() |
---|
| 1010 | |
---|
| 1011 | wlist = ['SansView files (*.svs)|*.svs', |
---|
| 1012 | 'P(r) files (*.prv)|*.prv', |
---|
| 1013 | 'Fitting files (*.fitv)|*.fitv', |
---|
| 1014 | 'Invariant files (*.inv)|*.inv'] |
---|
| 1015 | wlist = '|'.join(wlist) |
---|
| 1016 | dlg = wx.FileDialog(self, |
---|
| 1017 | "Choose a file", |
---|
| 1018 | self._default_save_location, "", |
---|
| 1019 | wlist) |
---|
| 1020 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1021 | path = dlg.GetPath() |
---|
| 1022 | if path is not None: |
---|
| 1023 | self._default_save_location = os.path.dirname(path) |
---|
| 1024 | dlg.Destroy() |
---|
[4e9583c] | 1025 | if path and os.path.isfile(path): |
---|
[32c0841] | 1026 | basename = os.path.basename(path) |
---|
| 1027 | if basename.endswith('.svs'): |
---|
| 1028 | #remove panels for new states |
---|
[03314e7] | 1029 | for plug in self.plugins: |
---|
| 1030 | plug.clear_panel() |
---|
| 1031 | self.panel_on_focus = None |
---|
| 1032 | |
---|
[75fbd17] | 1033 | self.get_data(path) |
---|
| 1034 | |
---|
[aebc4cc] | 1035 | if self.defaultPanel is not None and \ |
---|
| 1036 | self._mgr.GetPane(self.panels["default"].window_name).IsShown(): |
---|
| 1037 | self.on_close_welcome_panel() |
---|
[75fbd17] | 1038 | |
---|
[52725d6] | 1039 | def _on_save_application(self, event): |
---|
[b35d3d1] | 1040 | """ |
---|
[52725d6] | 1041 | save the state of the current active application |
---|
[b35d3d1] | 1042 | """ |
---|
[73b3ae2] | 1043 | if self.panel_on_focus is not None: |
---|
| 1044 | self.panel_on_focus.on_save(event) |
---|
[52725d6] | 1045 | |
---|
| 1046 | def _on_save_project(self, event): |
---|
| 1047 | """ |
---|
| 1048 | save the state of the current active application |
---|
| 1049 | """ |
---|
| 1050 | ## Default file location for save |
---|
| 1051 | self._default_save_location = os.getcwd() |
---|
| 1052 | if self._current_perspective is None: |
---|
| 1053 | return |
---|
| 1054 | reader, ext = self._current_perspective.get_extensions() |
---|
| 1055 | path = None |
---|
[75fbd17] | 1056 | dlg = wx.FileDialog(self, "Save Project file", |
---|
[52725d6] | 1057 | self._default_save_location, "", '.svs', wx.SAVE) |
---|
| 1058 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1059 | path = dlg.GetPath() |
---|
| 1060 | self._default_save_location = os.path.dirname(path) |
---|
| 1061 | else: |
---|
| 1062 | return None |
---|
| 1063 | dlg.Destroy() |
---|
| 1064 | if path is None: |
---|
| 1065 | return |
---|
| 1066 | # default cansas xml doc |
---|
| 1067 | doc = None |
---|
| 1068 | for panel in self.panels.values(): |
---|
| 1069 | doc = self.on_save_helper(doc, reader, panel, path) |
---|
| 1070 | |
---|
| 1071 | |
---|
| 1072 | def on_save_helper(self, doc, reader, panel, path): |
---|
| 1073 | """ |
---|
| 1074 | Save state into a file |
---|
| 1075 | """ |
---|
| 1076 | try: |
---|
| 1077 | data = panel.get_data() |
---|
| 1078 | state = panel.get_state() |
---|
| 1079 | if reader is not None: |
---|
| 1080 | if data is not None: |
---|
| 1081 | new_doc = reader.write_toXML(data, state) |
---|
| 1082 | if hasattr(doc, "firstChild"): |
---|
| 1083 | child = new_doc.firstChild.firstChild |
---|
| 1084 | doc.firstChild.appendChild(child) |
---|
| 1085 | else: |
---|
| 1086 | doc = new_doc |
---|
| 1087 | except: |
---|
| 1088 | raise |
---|
| 1089 | #pass |
---|
[b35d3d1] | 1090 | # Write the XML document |
---|
| 1091 | if doc != None: |
---|
| 1092 | fd = open(path, 'w') |
---|
| 1093 | fd.write(doc.toprettyxml()) |
---|
| 1094 | fd.close() |
---|
| 1095 | else: |
---|
[52725d6] | 1096 | raise |
---|
[32c0841] | 1097 | #print "Nothing to save..." |
---|
[52725d6] | 1098 | #raise RuntimeError, "%s is not a SansView (.svs) file..." % path |
---|
| 1099 | return doc |
---|
[b35d3d1] | 1100 | |
---|
[b5ca223] | 1101 | def quit_guiframe(self): |
---|
| 1102 | """ |
---|
| 1103 | Pop up message to make sure the user wants to quit the application |
---|
| 1104 | """ |
---|
| 1105 | message = "Do you really want to quit \n" |
---|
| 1106 | message += "this application?" |
---|
| 1107 | dial = wx.MessageDialog(self, message, 'Question', |
---|
| 1108 | wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION) |
---|
| 1109 | if dial.ShowModal() == wx.ID_YES: |
---|
| 1110 | return True |
---|
| 1111 | else: |
---|
| 1112 | return False |
---|
| 1113 | |
---|
[41d466f] | 1114 | def Close(self, event=None): |
---|
| 1115 | """ |
---|
[d955bf19] | 1116 | Quit the application |
---|
[41d466f] | 1117 | """ |
---|
[52725d6] | 1118 | #flag = self.quit_guiframe() |
---|
| 1119 | if True: |
---|
[ba535a6] | 1120 | wx.Exit() |
---|
| 1121 | sys.exit() |
---|
[41d466f] | 1122 | |
---|
| 1123 | def _check_update(self, event=None): |
---|
| 1124 | """ |
---|
[d955bf19] | 1125 | Check with the deployment server whether a new version |
---|
| 1126 | of the application is available. |
---|
| 1127 | A thread is started for the connecting with the server. The thread calls |
---|
| 1128 | a call-back method when the current version number has been obtained. |
---|
[52070a1] | 1129 | """ |
---|
[d68c655] | 1130 | if hasattr(config, "__update_URL__"): |
---|
| 1131 | import version |
---|
[32c0841] | 1132 | checker = version.VersionThread(config.__update_URL__, |
---|
| 1133 | self._process_version, |
---|
| 1134 | baggage=event==None) |
---|
[d68c655] | 1135 | checker.start() |
---|
[52070a1] | 1136 | |
---|
| 1137 | def _process_version(self, version, standalone=True): |
---|
| 1138 | """ |
---|
[d955bf19] | 1139 | Call-back method for the process of checking for updates. |
---|
| 1140 | This methods is called by a VersionThread object once the current |
---|
| 1141 | version number has been obtained. If the check is being done in the |
---|
| 1142 | background, the user will not be notified unless there's an update. |
---|
| 1143 | |
---|
| 1144 | :param version: version string |
---|
| 1145 | :param standalone: True of the update is being checked in |
---|
| 1146 | the background, False otherwise. |
---|
| 1147 | |
---|
[52070a1] | 1148 | """ |
---|
| 1149 | try: |
---|
[32c0841] | 1150 | if cmp(version, config.__version__) > 0: |
---|
| 1151 | msg = "Version %s is available! See the Help " |
---|
| 1152 | msg += "menu to download it." % version |
---|
| 1153 | self.SetStatusText(msg) |
---|
[52070a1] | 1154 | if not standalone: |
---|
| 1155 | import webbrowser |
---|
| 1156 | webbrowser.open(config.__download_page__) |
---|
| 1157 | else: |
---|
| 1158 | if not standalone: |
---|
[32c0841] | 1159 | msg = "You have the latest version" |
---|
| 1160 | msg += " of %s" % config.__appname__ |
---|
| 1161 | self.SetStatusText(msg) |
---|
[41d466f] | 1162 | except: |
---|
[32c0841] | 1163 | msg = "guiframe: could not get latest application" |
---|
| 1164 | msg += " version number\n %s" % sys.exc_value |
---|
| 1165 | logging.error(msg) |
---|
[52070a1] | 1166 | if not standalone: |
---|
[32c0841] | 1167 | msg = "Could not connect to the application server." |
---|
| 1168 | msg += " Please try again later." |
---|
| 1169 | self.SetStatusText(msg) |
---|
[52070a1] | 1170 | |
---|
[41d466f] | 1171 | def _onAbout(self, evt): |
---|
| 1172 | """ |
---|
[d955bf19] | 1173 | Pop up the about dialog |
---|
| 1174 | |
---|
| 1175 | :param evt: menu event |
---|
| 1176 | |
---|
[41d466f] | 1177 | """ |
---|
| 1178 | if config._do_aboutbox: |
---|
| 1179 | import aboutbox |
---|
| 1180 | dialog = aboutbox.DialogAbout(None, -1, "") |
---|
[6ab0ad1] | 1181 | dialog.ShowModal() |
---|
[4e9583c] | 1182 | |
---|
[41d466f] | 1183 | def set_manager(self, manager): |
---|
| 1184 | """ |
---|
[d955bf19] | 1185 | Sets the application manager for this frame |
---|
| 1186 | |
---|
| 1187 | :param manager: frame manager |
---|
[41d466f] | 1188 | """ |
---|
| 1189 | self.app_manager = manager |
---|
| 1190 | |
---|
| 1191 | def post_init(self): |
---|
| 1192 | """ |
---|
[d955bf19] | 1193 | This initialization method is called after the GUI |
---|
| 1194 | has been created and all plug-ins loaded. It calls |
---|
| 1195 | the post_init() method of each plug-in (if it exists) |
---|
| 1196 | so that final initialization can be done. |
---|
[41d466f] | 1197 | """ |
---|
| 1198 | for item in self.plugins: |
---|
| 1199 | if hasattr(item, "post_init"): |
---|
| 1200 | item.post_init() |
---|
| 1201 | |
---|
[b28278e] | 1202 | def set_default_perspective(self): |
---|
| 1203 | """ |
---|
[d955bf19] | 1204 | Choose among the plugin the first plug-in that has |
---|
| 1205 | "set_default_perspective" method and its return value is True will be |
---|
| 1206 | as a default perspective when the welcome page is closed |
---|
[b28278e] | 1207 | """ |
---|
| 1208 | for item in self.plugins: |
---|
| 1209 | if hasattr(item, "set_default_perspective"): |
---|
| 1210 | if item.set_default_perspective(): |
---|
[749eb8a] | 1211 | item.on_perspective(event=None) |
---|
[b28278e] | 1212 | return |
---|
[f444b20] | 1213 | |
---|
[41d466f] | 1214 | def set_perspective(self, panels): |
---|
| 1215 | """ |
---|
[d955bf19] | 1216 | Sets the perspective of the GUI. |
---|
| 1217 | Opens all the panels in the list, and closes |
---|
| 1218 | all the others. |
---|
| 1219 | |
---|
| 1220 | :param panels: list of panels |
---|
[41d466f] | 1221 | """ |
---|
| 1222 | for item in self.panels: |
---|
| 1223 | # Check whether this is a sticky panel |
---|
| 1224 | if hasattr(self.panels[item], "ALWAYS_ON"): |
---|
| 1225 | if self.panels[item].ALWAYS_ON: |
---|
| 1226 | continue |
---|
| 1227 | if self.panels[item].window_name in panels: |
---|
| 1228 | if not self._mgr.GetPane(self.panels[item].window_name).IsShown(): |
---|
| 1229 | self._mgr.GetPane(self.panels[item].window_name).Show() |
---|
| 1230 | else: |
---|
[3feed3e] | 1231 | # always show the data panel if enable |
---|
| 1232 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 1233 | if (style == GUIFRAME.MANAGER_ON) and self.panels[item] == self._data_panel: |
---|
| 1234 | if 'data_panel' in self.panels.keys(): |
---|
| 1235 | flag = self._mgr.GetPane(self.panels['data_panel'].window_name).IsShown() |
---|
| 1236 | self._mgr.GetPane(self.panels['data_panel'].window_name).Show(flag) |
---|
| 1237 | else: |
---|
| 1238 | if self._mgr.GetPane(self.panels[item].window_name).IsShown(): |
---|
| 1239 | self._mgr.GetPane(self.panels[item].window_name).Hide() |
---|
[41d466f] | 1240 | self._mgr.Update() |
---|
[4e9583c] | 1241 | |
---|
[213892bc] | 1242 | def show_data_panel(self, event=None): |
---|
[52b8b74] | 1243 | """ |
---|
[3feed3e] | 1244 | show the data panel |
---|
[52b8b74] | 1245 | """ |
---|
[e75b5fa] | 1246 | label = self._data_panel_menu.GetText() |
---|
| 1247 | if label == 'Data Explorer ON': |
---|
[75fbd17] | 1248 | pane = self._mgr.GetPane(self.panels["data_panel"].window_name) |
---|
| 1249 | #if not pane.IsShown(): |
---|
| 1250 | pane.Show(True) |
---|
| 1251 | self._mgr.Update() |
---|
[e75b5fa] | 1252 | self.__gui_style = self.__gui_style | GUIFRAME.MANAGER_ON |
---|
| 1253 | |
---|
| 1254 | self._data_panel_menu.SetText('Data Explorer OFF') |
---|
| 1255 | else: |
---|
| 1256 | pane = self._mgr.GetPane(self.panels["data_panel"].window_name) |
---|
| 1257 | #if not pane.IsShown(): |
---|
| 1258 | pane.Show(False) |
---|
| 1259 | self._mgr.Update() |
---|
| 1260 | self.__gui_style = self.__gui_style & (~GUIFRAME.MANAGER_ON) |
---|
| 1261 | self._data_panel_menu.SetText('Data Explorer ON') |
---|
[c70eb7c] | 1262 | |
---|
| 1263 | def add_data_helper(self, data_list): |
---|
| 1264 | """ |
---|
| 1265 | """ |
---|
[e88ebfd] | 1266 | if self._data_manager is not None: |
---|
| 1267 | self._data_manager.add_data(data_list) |
---|
[c70eb7c] | 1268 | |
---|
[75fbd17] | 1269 | def add_data(self, data_list): |
---|
[f444b20] | 1270 | """ |
---|
[e88ebfd] | 1271 | receive a dictionary of data from loader |
---|
| 1272 | store them its data manager if possible |
---|
| 1273 | send to data the current active perspective if the data panel |
---|
| 1274 | is not active. |
---|
| 1275 | :param data_list: dictionary of data's ID and value Data |
---|
[f444b20] | 1276 | """ |
---|
[e88ebfd] | 1277 | #Store data into manager |
---|
| 1278 | self.add_data_helper(data_list) |
---|
| 1279 | # set data in the data panel |
---|
| 1280 | if self._data_panel is not None: |
---|
| 1281 | data_state = self._data_manager.get_data_state(data_list.keys()) |
---|
| 1282 | self._data_panel.load_data_list(data_state) |
---|
| 1283 | #if the data panel is shown wait for the user to press a button |
---|
| 1284 | #to send data to the current perspective. if the panel is not |
---|
| 1285 | #show automatically send the data to the current perspective |
---|
[3feed3e] | 1286 | style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
| 1287 | if style == GUIFRAME.MANAGER_ON: |
---|
[9c169f4] | 1288 | #wait for button press from the data panel to set_data |
---|
[3feed3e] | 1289 | if self._data_panel is not None: |
---|
| 1290 | self._mgr.GetPane(self._data_panel.window_name).Show(True) |
---|
[9c169f4] | 1291 | self._mgr.Update() |
---|
[3feed3e] | 1292 | else: |
---|
| 1293 | #automatically send that to the current perspective |
---|
[e88ebfd] | 1294 | self.set_data(data_id=data_list.keys()) |
---|
[c70eb7c] | 1295 | |
---|
[e88ebfd] | 1296 | def set_data(self, data_id): |
---|
[c5e84fb] | 1297 | """ |
---|
[e88ebfd] | 1298 | set data to current perspective |
---|
[c5e84fb] | 1299 | """ |
---|
[e88ebfd] | 1300 | list_data, _ = self._data_manager.get_by_id(data_id) |
---|
| 1301 | if self._current_perspective is not None: |
---|
[df22224] | 1302 | self._current_perspective.set_data(list_data.values()) |
---|
[584c4c4] | 1303 | else: |
---|
[e88ebfd] | 1304 | msg = "Guiframe does not have a current perspective" |
---|
| 1305 | logging.info(msg) |
---|
| 1306 | |
---|
| 1307 | def set_theory(self, state_id, theory_id=None): |
---|
[c5e84fb] | 1308 | """ |
---|
| 1309 | """ |
---|
[df22224] | 1310 | _, list_theory = self._data_manager.get_by_id(theory_id) |
---|
[c5e84fb] | 1311 | if self._current_perspective is not None: |
---|
| 1312 | try: |
---|
[df22224] | 1313 | self._current_perspective.set_theory(list_theory.values()) |
---|
[c5e84fb] | 1314 | except: |
---|
[e88ebfd] | 1315 | msg = "Guiframe set_theory: \n" + str(sys.exc_value) |
---|
| 1316 | logging.info(msg) |
---|
[c5e84fb] | 1317 | wx.PostEvent(self, StatusEvent(status=msg, info="error")) |
---|
| 1318 | else: |
---|
| 1319 | msg = "Guiframe does not have a current perspective" |
---|
| 1320 | logging.info(msg) |
---|
[3feed3e] | 1321 | |
---|
[e88ebfd] | 1322 | def plot_data(self, state_id, data_id=None, |
---|
| 1323 | theory_id=None, append=False): |
---|
[f444b20] | 1324 | """ |
---|
| 1325 | send a list of data to plot |
---|
| 1326 | """ |
---|
[d7f727d] | 1327 | total_plot_list = [] |
---|
[e88ebfd] | 1328 | data_list, _ = self._data_manager.get_by_id(data_id) |
---|
[df22224] | 1329 | _, temp_list_theory = self._data_manager.get_by_id(theory_id) |
---|
[d7f727d] | 1330 | total_plot_list = data_list.values() |
---|
[df22224] | 1331 | for item in temp_list_theory.values(): |
---|
[e88ebfd] | 1332 | theory_data, theory_state = item |
---|
[d7f727d] | 1333 | total_plot_list.append(theory_data) |
---|
[e88ebfd] | 1334 | GROUP_ID = wx.NewId() |
---|
[d7f727d] | 1335 | for new_plot in total_plot_list: |
---|
[213892bc] | 1336 | if append: |
---|
[ee2b492] | 1337 | if self.panel_on_focus is None: |
---|
[213892bc] | 1338 | message = "cannot append plot. No plot panel on focus!" |
---|
| 1339 | message += "please click on any available plot to set focus" |
---|
| 1340 | wx.PostEvent(self, StatusEvent(status=message, |
---|
| 1341 | info='warning')) |
---|
| 1342 | return |
---|
| 1343 | else: |
---|
[e88ebfd] | 1344 | if self.enable_add_data(new_plot): |
---|
| 1345 | new_plot.group_id = self.panel_on_focus.group_id |
---|
| 1346 | else: |
---|
| 1347 | message = "Only 1D Data can be append to plot panel\n" |
---|
| 1348 | message += "%s will be plot separetly\n" %str(new_plot.name) |
---|
| 1349 | wx.PostEvent(self, StatusEvent(status=message, |
---|
| 1350 | info='warning')) |
---|
[4c0572f] | 1351 | else: |
---|
| 1352 | #if not append then new plot |
---|
[e88ebfd] | 1353 | new_plot.group_id = GROUP_ID |
---|
| 1354 | title = "PLOT " + str(new_plot.title) |
---|
[f444b20] | 1355 | wx.PostEvent(self, NewPlotEvent(plot=new_plot, |
---|
[e88ebfd] | 1356 | title=title)) |
---|
[f444b20] | 1357 | |
---|
[665c083] | 1358 | def remove_data(self, data_id, theory_id=None): |
---|
[213892bc] | 1359 | """ |
---|
| 1360 | Delete data state if data_id is provide |
---|
| 1361 | delete theory created with data of id data_id if theory_id is provide |
---|
| 1362 | if delete all true: delete the all state |
---|
| 1363 | else delete theory |
---|
| 1364 | """ |
---|
[6db811e] | 1365 | for plug in self.plugins: |
---|
| 1366 | plug.delete_data(data_id) |
---|
[3658717e] | 1367 | total_plot_list = [] |
---|
| 1368 | data_list, _ = self._data_manager.get_by_id(data_id) |
---|
| 1369 | _, temp_list_theory = self._data_manager.get_by_id(theory_id) |
---|
| 1370 | total_plot_list = data_list.values() |
---|
| 1371 | for item in temp_list_theory.values(): |
---|
| 1372 | theory_data, theory_state = item |
---|
| 1373 | total_plot_list.append(theory_data) |
---|
| 1374 | for new_plot in total_plot_list: |
---|
| 1375 | id = new_plot.id |
---|
| 1376 | for group_id in new_plot.list_group_id: |
---|
| 1377 | wx.PostEvent(self, NewPlotEvent(id=id, |
---|
| 1378 | group_id=group_id, |
---|
| 1379 | action='remove')) |
---|
| 1380 | self._data_manager.delete_data(data_id=data_id, |
---|
| 1381 | theory_id=theory_id) |
---|
[6db811e] | 1382 | |
---|
[213892bc] | 1383 | |
---|
[f444b20] | 1384 | def set_current_perspective(self, perspective): |
---|
| 1385 | """ |
---|
| 1386 | set the current active perspective |
---|
| 1387 | """ |
---|
| 1388 | self._current_perspective = perspective |
---|
[c5e84fb] | 1389 | name = "No current Application selected" |
---|
[cbf22e5] | 1390 | if self._current_perspective is not None: |
---|
| 1391 | self._add_current_plugin_menu() |
---|
[a45037aa] | 1392 | for panel in self.panels.values(): |
---|
| 1393 | if hasattr(panel, 'CENTER_PANE') and panel.CENTER_PANE: |
---|
| 1394 | for name in self._current_perspective.get_perspective(): |
---|
| 1395 | if name == panel.window_name: |
---|
| 1396 | panel.on_set_focus(event=None) |
---|
| 1397 | break |
---|
| 1398 | |
---|
[f036c692] | 1399 | name = self._current_perspective.sub_menu |
---|
[cbf22e5] | 1400 | if self._data_panel is not None: |
---|
| 1401 | self._data_panel.set_active_perspective(name) |
---|
[95f9cc4] | 1402 | self._check_applications_menu() |
---|
[568658b] | 1403 | |
---|
[95f9cc4] | 1404 | def _check_applications_menu(self): |
---|
| 1405 | """ |
---|
| 1406 | check the menu of the current application |
---|
| 1407 | """ |
---|
| 1408 | if self._applications_menu is not None: |
---|
| 1409 | for menu in self._applications_menu.GetMenuItems(): |
---|
| 1410 | if self._current_perspective is not None: |
---|
| 1411 | name = self._current_perspective.sub_menu |
---|
| 1412 | if menu.IsCheckable(): |
---|
| 1413 | if menu.GetLabel() == name: |
---|
| 1414 | menu.Check(True) |
---|
| 1415 | else: |
---|
| 1416 | menu.Check(False) |
---|
[c5e84fb] | 1417 | |
---|
[213892bc] | 1418 | def set_plotpanel_floating(self, event=None): |
---|
[7a67e075] | 1419 | """ |
---|
| 1420 | make the plot panel floatable |
---|
| 1421 | """ |
---|
[0663dfb1] | 1422 | self.__gui_style &= (~GUIFRAME.FIXED_PANEL) |
---|
[3feed3e] | 1423 | self.__gui_style |= GUIFRAME.FLOATING_PANEL |
---|
| 1424 | for p in self.panels.values(): |
---|
[ae83ad3] | 1425 | plot_panel = self._plotting_plugin.plot_panels.values() |
---|
[3feed3e] | 1426 | for p in self.panels.values(): |
---|
| 1427 | if p in plot_panel: |
---|
| 1428 | self._popup_floating_panel(p) |
---|
| 1429 | |
---|
[213892bc] | 1430 | def set_plotpanel_fixed(self, event=None): |
---|
[7a67e075] | 1431 | """ |
---|
| 1432 | make the plot panel fixed |
---|
| 1433 | """ |
---|
[0663dfb1] | 1434 | self.__gui_style &= (~GUIFRAME.FLOATING_PANEL) |
---|
[3feed3e] | 1435 | self.__gui_style |= GUIFRAME.FIXED_PANEL |
---|
| 1436 | plot_panel = [] |
---|
| 1437 | if self._plotting_plugin is not None: |
---|
[ae83ad3] | 1438 | plot_panel = self._plotting_plugin.plot_panels.values() |
---|
[3feed3e] | 1439 | for p in self.panels.values(): |
---|
| 1440 | if p in plot_panel: |
---|
| 1441 | self._popup_fixed_panel(p) |
---|
| 1442 | |
---|
| 1443 | def _popup_fixed_panel(self, p): |
---|
| 1444 | """ |
---|
| 1445 | """ |
---|
| 1446 | style = self.__gui_style & GUIFRAME.FIXED_PANEL |
---|
| 1447 | if style == GUIFRAME.FIXED_PANEL: |
---|
| 1448 | self._mgr.GetPane(p.window_name).Floatable() |
---|
| 1449 | self._mgr.GetPane(p.window_name).Right() |
---|
| 1450 | self._mgr.GetPane(p.window_name).TopDockable(False) |
---|
| 1451 | self._mgr.GetPane(p.window_name).BottomDockable(False) |
---|
| 1452 | self._mgr.GetPane(p.window_name).LeftDockable(False) |
---|
| 1453 | self._mgr.GetPane(p.window_name).RightDockable(True) |
---|
| 1454 | flag = self._mgr.GetPane(p.window_name).IsShown() |
---|
| 1455 | self._mgr.GetPane(p.window_name).Show(flag) |
---|
| 1456 | self._mgr.Update() |
---|
| 1457 | |
---|
| 1458 | def _popup_floating_panel(self, p): |
---|
| 1459 | """ |
---|
| 1460 | """ |
---|
| 1461 | style = self.__gui_style & GUIFRAME.FLOATING_PANEL |
---|
| 1462 | if style == GUIFRAME.FLOATING_PANEL: |
---|
| 1463 | self._mgr.GetPane(p.window_name).Floatable(True) |
---|
| 1464 | self._mgr.GetPane(p.window_name).Float() |
---|
| 1465 | self._mgr.GetPane(p.window_name).Dockable(False) |
---|
| 1466 | flag = self._mgr.GetPane(p.window_name).IsShown() |
---|
| 1467 | self._mgr.GetPane(p.window_name).Show(flag) |
---|
| 1468 | self._mgr.Update() |
---|
[213892bc] | 1469 | |
---|
| 1470 | def enable_add_data(self, new_plot): |
---|
| 1471 | """ |
---|
| 1472 | Enable append data on a plot panel |
---|
| 1473 | """ |
---|
[ee2b492] | 1474 | if self.panel_on_focus not in self._plotting_plugin.plot_panels.values(): |
---|
| 1475 | return |
---|
[213892bc] | 1476 | is_theory = len(self.panel_on_focus.plots) <= 1 and \ |
---|
| 1477 | self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D" |
---|
| 1478 | |
---|
| 1479 | is_data2d = hasattr(new_plot, 'data') |
---|
| 1480 | is_data1d = self.panel_on_focus.__class__.__name__ == "ModelPanel1D"\ |
---|
| 1481 | and self.panel_on_focus.group_id is not None |
---|
| 1482 | has_meta_data = hasattr(new_plot, 'meta_data') |
---|
| 1483 | |
---|
| 1484 | #disable_add_data if the data is being recovered from a saved state file. |
---|
| 1485 | is_state_data = False |
---|
| 1486 | if has_meta_data: |
---|
| 1487 | if 'invstate' in new_plot.meta_data: is_state_data = True |
---|
| 1488 | if 'prstate' in new_plot.meta_data: is_state_data = True |
---|
| 1489 | if 'fitstate' in new_plot.meta_data: is_state_data = True |
---|
| 1490 | |
---|
| 1491 | return is_data1d and not is_data2d and not is_theory and not is_state_data |
---|
[d828481] | 1492 | |
---|
[f036c692] | 1493 | def enable_edit_menu(self): |
---|
| 1494 | """ |
---|
| 1495 | enable menu item under edit menu depending on the panel on focus |
---|
| 1496 | """ |
---|
| 1497 | if self.panel_on_focus is not None and self._edit_menu is not None: |
---|
[a45037aa] | 1498 | flag = self.panel_on_focus.get_undo_flag() |
---|
[f036c692] | 1499 | self._edit_menu.Enable(GUIFRAME_ID.UNDO_ID, flag) |
---|
[a45037aa] | 1500 | flag = self.panel_on_focus.get_redo_flag() |
---|
[f036c692] | 1501 | self._edit_menu.Enable(GUIFRAME_ID.REDO_ID, flag) |
---|
[a45037aa] | 1502 | flag = self.panel_on_focus.get_print_flag() |
---|
[f036c692] | 1503 | self._edit_menu.Enable(GUIFRAME_ID.PRINT_ID, flag) |
---|
[a45037aa] | 1504 | flag = self.panel_on_focus.get_preview_flag() |
---|
[f036c692] | 1505 | self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) |
---|
[a45037aa] | 1506 | flag = self.panel_on_focus.get_reset_flag() |
---|
[f036c692] | 1507 | self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) |
---|
| 1508 | else: |
---|
| 1509 | flag = False |
---|
| 1510 | self._edit_menu.Enable(GUIFRAME_ID.UNDO_ID, flag) |
---|
| 1511 | self._edit_menu.Enable(GUIFRAME_ID.REDO_ID, flag) |
---|
| 1512 | self._edit_menu.Enable(GUIFRAME_ID.PRINT_ID, flag) |
---|
| 1513 | self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) |
---|
| 1514 | self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) |
---|
| 1515 | |
---|
[d828481] | 1516 | def on_undo_panel(self, event=None): |
---|
| 1517 | """ |
---|
| 1518 | undo previous action of the last panel on focus if possible |
---|
| 1519 | """ |
---|
[f036c692] | 1520 | if self.panel_on_focus is not None: |
---|
| 1521 | self.panel_on_focus.on_undo(event) |
---|
| 1522 | |
---|
[d828481] | 1523 | def on_redo_panel(self, event=None): |
---|
| 1524 | """ |
---|
| 1525 | redo the last cancel action done on the last panel on focus |
---|
| 1526 | """ |
---|
[f036c692] | 1527 | if self.panel_on_focus is not None: |
---|
| 1528 | self.panel_on_focus.on_redo(event) |
---|
| 1529 | |
---|
[d828481] | 1530 | def on_bookmark_panel(self, event=None): |
---|
| 1531 | """ |
---|
[4e4d3bb] | 1532 | bookmark panel |
---|
[d828481] | 1533 | """ |
---|
[f036c692] | 1534 | if self.panel_on_focus is not None: |
---|
| 1535 | self.panel_on_focus.on_bookmark(event) |
---|
| 1536 | |
---|
[4e4d3bb] | 1537 | def append_bookmark(self, event=None): |
---|
| 1538 | """ |
---|
| 1539 | Bookmark available information of the panel on focus |
---|
| 1540 | """ |
---|
| 1541 | self._toolbar.append_bookmark(event) |
---|
| 1542 | |
---|
[d828481] | 1543 | def on_save_panel(self, event=None): |
---|
| 1544 | """ |
---|
| 1545 | save possible information on the current panel |
---|
| 1546 | """ |
---|
[f036c692] | 1547 | if self.panel_on_focus is not None: |
---|
| 1548 | self.panel_on_focus.on_save(event) |
---|
| 1549 | |
---|
[d828481] | 1550 | def on_preview_panel(self, event=None): |
---|
| 1551 | """ |
---|
| 1552 | preview information on the panel on focus |
---|
| 1553 | """ |
---|
[f036c692] | 1554 | if self.panel_on_focus is not None: |
---|
| 1555 | self.panel_on_focus.on_preview(event) |
---|
| 1556 | |
---|
[d828481] | 1557 | def on_print_panel(self, event=None): |
---|
| 1558 | """ |
---|
| 1559 | print available information on the last panel on focus |
---|
| 1560 | """ |
---|
[f036c692] | 1561 | if self.panel_on_focus is not None: |
---|
| 1562 | self.panel_on_focus.on_print(event) |
---|
| 1563 | |
---|
[d828481] | 1564 | def on_zoom_panel(self, event=None): |
---|
| 1565 | """ |
---|
| 1566 | zoom on the current panel if possible |
---|
| 1567 | """ |
---|
[f036c692] | 1568 | if self.panel_on_focus is not None: |
---|
| 1569 | self.panel_on_focus.on_zoom(event) |
---|
| 1570 | |
---|
[d828481] | 1571 | def on_zoom_in_panel(self, event=None): |
---|
| 1572 | """ |
---|
| 1573 | zoom in of the panel on focus |
---|
| 1574 | """ |
---|
[f036c692] | 1575 | if self.panel_on_focus is not None: |
---|
| 1576 | self.panel_on_focus.on_zoom_in(event) |
---|
| 1577 | |
---|
[d828481] | 1578 | def on_zoom_out_panel(self, event=None): |
---|
| 1579 | """ |
---|
| 1580 | zoom out on the panel on focus |
---|
| 1581 | """ |
---|
[f036c692] | 1582 | if self.panel_on_focus is not None: |
---|
| 1583 | self.panel_on_focus.on_zoom_out(event) |
---|
| 1584 | |
---|
[d828481] | 1585 | def on_drag_panel(self, event=None): |
---|
| 1586 | """ |
---|
| 1587 | drag apply to the panel on focus |
---|
| 1588 | """ |
---|
[f036c692] | 1589 | if self.panel_on_focus is not None: |
---|
| 1590 | self.panel_on_focus.on_drag(event) |
---|
| 1591 | |
---|
[d828481] | 1592 | def on_reset_panel(self, event=None): |
---|
| 1593 | """ |
---|
| 1594 | reset the current panel |
---|
| 1595 | """ |
---|
[f036c692] | 1596 | if self.panel_on_focus is not None: |
---|
| 1597 | self.panel_on_focus.on_reset(event) |
---|
[03314e7] | 1598 | |
---|
| 1599 | def enable_undo(self): |
---|
| 1600 | """ |
---|
| 1601 | enable undo related control |
---|
| 1602 | """ |
---|
| 1603 | if self.panel_on_focus is not None: |
---|
| 1604 | self._toolbar.enable_undo(self.panel_on_focus) |
---|
| 1605 | |
---|
| 1606 | def enable_redo(self): |
---|
| 1607 | """ |
---|
| 1608 | enable redo |
---|
| 1609 | """ |
---|
| 1610 | if self.panel_on_focus is not None: |
---|
| 1611 | self._toolbar.enable_redo(self.panel_on_focus) |
---|
| 1612 | |
---|
| 1613 | def enable_bookmark(self): |
---|
| 1614 | """ |
---|
| 1615 | Bookmark |
---|
| 1616 | """ |
---|
| 1617 | if self.panel_on_focus is not None: |
---|
| 1618 | self._toolbar.enable_bookmark(self.panel_on_focus) |
---|
| 1619 | |
---|
| 1620 | def enable_save(self): |
---|
| 1621 | """ |
---|
| 1622 | save |
---|
| 1623 | """ |
---|
| 1624 | if self.panel_on_focus is not None: |
---|
| 1625 | self._toolbar.enable_save(self.panel_on_focus) |
---|
| 1626 | |
---|
| 1627 | def enable_preview(self): |
---|
| 1628 | """ |
---|
| 1629 | preview |
---|
| 1630 | """ |
---|
| 1631 | if self.panel_on_focus is not None: |
---|
| 1632 | self._toolbar.enable_preview(self.panel_on_focus) |
---|
| 1633 | |
---|
| 1634 | def enable_print(self): |
---|
| 1635 | """ |
---|
| 1636 | print |
---|
| 1637 | """ |
---|
| 1638 | if self.panel_on_focus is not None: |
---|
| 1639 | self._toolbar.enable_print(self.panel_on_focus) |
---|
| 1640 | |
---|
| 1641 | def enable_zoom(self): |
---|
| 1642 | """ |
---|
| 1643 | zoom |
---|
| 1644 | """ |
---|
| 1645 | if self.panel_on_focus is not None: |
---|
| 1646 | self._toolbar.enable_zoom(self.panel_on_focus) |
---|
| 1647 | |
---|
| 1648 | def enable_zoom_in(self): |
---|
| 1649 | """ |
---|
| 1650 | zoom in |
---|
| 1651 | """ |
---|
| 1652 | if self.panel_on_focus is not None: |
---|
| 1653 | self._toolbar.enable_zoom_in(self.panel_on_focus) |
---|
| 1654 | |
---|
| 1655 | def enable_zoom_out(self): |
---|
| 1656 | """ |
---|
| 1657 | zoom out |
---|
| 1658 | """ |
---|
| 1659 | if self.panel_on_focus is not None: |
---|
| 1660 | self._toolbar.enable_zoom_out(self.panel_on_focus) |
---|
| 1661 | |
---|
| 1662 | def enable_drag(self, event=None): |
---|
| 1663 | """ |
---|
| 1664 | drag |
---|
| 1665 | """ |
---|
| 1666 | if self.panel_on_focus is not None: |
---|
| 1667 | self._toolbar.enable_drag(self.panel_on_focus) |
---|
| 1668 | |
---|
| 1669 | def enable_reset(self): |
---|
| 1670 | """ |
---|
| 1671 | reset the current panel |
---|
| 1672 | """ |
---|
| 1673 | if self.panel_on_focus is not None: |
---|
| 1674 | self._toolbar.enable_reset(self.panel_on_focus) |
---|
[3feed3e] | 1675 | |
---|
[d828481] | 1676 | class DefaultPanel(wx.Panel, PanelBase): |
---|
[41d466f] | 1677 | """ |
---|
[d955bf19] | 1678 | Defines the API for a panels to work with |
---|
| 1679 | the GUI manager |
---|
[41d466f] | 1680 | """ |
---|
| 1681 | ## Internal nickname for the window, used by the AUI manager |
---|
| 1682 | window_name = "default" |
---|
| 1683 | ## Name to appear on the window title bar |
---|
| 1684 | window_caption = "Welcome panel" |
---|
| 1685 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
| 1686 | CENTER_PANE = True |
---|
[1b3a5a9] | 1687 | def __init__(self, parent, *args, **kwds): |
---|
| 1688 | wx.Panel.__init__(self, parent, *args, **kwds) |
---|
| 1689 | PanelBase.__init__(self, parent) |
---|
[d828481] | 1690 | |
---|
[41d466f] | 1691 | |
---|
[4753fc2] | 1692 | |
---|
[41d466f] | 1693 | # Toy application to test this Frame |
---|
| 1694 | class ViewApp(wx.App): |
---|
[d955bf19] | 1695 | """ |
---|
| 1696 | """ |
---|
[3385795] | 1697 | SIZE = (GUIFRAME_WIDTH,GUIFRAME_HEIGHT) |
---|
| 1698 | TITLE = config.__appname__ |
---|
| 1699 | PROG_SPLASH_PATH = PROG_SPLASH_SCREEN |
---|
[d828481] | 1700 | STYLE = GUIFRAME.SINGLE_APPLICATION |
---|
[783940c] | 1701 | SPLASH_WIDTH = 500 |
---|
| 1702 | SPLASH_HEIGHT = 300 |
---|
| 1703 | SPLASH_MAX_DISPLAY_TIME = 3000 #3 sec |
---|
| 1704 | |
---|
[41d466f] | 1705 | def OnInit(self): |
---|
[d955bf19] | 1706 | """ |
---|
| 1707 | """ |
---|
[3385795] | 1708 | pos, size = self.window_placement(self.SIZE) |
---|
| 1709 | self.frame = ViewerFrame(parent=None, |
---|
| 1710 | title=self.TITLE, |
---|
| 1711 | pos=pos, |
---|
| 1712 | gui_style = self.STYLE, |
---|
| 1713 | size=size) |
---|
| 1714 | # Display a splash screen on top of the frame. |
---|
| 1715 | if len(sys.argv) > 1 and '--time' in sys.argv[1:]: |
---|
| 1716 | log_time("Starting to display the splash screen") |
---|
| 1717 | if self.PROG_SPLASH_PATH is not None and \ |
---|
| 1718 | os.path.isfile(self.PROG_SPLASH_PATH): |
---|
| 1719 | try: |
---|
[783940c] | 1720 | s_screen = self.display_splash_screen(parent=self.frame, path=self.PROG_SPLASH_PATH) |
---|
[3385795] | 1721 | except: |
---|
[783940c] | 1722 | try: |
---|
| 1723 | self.frame.Show() |
---|
| 1724 | except: |
---|
| 1725 | |
---|
| 1726 | msg = "Cannot display splash screen\n" |
---|
| 1727 | msg += str (sys.exc_value) |
---|
| 1728 | #raise |
---|
| 1729 | logging.error(msg) |
---|
| 1730 | else: |
---|
| 1731 | self.frame.Show() |
---|
| 1732 | |
---|
[41d466f] | 1733 | |
---|
| 1734 | if hasattr(self.frame, 'special'): |
---|
| 1735 | self.frame.special.SetCurrent() |
---|
| 1736 | self.SetTopWindow(self.frame) |
---|
[783940c] | 1737 | import time |
---|
| 1738 | |
---|
[41d466f] | 1739 | return True |
---|
| 1740 | |
---|
| 1741 | def set_manager(self, manager): |
---|
| 1742 | """ |
---|
[d955bf19] | 1743 | Sets a reference to the application manager |
---|
| 1744 | of the GUI manager (Frame) |
---|
[41d466f] | 1745 | """ |
---|
| 1746 | self.frame.set_manager(manager) |
---|
| 1747 | |
---|
[278cc25] | 1748 | def build_gui(self): |
---|
| 1749 | """ |
---|
[d955bf19] | 1750 | Build the GUI |
---|
[278cc25] | 1751 | """ |
---|
| 1752 | self.frame.build_gui() |
---|
| 1753 | self.frame.post_init() |
---|
| 1754 | |
---|
[f9e803e] | 1755 | def set_welcome_panel(self, panel_class): |
---|
| 1756 | """ |
---|
[d955bf19] | 1757 | Set the welcome panel |
---|
| 1758 | |
---|
| 1759 | :param panel_class: class of the welcome panel to be instantiated |
---|
| 1760 | |
---|
[f9e803e] | 1761 | """ |
---|
| 1762 | self.frame.set_welcome_panel(panel_class) |
---|
| 1763 | |
---|
[278cc25] | 1764 | def add_perspective(self, perspective): |
---|
| 1765 | """ |
---|
[d955bf19] | 1766 | Manually add a perspective to the application GUI |
---|
[278cc25] | 1767 | """ |
---|
| 1768 | self.frame.add_perspective(perspective) |
---|
[3385795] | 1769 | |
---|
| 1770 | def window_placement(self, size): |
---|
| 1771 | """ |
---|
| 1772 | Determines the position and size of the application frame such that it |
---|
| 1773 | fits on the user's screen without obstructing (or being obstructed by) |
---|
| 1774 | the Windows task bar. The maximum initial size in pixels is bounded by |
---|
| 1775 | WIDTH x HEIGHT. For most monitors, the application |
---|
| 1776 | will be centered on the screen; for very large monitors it will be |
---|
| 1777 | placed on the left side of the screen. |
---|
| 1778 | """ |
---|
| 1779 | window_width, window_height = size |
---|
| 1780 | screen_size = wx.GetDisplaySize() |
---|
| 1781 | window_height = window_height if screen_size[1]>window_height else screen_size[1]-50 |
---|
| 1782 | window_width = window_width if screen_size[0]> window_width else screen_size[0]-50 |
---|
| 1783 | xpos = ypos = 0 |
---|
| 1784 | |
---|
| 1785 | # Note that when running Linux and using an Xming (X11) server on a PC |
---|
| 1786 | # with a dual monitor configuration, the reported display size may be |
---|
| 1787 | # that of both monitors combined with an incorrect display count of 1. |
---|
| 1788 | # To avoid displaying this app across both monitors, we check for |
---|
| 1789 | # screen 'too big'. If so, we assume a smaller width which means the |
---|
| 1790 | # application will be placed towards the left hand side of the screen. |
---|
| 1791 | |
---|
| 1792 | _, _, x, y = wx.Display().GetClientArea() # size excludes task bar |
---|
| 1793 | if len(sys.argv) > 1 and '--platform' in sys.argv[1:]: |
---|
| 1794 | w, h = wx.DisplaySize() # size includes task bar area |
---|
| 1795 | if x > 1920: x = 1280 # display on left side, not centered on screen |
---|
| 1796 | if x > window_width: xpos = (x - window_width)/2 |
---|
| 1797 | if y > window_height: ypos = (y - window_height)/2 |
---|
| 1798 | |
---|
| 1799 | # Return the suggested position and size for the application frame. |
---|
| 1800 | return (xpos, ypos), (min(x, window_width), min(y, window_height)) |
---|
| 1801 | |
---|
[783940c] | 1802 | def display_splash_screen(self, parent, |
---|
| 1803 | path=PROG_SPLASH_SCREEN): |
---|
[3385795] | 1804 | """Displays the splash screen. It will exactly cover the main frame.""" |
---|
| 1805 | |
---|
| 1806 | # Prepare the picture. On a 2GHz intel cpu, this takes about a second. |
---|
| 1807 | x, y = parent.GetSizeTuple() |
---|
| 1808 | image = wx.Image(path, wx.BITMAP_TYPE_PNG) |
---|
[783940c] | 1809 | image.Rescale(self.SPLASH_WIDTH, self.SPLASH_HEIGHT, wx.IMAGE_QUALITY_HIGH) |
---|
[3385795] | 1810 | bm = image.ConvertToBitmap() |
---|
| 1811 | |
---|
| 1812 | # Create and show the splash screen. It will disappear only when the |
---|
| 1813 | # program has entered the event loop AND either the timeout has expired |
---|
| 1814 | # or the user has left clicked on the screen. Thus any processing |
---|
| 1815 | # performed in this routine (including sleeping) or processing in the |
---|
| 1816 | # calling routine (including doing imports) will prevent the splash |
---|
| 1817 | # screen from disappearing. |
---|
| 1818 | # |
---|
| 1819 | # Note that on Linux, the timeout appears to occur immediately in which |
---|
| 1820 | # case the splash screen disappears upon entering the event loop. |
---|
[783940c] | 1821 | s_screen = wx.SplashScreen(bitmap=bm, |
---|
| 1822 | splashStyle=(wx.SPLASH_TIMEOUT| |
---|
| 1823 | wx.SPLASH_CENTRE_ON_SCREEN), |
---|
| 1824 | style=(wx.SIMPLE_BORDER| |
---|
| 1825 | wx.FRAME_NO_TASKBAR| |
---|
| 1826 | wx.STAY_ON_TOP), |
---|
| 1827 | |
---|
| 1828 | milliseconds=self.SPLASH_MAX_DISPLAY_TIME, |
---|
[3385795] | 1829 | parent=parent, |
---|
| 1830 | id=wx.ID_ANY) |
---|
| 1831 | |
---|
[783940c] | 1832 | s_screen.Bind(wx.EVT_CLOSE, self.on_close_splash_screen) |
---|
| 1833 | s_screen.Show() |
---|
| 1834 | return s_screen |
---|
| 1835 | |
---|
| 1836 | |
---|
| 1837 | def on_close_splash_screen(self, event): |
---|
| 1838 | """ |
---|
| 1839 | """ |
---|
| 1840 | self.frame.Show(True) |
---|
| 1841 | event.Skip() |
---|
| 1842 | |
---|
| 1843 | |
---|
[3385795] | 1844 | |
---|
[278cc25] | 1845 | |
---|
[41d466f] | 1846 | |
---|
| 1847 | if __name__ == "__main__": |
---|
| 1848 | app = ViewApp(0) |
---|
[32c0841] | 1849 | app.MainLoop() |
---|
| 1850 | |
---|
| 1851 | |
---|