From 391c42cdfff874cf9150dac24ddf305ac4c710cc Mon Sep 17 00:00:00 2001 From: steffen123 Date: Tue, 10 Aug 2010 00:35:02 +0200 Subject: [PATCH] add error handling for invalid entry into tourneNo field --- pyfpdb/GuiTourneyViewer.py | 77 +++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/pyfpdb/GuiTourneyViewer.py b/pyfpdb/GuiTourneyViewer.py index 777c8e9b..6881fac2 100644 --- a/pyfpdb/GuiTourneyViewer.py +++ b/pyfpdb/GuiTourneyViewer.py @@ -58,50 +58,48 @@ class GuiTourneyViewer (threading.Thread): #end def __init__ def displayClicked(self, widget, data=None): - self.prepare(10, 9) - - result=self.db.getTourneyInfo(self.siteName, self.tourneyNo) - x=0 - y=0 - for i in range(1,len(result[0])): - if y==9: - x+=2 - y=0 + if self.prepare(10, 9): + result=self.db.getTourneyInfo(self.siteName, self.tourneyNo) + x=0 + y=0 + for i in range(1,len(result[0])): + if y==9: + x+=2 + y=0 - label=gtk.Label(result[0][i]) - self.table.attach(label,x,x+1,y,y+1) + label=gtk.Label(result[0][i]) + self.table.attach(label,x,x+1,y,y+1) - if result[1][i]==None: - label=gtk.Label("N/A") - else: - label=gtk.Label(result[1][i]) - self.table.attach(label,x+1,x+2,y,y+1) + if result[1][i]==None: + label=gtk.Label("N/A") + else: + label=gtk.Label(result[1][i]) + self.table.attach(label,x+1,x+2,y,y+1) - y+=1 + y+=1 self.mainVBox.show_all() #def displayClicked def displayPlayerClicked(self, widget, data=None): - self.prepare(4, 5) - - result=self.db.getTourneyPlayerInfo(self.siteName, self.tourneyNo, self.playerName) - x=0 - y=0 - for i in range(1,len(result[0])): - if y==5: - x+=2 - y=0 + if self.prepare(4, 5): + result=self.db.getTourneyPlayerInfo(self.siteName, self.tourneyNo, self.playerName) + x=0 + y=0 + for i in range(1,len(result[0])): + if y==5: + x+=2 + y=0 - label=gtk.Label(result[0][i]) - self.table.attach(label,x,x+1,y,y+1) + label=gtk.Label(result[0][i]) + self.table.attach(label,x,x+1,y,y+1) - if result[1][i]==None: - label=gtk.Label("N/A") - else: - label=gtk.Label(result[1][i]) - self.table.attach(label,x+1,x+2,y,y+1) + if result[1][i]==None: + label=gtk.Label("N/A") + else: + label=gtk.Label(result[1][i]) + self.table.attach(label,x+1,x+2,y,y+1) - y+=1 + y+=1 self.mainVBox.show_all() #def displayPlayerClicked @@ -111,12 +109,21 @@ class GuiTourneyViewer (threading.Thread): #end def get_vbox def prepare(self, columns, rows): - self.tourneyNo=int(self.entryTourney.get_text()) + try: self.errorLabel.destroy() + except: pass + + try: + self.tourneyNo=int(self.entryTourney.get_text()) + except ValueError: + self.errorLabel=gtk.Label("invalid entry in tourney number - must enter numbers only") + self.mainVBox.add(self.errorLabel) + return False self.siteName=self.siteBox.get_active_text() self.playerName=self.entryPlayer.get_text() self.table.destroy() self.table=gtk.Table(columns=columns, rows=rows) self.mainVBox.add(self.table) + return True #end def readInfo #end class GuiTourneyViewer