Don't allow the start date to be later than the end date. If it is, modify whichever...
[fpdb-dooglus.git] / pyfpdb / TourneyFilters.py
blob76bcd4397c50a8ae3caf27b0054d57e8ff0d57cb
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 #TODO: migrate all of this into Filters.py
20 import L10n
21 _ = L10n.get_translation()
23 import threading
24 import pygtk
25 pygtk.require('2.0')
26 import gtk
27 import gobject
28 #import os
29 #import sys
30 #from optparse import OptionParser
31 from time import gmtime, mktime, strftime, strptime
32 #import pokereval
34 import logging #logging has been set up in fpdb.py or HUD_main.py, use their settings:
35 log = logging.getLogger("filter")
37 #import Configuration
38 #import Database
39 #import SQL
40 import Charset
41 import Filters
43 class TourneyFilters(Filters.Filters):
44 def __init__(self, db, config, qdict, display = {}, debug=True):
45 self.debug = debug
46 self.db = db
47 self.cursor = db.cursor
48 self.sql = db.sql
49 self.conf = db.config
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()
57 self.day_start = 0
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)
66 # Outer Packing box
67 self.mainVBox = gtk.VBox(False, 0)
68 self.sw.add_with_viewport(self.mainVBox)
69 self.sw.show()
71 self.label = {}
72 self.callback = {}
74 self.make_filter()
75 #end def __init__
77 def __refresh(self, widget, entry): #identical with Filters
78 for w in self.mainVBox.get_children():
79 w.destroy()
80 self.make_filter()
81 #end def __refresh
83 def make_filter(self):
84 self.tourneyTypes = {}
85 #self.tourneys = {}
86 self.sites = {}
87 self.seats = {}
88 self.siteid = {}
89 self.heroes = {}
90 self.boxes = {}
91 self.toggles = {}
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()
97 if len(result) == 1:
98 self.siteid[site] = result[0][0]
99 else:
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
109 #self.sbGroups = {}
110 self.numTourneys = 0
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)
124 sitesFrame.add(vbox)
126 # Tourney types
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)
135 # Seats
136 seatsFrame = gtk.Frame()
137 seatsFrame.show()
138 vbox = gtk.VBox(False, 0)
139 self.sbSeats = {}
141 self.fillSeatsFrame(vbox, self.display)
142 seatsFrame.add(vbox)
144 # Date
145 dateFrame = gtk.Frame()
146 dateFrame.set_label_align(0.0, 0.0)
147 dateFrame.show()
148 vbox = gtk.VBox(False, 0)
150 self.fillDateFrame(vbox)
151 dateFrame.add(vbox)
153 # Buttons
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)
160 expand = 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:
173 playerFrame.hide()
174 if "Sites" not in self.display or self.display["Sites"] == False:
175 sitesFrame.hide()
176 if "Seats" not in self.display or self.display["Seats"] == False:
177 seatsFrame.hide()
178 if "Dates" not in self.display or self.display["Dates"] == False:
179 dateFrame.hide()
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:
183 self.Button2.hide()
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:
197 self.db.rollback()
198 #end def make_filter
199 #end class TourneyFilters