[959eb01] | 1 | """ |
---|
| 2 | Calculator Module |
---|
| 3 | """ |
---|
| 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 | ################################################################################ |
---|
| 13 | |
---|
| 14 | import wx |
---|
| 15 | from sas.sasgui.guiframe.plugin_base import PluginBase |
---|
| 16 | from sas.sasgui.perspectives.calculator.data_operator import DataOperatorWindow |
---|
| 17 | from sas.sasgui.perspectives.calculator.data_editor import DataEditorWindow |
---|
| 18 | from sas.sasgui.perspectives.calculator.kiessig_calculator_panel import KiessigWindow |
---|
| 19 | from sas.sasgui.perspectives.calculator.sld_panel import SldWindow |
---|
| 20 | from sas.sasgui.perspectives.calculator.density_panel import DensityWindow |
---|
| 21 | from sas.sasgui.perspectives.calculator.slit_length_calculator_panel \ |
---|
| 22 | import SlitLengthCalculatorWindow |
---|
| 23 | from sas.sasgui.perspectives.calculator.resolution_calculator_panel \ |
---|
| 24 | import ResolutionWindow |
---|
| 25 | from sas.sasgui.perspectives.calculator.gen_scatter_panel import SasGenWindow |
---|
| 26 | from sas.sasgui.perspectives.calculator.image_viewer import ImageView |
---|
| 27 | from sas.sasgui.perspectives.calculator.pyconsole import PyConsole |
---|
| 28 | import logging |
---|
| 29 | |
---|
| 30 | logger = logging.getLogger(__name__) |
---|
| 31 | |
---|
| 32 | class Plugin(PluginBase): |
---|
| 33 | """ |
---|
| 34 | This class defines the interface for a Plugin class |
---|
| 35 | for calculator perspective |
---|
| 36 | """ |
---|
| 37 | def __init__(self): |
---|
| 38 | PluginBase.__init__(self, name="Calculator") |
---|
| 39 | # Log startup |
---|
| 40 | logger.info("Calculator plug-in started") |
---|
| 41 | self.sub_menu = "Tool" |
---|
| 42 | self.data_edit_frame = None |
---|
| 43 | # data operator use one frame all the time |
---|
| 44 | self.data_operator_frame = None |
---|
| 45 | self.kiessig_frame = None |
---|
| 46 | self.sld_frame = None |
---|
| 47 | self.cal_md_frame = None |
---|
| 48 | self.cal_slit_frame = None |
---|
| 49 | self.cal_res_frame = None |
---|
| 50 | self.gen_frame = None |
---|
| 51 | self.image_view = None |
---|
| 52 | self.py_frame = None |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | def get_tools(self): |
---|
| 56 | """ |
---|
| 57 | Returns a set of menu entries for tools |
---|
| 58 | """ |
---|
| 59 | data_oper_help = "Perform arithmetic data operation (+...) " |
---|
| 60 | data_oper_help += "and combination (|)" |
---|
| 61 | kiessig_help = "Approximately computes the " |
---|
| 62 | kiessig_help += "thickness of a shell or the size of " |
---|
| 63 | kiessig_help += "particles \n from the width of a Kiessig fringe." |
---|
| 64 | sld_help = "Computes the Scattering Length Density." |
---|
| 65 | slit_length_help = "Computes the slit length from the beam profile." |
---|
| 66 | resolution_help = "Approximately estimates the " |
---|
| 67 | resolution_help += "resolution of Q in 2D based on the SAS " |
---|
| 68 | resolution_help += "instrumental parameter values." |
---|
| 69 | mass_volume_help = "Based on the chemical formula, " |
---|
| 70 | mass_volume_help += "compute the mass density or the molar volume." |
---|
| 71 | gensas_help = "Generic SAS" |
---|
| 72 | pyconsole_help = "Python Console." |
---|
| 73 | imageviewer_help = "Load an image file and display the image." |
---|
| 74 | #data_editor_help = "Meta Data Editor" |
---|
| 75 | return [("Data Operation", |
---|
| 76 | data_oper_help, self.on_data_operation), |
---|
| 77 | ("SLD Calculator", sld_help, self.on_calculate_sld), |
---|
| 78 | ("Density/Volume Calculator", mass_volume_help, |
---|
| 79 | self.on_calculate_dv), |
---|
| 80 | ("Slit Size Calculator", slit_length_help, |
---|
| 81 | self.on_calculate_slit_size), |
---|
| 82 | ("Kiessig Thickness Calculator", |
---|
| 83 | kiessig_help, self.on_calculate_kiessig), |
---|
| 84 | ("Q Resolution Estimator", |
---|
| 85 | resolution_help, self.on_calculate_resoltuion), |
---|
| 86 | ("Generic Scattering Calculator", |
---|
| 87 | gensas_help, self.on_gen_model), |
---|
| 88 | ("Python Shell/Editor", pyconsole_help, self.on_python_console), |
---|
| 89 | ("Image Viewer", imageviewer_help, self.on_image_viewer), ] |
---|
| 90 | |
---|
| 91 | def on_edit_data(self, event): |
---|
| 92 | """ |
---|
| 93 | Edit meta data |
---|
| 94 | """ |
---|
[235f514] | 95 | if self.data_edit_frame is None: |
---|
[959eb01] | 96 | self.data_edit_frame = DataEditorWindow(parent=self.parent, |
---|
| 97 | manager=self, data=[], |
---|
| 98 | title="Data Editor") |
---|
| 99 | self.put_icon(self.data_edit_frame) |
---|
| 100 | else: |
---|
| 101 | self.data_edit_frame.Show(False) |
---|
| 102 | self.data_edit_frame.Show(True) |
---|
| 103 | |
---|
| 104 | def on_data_operation(self, event): |
---|
| 105 | """ |
---|
| 106 | Data operation |
---|
| 107 | """ |
---|
[235f514] | 108 | if self.data_operator_frame is None: |
---|
[959eb01] | 109 | # Use one frame all the time |
---|
| 110 | self.data_operator_frame = DataOperatorWindow(parent=self.parent, |
---|
| 111 | manager=self, |
---|
| 112 | title="Data Operation") |
---|
| 113 | self.put_icon(self.data_operator_frame) |
---|
| 114 | else: |
---|
| 115 | self.data_operator_frame.Show(False) |
---|
| 116 | self.data_operator_frame.panel.set_panel_on_focus(None) |
---|
| 117 | self.data_operator_frame.Show(True) |
---|
| 118 | |
---|
| 119 | def on_calculate_kiessig(self, event): |
---|
| 120 | """ |
---|
| 121 | Compute the Kiessig thickness |
---|
| 122 | """ |
---|
[235f514] | 123 | if self.kiessig_frame is None: |
---|
[959eb01] | 124 | frame = KiessigWindow(parent=self.parent, manager=self) |
---|
| 125 | self.put_icon(frame) |
---|
| 126 | self.kiessig_frame = frame |
---|
| 127 | else: |
---|
| 128 | self.kiessig_frame.Show(False) |
---|
| 129 | self.kiessig_frame.Show(True) |
---|
| 130 | |
---|
| 131 | def on_calculate_sld(self, event): |
---|
| 132 | """ |
---|
| 133 | Compute the scattering length density of molecula |
---|
| 134 | """ |
---|
[235f514] | 135 | if self.sld_frame is None: |
---|
[959eb01] | 136 | frame = SldWindow(parent=self.parent, |
---|
| 137 | base=self.parent, manager=self) |
---|
| 138 | self.put_icon(frame) |
---|
| 139 | self.sld_frame = frame |
---|
| 140 | else: |
---|
| 141 | self.sld_frame.Show(False) |
---|
| 142 | self.sld_frame.Show(True) |
---|
| 143 | |
---|
| 144 | def on_calculate_dv(self, event): |
---|
| 145 | """ |
---|
| 146 | Compute the mass density or molar voulme |
---|
| 147 | """ |
---|
[235f514] | 148 | if self.cal_md_frame is None: |
---|
[959eb01] | 149 | frame = DensityWindow(parent=self.parent, |
---|
| 150 | base=self.parent, manager=self) |
---|
| 151 | self.put_icon(frame) |
---|
| 152 | self.cal_md_frame = frame |
---|
| 153 | else: |
---|
| 154 | self.cal_md_frame.Show(False) |
---|
| 155 | self.cal_md_frame.Show(True) |
---|
| 156 | |
---|
| 157 | def on_calculate_slit_size(self, event): |
---|
| 158 | """ |
---|
| 159 | Compute the slit size a given data |
---|
| 160 | """ |
---|
[235f514] | 161 | if self.cal_slit_frame is None: |
---|
[959eb01] | 162 | frame = SlitLengthCalculatorWindow(parent=self.parent, manager=self) |
---|
| 163 | self.put_icon(frame) |
---|
| 164 | self.cal_slit_frame = frame |
---|
| 165 | else: |
---|
| 166 | self.cal_slit_frame.Show(False) |
---|
| 167 | self.cal_slit_frame.Show(True) |
---|
| 168 | |
---|
| 169 | def on_calculate_resoltuion(self, event): |
---|
| 170 | """ |
---|
| 171 | Estimate the instrumental resolution |
---|
| 172 | """ |
---|
[235f514] | 173 | if self.cal_res_frame is None: |
---|
[959eb01] | 174 | frame = ResolutionWindow(parent=self.parent, manager=self) |
---|
| 175 | self.put_icon(frame) |
---|
| 176 | self.cal_res_frame = frame |
---|
| 177 | else: |
---|
| 178 | self.cal_res_frame.Show(False) |
---|
| 179 | self.cal_res_frame.Show(True) |
---|
| 180 | |
---|
| 181 | def on_gen_model(self, event): |
---|
| 182 | """ |
---|
| 183 | On Generic model menu event |
---|
| 184 | """ |
---|
[235f514] | 185 | if self.gen_frame is None: |
---|
[959eb01] | 186 | frame = SasGenWindow(parent=self.parent, manager=self) |
---|
| 187 | self.put_icon(frame) |
---|
| 188 | self.gen_frame = frame |
---|
| 189 | else: |
---|
| 190 | self.gen_frame.Show(False) |
---|
| 191 | self.gen_frame.Show(True) |
---|
| 192 | |
---|
| 193 | def on_image_viewer(self, event): |
---|
| 194 | """ |
---|
| 195 | Get choose an image file dialog |
---|
| 196 | |
---|
| 197 | :param event: menu event |
---|
| 198 | """ |
---|
| 199 | self.image_view = ImageView(parent=self.parent) |
---|
| 200 | self.image_view.load() |
---|
| 201 | |
---|
| 202 | def on_python_console(self, event): |
---|
| 203 | """ |
---|
| 204 | Open Python Console |
---|
| 205 | |
---|
| 206 | :param event: menu event |
---|
| 207 | """ |
---|
| 208 | self.get_python_panel(filename=None) |
---|
| 209 | |
---|
| 210 | def get_python_panel(self, filename=None): |
---|
| 211 | """ |
---|
| 212 | Get the python shell panel |
---|
| 213 | |
---|
| 214 | :param filename: file name to open in editor |
---|
| 215 | """ |
---|
[235f514] | 216 | if self.py_frame is None: |
---|
[959eb01] | 217 | frame = PyConsole(parent=self.parent, base=self, |
---|
| 218 | filename=filename) |
---|
| 219 | self.put_icon(frame) |
---|
| 220 | self.py_frame = frame |
---|
| 221 | else: |
---|
| 222 | self.py_frame.Show(False) |
---|
| 223 | self.py_frame.Show(True) |
---|
| 224 | |
---|
| 225 | def put_icon(self, frame): |
---|
| 226 | """ |
---|
| 227 | Put icon in the frame title bar |
---|
| 228 | """ |
---|
| 229 | if hasattr(frame, "IsIconized"): |
---|
| 230 | if not frame.IsIconized(): |
---|
| 231 | try: |
---|
| 232 | icon = self.parent.GetIcon() |
---|
| 233 | frame.SetIcon(icon) |
---|
| 234 | except: |
---|
| 235 | pass |
---|