From 4aff0499f02c3d2deb5ae595f8ac456094da0eea Mon Sep 17 00:00:00 2001 From: Naya Verdier Date: Sat, 25 Jul 2020 08:43:26 -0700 Subject: [PATCH] [util.popup] Deduplicate code, "close" button only if leave=False --- bumblebee_status/util/popup.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/bumblebee_status/util/popup.py b/bumblebee_status/util/popup.py index f162846..bbabe66 100644 --- a/bumblebee_status/util/popup.py +++ b/bumblebee_status/util/popup.py @@ -16,23 +16,19 @@ class menu(object): def __init__(self, parent=None, leave=True): self.running = True - self.parent = None - if not parent: - self._root = tk.Tk() - self._root.withdraw() - self._menu = tk.Menu(self._root, tearoff=0) - self._menu.bind("", self.__on_focus_out) - self.add_menuitem("close", self.__on_focus_out) - self.add_separator() - else: - self._root = parent.root() - self._root.withdraw() - self._menu = tk.Menu(self._root, tearoff=0) - self._menu.bind("", self.__on_focus_out) - self.parent = parent + self.parent = parent + + self._root = parent.root() if parent else tk.Tk() + self._root.withdraw() + self._menu = tk.Menu(self._root, tearoff=0) + self._menu.bind("", self.__on_focus_out) + if leave: self._menu.bind("", self.__on_focus_out) + elif not parent: + self.add_menuitem("close", self.__on_focus_out) + self.add_separator() self._menu.bind("", self.release)