Skip to content

Commit

Permalink
Complete #71 - Windows GUI password prompt support
Browse files Browse the repository at this point in the history
  • Loading branch information
clach04 committed Dec 31, 2023
1 parent d25642f commit 38c5201
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
51 changes: 50 additions & 1 deletion puren_tonbo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,56 @@ def getpass(cls, prompt=None, stream=None):
# pywin32
from pythonwin.pywin.dialogs.login import GetPassword as win32_getpassword
except ImportError:
win32_getpassword = None
try:
from pywin.mfc import dialog # pywin32
import win32con
import win32ui

# from pythonwin.pywin.dialogs.login
def MakePasswordDlgTemplate(title):
style = (
win32con.DS_MODALFRAME
| win32con.WS_POPUP
| win32con.WS_VISIBLE
| win32con.WS_CAPTION
| win32con.WS_SYSMENU
| win32con.DS_SETFONT
)
cs = win32con.WS_CHILD | win32con.WS_VISIBLE
# Window frame and title
dlg = [
[title, (0, 0, 177, 45), style, None, (8, "MS Sans Serif")],
]

# Password label and text box
dlg.append([130, "Password:", -1, (7, 7, 69, 9), cs | win32con.SS_LEFT])
s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER
dlg.append(
["EDIT", None, win32ui.IDC_EDIT1, (50, 7, 60, 12), s | win32con.ES_PASSWORD]
)

# OK/Cancel Buttons
s = cs | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON
dlg.append(
[128, "OK", win32con.IDOK, (124, 5, 50, 14), s | win32con.BS_DEFPUSHBUTTON]
)
dlg.append([128, "Cancel", win32con.IDCANCEL, (124, 22, 50, 14), s])
return dlg

class PasswordDlg(dialog.Dialog):
def __init__(self, title):
dialog.Dialog.__init__(self, MakePasswordDlgTemplate(title))
self.AddDDX(win32ui.IDC_EDIT1, "password")


def win32_getpassword(title="Password", password=""):
d = PasswordDlg(title)
d["password"] = password
if d.DoModal() != win32con.IDOK:
return None
return d["password"]
except ImportError:
win32_getpassword = None


def easydialogs_getpass(prompt):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pycryptodome # for performance - actually used by pyzipper so not explictly nee
pyzipper; python_version > "2.7"
python-gnupg
openssl_enc_compat # https://github.com/clach04/openssl_enc_compat/
# pywin32 # Windows only - for GUI password prompt
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


is_py3 = sys.version_info >= (3,)
is_win = sys.platform.startswith('win')

if len(sys.argv) <= 1:
print("""
Expand Down Expand Up @@ -41,6 +42,8 @@
install_requires = ['colorama', 'pycryptodome', 'python-gnupg', 'openssl_enc_compat']
if is_py3:
install_requires += ['pyzipper'] # pyzipperis python 3.x+
if is_win:
install_requires += ['pywin32']
# TODO consider extras_require, for things like; pyvim, python-gnupg, chi_io
# TODO chi_io on pypi
# https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#optional-dependencies
Expand Down

0 comments on commit 38c5201

Please sign in to comment.