-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1430 from freedomofpress/1351-checkbox-control
Replace hide/show Passphrase icon control, with checkbox control
- Loading branch information
Showing
9 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ShowPassphrase_widget QFrame{ | ||
padding: 5px 3px 3px 5px; | ||
} | ||
#ShowPassphrase_widget QLabel{ | ||
font-family: 'Source Sans Pro'; | ||
font-weight: 500; | ||
font-size: 12px; | ||
line-height: 15px; | ||
padding: 0px 0px 0px 3px; | ||
} | ||
|
||
#ShowPassphrase_widget QFrame:hover { | ||
background-color: rgba(230, 253, 255, 0.2); | ||
} | ||
|
||
#ShowPassphrase_widget QLabel:hover { | ||
background-color: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
SecureDrop customized passphrase checkbox control | ||
A checkbox control created to toggle with hiding and showing PasswordEdit passphrases. | ||
Consists of a QCheckBox and a QLabel positioned horizontally within a QFrame. | ||
Present in the Sign-in and Export Dialog. | ||
""" | ||
from gettext import gettext as _ | ||
|
||
from pkg_resources import resource_string | ||
from PyQt5.QtCore import Qt, pyqtSignal | ||
from PyQt5.QtGui import QCursor, QFont, QMouseEvent | ||
from PyQt5.QtWidgets import QCheckBox, QFrame, QHBoxLayout, QLabel, QWidget | ||
|
||
|
||
class SDCheckBox(QWidget): | ||
clicked = pyqtSignal() | ||
CHECKBOX_CSS = resource_string(__name__, "checkbox.css").decode("utf-8") | ||
PASSPHRASE_LABEL_SPACING = 1 | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
self.setObjectName("ShowPassphrase_widget") | ||
self.setStyleSheet(self.CHECKBOX_CSS) | ||
|
||
font = QFont() | ||
font.setLetterSpacing(QFont.AbsoluteSpacing, self.PASSPHRASE_LABEL_SPACING) | ||
|
||
self.layout = QHBoxLayout() | ||
self.layout.setContentsMargins(0, 0, 0, 0) | ||
self.layout.setSpacing(0) | ||
self.setLayout(self.layout) | ||
|
||
self.frame = QFrame() | ||
self.frame.setLayout(QHBoxLayout()) | ||
self.frame.layout().setContentsMargins(0, 0, 0, 0) | ||
self.frame.layout().setSpacing(0) | ||
|
||
self.checkbox = QCheckBox() | ||
self.label = QLabel(_("Show Passphrase")) | ||
self.label.setFont(font) | ||
|
||
self.layout.addWidget(self.frame) | ||
self.frame.layout().addWidget(self.checkbox) | ||
self.frame.layout().addWidget(self.label) | ||
self.frame.setCursor(QCursor(Qt.PointingHandCursor)) | ||
|
||
self.clicked.connect(self.checkbox.click) | ||
|
||
def mousePressEvent(self, e: QMouseEvent) -> None: | ||
self.clicked.emit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
from PyQt5.QtWidgets import QApplication, QLineEdit | ||
from PyQt5.QtWidgets import QApplication, QCheckBox, QLineEdit | ||
|
||
from securedrop_client.gui.base import PasswordEdit | ||
|
||
app = QApplication([]) | ||
|
||
|
||
def test_PasswordEdit(mocker): | ||
checkbox = QCheckBox() | ||
passwordline = PasswordEdit(None) | ||
passwordline.togglepasswordAction.trigger() | ||
|
||
passwordline.on_toggle_password_Action() | ||
checkbox.isChecked() | ||
assert passwordline.echoMode() == QLineEdit.Normal | ||
passwordline.togglepasswordAction.trigger() | ||
passwordline.on_toggle_password_Action() | ||
assert passwordline.echoMode() == QLineEdit.Password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from PyQt5.QtTest import QSignalSpy | ||
from PyQt5.QtWidgets import QApplication | ||
|
||
from securedrop_client.gui.base.checkbox import SDCheckBox | ||
|
||
app = QApplication([]) | ||
|
||
|
||
def test_SDCheckBox(): | ||
checkbox_area = SDCheckBox() | ||
signal_emissions = QSignalSpy(checkbox_area.clicked) | ||
|
||
checkbox_area.mousePressEvent(None) | ||
|
||
assert len(signal_emissions) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters