Carbon Poker offers a 5 card stud game that wasn't listed here. It's not available...
[fpdb-dooglus.git] / pyfpdb / GuiTourneyViewer.py
blobab9857930dfb24c891548d4fd034ec447a03dc80
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 #Copyright 2010-2011 Steffen Schaumburg
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
18 import L10n
19 _ = L10n.get_translation()
21 import threading
22 import pygtk
23 pygtk.require('2.0')
24 import gtk
26 class GuiTourneyViewer (threading.Thread):
27 def __init__(self, config, db, sql, mainwin, debug=True):
28 self.db = db
30 self.mainVBox = gtk.VBox()
31 self.interfaceHBox = gtk.HBox()
32 self.mainVBox.pack_start(self.interfaceHBox, expand=False)
34 self.siteBox = gtk.combo_box_new_text()
35 for site in config.supported_sites:
36 self.siteBox.append_text(site)
37 self.siteBox.set_active(0)
38 self.interfaceHBox.add(self.siteBox)
40 label=gtk.Label(_("Enter the tourney number you want to display:"))
41 self.interfaceHBox.add(label)
43 self.entryTourney = gtk.Entry()
44 self.interfaceHBox.add(self.entryTourney)
46 self.displayButton = gtk.Button(_("_Display"))
47 self.displayButton.connect('clicked', self.displayClicked)
48 self.interfaceHBox.add(self.displayButton)
50 self.entryPlayer = gtk.Entry()
51 self.interfaceHBox.add(self.entryPlayer)
53 self.playerButton = gtk.Button(_("Display _Player"))
54 self.playerButton.connect('clicked', self.displayPlayerClicked)
55 self.interfaceHBox.add(self.playerButton)
57 self.table = gtk.Table(columns=10, rows=9)
58 self.mainVBox.add(self.table)
60 self.mainVBox.show_all()
61 #end def __init__
63 def displayClicked(self, widget, data=None):
64 if self.prepare(10, 9):
65 result=self.db.getTourneyInfo(self.siteName, self.tourneyNo)
66 if result[1] == None:
67 self.table.destroy()
68 self.errorLabel=gtk.Label(_("Tournament not found - please ensure you imported it and selected the correct site"))
69 self.mainVBox.add(self.errorLabel)
70 else:
71 x=0
72 y=0
73 for i in range(1,len(result[0])):
74 if y==9:
75 x+=2
76 y=0
78 label=gtk.Label(result[0][i])
79 self.table.attach(label,x,x+1,y,y+1)
81 if result[1][i]==None:
82 label=gtk.Label("N/A")
83 else:
84 label=gtk.Label(result[1][i])
85 self.table.attach(label,x+1,x+2,y,y+1)
87 y+=1
88 self.mainVBox.show_all()
89 #def displayClicked
91 def displayPlayerClicked(self, widget, data=None):
92 if self.prepare(4, 5):
93 result=self.db.getTourneyPlayerInfo(self.siteName, self.tourneyNo, self.playerName)
94 if result[1] == None:
95 self.table.destroy()
96 self.errorLabel=gtk.Label(_("Player or tourney not found - please ensure you imported it and selected the correct site"))
97 self.mainVBox.add(self.errorLabel)
98 else:
99 x=0
101 for i in range(1,len(result[0])):
102 if y==5:
103 x+=2
106 label=gtk.Label(result[0][i])
107 self.table.attach(label,x,x+1,y,y+1)
109 if result[1][i]==None:
110 label=gtk.Label(_("N/A"))
111 else:
112 label=gtk.Label(result[1][i])
113 self.table.attach(label,x+1,x+2,y,y+1)
115 y+=1
116 self.mainVBox.show_all()
117 #def displayPlayerClicked
119 def get_vbox(self):
120 """returns the vbox of this thread"""
121 return self.mainVBox
122 #end def get_vbox
124 def prepare(self, columns, rows):
125 try: self.errorLabel.destroy()
126 except: pass
128 try:
129 self.tourneyNo=int(self.entryTourney.get_text())
130 except ValueError:
131 self.errorLabel=gtk.Label(_("invalid entry in tourney number - must enter numbers only"))
132 self.mainVBox.add(self.errorLabel)
133 return False
134 self.siteName=self.siteBox.get_active_text()
135 self.playerName=self.entryPlayer.get_text()
137 self.table.destroy()
138 self.table=gtk.Table(columns=columns, rows=rows)
139 self.mainVBox.add(self.table)
140 return True
141 #end def readInfo
142 #end class GuiTourneyViewer