Changeset 52b8b74 in sasview
- Timestamp:
- Jan 25, 2011 9:45:50 PM (14 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 0912feab
- Parents:
- 5385a9e
- Location:
- guiframe
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/data_panel.py
r32c0841 r52b8b74 417 417 self.parent._onClose() 418 418 419 420 from sans.guiframe.dataFitting import Data1D 421 from DataLoader.loader import Loader 419 422 420 data_list = [('Data1', 'Data1D', '07/01/2010'), 421 ('Data2', 'Data2D', '07/03/2011'), 423 list = Loader().load('latex_smeared.xml') 424 data_list = [('Data1', list[0], '07/01/2010'), 425 ('Data2', list[1], '07/03/2011'), 422 426 ('Data3', 'Theory1D', '06/01/2010'), 423 427 ('Data4', 'Theory2D', '07/01/2010'), -
guiframe/gui_manager.py
r749eb8a r52b8b74 41 41 from sans.guiframe.events import StatusEvent 42 42 from sans.guiframe.events import NewPlotEvent 43 44 43 from sans.guiframe.gui_style import * 44 from sans.guiframe.events import NewLoadedDataEvent 45 45 STATE_FILE_EXT = ['.inv', '.fitv', '.prv'] 46 46 … … 55 55 56 56 def __init__(self, parent, id, title, 57 window_height=300, window_width=300): 57 window_height=300, window_width=300, 58 gui_style=GUIFRAME.SINGLE_APPLICATION): 58 59 """ 59 60 Initialize the Frame object … … 65 66 self._window_height = window_height 66 67 self._window_width = window_width 68 self.__gui_style = gui_style 67 69 68 70 # Logging info … … 87 89 #data manager 88 90 from data_manager import DataManager 89 self.data_manager = DataManager() 91 self._data_manager = DataManager() 92 self._data_panel = None 90 93 #add current perpsective 91 94 self._current_perspective = None 92 #file menu 93 self.file_menu = None 95 self._plotting_plugin = None 96 self._data_plugin = None 97 #Menu bar and item 98 self._menubar = None 99 self._file_menu = None 100 self._data_menu = None 101 self._window_menu = None 102 self._window_menu = None 103 self._help = None 94 104 95 105 ## Find plug-ins … … 97 107 self.plugins = [] 98 108 #add local plugin 99 100 from sans.guiframe.local_perspectives.plotting import plotting 101 from sans.guiframe.local_perspectives.data_loader import data_loader 102 self.plugins.append(plotting.Plugin()) 103 self.plugins.append(data_loader.Plugin()) 104 109 self.plugins += self._get_local_plugins() 105 110 self.plugins += self._find_plugins() 106 111 … … 154 159 self.SetStatusBar(self.sb) 155 160 # Add panel 156 self._mgr = wx.aui.AuiManager(self) 157 self._mgr.SetDockSizeConstraint(0.5, 0.5) 161 default_flag = wx.aui.AUI_MGR_DEFAULT| wx.aui.AUI_MGR_ALLOW_ACTIVE_PANE 162 self._mgr = wx.aui.AuiManager(self, flags=default_flag) 163 """ 164 if self.__gui_style in [GUIFRAME.MULTIPLE_APPLICATIONS]: 165 from data_panel import DataPanel 166 self._data_panel = DataPanel(self) 167 """ 158 168 # Load panels 159 169 self._load_panels() 160 170 self._mgr.Update() 161 171 172 def _layout(self, style): 173 """ 174 Layout the frame according to a style 175 """ 176 if self.__gui_style == GUIFRAME.SINGLE_APPLICATION: 177 #Divide the frame into 178 print "GUIFRAME.SINGLE_APPLICATION" 179 elif self.__gui_style == GUIFRAME.MULTIPLE_APPLICATIONS: 180 print 'GUIFRAME.MULTIPLE_APPLICATION' 181 elif self.__gui_style == GUIFRAME.FLOATING_PANEL: 182 print "GUIFRAME.FLOATING_PANEL" 183 162 184 def SetStatusText(self, *args, **kwds): 163 185 """ … … 192 214 self.plugins.append(plugin) 193 215 216 def _get_local_plugins(self): 217 """ 218 get plugins local to guiframe and others 219 """ 220 plugins = [] 221 #import guiframe local plugins 222 if self.__gui_style == GUIFRAME.DATALOADER_ON: 223 try: 224 from sans.guiframe.local_perspectives.data_loader import data_loader 225 self._data_plugin =data_loader.Plugin() 226 plugins.append(self._data_plugin) 227 except: 228 msg = "ViewerFrame._find_plugins:" 229 msg += "cannot import dataloader plugin.\n %s" % sys.exc_value 230 logging.error(msg) 231 elif self.__gui_style == GUIFRAME.PLOTTIN_ON: 232 try: 233 from sans.guiframe.local_perspectives.plotting import plotting 234 self._plotting_plugin = plotting.Plugin() 235 plugins.append(self._plotting_plugin) 236 except: 237 msg = "ViewerFrame._find_plugins:" 238 msg += "cannot import plotting plugin.\n %s" % sys.exc_value 239 elif self.__gui_style in [6, 7, 8]: 240 try: 241 from sans.guiframe.local_perspectives.data_loader import data_loader 242 self._data_plugin =data_loader.Plugin() 243 plugins.append(self._data_plugin) 244 from sans.guiframe.local_perspectives.plotting import plotting 245 self._plotting_plugin = plotting.Plugin() 246 plugins.append(self._plotting_plugin) 247 except: 248 msg = "ViewerFrame._get_local_plugins: %s" % sys.exc_value 249 logging.error(msg) 250 return plugins 251 194 252 def _find_plugins(self, dir="perspectives"): 195 253 """ … … 392 450 id = wx.NewId() 393 451 m_name, m_hint, m_handler = item 394 self. filemenu.Append(id, m_name, m_hint)452 self._filemenu.Append(id, m_name, m_hint) 395 453 wx.EVT_MENU(self, id, m_handler) 396 self. filemenu.AppendSeparator()454 self._filemenu.AppendSeparator() 397 455 398 456 def _setup_menus(self): … … 402 460 # Menu 403 461 self._menubar = wx.MenuBar() 404 # File menu 405 self.filemenu = wx.Menu() 406 407 # some menu of plugin to be seen under file menu 408 self._populate_file_menu() 409 id = wx.NewId() 410 self.filemenu.Append(id, '&Save state into File', 411 'Save project as a SansView (svs) file') 412 wx.EVT_MENU(self, id, self._on_save) 413 #self.filemenu.AppendSeparator() 414 415 id = wx.NewId() 416 self.filemenu.Append(id, '&Quit', 'Exit') 417 wx.EVT_MENU(self, id, self.Close) 418 419 # Add sub menus 420 self._menubar.Append(self.filemenu, '&File') 421 422 # Window menu 423 # Attach a menu item for each panel in our 424 # panel list that also appears in a plug-in. 425 426 # Only add the panel menu if there is only one perspective and 427 # it has more than two panels. 428 # Note: the first plug-in is always the plotting plug-in. 429 #The first application 430 # plug-in is always the second one in the list. 431 if len(self.plugins) == 2: 432 plug = self.plugins[1] 433 pers = plug.get_perspective() 462 self._add_menu_file() 463 self._add_menu_data() 464 self._add_menu_application() 465 self._add_menu_window() 434 466 435 if len(pers) > 1: 436 viewmenu = wx.Menu() 437 for item in self.panels: 438 if item == 'default': 439 continue 440 panel = self.panels[item] 441 if panel.window_name in pers: 442 viewmenu.Append(int(item), panel.window_caption, 443 "Show %s window" % panel.window_caption) 444 wx.EVT_MENU(self, int(item), self._on_view) 445 self._menubar.Append(viewmenu, '&Window') 446 447 # Perspective 448 # Attach a menu item for each defined perspective. 449 # Only add the perspective menu if there are more than one perspectives 450 n_perspectives = 0 451 for plug in self.plugins: 452 if len(plug.get_perspective()) > 0: 453 n_perspectives += 1 454 455 if n_perspectives > 1: 456 p_menu = wx.Menu() 457 for plug in self.plugins: 458 if len(plug.get_perspective()) > 0: 459 id = wx.NewId() 460 p_menu.Append(id, plug.sub_menu, 461 "Switch to %s perspective" % plug.sub_menu) 462 wx.EVT_MENU(self, id, plug.on_perspective) 463 self._menubar.Append(p_menu, '&Perspective') 467 468 464 469 465 470 # Tools menu … … 509 514 # Add available plug-in sub-menus. 510 515 for item in self.plugins: 511 if hasattr(item, "populate_menu"):516 if item != self._plotting_plugin: 512 517 for (self.next_id, menu, name) in \ 513 518 item.populate_menu(self.next_id, self): … … 517 522 self.SetMenuBar(self._menubar) 518 523 524 def _add_menu_window(self): 525 """ 526 add a menu window to the menu bar 527 Window menu 528 Attach a menu item for each panel in our 529 panel list that also appears in a plug-in. 530 531 Only add the panel menu if there is only one perspective and 532 it has more than two panels. 533 Note: the first plug-in is always the plotting plug-in. 534 The first application 535 #plug-in is always the second one in the list. 536 """ 537 self._window_menu = wx.Menu() 538 if self._plotting_plugin is not None: 539 for (self.next_id, menu, name) in \ 540 self._plotting_plugin.populate_menu(self.next_id, self): 541 self._window_menu.AppendSubMenu(menu, name) 542 self._window_menu.AppendSeparator() 543 self._menubar.Append(self._window_menu, '&Window') 544 if self.defaultPanel is not None : 545 id = wx.NewId() 546 self._window_menu.Append(id,'&Welcome', '') 547 548 wx.EVT_MENU(self, id, self.show_welcome_panel) 549 if self.__gui_style in [GUIFRAME.MANAGER_ON, 550 GUIFRAME.MULTIPLE_APPLICATIONS]: 551 id = wx.NewId() 552 self._window_menu.Append(id,'&Data Manager', '') 553 554 wx.EVT_MENU(self, id, self.show_data_panel) 555 556 """ 557 if len(self.plugins) == 2: 558 plug = self.plugins[1] 559 pers = plug.get_perspective() 560 561 if len(pers) > 1: 562 self._window_menu = wx.Menu() 563 for item in self.panels: 564 if item == 'default': 565 continue 566 panel = self.panels[item] 567 if panel.window_name in pers: 568 self._window_menu.Append(int(item), 569 panel.window_caption, 570 "Show %s window" % panel.window_caption) 571 wx.EVT_MENU(self, int(item), self._on_view) 572 self._menubar.Append(self._window_menu, '&Window') 573 """ 574 575 def _add_menu_application(self): 576 """ 577 578 # Attach a menu item for each defined perspective or application. 579 # Only add the perspective menu if there are more than one perspectives 580 add menu application 581 """ 582 if self.__gui_style in [GUIFRAME.MULTIPLE_APPLICATIONS]: 583 p_menu = wx.Menu() 584 for plug in self.plugins: 585 if len(plug.get_perspective()) > 0: 586 id = wx.NewId() 587 p_menu.Append(id, plug.sub_menu, 588 "Switch to application: %s" % plug.sub_menu) 589 wx.EVT_MENU(self, id, plug.on_perspective) 590 self._menubar.Append(p_menu, '&Applications') 591 592 def _add_menu_file(self): 593 """ 594 add menu file 595 """ 596 # File menu 597 self._filemenu = wx.Menu() 598 599 # some menu of plugin to be seen under file menu 600 self._populate_file_menu() 601 602 id = wx.NewId() 603 self._filemenu.Append(id, '&Save state into File', 604 'Save project as a SansView (svs) file') 605 wx.EVT_MENU(self, id, self._on_save) 606 #self.__filemenu.AppendSeparator() 607 608 id = wx.NewId() 609 self._filemenu.Append(id, '&Quit', 'Exit') 610 wx.EVT_MENU(self, id, self.Close) 611 612 # Add sub menus 613 self._menubar.Append(self._filemenu, '&File') 614 615 def _add_menu_data(self): 616 """ 617 Add menu item item data to menu bar 618 """ 619 # Add menu data 620 self._data_menu = wx.Menu() 621 #menu for data files 622 data_file_id = wx.NewId() 623 data_file_hint = "load one or more data in the application" 624 self._data_menu.Append(data_file_id, 625 '&Load Data File(s)', data_file_hint) 626 wx.EVT_MENU(self, data_file_id, self._load_data) 627 if self.__gui_style == GUIFRAME.SINGLE_APPLICATION: 628 self._menubar.Append(self._data_menu, '&Data') 629 return 630 else: 631 #menu for data from folder 632 data_folder_id = wx.NewId() 633 data_folder_hint = "load multiple data in the application" 634 self._data_menu.Append(data_folder_id, 635 '&Load Data Folder', data_folder_hint) 636 wx.EVT_MENU(self, data_folder_id, self._load_folder) 637 self._menubar.Append(self._data_menu, '&Data') 638 639 def _load_data(self, event): 640 """ 641 connect menu item load data with the first plugin that can load data 642 """ 643 for plug in self.plugins: 644 if plug.can_load_data(): 645 plug.load_data(event) 646 647 def _load_folder(self, event): 648 """ 649 connect menu item load data with the first plugin that can load data and 650 folder 651 """ 652 for plug in self.plugins: 653 if plug.can_load_data(): 654 plug.load_folder(event) 655 519 656 def _on_status_event(self, evt): 520 657 """ … … 832 969 return path 833 970 971 def show_data_panel(self, event): 972 """ 973 """ 974 def show_welcome_panel(self, event): 975 """ 976 show welcome panel 977 """ 978 834 979 def add_data(self, data_list): 835 980 """ … … 837 982 determine if data was be plot of send to data perspectives 838 983 """ 839 self.data_manager.add_data(data_list) 984 #send a list of available data to plotting plugin 985 avalaible_data = [] 986 if self._data_manager is not None: 987 self._data_manager.add_data(data_list) 988 avalaible_data = self._data_manager.get_all_data() 989 wx.PostEvent(self, NewLoadedDataEvent(data_to_add=avalaible_data, 990 data_to_remove = [])) 991 840 992 if AUTO_SET_DATA: 841 993 if self._current_perspective is not None: … … 853 1005 if AUTO_PLOT: 854 1006 self.plot_data(data_list) 855 1007 1008 1009 856 1010 def plot_data(self, data_list): 857 1011 """ -
guiframe/gui_style.py
rf444b20 r52b8b74 4 4 """ 5 5 6 LOADING = True 7 PLOTTING = True 8 DATAMANAGER = True 6 class GUIFRAME: 7 MANAGER_ON = 1 8 FLOATING_PANEL = 2 9 FIXED_PANEL = 3 10 PLOTTIN_ON = 4 11 DATALOADER_ON = 5 12 SINGLE_APPLICATION = 6 13 MULTIPLE_APPLICATIONS = 7 14 15 DEFAULT_STYLE = 8 9 16 17 if __name__ == "__main__": 18 19 print GUIFRAME.DEFAULT_STYLE 20 print GUIFRAME.FLOATING_PANEL 21 22 value = GUIFRAME.MANAGER_ON|GUIFRAME.DATALOADER_ON 23 print value 24 print value in [1,2] 25 print value in [5,2] 26 print value in [GUIFRAME.MANAGER_ON,GUIFRAME.DATALOADER_ON] -
guiframe/local_perspectives/data_loader/data_loader.py
rde48a1a r52b8b74 35 35 self.loader = Loader() 36 36 37 def populate_menu(self, id, owner):38 """39 Create a menu for the Data plug-in40 41 :param id: id to create a menu42 :param owner: owner of menu43 44 :return: list of information to populate the main menu45 46 """47 #Menu for data loader48 self.menu = wx.Menu()49 #menu for data files50 data_file_id = wx.NewId()51 data_file_hint = "load one or more data in the application"52 self.menu.Append(data_file_id,53 '&Load Data File(s)', data_file_hint)54 wx.EVT_MENU(owner, data_file_id, self._load_data)55 #menu for data from folder56 data_folder_id = wx.NewId()57 data_folder_hint = "load multiple data in the application"58 self.menu.Append(data_folder_id,59 '&Load Data Folder', data_folder_hint)60 wx.EVT_MENU(owner, data_folder_id, self._load_folder)61 #create menubar items62 return [(id, self.menu, "Data")]63 64 37 def populate_file_menu(self): 65 38 """ … … 69 42 70 43 hint_load_file = "Read state's files and load them into the application" 71 return [["Open State from File", hint_load_file, self. _load_file]]44 return [["Open State from File", hint_load_file, self.load_file]] 72 45 73 def _load_data(self, event):46 def load_data(self, event): 74 47 """ 75 48 Load data … … 81 54 self.get_data(file_list, flag=flag) 82 55 83 def _load_file(self, event): 56 def can_load_data(self): 57 """ 58 if return True, then call handler to laod data 59 """ 60 return True 61 62 def load_file(self, event): 84 63 """ 85 64 Load sansview defined files … … 91 70 self.get_data(file_list, flag=flag) 92 71 93 def _load_folder(self, event):72 def load_folder(self, event): 94 73 """ 95 74 Load entire folder … … 101 80 file_list = self.get_file_path(path) 102 81 self.get_data(file_list, flag=flag) 103 82 104 83 def get_wild_card(self, flag=True): 105 84 """ -
guiframe/local_perspectives/plotting/Plotter1D.py
rdf7046f r52b8b74 29 29 from sans.guiframe.events import RemoveDataEvent 30 30 from sans.guiframe.events import AddManyDataEvent 31 from sans.guiframe.events import EVT_NEW_LOADED_DATA 31 32 from sans.guiframe.utils import PanelMenu 32 33 from sans.guiframe.dataFitting import Data1D … … 64 65 ## Plottables 65 66 self.plots = {} 67 #context menu 68 self._slicerpop = None 69 self._menu_add_plot = None 70 self._available_data = [] 71 self._menu_add_ids = [] 66 72 ## save errors dy for each data plotted 67 73 self.err_dy = {} … … 80 86 self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 81 87 self.graph.render(self) 82 88 #bind with event to contrst context menu 89 self.parent.Bind(EVT_NEW_LOADED_DATA, self._add_new_plot) 90 91 def on_add_new_plot(self, event): 92 """ 93 """ 94 def _add_new_plot(self, event): 95 """ 96 Construct the context menu given available data 97 """ 98 self._available_data = event.data_to_add 99 100 def _fill_menu_add_plot(self): 101 """ 102 """ 103 if self._menu_add_plot is not None: 104 if self._available_data: 105 for id in self._menu_add_ids: 106 item = self._menu_add_plot.FindItemById(id) 107 if item is None: 108 for data in self._available_data: 109 new_id = wx.NewId() 110 hint = 'Add %s to this panel' % str(data.name) 111 self._menu_add_plot.Append(new_id, str(data.name), hint) 112 wx.EVT_MENU(self, id, self.on_add_new_plot) 113 self._menu_add_ids.append(new_id) 114 else: 115 if item.GetLabel() == 'No Loaded Data': 116 self._menu_add_plot.RemoveItem(item) 117 83 118 def set_data(self, list=None): 84 119 """ … … 205 240 206 241 """ 207 s licerpop = PanelMenu()208 s licerpop.set_plots(self.plots)209 s licerpop.set_graph(self.graph)242 self._slicerpop = PanelMenu() 243 self._slicerpop.set_plots(self.plots) 244 self._slicerpop.set_graph(self.graph) 210 245 # Various plot options 211 246 id = wx.NewId() 212 s licerpop.Append(id, '&Save image', 'Save image as PNG')247 self._slicerpop.Append(id, '&Save image', 'Save image as PNG') 213 248 wx.EVT_MENU(self, id, self.onSaveImage) 214 249 id = wx.NewId() 215 s licerpop.Append(id, '&Print image', 'Print image ')250 self._slicerpop.Append(id, '&Print image', 'Print image ') 216 251 wx.EVT_MENU(self, id, self.onPrint) 217 252 id = wx.NewId() 218 s licerpop.Append(id, '&Print Preview', 'image preview for print')253 self._slicerpop.Append(id, '&Print Preview', 'image preview for print') 219 254 wx.EVT_MENU(self, id, self.onPrinterPreview) 220 slicerpop.AppendSeparator() 255 #add plot 256 self._menu_add_plot = wx.Menu() 257 id = wx.NewId() 258 self._menu_add_plot.Append(id, '&No Loaded Data', 'Add new plot') 259 self._menu_add_plot.FindItemByPosition(0).Enable(False) 260 self._menu_add_ids.append(id) 261 262 self._slicerpop.AppendSubMenu(self._menu_add_plot, '&Add New Plot') 263 self._fill_menu_add_plot() 264 self._slicerpop.AppendSeparator() 265 #add menu of other plugins 221 266 item_list = self.parent.get_context_menu(self.graph) 222 267 if (not item_list == None) and (not len(item_list) == 0): … … 224 269 try: 225 270 id = wx.NewId() 226 s licerpop.Append(id, item[0], item[1])271 self._slicerpop.Append(id, item[0], item[1]) 227 272 wx.EVT_MENU(self, id, item[2]) 228 273 except: … … 231 276 wx.PostEvent(self.parent, StatusEvent(status=msg)) 232 277 pass 233 slicerpop.AppendSeparator() 234 278 self._slicerpop.AppendSeparator() 279 id = wx.NewId() 280 self._menu_add_plot = wx.Menu() 281 self._slicerpop.Append(id, '&Print image', 'Print image') 235 282 if self.graph.selected_plottable in self.plots: 236 283 plot = self.plots[self.graph.selected_plottable] 237 284 id = wx.NewId() 238 285 name = plot.name 239 s licerpop.Append(id, "&Save points")286 self._slicerpop.Append(id, "&Save points") 240 287 self.action_ids[str(id)] = plot 241 288 wx.EVT_MENU(self, id, self._onSave) 242 289 id = wx.NewId() 243 s licerpop.Append(id, "Remove %s curve" % name)290 self._slicerpop.Append(id, "Remove %s curve" % name) 244 291 self.action_ids[str(id)] = plot 245 292 wx.EVT_MENU(self, id, self._onRemove) 246 s licerpop.AppendSeparator()293 self._slicerpop.AppendSeparator() 247 294 # Option to hide 248 295 #TODO: implement functionality to hide a plottable (legend click) … … 250 297 selected_plot = self.plots[self.graph.selected_plottable] 251 298 id = wx.NewId() 252 s licerpop.Append(id, '&Linear fit')299 self._slicerpop.Append(id, '&Linear fit') 253 300 wx.EVT_MENU(self, id, self.onFitting) 254 s licerpop.AppendSeparator()255 id = wx.NewId() 256 s licerpop.Append(id, '&Change scale')301 self._slicerpop.AppendSeparator() 302 id = wx.NewId() 303 self._slicerpop.Append(id, '&Change scale') 257 304 wx.EVT_MENU(self, id, self._onProperties) 258 305 id = wx.NewId() 259 s licerpop.Append(id, '&Reset Graph')306 self._slicerpop.Append(id, '&Reset Graph') 260 307 wx.EVT_MENU(self, id, self.onResetGraph) 261 308 pos = event.GetPosition() 262 309 pos = self.ScreenToClient(pos) 263 self.PopupMenu(s licerpop, pos)310 self.PopupMenu(self._slicerpop, pos) 264 311 265 312 def _on_remove_errors(self, evt): -
guiframe/plugin_base.py
rf444b20 r52b8b74 46 46 self.perspective = [] 47 47 48 def can_load_data(self): 49 """ 50 if return True, then call handler to laod data 51 """ 52 return False 53 54 def use_data(self): 55 """ 56 return True if these plugin use data 57 """ 58 return True 59 60 def load_data(self, event): 61 """ 62 Load data 63 """ 64 raise NotImplemented 65 66 def load_folder(self, event): 67 """ 68 Load entire folder 69 """ 70 raise NotImplemented 71 48 72 def set_is_active(self, active=False): 49 73 """
Note: See TracChangeset
for help on using the changeset viewer.