From e4204cee29bbb4a189b59c25db18a30aee83e1c7 Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Sun, 6 Oct 2024 21:06:03 +0200 Subject: [PATCH] Add visibility toggle icons for password fields --- syng/gui.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/syng/gui.py b/syng/gui.py index c88ac30..77c23b1 100644 --- a/syng/gui.py +++ b/syng/gui.py @@ -108,14 +108,21 @@ class OptionFrame(QWidget): QIcon(":/icons/eye_strike.svg"), QLineEdit.ActionPosition.TrailingPosition, ) + if action is not None: - action.triggered.connect( - lambda: self.string_options[name].setEchoMode( + + def toggle_visibility() -> None: + self.string_options[name].setEchoMode( QLineEdit.EchoMode.Normal if self.string_options[name].echoMode() == QLineEdit.EchoMode.Password else QLineEdit.EchoMode.Password ) - ) + if self.string_options[name].echoMode() == QLineEdit.EchoMode.Password: + action.setIcon(QIcon(":/icons/eye_strike.svg")) + else: + action.setIcon(QIcon(":/icons/eye_clear.svg")) + + action.triggered.connect(toggle_visibility) self.string_options[name].insert(value) self.form_layout.addRow(label, self.string_options[name])