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