Index: guiframe/local_perspectives/plotting/SectorSlicer.py
===================================================================
--- guiframe/local_perspectives/plotting/SectorSlicer.py	(revision d955bf190082f518b5b97bfa21e5d38962be57f2)
+++ guiframe/local_perspectives/plotting/SectorSlicer.py	(revision 32c0841e02d6c59dd5e7872fdba98ea9afb790b9)
@@ -2,11 +2,12 @@
 import math
 import wx
-from copy import deepcopy
-
+#from copy import deepcopy
 from BaseInteractor import _BaseInteractor
-from sans.guicomm.events import NewPlotEvent, StatusEvent
-from sans.guicomm.events import SlicerParameterEvent,EVT_SLICER_PARS
-
+from sans.guicomm.events import NewPlotEvent
+from sans.guicomm.events import StatusEvent
+from sans.guicomm.events import SlicerParameterEvent
+from sans.guicomm.events import EVT_SLICER_PARS
 from sans.guiframe.dataFitting import Data1D
+
 
 class SectorInteractor(_BaseInteractor):
@@ -14,5 +15,5 @@
     Draw a sector slicer.Allow to performQ averaging on data 2D
     """
-    def __init__(self,base,axes,color='black', zorder=3):
+    def __init__(self, base, axes, color='black', zorder=3):
         
         _BaseInteractor.__init__(self, base, axes, color=color)
@@ -24,38 +25,36 @@
         
         ## compute qmax limit to reset the graph     
-        x = math.pow(max(self.base.data2D.xmax,math.fabs(self.base.data2D.xmin)),2)
-        y = math.pow(max(self.base.data2D.ymax,math.fabs(self.base.data2D.ymin)),2)
-        self.qmax= math.sqrt(x + y)
+        x = math.pow(max(self.base.data2D.xmax, 
+                         math.fabs(self.base.data2D.xmin)), 2)
+        y = math.pow(max(self.base.data2D.ymax, 
+                         math.fabs(self.base.data2D.ymin)), 2)
+        self.qmax = math.sqrt(x + y)
         ## Number of points on the plot
         self.nbins = 20
         ## Angle of the middle line
-        self.theta2= math.pi/3
+        self.theta2 = math.pi/3
         ## Absolute value of the Angle between the middle line and any side line
-        self.phi=math.pi/12
-        
+        self.phi = math.pi/12
         ## Middle line
-        self.main_line = LineInteractor(self, self.base.subplot,color='blue', zorder=zorder, r=self.qmax,
+        self.main_line = LineInteractor(self, self.base.subplot, color='blue', 
+                                        zorder=zorder, r=self.qmax,
                                            theta= self.theta2)
         self.main_line.qmax = self.qmax
         ## Right Side line
-        self.right_line= SideInteractor(self, self.base.subplot,color='black', zorder=zorder,
-                                     r=self.qmax,
-                                           phi= -1*self.phi,
-                                           theta2=self.theta2)
+        self.right_line = SideInteractor(self, self.base.subplot, color='black',
+                                          zorder=zorder, r=self.qmax,
+                                          phi=-1*self.phi, theta2=self.theta2)
         self.right_line.qmax = self.qmax
         ## Left Side line 
-        self.left_line= SideInteractor(self, self.base.subplot,color='black', zorder=zorder,
-                                     r=self.qmax,
-                                           phi= self.phi,
-                                           theta2=self.theta2)
+        self.left_line = SideInteractor(self, self.base.subplot, color='black',
+                                        zorder=zorder, r=self.qmax,
+                                           phi=self.phi, theta2=self.theta2)
         self.left_line.qmax = self.qmax
         ## draw the sector               
         self.update()
         self._post_data()
-
         ## Bind to slice parameter events
         self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS)
 
-
     def _onEVT_SLICER_PARS(self, event):
         """
@@ -66,5 +65,6 @@
         
         """
-        wx.PostEvent(self.base.parent, StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS"))
+        wx.PostEvent(self.base.parent,
+                     StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS"))
         event.Skip()
         if event.type == self.__class__.__name__:
@@ -99,26 +99,28 @@
         """
         # Update locations  
-        ## Check if the middle line was dragged and update the picture accordingly     
+        ## Check if the middle line was dragged and 
+        #update the picture accordingly     
         if self.main_line.has_move:
             self.main_line.update()
-            self.right_line.update( delta= -self.left_line.phi/2,
-                                    mline= self.main_line.theta )
-            self.left_line.update( delta = self.left_line.phi/2,
-                                   mline= self.main_line.theta )
+            self.right_line.update(delta=-self.left_line.phi/2,
+                                    mline=self.main_line.theta)
+            self.left_line.update(delta=self.left_line.phi/2,
+                                   mline=self.main_line.theta)
         ## Check if the left side has moved and update the slicer accordingly  
         if self.left_line.has_move:
             self.main_line.update()
-            self.left_line.update( phi=None, delta=None, mline=self.main_line ,
-                                  side=True, left=True )
-            self.right_line.update( phi= self.left_line.phi, delta= None,
-                                     mline= self.main_line, side= True,
-                                     left=False, right= True )
-        ## Check if the right side line has moved and update the slicer accordingly
+            self.left_line.update(phi=None, delta=None, mline=self.main_line,
+                                  side=True, left=True)
+            self.right_line.update(phi=self.left_line.phi, delta=None,
+                                     mline=self.main_line, side=True,
+                                     left=False, right=True)
+        ## Check if the right side line has moved and 
+        #update the slicer accordingly
         if self.right_line.has_move:
             self.main_line.update()
-            self.right_line.update( phi=None, delta=None, mline=self.main_line,
-                                   side=True, left=False, right=True )
-            self.left_line.update( phi=self.right_line.phi, delta=None,
-                                    mline=self.main_line, side=True, left=False )
+            self.right_line.update(phi=None, delta=None, mline=self.main_line,
+                                   side=True, left=False, right=True)
+            self.left_line.update(phi=self.right_line.phi, delta=None,
+                                    mline=self.main_line, side=True, left=False)
             
     def save(self, ev):
@@ -148,40 +150,37 @@
         phimin =  -self.left_line.phi + self.main_line.theta
         phimax = self.left_line.phi + self.main_line.theta
-       
-        if nbins==None:
+        if nbins == None:
             nbins = 20
-        sect = SectorQ(r_min= 0.0, r_max= radius ,
-                        phi_min= phimin + math.pi,
-                        phi_max= phimax + math.pi, nbins=nbins)
+        sect = SectorQ(r_min=0.0, r_max=radius,
+                        phi_min=phimin + math.pi,
+                        phi_max=phimax + math.pi, nbins=nbins)
      
         sector = sect(self.base.data2D)
         ##Create 1D data resulting from average
        
-        if hasattr(sector,"dxl"):
-            dxl= sector.dxl
+        if hasattr(sector, "dxl"):
+            dxl = sector.dxl
         else:
-            dxl= None
-        if hasattr(sector,"dxw"):
-            dxw= sector.dxw
+            dxl = None
+        if hasattr(sector, "dxw"):
+            dxw = sector.dxw
         else:
-            dxw= None
-       
-        new_plot = Data1D(x=sector.x,y=sector.y,dy=sector.dy)
+            dxw = None
+        new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy)
         new_plot.dxl = dxl
         new_plot.dxw = dxw
-        new_plot.name = "SectorQ" +"("+ self.base.data2D.name+")"
-        
-        new_plot.source=self.base.data2D.source
+        new_plot.name = "SectorQ" + "(" + self.base.data2D.name + ")"
+        new_plot.source = self.base.data2D.source
         #new_plot.info=self.base.data2D.info
         new_plot.interactive = True
-        new_plot.detector =self.base.data2D.detector
+        new_plot.detector = self.base.data2D.detector
         # If the data file does not tell us what the axes are, just assume...
         new_plot.xaxis("\\rm{Q}", 'A^{-1}')
-        new_plot.yaxis("\\rm{Intensity} ","cm^{-1}")
-        new_plot.group_id = "SectorQ"+self.base.data2D.name
-        new_plot.id = "SectorQ"+self.base.data2D.name
-        new_plot.is_data= True
+        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")
+        new_plot.group_id = "SectorQ" + self.base.data2D.name
+        new_plot.id = "SectorQ" + self.base.data2D.name
+        new_plot.is_data = True
         wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot,
-                                    title="SectorQ"+self.base.data2D.name ))
+                                    title="SectorQ" + self.base.data2D.name))
         
     def moveend(self, ev):
@@ -227,6 +226,7 @@
         ## angle of the middle line
         if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi):
-            raise ValueError,"Phi left and phi right are different %f, %f"%(self.left_line.phi, self.right_line.phi)
-        
+            msg = "Phi left and phi right are different"
+            msg += " %f, %f" % (self.left_line.phi, self.right_line.phi)
+            raise ValueError, msg
         params["Phi"] = self.main_line.theta
         params["Delta_Phi"] = math.fabs(self.left_line.phi)
@@ -243,12 +243,13 @@
         """
         main = params["Phi"] 
-        phi = math.fabs(params["Delta_Phi"] )
+        phi = math.fabs(params["Delta_Phi"])
         self.nbins = int(params["nbins"])
-        self.main_line.theta= main
+        self.main_line.theta = main
         ## Reset the slicer parameters
         self.main_line.update()
-        self.right_line.update( phi=phi,delta=None, mline=self.main_line,
-                               side=True, right=True )
-        self.left_line.update( phi=phi, delta=None, mline=self.main_line, side=True )
+        self.right_line.update(phi=phi, delta=None, mline=self.main_line,
+                               side=True, right=True)
+        self.left_line.update(phi=phi, delta=None, 
+                              mline=self.main_line, side=True)
         ## post the new corresponding data
         self._post_data(nbins=self.nbins)
@@ -278,6 +279,8 @@
     
     """
-    def __init__(self,base,axes,color='black', zorder=5, r=1.0,phi=math.pi/4, theta2= math.pi/3):
-        
+    def __init__(self, base, axes, color='black', zorder=5, r=1.0,
+                 phi=math.pi/4, theta2= math.pi/3):
+        """
+        """
         _BaseInteractor.__init__(self, base, axes, color=color)
         ## Initialize the class
@@ -287,5 +290,5 @@
         ## the x-axis  
         self.save_theta = theta2 + phi
-        self.theta= theta2 + phi
+        self.theta = theta2 + phi
         ## the value of the middle line angle with respect to the x-axis
         self.theta2 = theta2
@@ -294,38 +297,37 @@
         ## phi is the phase between the current line and the middle line
         self.phi = phi
-        
         ## End points polar coordinates
-        x1= self.radius*math.cos(self.theta)
-        y1= self.radius*math.sin(self.theta)
-        x2= -1*self.radius*math.cos(self.theta)
-        y2= -1*self.radius*math.sin(self.theta)
+        x1 = self.radius * math.cos(self.theta)
+        y1 = self.radius * math.sin(self.theta)
+        x2 = -1 * self.radius * math.cos(self.theta)
+        y2 = -1 * self.radius * math.sin(self.theta)
         ## defining a new marker 
         try:
-            self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='',
+            self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',
                                           marker='s', markersize=10,
                                           color=self.color, alpha=0.6,
                                           pickradius=5, label="pick", 
-                                          zorder=zorder, # Prefer this to other lines
-                                          visible=True)[0]
+                                          # Prefer this to other lines
+                                          zorder=zorder, visible=True)[0]
         except:
             self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='',
                                           marker='s', markersize=10,
                                           color=self.color, alpha=0.6,
-                                          label="pick", 
-                                          visible=True)[0]
-            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"
-            owner=self.base.base.parent
-            wx.PostEvent(owner, StatusEvent(status="sectorSlicer: %s"%message))
+                                          label="pick", visible=True)[0]
+            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST"
+            message += " VERSION OF MATPLOTLIB\n Get the SVN version that"
+            message += " is at least as recent as June 1, 2007"
+            owner = self.base.base.parent
+            wx.PostEvent(owner, 
+                         StatusEvent(status="sectorSlicer: %s" % message))
         
         ## Defining the current line
-        self.line = self.axes.plot([x1,x2],[y1,y2],
+        self.line = self.axes.plot([x1, x2], [y1, y2],
                                       linestyle='-', marker='',
-                                      color=self.color,
-                                      visible=True)[0]
+                                      color=self.color, visible=True)[0]
         ## Flag to differentiate the left line from the right line motion
-        self.left_moving=False
+        self.left_moving = False
         ## Flag to define a motion
-        self.has_move=False
+        self.has_move = False
         ## connecting markers and draw the picture
         self.connect_markers([self.inner_marker, self.line])
@@ -364,35 +366,33 @@
         """
         #print "update left or right ", self.has_move
-        self.left_moving=left
-        theta3=0
-        if phi !=None:
-            self.phi= phi
-        if delta==None:
+        self.left_moving = left
+        theta3 = 0
+        if phi != None:
+            self.phi = phi
+        if delta == None:
             delta = 0
         if  right:
-            self.phi = -1*math.fabs(self.phi)
+            self.phi = -1 * math.fabs(self.phi)
             #delta=-delta
         else:
-            self.phi =math.fabs(self.phi)
+            self.phi = math.fabs(self.phi)
         if side:
-            self.theta=  mline.theta + self.phi
+            self.theta = mline.theta + self.phi
                     
-        if mline!=None :
-            if delta!=0:
-                self.theta2 = mline+delta
+        if mline != None :
+            if delta != 0:
+                self.theta2 = mline + delta
             else:
                 self.theta2 = mline.theta
-        if delta==0:
-            theta3=self.theta+delta
+        if delta == 0:
+            theta3 = self.theta + delta
         else:
-            theta3=self.theta2+delta
-        
-        x1= self.radius*math.cos(theta3)
-        y1= self.radius*math.sin(theta3)
-        x2= -1*self.radius*math.cos(theta3)
-        y2= -1*self.radius*math.sin(theta3)
-       
-        self.inner_marker.set(xdata=[x1/2.5],ydata=[y1/2.5])
-        self.line.set(xdata=[x1,x2], ydata=[y1,y2])  
+            theta3 = self.theta2 + delta
+        x1 = self.radius * math.cos(theta3)
+        y1 = self.radius * math.sin(theta3)
+        x2 = -1 * self.radius * math.cos(theta3)
+        y2 = -1 * self.radius * math.sin(theta3)
+        self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5])
+        self.line.set(xdata=[x1, x2], ydata=[y1, y2])  
         
     def save(self, ev):
@@ -401,5 +401,5 @@
         can restore on Esc.
         """
-        self.save_theta= self.theta
+        self.save_theta = self.theta
         self.base.freeze_axes()
 
@@ -407,5 +407,5 @@
         """
         """
-        self.has_move=False
+        self.has_move = False
         self.base.moveend(ev)
             
@@ -420,24 +420,27 @@
         Process move to a new position, making sure that the move is allowed.
         """
-        self.theta= math.atan2(y,x)
-        self.has_move=True
+        self.theta = math.atan2(y, x)
+        self.has_move = True
         #ToDo: Simplify below
         if not self.left_moving:
-            if  self.theta2-self.theta <= 0 and self.theta2>0:#>= self.theta2:
+            if  self.theta2 - self.theta <= 0 and self.theta2 > 0:
+                self.restore()
+                return 
+            elif self.theta2 < 0 and self.theta < 0 and \
+                self.theta-self.theta2 >= 0:
+                self.restore()
+                return                             
+            elif  self.theta2 < 0 and self.theta > 0 and \
+                (self.theta2 + 2 * math.pi - self.theta) >= math.pi/2:
                 #print "my theta", self.theta
                 self.restore()
                 return 
-            elif self.theta2 < 0 and self.theta < 0 and self.theta-self.theta2 >= 0:
-                self.restore()
-                return                             
-            elif  self.theta2 < 0 and self.theta > 0 and self.theta2+2*math.pi-self.theta >=math.pi/2:
+            elif  self.theta2 < 0 and self.theta < 0 and \
+                (self.theta2 - self.theta) >= math.pi/2:
                 #print "my theta", self.theta
                 self.restore()
                 return 
-            elif  self.theta2 < 0 and self.theta < 0 and self.theta2-self.theta >=math.pi/2:
-                #print "my theta", self.theta
-                self.restore()
-                return 
-            elif self.theta2>0 and (self.theta2-self.theta >= math.pi/2 or (self.theta2-self.theta >= math.pi/2)):#<= self.theta2 -math.pi/2:
+            elif self.theta2 > 0 and (self.theta2-self.theta >= math.pi/2 or \
+                (self.theta2-self.theta >= math.pi/2)):
                 #print "self theta encore"
                 self.restore()
@@ -445,23 +448,24 @@
         else:
             #print "left move"
-            if  self.theta < 0 and self.theta+math.pi*2-self.theta2 <= 0:
+            if  self.theta < 0 and (self.theta + math.pi*2-self.theta2) <= 0:
                 self.restore()
                 return 
-            elif self.theta2 < 0 and self.theta-self.theta2 <= 0:
+            elif self.theta2 < 0 and (self.theta-self.theta2) <= 0:
                 self.restore()
                 return                             
-            elif  self.theta > 0 and self.theta-self.theta2 <=0:
+            elif  self.theta > 0 and self.theta-self.theta2 <= 0:
                 #print "my theta", self.theta
                 self.restore()
                 return 
-            elif self.theta-self.theta2 >= math.pi/2 or  (self.theta+math.pi*2-self.theta2 >= math.pi/2 and self.theta<0 and self.theta2>0):
+            elif self.theta-self.theta2 >= math.pi/2 or  \
+                ((self.theta + math.pi * 2 - self.theta2) >= math.pi/2 and \
+                 self.theta < 0 and self.theta2 > 0):
                 #print "self theta encore"
                 self.restore()
                 return 
             
-        self.phi= math.fabs(self.theta2 - self.theta)
-        if self.phi>math.pi:
-            self.phi= 2*math.pi-math.fabs(self.theta2 - self.theta)
-
+        self.phi = math.fabs(self.theta2 - self.theta)
+        if self.phi > math.pi:
+            self.phi = 2 * math.pi - math.fabs(self.theta2 - self.theta)
         self.base.base.update()
         
@@ -491,5 +495,6 @@
     Select an annulus through a 2D plot
     """
-    def __init__(self,base,axes,color='black', zorder=5, r=1.0,theta=math.pi/4):
+    def __init__(self, base, axes, color='black',
+                 zorder=5, r=1.0, theta=math.pi/4):
         """
         """
@@ -503,31 +508,31 @@
         self.scale = 10.0
         # Inner circle
-        x1= self.radius*math.cos(self.theta)
-        y1= self.radius*math.sin(self.theta)
-        x2= -1*self.radius*math.cos(self.theta)
-        y2= -1*self.radius*math.sin(self.theta)
+        x1 = self.radius * math.cos(self.theta)
+        y1 = self.radius * math.sin(self.theta)
+        x2 = -1*self.radius * math.cos(self.theta)
+        y2 = -1*self.radius * math.sin(self.theta)
         try:
             # Inner circle marker
-            self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='',
+            self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',
                                           marker='s', markersize=10,
                                           color=self.color, alpha=0.6,
                                           pickradius=5, label="pick", 
-                                          zorder=zorder, # Prefer this to other lines
+                                          # Prefer this to other lines
+                                          zorder=zorder, 
                                           visible=True)[0]
         except:
-            self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='',
+            self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',
                                           marker='s', markersize=10,
                                           color=self.color, alpha=0.6,
                                           label="pick", 
                                           visible=True)[0]
-            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"
-            
-        self.line = self.axes.plot([x1,x2],[y1,y2],
+            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION"
+            message += " OF MATPLOTLIB\n Get the SVN version that is at"
+            message += " least as recent as June 1, 2007"
+        self.line = self.axes.plot([x1, x2], [y1, y2],
                                       linestyle='-', marker='',
-                                      color=self.color,
-                                      visible=True)[0]
+                                      color=self.color, visible=True)[0]
         self.npts = 20
-        self.has_move=False
+        self.has_move = False
         self.connect_markers([self.inner_marker, self.line])
         self.update()
@@ -556,13 +561,13 @@
         """
        
-        if theta !=None:
-            self.theta= theta
-        x1= self.radius*math.cos(self.theta)
-        y1= self.radius*math.sin(self.theta)
-        x2= -1*self.radius*math.cos(self.theta)
-        y2= -1*self.radius*math.sin(self.theta)
-        
-        self.inner_marker.set(xdata=[x1/2.5],ydata=[y1/2.5])
-        self.line.set(xdata=[x1,x2], ydata=[y1,y2])  
+        if theta != None:
+            self.theta = theta
+        x1 = self.radius * math.cos(self.theta)
+        y1 = self.radius * math.sin(self.theta)
+        x2 = -1 * self.radius * math.cos(self.theta)
+        y2 = -1 * self.radius * math.sin(self.theta)
+        
+        self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5])
+        self.line.set(xdata=[x1, x2], ydata=[y1, y2])  
     
     def save(self, ev):
@@ -577,5 +582,5 @@
         """
         """
-        self.has_move=False
+        self.has_move = False
         self.base.moveend(ev)
             
@@ -590,6 +595,6 @@
         Process move to a new position, making sure that the move is allowed.
         """
-        self.theta= math.atan2(y,x)
-        self.has_move=True
+        self.theta = math.atan2(y, x)
+        self.has_move = True
         self.base.base.update()
         
