In the "Games" filter, 27_3draw was showing up as 273draw with the 3 underlined....
[fpdb-dooglus.git] / pyfpdb / Filters.py
blob85f93f48626d27f39fa806a814838cd59f4e573f
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 # text used on screen stored here so that it can be configured
53 self.filterText = {'limitsall':_('All'), 'limitsnone':_('None'), 'limitsshow':_('Show _Limits')
54 ,'seatsbetween':_('Between:'), 'seatsand':_('And:'), 'seatsshow':_('Show Number of _Players')
55 ,'playerstitle':_('Hero:'), 'sitestitle':(_('Sites')+':'), 'gamestitle':(_('Games')+':')
56 ,'limitstitle':_('Limits:'), 'seatstitle':_('Number of Players:')
57 ,'groupstitle':_('Grouping:'), 'posnshow':_('Show Position Stats')
58 ,'datestitle':_('Date:')
59 ,'groupsall':_('All Players')
60 ,'limitsFL':'FL', 'limitsNL':'NL', 'limitsPL':'PL', 'limitsCN':'CAP', 'ring':_('Ring'), 'tour':_('Tourney')
63 gen = self.conf.get_general_params()
64 self.day_start = 0
66 if 'day_start' in gen:
67 self.day_start = float(gen['day_start'])
70 self.sw = gtk.ScrolledWindow()
71 self.sw.set_border_width(0)
72 self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
73 self.sw.set_size_request(235, 300)
76 # Outer Packing box
77 self.mainVBox = gtk.VBox(False, 0)
78 self.sw.add_with_viewport(self.mainVBox)
79 self.sw.show()
80 #print(_("DEBUG:") + _("New packing box created!"))
82 self.found = {'nl':False, 'fl':False, 'pl':False, 'cn':False, 'ring':False, 'tour':False}
83 self.label = {}
84 self.callback = {}
86 self.make_filter()
88 def make_filter(self):
89 self.sites = {}
90 self.games = {}
91 self.limits = {}
92 self.seats = {}
93 self.groups = {}
94 self.siteid = {}
95 self.heroes = {}
96 self.boxes = {}
97 self.toggles = {}
98 self.graphops = {}
100 for site in self.conf.get_supported_sites():
101 #Get db site id for filtering later
102 self.cursor.execute(self.sql.query['getSiteId'], (site,))
103 result = self.db.cursor.fetchall()
104 if len(result) == 1:
105 self.siteid[site] = result[0][0]
106 else:
107 print _("Either 0 or more than one site matched (%s) - EEK") % site
109 # For use in date ranges.
110 self.start_date = gtk.Entry(max=12)
111 self.start_date.set_width_chars(12)
112 self.end_date = gtk.Entry(max=12)
113 self.end_date.set_width_chars(12)
114 self.start_date.set_property('editable', False)
115 self.end_date.set_property('editable', False)
117 # For use in groups etc
118 self.sbGroups = {}
119 self.numHands = 0
121 # for use in graphops
122 # dspin = display in '$' or 'B'
123 self.graphops['dspin'] = "$"
124 self.graphops['showdown'] = 'OFF'
125 self.graphops['nonshowdown'] = 'OFF'
127 playerFrame = gtk.Frame()
128 playerFrame.set_label_align(0.0, 0.0)
129 vbox = gtk.VBox(False, 0)
131 self.fillPlayerFrame(vbox, self.display)
132 playerFrame.add(vbox)
134 sitesFrame = gtk.Frame()
135 sitesFrame.set_label_align(0.0, 0.0)
136 vbox = gtk.VBox(False, 0)
138 self.fillSitesFrame(vbox)
139 sitesFrame.add(vbox)
141 # Game types
142 gamesFrame = gtk.Frame()
143 gamesFrame.set_label_align(0.0, 0.0)
144 gamesFrame.show()
145 vbox = gtk.VBox(False, 0)
147 self.fillGamesFrame(vbox)
148 gamesFrame.add(vbox)
150 # Limits
151 limitsFrame = gtk.Frame()
152 limitsFrame.show()
153 vbox = gtk.VBox(False, 0)
154 self.cbLimits = {}
155 self.cbNoLimits = None
156 self.cbAllLimits = None
157 self.cbFL = None
158 self.cbNL = None
159 self.cbPL = None
160 self.cbCN = None
161 self.rb = {} # radio buttons for ring/tour
162 self.type = None # ring/tour
163 self.types = {} # list of all ring/tour values
164 self.num_limit_types = 0
166 self.fillLimitsFrame(vbox, self.display)
167 limitsFrame.add(vbox)
169 # GraphOps
170 graphopsFrame = gtk.Frame()
171 #graphops.set_label_align(0,0, 0.0)
172 graphopsFrame.show()
173 vbox = gtk.VBox(False, 0)
175 self.fillGraphOpsFrame(vbox)
176 graphopsFrame.add(vbox)
179 # Seats
180 seatsFrame = gtk.Frame()
181 seatsFrame.show()
182 vbox = gtk.VBox(False, 0)
183 self.sbSeats = {}
185 self.fillSeatsFrame(vbox, self.display)
186 seatsFrame.add(vbox)
188 # Groups
189 groupsFrame = gtk.Frame()
190 groupsFrame.show()
191 vbox = gtk.VBox(False, 0)
193 self.fillGroupsFrame(vbox, self.display)
194 groupsFrame.add(vbox)
196 # Date
197 dateFrame = gtk.Frame()
198 dateFrame.set_label_align(0.0, 0.0)
199 dateFrame.show()
200 vbox = gtk.VBox(False, 0)
202 self.fillDateFrame(vbox)
203 dateFrame.add(vbox)
205 # Buttons
206 self.Button1=gtk.Button("Unnamed 1")
207 self.Button1.set_sensitive(False)
209 self.Button2=gtk.Button("Unnamed 2")
210 self.Button2.set_sensitive(False)
212 expand = False
213 self.mainVBox.pack_start(playerFrame, expand)
214 self.mainVBox.pack_start(sitesFrame, expand)
215 self.mainVBox.pack_start(gamesFrame, expand)
216 self.mainVBox.pack_start(limitsFrame, expand)
217 self.mainVBox.pack_start(seatsFrame, expand)
218 self.mainVBox.pack_start(groupsFrame, expand)
219 self.mainVBox.pack_start(dateFrame, expand)
220 self.mainVBox.pack_start(graphopsFrame, expand)
221 self.mainVBox.pack_start(gtk.VBox(False, 0))
222 self.mainVBox.pack_start(self.Button1, expand)
223 self.mainVBox.pack_start(self.Button2, expand)
225 self.mainVBox.show_all()
227 # Should do this cleaner
228 if "Heroes" not in self.display or self.display["Heroes"] == False:
229 playerFrame.hide()
230 if "Sites" not in self.display or self.display["Sites"] == False:
231 sitesFrame.hide()
232 if "Games" not in self.display or self.display["Games"] == False:
233 gamesFrame.hide()
234 if "Limits" not in self.display or self.display["Limits"] == False:
235 limitsFrame.hide()
236 if "Seats" not in self.display or self.display["Seats"] == False:
237 seatsFrame.hide()
238 if "Groups" not in self.display or self.display["Groups"] == False:
239 groupsFrame.hide()
240 if "Dates" not in self.display or self.display["Dates"] == False:
241 dateFrame.hide()
242 if "GraphOps" not in self.display or self.display["GraphOps"] == False:
243 graphopsFrame.hide()
244 if "Button1" not in self.display or self.display["Button1"] == False:
245 self.Button1.hide()
246 if "Button2" not in self.display or self.display["Button2"] == False:
247 self.Button2.hide()
249 if 'button1' in self.label and self.label['button1']:
250 self.Button1.set_label( self.label['button1'] )
251 if 'button2' in self.label and self.label['button2']:
252 self.Button2.set_label( self.label['button2'] )
253 if 'button1' in self.callback and self.callback['button1']:
254 self.Button1.connect("clicked", self.callback['button1'], "clicked")
255 self.Button1.set_sensitive(True)
256 if 'button2' in self.callback and self.callback['button2']:
257 self.Button2.connect("clicked", self.callback['button2'], "clicked")
258 self.Button2.set_sensitive(True)
260 # make sure any locks on db are released:
261 self.db.rollback()
263 def get_vbox(self):
264 """returns the vbox of this thread"""
265 return self.sw
266 #end def get_vbox
268 def getNumHands(self):
269 return self.numHands
270 #end def getNumHands
272 def getNumTourneys(self):
273 return self.numTourneys
274 #end def getNumTourneys
276 def getSites(self):
277 return self.sites
278 #end def getSites
280 def getTourneyTypes(self):
281 return self.tourneyTypes
282 #end def getTourneyTypes
284 def getGames(self):
285 return self.games
286 #end def getGames
288 def getSiteIds(self):
289 return self.siteid
290 #end def getSiteIds
292 def getHeroes(self):
293 return self.heroes
294 #end def getHeroes
296 def getGraphOps(self):
297 return self.graphops
299 def getLimits(self):
300 ltuple = []
301 for l in self.limits:
302 if self.limits[l] == True:
303 ltuple.append(l)
304 return ltuple
306 def getType(self):
307 return(self.type)
309 def getSeats(self):
310 if 'from' in self.sbSeats:
311 self.seats['from'] = self.sbSeats['from'].get_value_as_int()
312 if 'to' in self.sbSeats:
313 self.seats['to'] = self.sbSeats['to'].get_value_as_int()
314 return self.seats
315 #end def getSeats
317 def getGroups(self):
318 return self.groups
320 def getDates(self):
321 return self.__get_dates()
322 #end def getDates
324 def registerButton1Name(self, title):
325 self.Button1.set_label(title)
326 self.label['button1'] = title
328 def registerButton1Callback(self, callback):
329 self.Button1.connect("clicked", callback, "clicked")
330 self.Button1.set_sensitive(True)
331 self.callback['button1'] = callback
333 def registerButton2Name(self, title):
334 self.Button2.set_label(title)
335 self.label['button2'] = title
336 #end def registerButton2Name
338 def registerButton2Callback(self, callback):
339 self.Button2.connect("clicked", callback, "clicked")
340 self.Button2.set_sensitive(True)
341 self.callback['button2'] = callback
342 #end def registerButton2Callback
344 def cardCallback(self, widget, data=None):
345 log.debug( _("%s was toggled %s") % (data, (_("OFF"), _("ON"))[widget.get_active()]) )
347 def createPlayerLine(self, vbox, site, player):
348 log.debug('add:"%s"' % player)
349 label = gtk.Label(site +" id:")
350 label.set_alignment(xalign=0.0, yalign=1.0)
351 vbox.pack_start(label, False, False, 3)
353 hbox = gtk.HBox(False, 0)
354 vbox.pack_start(hbox, False, True, 0)
356 pname = gtk.Entry()
357 pname.set_text(player)
358 pname.set_width_chars(20)
359 hbox.pack_start(pname, True, True, 20)
360 pname.connect("changed", self.__set_hero_name, site)
362 # Added EntryCompletion but maybe comboBoxEntry is more flexible? (e.g. multiple choices)
363 completion = gtk.EntryCompletion()
364 pname.set_completion(completion)
365 liststore = gtk.ListStore(gobject.TYPE_STRING)
366 completion.set_model(liststore)
367 completion.set_text_column(0)
368 names = self.db.get_player_names(self.conf, self.siteid[site]) # (config=self.conf, site_id=None, like_player_name="%")
369 for n in names: # list of single-element "tuples"
370 _n = Charset.to_gui(n[0])
371 _nt = (_n, )
372 liststore.append(_nt)
374 self.__set_hero_name(pname, site)
375 #end def createPlayerLine
377 def __set_hero_name(self, w, site):
378 _name = w.get_text()
379 # get_text() returns a str but we want internal variables to be unicode:
380 _guiname = unicode(_name)
381 self.heroes[site] = _guiname
382 #log.debug("setting heroes[%s]: %s"%(site, self.heroes[site]))
383 #end def __set_hero_name
385 def __set_num_hands(self, w, val):
386 try:
387 self.numHands = int(w.get_text())
388 except:
389 self.numHands = 0
390 #log.debug("setting numHands:", self.numHands)
391 #end def __set_num_hands
393 def createSiteLine(self, hbox, site):
394 cb = gtk.CheckButton(site)
395 cb.connect('clicked', self.__set_site_select, site)
396 cb.set_active(True)
397 hbox.pack_start(cb, False, False, 0)
398 #end def createSiteLine
400 def __set_tourney_type_select(self, w, tourneyType):
401 #print w.get_active()
402 self.tourneyTypes[tourneyType] = w.get_active()
403 log.debug("self.tourney_types[%s] set to %s" %(tourneyType, self.tourneyTypes[tourneyType]))
404 #end def __set_tourney_type_select
406 def createTourneyTypeLine(self, hbox, tourneyType):
407 cb = gtk.CheckButton(str(tourneyType))
408 cb.connect('clicked', self.__set_tourney_type_select, tourneyType)
409 hbox.pack_start(cb, False, False, 0)
410 cb.set_active(True)
411 #end def createTourneyTypeLine
413 def createGameLine(self, hbox, game):
414 cb = gtk.CheckButton(game.replace("_", "__"))
415 cb.connect('clicked', self.__set_game_select, game)
416 hbox.pack_start(cb, False, False, 0)
417 cb.set_active(True)
419 def createLimitLine(self, hbox, limit, ltext):
420 cb = gtk.CheckButton(str(ltext))
421 cb.connect('clicked', self.__set_limit_select, limit)
422 hbox.pack_start(cb, False, False, 0)
423 if limit != "none":
424 cb.set_active(True)
425 return(cb)
427 def __set_site_select(self, w, site):
428 #print w.get_active()
429 self.sites[site] = w.get_active()
430 log.debug(_("self.sites[%s] set to %s") %(site, self.sites[site]))
431 #end def __set_site_select
433 def __set_game_select(self, w, game):
434 #print w.get_active()
435 self.games[game] = w.get_active()
436 log.debug(_("self.games[%s] set to %s") %(game, self.games[game]))
437 #end def __set_game_select
439 def __set_limit_select(self, w, limit):
440 #print "__set_limit_select: limit =", limit, w.get_active()
441 self.limits[limit] = w.get_active()
442 log.debug(_("self.limit[%s] set to %s") %(limit, self.limits[limit]))
443 if limit.isdigit() or (len(limit) > 2 and (limit[-2:] == 'nl' or limit[-2:] == 'fl' or limit[-2:] == 'pl' or limit[-2:] == 'cn')):
444 # turning a leaf limit on with 'None' checked turns 'None' off
445 if self.limits[limit]:
446 if self.cbNoLimits is not None:
447 self.cbNoLimits.set_active(False)
448 # turning a leaf limit off with 'All' checked turns 'All' off
449 else:
450 if self.cbAllLimits is not None:
451 self.cbAllLimits.set_active(False)
452 # turning off a leaf limit turns off the corresponding fl. nl, cn or pl
453 if not self.limits[limit]:
454 if limit.isdigit():
455 if self.cbFL is not None:
456 self.cbFL.set_active(False)
457 elif (len(limit) > 2 and (limit[-2:] == 'nl')):
458 if self.cbNL is not None:
459 self.cbNL.set_active(False)
460 elif (len(limit) > 2 and (limit[-2:] == 'cn')):
461 if self.cbCN is not None:
462 self.cbCN.set_active(False)
463 else:
464 if self.cbPL is not None:
465 self.cbPL.set_active(False)
466 elif limit == "all":
467 if self.limits[limit]:
468 if self.num_limit_types == 1:
469 for cb in self.cbLimits.values():
470 cb.set_active(True)
471 else:
472 if self.cbFL is not None:
473 self.cbFL.set_active(True)
474 if self.cbNL is not None:
475 self.cbNL.set_active(True)
476 if self.cbPL is not None:
477 self.cbPL.set_active(True)
478 if self.cbCN is not None:
479 self.cbCN.set_active(True)
480 elif limit == "none":
481 if self.limits[limit]:
482 if self.num_limit_types > 1:
483 if self.cbNL is not None:
484 self.cbNL.set_active(False)
485 if self.cbFL is not None:
486 self.cbFL.set_active(False)
487 if self.cbPL is not None:
488 self.cbPL.set_active(False)
489 if self.cbCN is not None:
490 self.cbCN.set_active(False)
492 # Finally, clean-up all individual limit checkboxes
493 # needed because the overall limit checkbox may
494 # not be set, or num_limit_types == 1
496 for cb in self.cbLimits.values():
497 cb.set_active(False)
498 elif limit == "fl":
499 if not self.limits[limit]:
500 # only toggle all fl limits off if they are all currently on
501 # this stops turning one off from cascading into 'fl' box off
502 # and then all fl limits being turned off
503 all_fl_on = True
504 for cb in self.cbLimits.values():
505 t = cb.get_children()[0].get_text()
506 if t.isdigit():
507 if not cb.get_active():
508 all_fl_on = False
509 found = {'ring':False, 'tour':False}
510 for cb in self.cbLimits.values():
511 #print "cb label: ", cb.children()[0].get_text()
512 t = cb.get_children()[0].get_text()
513 if t.isdigit():
514 if self.limits[limit] or all_fl_on:
515 cb.set_active(self.limits[limit])
516 found[self.types[t]] = True
517 if self.limits[limit]:
518 if not found[self.type]:
519 if self.type == 'ring':
520 if 'tour' in self.rb:
521 self.rb['tour'].set_active(True)
522 elif self.type == 'tour':
523 if 'ring' in self.rb:
524 self.rb['ring'].set_active(True)
525 elif limit == "nl":
526 if not self.limits[limit]:
527 # only toggle all nl limits off if they are all currently on
528 # this stops turning one off from cascading into 'nl' box off
529 # and then all nl limits being turned off
530 all_nl_on = True
531 for cb in self.cbLimits.values():
532 t = cb.get_children()[0].get_text()
533 if "nl" in t and len(t) > 2:
534 if not cb.get_active():
535 all_nl_on = False
536 found = {'ring':False, 'tour':False}
537 for cb in self.cbLimits.values():
538 t = cb.get_children()[0].get_text()
539 if "nl" in t and len(t) > 2:
540 if self.limits[limit] or all_nl_on:
541 cb.set_active(self.limits[limit])
542 found[self.types[t]] = True
543 if self.limits[limit]:
544 if not found[self.type]:
545 if self.type == 'ring':
546 if 'tour' in self.rb:
547 self.rb['tour'].set_active(True)
548 elif self.type == 'tour':
549 if 'ring' in self.rb:
550 self.rb['ring'].set_active(True)
551 elif limit == "pl":
552 if not self.limits[limit]:
553 # only toggle all nl limits off if they are all currently on
554 # this stops turning one off from cascading into 'nl' box off
555 # and then all nl limits being turned off
556 all_nl_on = True
557 for cb in self.cbLimits.values():
558 t = cb.get_children()[0].get_text()
559 if "pl" in t and len(t) > 2:
560 if not cb.get_active():
561 all_nl_on = False
562 found = {'ring':False, 'tour':False}
563 for cb in self.cbLimits.values():
564 t = cb.get_children()[0].get_text()
565 if "pl" in t and len(t) > 2:
566 if self.limits[limit] or all_nl_on:
567 cb.set_active(self.limits[limit])
568 found[self.types[t]] = True
569 if self.limits[limit]:
570 if not found[self.type]:
571 if self.type == 'ring':
572 if 'tour' in self.rb:
573 self.rb['tour'].set_active(True)
574 elif self.type == 'tour':
575 if 'ring' in self.rb:
576 self.rb['ring'].set_active(True)
577 elif limit == "cn":
578 if not self.limits[limit]:
579 all_cn_on = True
580 for cb in self.cbLimits.values():
581 t = cb.get_children()[0].get_text()
582 if "cn" in t and len(t) > 2:
583 if not cb.get_active():
584 all_cn_on = False
585 found = {'ring':False, 'tour':False}
586 for cb in self.cbLimits.values():
587 t = cb.get_children()[0].get_text()
588 if "cn" in t and len(t) > 2:
589 if self.limits[limit] or all_cn_on:
590 cb.set_active(self.limits[limit])
591 found[self.types[t]] = True
592 if self.limits[limit]:
593 if not found[self.type]:
594 if self.type == 'ring':
595 if 'tour' in self.rb:
596 self.rb['tour'].set_active(True)
597 elif self.type == 'tour':
598 if 'ring' in self.rb:
599 self.rb['ring'].set_active(True)
600 elif limit == "ring":
601 log.debug("set", limit, "to", self.limits[limit])
602 if self.limits[limit]:
603 self.type = "ring"
604 for cb in self.cbLimits.values():
605 #print "cb label: ", cb.children()[0].get_text()
606 if self.types[cb.get_children()[0].get_text()] == 'tour':
607 cb.set_active(False)
608 elif limit == "tour":
609 log.debug( "set", limit, "to", self.limits[limit] )
610 if self.limits[limit]:
611 self.type = "tour"
612 for cb in self.cbLimits.values():
613 #print "cb label: ", cb.children()[0].get_text()
614 if self.types[cb.get_children()[0].get_text()] == 'ring':
615 cb.set_active(False)
617 def __set_seat_select(self, w, seat):
618 #print "__set_seat_select: seat =", seat, "active =", w.get_active()
619 self.seats[seat] = w.get_active()
620 log.debug( _("self.seats[%s] set to %s") %(seat, self.seats[seat]) )
621 #end def __set_seat_select
623 def __set_group_select(self, w, group):
624 #print "__set_seat_select: seat =", seat, "active =", w.get_active()
625 self.groups[group] = w.get_active()
626 log.debug( _("self.groups[%s] set to %s") %(group, self.groups[group]) )
629 def __set_displayin_select(self, w, ops):
630 self.graphops['dspin'] = ops
632 def __set_graphopscheck_select(self, w, data):
633 #print "%s was toggled %s" % (data, ("OFF", "ON")[w.get_active()])
634 self.graphops[data] = ("OFF", "ON")[w.get_active()]
636 def fillPlayerFrame(self, vbox, display):
637 top_hbox = gtk.HBox(False, 0)
638 vbox.pack_start(top_hbox, False, False, 0)
639 lbl_title = gtk.Label(self.filterText['playerstitle'])
640 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
641 top_hbox.pack_start(lbl_title, expand=True, padding=3)
643 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
644 showb.set_alignment(xalign=1.0, yalign=0.5)
645 showb.connect('clicked', self.__toggle_box, 'Heroes')
646 self.toggles['Heroes'] = showb
647 showb.show()
648 top_hbox.pack_end(showb, expand=False, padding=1)
650 showb = gtk.Button(label=_("hide all"), stock=None, use_underline=True)
651 showb.set_alignment(xalign=1.0, yalign=0.5)
652 showb.connect('clicked', self.__toggle_box, 'all')
653 self.toggles['all'] = showb
654 showb.show()
655 top_hbox.pack_end(showb, expand=False, padding=1)
657 showb = gtk.Button(label=_("Refresh"), stock=None, use_underline=True)
658 showb.set_alignment(xalign=1.0, yalign=0.5)
659 showb.connect('clicked', self.__refresh, 'Heroes')
661 vbox1 = gtk.VBox(False, 0)
662 vbox.pack_start(vbox1, False, False, 0)
663 self.boxes['Heroes'] = vbox1
665 for site in self.conf.get_supported_sites():
666 player = self.conf.supported_sites[site].screen_name
667 _pname = Charset.to_gui(player)
668 self.createPlayerLine(vbox1, site, _pname)
670 if "GroupsAll" in display and display["GroupsAll"] == True:
671 hbox = gtk.HBox(False, 0)
672 vbox1.pack_start(hbox, False, False, 0)
673 cb = gtk.CheckButton(self.filterText['groupsall'])
674 cb.connect('clicked', self.__set_group_select, 'allplayers')
675 hbox.pack_start(cb, False, False, 0)
676 self.sbGroups['allplayers'] = cb
677 self.groups['allplayers'] = False
679 lbl = gtk.Label(_('Min # Hands:'))
680 lbl.set_alignment(xalign=1.0, yalign=0.5)
681 hbox.pack_start(lbl, expand=True, padding=3)
683 phands = gtk.Entry()
684 phands.set_text('0')
685 phands.set_width_chars(8)
686 hbox.pack_start(phands, False, False, 0)
687 phands.connect("changed", self.__set_num_hands, site)
688 top_hbox.pack_start(showb, expand=False, padding=1)
689 #end def fillPlayerFrame
691 def fillSitesFrame(self, vbox):
692 top_hbox = gtk.HBox(False, 0)
693 top_hbox.show()
694 vbox.pack_start(top_hbox, False, False, 0)
696 lbl_title = gtk.Label(self.filterText['sitestitle'])
697 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
698 top_hbox.pack_start(lbl_title, expand=True, padding=3)
700 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
701 showb.set_alignment(xalign=1.0, yalign=0.5)
702 showb.connect('clicked', self.__toggle_box, 'Sites')
703 self.toggles['Sites'] = showb
704 showb.show()
705 top_hbox.pack_start(showb, expand=False, padding=1)
707 vbox1 = gtk.VBox(False, 0)
708 self.boxes['Sites'] = vbox1
709 vbox.pack_start(vbox1, False, False, 0)
711 for site in self.conf.get_supported_sites():
712 hbox = gtk.HBox(False, 0)
713 vbox1.pack_start(hbox, False, True, 0)
714 self.createSiteLine(hbox, site)
715 #Get db site id for filtering later
716 #self.cursor.execute(self.sql.query['getSiteId'], (site,))
717 #result = self.db.cursor.fetchall()
718 #if len(result) == 1:
719 # self.siteid[site] = result[0][0]
720 #else:
721 # print "Either 0 or more than one site matched - EEK"
722 #end def fillSitesFrame
724 def fillTourneyTypesFrame(self, vbox):
725 top_hbox = gtk.HBox(False, 0)
726 vbox.pack_start(top_hbox, False, False, 0)
727 lbl_title = gtk.Label(self.filterText['tourneyTypesTitle'])
728 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
729 top_hbox.pack_start(lbl_title, expand=True, padding=3)
730 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
731 showb.set_alignment(xalign=1.0, yalign=0.5)
732 showb.connect('clicked', self.__toggle_box, 'tourneyTypes')
733 self.toggles['tourneyTypes'] = showb
734 top_hbox.pack_start(showb, expand=False, padding=1)
736 vbox1 = gtk.VBox(False, 0)
737 vbox.pack_start(vbox1, False, False, 0)
738 self.boxes['tourneyTypes'] = vbox1
740 result = self.db.getTourneyTypesIds()
741 if len(result) >= 1:
742 for line in result:
743 hbox = gtk.HBox(False, 0)
744 vbox1.pack_start(hbox, False, True, 0)
745 self.createTourneyTypeLine(hbox, line[0])
746 else:
747 print _("INFO: No tourney types returned from database")
748 log.info(_("No tourney types returned from database"))
749 #end def fillTourneyTypesFrame
751 def fillGamesFrame(self, vbox):
752 top_hbox = gtk.HBox(False, 0)
753 vbox.pack_start(top_hbox, False, False, 0)
754 lbl_title = gtk.Label(self.filterText['gamestitle'])
755 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
756 top_hbox.pack_start(lbl_title, expand=True, padding=3)
757 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
758 showb.set_alignment(xalign=1.0, yalign=0.5)
759 showb.connect('clicked', self.__toggle_box, 'Games')
760 self.toggles['Games'] = showb
761 top_hbox.pack_start(showb, expand=False, padding=1)
763 vbox1 = gtk.VBox(False, 0)
764 vbox.pack_start(vbox1, False, False, 0)
765 self.boxes['Games'] = vbox1
767 self.cursor.execute(self.sql.query['getGames'])
768 result = self.db.cursor.fetchall()
769 if len(result) >= 1:
770 for line in result:
771 hbox = gtk.HBox(False, 0)
772 vbox1.pack_start(hbox, False, True, 0)
773 self.createGameLine(hbox, line[0])
774 else:
775 print _("INFO: No games returned from database")
776 log.info(_("No games returned from database"))
777 #end def fillGamesFrame
779 def fillLimitsFrame(self, vbox, display):
780 top_hbox = gtk.HBox(False, 0)
781 vbox.pack_start(top_hbox, False, False, 0)
782 lbl_title = gtk.Label(self.filterText['limitstitle'])
783 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
784 top_hbox.pack_start(lbl_title, expand=True, padding=3)
785 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
786 showb.set_alignment(xalign=1.0, yalign=0.5)
787 showb.connect('clicked', self.__toggle_box, 'Limits')
788 self.toggles['Limits'] = showb
789 top_hbox.pack_start(showb, expand=False, padding=1)
791 vbox1 = gtk.VBox(False, 15)
792 vbox.pack_start(vbox1, False, False, 0)
793 self.boxes['Limits'] = vbox1
795 self.cursor.execute(self.sql.query['getCashLimits'])
796 # selects limitType, bigBlind
797 result = self.db.cursor.fetchall()
798 self.found = {'nl':False, 'fl':False, 'pl':False, 'cn':False, 'ring':False, 'tour':False}
800 if len(result) >= 1:
801 hbox = gtk.HBox(True, 0)
802 vbox1.pack_start(hbox, False, False, 0)
803 vbox2 = gtk.VBox(False, 0)
804 hbox.pack_start(vbox2, False, False, 0)
805 vbox3 = gtk.VBox(False, 0)
806 hbox.pack_start(vbox3, False, False, 0)
807 for i, line in enumerate(result):
808 if "UseType" in self.display:
809 if line[0] != self.display["UseType"]:
810 continue
811 hbox = gtk.HBox(False, 0)
812 if i < len(result)/2:
813 vbox2.pack_start(hbox, False, False, 0)
814 else:
815 vbox3.pack_start(hbox, False, False, 0)
816 if True: #line[0] == 'ring':
817 if line[1] == 'fl':
818 name = str(line[2])
819 self.found['fl'] = True
820 elif line[1] == 'pl':
821 name = str(line[2])+line[1]
822 self.found['pl'] = True
823 elif line[1] == 'cn':
824 name = str(line[2])+line[1]
825 self.found['cn'] = True
826 else:
827 name = str(line[2])+line[1]
828 self.found['nl'] = True
829 self.cbLimits[name] = self.createLimitLine(hbox, name, name)
830 self.types[name] = line[0]
831 self.found[line[0]] = True # type is ring/tour
832 self.type = line[0] # if only one type, set it now
833 if "LimitSep" in display and display["LimitSep"] == True and len(result) >= 2:
834 hbox = gtk.HBox(True, 0)
835 vbox1.pack_start(hbox, False, False, 0)
836 vbox2 = gtk.VBox(False, 0)
837 hbox.pack_start(vbox2, False, False, 0)
838 vbox3 = gtk.VBox(False, 0)
839 hbox.pack_start(vbox3, False, False, 0)
841 hbox = gtk.HBox(False, 0)
842 vbox2.pack_start(hbox, False, False, 0)
843 self.cbAllLimits = self.createLimitLine(hbox, 'all', self.filterText['limitsall'])
844 hbox = gtk.HBox(False, 0)
845 vbox2.pack_start(hbox, False, False, 0)
846 self.cbNoLimits = self.createLimitLine(hbox, 'none', self.filterText['limitsnone'])
848 dest = vbox3 # for ring/tour buttons
849 if "LimitType" in display and display["LimitType"] == True:
850 self.num_limit_types = 0
851 if self.found['fl']: self.num_limit_types = self.num_limit_types + 1
852 if self.found['pl']: self.num_limit_types = self.num_limit_types + 1
853 if self.found['nl']: self.num_limit_types = self.num_limit_types + 1
854 if self.found['cn']: self.num_limit_types = self.num_limit_types + 1
855 if self.num_limit_types > 1:
856 if self.found['fl']:
857 hbox = gtk.HBox(False, 0)
858 vbox3.pack_start(hbox, False, False, 0)
859 self.cbFL = self.createLimitLine(hbox, 'fl', self.filterText['limitsFL'])
860 if self.found['nl']:
861 hbox = gtk.HBox(False, 0)
862 vbox3.pack_start(hbox, False, False, 0)
863 self.cbNL = self.createLimitLine(hbox, 'nl', self.filterText['limitsNL'])
864 if self.found['pl']:
865 hbox = gtk.HBox(False, 0)
866 vbox3.pack_start(hbox, False, False, 0)
867 self.cbPL = self.createLimitLine(hbox, 'pl', self.filterText['limitsPL'])
868 if self.found['cn']:
869 hbox = gtk.HBox(False, 0)
870 vbox3.pack_start(hbox, False, False, 0)
871 self.cbCN = self.createLimitLine(hbox, 'cn', self.filterText['limitsCN'])
872 dest = vbox2 # for ring/tour buttons
873 else:
874 print _("INFO: No games returned from database")
875 log.info(_("No games returned from database"))
877 if "Type" in display and display["Type"] == True and self.found['ring'] and self.found['tour']:
878 rb1 = gtk.RadioButton(None, self.filterText['ring'])
879 rb1.connect('clicked', self.__set_limit_select, 'ring')
880 rb2 = gtk.RadioButton(rb1, self.filterText['tour'])
881 rb2.connect('clicked', self.__set_limit_select, 'tour')
882 top_hbox.pack_start(rb1, False, False, 0) # (child, expand, fill, padding)
883 top_hbox.pack_start(rb2, True, True, 0) # child uses expand space if fill is true
885 self.rb['ring'] = rb1
886 self.rb['tour'] = rb2
887 #print "about to set ring to true"
888 rb1.set_active(True)
889 # set_active doesn't seem to call this for some reason so call manually:
890 self.__set_limit_select(rb1, 'ring')
891 self.type = 'ring'
892 top_hbox.pack_start(showb, expand=False, padding=1)
894 def fillGraphOpsFrame(self, vbox):
895 top_hbox = gtk.HBox(False, 0)
896 vbox.pack_start(top_hbox, False, False, 0)
897 title = gtk.Label(_("Graphing Options:"))
898 title.set_alignment(xalign=0.0, yalign=0.5)
899 top_hbox.pack_start(title, expand=True, padding=3)
900 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
901 showb.set_alignment(xalign=1.0, yalign=0.5)
902 showb.connect('clicked', self.__toggle_box, 'GraphOps')
903 self.toggles['GraphOps'] = showb
904 top_hbox.pack_start(showb, expand=False, padding=1)
906 vbox1 = gtk.VBox(False, 0)
907 vbox.pack_start(vbox1, False, False, 0)
908 vbox1.show()
909 self.boxes['GraphOps'] = vbox1
911 hbox1 = gtk.HBox(False, 0)
912 vbox1.pack_start(hbox1, False, False, 0)
913 hbox1.show()
915 label = gtk.Label(_("Show Graph In:"))
916 label.set_alignment(xalign=0.0, yalign=0.5)
917 hbox1.pack_start(label, True, True, 0)
918 label.show()
920 button = gtk.RadioButton(None, "$$")
921 hbox1.pack_start(button, True, True, 0)
922 button.connect("toggled", self.__set_displayin_select, "$")
923 button.set_active(True)
924 button.show()
926 button = gtk.RadioButton(button, "BB")
927 hbox1.pack_start(button, True, True, 0)
928 button.connect("toggled", self.__set_displayin_select, "BB")
929 button.show()
931 button = gtk.CheckButton(_("Showdown Winnings"), False)
932 vbox1.pack_start(button, True, True, 0)
933 # wouldn't it be awesome if there was a way to remember the state of things like
934 # this and be able to set it to what it was last time?
935 #button.set_active(True)
936 button.connect("toggled", self.__set_graphopscheck_select, "showdown")
937 button.show()
939 button = gtk.CheckButton(_("Non-Showdown Winnings"), False)
940 vbox1.pack_start(button, True, True, 0)
941 # ditto as 8 lines up :)
942 #button.set_active(True)
943 button.connect("toggled", self.__set_graphopscheck_select, "nonshowdown");
944 button.show()
946 def fillSeatsFrame(self, vbox, display):
947 hbox = gtk.HBox(False, 0)
948 vbox.pack_start(hbox, False, False, 0)
949 lbl_title = gtk.Label(self.filterText['seatstitle'])
950 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
951 hbox.pack_start(lbl_title, expand=True, padding=3)
952 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
953 showb.set_alignment(xalign=1.0, yalign=0.5)
954 showb.connect('clicked', self.__toggle_box, 'Seats')
955 self.toggles['Seats'] = showb
956 hbox.pack_start(showb, expand=False, padding=1)
958 vbox1 = gtk.VBox(False, 0)
959 vbox.pack_start(vbox1, False, False, 0)
960 self.boxes['Seats'] = vbox1
962 hbox = gtk.HBox(False, 0)
963 vbox1.pack_start(hbox, False, True, 0)
965 lbl_from = gtk.Label(self.filterText['seatsbetween'])
966 lbl_to = gtk.Label(self.filterText['seatsand'])
968 adj1 = gtk.Adjustment(value=2, lower=2, upper=10, step_incr=1, page_incr=1, page_size=0)
969 sb1 = gtk.SpinButton(adjustment=adj1, climb_rate=0.0, digits=0)
970 adj1.connect('value-changed', self.__seats_changed, 'from')
972 adj2 = gtk.Adjustment(value=10, lower=2, upper=10, step_incr=1, page_incr=1, page_size=0)
973 sb2 = gtk.SpinButton(adjustment=adj2, climb_rate=0.0, digits=0)
974 adj2.connect('value-changed', self.__seats_changed, 'to')
976 hbox.pack_start(lbl_from, expand=False, padding=3)
977 hbox.pack_start(sb1, False, False, 0)
978 hbox.pack_start(lbl_to, expand=False, padding=3)
979 hbox.pack_start(sb2, False, False, 0)
981 self.sbSeats['from'] = sb1
982 self.sbSeats['to'] = sb2
983 #end def fillSeatsFrame
985 def fillGroupsFrame(self, vbox, display):
986 hbox = gtk.HBox(False, 0)
987 vbox.pack_start(hbox, False, False, 0)
988 lbl_title = gtk.Label(self.filterText['groupstitle'])
989 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
990 hbox.pack_start(lbl_title, expand=True, padding=3)
991 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
992 showb.set_alignment(xalign=1.0, yalign=0.5)
993 showb.connect('clicked', self.__toggle_box, 'Groups')
994 self.toggles['Groups'] = showb
995 hbox.pack_start(showb, expand=False, padding=1)
997 vbox1 = gtk.VBox(False, 0)
998 vbox.pack_start(vbox1, False, False, 0)
999 self.boxes['Groups'] = vbox1
1001 hbox = gtk.HBox(False, 0)
1002 vbox1.pack_start(hbox, False, False, 0)
1003 cb = self.createLimitLine(hbox, 'show', self.filterText['limitsshow'])
1005 hbox = gtk.HBox(False, 0)
1006 vbox1.pack_start(hbox, False, True, 0)
1007 cb = gtk.CheckButton(self.filterText['posnshow'])
1008 cb.connect('clicked', self.__set_group_select, 'posn')
1009 hbox.pack_start(cb, False, False, 0)
1010 self.sbGroups['posn'] = cb
1011 self.groups['posn'] = False
1013 if "SeatSep" in display and display["SeatSep"] == True:
1014 hbox = gtk.HBox(False, 0)
1015 vbox1.pack_start(hbox, False, True, 0)
1016 cb = gtk.CheckButton(self.filterText['seatsshow'])
1017 cb.connect('clicked', self.__set_seat_select, 'show')
1018 hbox.pack_start(cb, False, False, 0)
1019 self.sbSeats['show'] = cb
1020 self.seats['show'] = False
1022 def fillCardsFrame(self, vbox):
1023 hbox1 = gtk.HBox(True,0)
1024 hbox1.show()
1025 vbox.pack_start(hbox1, True, True, 0)
1027 cards = [ "A", "K","Q","J","T","9","8","7","6","5","4","3","2" ]
1029 for j in range(0, len(cards)):
1030 hbox1 = gtk.HBox(True,0)
1031 hbox1.show()
1032 vbox.pack_start(hbox1, True, True, 0)
1033 for i in range(0, len(cards)):
1034 if i < (j + 1):
1035 suit = "o"
1036 else:
1037 suit = "s"
1038 button = gtk.ToggleButton("%s%s%s" %(cards[i], cards[j], suit))
1039 button.connect("toggled", self.cardCallback, "%s%s%s" %(cards[i], cards[j], suit))
1040 hbox1.pack_start(button, True, True, 0)
1041 button.show()
1043 def fillDateFrame(self, vbox):
1044 # Hat tip to Mika Bostrom - calendar code comes from PokerStats
1045 top_hbox = gtk.HBox(False, 0)
1046 vbox.pack_start(top_hbox, False, False, 0)
1047 lbl_title = gtk.Label(self.filterText['datestitle'])
1048 lbl_title.set_alignment(xalign=0.0, yalign=0.5)
1049 top_hbox.pack_start(lbl_title, expand=True, padding=3)
1050 showb = gtk.Button(label=_("hide"), stock=None, use_underline=True)
1051 showb.set_alignment(xalign=1.0, yalign=0.5)
1052 showb.connect('clicked', self.__toggle_box, 'Dates')
1053 self.toggles['Dates'] = showb
1054 top_hbox.pack_start(showb, expand=False, padding=1)
1056 hbox1 = gtk.HBox(False, 0)
1057 vbox.pack_start(hbox1, False, False, 0)
1058 self.boxes['Dates'] = hbox1
1060 table = gtk.Table(2,4,False)
1061 hbox1.pack_start(table, False, True, 0)
1063 lbl_start = gtk.Label(_('From:'))
1064 lbl_start.set_alignment(xalign=1.0, yalign=0.5)
1065 btn_start = gtk.Button()
1066 btn_start.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
1067 btn_start.connect('clicked', self.__calendar_dialog, self.start_date)
1068 clr_start = gtk.Button()
1069 clr_start.set_image(gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_BUTTON))
1070 clr_start.connect('clicked', self.__clear_start_date)
1072 lbl_end = gtk.Label(_('To:'))
1073 lbl_end.set_alignment(xalign=1.0, yalign=0.5)
1074 btn_end = gtk.Button()
1075 btn_end.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
1076 btn_end.connect('clicked', self.__calendar_dialog, self.end_date)
1077 clr_end = gtk.Button()
1078 clr_end.set_image(gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_BUTTON))
1079 clr_end.connect('clicked', self.__clear_end_date)
1081 table.attach(lbl_start, 0,1, 0,1)
1082 table.attach(btn_start, 1,2, 0,1)
1083 table.attach(self.start_date, 2,3, 0,1)
1084 table.attach(clr_start, 3,4, 0,1)
1086 table.attach(lbl_end, 0,1, 1,2)
1087 table.attach(btn_end, 1,2, 1,2)
1088 table.attach(self.end_date, 2,3, 1,2)
1089 table.attach(clr_end, 3,4, 1,2)
1091 #end def fillDateFrame
1093 def __refresh(self, widget, entry):
1094 for w in self.mainVBox.get_children():
1095 w.destroy()
1096 self.make_filter()
1097 #end def __refresh
1099 def __toggle_box(self, widget, entry):
1100 if (entry == "all"):
1101 if (widget.get_label() == _("hide all")):
1102 for entry in self.boxes.keys():
1103 if (self.boxes[entry].props.visible):
1104 self.__toggle_box(widget, entry)
1105 widget.set_label(_("show all"))
1106 else:
1107 for entry in self.boxes.keys():
1108 if (not self.boxes[entry].props.visible):
1109 self.__toggle_box(widget, entry)
1110 widget.set_label(_("hide all"))
1111 elif self.boxes[entry].props.visible:
1112 self.boxes[entry].hide()
1113 self.toggles[entry].set_label(_("show"))
1114 for entry in self.boxes.keys():
1115 if (self.display.has_key(entry) and
1116 self.display[entry] and
1117 self.boxes[entry].props.visible):
1118 break
1119 else:
1120 self.toggles["all"].set_label(_("show all"))
1121 else:
1122 self.boxes[entry].show()
1123 self.toggles[entry].set_label(_("hide"))
1124 for entry in self.boxes.keys():
1125 if (self.display.has_key(entry) and
1126 self.display[entry] and
1127 not self.boxes[entry].props.visible):
1128 break
1129 else:
1130 self.toggles["all"].set_label(_("hide all"))
1131 #end def __toggle_box
1133 def __calendar_dialog(self, widget, entry):
1134 d = gtk.Window(gtk.WINDOW_TOPLEVEL)
1135 d.set_title(_('Pick a date'))
1137 vb = gtk.VBox()
1138 cal = gtk.Calendar()
1139 vb.pack_start(cal, expand=False, padding=0)
1141 # if the date field is already set, default to the currently selected date, else default to 'today'
1142 text = entry.get_text()
1143 if (text):
1144 date = strptime(text, "%Y-%m-%d")
1145 else:
1146 # if the day is configured to not start at midnight, check whether it's still yesterday,
1147 # and if so, select yesterday in the calendar instead of today
1148 date = localtime()
1149 if (date.tm_hour < self.day_start):
1150 date = localtime(mktime(date) - 24*3600)
1151 cal.select_month(date.tm_mon - 1, date.tm_year) # months are 0 through 11
1152 cal.select_day(date.tm_mday)
1154 btn = gtk.Button(_('Done'))
1155 btn.connect('clicked', self.__get_date, cal, entry, d)
1157 vb.pack_start(btn, expand=False, padding=4)
1159 d.add(vb)
1160 d.set_position(gtk.WIN_POS_MOUSE)
1161 d.show_all()
1162 #end def __calendar_dialog
1164 def __clear_start_date(self, w):
1165 self.start_date.set_text('')
1166 #end def __clear_start_date
1168 def __clear_end_date(self, w):
1169 self.end_date.set_text('')
1170 #end def __clear_end_date
1172 def __get_dates(self):
1173 # self.day_start gives user's start of day in hours
1174 offset = int(self.day_start * 3600) # calc day_start in seconds
1176 t1 = self.start_date.get_text()
1177 t2 = self.end_date.get_text()
1179 if t1 == '':
1180 t1 = '1970-01-02'
1181 if t2 == '':
1182 t2 = '2020-12-12'
1184 s1 = strptime(t1, "%Y-%m-%d") # make time_struct
1185 s2 = strptime(t2, "%Y-%m-%d")
1186 e1 = mktime(s1) + offset # s1 is localtime, but returned time since epoch is UTC, then add the
1187 e2 = mktime(s2) + offset # s2 is localtime, but returned time since epoch is UTC
1188 e2 = e2 + 24 * 3600 - 1 # date test is inclusive, so add 23h 59m 59s to e2
1190 adj_t1 = strftime("%Y-%m-%d %H:%M:%S", gmtime(e1)) # make adjusted string including time
1191 adj_t2 = strftime("%Y-%m-%d %H:%M:%S", gmtime(e2))
1192 log.info("t1="+t1+" adj_t1="+adj_t1+'.')
1194 return (adj_t1, adj_t2)
1195 #end def __get_dates
1197 def __get_date(self, widget, calendar, entry, win):
1198 # year and day are correct, month is 0..11
1199 (year, month, day) = calendar.get_date()
1200 month += 1
1201 ds = '%04d-%02d-%02d' % (year, month, day)
1202 entry.set_text(ds)
1203 win.destroy()
1205 # if the opposite date is set, and now the start date is later
1206 # than the end date, modify the one we didn't just set to be
1207 # the same as the one we did just set
1208 if (entry == self.start_date):
1209 end = self.end_date.get_text()
1210 if (end and ds > end):
1211 self.end_date.set_text(ds)
1212 else:
1213 start = self.start_date.get_text()
1214 if (start and ds < start):
1215 self.start_date.set_text(ds)
1217 def __seats_changed(self, widget, which):
1218 seats_from = self.sbSeats['from'].get_value_as_int()
1219 seats_to = self.sbSeats['to'].get_value_as_int()
1220 if (seats_from > seats_to):
1221 if (which == 'from'):
1222 self.sbSeats['to'].set_value(seats_from)
1223 else:
1224 self.sbSeats['from'].set_value(seats_to)
1226 def main(argv=None):
1227 """main can also be called in the python interpreter, by supplying the command line as the argument."""
1228 if argv is None:
1229 argv = sys.argv[1:]
1231 def destroy(*args): # call back for terminating the main eventloop
1232 gtk.main_quit()
1234 parser = OptionParser()
1235 (options, argv) = parser.parse_args(args = argv)
1237 config = Configuration.Config()
1238 db = None
1240 db = Database.Database()
1241 db.do_connect(config)
1243 qdict = SQL.SQL(db.get_backend_name())
1245 i = Filters(db, config, qdict)
1246 main_window = gtk.Window()
1247 main_window.connect('destroy', destroy)
1248 main_window.add(i.get_vbox())
1249 main_window.show()
1250 gtk.main()
1252 if __name__ == '__main__':
1253 sys.exit(main())