[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 | """ |
---|
[91f151a] | 108 | sld_help = "Provides computation related to Scattering Length Density" |
---|
| 109 | slit_length_help = "Provides computation related to Slit Length Density" |
---|
| 110 | data_editor_help = "Meta Data Editor" |
---|
[378d2eb] | 111 | return [("SLD Calculator", sld_help, self.on_calculate_sld), |
---|
[b500652] | 112 | ("Slit Size Calculator", slit_length_help, |
---|
[91f151a] | 113 | self.on_calculate_slit_size), |
---|
| 114 | ("Data Editor", data_editor_help, |
---|
| 115 | self.on_edit_data)] |
---|
[fb0d7a20] | 116 | |
---|
[91f151a] | 117 | def on_edit_data(self, event): |
---|
| 118 | """ |
---|
| 119 | Edit meta data |
---|
| 120 | """ |
---|
| 121 | from data_editor import DataEditorWindow |
---|
| 122 | frame = DataEditorWindow(parent=self.parent, data=[], title="Data Editor") |
---|
| 123 | frame.Show(True) |
---|
| 124 | |
---|
[fb0d7a20] | 125 | def on_calculate_sld(self, event): |
---|
| 126 | """ |
---|
| 127 | Compute the scattering length density of molecula |
---|
| 128 | """ |
---|
| 129 | from sld_panel import SldWindow |
---|
| 130 | frame = SldWindow(base=self.parent) |
---|
| 131 | frame.Show(True) |
---|
[378d2eb] | 132 | |
---|
| 133 | def on_calculate_slit_size(self, event): |
---|
| 134 | """ |
---|
| 135 | Compute the slit size a given data |
---|
| 136 | """ |
---|
| 137 | from slit_length_calculator_panel import SlitLengthCalculatorWindow |
---|
| 138 | frame = SlitLengthCalculatorWindow(parent=self.parent) |
---|
| 139 | frame.Show(True) |
---|
[fb0d7a20] | 140 | |
---|
[427fa87] | 141 | def on_perspective(self, event): |
---|
| 142 | """ |
---|
| 143 | Call back function for the perspective menu item. |
---|
| 144 | We notify the parent window that the perspective |
---|
| 145 | has changed. |
---|
| 146 | @param event: menu event |
---|
| 147 | """ |
---|
| 148 | self.parent.set_perspective(self.perspective) |
---|
[fb0d7a20] | 149 | |
---|
[427fa87] | 150 | |
---|
| 151 | def post_init(self): |
---|
| 152 | """ |
---|
| 153 | Post initialization call back to close the loose ends |
---|
| 154 | """ |
---|
| 155 | pass |
---|
[fb0d7a20] | 156 | |
---|
| 157 | |
---|
| 158 | |
---|