[41d466f] | 1 | """ |
---|
[d955bf19] | 2 | Dummy application. |
---|
| 3 | Allows the user to set an external data manager |
---|
[41d466f] | 4 | """ |
---|
[70ecd530] | 5 | import sans.guiframe.gui_manager as gui_manager |
---|
[957723f] | 6 | |
---|
[4753fc2] | 7 | from sans.guiframe.plugin_base import PluginBase |
---|
[41d466f] | 8 | |
---|
[4753fc2] | 9 | class DummyView(gui_manager.ViewApp): |
---|
| 10 | """ |
---|
| 11 | """ |
---|
[d68c655] | 12 | |
---|
[4753fc2] | 13 | class TestPlugin(PluginBase): |
---|
| 14 | |
---|
| 15 | def populate_menu(self, parent): |
---|
[d68c655] | 16 | """ |
---|
[d955bf19] | 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 | |
---|
[d68c655] | 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. |
---|
[4753fc2] | 38 | return [(plug_menu, "DummyApp")] |
---|
[d68c655] | 39 | |
---|
| 40 | def get_panels(self, parent): |
---|
| 41 | """ |
---|
[d955bf19] | 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 | |
---|
[d68c655] | 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 | """ |
---|
[d955bf19] | 69 | Returns a set of menu entries for tools |
---|
[d68c655] | 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 | """ |
---|
[d955bf19] | 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 |
---|
[d68c655] | 98 | """ |
---|
| 99 | return [["Menu text", |
---|
| 100 | "Tool-tip help text", |
---|
| 101 | self._on_context_do_something]] |
---|
| 102 | |
---|
[41d466f] | 103 | class SansView(): |
---|
| 104 | |
---|
| 105 | def __init__(self): |
---|
| 106 | """ |
---|
[d955bf19] | 107 | Initialization |
---|
[41d466f] | 108 | """ |
---|
[4753fc2] | 109 | self.gui = DummyView(0) |
---|
[d68c655] | 110 | |
---|
| 111 | fitting_plug = TestPlugin() |
---|
| 112 | self.gui.add_perspective(fitting_plug) |
---|
[41d466f] | 113 | |
---|
[7bb61da] | 114 | # Build the GUI |
---|
| 115 | self.gui.build_gui() |
---|
| 116 | |
---|
[41d466f] | 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__": |
---|
[6df04e43] | 124 | from multiprocessing import freeze_support |
---|
| 125 | freeze_support() |
---|
[783940c] | 126 | sansview = SansView() |
---|