[427fa87] | 1 | |
---|
| 2 | import wx |
---|
| 3 | import logging |
---|
| 4 | from sld_panel import SldPanel |
---|
| 5 | from sans.guicomm.events import NewPlotEvent, StatusEvent |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | class Plugin: |
---|
| 9 | """ |
---|
| 10 | This class defines the interface for a Plugin class |
---|
| 11 | for calculator perspective |
---|
| 12 | """ |
---|
| 13 | |
---|
| 14 | def __init__(self, standalone=True): |
---|
| 15 | """ |
---|
| 16 | Abstract class for gui_manager Plugins. |
---|
| 17 | """ |
---|
| 18 | ## Plug-in name. It will appear on the application menu. |
---|
| 19 | self.sub_menu = "Calculator" |
---|
| 20 | |
---|
| 21 | ## Reference to the parent window. Filled by get_panels() below. |
---|
| 22 | self.parent = None |
---|
| 23 | |
---|
| 24 | ## List of panels that you would like to open in AUI windows |
---|
| 25 | # for your plug-in. This defines your plug-in "perspective" |
---|
| 26 | self.perspective = [] |
---|
| 27 | # Log startup |
---|
| 28 | logging.info("Calculator plug-in started") |
---|
| 29 | |
---|
| 30 | def populate_menu(self, id, owner): |
---|
| 31 | """ |
---|
| 32 | Create and return the list of application menu |
---|
| 33 | items for the plug-in. |
---|
| 34 | |
---|
| 35 | @param id: deprecated. Un-used. |
---|
| 36 | @param parent: parent window |
---|
| 37 | @return: plug-in menu |
---|
| 38 | """ |
---|
| 39 | return [] |
---|
| 40 | |
---|
| 41 | def get_panels(self, parent): |
---|
| 42 | """ |
---|
| 43 | Create and return the list of wx.Panels for your plug-in. |
---|
| 44 | Define the plug-in perspective. |
---|
| 45 | |
---|
| 46 | Panels should inherit from DefaultPanel defined below, |
---|
| 47 | or should present the same interface. They must define |
---|
| 48 | "window_caption" and "window_name". |
---|
| 49 | |
---|
| 50 | @param parent: parent window |
---|
| 51 | @return: list of panels |
---|
| 52 | """ |
---|
| 53 | ## Save a reference to the parent |
---|
| 54 | self.parent = parent |
---|
[e847a42] | 55 | |
---|
| 56 | return [] |
---|
[fb0d7a20] | 57 | |
---|
[427fa87] | 58 | |
---|
| 59 | def help(self, evt): |
---|
| 60 | """ |
---|
| 61 | Show a general help dialog. |
---|
| 62 | TODO: replace the text with a nice image |
---|
| 63 | provide more hint on the SLD calculator |
---|
| 64 | """ |
---|
| 65 | from help_panel import HelpWindow |
---|
[fb0d7a20] | 66 | frame = HelpWindow(None, -1) |
---|
[427fa87] | 67 | frame.Show(True) |
---|
[fb0d7a20] | 68 | |
---|
[427fa87] | 69 | def get_context_menu(self, graph=None): |
---|
| 70 | """ |
---|
| 71 | This method is optional. |
---|
| 72 | |
---|
| 73 | When the context menu of a plot is rendered, the |
---|
| 74 | get_context_menu method will be called to give you a |
---|
| 75 | chance to add a menu item to the context menu. |
---|
| 76 | |
---|
| 77 | A ref to a Graph object is passed so that you can |
---|
| 78 | investigate the plot content and decide whether you |
---|
| 79 | need to add items to the context menu. |
---|
| 80 | |
---|
| 81 | This method returns a list of menu items. |
---|
| 82 | Each item is itself a list defining the text to |
---|
| 83 | appear in the menu, a tool-tip help text, and a |
---|
| 84 | call-back method. |
---|
| 85 | |
---|
| 86 | @param graph: the Graph object to which we attach the context menu |
---|
| 87 | @return: a list of menu items with call-back function |
---|
| 88 | """ |
---|
| 89 | return [] |
---|
| 90 | |
---|
| 91 | def get_perspective(self): |
---|
| 92 | """ |
---|
| 93 | Get the list of panel names for this perspective |
---|
| 94 | """ |
---|
| 95 | return self.perspective |
---|
[fb0d7a20] | 96 | |
---|
[427fa87] | 97 | |
---|
[fb0d7a20] | 98 | def get_tools(self): |
---|
| 99 | """ |
---|
| 100 | Returns a set of menu entries for tools |
---|
| 101 | """ |
---|
| 102 | id = wx.NewId() |
---|
| 103 | sld_help = "Provides computation related to Scattering Length density" |
---|
| 104 | return [("SLD Calculator", sld_help, self.on_calculate_sld)] |
---|
| 105 | |
---|
| 106 | def on_calculate_sld(self, event): |
---|
| 107 | """ |
---|
| 108 | Compute the scattering length density of molecula |
---|
| 109 | """ |
---|
| 110 | from sld_panel import SldWindow |
---|
| 111 | frame = SldWindow(base=self.parent) |
---|
| 112 | frame.Show(True) |
---|
| 113 | |
---|
| 114 | |
---|
[427fa87] | 115 | def on_perspective(self, event): |
---|
| 116 | """ |
---|
| 117 | Call back function for the perspective menu item. |
---|
| 118 | We notify the parent window that the perspective |
---|
| 119 | has changed. |
---|
| 120 | @param event: menu event |
---|
| 121 | """ |
---|
| 122 | self.parent.set_perspective(self.perspective) |
---|
[fb0d7a20] | 123 | |
---|
[427fa87] | 124 | |
---|
| 125 | def post_init(self): |
---|
| 126 | """ |
---|
| 127 | Post initialization call back to close the loose ends |
---|
| 128 | """ |
---|
| 129 | pass |
---|
[fb0d7a20] | 130 | |
---|
| 131 | |
---|
| 132 | |
---|