2011-02-26 20:26:46 +01:00
|
|
|
#!/usr/bin/env python
|
2010-07-09 04:47:33 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#Copyright 2010 Steffen Schaumburg
|
|
|
|
#This program is free software: you can redistribute it and/or modify
|
|
|
|
#it under the terms of the GNU Affero General Public License as published by
|
|
|
|
#the Free Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
#This program is distributed in the hope that it will be useful,
|
|
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
#GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
#You should have received a copy of the GNU Affero General Public License
|
|
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#In the "official" distribution you can find the license in agpl-3.0.txt.
|
|
|
|
|
2010-09-23 08:31:16 +02:00
|
|
|
import L10n
|
|
|
|
_ = L10n.get_translation()
|
|
|
|
|
2010-07-10 02:09:58 +02:00
|
|
|
import threading
|
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
|
|
|
import gobject
|
2010-07-09 04:47:33 +02:00
|
|
|
#import os
|
|
|
|
#import sys
|
|
|
|
#from optparse import OptionParser
|
2010-07-10 05:19:50 +02:00
|
|
|
from time import gmtime, mktime, strftime, strptime
|
2010-07-09 04:47:33 +02:00
|
|
|
#import pokereval
|
|
|
|
|
2010-07-10 02:09:58 +02:00
|
|
|
import logging #logging has been set up in fpdb.py or HUD_main.py, use their settings:
|
|
|
|
log = logging.getLogger("filter")
|
2010-07-09 04:47:33 +02:00
|
|
|
|
|
|
|
#import Configuration
|
|
|
|
#import Database
|
|
|
|
#import SQL
|
2010-07-10 02:09:58 +02:00
|
|
|
import Charset
|
2010-07-11 05:58:00 +02:00
|
|
|
import Filters
|
2010-07-09 04:47:33 +02:00
|
|
|
|
2010-07-11 05:58:00 +02:00
|
|
|
class TourneyFilters(Filters.Filters):
|
2010-07-10 02:09:58 +02:00
|
|
|
def __init__(self, db, config, qdict, display = {}, debug=True):
|
|
|
|
self.debug = debug
|
|
|
|
self.db = db
|
|
|
|
self.cursor = db.cursor
|
|
|
|
self.sql = db.sql
|
|
|
|
self.conf = db.config
|
|
|
|
self.display = display
|
|
|
|
|
2010-08-15 21:09:18 +02:00
|
|
|
self.filterText = {'playerstitle':_('Hero:'), 'sitestitle':_('Sites:'), 'seatstitle':_('Number of Players:'),
|
|
|
|
'seatsbetween':_('Between:'), 'seatsand':_('And:'), 'datestitle':_('Date:'),
|
|
|
|
'tourneyTypesTitle':_('Tourney Type')}
|
2010-07-10 02:09:58 +02:00
|
|
|
|
2010-07-10 05:19:50 +02:00
|
|
|
gen = self.conf.get_general_params()
|
|
|
|
self.day_start = 0
|
|
|
|
if 'day_start' in gen:
|
|
|
|
self.day_start = float(gen['day_start'])
|
|
|
|
|
2011-02-18 06:23:03 +01:00
|
|
|
self.sw = gtk.ScrolledWindow()
|
|
|
|
self.sw.set_border_width(0)
|
|
|
|
self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
|
|
|
self.sw.set_size_request(370, 300)
|
|
|
|
|
2010-07-10 02:09:58 +02:00
|
|
|
# Outer Packing box
|
|
|
|
self.mainVBox = gtk.VBox(False, 0)
|
2011-02-18 06:23:03 +01:00
|
|
|
self.sw.add_with_viewport(self.mainVBox)
|
|
|
|
self.sw.show()
|
2010-07-10 02:09:58 +02:00
|
|
|
|
|
|
|
self.label = {}
|
|
|
|
self.callback = {}
|
|
|
|
|
|
|
|
self.make_filter()
|
|
|
|
#end def __init__
|
|
|
|
|
2010-07-27 18:41:51 +02:00
|
|
|
def __refresh(self, widget, entry): #identical with Filters
|
2010-07-10 02:09:58 +02:00
|
|
|
for w in self.mainVBox.get_children():
|
|
|
|
w.destroy()
|
|
|
|
self.make_filter()
|
|
|
|
#end def __refresh
|
|
|
|
|
2010-07-10 05:19:50 +02:00
|
|
|
def __set_num_tourneys(self, w, val):
|
|
|
|
try:
|
|
|
|
self.numTourneys = int(w.get_text())
|
|
|
|
except:
|
|
|
|
self.numTourneys = 0
|
2010-08-16 01:41:25 +02:00
|
|
|
print _("setting numTourneys:"), self.numTourneys
|
2010-07-10 05:19:50 +02:00
|
|
|
#end def __set_num_tourneys
|
2010-07-10 02:09:58 +02:00
|
|
|
|
2010-07-27 18:54:40 +02:00
|
|
|
def __toggle_box(self, widget, entry): #identical with Filters
|
2010-07-10 02:09:58 +02:00
|
|
|
if self.boxes[entry].props.visible:
|
|
|
|
self.boxes[entry].hide()
|
|
|
|
widget.set_label("show")
|
|
|
|
else:
|
|
|
|
self.boxes[entry].show()
|
|
|
|
widget.set_label("hide")
|
|
|
|
#end def __toggle_box
|
|
|
|
|
|
|
|
def make_filter(self):
|
2010-07-10 05:19:50 +02:00
|
|
|
self.tourneyTypes = {}
|
|
|
|
#self.tourneys = {}
|
|
|
|
self.sites = {}
|
|
|
|
self.seats = {}
|
2010-07-10 02:09:58 +02:00
|
|
|
self.siteid = {}
|
|
|
|
self.heroes = {}
|
2010-07-10 05:19:50 +02:00
|
|
|
self.boxes = {}
|
2010-07-10 02:09:58 +02:00
|
|
|
|
|
|
|
for site in self.conf.get_supported_sites():
|
|
|
|
#Get db site id for filtering later
|
|
|
|
self.cursor.execute(self.sql.query['getSiteId'], (site,))
|
|
|
|
result = self.db.cursor.fetchall()
|
|
|
|
if len(result) == 1:
|
|
|
|
self.siteid[site] = result[0][0]
|
|
|
|
else:
|
2010-08-15 21:09:18 +02:00
|
|
|
print _("Either 0 or more than one site matched (%s) - EEK") % site
|
2010-07-10 02:09:58 +02:00
|
|
|
|
|
|
|
# For use in date ranges.
|
|
|
|
self.start_date = gtk.Entry(max=12)
|
|
|
|
self.end_date = gtk.Entry(max=12)
|
|
|
|
self.start_date.set_property('editable', False)
|
|
|
|
self.end_date.set_property('editable', False)
|
|
|
|
|
|
|
|
# For use in groups etc
|
|
|
|
#self.sbGroups = {}
|
|
|
|
self.numTourneys = 0
|
|
|
|
|
|
|
|
playerFrame = gtk.Frame()
|
|
|
|
playerFrame.set_label_align(0.0, 0.0)
|
|
|
|
vbox = gtk.VBox(False, 0)
|
|
|
|
|
|
|
|
self.fillPlayerFrame(vbox, self.display)
|
|
|
|
playerFrame.add(vbox)
|
|
|
|
|
|
|
|
sitesFrame = gtk.Frame()
|
|
|
|
sitesFrame.set_label_align(0.0, 0.0)
|
|
|
|
vbox = gtk.VBox(False, 0)
|
|
|
|
|
|
|
|
self.fillSitesFrame(vbox)
|
|
|
|
sitesFrame.add(vbox)
|
|
|
|
|
2010-07-10 05:19:50 +02:00
|
|
|
# Tourney types
|
|
|
|
tourneyTypesFrame = gtk.Frame()
|
|
|
|
tourneyTypesFrame.set_label_align(0.0, 0.0)
|
|
|
|
tourneyTypesFrame.show()
|
|
|
|
vbox = gtk.VBox(False, 0)
|
|
|
|
|
|
|
|
self.fillTourneyTypesFrame(vbox)
|
|
|
|
tourneyTypesFrame.add(vbox)
|
|
|
|
|
2010-07-10 02:09:58 +02:00
|
|
|
# Seats
|
|
|
|
seatsFrame = gtk.Frame()
|
|
|
|
seatsFrame.show()
|
|
|
|
vbox = gtk.VBox(False, 0)
|
|
|
|
self.sbSeats = {}
|
|
|
|
|
|
|
|
self.fillSeatsFrame(vbox, self.display)
|
|
|
|
seatsFrame.add(vbox)
|
|
|
|
|
|
|
|
# Date
|
|
|
|
dateFrame = gtk.Frame()
|
|
|
|
dateFrame.set_label_align(0.0, 0.0)
|
|
|
|
dateFrame.show()
|
|
|
|
vbox = gtk.VBox(False, 0)
|
|
|
|
|
|
|
|
self.fillDateFrame(vbox)
|
|
|
|
dateFrame.add(vbox)
|
|
|
|
|
|
|
|
# Buttons
|
|
|
|
#self.Button1=gtk.Button("Unnamed 1")
|
|
|
|
#self.Button1.set_sensitive(False)
|
|
|
|
|
|
|
|
self.Button2=gtk.Button("Unnamed 2")
|
|
|
|
self.Button2.set_sensitive(False)
|
|
|
|
|
|
|
|
self.mainVBox.add(playerFrame)
|
|
|
|
self.mainVBox.add(sitesFrame)
|
|
|
|
self.mainVBox.add(seatsFrame)
|
|
|
|
self.mainVBox.add(dateFrame)
|
|
|
|
#self.mainVBox.add(self.Button1)
|
|
|
|
self.mainVBox.add(self.Button2)
|
|
|
|
|
|
|
|
self.mainVBox.show_all()
|
|
|
|
|
|
|
|
# Should do this cleaner
|
|
|
|
if "Heroes" not in self.display or self.display["Heroes"] == False:
|
|
|
|
playerFrame.hide()
|
|
|
|
if "Sites" not in self.display or self.display["Sites"] == False:
|
|
|
|
sitesFrame.hide()
|
|
|
|
if "Seats" not in self.display or self.display["Seats"] == False:
|
|
|
|
seatsFrame.hide()
|
|
|
|
if "Dates" not in self.display or self.display["Dates"] == False:
|
|
|
|
dateFrame.hide()
|
|
|
|
#if "Button1" not in self.display or self.display["Button1"] == False:
|
|
|
|
# self.Button1.hide()
|
|
|
|
if "Button2" not in self.display or self.display["Button2"] == False:
|
|
|
|
self.Button2.hide()
|
|
|
|
|
|
|
|
#if 'button1' in self.label and self.label['button1']:
|
|
|
|
# self.Button1.set_label( self.label['button1'] )
|
|
|
|
if 'button2' in self.label and self.label['button2']:
|
|
|
|
self.Button2.set_label( self.label['button2'] )
|
|
|
|
#if 'button1' in self.callback and self.callback['button1']:
|
|
|
|
# self.Button1.connect("clicked", self.callback['button1'], "clicked")
|
|
|
|
# self.Button1.set_sensitive(True)
|
|
|
|
if 'button2' in self.callback and self.callback['button2']:
|
|
|
|
self.Button2.connect("clicked", self.callback['button2'], "clicked")
|
|
|
|
self.Button2.set_sensitive(True)
|
|
|
|
|
|
|
|
# make sure any locks on db are released:
|
|
|
|
self.db.rollback()
|
|
|
|
#end def make_filter
|
|
|
|
#end class TourneyFilters
|