diff --git a/pysollib/actions.py b/pysollib/actions.py index 3c82db9d3..65eb53811 100644 --- a/pysollib/actions.py +++ b/pysollib/actions.py @@ -606,6 +606,7 @@ def mPlayerStats(self, *args, **kw): mode = kw.get("mode", 101) demo = 0 gameid = None + gamenum = None while mode > 0: if mode > 1000: demo = not demo @@ -640,10 +641,14 @@ def mPlayerStats(self, *args, **kw): 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 @@ def mPlayerStats(self, *args, **kw): 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 diff --git a/pysollib/tile/tkstats.py b/pysollib/tile/tkstats.py index ce60c795d..9d940497e 100644 --- a/pysollib/tile/tkstats.py +++ b/pysollib/tile/tkstats.py @@ -383,6 +383,7 @@ def writeLog(self, player, prev_games): 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 @@ def __init__(self, parent, title, app, player, **kw): 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 @@ def __init__(self, parent, title, app, player, **kw): 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, '<>', self.tabChanged) + bind(notebook, '<>', 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 @@ def initKw(self, kw): 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 @@ def __init__(self, dialog, parent, app, player, **kw): 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 @@ def fillTreeview(self, player): 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):