source: sasview/guiframe/dummyapp.py @ d520f1b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since d520f1b was d68c655, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

guiframe: added API to add Tools to a plugin.

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[41d466f]1"""
2    Dummy application.
3    Allows the user to set an external data manager
4"""
5import gui_manager
6
[d68c655]7class 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]]   
93
[41d466f]94class SansView():
95   
96    def __init__(self):
97        """
98            Initialization
99        """
[d68c655]100        self.gui = gui_manager.ViewApp(0)
101       
102        fitting_plug = TestPlugin()
103        self.gui.add_perspective(fitting_plug)
[41d466f]104       
[7bb61da]105        # Build the GUI
106        self.gui.build_gui()
107       
[41d466f]108        # Set the application manager for the GUI
109        self.gui.set_manager(self)
110       
111        # Start the main loop
112        self.gui.MainLoop() 
113
114if __name__ == "__main__": 
115    sansview = SansView()
Note: See TracBrowser for help on using the repository browser.