Index: calculatorview/perspectives/calculator/sld_panel.py
===================================================================
--- calculatorview/perspectives/calculator/sld_panel.py	(revision 6996942032976c15f6470b64e3f6f9d94c6b781b)
+++ calculatorview/perspectives/calculator/sld_panel.py	(revision 66bfacfc4fd20a684522c11a1bfb369dd63f44a5)
@@ -68,4 +68,5 @@
         self.neutron_inc_ctl = None
         self.neutron_length_ctl = None
+        self.button_calculate = None
         #Draw the panel
         self._do_layout()
@@ -274,10 +275,10 @@
     
         id = wx.NewId()
-        button_calculate = wx.Button(self, id, "Calculate")
-        button_calculate.SetToolTipString("Calculate SLD.")
+        self.button_calculate = wx.Button(self, id, "Calculate")
+        self.button_calculate.SetToolTipString("Calculate SLD.")
         self.Bind(wx.EVT_BUTTON, self.calculateSld, id=id)   
         
         sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 20)
+        sizer_button.Add(self.button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 20)
         sizer3.Add(sizer_button)
         #---------layout----------------
@@ -309,14 +310,18 @@
         """Check validity user inputs"""
         flag = True
-       
+        msg = ""
         if check_float(self.density_ctl):
             self.density = float(self.density_ctl.GetValue())
         else:
             flag = False
-            raise ValueError,"Error for Density value :expect float"
+            msg += "Error for Density value :expect float"
     
         self.wavelength = self.wavelength_ctl.GetValue()
         if self.wavelength.lstrip().rstrip() == "":
             self.wavelength = WAVELENGTH
+            self.wavelength_ctl.SetValue(str(WAVELENGTH))
+            self.wavelength_ctl.SetBackgroundColour(wx.WHITE)
+            self.wavelength_ctl.Refresh()
+            msg += "Default value for wavelength is 6.0"
         else:
             if check_float(self.wavelength_ctl):
@@ -324,16 +329,23 @@
             else:
                 flag = False
-                raise ValueError, "Error for wavelength value :expect float"
+                msg += "Error for wavelength value :expect float"
                 
         self.compound = self.compound_ctl.GetValue().lstrip().rstrip()
         if self.compound != "":
-            self.compound_ctl.SetBackgroundColour(wx.WHITE)
-            self.compound_ctl.Refresh()
+            try :
+                formula(self.compound)
+                self.compound_ctl.SetBackgroundColour(wx.WHITE)
+                self.compound_ctl.Refresh()
+            except:
+                self.compound_ctl.SetBackgroundColour("pink")
+                self.compound_ctl.Refresh()
+                flag = False
+                msg += "Enter correct formula"
         else:
             self.compound_ctl.SetBackgroundColour("pink")
             self.compound_ctl.Refresh()
             flag = False
-            raise ValueError, "Enter a formula"
-        return flag 
+            msg += "Enter a formula"
+        return flag, msg
         
     def calculate_sld_helper(self, element, density, molecule_formula):
@@ -357,63 +369,68 @@
             Calculate the neutron scattering density length of a molecule
         """
+        self.clear_outputs()
         try:
             #Check validity user inputs
-            if self.check_inputs():
-                #get ready to compute
-                try:
-                    self.sld_formula = formula(self.compound,
-                                                density=self.density)
-                except:
-                    if self.base is not None:
-                        msg = "SLD Calculator: %s"  % (sys.exc_value)
-                        wx.PostEvent(self.base, StatusEvent(status=msg))
-                    else:
-                        raise
-                    return
-                
-                
-                (sld_real, sld_im, _), (_, absorp, incoh), \
-                            length = neutron_scattering(compound=self.compound,
-                                       density=self.density, 
-                                       wavelength=self.wavelength) 
-                cu_real, cu_im = self.calculate_sld_helper(element="Cu",
-                                                     density=self.density,
-                                            molecule_formula=self.sld_formula)
-                mo_real, mo_im = self.calculate_sld_helper(element="Mo", 
-                                                           density=self.density,
-                                         molecule_formula=self.sld_formula)
-                # set neutron sld values
-                val = format_number(sld_real * _SCALE)
-                self.neutron_sld_reel_ctl.SetValue(val)
-                val = format_number(math.fabs(sld_im) * _SCALE)
-                self.neutron_sld_im_ctl.SetValue(val)
-                # Compute the Cu SLD
-                self.cu_ka_sld_reel_ctl.SetValue(format_number(cu_real *_SCALE))
-                val = format_number(math.fabs(cu_im )* _SCALE)
-                self.cu_ka_sld_im_ctl.SetValue(val)
-                # Compute the Mo SLD
-                self.mo_ka_sld_reel_ctl.SetValue(format_number(mo_real *_SCALE))
-                val = format_number(math.fabs(mo_im)* _SCALE)
-                self.mo_ka_sld_im_ctl.SetValue(val)
-                # set incoherence and absorption
-                self.neutron_inc_ctl.SetValue(format_number(incoh))
-                self.neutron_abs_ctl.SetValue(format_number(absorp))
-                # Neutron length
-                self.neutron_length_ctl.SetValue(format_number(length))
-                # display wavelength
-                self.wavelength_ctl.SetValue(str(self.wavelength))
+            flag, msg = self.check_inputs()
+            if self.base is not None and msg.lstrip().rstrip() != "":
+                msg = "SLD Calculator: %s" % str(msg)
+                wx.PostEvent(self.base, StatusEvent(status=msg))
+            if not flag:
+               return 
+            #get ready to compute
+            self.sld_formula = formula(self.compound,
+                                            density=self.density)
+            (sld_real, sld_im, _), (_, absorp, incoh), \
+                        length = neutron_scattering(compound=self.compound,
+                                   density=self.density, 
+                                   wavelength=self.wavelength) 
+            cu_real, cu_im = self.calculate_sld_helper(element="Cu",
+                                                 density=self.density,
+                                        molecule_formula=self.sld_formula)
+            mo_real, mo_im = self.calculate_sld_helper(element="Mo", 
+                                                       density=self.density,
+                                     molecule_formula=self.sld_formula)
+            # set neutron sld values
+            val = format_number(sld_real * _SCALE)
+            self.neutron_sld_reel_ctl.SetValue(val)
+            val = format_number(math.fabs(sld_im) * _SCALE)
+            self.neutron_sld_im_ctl.SetValue(val)
+            # Compute the Cu SLD
+            self.cu_ka_sld_reel_ctl.SetValue(format_number(cu_real *_SCALE))
+            val = format_number(math.fabs(cu_im )* _SCALE)
+            self.cu_ka_sld_im_ctl.SetValue(val)
+            # Compute the Mo SLD
+            self.mo_ka_sld_reel_ctl.SetValue(format_number(mo_real *_SCALE))
+            val = format_number(math.fabs(mo_im)* _SCALE)
+            self.mo_ka_sld_im_ctl.SetValue(val)
+            # set incoherence and absorption
+            self.neutron_inc_ctl.SetValue(format_number(incoh))
+            self.neutron_abs_ctl.SetValue(format_number(absorp))
+            # Neutron length
+            self.neutron_length_ctl.SetValue(format_number(length))
+            # display wavelength
+            self.wavelength_ctl.SetValue(str(self.wavelength))
         except:
-            raise
-            """
             if self.base is not None:
                 msg = "SLD Calculator: %s"%(sys.exc_value)
                 wx.PostEvent(self.base, StatusEvent(status=msg))
-            else:
-                raise
-            return   
-            """
         if event is not None:
             event.Skip()
-   
+            
+    def clear_outputs(self):
+        """
+        Clear the outputs textctrl
+        """
+        self.neutron_sld_reel_ctl.SetValue("")
+        self.neutron_sld_im_ctl.SetValue("")
+        self.mo_ka_sld_reel_ctl.SetValue("")
+        self.mo_ka_sld_im_ctl.SetValue("")
+        self.cu_ka_sld_reel_ctl.SetValue("")
+        self.cu_ka_sld_im_ctl.SetValue("")
+        self.neutron_abs_ctl.SetValue("")
+        self.neutron_inc_ctl.SetValue("")
+        self.neutron_length_ctl.SetValue("")
+        
+        
 class SldWindow(wx.Frame):
     """
Index: calculatorview/test/utest_gui_sld.py
===================================================================
--- calculatorview/test/utest_gui_sld.py	(revision 66bfacfc4fd20a684522c11a1bfb369dd63f44a5)
+++ calculatorview/test/utest_gui_sld.py	(revision 66bfacfc4fd20a684522c11a1bfb369dd63f44a5)
@@ -0,0 +1,164 @@
+"""
+test gui for sld calculator
+"""
+
+import unittest
+import wx
+
+H2O_DENSITY = 1.0
+WAVELENGTH = 6.0
+
+class testTextCtrl(unittest.TestCase):
+    """
+    txtctrl should have a pink background when the result are incorrect
+    and white when reset or correct value
+    """
+    def setUp(self):
+        """
+        Create an Sld calculator
+        """
+        self.app = wx.App()
+        from sans.perspectives.calculator.sld_panel import SldWindow
+        self.sld_frame = SldWindow()
+       
+    def testCompoundTextCtrl(self):
+        """
+        Test Compund textCtrl
+        """
+        #add  invalid value for compound
+        self.sld_frame.panel.compound_ctl.SetValue("String not in table")
+        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
+        id = self.sld_frame.panel.button_calculate.GetId()
+        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
+        self.assert_(bkg.GetAsString() == 'pink')
+        #compute invariant without entering a value for compound
+        self.sld_frame.panel.compound_ctl.SetValue("")
+        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
+        self.assert_(bkg.GetAsString() == 'pink')
+        #compute invariant without entering a value for compound
+        self.sld_frame.panel.compound_ctl.SetValue("H2O")
+        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
+        self.assert_(bkg.GetAsString() == 'white')
+       
+    def testDensityTextCtrl(self):
+        """
+        Test Density textCtrl
+        
+        """
+        #add  invalid value for density
+        self.sld_frame.panel.compound_ctl.SetValue("H2O")
+        self.sld_frame.panel.density_ctl.SetValue("invalid density")
+        id = self.sld_frame.panel.button_calculate.GetId()
+        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
+        self.assert_(bkg.GetAsString() == 'pink')
+        #compute invariant without entering a value for density
+        self.sld_frame.panel.compound_ctl.SetValue("H2O")
+        self.sld_frame.panel.density_ctl.SetValue("")
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
+        self.assert_(bkg.GetAsString() == 'pink')
+        #compute invariant without entering a value for density
+        self.sld_frame.panel.compound_ctl.SetValue("H2O")
+        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
+        self.assert_(bkg.GetAsString() == 'white')
+        
+    def testWavelengthTextCtrl(self):
+        """
+        Test wavelength textCtrl
+        
+        """
+        #add  invalid value for wavelength
+        self.sld_frame.panel.compound_ctl.SetValue("H2O")
+        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
+        self.sld_frame.panel.wavelength_ctl.SetValue("invalid wavelength")
+        id = self.sld_frame.panel.button_calculate.GetId()
+        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
+        self.assert_(bkg.GetAsString() == 'pink')
+        #compute invariant without entering a value for wavelegnth
+        self.sld_frame.panel.compound_ctl.SetValue("H2O")
+        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
+        self.sld_frame.panel.wavelength_ctl.SetValue("")
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
+        value = self.sld_frame.panel.wavelength_ctl.GetValue()
+        self.assert_(bkg.GetAsString() == 'white')
+        self.assert_(float(value) == WAVELENGTH)
+        #compute invariant with all correct inputs value
+        self.sld_frame.panel.compound_ctl.SetValue("H2O")
+        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
+        self.sld_frame.panel.wavelength_ctl.SetValue(str(WAVELENGTH/2))
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
+        value = self.sld_frame.panel.wavelength_ctl.GetValue()
+        self.assert_(bkg.GetAsString() == 'white')
+        self.assert_(float(value) == WAVELENGTH/2)
+        
+    def testSomeCombination(self):
+        """
+        Test other error
+        """
+        #only wavelength is invalid
+        self.sld_frame.panel.compound_ctl.SetValue("H2O")
+        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
+        self.sld_frame.panel.wavelength_ctl.SetValue("invalid wavelength")
+        id = self.sld_frame.panel.button_calculate.GetId()
+        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
+        self.assert_(cp_bkg.GetAsString() == 'white')
+        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
+        self.assert_(ds_bkg.GetAsString() == 'white')
+        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
+        self.assert_(wv_bkg.GetAsString() == 'pink')
+        #density, wavelength is invalid
+        self.sld_frame.panel.compound_ctl.SetValue("H2O")
+        self.sld_frame.panel.density_ctl.SetValue("invalid density")
+        self.sld_frame.panel.wavelength_ctl.SetValue("invalid wavelength")
+        id = self.sld_frame.panel.button_calculate.GetId()
+        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
+        self.assert_(cp_bkg.GetAsString() == 'white')
+        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
+        self.assert_(ds_bkg.GetAsString() == 'pink')
+        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
+        self.assert_(wv_bkg.GetAsString() == 'pink')
+        #density, wavelength is invalid
+        self.sld_frame.panel.compound_ctl.SetValue("invalid compound")
+        self.sld_frame.panel.density_ctl.SetValue("invalid density")
+        self.sld_frame.panel.wavelength_ctl.SetValue("")
+        id = self.sld_frame.panel.button_calculate.GetId()
+        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
+        self.sld_frame.panel.ProcessEvent(clickEvent)
+        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
+        self.assert_(cp_bkg.GetAsString() == 'pink')
+        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
+        self.assert_(ds_bkg.GetAsString() == 'pink')
+        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
+        self.assert_(wv_bkg.GetAsString() == 'white')
+        value = self.sld_frame.panel.wavelength_ctl.GetValue()
+        self.assert_(float(value) == WAVELENGTH)
+
+        
+        
+    def tearDown(self):
+        """
+        Destroy the sld calculator frame
+        """
+        self.sld_frame.Close()
+        self.app.MainLoop()
+        
+if __name__ == "__main__":
+    unittest.main()
Index: calculatorview/test/utest_sld.py
===================================================================
--- calculatorview/test/utest_sld.py	(revision 810f196fd1b147a38b926adc3e1bda37eb7429cb)
+++ calculatorview/test/utest_sld.py	(revision 66bfacfc4fd20a684522c11a1bfb369dd63f44a5)
@@ -45,5 +45,5 @@
         #Compute incoherence , absorption, and incoherence
         (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound,
-                                       self.density, self.wavelength) 
+                                       density=self.density, wavelength=self.wavelength) 
         cu_reel, cu_im = calculate_xray_sld(element="Cu", density=self.density,
                                   molecule_formula=self.sld_formula)
@@ -85,5 +85,5 @@
         #Compute incoherence , absorption, and incoherence
         (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound,
-                                       self.density, self.wavelength) 
+                                       density=self.density, wavelength=self.wavelength) 
         cu_reel, cu_im = calculate_xray_sld(element="Cu", density=self.density,
                                   molecule_formula=self.sld_formula)
@@ -125,5 +125,5 @@
         #Compute incoherence , absorption, and incoherence
         (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound,
-                                       self.density, self.wavelength) 
+                                density=self.density, wavelength=self.wavelength) 
         cu_reel, cu_im = calculate_xray_sld(element="Cu", density=self.density,
                                   molecule_formula=self.sld_formula)
