Skip to content

Commit

Permalink
Adds new PasswordEdit widget
Browse files Browse the repository at this point in the history
It loads icons to show/hidden the password entry.
  • Loading branch information
kushaldas committed Jan 3, 2020
1 parent 4d71556 commit a2fc708
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
44 changes: 41 additions & 3 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,43 @@ def clear_message(self):
self.hide()


class PasswordEdit(QLineEdit):
"""
A LineEdit with icons to show/hide password entries
"""
CSS = '''QLineEdit {
border-radius: 0px;
height: 30px;
margin: 0px 0px 0px 0px;
}
'''

def __init__(self, parent):
self.parent = parent
super().__init__(self.parent)

# Set styles
self.setStyleSheet(self.CSS)

self.visibleIcon = load_icon("eye_visible.svg")
self.hiddenIcon = load_icon("eye_hidden.svg")

self.setEchoMode(QLineEdit.Password)
self.togglepasswordAction = self.addAction(self.visibleIcon, QLineEdit.TrailingPosition)
self.togglepasswordAction.triggered.connect(self.on_toggle_password_Action)
self.password_shown = False

def on_toggle_password_Action(self):
if not self.password_shown:
self.setEchoMode(QLineEdit.Normal)
self.password_shown = True
self.togglepasswordAction.setIcon(self.hiddenIcon)
else:
self.setEchoMode(QLineEdit.Password)
self.password_shown = False
self.togglepasswordAction.setIcon(self.visibleIcon)


class LoginDialog(QDialog):
"""
A dialog to display the login form.
Expand All @@ -1314,7 +1351,7 @@ class LoginDialog(QDialog):
#login_form QLineEdit {
border-radius: 0px;
height: 30px;
margin: 0px 0px 10px 0px;
margin: 0px 0px 0px 0px;
}
'''

Expand Down Expand Up @@ -1366,8 +1403,7 @@ def __init__(self, parent):
self.username_field = QLineEdit()

self.password_label = QLabel(_('Passphrase'))
self.password_field = QLineEdit()
self.password_field.setEchoMode(QLineEdit.Password)
self.password_field = PasswordEdit(self)

self.tfa_label = QLabel(_('Two-Factor Code'))
self.tfa_field = QLineEdit()
Expand All @@ -1385,8 +1421,10 @@ def __init__(self, parent):

form_layout.addWidget(self.username_label)
form_layout.addWidget(self.username_field)
form_layout.addWidget(QWidget(self))
form_layout.addWidget(self.password_label)
form_layout.addWidget(self.password_field)
form_layout.addWidget(QWidget(self))
form_layout.addWidget(self.tfa_label)
form_layout.addWidget(self.tfa_field)
form_layout.addWidget(buttons)
Expand Down
20 changes: 20 additions & 0 deletions securedrop_client/resources/images/eye_hidden.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions securedrop_client/resources/images/eye_visible.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a2fc708

Please sign in to comment.