From 171bea4f6e83a59408fcf06736d8b663100226c0 Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Mon, 10 Jun 2019 14:47:59 +0200 Subject: [PATCH] added alternative bumblebee popup implementation * the original implementation doesn't always generate click events. This new implementation fixes this issue. But as the old implementation is still in use (the bluetooth module makes use of it) and this implementation is probably not as matured as the old one, it was agreed to keep both the old and the new implementation until the bluetooth module has been migrated to the new implementatation. --- bumblebee/popup_v2.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 bumblebee/popup_v2.py diff --git a/bumblebee/popup_v2.py b/bumblebee/popup_v2.py new file mode 100644 index 0000000..0894d88 --- /dev/null +++ b/bumblebee/popup_v2.py @@ -0,0 +1,38 @@ +"""Pop-up menus.""" + +try: + import Tkinter as tk +except ImportError: + # python 3 + try: + import tkinter as tk + except ImportError: + pass + +import functools + + +class PopupMenu(object): + def __init__(self): + self._root = tk.Tk() + self._root.withdraw() + self._menu = tk.Menu(self._root) + self._menu.bind("", self._on_focus_out) + + def _on_focus_out(self, event=None): + self._root.destroy() + + def _on_click(self, callback): + self._root.destroy() + callback() + + + def add_menuitem(self, menuitem, callback): + self._menu.add_command(label=menuitem, command=functools.partial(self._on_click, callback)) + + def show(self, event): + try: + self._menu.tk_popup(event['x'], event['y']) + finally: + self._menu.grab_release() + self._root.mainloop()