-
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.
Refactor LoginOfflineButton as QPushButton
The Qt buttons do integrate with the operating system, as a result they are easier to take advantage of for accessibility purposes. This is a minimal modification: the button behavior has not changed, even though it could be improved in a few aspects (e.g. implementing some of the conventional button states would allow to provide timely feedback to the person interacting with the button). Decisions: - I called the base class SDPushButton by analogy with QPushButton. The intention is for that class to provide a generic button, adequate to the SecureDrop Client context. - I'd argue that LoginOfflineLink wasn't a link - understood as hyperlink. Links come with expectations of behavior (e.g. history) that are not met in this case. On the other hand, the behavior of LoginOffineLink was close to that of a dialog "dismiss" button. - I didn't write any test for SDPushButton because it doesn't implement any behavior that was tested in LoginOfflineLink. In other words, the button is not less tested as it is. - I inlined the stylesheet in the component for two reasons: 1. It is meant to be a generic component and no other, or few other buttons should ever need to override styles or behavior. If the styles cover all buttons, then having them scoped to the button's namespace and close to the button's code seems preferrable to having them in a (large) single stylesheet. 2. QSS doesn't support CSS custom properties, but Python f-strings can be used to make intentions clearer. See https://material.io/components/buttons and https://speakerdeck.com/didoo/let-there-be-peace-on-css?slide=62
- Loading branch information
1 parent
5fdcd71
commit a82cd00
Showing
7 changed files
with
76 additions
and
37 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,47 @@ | ||
""" | ||
SecureDrop Buttons | ||
These are appropriate for use in the SecureDrop Client. | ||
These buttons look and behave appropriately in the context of SecureDrop client, | ||
but besides that, they are regular Qt buttons which means they benefit from | ||
the full-range of accessibility features provided by the framework. | ||
When adding or extending buttons in this file, please make sure the implementation | ||
doesn't obstruct the default Qt buttons API. | ||
Copyright (C) 2021 The Freedom of the Press Foundation. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
from typing import NewType | ||
|
||
from PyQt5.QtWidgets import QPushButton | ||
|
||
from securedrop_client.resources import load_css | ||
|
||
|
||
class SDPushButton(QPushButton): | ||
"""A QPushButton that follows SecureDrop guidelines.""" | ||
|
||
Alignment = NewType("Alignment", str) | ||
AlignLeft = Alignment("left-aligned") | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
self.setStyleSheet(load_css("button.css")) | ||
|
||
def setAlignment(self, align: Alignment) -> None: | ||
"""Visually align a button that doesn't have a visible outline.""" | ||
self.setProperty("class", f"button text {align}") |
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,17 @@ | ||
.button { | ||
color: #ffffff; | ||
font-family: "Montserrat"; | ||
font-weight: 500; | ||
font-size: 13px; | ||
padding: 11px 18px; | ||
} | ||
|
||
.text { | ||
border: none; | ||
background-color: none; | ||
text-decoration: underline; | ||
} | ||
|
||
.left-aligned { | ||
margin: 0 0 0 -18px; | ||
} |
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