@ -7,6 +7,7 @@ from typing import Union
import wx
import wx . lib . scrolledpanel as scrolled
import gnupg
from pass_handler import Pass , copy_to_clipboard , get_password_from_path , pass_pull , pass_push
@ -42,13 +43,18 @@ class PassUi(wx.Frame):
"""
super ( ) . __init__ ( * args , * * kw )
self . pass_handler : Pass = Pass ( )
self . gpg_handler : gnupg . GPG = gnupg . GPG ( )
self . gpg_key : str = str ( )
# create a panel in the frame
self . pnl : wx . lib . scrolledpanel . ScrolledPanel = scrolled . ScrolledPanel ( self , - 1 , style = wx . VSCROLL )
self . pnl . SetupScrolling ( )
# and create a sizer to manage the layout of child widgets
self . sizer : wx . BoxSizer = wx . BoxSizer ( wx . VERTICAL )
self . pnl . SetSizer ( self . sizer )
if self . pass_handler . is_init :
self . add_buttons ( )
else :
self . add_init ( )
@redraw
def add_buttons ( self ) :
@ -82,6 +88,25 @@ class PassUi(wx.Frame):
btn )
index = index + 1
@redraw
def add_init ( self ) :
select_label : str = " Select GPG Key "
if self . gpg_key :
label : wx . StaticText = wx . StaticText ( self . pnl , label = " Selected GPG key: " )
self . sizer . Add ( label , 0 , wx . EXPAND ) # pylint: disable=no-member
choice : wx . StaticText = wx . StaticText ( self . pnl , label = self . gpg_key )
self . sizer . Add ( choice , 0 , wx . EXPAND ) # pylint: disable=no-member
select_label : str = " Select New GPG Key "
gpg_btn : wx . Button = wx . Button ( self . pnl , label = select_label )
init_btn : wx . Button = wx . Button ( self . pnl , label = " Init Local Password Store " )
self . sizer . Add ( gpg_btn , 0 , wx . EXPAND ) # pylint: disable=no-member
self . sizer . Add ( init_btn , 0 , wx . EXPAND ) # pylint: disable=no-member
self . Bind ( wx . EVT_BUTTON ,
lambda event : self . gpg_button_clicked ( ) , gpg_btn )
if self . gpg_key :
self . Bind ( wx . EVT_BUTTON ,
lambda event : self . init_button_clicked ( ) , init_btn )
def add_push_pull ( self ) :
""" add_push_pull. """
push_btn : wx . Button = wx . Button ( self . pnl , label = " Push to remote " )
@ -145,6 +170,24 @@ class PassUi(wx.Frame):
btn . SetFont ( font )
return btn
def gpg_button_clicked ( self ) :
""" gpg_button_clicked.
"""
private_keys : dict = self . gpg_handler . list_keys ( True )
uid_list : list [ str ] = list ( )
for key in private_keys :
for uid in key [ ' uids ' ] :
uid_list . append ( uid )
self . show_choice ( uid_list , " Select GNUPG Key " )
def init_button_clicked ( self ) :
""" init_button_clicked.
"""
self . pass_handler . pass_init ( self . gpg_key )
self . add_buttons ( )
def password_button_clicked ( self , index : int ) :
""" password_button_clicked.
@ -202,6 +245,18 @@ class PassUi(wx.Frame):
self . pass_handler . save_to_pass ( password , path , full_path )
self . back_button_clicked ( )
@redraw
def show_choice ( self , choices : list [ str ] , name : str ) :
choice : wx . Choice = wx . Choice ( self . pnl , choices = choices , name = name )
self . sizer . Add ( choice , 0 , wx . EXPAND )
self . Bind ( wx . EVT_CHOICE , lambda event : self . choice_button_clicked ( event ) , choice )
def choice_button_clicked ( self , event ) :
choice = event . GetEventObject ( )
self . gpg_key = choice . GetString ( choice . GetSelection ( ) )
print ( self . gpg_key )
self . add_init ( )
@redraw
def show_new_dialog ( self ) :
""" show_new_dialog.
@ -326,7 +381,6 @@ class PassUi(wx.Frame):
n_btn )
self . add_push_pull ( )
if __name__ == ' __main__ ' :
# When this module is run (not imported) then create the app, the
# frame, show it, and start the event loop.