Add 'Currencies' filter to the ring player stats viewer.
[fpdb-dooglus.git] / pyfpdb / Filters.py
bloba1b50745c36f087299cc3c23d4d7db3a94e6f17c
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 #Copyright 2008-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 import L10n
19 _ = L10n.get_translation()
21 import threading
22 import pygtk
23 pygtk.require('2.0')
24 import gtk
25 import os
26 import sys
27 from optparse import OptionParser
28 from time import gmtime, mktime, strftime, strptime, localtime
29 import gobject
30 #import pokereval
32 import logging
33 # logging has been set up in fpdb.py or HUD_main.py, use their settings:
34 log = logging.getLogger("filter")
36 import Configuration
37 import Database
38 import SQL
39 import Charset
40 import Filters
42 class Filters(threading.Thread):
43 def __init__(self, db, config, qdict, display = {}, debug=True):
44 # config and qdict are now redundant
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.gameName = {"27_1draw" : _("Single Draw 2-7 Lowball")
53 ,"27_3draw" : _("Triple Draw 2-7 Lowball")
54 ,"5studhi" : _("5 Card Stud")
55 ,"badugi" : _("Badugi")
56 ,"fivedraw" : _("5 Card Draw")
57 ,"holdem" : _("Hold'em")
58 ,"omahahi" : _("Omaha")
59 ,"omahahilo" : _("Omaha Hi/Lo")
60 ,"razz" : _("Razz")
61 ,"studhi" : _("7 Card Stud")
62 ,"studhilo" : _("7 Card Stud Hi/Lo")
65 self.currencyName = {"USD" : _("US Dollars")
66 ,"EUR" : _("Euros")
67 ,"T$" : _("Tournament Dollars")
68 ,"play": _("Play Money")
71 # text used on screen stored here so that it can be configured
72 self.filterText = {'limitsall':_('All'), 'limitsnone':_('None'), 'limitsshow':_('Show _Limits')
73 ,'gamesall':_('All'), 'gamesnone':_('None')
74 ,'currenciesall':_('All'), 'currenciesnone':_('None')
75 ,'seatsbetween':_('Between:'), 'seatsand':_('And:'), 'seatsshow':_('Show Number of _Players')
76 ,'playerstitle':_('Hero:'), 'sitestitle':(_('Sites')+':'), 'gamestitle':(_('Games')+':')
77 ,'limitstitle':_('Limits:'), 'seatstitle':_('Number of Players:')
78 ,'groupstitle':_('Grouping:'), 'posnshow':_('Show Position Stats')
79 ,'datestitle':_('Date:'), 'currenciestitle':(_('Currencies')+':')
80 ,'groupsall':_('All Players')
81 ,'limitsFL':'FL', 'limitsNL':'NL', 'limitsPL':'PL', 'limitsCN':'CAP', 'ring':_('Ring'), 'tour':_('Tourney')
84 gen = self.conf.get_general_params()
85 self.day_start = 0
87 if 'day_start' in gen:
88 self.day_start = float(gen['day_start'])
91 self.sw = gtk.ScrolledWindow()
92 self.sw.set_border_width(0)
93 self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
94 self.sw.set_size_request(235, 300)
97 # Outer Packing box
98 self.mainVBox = gtk.VBox(False, 0)
99 self.sw.add_with_viewport(self.mainVBox)
100 self.sw.show()
101 #print(_("DEBUG:") + _("New packing box created!"))
103 self.found = {'nl':False, 'fl':False, 'pl':False, 'cn':False, 'ring':False, 'tour':False}
104 self.label = {}
105 self.callback = {}
107 self.make_filter()
109 def make_filter(self):
110 self.sites = {}
111 self.games = {}
112 self.limits = {}
113 self.seats = {}
114 self.groups = {}
115 self.siteid = {}
116 self.heroes = {}
117 self.boxes = {}
118 self.toggles = {}
119 self.graphops = {}
120 self.currencies = {}
122 for site in self.conf.get_supported_sites():
123 #Get db site id for filtering later
124 self.cursor.execute(self.sql.query['getSiteId'], (site,))
125 result = self.db.cursor.fetchall()
126 if len(result) == 1:
127 self.siteid[site] = result[0][0]
128 else:
129 print _("Either 0 or more than one site matched (%s) - EEK") % site
131 # For use in date ranges.
132 self.start_date = gtk.Entry(max=12)
133 self.start_date.set_width_chars(12)
134 self.end_date = gtk.Entry(max=12)
135 self.end_date.set_width_chars(12)
136 self.start_date.set_property('editable', False)
137 self.end_date.set_property('editable', False)
139 # For use in groups etc
140 self.sbGroups = {}
141 self.numHands = 0
143 # for use in graphops
144 # dspin = display in '$' or 'B'
145 self.graphops['dspin'] = "$"
146 self.graphops['showdown'] = 'OFF'
147 self.graphops['nonshowdown'] = 'OFF'
149 playerFrame = gtk.Frame()
150 playerFrame.set_label_align(0.0, 0.0)
151 vbox = gtk.VBox(False, 0)
153 self.fillPlayerFrame(vbox, self.display)
154 playerFrame.add(vbox)
156 sitesFrame = gtk.Frame()
157 sitesFrame.set_label_align(0.0, 0.0)
158 vbox = gtk.VBox(False, 0)
160 self.fillSitesFrame(vbox)
161 sitesFrame.add(vbox)
163 # Game types
164 gamesFrame = gtk.Frame()
165 gamesFrame.set_label_align(0.0, 0.0)
166 gamesFrame.show()
167 vbox = gtk.VBox(False, 0)
168 self.cbGames = {}
169 self.cbNoGames = None
170 self.cbAllGames = None
172 self.fillGamesFrame(vbox)
173 gamesFrame.add(vbox)
175 # Currencies
176 currenciesFrame = gtk.Frame()
177 currenciesFrame.set_label_align(0.0, 0.0)
178 currenciesFrame.show()
179 vbox = gtk.VBox(False, 0)
180 self.cbCurrencies = {}
181 self.cbNoCurrencies = None
182 self.cbAllCurrencies = None
184 self.fillCurrenciesFrame(vbox)
185 currenciesFrame.add(vbox)
187 # Limits
188 limitsFrame = gtk.Frame()
189 limitsFrame.show()
190 vbox = gtk.VBox(False, 0)
191 self.cbLimits = {}
192 self.cbNoLimits = None
193 self.cbAllLimits = None
194 self.cbFL = None
195 self.cbNL = None
196 self.cbPL = None
197 self.cbCN = None
198 self.rb = {} # radio buttons for ring/tour
199 self.type = None # ring/tour
200 self.types = {} # list of all ring/tour values
201 self.num_limit_types = 0
203 self.fillLimitsFrame(vbox, self.display)
204 limitsFrame.add(vbox)
206 # GraphOps
207 graphopsFrame = gtk.Frame()
208 #graphops.set_label_align(0,0, 0.0)
209 graphopsFrame.show()
210 vbox = gtk.VBox(False, 0)
212 self.fillGraphOpsFrame(vbox)
213 graphopsFrame.add(vbox)
216 # Seats
217 seatsFrame = gtk.Frame()
218 seatsFrame.show()
219 vbox = gtk.VBox(False, 0)
220 self.sbSeats = {}
222 self.fillSeatsFrame(vbox, self.display)
223 seatsFrame.add(vbox)
225 # Groups
226 groupsFrame = gtk.Frame()
227 groupsFrame.show()
228 vbox = gtk.VBox(False, 0)
230 self.fillGroupsFrame(vbox, self.display)
231 groupsFrame.add(vbox)
233 # Date
234 dateFrame = gtk.Frame()
235 dateFrame.set_label_align(0.0, 0.0)
236 dateFrame.show()
237 vbox = gtk.VBox(False, 0)
239 self.fillDateFrame(vbox)
240 dateFrame.add(vbox)
242 # Buttons
243 self.Button1=gtk.Button("Unnamed 1")
244 self.Button1.set_sensitive(False)
246 self.Button2=gtk.Button("Unnamed 2")
247 self.Button2.set_sensitive(False)
249 expand = False
250 self.mainVBox.pack_start(playerFrame, expand)
251 self.mainVBox.pack_start(sitesFrame, expand)
252 self.mainVBox.pack_start(gamesFrame, expand)
253 self.mainVBox.pack_start(currenciesFrame, expand)
254 self.mainVBox.pack_start(limitsFrame, expand)
255 self.mainVBox.pack_start(seatsFrame, expand)
256 self.mainVBox.pack_start(groupsFrame, expand)
257 self.mainVBox.pack_start(dateFrame, expand)
258 self.mainVBox.pack_start(graphopsFrame, expand)
259 self.mainVBox.pack_start(gtk.VBox(False, 0))
260 self.mainVBox.pack_start(self.Button1, expand)
261 self.mainVBox.pack_start(self.Button2, expand)
263 self.mainVBox.show_all()
265 # Should do this cleaner
266 if "Heroes" not in self.display or self.display["Heroes"] == False:
267 playerFrame.hide()
268 if "Sites" not in self.display or self.display["Sites"] == False:
269 sitesFrame.hide()
270 if "Games" not in self.display or self.display["Games"] == False:
271 gamesFrame.hide()
272 if "Currencies" not in self.display or self.display["Currencies"] == False:
273 currenciesFrame.hide()
274 if "Limits" not in self.display or self.display["Limits"] == False:
275 limitsFrame.hide()
276 if "Seats" not in self.display or self.display["Seats"] == False:
277 seatsFrame.hide()
278 if "Groups" not in self.display or self.display["Groups"] == False:
279 groupsFrame.hide()
280 if "Dates" not in self.display or self.display["Dates"] == False:
281 dateFrame.hide()
282 if "GraphOps" not in self.display or self.display["GraphOps"] == False:
283 graphopsFrame.hide()
284 if "Button1" not in self.display or self.display["Button1"] == False:
285 self.Button1.hide()
286 if "Button2" not in self.display or self.display["Button2"] == False:
287 self.Button2.hide()
289 if 'button1' in self.label and self.label['button1']:
290 self.Button1.set_label( self.label['button1'] )
291 if 'button2' in self.label and self.label['button2']:
292 self.Button2.set_label( self.label['button2'] )
293 if 'button1' in self.callback and self.callback['button1']:
294 self.Button1.connect("clicked", self.callback['button1'], "clicked")
295 self.Button1.set_sensitive(True)
296 if 'button2' in self.callback and self.callback['button2']:
297 self.Button2.connect("clicked", self.callback['button2'], "clicked")
298 self.Button2.set_sensitive(True)
300 # make sure any locks on db are released:
301 self.db.rollback()
303 def get_vbox(self):
304 """returns the vbox of this thread"""
305 return self.sw
306 #end def get_vbox
308 def getNumHands(self):
309 return self.numHands
310 #end def getNumHands
312 def getNumTourneys(self):
313 return self.numTourneys
314 #end def getNumTourneys
316 def getSites(self):
317 return self.sites
318 #end def getSites
320 def getTourneyTypes(self):
321 return self.tourneyTypes
322 #end def getTourneyTypes
324 def getGames(self):
325 return self.games
326 #end def getGames
328 def getCurrencies(self):
329 return self.currencies
330 #end def getCurrencies
332 def getSiteIds(self):
333 return self.siteid
334 #end def getSiteIds
336 def getHeroes(self):
337 return self.heroes
338 #end def getHeroes
340 def getGraphOps(self):
341 return self.graphops
343 def getLimits(self):
344 ltuple = []
345 for l in self.limits:
346 if self.limits[l] == True:
347 ltuple.append(l)
348 return ltuple
350 def getType(self):
351 return(self.type)
353 def getSeats(self):
354 if 'from' in self.sbSeats:
355 self.seats['from'] = self.sbSeats['from'].get_value_as_int()
356 if 'to' in self.sbSeats:
357 self.seats['to'] = self.sbSeats['to'].get_value_as_int()
358 return self.seats
359 #end def getSeats
361 def getGroups(self):
362 return self.groups
364 def getDates(self):
365 return self.__get_dates()
366 #end def getDates
368 def registerButton1Name(self, title):
369 self.Button1.set_label(title)
370 self.label['button1'] = title
372 def registerButton1Callback(self, callback):
373 self.Button1.connect("clicked", callback, "clicked")
374 self.Button1.set_sensitive(True)
375 self.callback['button1'] = callback
377 def registerButton2Name(self, title):
378 self.Button2.set_label(title)
379 self.label['button2'] = title
380 #end def registerButton2Name
382 def registerButton2Callback(self, callback):
383 self.Button2.connect("clicked", callback, "clicked")
384 self.Button2.set_sensitive(True)
385 self.callback['button2'] = callback
386 #end def registerButton2Callback
388 def cardCallback(self, widget, data=None):
389 log.debug( _("%s was toggled %s") % (data, (_("OFF"), _("ON"))[widget.get_active()]) )
391 def createPlayerLine(self, vbox, site, player):
392 log.debug('add:"%s"' % player)
393 label = gtk.Label(site +" id:")
394 label.set_alignment(xalign=0.0, yalign=1.0)
395 vbox.pack_start(label, False, False, 3)
397 hbox = gtk.HBox(False, 0)
398 vbox.pack_start(hbox, False, True, 0)
400 pname = gtk.Entry()
401 pname.set_text(player)
402 pname.set_width_chars(20)
403 hbox.pack_start(pname, True, True, 20)
404 pname.connect("changed", self.__set_hero_name, site)
406 # Added EntryCompletion but maybe comboBoxEntry is more flexible? (e.g. multiple choices)
407 completion = gtk.EntryCompletion()
408 pname.set_completion(completion)
409 liststore = gtk.ListStore(gobject.TYPE_STRING)
410 completion.set_model(liststore)
411 completion.set_text_column(0)
412 names = self.db.get_player_names(self.conf, self.siteid[site]) # (config=self.conf, site_id=None, like_player_name="%")
413 for n in names: # list of single-element "tuples"
414 _n = Charset.to_gui(n[0])
415 _nt = (_n, )
416 liststore.append(_nt)
418 self.__set_hero_name(pname, site)
419 #end def createPlayerLine
421 def __set_hero_name(self, w, site):
422 _name = w.get_text()
423 # get_text() returns a str but we want internal variables to be unicode:
424 _guiname = unicode(_name)
425 self.heroes[site] = _guiname
426 #log.debug("setting heroes[%s]: %s"%(site, self.heroes[site]))
427 #end def __set_hero_name
429 def __set_num_hands(self, w, val):
430 try:
431 self.numHands = int(w.get_text())
432 except:
433 self.numHands = 0
434 #log.debug("setting numHands:", self.numHands)
435 #end def __set_num_hands
437 def createSiteLine(self, hbox, site):
438 cb = gtk.CheckButton(site)
439 cb.connect('clicked', self.__set_site_select, site)
440 cb.set_active(True)
441 hbox.pack_start(cb, False, False, 0)
442 #end def createSiteLine
444 def __set_tourney_type_select(self, w, tourneyType):
445 #print w.get_active()
446 self.tourneyTypes[tourneyType] = w.get_active()
447 log.debug("self.tourney_types[%s] set to %s" %(tourneyType, self.tourneyTypes[tourneyType]))
448 #end def __set_tourney_type_select
450 def createTourneyTypeLine(self, hbox, tourneyType):
451 cb = gtk.CheckButton(str(tourneyType))
452 cb.connect('clicked', self.__set_tourney_type_select, tourneyType)
453 hbox.pack_start(cb, False, False, 0)
454 cb.set_active(True)
455 #end def createTourneyTypeLine
457 def createGameLine(self, hbox, game, gtext):
458 cb = gtk.CheckButton(gtext.replace("_", "__"))
459 cb.connect('clicked', self.__set_game_select, game)
460 hbox.pack_start(cb, False, False, 0)
461 if game != "none":
462 cb.set_active(True)
463 return(cb)
465 def createCurrencyLine(self, hbox, currency, ctext):
466 cb = gtk.CheckButton(ctext.replace("_", "__"))
467 cb.connect('clicked', self.__set_currency_select, currency)
468 hbox.pack_start(cb, False, False, 0)
469 if currency != "none" and currency != "all" and currency != "play":
470 cb.set_active(True)
471 return(cb)
473 def createLimitLine(self, hbox, limit, ltext):
474 cb = gtk.CheckButton(str(ltext))
475 cb.connect('clicked', self.__set_limit_select, limit)
476 hbox.pack_start(cb, False, False, 0)
477 if limit != "none":
478 cb.set_active(True)
479 return(cb)
481 def __set_site_select(self, w, site):
482 #print w.get_active()
483 self.sites[site] = w.get_active()
484 log.debug(_("self.sites[%s] set to %s") %(site, self.sites[site]))
485 #end def __set_site_select
487 def __set_game_select(self, w, game):
488 if (game == 'all'):
489 if (w.get_active()):
490 for cb in self.cbGames.values():
491 cb.set_active(True)
492 elif (game == 'none'):
493 if (w.get_active()):
494 for cb in self.cbGames.values():
495 cb.set_active(False)
496 else:
497 self.games[game] = w.get_active()
498 if (w.get_active()): # when we turn a game on, turn 'none' off if it's on
499 if (self.cbNoGames and self.cbNoGames.get_active()):
500 self.cbNoGames.set_active(False)
501 else: # when we turn a game off, turn 'all' off if it's on
502 if (self.cbAllGames and self.cbAllGames.get_active()):
503 self.cbAllGames.set_active(False)
504 #end def __set_game_select
506 def __set_currency_select(self, w, currency):
507 if (currency == 'all'):
508 if (w.get_active()):
509 for cb in self.cbCurrencies.values():
510 cb.set_active(True)
511 elif (currency == 'none'):
512 if (w.get_active()):
513 for cb in self.cbCurrencies.values():
514 cb.set_active(False)
515 else:
516 self.currencies[currency] = w.get_active()
517 if (w.get_active()): # when we turn a currency on, turn 'none' off if it's on
518 if (self.cbNoCurrencies and self.cbNoCurrencies.get_active()):
519 self.cbNoCurrencies.set_active(False)
520 else: # when we turn a currency off, turn 'all' off if it's on
521 if (self.cbAllCurrencies and self.cbAllCurrencies.get_active()):
522 self.cbAllCurrencies.set_active(False)
523 #end def __set_currency_select
525 def __set_limit_select(self, w, limit):
526 #print "__set_limit_select: limit =", limit, w.get_active()
527 self.limits[limit] = w.get_active()
528 log.debug(_("self.limit[%s] set to %s") %(limit, self.limits[limit]))
529 if limit.isdigit() or (len(limit) > 2 and (limit[-2:] == 'nl' or limit[-2:] == 'fl' or limit[-2:] == 'pl' or limit[-2:] == 'cn')):
530 # turning a leaf limit on with 'None' checked turns 'None' off
531 if self.limits[limit]:
532 if self.cbNoLimits is not None:
533 self.cbNoLimits.set_active(False)
534 # turning a leaf limit off with 'All' checked turns 'All' off
535 else:
536 if self.cbAllLimits is not None:
537 self.cbAllLimits.set_active(False)
538 # turning off a leaf limit turns off the corresponding fl. nl, cn or pl
539 if not self.limits[limit]:
540 if limit.isdigit():
541 if self.cbFL is not None:
542 self.cbFL.set_active(False)
543 elif (len(limit) > 2 and (limit[-2:] == 'nl')):
544 if self.cbNL is not None:
545 self.cbNL.set_active(False)
546 elif (len(limit) > 2 and (limit[-2:] == 'cn')):
547 if self.cbCN is not None:
548 self.cbCN.set_active(False)
549 else:
550 if self.cbPL is not None:
551 self.cbPL.set_active(False)
552 elif limit == "all":
553 if self.limits[limit]:
554 if self.num_limit_types == 1:
555 for cb in self.cbLimits.values():
556 cb.set_active(True)
557 else:
558 if self.cbFL is not None:
559 self.cbFL.set_active(True)
560 if self.cbNL is not None:
561 self.cbNL.set_active(True)
562 if self.cbPL is not None:
563 self.cbPL.set_active(True)
564 if self.cbCN is not None:
565 self.cbCN.set_active(True)
566 elif limit == "none":
567 if self.limits[limit]:
568 if self.num_limit_types > 1:
569 if self.cbNL is not None:
570 self.cbNL.set_active(False)
571 if self.cbFL is not None:
572 self.cbFL.set_active(False)
573 if self.cbPL is not None:
574 self.cbPL.set_active(False)
575 if self.cbCN is not None:
576 self.cbCN.set_active(False)
578 # Finally, clean-up all individual limit checkboxes
579 # needed because the overall limit checkbox may
580 # not be set, or num_limit_types == 1
582 for cb in self.cbLimits.values():
583 cb.set_active(False)
584 elif limit == "fl":
585 if not self.limits[limit]:
586 # only toggle all fl limits off if they are all currently on
587 # this stops turning one off from cascading into 'fl' box off
588 # and then all fl limits being turned off
589 all_fl_on = True
590 for cb in self.cbLimits.values():
591 t = cb.get_children()[0].get_text()
592 if t.isdigit():
593 if not cb.get_active():
594 all_fl_on = False
595 found = {'ring':False, 'tour':False}
596 for cb in self.cbLimits.values():
597 #print "cb label: ", cb.children()[0].get_text()
598 t = cb.get_children()[0].get_text()
599 if t.isdigit():
600 if self.limits[limit] or all_fl_on:
601 cb.set_active(self.limits[limit])
602 found[self.types[t]] = True
603 if self.limits[limit]:
604 if not found[self.type]:
605 if self.type == 'ring':
606 if 'tour' in self.rb:
607 self.rb['tour'].set_active(True)
608 elif self.type == 'tour':
609 if 'ring' in self.rb:
610 self.rb['ring'].set_active(True)
611 elif limit == "nl":
612 if not self.limits[limit]:
613 # only toggle all nl limits off if they are all currently on
614 # this stops turning one off from cascading into 'nl' box off
615 # and then all nl limits being turned off
616 all_nl_on = True
617 for cb in self.cbLimits.values():
618 t = cb.get_children()[0].get_text()
619 if "nl" in t and len(t) > 2:
620 if not cb.get_active():
621 all_nl_on = False
622 found = {'ring':False, 'tour':False}
623 for cb in self.cbLimits.values():
624 t = cb.get_children()[0].get_text()
625 if "nl" in t and len(t) > 2:
626 if self.limits[limit] or all_nl_on:
627 cb.set_active(self.limits[limit])
628 found[self.types[t]] = True
629 if self.limits[limit]:
630 if not found[self.type]:
631 if self.type == 'ring':
632 if 'tour' in self.rb:
633 self.rb['tour'].set_active(True)
634 elif self.type == 'tour':
635 if 'ring' in self.rb:
636 self.rb['ring'].set_active(True)
637 elif limit == "pl":
638 if not self.limits[limit]:
639 # only toggle all nl limits off if they are all currently on
640 # this stops turning one off from cascading into 'nl' box off
641 # and then all nl limits being turned off
642 all_nl_on = True
643 for cb in self.cbLimits.values():
644 t = cb.get_children()[0].get_text()
645 if "pl" in t and len(t) > 2:
646 if not cb.get_active():
647 all_nl_on = False
648 found = {'ring':False, 'tour':False}
649 for cb in self.cbLimits.values():
650 t = cb.get_children()[0].get_text()
651 if "pl" in t and len(t) > 2:
652 if self.limits[limit] or all_nl_on:
653 cb.set_active(self.limits[limit])
654 found[self.types[t]] = True
655 if self.limits[limit]:
656 if not found[self.type]:
657 if self.type == 'ring':
658 if 'tour' in self.rb:
659 self.rb['tour'].set_active(True)
660 elif self.type == 'tour':
661 if 'ring' in self.rb:
662 self.rb['ring'].set_active(True)
663 elif limit == "cn":
664 if not self.limits[limit]:
665 all_cn_on = True
666 for cb in self.cbLimits.values():
667 t = cb.get_children()[0].get_text()
668 if "cn" in t and len(t) > 2:
669 if not cb.get_active():
670 all_cn_on = False
671 found = {'ring':False, 'tour':False}
672 for cb in self.cbLimits.values():
673 t = cb.get_children()[0].get_text()
674 if "cn" in t and len(t) > 2:
675 if self.limits[limit] or all_cn_on:
676 cb.set_active(self.limits[limit])
677 found[self.types[t]] = True
678 if self.limits[limit]:
679 if not found[self.type]:
680 if self.type == 'ring':
681 if 'tour' in self.rb:
682 self.rb['tour'].set_active(True)
683 elif self.type == 'tour':
684 if 'ring' in self.rb:
685 self.rb['ring'].set_active(True)
686 elif limit == "ring":
687 log.debug("set", limit, "to", self.limits[limit])
688 if self.limits[limit]:
689 self.type = "ring"
690 for cb in self.cbLimits.values():
691 #print "cb label: ", cb.children()[0].get_text()
692 if self.types[cb.get_children()[0].get_text()] == 'tour':
693 cb.set_active(False)
694 elif limit == "tour":
695 log.debug( "set", limit, "to", self.limits[limit] )
696 if self.limits[limit]:
697 self.type = "tour"
698 for cb in self.cbLimits.values():
699 #print "cb label: ", cb.children()[0].get_text()
700 if self.types[cb.get_children()[0].get_text()] == 'ring':
701 cb.set_active(False)
703 def __set_seat_select(self, w, seat):
704 #print "__set_seat_select: seat =", seat, "active =", w.get_active()
705 self.seats[seat] = w.get_active()
706 log.debug( _("self.seats[%s] set to %s") %(seat, self.seats[seat]) )
707 #end def __set_seat_select
709 def __set_group_select(self, w, group):
710 #print "__set_seat_select: seat =", seat, "active =", w.get_active()
711 self.groups[group] = w.get_active()
712 log.debug( _("self.groups[%s] set to %s") %(group, self.groups[group]) )
715 def __set_displayin_select(self, w, ops):
716 self.graphops['dspin'] = ops
718 def __set_graphopscheck_select(self, w, data):
719 #print "%s was toggled %s" % (data, ("OFF", "ON")[w.get_active()])
720 self.graphops[data] = ("OFF", "ON")[w.get_active()]
722 def fillPlayerFrame(self, vbox, display):
723 top_hbox = gtk.HBox(False, 0)
724 vbox.pack_start(top_hbox, False, False, 0)
725 lbl_title = gtk.Label(self.filterText['playerstitle'])
726 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
727 top_hbox.pack_start(lbl_title, expand=True, padding=3)
729 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
730 showb.set_alignment(xalign=1.0, yalign=0.5)
731 showb.connect('clicked', self.__toggle_box, 'Heroes')
732 self.toggles['Heroes'] = showb
733 showb.show()
734 top_hbox.pack_end(showb, expand=False, padding=1)
736 showb = gtk.Button(label=_("hide all"), stock=None, use_underline=True)
737 showb.set_alignment(xalign=1.0, yalign=0.5)
738 showb.connect('clicked', self.__toggle_box, 'all')
739 self.toggles['all'] = showb
740 showb.show()
741 top_hbox.pack_end(showb, expand=False, padding=1)
743 showb = gtk.Button(label=_("Refresh"), stock=None, use_underline=True)
744 showb.set_alignment(xalign=1.0, yalign=0.5)
745 showb.connect('clicked', self.__refresh, 'Heroes')
747 vbox1 = gtk.VBox(False, 0)
748 vbox.pack_start(vbox1, False, False, 0)
749 self.boxes['Heroes'] = vbox1
751 for site in self.conf.get_supported_sites():
752 player = self.conf.supported_sites[site].screen_name
753 _pname = Charset.to_gui(player)
754 self.createPlayerLine(vbox1, site, _pname)
756 if "GroupsAll" in display and display["GroupsAll"] == True:
757 hbox = gtk.HBox(False, 0)
758 vbox1.pack_start(hbox, False, False, 0)
759 cb = gtk.CheckButton(self.filterText['groupsall'])
760 cb.connect('clicked', self.__set_group_select, 'allplayers')
761 hbox.pack_start(cb, False, False, 0)
762 self.sbGroups['allplayers'] = cb
763 self.groups['allplayers'] = False
765 lbl = gtk.Label(_('Min # Hands:'))
766 lbl.set_alignment(xalign=1.0, yalign=0.5)
767 hbox.pack_start(lbl, expand=True, padding=3)
769 phands = gtk.Entry()
770 phands.set_text('0')
771 phands.set_width_chars(8)
772 hbox.pack_start(phands, False, False, 0)
773 phands.connect("changed", self.__set_num_hands, site)
774 top_hbox.pack_start(showb, expand=False, padding=1)
775 #end def fillPlayerFrame
777 def fillSitesFrame(self, vbox):
778 top_hbox = gtk.HBox(False, 0)
779 top_hbox.show()
780 vbox.pack_start(top_hbox, False, False, 0)
782 lbl_title = gtk.Label(self.filterText['sitestitle'])
783 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
784 top_hbox.pack_start(lbl_title, expand=True, padding=3)
786 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
787 showb.set_alignment(xalign=1.0, yalign=0.5)
788 showb.connect('clicked', self.__toggle_box, 'Sites')
789 self.toggles['Sites'] = showb
790 showb.show()
791 top_hbox.pack_start(showb, expand=False, padding=1)
793 vbox1 = gtk.VBox(False, 0)
794 self.boxes['Sites'] = vbox1
795 vbox.pack_start(vbox1, False, False, 0)
797 for site in self.conf.get_supported_sites():
798 hbox = gtk.HBox(False, 0)
799 vbox1.pack_start(hbox, False, True, 0)
800 self.createSiteLine(hbox, site)
801 #Get db site id for filtering later
802 #self.cursor.execute(self.sql.query['getSiteId'], (site,))
803 #result = self.db.cursor.fetchall()
804 #if len(result) == 1:
805 # self.siteid[site] = result[0][0]
806 #else:
807 # print "Either 0 or more than one site matched - EEK"
808 #end def fillSitesFrame
810 def fillTourneyTypesFrame(self, vbox):
811 top_hbox = gtk.HBox(False, 0)
812 vbox.pack_start(top_hbox, False, False, 0)
813 lbl_title = gtk.Label(self.filterText['tourneyTypesTitle'])
814 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
815 top_hbox.pack_start(lbl_title, expand=True, padding=3)
816 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
817 showb.set_alignment(xalign=1.0, yalign=0.5)
818 showb.connect('clicked', self.__toggle_box, 'tourneyTypes')
819 self.toggles['tourneyTypes'] = showb
820 top_hbox.pack_start(showb, expand=False, padding=1)
822 vbox1 = gtk.VBox(False, 0)
823 vbox.pack_start(vbox1, False, False, 0)
824 self.boxes['tourneyTypes'] = vbox1
826 result = self.db.getTourneyTypesIds()
827 if len(result) >= 1:
828 for line in result:
829 hbox = gtk.HBox(False, 0)
830 vbox1.pack_start(hbox, False, True, 0)
831 self.createTourneyTypeLine(hbox, line[0])
832 else:
833 print _("INFO: No tourney types returned from database")
834 log.info(_("No tourney types returned from database"))
835 #end def fillTourneyTypesFrame
837 def fillGamesFrame(self, vbox):
838 top_hbox = gtk.HBox(False, 0)
839 vbox.pack_start(top_hbox, False, False, 0)
840 lbl_title = gtk.Label(self.filterText['gamestitle'])
841 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
842 top_hbox.pack_start(lbl_title, expand=True, padding=3)
843 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
844 showb.set_alignment(xalign=1.0, yalign=0.5)
845 showb.connect('clicked', self.__toggle_box, 'Games')
846 self.toggles['Games'] = showb
847 top_hbox.pack_start(showb, expand=False, padding=1)
849 vbox1 = gtk.VBox(False, 0)
850 vbox.pack_start(vbox1, False, False, 0)
851 self.boxes['Games'] = vbox1
853 self.cursor.execute(self.sql.query['getGames'])
854 result = self.db.cursor.fetchall()
855 if len(result) >= 1:
856 for line in sorted(result, key = lambda game: self.gameName[game[0]]):
857 hbox = gtk.HBox(False, 0)
858 vbox1.pack_start(hbox, False, True, 0)
859 self.cbGames[line[0]] = self.createGameLine(hbox, line[0], self.gameName[line[0]])
861 if len(result) >= 2:
862 hbox = gtk.HBox(True, 0)
863 vbox1.pack_start(hbox, False, False, 0)
864 vbox2 = gtk.VBox(False, 0)
865 hbox.pack_start(vbox2, False, False, 0)
866 vbox3 = gtk.VBox(False, 0)
867 hbox.pack_start(vbox3, False, False, 0)
869 hbox = gtk.HBox(False, 0)
870 vbox2.pack_start(hbox, False, False, 0)
871 self.cbAllGames = self.createGameLine(hbox, 'all', self.filterText['gamesall'])
872 hbox = gtk.HBox(False, 0)
873 vbox3.pack_start(hbox, False, False, 0)
874 self.cbNoGames = self.createGameLine(hbox, 'none', self.filterText['gamesnone'])
875 else:
876 print _("INFO: No games returned from database")
877 log.info(_("No games returned from database"))
878 #end def fillGamesFrame
880 def fillCurrenciesFrame(self, vbox):
881 top_hbox = gtk.HBox(False, 0)
882 vbox.pack_start(top_hbox, False, False, 0)
883 lbl_title = gtk.Label(self.filterText['currenciestitle'])
884 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
885 top_hbox.pack_start(lbl_title, expand=True, padding=3)
886 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
887 showb.set_alignment(xalign=1.0, yalign=0.5)
888 showb.connect('clicked', self.__toggle_box, 'Currencies')
889 self.toggles['Currencies'] = showb
890 top_hbox.pack_start(showb, expand=False, padding=1)
892 vbox1 = gtk.VBox(False, 0)
893 vbox.pack_start(vbox1, False, False, 0)
894 self.boxes['Currencies'] = vbox1
896 self.cursor.execute(self.sql.query['getCurrencies'])
897 result = self.db.cursor.fetchall()
898 if len(result) >= 1:
899 for line in result:
900 hbox = gtk.HBox(False, 0)
901 vbox1.pack_start(hbox, False, True, 0)
902 if (self.currencyName.has_key(line[0])):
903 cname = self.currencyName[line[0]]
904 else:
905 cname = line[0]
906 self.cbCurrencies[line[0]] = self.createCurrencyLine(hbox, line[0], cname)
908 if len(result) >= 2:
909 hbox = gtk.HBox(True, 0)
910 vbox1.pack_start(hbox, False, False, 0)
911 vbox2 = gtk.VBox(False, 0)
912 hbox.pack_start(vbox2, False, False, 0)
913 vbox3 = gtk.VBox(False, 0)
914 hbox.pack_start(vbox3, False, False, 0)
916 hbox = gtk.HBox(False, 0)
917 vbox2.pack_start(hbox, False, False, 0)
918 self.cbAllCurrencies = self.createCurrencyLine(hbox, 'all', self.filterText['currenciesall'])
919 hbox = gtk.HBox(False, 0)
920 vbox3.pack_start(hbox, False, False, 0)
921 self.cbNoCurrencies = self.createCurrencyLine(hbox, 'none', self.filterText['currenciesnone'])
922 else:
923 print _("INFO: No currencies returned from database")
924 log.info(_("No currencies returned from database"))
925 #end def fillCurrenciesFrame
927 def fillLimitsFrame(self, vbox, display):
928 top_hbox = gtk.HBox(False, 0)
929 vbox.pack_start(top_hbox, False, False, 0)
930 lbl_title = gtk.Label(self.filterText['limitstitle'])
931 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
932 top_hbox.pack_start(lbl_title, expand=True, padding=3)
933 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
934 showb.set_alignment(xalign=1.0, yalign=0.5)
935 showb.connect('clicked', self.__toggle_box, 'Limits')
936 self.toggles['Limits'] = showb
937 top_hbox.pack_start(showb, expand=False, padding=1)
939 vbox1 = gtk.VBox(False, 15)
940 vbox.pack_start(vbox1, False, False, 0)
941 self.boxes['Limits'] = vbox1
943 self.cursor.execute(self.sql.query['getCashLimits'])
944 # selects limitType, bigBlind
945 result = self.db.cursor.fetchall()
946 self.found = {'nl':False, 'fl':False, 'pl':False, 'cn':False, 'ring':False, 'tour':False}
948 if len(result) >= 1:
949 hbox = gtk.HBox(True, 0)
950 vbox1.pack_start(hbox, False, False, 0)
951 vbox2 = gtk.VBox(False, 0)
952 hbox.pack_start(vbox2, False, False, 0)
953 vbox3 = gtk.VBox(False, 0)
954 hbox.pack_start(vbox3, False, False, 0)
955 for i, line in enumerate(result):
956 if "UseType" in self.display:
957 if line[0] != self.display["UseType"]:
958 continue
959 hbox = gtk.HBox(False, 0)
960 if i < (len(result)+1)/2:
961 vbox2.pack_start(hbox, False, False, 0)
962 else:
963 vbox3.pack_start(hbox, False, False, 0)
964 if True: #line[0] == 'ring':
965 if line[1] == 'fl':
966 name = str(line[2])+line[1]
967 self.found['fl'] = True
968 elif line[1] == 'pl':
969 name = str(line[2])+line[1]
970 self.found['pl'] = True
971 elif line[1] == 'cn':
972 name = str(line[2])+line[1]
973 self.found['cn'] = True
974 else:
975 name = str(line[2])+line[1]
976 self.found['nl'] = True
977 self.cbLimits[name] = self.createLimitLine(hbox, name, name)
978 self.types[name] = line[0]
979 self.found[line[0]] = True # type is ring/tour
980 self.type = line[0] # if only one type, set it now
981 if "LimitSep" in display and display["LimitSep"] == True and len(result) >= 2:
982 hbox = gtk.HBox(True, 0)
983 vbox1.pack_start(hbox, False, False, 0)
984 vbox2 = gtk.VBox(False, 0)
985 hbox.pack_start(vbox2, False, False, 0)
986 vbox3 = gtk.VBox(False, 0)
987 hbox.pack_start(vbox3, False, False, 0)
989 hbox = gtk.HBox(False, 0)
990 vbox2.pack_start(hbox, False, False, 0)
991 self.cbAllLimits = self.createLimitLine(hbox, 'all', self.filterText['limitsall'])
992 hbox = gtk.HBox(False, 0)
993 vbox2.pack_start(hbox, False, False, 0)
994 self.cbNoLimits = self.createLimitLine(hbox, 'none', self.filterText['limitsnone'])
996 dest = vbox3 # for ring/tour buttons
997 if "LimitType" in display and display["LimitType"] == True:
998 self.num_limit_types = 0
999 if self.found['fl']: self.num_limit_types = self.num_limit_types + 1
1000 if self.found['pl']: self.num_limit_types = self.num_limit_types + 1
1001 if self.found['nl']: self.num_limit_types = self.num_limit_types + 1
1002 if self.found['cn']: self.num_limit_types = self.num_limit_types + 1
1003 if self.num_limit_types > 1:
1004 if self.found['fl']:
1005 hbox = gtk.HBox(False, 0)
1006 vbox3.pack_start(hbox, False, False, 0)
1007 self.cbFL = self.createLimitLine(hbox, 'fl', self.filterText['limitsFL'])
1008 if self.found['nl']:
1009 hbox = gtk.HBox(False, 0)
1010 vbox3.pack_start(hbox, False, False, 0)
1011 self.cbNL = self.createLimitLine(hbox, 'nl', self.filterText['limitsNL'])
1012 if self.found['pl']:
1013 hbox = gtk.HBox(False, 0)
1014 vbox3.pack_start(hbox, False, False, 0)
1015 self.cbPL = self.createLimitLine(hbox, 'pl', self.filterText['limitsPL'])
1016 if self.found['cn']:
1017 hbox = gtk.HBox(False, 0)
1018 vbox3.pack_start(hbox, False, False, 0)
1019 self.cbCN = self.createLimitLine(hbox, 'cn', self.filterText['limitsCN'])
1020 dest = vbox2 # for ring/tour buttons
1021 else:
1022 print _("INFO: No games returned from database")
1023 log.info(_("No games returned from database"))
1025 if "Type" in display and display["Type"] == True and self.found['ring'] and self.found['tour']:
1026 rb1 = gtk.RadioButton(None, self.filterText['ring'])
1027 rb1.connect('clicked', self.__set_limit_select, 'ring')
1028 rb2 = gtk.RadioButton(rb1, self.filterText['tour'])
1029 rb2.connect('clicked', self.__set_limit_select, 'tour')
1030 top_hbox.pack_start(rb1, False, False, 0) # (child, expand, fill, padding)
1031 top_hbox.pack_start(rb2, True, True, 0) # child uses expand space if fill is true
1033 self.rb['ring'] = rb1
1034 self.rb['tour'] = rb2
1035 #print "about to set ring to true"
1036 rb1.set_active(True)
1037 # set_active doesn't seem to call this for some reason so call manually:
1038 self.__set_limit_select(rb1, 'ring')
1039 self.type = 'ring'
1040 top_hbox.pack_start(showb, expand=False, padding=1)
1042 def fillGraphOpsFrame(self, vbox):
1043 top_hbox = gtk.HBox(False, 0)
1044 vbox.pack_start(top_hbox, False, False, 0)
1045 title = gtk.Label(_("Graphing Options:"))
1046 title.set_alignment(xalign=0.0, yalign=0.5)
1047 top_hbox.pack_start(title, expand=True, padding=3)
1048 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
1049 showb.set_alignment(xalign=1.0, yalign=0.5)
1050 showb.connect('clicked', self.__toggle_box, 'GraphOps')
1051 self.toggles['GraphOps'] = showb
1052 top_hbox.pack_start(showb, expand=False, padding=1)
1054 vbox1 = gtk.VBox(False, 0)
1055 vbox.pack_start(vbox1, False, False, 0)
1056 vbox1.show()
1057 self.boxes['GraphOps'] = vbox1
1059 hbox1 = gtk.HBox(False, 0)
1060 vbox1.pack_start(hbox1, False, False, 0)
1061 hbox1.show()
1063 label = gtk.Label(_("Show Graph In:"))
1064 label.set_alignment(xalign=0.0, yalign=0.5)
1065 hbox1.pack_start(label, True, True, 0)
1066 label.show()
1068 button = gtk.RadioButton(None, "$$")
1069 hbox1.pack_start(button, True, True, 0)
1070 button.connect("toggled", self.__set_displayin_select, "$")
1071 button.set_active(True)
1072 button.show()
1074 button = gtk.RadioButton(button, "BB")
1075 hbox1.pack_start(button, True, True, 0)
1076 button.connect("toggled", self.__set_displayin_select, "BB")
1077 button.show()
1079 button = gtk.CheckButton(_("Showdown Winnings"), False)
1080 vbox1.pack_start(button, True, True, 0)
1081 # wouldn't it be awesome if there was a way to remember the state of things like
1082 # this and be able to set it to what it was last time?
1083 #button.set_active(True)
1084 button.connect("toggled", self.__set_graphopscheck_select, "showdown")
1085 button.show()
1087 button = gtk.CheckButton(_("Non-Showdown Winnings"), False)
1088 vbox1.pack_start(button, True, True, 0)
1089 # ditto as 8 lines up :)
1090 #button.set_active(True)
1091 button.connect("toggled", self.__set_graphopscheck_select, "nonshowdown");
1092 button.show()
1094 def fillSeatsFrame(self, vbox, display):
1095 hbox = gtk.HBox(False, 0)
1096 vbox.pack_start(hbox, False, False, 0)
1097 lbl_title = gtk.Label(self.filterText['seatstitle'])
1098 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
1099 hbox.pack_start(lbl_title, expand=True, padding=3)
1100 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
1101 showb.set_alignment(xalign=1.0, yalign=0.5)
1102 showb.connect('clicked', self.__toggle_box, 'Seats')
1103 self.toggles['Seats'] = showb
1104 hbox.pack_start(showb, expand=False, padding=1)
1106 vbox1 = gtk.VBox(False, 0)
1107 vbox.pack_start(vbox1, False, False, 0)
1108 self.boxes['Seats'] = vbox1
1110 hbox = gtk.HBox(False, 0)
1111 vbox1.pack_start(hbox, False, True, 0)
1113 lbl_from = gtk.Label(self.filterText['seatsbetween'])
1114 lbl_to = gtk.Label(self.filterText['seatsand'])
1116 adj1 = gtk.Adjustment(value=2, lower=2, upper=10, step_incr=1, page_incr=1, page_size=0)
1117 sb1 = gtk.SpinButton(adjustment=adj1, climb_rate=0.0, digits=0)
1118 adj1.connect('value-changed', self.__seats_changed, 'from')
1120 adj2 = gtk.Adjustment(value=10, lower=2, upper=10, step_incr=1, page_incr=1, page_size=0)
1121 sb2 = gtk.SpinButton(adjustment=adj2, climb_rate=0.0, digits=0)
1122 adj2.connect('value-changed', self.__seats_changed, 'to')
1124 hbox.pack_start(lbl_from, expand=False, padding=3)
1125 hbox.pack_start(sb1, False, False, 0)
1126 hbox.pack_start(lbl_to, expand=False, padding=3)
1127 hbox.pack_start(sb2, False, False, 0)
1129 self.sbSeats['from'] = sb1
1130 self.sbSeats['to'] = sb2
1131 #end def fillSeatsFrame
1133 def fillGroupsFrame(self, vbox, display):
1134 hbox = gtk.HBox(False, 0)
1135 vbox.pack_start(hbox, False, False, 0)
1136 lbl_title = gtk.Label(self.filterText['groupstitle'])
1137 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
1138 hbox.pack_start(lbl_title, expand=True, padding=3)
1139 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
1140 showb.set_alignment(xalign=1.0, yalign=0.5)
1141 showb.connect('clicked', self.__toggle_box, 'Groups')
1142 self.toggles['Groups'] = showb
1143 hbox.pack_start(showb, expand=False, padding=1)
1145 vbox1 = gtk.VBox(False, 0)
1146 vbox.pack_start(vbox1, False, False, 0)
1147 self.boxes['Groups'] = vbox1
1149 hbox = gtk.HBox(False, 0)
1150 vbox1.pack_start(hbox, False, False, 0)
1151 cb = self.createLimitLine(hbox, 'show', self.filterText['limitsshow'])
1153 hbox = gtk.HBox(False, 0)
1154 vbox1.pack_start(hbox, False, True, 0)
1155 cb = gtk.CheckButton(self.filterText['posnshow'])
1156 cb.connect('clicked', self.__set_group_select, 'posn')
1157 hbox.pack_start(cb, False, False, 0)
1158 self.sbGroups['posn'] = cb
1159 self.groups['posn'] = False
1161 if "SeatSep" in display and display["SeatSep"] == True:
1162 hbox = gtk.HBox(False, 0)
1163 vbox1.pack_start(hbox, False, True, 0)
1164 cb = gtk.CheckButton(self.filterText['seatsshow'])
1165 cb.connect('clicked', self.__set_seat_select, 'show')
1166 hbox.pack_start(cb, False, False, 0)
1167 self.sbSeats['show'] = cb
1168 self.seats['show'] = False
1170 def fillCardsFrame(self, vbox):
1171 hbox1 = gtk.HBox(True,0)
1172 hbox1.show()
1173 vbox.pack_start(hbox1, True, True, 0)
1175 cards = [ "A", "K","Q","J","T","9","8","7","6","5","4","3","2" ]
1177 for j in range(0, len(cards)):
1178 hbox1 = gtk.HBox(True,0)
1179 hbox1.show()
1180 vbox.pack_start(hbox1, True, True, 0)
1181 for i in range(0, len(cards)):
1182 if i < (j + 1):
1183 suit = "o"
1184 else:
1185 suit = "s"
1186 button = gtk.ToggleButton("%s%s%s" %(cards[i], cards[j], suit))
1187 button.connect("toggled", self.cardCallback, "%s%s%s" %(cards[i], cards[j], suit))
1188 hbox1.pack_start(button, True, True, 0)
1189 button.show()
1191 def fillDateFrame(self, vbox):
1192 # Hat tip to Mika Bostrom - calendar code comes from PokerStats
1193 top_hbox = gtk.HBox(False, 0)
1194 vbox.pack_start(top_hbox, False, False, 0)
1195 lbl_title = gtk.Label(self.filterText['datestitle'])
1196 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
1197 top_hbox.pack_start(lbl_title, expand=True, padding=3)
1198 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
1199 showb.set_alignment(xalign=1.0, yalign=0.5)
1200 showb.connect('clicked', self.__toggle_box, 'Dates')
1201 self.toggles['Dates'] = showb
1202 top_hbox.pack_start(showb, expand=False, padding=1)
1204 hbox1 = gtk.HBox(False, 0)
1205 vbox.pack_start(hbox1, False, False, 0)
1206 self.boxes['Dates'] = hbox1
1208 table = gtk.Table(2,4,False)
1209 hbox1.pack_start(table, False, True, 0)
1211 lbl_start = gtk.Label(_('From:'))
1212 lbl_start.set_alignment(xalign=1.0, yalign=0.5)
1213 btn_start = gtk.Button()
1214 btn_start.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
1215 btn_start.connect('clicked', self.__calendar_dialog, self.start_date)
1216 clr_start = gtk.Button()
1217 clr_start.set_image(gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_BUTTON))
1218 clr_start.connect('clicked', self.__clear_start_date)
1220 lbl_end = gtk.Label(_('To:'))
1221 lbl_end.set_alignment(xalign=1.0, yalign=0.5)
1222 btn_end = gtk.Button()
1223 btn_end.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
1224 btn_end.connect('clicked', self.__calendar_dialog, self.end_date)
1225 clr_end = gtk.Button()
1226 clr_end.set_image(gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_BUTTON))
1227 clr_end.connect('clicked', self.__clear_end_date)
1229 table.attach(lbl_start, 0,1, 0,1)
1230 table.attach(btn_start, 1,2, 0,1)
1231 table.attach(self.start_date, 2,3, 0,1)
1232 table.attach(clr_start, 3,4, 0,1)
1234 table.attach(lbl_end, 0,1, 1,2)
1235 table.attach(btn_end, 1,2, 1,2)
1236 table.attach(self.end_date, 2,3, 1,2)
1237 table.attach(clr_end, 3,4, 1,2)
1239 #end def fillDateFrame
1241 def __refresh(self, widget, entry):
1242 for w in self.mainVBox.get_children():
1243 w.destroy()
1244 self.make_filter()
1245 #end def __refresh
1247 def __toggle_box(self, widget, entry):
1248 if (entry == "all"):
1249 if (widget.get_label() == _("hide all")):
1250 for entry in self.boxes.keys():
1251 if (self.boxes[entry].props.visible):
1252 self.__toggle_box(widget, entry)
1253 widget.set_label(_("show all"))
1254 else:
1255 for entry in self.boxes.keys():
1256 if (not self.boxes[entry].props.visible):
1257 self.__toggle_box(widget, entry)
1258 widget.set_label(_("hide all"))
1259 elif self.boxes[entry].props.visible:
1260 self.boxes[entry].hide()
1261 self.toggles[entry].set_label(_("show"))
1262 for entry in self.boxes.keys():
1263 if (self.display.has_key(entry) and
1264 self.display[entry] and
1265 self.boxes[entry].props.visible):
1266 break
1267 else:
1268 self.toggles["all"].set_label(_("show all"))
1269 else:
1270 self.boxes[entry].show()
1271 self.toggles[entry].set_label(_("hide"))
1272 for entry in self.boxes.keys():
1273 if (self.display.has_key(entry) and
1274 self.display[entry] and
1275 not self.boxes[entry].props.visible):
1276 break
1277 else:
1278 self.toggles["all"].set_label(_("hide all"))
1279 #end def __toggle_box
1281 def __calendar_dialog(self, widget, entry):
1282 d = gtk.Window(gtk.WINDOW_TOPLEVEL)
1283 d.set_title(_('Pick a date'))
1285 vb = gtk.VBox()
1286 cal = gtk.Calendar()
1287 vb.pack_start(cal, expand=False, padding=0)
1289 # if the date field is already set, default to the currently selected date, else default to 'today'
1290 text = entry.get_text()
1291 if (text):
1292 date = strptime(text, "%Y-%m-%d")
1293 else:
1294 # if the day is configured to not start at midnight, check whether it's still yesterday,
1295 # and if so, select yesterday in the calendar instead of today
1296 date = localtime()
1297 if (date.tm_hour < self.day_start):
1298 date = localtime(mktime(date) - 24*3600)
1299 cal.select_month(date.tm_mon - 1, date.tm_year) # months are 0 through 11
1300 cal.select_day(date.tm_mday)
1302 btn = gtk.Button(_('Done'))
1303 btn.connect('clicked', self.__get_date, cal, entry, d)
1305 vb.pack_start(btn, expand=False, padding=4)
1307 d.add(vb)
1308 d.set_position(gtk.WIN_POS_MOUSE)
1309 d.show_all()
1310 #end def __calendar_dialog
1312 def __clear_start_date(self, w):
1313 self.start_date.set_text('')
1314 #end def __clear_start_date
1316 def __clear_end_date(self, w):
1317 self.end_date.set_text('')
1318 #end def __clear_end_date
1320 def __get_dates(self):
1321 # self.day_start gives user's start of day in hours
1322 offset = int(self.day_start * 3600) # calc day_start in seconds
1324 t1 = self.start_date.get_text()
1325 t2 = self.end_date.get_text()
1327 if t1 == '':
1328 t1 = '1970-01-02'
1329 if t2 == '':
1330 t2 = '2020-12-12'
1332 s1 = strptime(t1, "%Y-%m-%d") # make time_struct
1333 s2 = strptime(t2, "%Y-%m-%d")
1334 e1 = mktime(s1) + offset # s1 is localtime, but returned time since epoch is UTC, then add the
1335 e2 = mktime(s2) + offset # s2 is localtime, but returned time since epoch is UTC
1336 e2 = e2 + 24 * 3600 - 1 # date test is inclusive, so add 23h 59m 59s to e2
1338 adj_t1 = strftime("%Y-%m-%d %H:%M:%S", gmtime(e1)) # make adjusted string including time
1339 adj_t2 = strftime("%Y-%m-%d %H:%M:%S", gmtime(e2))
1340 log.info("t1="+t1+" adj_t1="+adj_t1+'.')
1342 return (adj_t1, adj_t2)
1343 #end def __get_dates
1345 def __get_date(self, widget, calendar, entry, win):
1346 # year and day are correct, month is 0..11
1347 (year, month, day) = calendar.get_date()
1348 month += 1
1349 ds = '%04d-%02d-%02d' % (year, month, day)
1350 entry.set_text(ds)
1351 win.destroy()
1353 # if the opposite date is set, and now the start date is later
1354 # than the end date, modify the one we didn't just set to be
1355 # the same as the one we did just set
1356 if (entry == self.start_date):
1357 end = self.end_date.get_text()
1358 if (end and ds > end):
1359 self.end_date.set_text(ds)
1360 else:
1361 start = self.start_date.get_text()
1362 if (start and ds < start):
1363 self.start_date.set_text(ds)
1365 def __seats_changed(self, widget, which):
1366 seats_from = self.sbSeats['from'].get_value_as_int()
1367 seats_to = self.sbSeats['to'].get_value_as_int()
1368 if (seats_from > seats_to):
1369 if (which == 'from'):
1370 self.sbSeats['to'].set_value(seats_from)
1371 else:
1372 self.sbSeats['from'].set_value(seats_to)
1374 def main(argv=None):
1375 """main can also be called in the python interpreter, by supplying the command line as the argument."""
1376 if argv is None:
1377 argv = sys.argv[1:]
1379 def destroy(*args): # call back for terminating the main eventloop
1380 gtk.main_quit()
1382 parser = OptionParser()
1383 (options, argv) = parser.parse_args(args = argv)
1385 config = Configuration.Config()
1386 db = None
1388 db = Database.Database()
1389 db.do_connect(config)
1391 qdict = SQL.SQL(db.get_backend_name())
1393 i = Filters(db, config, qdict)
1394 main_window = gtk.Window()
1395 main_window.connect('destroy', destroy)
1396 main_window.add(i.get_vbox())
1397 main_window.show()
1398 gtk.main()
1400 if __name__ == '__main__':
1401 sys.exit(main())