source: sasview/guiframe/dummyapp.py @ 1b3a5a9

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 1b3a5a9 was 4753fc2, checked in by Gervaise Alina <gervyh@…>, 14 years ago

update dummy example

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