[b0ab6cb] | 1 | """ |
---|
| 2 | Calculator Module |
---|
| 3 | """ |
---|
[6137b150] | 4 | ################################################################################ |
---|
| 5 | #This software was developed by the University of Tennessee as part of the |
---|
| 6 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 7 | #project funded by the US National Science Foundation. |
---|
| 8 | # |
---|
| 9 | #See the license text in license.txt |
---|
| 10 | # |
---|
| 11 | #copyright 2010, University of Tennessee |
---|
| 12 | ################################################################################ |
---|
[427fa87] | 13 | |
---|
[b0ab6cb] | 14 | #import wx |
---|
[427fa87] | 15 | import logging |
---|
| 16 | |
---|
| 17 | class Plugin: |
---|
| 18 | """ |
---|
[6137b150] | 19 | This class defines the interface for a Plugin class |
---|
| 20 | for calculator perspective |
---|
[427fa87] | 21 | """ |
---|
| 22 | def __init__(self, standalone=True): |
---|
| 23 | """ |
---|
[6137b150] | 24 | Abstract class for gui_manager Plugins. |
---|
[427fa87] | 25 | """ |
---|
| 26 | ## Plug-in name. It will appear on the application menu. |
---|
| 27 | self.sub_menu = "Calculator" |
---|
[b0ab6cb] | 28 | #standalone flag |
---|
| 29 | self.standalone = standalone |
---|
[427fa87] | 30 | ## Reference to the parent window. Filled by get_panels() below. |
---|
| 31 | self.parent = None |
---|
| 32 | |
---|
| 33 | ## List of panels that you would like to open in AUI windows |
---|
| 34 | # for your plug-in. This defines your plug-in "perspective" |
---|
| 35 | self.perspective = [] |
---|
| 36 | # Log startup |
---|
| 37 | logging.info("Calculator plug-in started") |
---|
| 38 | |
---|
| 39 | def populate_menu(self, id, owner): |
---|
| 40 | """ |
---|
[6137b150] | 41 | Create and return the list of application menu |
---|
| 42 | items for the plug-in. |
---|
| 43 | |
---|
| 44 | :param id: deprecated. Un-used. |
---|
| 45 | :param parent: parent window |
---|
| 46 | |
---|
| 47 | :return: plug-in menu |
---|
| 48 | |
---|
[427fa87] | 49 | """ |
---|
| 50 | return [] |
---|
| 51 | |
---|
| 52 | def get_panels(self, parent): |
---|
| 53 | """ |
---|
[6137b150] | 54 | Create and return the list of wx.Panels for your plug-in. |
---|
| 55 | Define the plug-in perspective. |
---|
| 56 | |
---|
| 57 | Panels should inherit from DefaultPanel defined below, |
---|
| 58 | or should present the same interface. They must define |
---|
| 59 | "window_caption" and "window_name". |
---|
| 60 | |
---|
| 61 | :param parent: parent window |
---|
| 62 | |
---|
| 63 | :return: list of panels |
---|
| 64 | |
---|
[427fa87] | 65 | """ |
---|
| 66 | ## Save a reference to the parent |
---|
| 67 | self.parent = parent |
---|
[e847a42] | 68 | |
---|
| 69 | return [] |
---|
[fb0d7a20] | 70 | |
---|
[427fa87] | 71 | |
---|
| 72 | def help(self, evt): |
---|
| 73 | """ |
---|
[6137b150] | 74 | Show a general help dialog. |
---|
| 75 | |
---|
| 76 | :TODO: replace the text with a nice image |
---|
[427fa87] | 77 | provide more hint on the SLD calculator |
---|
| 78 | """ |
---|
| 79 | from help_panel import HelpWindow |
---|
[fb0d7a20] | 80 | frame = HelpWindow(None, -1) |
---|
[427fa87] | 81 | frame.Show(True) |
---|
[82826c4] | 82 | #evt.Skip() |
---|
[b0ab6cb] | 83 | |
---|
[427fa87] | 84 | def get_context_menu(self, graph=None): |
---|
| 85 | """ |
---|
[6137b150] | 86 | This method is optional. |
---|
| 87 | |
---|
| 88 | When the context menu of a plot is rendered, the |
---|
| 89 | get_context_menu method will be called to give you a |
---|
| 90 | chance to add a menu item to the context menu. |
---|
[427fa87] | 91 | |
---|
[6137b150] | 92 | A ref to a Graph object is passed so that you can |
---|
| 93 | investigate the plot content and decide whether you |
---|
| 94 | need to add items to the context menu. |
---|
| 95 | |
---|
| 96 | This method returns a list of menu items. |
---|
| 97 | Each item is itself a list defining the text to |
---|
| 98 | appear in the menu, a tool-tip help text, and a |
---|
| 99 | call-back method. |
---|
[427fa87] | 100 | |
---|
| 101 | @param graph: the Graph object to which we attach the context menu |
---|
| 102 | @return: a list of menu items with call-back function |
---|
| 103 | """ |
---|
| 104 | return [] |
---|
| 105 | |
---|
| 106 | def get_perspective(self): |
---|
| 107 | """ |
---|
[6137b150] | 108 | Get the list of panel names for this perspective |
---|
[427fa87] | 109 | """ |
---|
| 110 | return self.perspective |
---|
[fb0d7a20] | 111 | |
---|
[427fa87] | 112 | |
---|
[fb0d7a20] | 113 | def get_tools(self): |
---|
| 114 | """ |
---|
[6137b150] | 115 | Returns a set of menu entries for tools |
---|
[fb0d7a20] | 116 | """ |
---|
[5cc393b8] | 117 | kiessig_help = "Approximately computes the " |
---|
[74b1770] | 118 | kiessig_help += "thickness of a shell or the size of " |
---|
| 119 | kiessig_help += "particles \n from the width of a Kiessig fringe." |
---|
[5cc393b8] | 120 | sld_help = "Computes the Scattering Length Density." |
---|
| 121 | slit_length_help = "Computes the slit length from the beam profile." |
---|
| 122 | resolution_help = "Approximately estimates the " |
---|
| 123 | resolution_help += "resolution of Q in 2D based on the SANS " |
---|
| 124 | resolution_help += "instrumental parameter values." |
---|
[b0ab6cb] | 125 | #data_editor_help = "Meta Data Editor" |
---|
[378d2eb] | 126 | return [("SLD Calculator", sld_help, self.on_calculate_sld), |
---|
[b500652] | 127 | ("Slit Size Calculator", slit_length_help, |
---|
[74b1770] | 128 | self.on_calculate_slit_size), |
---|
| 129 | ("Kiessig Thickness Calculator", |
---|
[3be3a80] | 130 | kiessig_help, self.on_calculate_kiessig), |
---|
| 131 | ("SANS Resolution Estimator", |
---|
[5cc393b8] | 132 | resolution_help, self.on_calculate_resoltuion)]#, |
---|
[6137b150] | 133 | #("Data Editor", data_editor_help, self.on_edit_data)] |
---|
[fb0d7a20] | 134 | |
---|
[91f151a] | 135 | def on_edit_data(self, event): |
---|
| 136 | """ |
---|
[6137b150] | 137 | Edit meta data |
---|
[91f151a] | 138 | """ |
---|
| 139 | from data_editor import DataEditorWindow |
---|
[b0ab6cb] | 140 | frame = DataEditorWindow(parent=self.parent, data=[], |
---|
| 141 | title="Data Editor") |
---|
[91f151a] | 142 | frame.Show(True) |
---|
[b0ab6cb] | 143 | event.Skip() |
---|
[74b1770] | 144 | |
---|
| 145 | def on_calculate_kiessig(self, event): |
---|
| 146 | """ |
---|
| 147 | Compute the Kiessig thickness |
---|
| 148 | """ |
---|
| 149 | from kiessig_calculator_panel import KiessigWindow |
---|
| 150 | frame = KiessigWindow() |
---|
| 151 | frame.Show(True) |
---|
[44148f0] | 152 | |
---|
[fb0d7a20] | 153 | def on_calculate_sld(self, event): |
---|
| 154 | """ |
---|
[6137b150] | 155 | Compute the scattering length density of molecula |
---|
[fb0d7a20] | 156 | """ |
---|
| 157 | from sld_panel import SldWindow |
---|
| 158 | frame = SldWindow(base=self.parent) |
---|
| 159 | frame.Show(True) |
---|
[44148f0] | 160 | |
---|
[378d2eb] | 161 | def on_calculate_slit_size(self, event): |
---|
| 162 | """ |
---|
[6137b150] | 163 | Compute the slit size a given data |
---|
[378d2eb] | 164 | """ |
---|
| 165 | from slit_length_calculator_panel import SlitLengthCalculatorWindow |
---|
| 166 | frame = SlitLengthCalculatorWindow(parent=self.parent) |
---|
| 167 | frame.Show(True) |
---|
[3be3a80] | 168 | |
---|
| 169 | def on_calculate_resoltuion(self, event): |
---|
| 170 | """ |
---|
| 171 | Estimate the instrumental resolution |
---|
| 172 | """ |
---|
| 173 | from resolution_calculator_panel import ResolutionWindow |
---|
| 174 | frame = ResolutionWindow(parent=self.parent) |
---|
| 175 | frame.Show(True) |
---|
| 176 | |
---|
[427fa87] | 177 | def on_perspective(self, event): |
---|
| 178 | """ |
---|
[6137b150] | 179 | Call back function for the perspective menu item. |
---|
| 180 | We notify the parent window that the perspective |
---|
| 181 | has changed. |
---|
| 182 | |
---|
| 183 | :param event: menu event |
---|
| 184 | |
---|
[427fa87] | 185 | """ |
---|
| 186 | self.parent.set_perspective(self.perspective) |
---|
[b0ab6cb] | 187 | event.Skip() |
---|
| 188 | |
---|
[427fa87] | 189 | def post_init(self): |
---|
| 190 | """ |
---|
[6137b150] | 191 | Post initialization call back to close the loose ends |
---|
[427fa87] | 192 | """ |
---|
| 193 | pass |
---|
[fb0d7a20] | 194 | |
---|
| 195 | |
---|
| 196 | |
---|