From 3a1ddad58ff7b06c154c2abce3cd9b110f480bcb Mon Sep 17 00:00:00 2001 From: Worros Date: Thu, 11 Dec 2008 23:55:03 +0900 Subject: [PATCH] Fix crasher in Grapher if no hands returned. Should alert user or at least draw something in right pane. --- pyfpdb/GuiGraphViewer.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index d50f6b6a..94732295 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -83,22 +83,24 @@ class GuiGraphViewer (threading.Thread): self.ax.set_xlabel("Hands", fontsize = 12) self.ax.set_ylabel("$", fontsize = 12) self.ax.grid(color='g', linestyle=':', linewidth=0.2) - #This line will crash if no hands exist in the query. - text = "All Hands, " + sitename + str(name) + "\nProfit: $" + str(line[-1]) + "\nTotal Hands: " + str(len(line)) + if(line == None): + #TODO: Do something useful like alert user + print "No hands returned by graph query" + else: + text = "All Hands, " + sitename + str(name) + "\nProfit: $" + str(line[-1]) + "\nTotal Hands: " + str(len(line)) - self.ax.annotate(text, - xy=(10, -10), - xycoords='axes points', - horizontalalignment='left', verticalalignment='top', - fontsize=10) + self.ax.annotate(text, + xy=(10, -10), + xycoords='axes points', + horizontalalignment='left', verticalalignment='top', + fontsize=10) + #Draw plot + self.ax.plot(line,) - #Draw plot - self.ax.plot(line,) - - self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea - self.graphBox.add(self.canvas) - self.canvas.show() + self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea + self.graphBox.add(self.canvas) + self.canvas.show() #end of def showClicked def getRingProfitGraph(self, name, site): @@ -106,6 +108,9 @@ class GuiGraphViewer (threading.Thread): #returns (HandId,Winnings,Costs,Profit) winnings = self.db.cursor.fetchall() + if(winnings == ()): + return None + y=map(lambda x:float(x[3]), winnings) line = cumsum(y) return line/100