Don't expand the tourney filters either.
[fpdb-dooglus.git] / pyfpdb / TourneyFilters.py
blob3b070b9bc08ccb16da5551c688442331dfb4f47e
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 __set_num_tourneys(self, w, val):
84 try:
85 self.numTourneys = int(w.get_text())
86 except:
87 self.numTourneys = 0
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")
95 else:
96 self.boxes[entry].show()
97 widget.set_label("hide")
98 #end def __toggle_box
100 def make_filter(self):
101 self.tourneyTypes = {}
102 #self.tourneys = {}
103 self.sites = {}
104 self.seats = {}
105 self.siteid = {}
106 self.heroes = {}
107 self.boxes = {}
108 self.toggles = {}
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()
114 if len(result) == 1:
115 self.siteid[site] = result[0][0]
116 else:
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
126 #self.sbGroups = {}
127 self.numTourneys = 0
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)
141 sitesFrame.add(vbox)
143 # Tourney types
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)
152 # Seats
153 seatsFrame = gtk.Frame()
154 seatsFrame.show()
155 vbox = gtk.VBox(False, 0)
156 self.sbSeats = {}
158 self.fillSeatsFrame(vbox, self.display)
159 seatsFrame.add(vbox)
161 # Date
162 dateFrame = gtk.Frame()
163 dateFrame.set_label_align(0.0, 0.0)
164 dateFrame.show()
165 vbox = gtk.VBox(False, 0)
167 self.fillDateFrame(vbox)
168 dateFrame.add(vbox)
170 # Buttons
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)
177 expand = 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:
190 playerFrame.hide()
191 if "Sites" not in self.display or self.display["Sites"] == False:
192 sitesFrame.hide()
193 if "Seats" not in self.display or self.display["Seats"] == False:
194 seatsFrame.hide()
195 if "Dates" not in self.display or self.display["Dates"] == False:
196 dateFrame.hide()
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:
200 self.Button2.hide()
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:
214 self.db.rollback()
215 #end def make_filter
216 #end class TourneyFilters