Index: guiframe/local_perspectives/plotting/boxSum.py
===================================================================
--- guiframe/local_perspectives/plotting/boxSum.py	(revision 6d920cd2a2b96abc4845a5766911d8ef7fe5adc5)
+++ guiframe/local_perspectives/plotting/boxSum.py	(revision eba08f1a43992e4ce1b52d3a3dd206926fdeb56a)
@@ -1,49 +1,55 @@
-#TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it
-#      before pushing a new 1D data update.
-
-#
-#TODO: NEED MAJOR REFACTOR
-#
-
-
-# Debug printout
-#from config import printEVT
+
+
+
+import math
+import wx
+from copy import deepcopy
 from BaseInteractor import _BaseInteractor
-from copy import deepcopy
-import math
-
-#from Plotter1D import AddPlotEvent
-import SlicerParameters
-import wx
-
 from sans.guicomm.events import SlicerParamUpdateEvent,EVT_SLICER_PARS,StatusEvent
+
+
 class BoxSum(_BaseInteractor):
     """
-         Select an annulus through a 2D plot
+        Boxsum Class: determine 2 rectangular area to compute the sum of pixel of
+        a Data. 
+        Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine.
+        @param zorder:  Artists with lower zorder values are drawn first.
+        @param x_min: the minimum value of the x coordinate
+        @param x_max: the maximum value of the x coordinate
+        @param y_min: the minimum value of the y coordinate
+        @param y_max: the maximum value of the y coordinate
+
     """
-    def __init__(self,base,axes,color='black', zorder=3, x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025):
+    def __init__(self,base,axes,color='black', zorder=3, x_min=0.008,
+                  x_max=0.008, y_min=0.0025, y_max=0.0025):
         
         _BaseInteractor.__init__(self, base, axes, color=color)
+        ## class initialization
+        ## list of Boxsmun markers
         self.markers = []
         self.axes = axes
+        ## connect the artist for the motion
+        self.connect = self.base.connect
+        ## when qmax is reached the selected line is reset the its previous value
         self.qmax = min(self.base.data2D.xmax, self.base.data2D.xmin)
-        self.connect = self.base.connect
+        ## Define the boxsum limits
         self.xmin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin))
         self.ymin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin))
-        #self.xmax= x_max
-        #self.ymax=  y_max
+       
         self.xmax= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin))
         self.ymax=  0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin))
-        # center of the figure
+        ## center of the boxSum
         self.center_x= 0.0002
         self.center_y= 0.0003
-       
         ## Number of points on the plot
         self.nbins = 20
+        ## Define initial result the summation 
         self.count=0
         self.error=0
+        ## Flag to determine if the current figure has moved
+        ## set to False == no motion , set to True== motion
         self.has_move= False
-    
-        self.horizontal_lines= Horizontal_DoubleLine(self, self.base.subplot,color='blue',
+        ## Create Boxsum edges 
+        self.horizontal_lines= HorizontalDoubleLine(self, self.base.subplot,color='blue',
                                                       zorder=zorder,
                                     y= self.ymax,
@@ -53,5 +59,5 @@
         self.horizontal_lines.qmax = self.qmax
         
-        self.vertical_lines= Vertical_DoubleLine(self, self.base.subplot,color='black',
+        self.vertical_lines= VerticalDoubleLine(self, self.base.subplot,color='black',
                                                       zorder=zorder,
                                     y= self.ymax,
@@ -60,50 +66,54 @@
                                     center_y= self.center_y)
         self.vertical_lines.qmax = self.qmax
+        
         self.center= PointInteractor(self, self.base.subplot,color='grey',
                                                       zorder=zorder,
                                     center_x= self.center_x,
                                     center_y= self.center_y)
-      
-            
-        #self.connect_markers([])
-        self.panel_name=""      
+        ## Save the name of the slicer panel associate with this slicer 
+        self.panel_name=""    
+        ## Update and post slicer parameters  
         self.update()
         self._post_data()
-        
-        # Bind to slice parameter events
-        #print "box sum  self.base.parent",self.base.parent
+        ## Bind to slice parameter events
         self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS)
         
+        
     def set_panel_name(self, name):
+        """
+            Store the name of the panel associated to this slicer
+            @param name: the name of this panel
+        """
         self.panel_name= name
         
         
     def _onEVT_SLICER_PARS(self, event):
+        """
+            receive an event containing parameters values to reset the slicer
+            @param event: event of type SlicerParameterEvent with params as 
+            attribute
+        """
+        ## Post e message to declare what kind of event has being received
         wx.PostEvent(self.base.parent, StatusEvent(status="Boxsum._onEVT_SLICER_PARS"))
-        #print "receiving value ",event.params
         event.Skip()
+        ## reset the slicer with the values contains the event.params dictionary
         if event.type == self.__class__.__name__:
             self.set_params(event.params)
             self.base.update()
 
-    def update_and_post(self):
-        self.update()
-        self._post_data()
-
-    def save_data(self, path, image, x, y):
-        output = open(path, 'w')
-        
-        data_x, data_y = self.get_data(image, x, y)
-        
-        output.write("<phi>  <average>\n")
-        for i in range(len(data_x)):
-            output.write("%g  %g\n" % (data_x[i], data_y[i]))
-        output.close()
 
     def set_layer(self, n):
+        """
+             Allow adding plot to the same panel
+             @param n: the number of layer
+        """
         self.layernum = n
         self.update()
         
+        
     def clear(self):
+        """
+            Clear the slicer and all connected events related to this slicer
+        """
         self.clear_markers()
         self.horizontal_lines.clear()
@@ -111,26 +121,25 @@
         self.center.clear()
         self.base.connect.clearall()
-        #self.base.connect.disconnect()
         self.base.Unbind(EVT_SLICER_PARS)
         
+        
     def update(self):
         """
-        Respond to changes in the model by recalculating the profiles and
-        resetting the widgets.
-        """
+            Respond to changes in the model by recalculating the profiles and
+            resetting the widgets.
+        """
+        ## check if the center point has moved and update the figure accordingly 
         if self.center.has_move:
-            #print "center has move"
             self.center.update()
             self.horizontal_lines.update( center= self.center)
             self.vertical_lines.update( center= self.center)
-            
+        ## check if the horizontal lines have moved and update the figure accordingly    
         if self.horizontal_lines.has_move:
-            #print "top has moved"
             self.horizontal_lines.update()
             self.vertical_lines.update(y1=self.horizontal_lines.y1,
                                        y2=self.horizontal_lines.y2,
                                        height= self.horizontal_lines.half_height )
+        ## check if the vertical lines have moved and update the figure accordingly    
         if self.vertical_lines.has_move:
-            #print "right has moved"
             self.vertical_lines.update()
             self.horizontal_lines.update(x1=self.vertical_lines.x1,
@@ -150,24 +159,31 @@
         
     def _post_data(self):
-        # Compute data
-        print 
-        
+        """
+            Get the limits of the boxsum and compute the sum of the pixel
+            contained in that region and the error on that sum
+        """
+        ## Data 2D for which the pixel will be summed
         data = self.base.data2D
-        from DataLoader.manipulations import  Boxavg
-        #radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2))
+        ## the region of the summation
         x_min= self.horizontal_lines.x2 
         x_max= self.horizontal_lines.x1 
         y_min= self.vertical_lines.y2
         y_max= self.vertical_lines.y1
-        #print "xmin, xmax, ymin , ymax", x_min, x_max, y_min, y_max
+        ##computation of the sum and its error
+        from DataLoader.manipulations import  Boxavg
         box =  Boxavg (x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max)
         self.count, self.error = box(self.base.data2D)
-        #print "box_sum output",box(self.base.data2D)
+
                           
     def moveend(self, ev):
+        """
+            After a dragging motion this function is called to compute
+            the error and the sum of pixel of a given data 2D 
+        """
         self.base.thaw_axes()
-        # Post paramters
+        ## compute error an d sum of data's pixel
         self._post_data()
-       
+        ## Create and event ( posted to guiframe)that  set the 
+        ##current slicer parameter to a panel of name self.panel_name
         self.type= self.__class__.__name__
         params= self.get_params()
@@ -184,4 +200,6 @@
         self.vertical_lines.restore()
         self.center.restore()
+        
+        
     def move(self, x, y, ev):
         """
@@ -189,19 +207,22 @@
         """
         pass
+    
     
     def set_cursor(self, x, y):
         pass
         
+        
     def get_params(self):
+        """
+            Store a copy of values of parameters of the slicer into a dictionary.
+            @return params: the dictionary created
+        """
         params = {}
-       
         params["Width"] = math.fabs(self.vertical_lines.half_width)*2
         params["Height"] = math.fabs(self.horizontal_lines.half_height)*2 
-        
         params["center_x"] = self.center.x
         params["center_y"] =self.center.y
         params["count"] = self.count
         params["errors"]= self.error
-        
         return params
     
@@ -218,5 +239,10 @@
         
     def set_params(self, params):
-        
+        """
+            Receive a dictionary and reset the slicer with values contained 
+            in the values of the dictionary.
+            @param params: a dictionary containing name of slicer parameters and 
+            values the user assigned to the slicer.
+        """
         x_max = math.fabs(params["Width"] )/2
         y_max = math.fabs(params["Height"] )/2
@@ -224,7 +250,6 @@
         self.center_x=params["center_x"] 
         self.center_y=params["center_y"]
-       
+        #update the slicer given values of params
         self.center.update(center_x=self.center_x,center_y=self.center_y)
-       
         self.horizontal_lines.update(center= self.center,
                                      width=x_max,
@@ -233,5 +258,5 @@
                                     width=x_max,
                                     height=y_max)
-        
+        #compute the new error and sum given values of params
         self._post_data()
         
@@ -241,12 +266,18 @@
         self.base.freeze_axes()
         
+        
     def thaw_axes(self):
         self.base.thaw_axes()
 
+
     def draw(self):
         self.base.draw()
+        
+        
+        
 class PointInteractor(_BaseInteractor):
     """
-         Select an annulus through a 2D plot
+         Draw a point that can be dragged with the marker.
+         this class controls the motion the center of the BoxSum 
     """
     def __init__(self,base,axes,color='black', zorder=5,
@@ -255,14 +286,14 @@
         
         _BaseInteractor.__init__(self, base, axes, color=color)
+        ## Initialization the class 
         self.markers = []
         self.axes = axes
-        # center
+        # center coordinates
         self.x = center_x
         self.y = center_y
-        
+        ## saved value of the center coordinates
         self.save_x = center_x
         self.save_y = center_y
-         
-        
+        ## Create a marker 
         try:
             self.center_marker = self.axes.plot([self.x],[self.y], linestyle='',
@@ -280,23 +311,33 @@
             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n"
             message += "Get the SVN version that is at least as recent as June 1, 2007"
-            
-            #raise "Version error", message
-            
-        # line
+            owner=self.base.base.parent
+            wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message))
+            
+        ## Draw a point
         self.center = self.axes.plot([self.x],[self.y],
                                       linestyle='-', marker='',
                                       color=self.color,
                                       visible=True)[0]
-    
-        self.npts = 30
-        self.has_move=False    
+        ## Flag to determine the motion this point 
+        self.has_move=False   
+        ## connecting the marker to allow them to move 
         self.connect_markers([self.center_marker])
-        self.update()
+        ## Update the figure
+        self.update()
+    
     
     def set_layer(self, n):
+        """
+            Allow adding plot to the same panel
+            @param n: the number of layer
+        """
         self.layernum = n
         self.update()
         
+        
     def clear(self):
+        """
+            Clear this figure and its markers
+        """
         self.clear_markers()
         try:
@@ -307,12 +348,9 @@
             for item in range(len(self.axes.lines)):
                 del self.axes.lines[0]
-        
-    def get_radius(self):
-        
-        return 0
+  
    
     def update(self, center_x=None,center_y=None):
         """
-        Draw the new roughness on the graph.
+            Draw the new roughness on the graph.
         """
         if center_x !=None: self.x= center_x
@@ -323,6 +361,4 @@
         
         
-        
-        
     def save(self, ev):
         """
@@ -332,6 +368,6 @@
         self.save_x= self.x
         self.save_y= self.y
-        
         self.base.freeze_axes()
+
 
     def moveend(self, ev):
@@ -346,4 +382,5 @@
         self.y= self.save_y
         self.x= self.save_x
+        
         
     def move(self, x, y, ev):
@@ -357,4 +394,5 @@
         self.base.base.update()
         
+        
     def set_cursor(self, x, y):
         self.move(x, y, None)
@@ -366,6 +404,6 @@
         params["x"] = self.x
         params["y"] = self.y
-        
         return params
+    
     
     def set_params(self, params):
@@ -375,7 +413,8 @@
        
         
-class Vertical_DoubleLine(_BaseInteractor):
+class VerticalDoubleLine(_BaseInteractor):
     """
-         Select an annulus through a 2D plot
+         Draw 2 vertical lines moving in opposite direction and centered on 
+         a point (PointInteractor)
     """
     def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5,
@@ -384,12 +423,11 @@
         
         _BaseInteractor.__init__(self, base, axes, color=color)
+        ## Initialization the class 
         self.markers = []
         self.axes = axes
-        # center
+        ## Center coordinates
         self.center_x = center_x
         self.center_y = center_y
-        
-       
-        
+        ## defined end points vertical lignes and their saved values
         self.y1     = y + self.center_y
         self.save_y1= self.y1
@@ -405,13 +443,13 @@
         self.x2= self.center_x - delta
         self.save_x2 = self.x2
-        
-        self.color=color
-        
+        ## save the color of the line
+        self.color = color
+        ## the height of the rectangle
         self.half_height= math.fabs(y)
         self.save_half_height= math.fabs(y)
-        
+        ## the with of the rectangle
         self.half_width= math.fabs(self.x1- self.x2)/2
         self.save_half_width=math.fabs(self.x1- self.x2)/2
-        
+        ## Create marker 
         try:
             self.right_marker = self.axes.plot([self.x1],[0], linestyle='',
@@ -429,8 +467,8 @@
             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n"
             message += "Get the SVN version that is at least as recent as June 1, 2007"
-            
-            #raise "Version error", message
-            
-        # line
+            owner=self.base.base.parent
+            wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message))
+            
+        ## define the left and right lines of the rectangle
         self.right_line = self.axes.plot([self.x1,self.x1],[self.y1,self.y2],
                                       linestyle='-', marker='',
@@ -441,7 +479,7 @@
                                       color=self.color,
                                       visible=True)[0]
-    
-        self.npts = 30
-        self.has_move=False    
+        ## Flag to determine if the lines have moved
+        self.has_move=False  
+        ## connection the marker and draw the pictures  
         self.connect_markers([self.right_marker])
         self.update()
@@ -449,8 +487,16 @@
 
     def set_layer(self, n):
+        """
+            Allow adding plot to the same panel
+            @param n: the number of layer
+        """
         self.layernum = n
         self.update()
         
+        
     def clear(self):
+        """
+            Clear this figure and its markers
+        """
         self.clear_markers()
         try:
@@ -462,22 +508,28 @@
             for item in range(len(self.axes.lines)):
                 del self.axes.lines[0]
-        
-    def get_radius(self):
-        
-        return 0
+   
    
     def update(self,x1=None,x2=None, y1=None,y2=None,width=None, height=None, center=None):
         """
-        Draw the new roughness on the graph.
-        """
-        #print "self.half_height",self.half_height,self.half_width
+            Draw the new roughness on the graph.
+            @param x1: new maximum value of x coordinates
+            @param x2: new minimum value of x coordinates
+            @param y1: new maximum value of y coordinates
+            @param y2: new minimum value of y coordinates
+            @param width: is the width of the new rectangle
+            @param height: is the height of the new rectangle
+            @param center: provided x, y  coordinates of the center point
+        """
+        ## save the new height, witdh of the rectangle if given as a param
         if width!=None:
             self.half_width= width
         if height!=None:
             self.half_height= height
+        ## If new  center coordinates are given draw the rectangle 
+        ##given these value 
         if center!=None:
             self.center_x= center.x
             self.center_y= center.y
-            #print "vertical width",self.half_width ,self.center_x
+            
             self.x1 = self.half_width + self.center_x
             self.x2= -self.half_width + self.center_x
@@ -490,4 +542,5 @@
             self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2])
             return 
+        ## if x1, y1, y2, y3 are given draw the rectangle with this value
         if x1 !=None: 
             self.x1= x1
@@ -498,7 +551,5 @@
         if y2 !=None: 
             self.y2= y2
-        
-       
-       
+        ## Draw 2 vertical lines and a marker 
         self.right_marker.set(xdata=[self.x1],ydata=[self.center_y])
         self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2])
@@ -518,13 +569,17 @@
         
         self.save_half_height= self.half_height
-        #self.save_half_width = math.fabs(self.x1-self.x2)/2
         self.save_half_width = self.half_width
+        
         self.base.freeze_axes()
 
+
     def moveend(self, ev):
-        
+        """
+            After a dragging motion reset the flag self.has_move to False
+        """
         self.has_move=False
         self.base.moveend(ev)
             
+            
     def restore(self):
         """
@@ -538,6 +593,6 @@
         
         self.half_height= self.save_half_height
-        #self.half_width= math.fabs(self.x1-self.x2)/2
         self.half_width= self.save_half_width
+       
        
     def move(self, x, y, ev):
@@ -550,9 +605,13 @@
         
         self.half_width= math.fabs(self.x1-self.x2)/2
-        #print "Move vert: vertical width",self.half_width ,self.center_x
+        
         self.has_move=True
         self.base.base.update()
         
+        
     def set_cursor(self, x, y):
+        """
+            Update the figure given x and y 
+        """
         self.move(x, y, None)
         self.update()
@@ -560,4 +619,8 @@
         
     def get_params(self):
+        """
+            Store a copy of values of parameters of the slicer into a dictionary.
+            @return params: the dictionary created
+        """
         params = {}
         params["x"] = self.x1
@@ -567,9 +630,16 @@
     
     def set_params(self, params):
+        """
+            Receive a dictionary and reset the slicer with values contained 
+            in the values of the dictionary.
+            @param params: a dictionary containing name of slicer parameters and 
+            values the user assigned to the slicer.
+        """
         x = params["x"] 
         y = params["y"] 
         self.update(x=x, y=y, center_x=None,center_y=None)
 
-class Horizontal_DoubleLine(_BaseInteractor):
+
+class HorizontalDoubleLine(_BaseInteractor):
     """
          Select an annulus through a 2D plot
@@ -580,7 +650,8 @@
         
         _BaseInteractor.__init__(self, base, axes, color=color)
+        ## Initialization the class 
         self.markers = []
         self.axes = axes
-        # center
+        ## Center coordinates
         self.center_x = center_x
         self.center_y = center_y
@@ -623,8 +694,8 @@
             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n"
             message += "Get the SVN version that is at least as recent as June 1, 2007"
-            
-            #raise "Version error", message
-            
-        # line
+            owner=self.base.base.parent
+            wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message))
+            
+        # Define 2 horizotnal lines
         self.top_line = self.axes.plot([self.x1,-self.x1],[self.y1,self.y1],
                                       linestyle='-', marker='',
@@ -635,7 +706,7 @@
                                       color=self.color,
                                       visible=True)[0]
-    
-        self.npts = 30
+        ## Flag to determine if the lines have moved
         self.has_move=False    
+        ## connection the marker and draw the pictures 
         self.connect_markers([self.top_marker])
         self.update()
@@ -643,8 +714,16 @@
 
     def set_layer(self, n):
+        """
+            Allow adding plot to the same panel
+            @param n: the number of layer
+        """
         self.layernum = n
         self.update()
         
+        
     def clear(self):
+        """
+            Clear this figure and its markers
+        """
         self.clear_markers()
         try:
@@ -656,18 +735,24 @@
             for item in range(len(self.axes.lines)):
                 del self.axes.lines[0]
-        
-    def get_radius(self):
-        
-        return 0
+    
    
     def update(self,x1=None,x2=None, y1=None,y2=None,width=None,height=None, center=None):
         """
-        Draw the new roughness on the graph.
-        """
-        #print "self.half_width",self.half_width
-        if width!=None:
-            self.half_width= width
-        if height!=None:
+            Draw the new roughness on the graph.
+            @param x1: new maximum value of x coordinates
+            @param x2: new minimum value of x coordinates
+            @param y1: new maximum value of y coordinates
+            @param y2: new minimum value of y coordinates
+            @param width: is the width of the new rectangle
+            @param height: is the height of the new rectangle
+            @param center: provided x, y  coordinates of the center point
+        """
+        ## save the new height, witdh of the rectangle if given as a param
+        if width != None:
+            self.half_width = width
+        if height!= None:
             self.half_height= height
+        ## If new  center coordinates are given draw the rectangle 
+        ##given these value 
         if center!=None:
             self.center_x= center.x
@@ -684,4 +769,5 @@
             self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2])
             return 
+        ## if x1, y1, y2, y3 are given draw the rectangle with this value
         if x1 !=None: 
             self.x1= x1
@@ -692,6 +778,5 @@
         if y2 !=None: 
             self.y2= y2
-       
-             
+        ## Draw 2 vertical lines and a marker 
         self.top_marker.set(xdata=[self.center_x],ydata=[self.y1])
         self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1])
@@ -699,5 +784,4 @@
        
         
-        
     def save(self, ev):
         """
@@ -717,7 +801,10 @@
 
     def moveend(self, ev):
-        
+        """
+            After a dragging motion reset the flag self.has_move to False
+        """
         self.has_move=False
         self.base.moveend(ev)
+           
             
     def restore(self):
@@ -732,4 +819,5 @@
         self.half_height= self.save_half_height
         self.half_width= self.save_half_width
+        
         
     def move(self, x, y, ev):
@@ -744,5 +832,9 @@
         self.base.base.update()
         
+        
     def set_cursor(self, x, y):
+        """
+            Update the figure given x and y 
+        """
         self.move(x, y, None)
         self.update()
@@ -750,13 +842,25 @@
         
     def get_params(self):
+        """
+            Store a copy of values of parameters of the slicer into a dictionary.
+            @return params: the dictionary created
+        """
         params = {}
         params["x"] = self.x
         params["y"] = self.y
-        
         return params
     
+    
     def set_params(self, params):
+        """
+            Receive a dictionary and reset the slicer with values contained 
+            in the values of the dictionary.
+            @param params: a dictionary containing name of slicer parameters and 
+            values the user assigned to the slicer.
+        """
         x = params["x"] 
         y = params["y"] 
         self.update(x=x, y=y, center_x=None,center_y=None)
          
+         
+         
