Changeset d68c655 in sasview
- Timestamp:
- Jan 18, 2010 11:57:10 AM (15 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:
- e6b9723
- Parents:
- 52070a1
- Location:
- guiframe
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/dummyapp.py
r7bb61da rd68c655 4 4 """ 5 5 import gui_manager 6 7 class TestPlugin(gui_manager.Plugin): 8 9 def populate_menu(self, id, parent): 10 """ 11 Create and return the list of application menu 12 items for the plug-in. 13 14 @param id: deprecated. Un-used. 15 @param parent: parent window 16 @return: plug-in menu 17 """ 18 import wx 19 # Create a menu 20 plug_menu = wx.Menu() 21 22 # Always get event IDs from wx 23 id = wx.NewId() 24 25 # Fill your menu 26 plug_menu.Append(id, '&Do something') 27 def _on_do_something(event): 28 print "Do something" 29 wx.EVT_MENU(self.parent, id, _on_do_something) 30 31 # Returns the menu and a name for it. 32 return [(id, plug_menu, "DummyApp")] 33 34 def get_panels(self, parent): 35 """ 36 Create and return the list of wx.Panels for your plug-in. 37 Define the plug-in perspective. 38 39 Panels should inherit from DefaultPanel defined below, 40 or should present the same interface. They must define 41 "window_caption" and "window_name". 42 43 @param parent: parent window 44 @return: list of panels 45 """ 46 ## Save a reference to the parent 47 self.parent = parent 48 49 # Define a panel 50 defaultpanel = gui_manager.DefaultPanel(self.parent, -1) 51 defaultpanel.window_name = "Test" 52 53 # If needed, add its name to the perspective list 54 self.perspective = [defaultpanel.window_name] 55 56 # Return the list of panels 57 return [defaultpanel] 58 59 def get_tools(self): 60 """ 61 Returns a set of menu entries for tools 62 """ 63 def _test_dialog(event): 64 import wx 65 frame = wx.Dialog(None, -1, 'Test Tool') 66 frame.Show(True) 67 return [["Tool 1", "This is an example tool", _test_dialog], 68 ["Tool 2", "This is another example tool", _test_dialog]] 69 70 def get_context_menu(self, graph=None): 71 """ 72 This method is optional. 73 74 When the context menu of a plot is rendered, the 75 get_context_menu method will be called to give you a 76 chance to add a menu item to the context menu. 77 78 A ref to a Graph object is passed so that you can 79 investigate the plot content and decide whether you 80 need to add items to the context menu. 81 82 This method returns a list of menu items. 83 Each item is itself a list defining the text to 84 appear in the menu, a tool-tip help text, and a 85 call-back method. 86 87 @param graph: the Graph object to which we attach the context menu 88 @return: a list of menu items with call-back function 89 """ 90 return [["Menu text", 91 "Tool-tip help text", 92 self._on_context_do_something]] 6 93 7 94 class SansView(): … … 11 98 Initialization 12 99 """ 13 from gui_manager import ViewApp 14 self.gui = ViewApp(0) 100 self.gui = gui_manager.ViewApp(0) 101 102 fitting_plug = TestPlugin() 103 self.gui.add_perspective(fitting_plug) 15 104 16 105 # Build the GUI -
guiframe/gui_manager.py
r52070a1 rd68c655 17 17 18 18 """ 19 #TODO: rewrite the status bar monstrosity 20 19 21 import wx 20 22 import wx.aui … … 60 62 class for the Foo plug-in. The interface of that Plugin class 61 63 should follow the interface of the class you are looking at. 64 65 See dummyapp.py for a plugin example. 62 66 """ 63 67 64 def __init__(self ):68 def __init__(self, name="Test_plugin"): 65 69 """ 66 70 Abstract class for gui_manager Plugins. 67 71 """ 68 72 ## Plug-in name. It will appear on the application menu. 69 self.sub_menu = "Plugin"73 self.sub_menu = name 70 74 71 75 ## Reference to the parent window. Filled by get_panels() below. … … 76 80 self.perspective = [] 77 81 78 raise RuntimeError, "gui_manager.Plugin is an abstract class"79 82 80 83 def populate_menu(self, id, parent): … … 87 90 @return: plug-in menu 88 91 """ 89 import wx 90 # Create a menu 91 plug_menu = wx.Menu() 92 93 # Always get event IDs from wx 94 id = wx.NewId() 95 96 # Fill your menu 97 plug_menu.Append(id, '&Do something') 98 wx.EVT_MENU(owner, id, self._on_do_something) 99 100 # Returns the menu and a name for it. 101 return [(id, plug_menu, "name of the application menu")] 102 92 return [] 103 93 104 94 def get_panels(self, parent): … … 117 107 self.parent = parent 118 108 119 # Define a panel120 defaultpanel = DefaultPanel(self.parent, -1)121 122 # If needed, add its name to the perspective list123 self.perspective.append(self.control_panel.window_name)124 125 109 # Return the list of panels 126 return [defaultpanel] 110 return [] 111 112 def get_tools(self): 113 """ 114 Returns a set of menu entries for tools 115 """ 116 return [] 117 127 118 128 119 def get_context_menu(self, graph=None): … … 146 137 @return: a list of menu items with call-back function 147 138 """ 148 return [["Menu text", 149 "Tool-tip help text", 150 self._on_context_do_something]] 139 return [] 151 140 152 141 def get_perspective(self): … … 293 282 """ 294 283 import imp 295 #print "Looking for plug-ins in %s" % dir296 # List of plug-in objects297 298 #path_exe = os.getcwd()299 #path_plugs = os.path.join(path_exe, dir)300 f = open("load.log",'w')301 f.write(os.getcwd()+'\n\n')302 #f.write(str(os.listdir(dir))+'\n')303 304 284 305 285 plugins = [] … … 320 300 try: 321 301 if toks[1]=='': 322 f.write("trying to import \n")323 302 mod_path = '.'.join([dir, name]) 324 f.write("mod_path= %s\n" % mod_path)325 303 module = __import__(mod_path, globals(), locals(), [name]) 326 f.write(str(module)+'\n')327 304 else: 328 305 (file, path, info) = imp.find_module(name, path) … … 331 308 try: 332 309 plugins.append(module.Plugin()) 333 print "Found plug-in: %s" % module.PLUGIN_ID310 logging.info("Found plug-in: %s" % module.PLUGIN_ID) 334 311 except: 335 312 config.printEVT("Error accessing PluginPanel in %s\n %s" % (name, sys.exc_value)) … … 337 314 except: 338 315 print sys.exc_value 339 f.write(str(sys.exc_value)+'\n')316 logging.error("ViewerFrame._find_plugins: %s" % sys.exc_value) 340 317 finally: 341 318 if not file==None: … … 344 321 # Should raise and catch at a higher level and display error on status bar 345 322 pass 346 f.write(str(plugins)+'\n')347 f.close()348 323 return plugins 349 324 … … 540 515 # Perspective 541 516 # Attach a menu item for each defined perspective. 542 # Only add the perspective menu if there are more than one perspect ves517 # Only add the perspective menu if there are more than one perspectives 543 518 n_perspectives = 0 544 519 for plug in self.plugins: … … 554 529 wx.EVT_MENU(self, id, plug.on_perspective) 555 530 menubar.Append(p_menu, '&Perspective') 531 532 # Tools menu 533 # Go through plug-ins and find tools to populate the tools menu 534 toolsmenu = None 535 for item in self.plugins: 536 if hasattr(item, "get_tools"): 537 for tool in item.get_tools(): 538 # Only create a menu if we have at least one tool 539 if toolsmenu is None: 540 toolsmenu = wx.Menu() 541 id = wx.NewId() 542 toolsmenu.Append(id, tool[0], tool[1]) 543 wx.EVT_MENU(self, id, tool[2]) 544 if toolsmenu is not None: 545 menubar.Append(toolsmenu, '&Tools') 556 546 557 547 # Help menu … … 693 683 a call-back method when the current version number has been obtained. 694 684 """ 695 import version 696 checker = version.VersionThread(config.__update_URL__, self._process_version, baggage=event==None) 697 checker.start() 685 if hasattr(config, "__update_URL__"): 686 import version 687 checker = version.VersionThread(config.__update_URL__, self._process_version, baggage=event==None) 688 checker.start() 698 689 699 690 def _process_version(self, version, standalone=True):
Note: See TracChangeset
for help on using the changeset viewer.