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 make_filter(self
):
84 self
.tourneyTypes
= {}
93 for site
in self
.conf
.get_supported_sites():
94 #Get db site id for filtering later
95 self
.cursor
.execute(self
.sql
.query
['getSiteId'], (site
,))
96 result
= self
.db
.cursor
.fetchall()
98 self
.siteid
[site
] = result
[0][0]
100 print _("Either 0 or more than one site matched (%s) - EEK") % site
102 # For use in date ranges.
103 self
.start_date
= gtk
.Entry(max=12)
104 self
.end_date
= gtk
.Entry(max=12)
105 self
.start_date
.set_property('editable', False)
106 self
.end_date
.set_property('editable', False)
108 # For use in groups etc
112 playerFrame
= gtk
.Frame()
113 playerFrame
.set_label_align(0.0, 0.0)
114 vbox
= gtk
.VBox(False, 0)
116 self
.fillPlayerFrame(vbox
, self
.display
)
117 playerFrame
.add(vbox
)
119 sitesFrame
= gtk
.Frame()
120 sitesFrame
.set_label_align(0.0, 0.0)
121 vbox
= gtk
.VBox(False, 0)
123 self
.fillSitesFrame(vbox
)
127 tourneyTypesFrame
= gtk
.Frame()
128 tourneyTypesFrame
.set_label_align(0.0, 0.0)
129 tourneyTypesFrame
.show()
130 vbox
= gtk
.VBox(False, 0)
132 self
.fillTourneyTypesFrame(vbox
)
133 tourneyTypesFrame
.add(vbox
)
136 seatsFrame
= gtk
.Frame()
138 vbox
= gtk
.VBox(False, 0)
141 self
.fillSeatsFrame(vbox
, self
.display
)
145 dateFrame
= gtk
.Frame()
146 dateFrame
.set_label_align(0.0, 0.0)
148 vbox
= gtk
.VBox(False, 0)
150 self
.fillDateFrame(vbox
)
154 #self.Button1=gtk.Button("Unnamed 1")
155 #self.Button1.set_sensitive(False)
157 self
.Button2
=gtk
.Button("Unnamed 2")
158 self
.Button2
.set_sensitive(False)
161 self
.mainVBox
.pack_start(playerFrame
, expand
)
162 self
.mainVBox
.pack_start(sitesFrame
, expand
)
163 self
.mainVBox
.pack_start(seatsFrame
, expand
)
164 self
.mainVBox
.pack_start(dateFrame
, expand
)
165 self
.mainVBox
.pack_start(gtk
.VBox(False, 0))
166 #self.mainVBox.pack_start(self.Button1, expand)
167 self
.mainVBox
.pack_start(self
.Button2
, expand
)
169 self
.mainVBox
.show_all()
171 # Should do this cleaner
172 if "Heroes" not in self
.display
or self
.display
["Heroes"] == False:
174 if "Sites" not in self
.display
or self
.display
["Sites"] == False:
176 if "Seats" not in self
.display
or self
.display
["Seats"] == False:
178 if "Dates" not in self
.display
or self
.display
["Dates"] == False:
180 #if "Button1" not in self.display or self.display["Button1"] == False:
181 # self.Button1.hide()
182 if "Button2" not in self
.display
or self
.display
["Button2"] == False:
185 #if 'button1' in self.label and self.label['button1']:
186 # self.Button1.set_label( self.label['button1'] )
187 if 'button2' in self
.label
and self
.label
['button2']:
188 self
.Button2
.set_label( self
.label
['button2'] )
189 #if 'button1' in self.callback and self.callback['button1']:
190 # self.Button1.connect("clicked", self.callback['button1'], "clicked")
191 # self.Button1.set_sensitive(True)
192 if 'button2' in self
.callback
and self
.callback
['button2']:
193 self
.Button2
.connect("clicked", self
.callback
['button2'], "clicked")
194 self
.Button2
.set_sensitive(True)
196 # make sure any locks on db are released:
199 #end class TourneyFilters