From: <dg...@us...> - 2009-11-12 19:33:38
|
Revision: 385 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=385&view=rev Author: dgranda Date: 2009-11-12 19:33:28 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Removed widgets from vertical containers to avoid graphs multiplicity. Improved logging Modified Paths: -------------- pytrainer/trunk/pytrainer/gui/drawArea.py Modified: pytrainer/trunk/pytrainer/gui/drawArea.py =================================================================== --- pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-12 19:31:14 UTC (rev 384) +++ pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-12 19:33:28 UTC (rev 385) @@ -19,14 +19,14 @@ import matplotlib matplotlib.use('GTK') from matplotlib.figure import Figure -from matplotlib.backends.backend_gtk import FigureCanvasGTK +from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvasGTK +from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar +#from matplotlib.backends.backend_gtk import FigureCanvasGTK #from matplotlib.numerix import * import matplotlib.pyplot as plt #from pylab import * import logging -from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar - class DrawArea: def __init__(self, vbox = None, window = None): logging.debug('>>') @@ -45,7 +45,7 @@ return False #logging.debug('xvalues: '+str(xvalues)) #logging.debug('yvalues: '+str(yvalues)) - logging.info("Type: "+type+" | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) + logging.debug("Type: "+type+" | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) if type == "bars": self.drawBars(xvalues,yvalues,xlabel,ylabel,title,color) elif type == "plot": @@ -55,14 +55,15 @@ logging.debug('<<') def drawBars(self,xvalues,yvalues,xlabel,ylabel,title,color): - logging.debug('>>') - + logging.debug('>>') + + # ToDo: check why vertical container is shared for child in self.vbox.get_children(): - if self.vbox.get_children()[0] != child: - self.vbox.remove(child) + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) figure = Figure(figsize=(6,4), dpi=72) - canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea + #canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea xmod = 0.4 if len(xvalues) > 1: @@ -100,28 +101,33 @@ else: axis.set_title("%s" %(ylabel[0])) - canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea canvas.show() self.vbox.pack_start(canvas, True, True) toolbar = NavigationToolbar(canvas, self.window) self.vbox.pack_start(toolbar, False, False) + + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) + logging.debug('<<') def drawPlot(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): logging.debug('>>') + logging.debug('xlabel: '+str(xlabel)+' | ylabel: '+str(ylabel)+' | title: '+str(title)) + # ToDo: check why vertical container is shared for child in self.vbox.get_children(): - if self.vbox.get_children()[0] != child: - self.vbox.remove(child) + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) figure = Figure() + figure.clf() i = 0 for value in xvalues: if i<1: axis = figure.add_subplot(111) axis.plot(xvalues[i],yvalues[i], color=color[i]) - axis.grid(True) for tl in axis.get_yticklabels(): tl.set_color('%s' %color[i]) @@ -129,7 +135,7 @@ ax2 = axis.twinx() ax2.plot(xvalues[i], yvalues[i], color=color[i]) for tl in ax2.get_yticklabels(): - tl.set_color('%s' %color[i]) + tl.set_color('%s' %color[i]) axis.set_xlabel(xlabel[i]) i+=1 @@ -137,12 +143,17 @@ axis.set_title("%s vs %s" %(ylabel[0],ylabel[1])) else: axis.set_title("%s" %(ylabel[0])) - + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea canvas.show() + self.vbox.pack_start(canvas, True, True) toolbar = NavigationToolbar(canvas, self.window) self.vbox.pack_start(toolbar, False, False) + + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) + if title[0] == 'Stage Profile': figure.savefig('/tmp/stage.png', dpi=75) if title[0] == 'Heart Rate': @@ -151,12 +162,14 @@ def drawPie(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): logging.debug('>>') - + + # ToDo: check why vertical container is shared for child in self.vbox.get_children(): - if self.vbox.get_children()[0] != child: - self.vbox.remove(child) + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) figure = Figure(figsize=(6,4), dpi=72) + figure.clf() axis = figure.add_subplot(111) labels = ["rest"] @@ -188,9 +201,13 @@ fracs = [frac0,frac1,frac2,frac3,frac4, frac5] explode=(0, 0, 0, 0,0,0) axis.pie(fracs, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True) - + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea canvas.show() + + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) + self.vbox.pack_start(canvas, True, True) logging.debug('<<') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |