[modules/vault] Add a new password vault module ("pass")

Add a new module that can be used to copy passwords from a password
store into the clipboard.

Currently, only "pass" is supported.

As long as only bumblebee is used, it will also show which password is
currently in the clipboard and how long it will still stay there.
This commit is contained in:
Tobias Witek 2019-07-06 20:28:21 +02:00
parent 6deb80edda
commit 451de4544c
3 changed files with 103 additions and 9 deletions

View file

@ -13,14 +13,27 @@ except ImportError:
import functools
class PopupMenu(object):
def __init__(self):
self._root = tk.Tk()
self._root.withdraw()
self._menu = tk.Menu(self._root)
self._menu.bind("<FocusOut>", self._on_focus_out)
self._menu.bind("<Leave>", self._on_focus_out)
def __init__(self, parent=None, leave=True):
if not parent:
self._root = tk.Tk()
self._root.withdraw()
self._menu = tk.Menu(self._root, tearoff=0)
self._menu.bind("<FocusOut>", self._on_focus_out)
else:
self._root = parent.root()
self._root.withdraw()
self._menu = tk.Menu(self._root, tearoff=0)
self._menu.bind("<FocusOut>", self._on_focus_out)
if leave:
self._menu.bind("<Leave>", self._on_focus_out)
def root(self):
return self._root
def menu(self):
return self._menu
def _on_focus_out(self, event=None):
self._root.destroy()
@ -29,13 +42,15 @@ class PopupMenu(object):
self._root.destroy()
callback()
def add_cascade(self, menuitem, submenu):
self._menu.add_cascade(label=menuitem, menu=submenu.menu())
def add_menuitem(self, menuitem, callback):
self._menu.add_command(label=menuitem, command=functools.partial(self._on_click, callback))
def show(self, event):
def show(self, event, offset_x=0, offset_y=0):
try:
self._menu.tk_popup(event['x'], event['y'])
self._menu.tk_popup(event['x'] + offset_x, event['y'] + offset_y)
finally:
self._menu.grab_release()
self._root.mainloop()