Changeset 8963a55 in sasview


Ignore:
Timestamp:
Apr 9, 2017 4:31:52 AM (7 years ago)
Author:
Tim Snow <tim.snow@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
bd8411d5
Parents:
ec65dc81
Message:

GUI elements drawn

Build the relevant GUI elements and started work on the underlying code
to populate the results fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/calculator/sld_panel.py

    r959eb01 r8963a55  
    6060        # Object that receive status event 
    6161        self.base = base 
    62         self.wavelength = WAVELENGTH 
     62        self.neutron_wavelength = WAVELENGTH 
     63        self.xray_wavelength = WAVELENGTH 
    6364        self.parent = parent 
    6465        #layout attribute 
     
    6768        self.compound = "" 
    6869        self.density = "" 
    69         self.wavelength_ctl = None 
     70        self.neutron_wavelength_ctl = None 
     71        self.xray_wavelength_ctl = None 
     72        self.xray_cbox = None 
    7073        self.neutron_sld_real_ctl = None 
    7174        self.neutron_sld_im_ctl = None 
    72         self.mo_ka_sld_real_ctl = None 
    73         self.mo_ka_sld_im_ctl = None 
    74         self.cu_ka_sld_real_ctl = None 
    75         self.cu_ka_sld_im_ctl = None 
     75        self.xray_sld_real_ctl = None 
     76        self.xray_sld_im_ctl = None 
    7677        self.neutron_abs_ctl = None 
    7778        self.neutron_inc_ctl = None 
    7879        self.neutron_length_ctl = None 
    7980        self.button_calculate = None 
     81        self.xray_source = None 
    8082        #Draw the panel 
    8183        self._do_layout() 
    8284        self.SetAutoLayout(True) 
    8385        self.Layout() 
     86        self.fill_xray_cbox() 
    8487 
    8588    def _do_layout(self): 
     
    108111        self.density_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    109112        unit_density_txt = wx.StaticText(self, -1, unit_density) 
    110         wavelength_txt = wx.StaticText(self, -1, 'Wavelength ') 
    111         self.wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    112         self.wavelength_ctl.SetValue(str(self.wavelength)) 
    113         unit_a_txt = wx.StaticText(self, -1, unit_a) 
     113        neutron_wavelength_txt = wx.StaticText(self, -1, 'Neutron wavelength') 
     114        self.neutron_wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     115        self.neutron_wavelength_ctl.SetValue(str(self.neutron_wavelength)) 
     116        xray_wavelength_txt = wx.StaticText(self, -1, 'X-ray wavelength') 
     117        self.xray_wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     118        self.xray_wavelength_ctl.SetValue(str(self.xray_wavelength)) 
     119        neutron_unit_a_txt = wx.StaticText(self, -1, unit_a) 
     120 
     121        self.xray_cbox = wx.ComboBox(self, -1, size=(70, 20), style=wx.CB_READONLY) 
     122        xray_cbox_tip = "Select an element, wavelength or energy" 
     123        self.xray_cbox.SetToolTipString(xray_cbox_tip) 
     124        wx.EVT_COMBOBOX(self.xray_cbox, -1, self.on_select_xray) 
     125 
    114126        iy = 0 
    115127        ix = 0 
     
    131143        iy += 1 
    132144        ix = 0 
    133         sizer_input.Add(wavelength_txt, (iy, ix), (1, 1), 
    134                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    135         ix += 1 
    136         sizer_input.Add(self.wavelength_ctl, (iy, ix), (1, 1), 
    137                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    138         ix += 1 
    139         sizer_input.Add(unit_a_txt, (iy, ix), (1, 1), 
     145        sizer_input.Add(neutron_wavelength_txt, (iy, ix), (1, 1), 
     146                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     147        ix += 1 
     148        sizer_input.Add(self.neutron_wavelength_ctl, (iy, ix), (1, 1), 
     149                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     150        ix += 1 
     151        sizer_input.Add(neutron_unit_a_txt, (iy, ix), (1, 1), 
     152                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     153        iy += 1 
     154        ix = 0 
     155        sizer_input.Add(xray_wavelength_txt, (iy, ix), (1, 1), 
     156                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     157        ix += 1 
     158        sizer_input.Add(self.xray_wavelength_ctl, (iy, ix), (1, 1), 
     159                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     160        ix += 1 
     161        sizer_input.Add(self.xray_cbox, (iy, ix), (1, 1), 
    140162                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    141163        boxsizer1.Add(sizer_input) 
     
    151173                                                 size=(_BOX_WIDTH, -1)) 
    152174        self.neutron_sld_real_ctl.SetEditable(False) 
    153         self.neutron_sld_real_ctl.SetToolTipString("Neutron SLD real.") 
     175        self.neutron_sld_real_ctl.SetToolTipString("Neutron SLD real") 
    154176        self.neutron_sld_im_ctl = wx.TextCtrl(self, -1, 
    155177                                              size=(_BOX_WIDTH, -1)) 
    156178        self.neutron_sld_im_ctl.SetEditable(False) 
    157         self.neutron_sld_im_ctl.SetToolTipString("Neutron SLD imaginary.") 
     179        self.neutron_sld_im_ctl.SetToolTipString("Neutron SLD imaginary") 
    158180        neutron_sld_units_txt = wx.StaticText(self, -1, unit_sld) 
    159181 
    160         cu_ka_sld_txt = wx.StaticText(self, -1, 'Cu Ka SLD') 
    161         self.cu_ka_sld_real_ctl = wx.TextCtrl(self, -1, 
     182        xray_sld_txt = wx.StaticText(self, -1, 'X-ray SLD') 
     183        self.xray_sld_real_ctl = wx.TextCtrl(self, -1, 
    162184                                               size=(_BOX_WIDTH, -1)) 
    163         self.cu_ka_sld_real_ctl.SetEditable(False) 
    164         self.cu_ka_sld_real_ctl.SetToolTipString("Cu Ka SLD real.") 
    165         self.cu_ka_sld_im_ctl = wx.TextCtrl(self, -1, 
     185        self.xray_sld_real_ctl.SetEditable(False) 
     186        self.xray_sld_real_ctl.SetToolTipString("X-ray SLD real") 
     187        self.xray_sld_im_ctl = wx.TextCtrl(self, -1, 
    166188                                            size=(_BOX_WIDTH, -1)) 
    167         self.cu_ka_sld_im_ctl.SetEditable(False) 
    168         self.cu_ka_sld_im_ctl.SetToolTipString("Cu Ka SLD imaginary.") 
    169         cu_ka_sld_units_txt = wx.StaticText(self, -1, unit_sld) 
    170  
    171         mo_ka_sld_txt = wx.StaticText(self, -1, 'Mo Ka SLD') 
    172         self.mo_ka_sld_real_ctl = wx.TextCtrl(self, -1, 
    173                                                size=(_BOX_WIDTH, -1)) 
    174         self.mo_ka_sld_real_ctl.SetEditable(False) 
    175         self.mo_ka_sld_real_ctl.SetToolTipString("Mo Ka SLD real.") 
    176         self.mo_ka_sld_im_ctl = wx.TextCtrl(self, -1, 
    177                                              size=(_BOX_WIDTH, -1)) 
    178         self.mo_ka_sld_im_ctl.SetEditable(False) 
    179         self.mo_ka_sld_im_ctl.SetToolTipString("Mo Ka SLD imaginary.") 
    180         mo_ka_sld_units_txt = wx.StaticText(self, -1, unit_sld) 
     189        self.xray_sld_im_ctl.SetEditable(False) 
     190        self.xray_sld_im_ctl.SetToolTipString("X-ray SLD imaginary") 
     191        xray_sld_units_txt = wx.StaticText(self, -1, unit_sld) 
    181192 
    182193        neutron_inc_txt = wx.StaticText(self, -1, 'Neutron Inc. Xs') 
     
    219230        iy += 1 
    220231        ix = 0 
    221         sizer_output.Add(cu_ka_sld_txt, (iy, ix), (1, 1), 
    222                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    223         ix += 1 
    224         sizer_output.Add(self.cu_ka_sld_real_ctl, (iy, ix), (1, 1), 
     232        sizer_output.Add(xray_sld_txt, (iy, ix), (1, 1), 
     233                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     234        ix += 1 
     235        sizer_output.Add(self.xray_sld_real_ctl, (iy, ix), (1, 1), 
    225236                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    226237        ix += 1 
     
    228239                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    229240        ix += 1 
    230         sizer_output.Add(self.cu_ka_sld_im_ctl, 
     241        sizer_output.Add(self.xray_sld_im_ctl, 
    231242                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    232243        ix += 1 
    233         sizer_output.Add(cu_ka_sld_units_txt, 
    234                          (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    235         iy += 1 
    236         ix = 0 
    237         sizer_output.Add(mo_ka_sld_txt, (iy, ix), (1, 1), 
    238                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    239         ix += 1 
    240         sizer_output.Add(self.mo_ka_sld_real_ctl, (iy, ix), (1, 1), 
    241                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    242         ix += 1 
    243         sizer_output.Add(wx.StaticText(self, -1, i_complex), 
    244                          (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    245         ix += 1 
    246         sizer_output.Add(self.mo_ka_sld_im_ctl, 
    247                          (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    248         ix += 1 
    249         sizer_output.Add(mo_ka_sld_units_txt, 
     244        sizer_output.Add(xray_sld_units_txt, 
    250245                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    251246        iy += 1 
     
    310305        self.SetSizer(vbox) 
    311306 
     307    def fill_xray_cbox(self): 
     308        """ 
     309        fill the x-ray combobox with the sources 
     310        """ 
     311        # source_list = ['Element', 'Energy (keV)', 'Wavelength (A)'] 
     312        source_list = ['[A]', '[keV]', 'Element'] 
     313        for source in source_list: 
     314            pos = self.xray_cbox.Append(str(source)) 
     315            self.xray_cbox.SetClientData(pos, str(source.strip())) 
     316        self.xray_cbox.SetSelection(0) 
     317 
     318    def on_select_xray(self, event=None): 
     319        """ 
     320        On Selecting a source 
     321        """ 
     322        item = event.GetEventObject() 
     323        self.xray_source = item.GetValue().strip() 
     324 
    312325    def on_help(self, event): 
    313326        """ 
     
    363376            msg += "Error for Density value :expect float" 
    364377 
    365         self.wavelength = self.wavelength_ctl.GetValue() 
    366         if str(self.wavelength).lstrip().rstrip() == "": 
    367             self.wavelength = WAVELENGTH 
    368             self.wavelength_ctl.SetValue(str(WAVELENGTH)) 
    369             self.wavelength_ctl.SetBackgroundColour(wx.WHITE) 
    370             self.wavelength_ctl.Refresh() 
     378        self.neutron_wavelength = self.neutron_wavelength_ctl.GetValue() 
     379        self.xray_wavelength = self.xray_wavelength_ctl.GetValue() 
     380 
     381        if str(self.neutron_wavelength).lstrip().rstrip() == "": 
     382            self.neutron_wavelength = WAVELENGTH 
     383            self.neutron_wavelength_ctl.SetValue(str(WAVELENGTH)) 
     384            self.neutron_wavelength_ctl.SetBackgroundColour(wx.WHITE) 
     385            self.neutron_wavelength_ctl.Refresh() 
    371386            msg += "Default value for wavelength is 6.0" 
    372387        else: 
    373             if check_float(self.wavelength_ctl): 
    374                 self.wavelength = float(self.wavelength) 
     388            if check_float(self.neutron_wavelength_ctl): 
     389                self.neutron_wavelength = float(self.neutron_wavelength) 
     390            else: 
     391                flag = False 
     392                msg += "Error for wavelength value :expect float" 
     393 
     394        if str(self.xray_wavelength).lstrip().rstrip() == "": 
     395            self.xray_wavelength = WAVELENGTH 
     396            self.xray_wavelength_ctl.SetValue(str(WAVELENGTH)) 
     397            self.xray_wavelength_ctl.SetBackgroundColour(wx.WHITE) 
     398            self.xray_wavelength_ctl.Refresh() 
     399            msg += "Default value for wavelength is 6.0" 
     400        else: 
     401            if check_float(self.xray_wavelength_ctl): 
     402                self.xray_wavelength = float(self.xray_wavelength) 
    375403            else: 
    376404                flag = False 
     
    430458                        length = neutron_scattering(compound=self.compound, 
    431459                                   density=self.density, 
    432                                    wavelength=self.wavelength) 
    433             cu_real, cu_im = self.calculate_sld_helper(element="Cu", 
    434                                                  density=self.density, 
    435                                         molecule_formula=self.sld_formula) 
    436             mo_real, mo_im = self.calculate_sld_helper(element="Mo", 
    437                                                        density=self.density, 
    438                                      molecule_formula=self.sld_formula) 
     460                                   wavelength=self.neutron_wavelength) 
     461            if self.xray_source == "[A]": 
     462                # xray_real, xray_im = self.calculate_sld_helper(element=self.xray_wavelength, 
     463                #                                      density=self.density, 
     464                #                             molecule_formula=self.sld_formula) 
     465                pass 
     466            elif self.xray_source == "[keV]": 
     467                # xray_real, xray_im = self.calculate_sld_helper(element=self.xray_wavelength, 
     468                #                                      density=self.density, 
     469                #                             molecule_formula=self.sld_formula) 
     470                pass 
     471            elif self.xray_source == "Element": 
     472                # xray_real, xray_im = self.calculate_sld_helper(element=self.xray_wavelength, 
     473                #                                      density=self.density, 
     474                #                             molecule_formula=self.sld_formula) 
     475                pass 
    439476            # set neutron sld values 
    440477            val = format_number(sld_real * _SCALE) 
     
    443480            self.neutron_sld_im_ctl.SetValue(val) 
    444481            # Compute the Cu SLD 
    445             self.cu_ka_sld_real_ctl.SetValue(format_number(cu_real * _SCALE)) 
    446             val = format_number(math.fabs(cu_im) * _SCALE) 
    447             self.cu_ka_sld_im_ctl.SetValue(val) 
    448             # Compute the Mo SLD 
    449             self.mo_ka_sld_real_ctl.SetValue(format_number(mo_real * _SCALE)) 
    450             val = format_number(math.fabs(mo_im) * _SCALE) 
    451             self.mo_ka_sld_im_ctl.SetValue(val) 
     482            self.xray_sld_real_ctl.SetValue(format_number(xray_real * _SCALE)) 
     483            val = format_number(math.fabs(xray_im) * _SCALE) 
     484            self.xray_sld_im_ctl.SetValue(val) 
    452485            # set incoherence and absorption 
    453486            self.neutron_inc_ctl.SetValue(format_number(incoh)) 
     
    456489            self.neutron_length_ctl.SetValue(format_number(length)) 
    457490            # display wavelength 
    458             self.wavelength_ctl.SetValue(str(self.wavelength)) 
     491            #self.wavelength_ctl.SetValue(str(self.wavelength)) 
     492            #self.wavelength_ctl.SetValue(str(self.wavelength)) 
    459493        except: 
    460494            if self.base is not None: 
Note: See TracChangeset for help on using the changeset viewer.