From 914c73d5aa2d87d55bcc10b3bf5cfd4d4f6a8f93 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 19 Jul 2019 12:05:18 +0200 Subject: "Handling" of some GUI errors that occur during file load/unload and component attach/detach --- jfr_playoff/gui/frames/__init__.py | 31 ++++++++++++++++++------------- jfr_playoff/gui/frames/match.py | 12 ++++++++---- jfr_playoff/gui/frames/visual.py | 6 +++++- jfr_playoff/gui/tabs.py | 2 +- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/jfr_playoff/gui/frames/__init__.py b/jfr_playoff/gui/frames/__init__.py index bef832f..855be4e 100644 --- a/jfr_playoff/gui/frames/__init__.py +++ b/jfr_playoff/gui/frames/__init__.py @@ -382,19 +382,24 @@ class RefreshableOptionMenu(ttk.OptionMenu): self.__callback(self._valueVariable, *args) def refreshOptions(self, *args): - options = self.getOptions() - self['menu'].delete(0, tk.END) - for label, option in options: - self['menu'].add_command( - label=label, - command=self._setit( - self._variable, self._valueVariable, - label, option, self._callback)) - self._valueLock = True - self._valueVariable.set( - self._lastValue - if self._lastValue in [option[1] for option in options] else '') - self._valueLock = False + try: + options = self.getOptions() + self['menu'].delete(0, tk.END) + for label, option in options: + self['menu'].add_command( + label=label, + command=self._setit( + self._variable, self._valueVariable, + label, option, self._callback)) + self._valueLock = True + self._valueVariable.set( + self._lastValue + if self._lastValue in [option[1] for option in options] + else '') + self._valueLock = False + except tk.TclError: + # we're probably being destroyed, ignore + pass def getOptions(self): return [ diff --git a/jfr_playoff/gui/frames/match.py b/jfr_playoff/gui/frames/match.py index 4c8736c..685d399 100644 --- a/jfr_playoff/gui/frames/match.py +++ b/jfr_playoff/gui/frames/match.py @@ -600,10 +600,14 @@ class MatchSettingsFrame(RepeatableFrame): @property def label(self): - phase = self._getPhase() - return 'Mecz #%d (%s)' % ( - self.getMatchID(), - phase.master.tab(phase)['text'] if phase is not None else '') + try: + phase = self._getPhase() + return 'Mecz #%d (%s)' % ( + self.getMatchID(), + phase.master.tab(phase)['text'] if phase is not None else '') + except tk.TclError: + # we're probably just being created, ignore + return '' def setValue(self, value): self.matchID.set(value['id'] if 'id' in value else 0) diff --git a/jfr_playoff/gui/frames/visual.py b/jfr_playoff/gui/frames/visual.py index 3e09445..6780e99 100644 --- a/jfr_playoff/gui/frames/visual.py +++ b/jfr_playoff/gui/frames/visual.py @@ -190,7 +190,11 @@ class MatchList(RefreshableOptionMenu): return match.label def getValues(self): - return self.winfo_toplevel().getMatches() + try: + return self.winfo_toplevel().getMatches() + except tk.TclError: + # we're probably being destroyed, ignore + return [] def getVarValue(self, match): return unicode(match.getMatchID()) diff --git a/jfr_playoff/gui/tabs.py b/jfr_playoff/gui/tabs.py index a12a993..8b66b25 100644 --- a/jfr_playoff/gui/tabs.py +++ b/jfr_playoff/gui/tabs.py @@ -282,7 +282,7 @@ class MatchesTab(PlayoffTab): def setValues(self, config): phases = config['phases'] if 'phases' in config else [] - for idx in self.phases: + for idx in self.phases.keys(): self.removePhase(idx) for phase in phases: newPhase = self.addPhase() -- cgit v1.2.3