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.
19 _
= L10n
.get_translation()
26 class GuiTourneyViewer (threading
.Thread
):
27 def __init__(self
, config
, db
, sql
, mainwin
, debug
=True):
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()
63 def displayClicked(self
, widget
, data
=None):
64 if self
.prepare(10, 9):
65 result
=self
.db
.getTourneyInfo(self
.siteName
, self
.tourneyNo
)
68 self
.errorLabel
=gtk
.Label(_("Tournament not found - please ensure you imported it and selected the correct site"))
69 self
.mainVBox
.add(self
.errorLabel
)
73 for i
in range(1,len(result
[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")
84 label
=gtk
.Label(result
[1][i
])
85 self
.table
.attach(label
,x
+1,x
+2,y
,y
+1)
88 self
.mainVBox
.show_all()
91 def displayPlayerClicked(self
, widget
, data
=None):
92 if self
.prepare(4, 5):
93 result
=self
.db
.getTourneyPlayerInfo(self
.siteName
, self
.tourneyNo
, self
.playerName
)
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
)
101 for i
in range(1,len(result
[0])):
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"))
112 label
=gtk
.Label(result
[1][i
])
113 self
.table
.attach(label
,x
+1,x
+2,y
,y
+1)
116 self
.mainVBox
.show_all()
117 #def displayPlayerClicked
120 """returns the vbox of this thread"""
124 def prepare(self
, columns
, rows
):
125 try: self
.errorLabel
.destroy()
129 self
.tourneyNo
=int(self
.entryTourney
.get_text())
131 self
.errorLabel
=gtk
.Label(_("invalid entry in tourney number - must enter numbers only"))
132 self
.mainVBox
.add(self
.errorLabel
)
134 self
.siteName
=self
.siteBox
.get_active_text()
135 self
.playerName
=self
.entryPlayer
.get_text()
138 self
.table
=gtk
.Table(columns
=columns
, rows
=rows
)
139 self
.mainVBox
.add(self
.table
)
142 #end class GuiTourneyViewer