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

Add option to replay a specific game/deal from the log

This commit is contained in:
Joe R 2024-09-06 22:45:08 -04:00
parent a0ea7a3870
commit 792fbca78a
2 changed files with 49 additions and 16 deletions

View file

@ -606,6 +606,7 @@ class PysolMenubar(PysolMenubarTk):
mode = kw.get("mode", 101)
demo = 0
gameid = None
gamenum = None
while mode > 0:
if mode > 1000:
demo = not demo
@ -640,10 +641,14 @@ class PysolMenubar(PysolMenubarTk):
header = (_("%(app)s Demo Full log") if demo
else _("Full log for %(player)s")) % transkw
d = FullLog_StatsDialog(self.top, header, self.app, player)
gameid = d.selected_game
gamenum = d.selected_game_num
elif mode == 104:
header = (_("%(app)s Demo Session log") if demo
else _("Session log for %(player)s")) % transkw
d = SessionLog_StatsDialog(self.top, header, self.app, player)
gameid = d.selected_game
gamenum = d.selected_game_num
elif mode == 105:
# TRANSLATORS: eg. top 10 or top 5 results for a certain game
header = (_("%(app)s Demo Top %(tops)d for %(game)s") if demo
@ -698,8 +703,12 @@ class PysolMenubar(PysolMenubarTk):
self.game.quitGame(gameid)
elif mode == 402:
# start a new game with a gameid / gamenumber
# TODO
pass
if (gameid and gamenum and
(gameid != self.game.id or
gamenum != self.game.getGameNumber(format=0))):
self.game.endGame()
self.game.quitGame(gameid,
random=construct_random(gamenum))
else:
print_err("stats problem: %s %s %s" % (mode, demo, player))
pass

View file

@ -383,6 +383,7 @@ class TreeFormatter(PysolStatsFormatter):
t1, t2, t3, t4, t5, t6 = result
id = self.tree.insert("", "end", text=t1, values=(t2, t3, t4))
self.parent_window.tree_items.append(id)
self.parent_window.games[id] = (t6, t2)
num_rows += 1
if num_rows > self.MAX_ROWS:
break
@ -512,7 +513,8 @@ class LogDialog(MfxDialog):
title = _('Log')
MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
# self.selected_game = None
self.selected_game = None
self.selected_game_num = None
top_frame, bottom_frame = self.createFrames(kw)
notebook = ttk.Notebook(top_frame)
@ -522,24 +524,40 @@ class LogDialog(MfxDialog):
full_frame = FullLogFrame(self, notebook, app, player)
notebook.add(full_frame, text=_('Full log'))
self.full_log_frame = full_frame
self.notebook_tabs.append(full_frame._w)
session_frame = SessionLogFrame(self, notebook, app, player)
notebook.add(session_frame, text=_('Session log'))
self.session_log_frame = session_frame
self.notebook_tabs.append(session_frame._w)
notebook.select(LogDialog.SELECTED_TAB)
# bind(notebook, '<<NotebookTabChanged>>', self.tabChanged)
bind(notebook, '<<NotebookTabChanged>>', self.tabChanged)
self.notebook = notebook
focus = self.createButtons(bottom_frame, kw)
# self.tabChanged() # configure buttons state
self.tabChanged() # configure buttons state
self.mainloop(focus, kw.timeout)
def tabChanged(self, *args):
w = self.notebook.select()
run_button = self.buttons[0]
indx = self.notebook_tabs.index(w)
if indx == 0:
g = self.full_log_frame.getSelectedGame()
else:
g = self.session_log_frame.getSelectedGame()
if g[0] is None:
run_button.config(state='disabled')
else:
run_button.config(state='normal')
def initKw(self, kw):
kw = KwStruct(kw,
strings=(_("&OK"),
strings=((_("&Play this game"), 402),
"sep", _("&OK"),
(_("&Save to file"), 500)),
default=0,
width=76*self.CHAR_W,
@ -548,16 +566,17 @@ class LogDialog(MfxDialog):
return MfxDialog.initKw(self, kw)
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
if indx == 0:
self.selected_game, self.selected_game_num \
= self.full_log_frame.getSelectedGame()
else:
self.selected_game, self.selected_game_num \
= self.session_log_frame.getSelectedGame()
MfxDialog.mDone(self, button)
@ -576,6 +595,7 @@ class FullLogFrame(AllGamesFrame):
AllGamesFrame.__init__(self, dialog, parent, app, player, **kw)
header = ('', '99999999999999999999', '9999-99-99 99:99',
'XXXXXXXXXXXX')
self.games = {}
self.formatter.resizeHeader(player, header)
def createHeader(self, player):
@ -587,12 +607,16 @@ class FullLogFrame(AllGamesFrame):
return
self.formatter.writeFullLog(player)
def treeviewSelected(self, *args):
pass
def headerClick(self, column):
pass
def getSelectedGame(self):
sel = self.tree.selection()
if sel and len(sel) == 1:
if sel[0] in self.games:
return self.games[sel[0]]
return (None, None)
class SessionLogFrame(FullLogFrame):
def fillTreeview(self, player):