Skip to content

Commit

Permalink
EasyDialogs support for password prompt
Browse files Browse the repository at this point in the history
Potentially a fix for #71 - Windows GUI password prompt support
  • Loading branch information
clach04 committed Dec 31, 2023
1 parent 76dac90 commit 65e9102
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion puren_tonbo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import sys


try:
# Multiple EasyDialogs implementations out there, we don't care what we get so long as it works
import EasyDialogs
except ImportError:
EasyDialogs = None

try:
import getpass
except ImportError:
Expand Down Expand Up @@ -33,6 +39,14 @@ def getpass(cls, prompt=None, stream=None):
tkinter = None


def easydialogs_getpass(prompt):
password = EasyDialogs.AskPassword('password?', default='')
# if password is None, cancel was issued
# if password == '', no password issue, OK was issued. See , `default` parameter above
if password and not isinstance(password, bytes):
password = password.encode('us-ascii')
return password

def tk_getpass(prompt):
tkinter.Tk().withdraw()
password = askstring('puren tonbo', 'Password', show='*')
Expand All @@ -41,9 +55,15 @@ def tk_getpass(prompt):
return password


supported_password_prompt = ('any', 'text', 'gui',) # although GUI may not be possible
if EasyDialogs:
supported_password_prompt += ('EasyDialogs',) # case?
if tkinter:
supported_password_prompt += ('tk',)

# TODO replace with plugin classes
def supported_password_prompt_mechanisms():
return ('any', 'text', 'gui', 'tk')
return supported_password_prompt # ('any', 'text', 'gui', 'tk')
# TODO return ('any', 'text', 'gui', 'tk', 'psidialog' , 'external') # external would use os var PT_ASKPASS

# TODO see dirname param in gen_caching_get_password()
Expand All @@ -61,6 +81,9 @@ def getpassfunc(prompt=None, preference_list=None):
else:
return getpass.getpass()

if EasyDialogs and ('EasyDialogs' in preference_list or 'gui' in preference_list or 'any' in preference_list):
return easydialogs_getpass(prompt)

if tkinter and ('tk' in preference_list or 'gui' in preference_list or 'any' in preference_list):
return tk_getpass(prompt)

0 comments on commit 65e9102

Please sign in to comment.