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 #TODO: migrate all of this into Filters.py
21 _
= L10n
.get_translation()
30 #from optparse import OptionParser
31 from time
import gmtime
, mktime
, strftime
, strptime
34 import logging
#logging has been set up in fpdb.py or HUD_main.py, use their settings:
35 log
= logging
.getLogger("filter")
43 class TourneyFilters(Filters
.Filters
):
44 def __init__(self
, db
, config
, qdict
, display
= {}, debug
=True):
47 self
.cursor
= db
.cursor
50 self
.display
= display
52 self
.filterText
= {'playerstitle':_('Hero:'), 'sitestitle':_('Sites:'), 'seatstitle':_('Number of Players:'),
53 'seatsbetween':_('Between:'), 'seatsand':_('And:'), 'datestitle':_('Date:'),
54 'tourneyTypesTitle':_('Tourney Type')}
56 gen
= self
.conf
.get_general_params()
58 if 'day_start' in gen
:
59 self
.day_start
= float(gen
['day_start'])
61 self
.sw
= gtk
.ScrolledWindow()
62 self
.sw
.set_border_width(0)
63 self
.sw
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_AUTOMATIC
)
64 self
.sw
.set_size_request(370, 300)
67 self
.mainVBox
= gtk
.VBox(False, 0)
68 self
.sw
.add_with_viewport(self
.mainVBox
)
77 def __refresh(self
, widget
, entry
): #identical with Filters
78 for w
in self
.mainVBox
.get_children():
83 def __set_num_tourneys(self
, w
, val
):
85 self
.numTourneys
= int(w
.get_text())
88 print _("setting numTourneys:"), self
.numTourneys
89 #end def __set_num_tourneys
91 def __toggle_box(self
, widget
, entry
): #identical with Filters
92 if self
.boxes
[entry
].props
.visible
:
93 self
.boxes
[entry
].hide()
94 widget
.set_label("show")
96 self
.boxes
[entry
].show()
97 widget
.set_label("hide")
100 def make_filter(self
):
101 self
.tourneyTypes
= {}
110 for site
in self
.conf
.get_supported_sites():
111 #Get db site id for filtering later
112 self
.cursor
.execute(self
.sql
.query
['getSiteId'], (site
,))
113 result
= self
.db
.cursor
.fetchall()
115 self
.siteid
[site
] = result
[0][0]
117 print _("Either 0 or more than one site matched (%s) - EEK") % site
119 # For use in date ranges.
120 self
.start_date
= gtk
.Entry(max=12)
121 self
.end_date
= gtk
.Entry(max=12)
122 self
.start_date
.set_property('editable', False)
123 self
.end_date
.set_property('editable', False)
125 # For use in groups etc
129 playerFrame
= gtk
.Frame()
130 playerFrame
.set_label_align(0.0, 0.0)
131 vbox
= gtk
.VBox(False, 0)
133 self
.fillPlayerFrame(vbox
, self
.display
)
134 playerFrame
.add(vbox
)
136 sitesFrame
= gtk
.Frame()
137 sitesFrame
.set_label_align(0.0, 0.0)
138 vbox
= gtk
.VBox(False, 0)
140 self
.fillSitesFrame(vbox
)
144 tourneyTypesFrame
= gtk
.Frame()
145 tourneyTypesFrame
.set_label_align(0.0, 0.0)
146 tourneyTypesFrame
.show()
147 vbox
= gtk
.VBox(False, 0)
149 self
.fillTourneyTypesFrame(vbox
)
150 tourneyTypesFrame
.add(vbox
)
153 seatsFrame
= gtk
.Frame()
155 vbox
= gtk
.VBox(False, 0)
158 self
.fillSeatsFrame(vbox
, self
.display
)
162 dateFrame
= gtk
.Frame()
163 dateFrame
.set_label_align(0.0, 0.0)
165 vbox
= gtk
.VBox(False, 0)
167 self
.fillDateFrame(vbox
)
171 #self.Button1=gtk.Button("Unnamed 1")
172 #self.Button1.set_sensitive(False)
174 self
.Button2
=gtk
.Button("Unnamed 2")
175 self
.Button2
.set_sensitive(False)
178 self
.mainVBox
.pack_start(playerFrame
, expand
)
179 self
.mainVBox
.pack_start(sitesFrame
, expand
)
180 self
.mainVBox
.pack_start(seatsFrame
, expand
)
181 self
.mainVBox
.pack_start(dateFrame
, expand
)
182 self
.mainVBox
.pack_start(gtk
.VBox(False, 0))
183 #self.mainVBox.pack_start(self.Button1, expand)
184 self
.mainVBox
.pack_start(self
.Button2
, expand
)
186 self
.mainVBox
.show_all()
188 # Should do this cleaner
189 if "Heroes" not in self
.display
or self
.display
["Heroes"] == False:
191 if "Sites" not in self
.display
or self
.display
["Sites"] == False:
193 if "Seats" not in self
.display
or self
.display
["Seats"] == False:
195 if "Dates" not in self
.display
or self
.display
["Dates"] == False:
197 #if "Button1" not in self.display or self.display["Button1"] == False:
198 # self.Button1.hide()
199 if "Button2" not in self
.display
or self
.display
["Button2"] == False:
202 #if 'button1' in self.label and self.label['button1']:
203 # self.Button1.set_label( self.label['button1'] )
204 if 'button2' in self
.label
and self
.label
['button2']:
205 self
.Button2
.set_label( self
.label
['button2'] )
206 #if 'button1' in self.callback and self.callback['button1']:
207 # self.Button1.connect("clicked", self.callback['button1'], "clicked")
208 # self.Button1.set_sensitive(True)
209 if 'button2' in self
.callback
and self
.callback
['button2']:
210 self
.Button2
.connect("clicked", self
.callback
['button2'], "clicked")
211 self
.Button2
.set_sensitive(True)
213 # make sure any locks on db are released:
216 #end class TourneyFilters