From b8d98eb0e0f9fa7e695539164d61f90a271478d2 Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 23 Jun 2019 12:39:37 +0200 Subject: Reusable refreshable menu option list --- jfr_playoff/gui/frames/team.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/jfr_playoff/gui/frames/team.py b/jfr_playoff/gui/frames/team.py index 9056070..28ffeba 100644 --- a/jfr_playoff/gui/frames/team.py +++ b/jfr_playoff/gui/frames/team.py @@ -6,7 +6,7 @@ from tkinter import ttk from ..frames import GuiFrame, RepeatableFrame, ScrollableFrame from ..frames import WidgetRepeater, RepeatableEntry -from ..frames import SelectionButton, SelectionFrame +from ..frames import SelectionButton, SelectionFrame, RefreshableOptionMenu from ..frames import getIntVal, setPanelState class ManualTeamRow(RepeatableFrame): @@ -276,23 +276,15 @@ class TeamSettingsFrame(ScrollableFrame): return self.fetchSettingsFrame.getTeams() return [] -class TeamList(ttk.OptionMenu): +class TeamList(RefreshableOptionMenu): def __init__(self, *args, **kwargs): - ttk.OptionMenu.__init__(self, *args, **kwargs) + RefreshableOptionMenu.__init__(self, *args, **kwargs) self.winfo_toplevel().bind( - '<>', self._refreshTeams, add='+') - self._refreshTeams(None) + '<>', self.refreshOptions, add='+') self.configure(width=10) - def _refreshTeams(self, event): - oldValue = self._variable.get() - options = [team[0] for team in self.winfo_toplevel().getTeams()] - self['menu'].delete(0, tk.END) - for option in options: - self['menu'].add_command( - label=option, command=tk._setit(self._variable, option)) - if oldValue not in options: - self._variable.set('') + def getOptions(self): + return [team[0] for team in self.winfo_toplevel().getTeams()] class TeamAliasRow(RepeatableFrame): def renderContent(self): -- cgit v1.2.3