Index: guitools/PlotPanel.py
===================================================================
--- guitools/PlotPanel.py	(revision 15f0e943ddf20630e6bf46d998576dc36e64473d)
+++ guitools/PlotPanel.py	(revision 52b1f77b9587273e72c19ecf88a3e5f2a75af750)
@@ -1,3 +1,3 @@
-import wx
+import wx.lib.newevent
 import matplotlib
 matplotlib.interactive(False)
@@ -7,9 +7,11 @@
 from matplotlib.figure import Figure
 import os
-
+import fittings
 from canvas import FigureCanvas
 #TODO: make the plottables interactive
+
 from plottables import Graph
-
+#(FuncFitEvent, EVT_FUNC_FIT) = wx.lib.newevent.NewEvent()
+import math,pylab
 def show_tree(obj,d=0):
     """Handy function for displaying a tree of graph objects"""
@@ -29,5 +31,5 @@
         dpi = None, **kwargs):
         wx.Panel.__init__(self, parent, id = id, **kwargs)
-
+        self.parent = parent
         self.figure = Figure(None, dpi)
         #self.figure = pylab.Figure(None, dpi)
@@ -42,5 +44,5 @@
         self.figure.subplots_adjust(left=.2, bottom=.2)
         self.yscale = 'linear'
-
+        self.xscale = 'linear'
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(self.canvas,1,wx.EXPAND)
@@ -49,10 +51,78 @@
         # Graph object to manage the plottables
         self.graph = Graph()
-        
+        #self.Bind(EVT_FUNC_FIT, self.onFitRange)
         self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu)
-
+        #self.Bind(EVT_PROPERTY, self._onEVT_FUNC_PROPERTY)
         # Define some constants
         self.colorlist = ['b','g','r','c','m','y']
         self.symbollist = ['o','x','^','v','<','>','+','s','d','D','h','H','p']
+        #User scale
+        self.xscales =""
+        self.yscales =""
+        # keep track if the previous transformation
+        self.prevXtrans ="x"
+        self.prevYtrans ="Log(y)"
+        
+    def onFitting(self, event): 
+        list =[]
+        list = self.graph.returnPlottable()
+        from fitDialog import LinearFit
+        
+        print len(list)
+        if len(list.keys())>0:
+            first_item = list.keys()[0]
+            print first_item, list[first_item].__class__.__name__
+            dlg = LinearFit( None, first_item, self.onFitDisplay, -1, 'Fitting')
+            dlg.ShowModal() 
+
+    def _onProperties(self, event):
+       
+        from PropertyDialog import Properties
+        dial = Properties(self, -1, 'Properties')
+        if dial.ShowModal() == wx.ID_OK:
+            self.xscales, self.yscales = dial.getValues()
+            self._onEVT_FUNC_PROPERTY()
+        dial.Destroy()
+            
+    def toX(self,x):
+        return x
+    
+    def toX2(self,x):
+        """
+            Calculate x^(2)
+            @param x: float value
+        """
+        return math.pow(x,2)
+    def fromX2(self,x):
+         """
+            Calculate square root of x
+            @param x: float value
+         """
+         if x >=0 :
+             return math.sqrt(x)
+         else:
+            return 0
+    def toLogXY(self,x):
+        """
+            calculate log x
+            @param x: float value
+        """
+        if x > 0:
+            return math.log(x)
+        else:
+            return 0
+    def fromLogXY(self,x):
+        """
+            Calculate e^(x)
+            @param x: float value
+        """
+        if x.__class__.__name__ == 'list':
+            temp =[]
+            for x_i in x:
+                temp.append(math.exp(x_i))
+            return temp
+        else:
+            return math.exp(x)
+    
 
     def set_yscale(self, scale='linear'):
@@ -62,4 +132,11 @@
     def get_yscale(self):
         return self.yscale
+    
+    def set_xscale(self, scale='linear'):
+        self.subplot.set_xscale(scale)
+        self.xscale = scale
+        
+    def get_xscale(self):
+        return self.xscale
 
     def SetColor(self, rgbtuple):
@@ -120,5 +197,19 @@
         slicerpop.Append(313,'&Save image', 'Save image as PNG')
         wx.EVT_MENU(self, 313, self.onSaveImage)
-
+        slicerpop.Append(316, '&Load 1D data file')
+       
+        wx.EVT_MENU(self, 314, self.onSave1DData)
+        wx.EVT_MENU(self, 316, self._onLoad1DData)
+        slicerpop.AppendSeparator()
+        slicerpop.Append(315, '&Properties')
+        
+        slicerpop.AppendSeparator()
+        slicerpop.Append(317, '&Linear Fit')
+       
+        wx.EVT_MENU(self, 314, self.onSave1DData)
+        wx.EVT_MENU(self, 316, self._onLoad1DData)
+        wx.EVT_MENU(self, 315, self._onProperties)
+        wx.EVT_MENU(self, 317, self.onFitting)
+       
         pos = event.GetPosition()
         pos = self.ScreenToClient(pos)
@@ -199,4 +290,5 @@
         """Draw markers with error bars"""
         self.subplot.set_yscale('linear')
+        self.subplot.set_xscale('linear')
         # Convert tuple (lo,hi) to array [(x-lo),(hi-x)]
         if dx != None and type(dx) == type(()):
@@ -209,13 +301,12 @@
                                    marker=self._symbol(symbol),linestyle='',label=label)
         else:
-            col = self._color(color)
             self.subplot.errorbar(x, y, yerr=dy, xerr=None,
-             ecolor=col, capsize=2,linestyle='', barsabove=False,
+             ecolor=self._color(color), capsize=2,linestyle='', barsabove=False,
              marker=self._symbol(symbol),
              lolims=False, uplims=False,
-             xlolims=False, xuplims=False,label=label,
-             mec = col, mfc = col)
+             xlolims=False, xuplims=False,label=label)
             
         self.subplot.set_yscale(self.yscale)
+        self.subplot.set_xscale(self.xscale)
 
     def curve(self,x,y,dy=None,color=0,symbol=0,label=None):
@@ -223,8 +314,10 @@
         c = self._color(color)
         self.subplot.set_yscale('linear')
+        self.subplot.set_xscale('linear')
         
         hlist = self.subplot.plot(x,y,color=c,marker='',linestyle='-',label=label)
         
         self.subplot.set_yscale(self.yscale)
+        self.subplot.set_xscale(self.xscale)
 
     def _color(self,c):
@@ -235,8 +328,90 @@
         """Return a particular symbol"""
         return self.symbollist[s%len(self.symbollist)]
-
-
-    
-
+   
+    def _onEVT_FUNC_PROPERTY(self):
+        """
+             Receive the scale from myDialog and set the scale
+        """ 
+        list =[]
+        list = self.graph.returnPlottable()
+        for item in list:
+            if ( self.xscales=="x" ):
+                if self.prevXtrans == "x^(2)":
+                    item.transform_x(  self.fromX2, self.errFunc )
+                #elif self.prevXtrans == "Log(x)"
+                    #item.transform_x(  self.fromLogXY,self.errFunc )
+                print "Values of  x",item.x[0:5]
+                print "Values of view x",item.view.x[0:5]
+                self.set_xscale("linear")
+                self.graph.xaxis('\\rm{q} ', 'A^{-1}')
+                
+            if ( self.xscales=="x^(2)" ):
+                #if self.prevXtrans == "Log(x)":
+                    #item.transform_x(  self.fromLogXY, self.errFunc )
+                if  self.prevXtrans != "x^(2)":
+                    item.transform_x(  self.toX2, self.errFunc )
+                    print "Values of  x",item.x[0:5]
+                    print "Values of view x^(2)",item.view.x[0:5]
+                self.set_xscale('linear')
+                self.graph.xaxis('\\rm{q^{2}} ', 'A^{-2}')
+                
+            if (self.xscales=="Log(x)" ):
+                if self.prevXtrans == "x^(2)":
+                    item.transform_x(  self.fromX2, self.errFunc )
+                #elif self.prevXtrans == "Log(x)":
+                    #item.transform_x(  self.toLogXY, self.errFunc )
+                #self.set_xscale("linear")
+                self.set_xscale('log')
+                self.graph.xaxis('\\rm{log(q)} ', 'A^{-1}')
+                
+            if ( self.yscales=="y" ):
+                if self.prevYtrans == "y^(2)":
+                    item.transform_y(  self.toX2, self.errFunc )
+                #elif self.prevXtrans == "Log(y)"
+                    #item.transform_y(  self.fromLogXY.errFunc )   
+                self.set_yscale("linear")
+                self.graph.yaxis("\\rm{Intensity} ","cm^{-1}")
+                
+            if ( self.yscales=="Log(y)" ):
+                if self.prevYtrans == "y^(2)":
+                     item.transform_y(  self.fromX2, self.errFunc )
+                #elif self.prevYtrans != "Log(y)":
+                    #item.transform_y(  self.toLogXY, self.errFunc )
+                #self.set_yscale("linear")  
+                self.set_yscale("log")  
+                self.graph.yaxis("\\rm{Intensity} ","cm^{-1}")
+                
+            if ( self.yscales=="y^(2)" ):
+                 #if self.prevYtrans == "Log(y)":
+                       #item.transform_y(  self.fromLogXY, self.errFunc )
+                if self.prevYtrans != "y^(2)":
+                     item.transform_y(  self.toX2, self.errFunc )   
+                self.set_yscale("linear")
+                self.graph.yaxis("\\rm{Intensity^{2}} ","cm^{-2}")
+            item.set_View(item.x,item.y) 
+             
+        self.prevXtrans = self.xscales 
+        self.prevYtrans = self.yscales  
+       
+        self.graph.render(self)
+        self.subplot.figure.canvas.draw_idle()
+        
+    def errFunc(self,x):
+        """
+            calculate log x
+            @param x: float value
+        """
+        if x >=0:
+            return math.sqrt(x)
+        else:
+            return 0
+   
+                
+    def onFitDisplay(self, plottable):
+        self.graph.add(plottable)
+        self.graph.render(self)
+        self.subplot.figure.canvas.draw_idle()
+      
+    
 class NoRepaintCanvas(FigureCanvasWxAgg):
     """We subclass FigureCanvasWxAgg, overriding the _onPaint method, so that
Index: guitools/plottables.py
===================================================================
--- guitools/plottables.py	(revision 8e4516fa0037d548b0d302704898c46be3a20629)
+++ guitools/plottables.py	(revision 52b1f77b9587273e72c19ecf88a3e5f2a75af750)
@@ -199,4 +199,5 @@
         
         return labels
+    
     def returnPlottable(self):
         return self.plottables
@@ -335,4 +336,13 @@
     def __init__(self):
         self.view = View()
+    def set_View(self,x,y):
+        self.x= x
+        self.y = y
+        self.dx= x
+        self.dy = y
+        self.reset_view()
+        
+    def reset_view(self):
+        self.view = self.View(self.x, self.y, self.dx, self.dy)
     
     def render(self,plot):
@@ -344,5 +354,5 @@
         that it makes sense.
         """
-        
+       
         plot.xaxis(self._xaxis, self._xunit)
         plot.yaxis(self._yaxis, self._yunit)
@@ -400,4 +410,5 @@
             for i in range(len(x)):
                  self.x[i] = func(x[i])
+            for i in range(len(dx)):
                  self.dx[i] = errfunc(dx[i])
                           
@@ -416,13 +427,12 @@
                 raise ValueError, "Plottable.View: Given y and dy are not of the same length"
             
-            self.y  = deepcopy(y)
-            self.dy = deepcopy(dy)
+            self.y  = copy.deepcopy(y)
+            self.dy = copy.deepcopy(dy)
             
             for i in range(len(y)):
                  self.y[i] = func(y[i])
+            for i in range(len(dy)):
                  self.dy[i] = errfunc(dy[i])
-                 
-            
-
+     
 class Data1D(Plottable):
     """Data plottable: scatter plot of x,y with errors in x and y.
@@ -444,8 +454,8 @@
         
         self.view = self.View(self.x, self.y, self.dx, self.dy)
-
+        
     def render(self,plot,**kw):
         plot.points(self.view.x,self.view.y,dx=self.view.dx,dy=self.view.dy,**kw)
-
+   
     def changed(self):
         return False
@@ -524,5 +534,5 @@
     graph.add(Theory1D(x,y,dy=dy))
 
-    return graph
+    return graph 
 
 def demo_plotter(graph):
