add dropdown to player name in filter

This commit is contained in:
sqlcoder 2009-10-05 22:12:35 +01:00
parent 7149de3aa2
commit 8851b141a2
3 changed files with 28 additions and 1 deletions

View File

@ -537,6 +537,16 @@ class Database:
else:
return None
def get_player_names(self, config, site_id=None, like_player_name="%"):
"""Fetch player names from players. Use site_id and like_player_name if provided"""
if site_id == None:
site_id = -1
c = self.get_cursor()
c.execute(self.sql.query['get_player_names'], (like_player_name, site_id, site_id))
rows = c.fetchall()
return rows
#returns the SQL ids of the names given in an array
# TODO: if someone gets industrious, they should make the parts that use the output of this function deal with a dict
# { playername: id } instead of depending on it's relation to the positions list

View File

@ -23,6 +23,7 @@ import os
import sys
from optparse import OptionParser
from time import *
import gobject
#import pokereval
import Configuration
@ -228,7 +229,16 @@ class Filters(threading.Thread):
pname.set_width_chars(20)
hbox.pack_start(pname, False, True, 0)
pname.connect("changed", self.__set_hero_name, site)
#TODO: Look at GtkCompletion - to fill out usernames
# Added EntryCompletion but maybe comboBoxEntry is more flexible? (e.g. multiple choices)
completion = gtk.EntryCompletion()
pname.set_completion(completion)
liststore = gtk.ListStore(gobject.TYPE_STRING)
completion.set_model(liststore)
completion.set_text_column(0)
names = self.db.get_player_names(self.conf) # (config=self.conf, site_id=None, like_player_name="%")
for n in names:
liststore.append(n)
self.__set_hero_name(pname, site)

View File

@ -1235,6 +1235,13 @@ class Sql:
and Players.siteId = Sites.id
"""
self.query['get_player_names'] = """
select p.name
from Players p
where lower(p.name) like lower(%s)
and (p.siteId = %s or %s = -1)
"""
self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
self.query['get_stats_from_hand'] = """