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