improve sorting but still not quite working right

This commit is contained in:
sqlcoder 2009-10-26 00:33:33 +00:00
parent 0b049a128b
commit 69b3c5a339

View File

@ -15,6 +15,7 @@
#In the "official" distribution you can find the license in
#agpl-3.0.txt in the docs folder of the package.
import traceback
import threading
import pygtk
pygtk.require('2.0')
@ -29,7 +30,11 @@ import Database
import fpdb_db
import Filters
colalias,colshow,colheading,colxalign,colformat,coltype = 0,1,2,3,4,5
ranks = {'x':0, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13, 'A':14}
class GuiPlayerStats (threading.Thread):
def __init__(self, config, querylist, mainwin, debug=True):
self.debug = debug
self.conf = config
@ -252,22 +257,56 @@ class GuiPlayerStats (threading.Thread):
return
def sortnums(self, model, iter1, iter2, n):
try:
ret = 0
a = self.liststore.get_value(iter1, n)
b = self.liststore.get_value(iter2, n)
if 'f' in self.cols_to_show[n][4]:
try: a = float(a)
except: a = 0.0
try: b = float(b)
except: b = 0.0
if n == 0:
a1,a2,a3 = ranks[a[0]], ranks[a[1]], (a+'o')[2]
b1,b2,b3 = ranks[b[0]], ranks[b[1]], (b+'o')[2]
if a1 > b1 or ( a1 == b1 and (a2 > b2 or (a2 == b2 and a3 > b3) ) ):
ret = 1
else:
ret = -1
else:
if a < b:
ret = -1
elif a == b:
ret = 0
else:
ret = 1
#print "n =", n, "iter1[n] =", self.liststore.get_value(iter1,n), "iter2[n] =", self.liststore.get_value(iter2,n), "ret =", ret
except:
err = traceback.extract_tb(sys.exc_info()[2])
print "***sortnums error: " + str(sys.exc_info()[1])
print "\n".join( [e[0]+':'+str(e[1])+" "+e[2] for e in err] )
return(ret)
def sortcols(self, col, n):
#This doesn't actually work yet
if n == 0:
# Card values can stay the same for the moment.
return
if col.get_sort_order() == gtk.SORT_ASCENDING:
col.set_sort_order(gtk.SORT_DESCENDING)
else:
col.set_sort_order(gtk.SORT_ASCENDING)
self.liststore.set_sort_column_id(n, col.get_sort_order())
try:
#This doesn't actually work yet - clicking heading in top section sorts bottom section :-(
if col.get_sort_order() == gtk.SORT_ASCENDING:
col.set_sort_order(gtk.SORT_DESCENDING)
else:
col.set_sort_order(gtk.SORT_ASCENDING)
self.liststore.set_sort_column_id(n, col.get_sort_order())
self.liststore.set_sort_func(n, self.sortnums, n)
except:
err = traceback.extract_tb(sys.exc_info()[2])
print "***sortcols error: " + str(sys.exc_info()[1])
print "\n".join( [e[0]+':'+str(e[1])+" "+e[2] for e in err] )
def addTable(self, vbox, query, flags, playerids, sitenos, limits, type, seats, groups, dates):
counter = 0
row = 0
sqlrow = 0
colalias,colshow,colheading,colxalign,colformat,coltype = 0,1,2,3,4,5
if not flags: holecards = False
else: holecards = flags[0]
@ -278,10 +317,10 @@ class GuiPlayerStats (threading.Thread):
colnames = [desc[0].lower() for desc in self.cursor.description]
# pre-fetch some constant values:
cols_to_show = [x for x in self.columns if x[colshow]]
self.cols_to_show = [x for x in self.columns if x[colshow]]
hgametypeid_idx = colnames.index('hgametypeid')
self.liststore = gtk.ListStore(*([str] * len(cols_to_show)))
self.liststore = gtk.ListStore(*([str] * len(self.cols_to_show)))
view = gtk.TreeView(model=self.liststore)
view.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
#vbox.pack_start(view, expand=False, padding=3)
@ -292,10 +331,9 @@ class GuiPlayerStats (threading.Thread):
numcell = gtk.CellRendererText()
numcell.set_property('xalign', 1.0)
listcols = []
idx = 0
# Create header row eg column: ("game", True, "Game", 0.0, "%s")
for col, column in enumerate(cols_to_show):
for col, column in enumerate(self.cols_to_show):
if column[colalias] == 'game' and holecards:
s = [x for x in self.columns if x[colalias] == 'hand'][0][colheading]
else:
@ -304,7 +342,7 @@ class GuiPlayerStats (threading.Thread):
view.append_column(listcols[col])
#listcols[col].set_clickable(True)
#listcols[col].set_sort_indicator(True)
#listcols[col].connect("clicked", self.sortcols, idx)
#listcols[col].connect("clicked", self.sortcols, col)
if column[colformat] == '%s':
if column[colxalign] == 0.0:
listcols[col].pack_start(textcell, expand=True)
@ -322,13 +360,12 @@ class GuiPlayerStats (threading.Thread):
listcols[col].set_cell_data_func(numcell, self.ledger_style_render_func)
else:
listcols[col].set_cell_data_func(numcell, self.reset_style_render_func)
idx = idx+1
rows = len(result) # +1 for title row
while sqlrow < rows:
treerow = []
for col,column in enumerate(cols_to_show):
for col,column in enumerate(self.cols_to_show):
if column[colalias] in colnames:
value = result[sqlrow][colnames.index(column[colalias])]
if column[colalias] == 'plposition':