1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

* redesigned statistics dialogs: all statistics in single dialog (Tile)

git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@145 39dd0a4e-7c14-0410-91b3-c4f2d318f732
This commit is contained in:
skomoroh 2007-03-03 22:17:47 +00:00
parent 2b6b19dd49
commit 855cf7384c
8 changed files with 295 additions and 187 deletions

View file

@ -584,6 +584,7 @@ class PysolMenubarActions:
elif mode == 101: elif mode == 101:
header = p1 + _("Statistics for ") + n header = p1 + _("Statistics for ") + n
d = SingleGame_StatsDialog(self.top, header, self.app, player, gameid=self.game.id) d = SingleGame_StatsDialog(self.top, header, self.app, player, gameid=self.game.id)
gameid = d.selected_game
elif mode == 102: elif mode == 102:
header = p1 + _("Statistics") + p2 header = p1 + _("Statistics") + p2
d = AllGames_StatsDialog(self.top, header, self.app, player) d = AllGames_StatsDialog(self.top, header, self.app, player)

View file

@ -215,6 +215,7 @@ class Game:
self.busy = old_busy self.busy = old_busy
##print timer ##print timer
self.showHelp() # just in case self.showHelp() # just in case
##self.reallocateStacks()
def _checkGame(self): def _checkGame(self):
@ -631,6 +632,23 @@ class Game:
self.endGame(restart=1) self.endGame(restart=1)
self.newGame(restart=1, random=self.random) self.newGame(restart=1, random=self.random)
def reallocateStacks(self):
w0, h0 = self.width, self.height
iw = int(self.canvas.cget('width'))
ih = int(self.canvas.cget('height'))
vw = self.canvas.winfo_width()
vh = self.canvas.winfo_height()
if vw <= iw or vh <= ih:
return
xf = float(vw)/iw
yf = float(vh)/ih
for stack in self.allstacks:
x0, y0 = stack.init_coord
x, y = int(x0*xf), int(y0*yf)
if x == stack.x and y == stack.y:
continue
stack.moveTo(x, y)
def createRandom(self, random): def createRandom(self, random):
if random is None: if random is None:
if isinstance(self.random, PysolRandom): if isinstance(self.random, PysolRandom):

View file

@ -112,6 +112,7 @@ class Game_StatsDialog:
def __init__(self, parent, header, app, player, gameid): def __init__(self, parent, header, app, player, gameid):
# #
self.app = app self.app = app
self.selected_game = None
self.player = player self.player = player
self.gameid = gameid self.gameid = gameid
self.games = {} self.games = {}

View file

@ -241,6 +241,7 @@ class Stack:
mapkey = (x, y) mapkey = (x, y)
###assert not game.stackmap.has_key(mapkey) ## can happen in PyJonngg ###assert not game.stackmap.has_key(mapkey) ## can happen in PyJonngg
game.stackmap[mapkey] = id game.stackmap[mapkey] = id
self.init_coord = (x, y)
# #
# setup our pseudo MVC scheme # setup our pseudo MVC scheme
@ -520,6 +521,26 @@ class Stack:
x, y = self.getPositionFor(card) x, y = self.getPositionFor(card)
card.moveTo(x, y) card.moveTo(x, y)
# move stack to new coords
def moveTo(self, x, y):
dx, dy = x-self.x, y-self.y
self.x, self.y = x, y
for c in self.cards:
x, y = self.getPositionFor(c)
c.moveTo(x, y)
if self.images.bottom:
self.images.bottom.move(dx, dy)
if self.images.redeal:
self.images.redeal.move(dx, dy)
if self.texts.ncards:
self.texts.ncards.move(dx, dy)
if self.texts.rounds:
self.texts.rounds.move(dx, dy)
if self.texts.redeal:
self.texts.redeal.move(dx, dy)
if self.texts.misc:
self.texts.misc.move(dx, dy)
# find card # find card
def _findCard(self, event): def _findCard(self, event):
model, view = self, self model, view = self, self

View file

@ -222,10 +222,11 @@ class Notebook(Widget):
""" """
return self.tk.call(self._w, "index") return self.tk.call(self._w, "index")
def select(self, index): def select(self, index=None):
"""Selects the specified tab; the associated child pane will """Selects the specified tab. The associated child pane will be
be displayed, and the previously-selected pane (if different) displayed, and the previously-selected pane (if different) is
is unmapped. unmapped. If tabid is omitted, returns the widget name of the
currently selected pane.
""" """
return self.tk.call(self._w, "select", index) return self.tk.call(self._w, "select", index)

View file

@ -413,18 +413,10 @@ class PysolMenubar(PysolMenubarActions):
menu.add_command(label=n_("S&tatus..."), command=self.mStatus, accelerator=m+"Y") menu.add_command(label=n_("S&tatus..."), command=self.mStatus, accelerator=m+"Y")
menu.add_checkbutton(label=n_("&Comments..."), variable=self.tkopt.comment, command=self.mEditGameComment) menu.add_checkbutton(label=n_("&Comments..."), variable=self.tkopt.comment, command=self.mEditGameComment)
menu.add_separator() menu.add_separator()
submenu = MfxMenu(menu, label=n_("&Statistics")) menu.add_command(label=n_("&Statistics..."), command=lambda self=self: self.mPlayerStats(mode=102))
submenu.add_command(label=n_("Current game..."), command=lambda self=self: self.mPlayerStats(mode=101)) menu.add_command(label=n_("Log..."), command=lambda self=self: self.mPlayerStats(mode=103))
submenu.add_command(label=n_("All games..."), command=lambda self=self: self.mPlayerStats(mode=102)) menu.add_separator()
submenu.add_separator() menu.add_command(label=n_("D&emo statistics"), command=lambda self=self: self.mPlayerStats(mode=1102))
submenu.add_command(label=n_("Session log..."), command=lambda self=self: self.mPlayerStats(mode=104))
submenu.add_command(label=n_("Full log..."), command=lambda self=self: self.mPlayerStats(mode=103))
submenu.add_separator()
submenu.add_command(label=TOP_TITLE+"...", command=self.mTop10, accelerator=m+"T")
submenu.add_command(label=n_("Progression..."), command=lambda self=self: self.mPlayerStats(mode=107))
submenu = MfxMenu(menu, label=n_("D&emo statistics"))
submenu.add_command(label=n_("Current game..."), command=lambda self=self: self.mPlayerStats(mode=1101))
submenu.add_command(label=n_("All games..."), command=lambda self=self: self.mPlayerStats(mode=1102))
menu = MfxMenu(self.__menubar, label=n_("&Assist")) menu = MfxMenu(self.__menubar, label=n_("&Assist"))
menu.add_command(label=n_("&Hint"), command=self.mHint, accelerator="H") menu.add_command(label=n_("&Hint"), command=self.mHint, accelerator="H")

View file

@ -63,39 +63,132 @@ from tkwidget import MfxScrolledCanvas
gettext = _ gettext = _
# FIXME - this file a quick hack and needs a rewrite # /***********************************************************************
# //
# ************************************************************************/
class StatsDialog(MfxDialog):
SELECTED_TAB = 0
def __init__(self, parent, title, app, player, gameid, **kw):
kw = self.initKw(kw)
MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
self.font = app.getFont('default')
self.tkfont = tkFont.Font(parent, self.font)
self.font_metrics = self.tkfont.metrics()
self.selected_game = None
top_frame, bottom_frame = self.createFrames(kw)
notebook = Tkinter.Notebook(top_frame)
notebook.pack(expand=True, fill='both', padx=10, pady=10)
self.notebook_tabs = []
## frame = Tkinter.Frame(notebook)
## notebook.add(frame, text=_('Current game'))
## single_frame = SingleGameFrame(self, frame, app, player, gameid)
## single_frame.pack(side='left', expand=True, fill='both')
## top_frame = TopFrame(self, frame, app, player, gameid)
## top_frame.pack(side='right', expand=True, fill='both')
single_frame = SingleGameFrame(self, notebook, app, player, gameid)
notebook.add(single_frame, text=_('Current game'))
self.notebook_tabs.append(single_frame._w)
all_frame = AllGamesFrame(self, notebook, app, player)
notebook.add(all_frame, text=_('All games'))
self.all_games_frame = all_frame
self.notebook_tabs.append(all_frame._w)
top_frame = TopFrame(self, notebook, app, player, gameid)
notebook.add(top_frame, text=TOP_TITLE)
self.notebook_tabs.append(top_frame._w)
if player is not None:
progr_frame = ProgressionFrame(self, notebook, app, player, gameid)
notebook.add(progr_frame, text=_('Progression'))
self.notebook_tabs.append(progr_frame._w)
if StatsDialog.SELECTED_TAB < len(self.notebook_tabs):
notebook.select(StatsDialog.SELECTED_TAB)
bind(notebook, '<<NotebookTabChanged>>', self.tabChanged)
self.notebook = notebook
focus = self.createButtons(bottom_frame, kw)
self.tabChanged() # configure buttons state
self.mainloop(focus, kw.timeout)
def initKw(self, kw):
kw = KwStruct(kw,
strings=((_("&Play this game"), 401),
"sep",_("&OK"),
(_("&Reset..."), 500)), default=0,
)
return MfxDialog.initKw(self, kw)
def tabChanged(self, *args):
w = self.notebook.select()
run_button = self.buttons[0]
indx = self.notebook_tabs.index(w)
if indx == 1: # "All games"
g = self.all_games_frame.getSelectedGame()
if g is None:
run_button.config(state='disabled')
else:
run_button.config(state='normal')
else:
run_button.config(state='disabled')
reset_button = self.buttons[2]
if indx in (0, 1): # "Current game" or "All games"
reset_button.config(state='normal')
else:
reset_button.config(state='disabled')
def mDone(self, button):
self.selected_game = self.all_games_frame.getSelectedGame()
w = self.notebook.select()
indx = self.notebook_tabs.index(w)
StatsDialog.SELECTED_TAB = indx
if button == 500: # "Reset..."
assert indx in (0, 1)
if indx == 0: # "Current game"
button = 302
else: # "All games"
button = 301
MfxDialog.mDone(self, button)
SingleGame_StatsDialog = AllGames_StatsDialog = Top_StatsDialog = ProgressionDialog = StatsDialog
# /*********************************************************************** # /***********************************************************************
# // # //
# ************************************************************************/ # ************************************************************************/
class SingleGame_StatsDialog(MfxDialog): class SingleGameFrame(Tkinter.Frame):
def __init__(self, parent, title, app, player, gameid, **kw): def __init__(self, dialog, parent, app, player, gameid, **kw):
Tkinter.Frame.__init__(self, parent)
left_label = Tkinter.Label(self, image=app.gimages.logos[5])
left_label.pack(side='left', expand=True, fill='both')
self.right_frame = Tkinter.Frame(self)
self.right_frame.pack(side='right', expand=True)
self.dialog = dialog
self.app = app self.app = app
kw = self.initKw(kw)
MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.top_frame = top_frame
self.createBitmaps(top_frame, kw)
#
self.player = player or _("Demo games") self.player = player or _("Demo games")
self.top.wm_minsize(200, 200)
self.button = kw.default
# #
createChart = self.createPieChart
#
self.font = self.app.getFont("default")
self.tk_font = tkFont.Font(self.top, self.font)
self.font_metrics = self.tk_font.metrics()
self._calc_tabs() self._calc_tabs()
# #
won, lost = app.stats.getStats(player, gameid) won, lost = app.stats.getStats(player, gameid)
createChart(app, won, lost, _("Total")) self.createPieChart(app, won, lost, _("Total"))
won, lost = app.stats.getSessionStats(player, gameid) won, lost = app.stats.getSessionStats(player, gameid)
createChart(app, won, lost, _("Current session")) self.createPieChart(app, won, lost, _("Current session"))
# #
focus = self.createButtons(bottom_frame, kw)
self.mainloop(focus, kw.timeout)
# #
# helpers # helpers
@ -103,7 +196,7 @@ class SingleGame_StatsDialog(MfxDialog):
def _calc_tabs(self): def _calc_tabs(self):
# #
font = self.tk_font font = self.dialog.tkfont
t0 = 160 t0 = 160
t = '' t = ''
for i in (_("Won:"), for i in (_("Won:"),
@ -122,7 +215,7 @@ class SingleGame_StatsDialog(MfxDialog):
t3 = 45 t3 = 45
tx = (t0, t0+t1+t2, t0+t1+t2+t3, t0+t1+t2+t3+20) tx = (t0, t0+t1+t2, t0+t1+t2+t3, t0+t1+t2+t3+20)
# #
ls = self.font_metrics['linespace'] ls = self.dialog.font_metrics['linespace']
ls += 5 ls += 5
#ls = max(ls, 20) #ls = max(ls, 20)
ty = (5, 5+ls, 5+2*ls+15, max(85, 5+3*ls+15)) ty = (5, 5+ls, 5+2*ls+15, max(85, 5+3*ls+15))
@ -138,9 +231,9 @@ class SingleGame_StatsDialog(MfxDialog):
return pwon, plost return pwon, plost
def _createChartInit(self, text): def _createChartInit(self, text):
frame = Tkinter.LabelFrame(self.top_frame, text=text) frame = Tkinter.LabelFrame(self.right_frame, text=text)
frame.pack(side='top', fill='both', expand=False, padx=20, pady=10) frame.pack(side='top', fill='both', expand=False, padx=20, pady=10)
style = Tkinter.Style(self.top_frame) style = Tkinter.Style(self.right_frame)
fg = style.lookup('.', 'foreground') or None # use default if fg == '' fg = style.lookup('.', 'foreground') or None # use default if fg == ''
bg = style.lookup('.', 'background') or None bg = style.lookup('.', 'background') or None
self.fg = fg self.fg = fg
@ -152,11 +245,11 @@ class SingleGame_StatsDialog(MfxDialog):
self.canvas = c self.canvas = c
def _createChartTexts(self, tx, ty, won, lost): def _createChartTexts(self, tx, ty, won, lost):
c, tfont, fg = self.canvas, self.font, self.fg c, tfont, fg = self.canvas, self.dialog.font, self.fg
pwon, plost = self._getPwon(won, lost) pwon, plost = self._getPwon(won, lost)
# #
x = tx[0] x = tx[0]
dy = int(self.font_metrics['ascent']) - 10 dy = int(self.dialog.font_metrics['ascent']) - 10
dy = dy/2 dy = dy/2
c.create_text(x, ty[0]-dy, text=_("Won:"), anchor="nw", font=tfont, fill=fg) c.create_text(x, ty[0]-dy, text=_("Won:"), anchor="nw", font=tfont, fill=fg)
c.create_text(x, ty[1]-dy, text=_("Lost:"), anchor="nw", font=tfont, fill=fg) c.create_text(x, ty[1]-dy, text=_("Lost:"), anchor="nw", font=tfont, fill=fg)
@ -179,7 +272,7 @@ class SingleGame_StatsDialog(MfxDialog):
#c, tfont, fg = self._createChartInit(frame, 300, 100, text) #c, tfont, fg = self._createChartInit(frame, 300, 100, text)
# #
self._createChartInit(text) self._createChartInit(text)
c, tfont, fg = self.canvas, self.font, self.fg c, tfont, fg = self.canvas, self.dialog.font, self.fg
pwon, plost = self._getPwon(won, lost) pwon, plost = self._getPwon(won, lost)
# #
#tx = (160, 250, 280) #tx = (160, 250, 280)
@ -207,21 +300,6 @@ class SingleGame_StatsDialog(MfxDialog):
# #
self._createChartTexts(tx, ty, won, lost) self._createChartTexts(tx, ty, won, lost)
#
#
#
def initKw(self, kw):
kw = KwStruct(kw,
strings=(_("&OK"),
(_("&All games..."), 102),
(TOP_TITLE+"...", 105),
(_("&Reset..."), 302)), default=0,
image=self.app.gimages.logos[5],
padx=10, pady=10,
)
return MfxDialog.initKw(self, kw)
# /*********************************************************************** # /***********************************************************************
# // # //
@ -234,8 +312,7 @@ class TreeFormatter(PysolStatsFormatter):
self.app = app self.app = app
self.tree = tree self.tree = tree
self.parent_window = parent_window self.parent_window = parent_window
self.font = font self.tkfont = font
self.tkfont = tkFont.Font(tree, font)
self.gameid = None self.gameid = None
self.gamenumber = None self.gamenumber = None
self._tabs = None self._tabs = None
@ -249,7 +326,6 @@ class TreeFormatter(PysolStatsFormatter):
tw = 20*self.w tw = 20*self.w
##tw = 160 ##tw = 160
self._tabs = [tw] self._tabs = [tw]
#font = tkFont.Font(self.tree, self.font)
font = self.tkfont font = self.tkfont
for t in arg[1:]: for t in arg[1:]:
tw = font.measure(t)+20 tw = font.measure(t)+20
@ -332,41 +408,26 @@ class TreeFormatter(PysolStatsFormatter):
# // # //
# ************************************************************************/ # ************************************************************************/
class AllGames_StatsDialog(MfxDialog): class AllGamesFrame(Tkinter.Frame):
COLUMNS = ('played', 'won', 'lost', 'time', 'moves', 'percent') COLUMNS = ('played', 'won', 'lost', 'time', 'moves', 'percent')
def __init__(self, parent, title, app, player, **kw): def __init__(self, dialog, parent, app, player, **kw):
lines = 25 Tkinter.Frame.__init__(self, parent)
#if parent and parent.winfo_screenheight() < 600:
# lines = 20
# #
self.font = app.getFont('default') self.dialog = dialog
font = tkFont.Font(parent, self.font)
self.font_metrics = font.metrics()
self.CHAR_H = self.font_metrics['linespace']
self.CHAR_W = font.measure('M')
self.app = app self.app = app
self.CHAR_H = self.dialog.font_metrics['linespace']
self.CHAR_W = self.dialog.tkfont.measure('M')
# #
self.player = player self.player = player
self.title = title
self.sort_by = 'name' self.sort_by = 'name'
self.tree_items = [] self.tree_items = []
self.tree_tabs = None self.tree_tabs = None
self.games = {} # tree_itemid: gameid self.games = {} # tree_itemid: gameid
self.selected_game = None
# #
kwdefault(kw, width=self.CHAR_W*64, height=lines*self.CHAR_H) frame = Tkinter.Frame(self)
kw = self.initKw(kw) frame.pack(fill='both', expand=True, padx=10, pady=10)
MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
#
self.top.wm_minsize(200, 200)
self.button = kw.default
#
frame = Tkinter.Frame(top_frame)
frame.pack(fill='both', expand=True, padx=kw.padx, pady=kw.pady)
sb = Tkinter.Scrollbar(frame) sb = Tkinter.Scrollbar(frame)
sb.pack(side='right', fill='y') sb.pack(side='right', fill='y')
self.tree = Tkinter.Treeview(frame, columns=self.COLUMNS, self.tree = Tkinter.Treeview(frame, columns=self.COLUMNS,
@ -376,40 +437,18 @@ class AllGames_StatsDialog(MfxDialog):
sb.config(command=self.tree.yview) sb.config(command=self.tree.yview)
bind(self.tree, '<<TreeviewSelect>>', self.treeviewSelected) bind(self.tree, '<<TreeviewSelect>>', self.treeviewSelected)
# #
focus = self.createButtons(bottom_frame, kw) self.fillTreeview(player)
self.fillCanvas(player, title)
#run_button = self.buttons[0]
#run_button.config(state='disabled')
self.mainloop(focus, kw.timeout)
def initKw(self, kw): def getSelectedGame(self):
kw = KwStruct(kw,
strings=((_("&Play this game"), 401),
"sep", _("&OK"),
(_("&Save to file"), 202),
(_("&Reset all..."), 301),),
default=0,
resizable=1,
padx=10, pady=10,
#width=900,
)
return MfxDialog.initKw(self, kw)
def mDone(self, button):
sel = self.tree.selection() sel = self.tree.selection()
if sel and len(sel) == 1: if sel and len(sel) == 1:
if sel[0] in self.games: if sel[0] in self.games:
self.selected_game = self.games[sel[0]] return self.games[sel[0]]
MfxDialog.mDone(self, button) return None
def destroy(self):
self.app = None
self.tree.destroy()
MfxDialog.destroy(self)
def treeviewSelected(self, *args): def treeviewSelected(self, *args):
sel = self.tree.selection() sel = self.tree.selection()
run_button = self.buttons[0] run_button = self.dialog.buttons[0]
if sel and len(sel) == 1: if sel and len(sel) == 1:
if sel[0] not in self.games: # "Total" if sel[0] not in self.games: # "Total"
run_button.config(state='disabled') run_button.config(state='disabled')
@ -425,21 +464,21 @@ class AllGames_StatsDialog(MfxDialog):
sort_by = column sort_by = column
if self.sort_by == sort_by: return if self.sort_by == sort_by: return
self.sort_by = sort_by self.sort_by = sort_by
self.fillCanvas(self.player, self.title) self.fillTreeview(self.player)
# #
# #
# #
def fillCanvas(self, player, header): def fillTreeview(self, player):
if self.tree_items: if self.tree_items:
self.tree.delete(tuple(self.tree_items)) self.tree.delete(tuple(self.tree_items))
self.tree_items = [] self.tree_items = []
formatter = TreeFormatter(self.app, self.tree, self, formatter = TreeFormatter(self.app, self.tree, self,
self.font, self.CHAR_W, self.CHAR_H) self.dialog.tkfont, self.CHAR_W, self.CHAR_H)
formatter.writeStats(player, sort_by=self.sort_by) formatter.writeStats(player, sort_by=self.sort_by)
if self.buttons: if self.dialog.buttons:
run_button = self.buttons[0] run_button = self.dialog.buttons[0]
run_button.config(state='disabled') run_button.config(state='disabled')
@ -447,44 +486,97 @@ class AllGames_StatsDialog(MfxDialog):
# // # //
# ************************************************************************/ # ************************************************************************/
class FullLog_StatsDialog(AllGames_StatsDialog): class LogDialog(MfxDialog):
SELECTED_TAB = 0
COLUMNS = ('gamenumber', 'date', 'status') def __init__(self, parent, title, app, player, **kw):
def fillCanvas(self, player, header): self.font = app.getFont('default')
formatter = TreeFormatter(self.app, self.tree, self, self.font, self.tkfont = tkFont.Font(parent, self.font)
self.CHAR_W, self.CHAR_H) self.font_metrics = self.tkfont.metrics()
formatter.writeFullLog(player)
self.CHAR_H = self.font_metrics['linespace']
self.CHAR_W = self.tkfont.measure('M')
kw = self.initKw(kw)
MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
##self.selected_game = None
top_frame, bottom_frame = self.createFrames(kw)
notebook = Tkinter.Notebook(top_frame)
notebook.pack(expand=True, fill='both', padx=10, pady=10)
self.notebook_tabs = []
full_frame = FullLogFrame(self, notebook, app, player)
notebook.add(full_frame, text=_('Full log'))
self.notebook_tabs.append(full_frame._w)
session_frame = SessionLogFrame(self, notebook, app, player)
notebook.add(session_frame, text=_('Session log'))
self.notebook_tabs.append(session_frame._w)
notebook.select(LogDialog.SELECTED_TAB)
## bind(notebook, '<<NotebookTabChanged>>', self.tabChanged)
self.notebook = notebook
focus = self.createButtons(bottom_frame, kw)
##self.tabChanged() # configure buttons state
self.mainloop(focus, kw.timeout)
def initKw(self, kw): def initKw(self, kw):
kw = KwStruct(kw, kw = KwStruct(kw,
strings=(_("&OK"), (_("Session &log..."), 104), strings=(_("&OK"),
(_("&Save to file"), 203)), default=0, (_("&Save to file"), 500)), default=0,
width=76*self.CHAR_W, width=76*self.CHAR_W,
) )
return AllGames_StatsDialog.initKw(self, kw) return MfxDialog.initKw(self, kw)
def mDone(self, button): def mDone(self, button):
##self.selected_game = self.all_games_frame.getSelectedGame()
w = self.notebook.select()
indx = self.notebook_tabs.index(w)
LogDialog.SELECTED_TAB = indx
if button == 500: # "Save to file"
assert indx in (0, 1)
if indx == 0: # "Full log"
button = 203
else: # "Session log"
button = 204
MfxDialog.mDone(self, button) MfxDialog.mDone(self, button)
FullLog_StatsDialog = SessionLog_StatsDialog = LogDialog
##class FullLog_StatsDialog(AllGames_StatsDialog):
class FullLogFrame(AllGamesFrame):
COLUMNS = ('gamenumber', 'date', 'status')
def fillTreeview(self, player):
formatter = TreeFormatter(self.app, self.tree, self,
self.dialog.tkfont,
self.CHAR_W, self.CHAR_H)
formatter.writeFullLog(player)
def treeviewSelected(self, *args): def treeviewSelected(self, *args):
pass pass
def headerClick(self, column): def headerClick(self, column):
pass pass
class SessionLog_StatsDialog(FullLog_StatsDialog): ##class SessionLog_StatsDialog(FullLog_StatsDialog):
def fillCanvas(self, player, header): class SessionLogFrame(FullLogFrame):
formatter = TreeFormatter(self.app, self.tree, self, self.font, def fillTreeview(self, player):
formatter = TreeFormatter(self.app, self.tree, self,
self.dialog.tkfont,
self.CHAR_W, self.CHAR_H) self.CHAR_W, self.CHAR_H)
formatter.writeSessionLog(player) formatter.writeSessionLog(player)
def initKw(self, kw):
kw = KwStruct(kw,
strings=(_("&OK"), (_("&Full log..."), 103),
(_("&Save to file"), 204)), default=0,
)
return FullLog_StatsDialog.initKw(self, kw)
# /*********************************************************************** # /***********************************************************************
# // # //
@ -525,8 +617,7 @@ class Status_StatsDialog(MfxMessageDialog):
"\n" + "\n" +
w1 + w2, w1 + w2,
strings=(_("&OK"), strings=(_("&OK"),
(_("&Statistics..."), 101), (_("&Statistics..."), 101))
(TOP_TITLE+"...", 105), ),
image=game.app.gimages.logos[3], image=game.app.gimages.logos[3],
image_side="left", image_padx=20, image_side="left", image_padx=20,
padx=20, padx=20,
@ -599,17 +690,18 @@ class _TopDialog(MfxDialog):
return MfxDialog.initKw(self, kw) return MfxDialog.initKw(self, kw)
class Top_StatsDialog(MfxDialog): class TopFrame(Tkinter.Frame):
def __init__(self, parent, title, app, player, gameid, **kw): def __init__(self, dialog, parent, app, player, gameid):
self.app = app Tkinter.Frame.__init__(self, parent)
kw = self.initKw(kw)
MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
frame = Tkinter.Frame(top_frame) self.app = app
frame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH, padx=10, pady=10) self.dialog = dialog
frame.columnconfigure(0, weight=1)
left_label = Tkinter.Label(self, image=app.gimages.logos[4])
left_label.pack(side='left', expand=True, fill='both')
frame = Tkinter.Frame(self)
frame.pack(side='right', expand=True, fill='both', padx=10, pady=10)
##frame.columnconfigure(0, weight=1)
if (player in app.stats.games_stats and if (player in app.stats.games_stats and
gameid in app.stats.games_stats[player] and gameid in app.stats.games_stats[player] and
@ -670,52 +762,35 @@ class Top_StatsDialog(MfxDialog):
else: else:
Tkinter.Label(frame, text=_('No TOP for this game')).pack() Tkinter.Label(frame, text=_('No TOP for this game')).pack()
focus = self.createButtons(bottom_frame, kw)
self.mainloop(focus, kw.timeout)
def showTop(self, top): def showTop(self, top):
#print top d = _TopDialog(self.dialog.top, TOP_TITLE, top)
d = _TopDialog(self.top, TOP_TITLE, top)
def initKw(self, kw):
kw = KwStruct(kw,
strings=(_('&OK'),),
default=0,
image=self.app.gimages.logos[4],
separatorwidth=2,
)
return MfxDialog.initKw(self, kw)
# /*********************************************************************** # /***********************************************************************
# // # //
# ************************************************************************/ # ************************************************************************/
class ProgressionDialog(MfxDialog): ##class ProgressionDialog(MfxDialog):
def __init__(self, parent, title, app, player, gameid, **kw):
font_name = app.getFont('default') class ProgressionFrame(Tkinter.Frame):
font = tkFont.Font(parent, font_name)
tkfont = tkFont.Font(parent, font) def __init__(self, dialog, parent, app, player, gameid, **kw):
font_metrics = font.metrics() Tkinter.Frame.__init__(self, parent)
measure = tkfont.measure
self.text_height = font_metrics['linespace'] self.text_height = dialog.font_metrics['linespace']
self.text_width = measure('XX.XX.XX') measure = dialog.tkfont.measure
self.text_width_1 = measure('XX.XX')
self.text_width_2 = measure('XX.XX.XX')
self.items = [] self.items = []
self.formatter = ProgressionFormatter(app, player, gameid) self.formatter = ProgressionFormatter(app, player, gameid)
kw = self.initKw(kw) frame = Tkinter.Frame(self)
MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
frame = Tkinter.Frame(top_frame)
frame.pack(expand=True, fill='both', padx=5, pady=10) frame.pack(expand=True, fill='both', padx=5, pady=10)
frame.columnconfigure(0, weight=1) frame.columnconfigure(0, weight=1)
# constants # constants
self.canvas_width, self.canvas_height = 600, 250 self.canvas_width, self.canvas_height = 540, 220
if parent.winfo_screenwidth() < 800 or \ if parent.winfo_screenwidth() < 800 or \
parent.winfo_screenheight() < 600: parent.winfo_screenheight() < 600:
self.canvas_width, self.canvas_height = 400, 200 self.canvas_width, self.canvas_height = 400, 200
@ -836,15 +911,6 @@ class ProgressionDialog(MfxDialog):
self.updateGraph() self.updateGraph()
focus = self.createButtons(bottom_frame, kw)
self.mainloop(focus, kw.timeout)
def initKw(self, kw):
kw = KwStruct(kw, strings=(_('&OK'),), default=0, separatorwidth=2)
return MfxDialog.initKw(self, kw)
def updateGraph(self, *args): def updateGraph(self, *args):
interval = self.variable.get() interval = self.variable.get()
canvas = self.canvas canvas = self.canvas
@ -874,12 +940,19 @@ class ProgressionDialog(MfxDialog):
x = x0+graph_dx x = x0+graph_dx
xx = -100 # coord. of prev. text xx = -100 # coord. of prev. text
for res in result: for res in result:
if res[0] is not None and x > xx+self.text_width+4: text = res[0]
text_width = 0
if text is not None:
if len(text) == 5: # day.month
text_width = self.text_width_1
else: # day.month.year
text_width = self.text_width_2
if text is not None and x > xx+text_width+4:
##id = canvas.create_line(x, y0, x, y0-5, width=3) ##id = canvas.create_line(x, y0, x, y0-5, width=3)
##self.items.append(id) ##self.items.append(id)
id = canvas.create_line(x, y0, x, y1, stipple='gray50') id = canvas.create_line(x, y0, x, y1, stipple='gray50')
self.items.append(id) self.items.append(id)
id = canvas.create_text(x, y0+td, anchor='n', text=res[0]) id = canvas.create_text(x, y0+td, anchor='n', text=text)
self.items.append(id) self.items.append(id)
xx = x xx = x
else: else:

View file

@ -71,6 +71,7 @@ gettext = _
class SingleGame_StatsDialog(MfxDialog): class SingleGame_StatsDialog(MfxDialog):
def __init__(self, parent, title, app, player, gameid, **kw): def __init__(self, parent, title, app, player, gameid, **kw):
self.app = app self.app = app
self.selected_game = None
kw = self.initKw(kw) kw = self.initKw(kw)
MfxDialog.__init__(self, parent, title, kw.resizable, kw.default) MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw) top_frame, bottom_frame = self.createFrames(kw)