-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGuiTourneyViewer.py
138 lines (114 loc) · 5.04 KB
/
GuiTourneyViewer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gtk
#Copyright 2010-2011 Steffen Schaumburg
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, version 3 of the License.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU Affero General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#In the "official" distribution you can find the license in agpl-3.0.txt.
import L10n
_ = L10n.get_translation()
class GuiTourneyViewer:
def __init__(self, config, db, sql, mainwin, debug=True):
self.db = db
self.mainVBox = gtk.VBox()
self.interfaceHBox = gtk.HBox()
self.mainVBox.pack_start(self.interfaceHBox, expand=False)
self.siteBox = gtk.combo_box_new_text()
for site in config.supported_sites:
self.siteBox.append_text(site)
self.siteBox.set_active(0)
self.interfaceHBox.add(self.siteBox)
label=gtk.Label(_("Enter the tourney number you want to display:"))
self.interfaceHBox.add(label)
self.entryTourney = gtk.Entry()
self.interfaceHBox.add(self.entryTourney)
self.displayButton = gtk.Button(_("Display"))
self.displayButton.connect('clicked', self.displayClicked)
self.interfaceHBox.add(self.displayButton)
self.entryPlayer = gtk.Entry()
self.interfaceHBox.add(self.entryPlayer)
self.playerButton = gtk.Button(_("Display Player"))
self.playerButton.connect('clicked', self.displayPlayerClicked)
self.interfaceHBox.add(self.playerButton)
self.table = gtk.Table(columns=10, rows=9)
self.mainVBox.add(self.table)
self.mainVBox.show_all()
#end def __init__
def displayClicked(self, widget, data=None):
if self.prepare(10, 9):
result=self.db.getTourneyInfo(self.siteName, self.tourneyNo)
if result[1] == None:
self.table.destroy()
self.errorLabel=gtk.Label(_("Tournament not found.") + " " + _("Please ensure you imported it and selected the correct site."))
self.mainVBox.add(self.errorLabel)
else:
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)
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
self.mainVBox.show_all()
#def displayClicked
def displayPlayerClicked(self, widget, data=None):
if self.prepare(4, 5):
result=self.db.getTourneyPlayerInfo(self.siteName, self.tourneyNo, self.playerName)
if result[1] == None:
self.table.destroy()
self.errorLabel=gtk.Label(_("Player or tournament not found.") + " " + _("Please ensure you imported it and selected the correct site."))
self.mainVBox.add(self.errorLabel)
else:
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)
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
self.mainVBox.show_all()
#def displayPlayerClicked
def get_vbox(self):
"""returns the vbox of this thread"""
return self.mainVBox
#end def get_vbox
def prepare(self, columns, rows):
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