source: sasview/src/sas/sasgui/guiframe/dummyapp.py @ c812d11

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 c812d11 was b080ba8, checked in by smk78, 9 years ago

Changed ViewApp? to SasViewApp? to fix Sphinx doc build errors.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1"""
2Dummy application.
3Allows the user to set an external data manager
4"""
5import sas.sasgui.guiframe.gui_manager as gui_manager
6
7from sas.sasgui.guiframe.plugin_base import PluginBase
8
9class DummyView(gui_manager.SasViewApp):
10    """
11    """
12   
13class TestPlugin(PluginBase):
14   
15    def populate_menu(self, parent):
16        """
17        Create and return the list of application menu
18        items for the plug-in.
19        :param parent: parent window
20       
21        :return: plug-in menu
22       
23        """
24        import wx
25        # Create a menu
26        plug_menu = wx.Menu()
27
28        # Always get event IDs from wx
29        id = wx.NewId()
30       
31        # Fill your menu
32        plug_menu.Append(id, '&Do something')
33        def _on_do_something(event):
34            print "Do something"
35        wx.EVT_MENU(self.parent, id, _on_do_something)
36   
37        # Returns the menu and a name for it.
38        return [(plug_menu, "DummyApp")]   
39   
40    def get_panels(self, parent):
41        """
42        Create and return the list of wx.Panels for your plug-in.
43        Define the plug-in perspective.
44       
45        Panels should inherit from DefaultPanel defined below,
46        or should present the same interface. They must define
47        "window_caption" and "window_name".
48       
49        :param parent: parent window
50       
51        :return: list of panels
52       
53        """
54        ## Save a reference to the parent
55        self.parent = parent
56       
57        # Define a panel
58        defaultpanel = gui_manager.DefaultPanel(self.parent, -1)
59        defaultpanel.window_name = "Test"
60       
61        # If needed, add its name to the perspective list
62        self.perspective = [defaultpanel.window_name]
63
64        # Return the list of panels
65        return [defaultpanel]
66   
67    def get_tools(self):
68        """
69        Returns a set of menu entries for tools
70        """
71        def _test_dialog(event):
72            import wx
73            frame = wx.Dialog(None, -1, 'Test Tool')   
74            frame.Show(True)
75        return [["Tool 1", "This is an example tool", _test_dialog],
76                ["Tool 2", "This is another example tool", _test_dialog]]
77
78    def get_context_menu(self, graph=None):
79        """
80        This method is optional.
81   
82        When the context menu of a plot is rendered, the
83        get_context_menu method will be called to give you a
84        chance to add a menu item to the context menu.
85       
86        A ref to a Graph object is passed so that you can
87        investigate the plot content and decide whether you
88        need to add items to the context menu. 
89       
90        This method returns a list of menu items.
91        Each item is itself a list defining the text to
92        appear in the menu, a tool-tip help text, and a
93        call-back method.
94       
95        :param graph: the Graph object to which we attach the context menu
96       
97        :return: a list of menu items with call-back function
98        """
99        return [["Menu text", 
100                 "Tool-tip help text", 
101                 "self._on_context_do_something"]]   
102
103class SasView():
104   
105    def __init__(self):
106        """
107        Initialization
108        """
109        self.gui = DummyView(0)
110       
111        fitting_plug = TestPlugin()
112        self.gui.add_perspective(fitting_plug)
113       
114        # Build the GUI
115        self.gui.build_gui()
116       
117        # Set the application manager for the GUI
118        self.gui.set_manager(self)
119       
120        # Start the main loop
121        self.gui.MainLoop() 
122
123if __name__ == "__main__": 
124    from multiprocessing import freeze_support
125    freeze_support()
126    sasview = SasView()
Note: See TracBrowser for help on using the repository browser.