1 | """ |
---|
2 | Dummy application. |
---|
3 | Allows the user to set an external data manager |
---|
4 | """ |
---|
5 | import gui_manager |
---|
6 | |
---|
7 | from sans.guiframe.plugin_base import PluginBase |
---|
8 | |
---|
9 | class DummyView(gui_manager.ViewApp): |
---|
10 | """ |
---|
11 | """ |
---|
12 | |
---|
13 | class 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 | |
---|
103 | class SansView(): |
---|
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 | |
---|
123 | if __name__ == "__main__": |
---|
124 | sansview = SansView() |
---|
125 | |
---|