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