fix problem when using more recent gtk libraries (each refresh was adding an extra chart to the existing one)

This commit is contained in:
sqlcoder 2009-08-06 20:36:11 +01:00
parent 6de41be9c9
commit 0850721ecc

View File

@ -72,20 +72,19 @@ class GuiGraphViewer (threading.Thread):
self.mainHBox.show()
self.leftPanelBox = self.filters.get_vbox()
self.graphBox = gtk.VBox(False, 0)
self.graphBox.show()
self.hpane = gtk.HPaned()
self.hpane.pack1(self.leftPanelBox)
self.mainHBox.add(self.hpane)
# hierarchy: self.mainHBox / self.hpane / self.graphBox / self.canvas / self.fig / self.ax
self.graphBox = gtk.VBox(False, 0)
self.graphBox.show()
self.hpane.pack2(self.graphBox)
self.hpane.show()
self.mainHBox.add(self.hpane)
self.fig = None
#self.exportButton.set_sensitive(False)
self.fig = Figure(figsize=(5,4), dpi=100)
self.canvas = None
@ -125,14 +124,31 @@ class GuiGraphViewer (threading.Thread):
#end def get_vbox
def clearGraphData(self):
try:
try:
if self.canvas:
self.graphBox.remove(self.canvas)
except:
pass
if self.fig != None:
self.fig.clear()
self.fig = Figure(figsize=(5,4), dpi=100)
if self.canvas is not None:
self.canvas.destroy()
self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea
except:
err = traceback.extract_tb(sys.exc_info()[2])[-1]
print "***Error: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
raise
def generateGraph(self, widget, data):
print "generateGraph: start"
try:
self.clearGraphData()
print "after cleardata"
sitenos = []
playerids = []
@ -141,6 +157,7 @@ class GuiGraphViewer (threading.Thread):
heroes = self.filters.getHeroes()
siteids = self.filters.getSiteIds()
limits = self.filters.getLimits()
print "got filter data"
# Which sites are selected?
for site in sites:
if sites[site] == True:
@ -164,10 +181,12 @@ class GuiGraphViewer (threading.Thread):
return
#Set graph properties
print "add_subplot"
self.ax = self.fig.add_subplot(111)
#Get graph data from DB
starttime = time()
print "get line: playerids =", playerids, "sitenos =", sitenos, "limits =", limits
line = self.getRingProfitGraph(playerids, sitenos, limits)
print "Graph generated in: %s" %(time() - starttime)
@ -198,6 +217,10 @@ class GuiGraphViewer (threading.Thread):
self.canvas.show()
self.canvas.draw()
#self.exportButton.set_sensitive(True)
except:
err = traceback.extract_tb(sys.exc_info()[2])[-1]
print "***Error: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
#end of def showClicked
def getRingProfitGraph(self, names, sites, limits):