-
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 #293 from freedomofpress/issue-279-refreshing
Top Pane and User Button
- Loading branch information
Showing
13 changed files
with
1,084 additions
and
364 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
""" | ||
Generic custom widgets. | ||
Copyright (C) 2018 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 PyQt5.QtWidgets import QLabel, QHBoxLayout, QPushButton | ||
from PyQt5.QtCore import QSize | ||
|
||
from securedrop_client.resources import load_svg, load_icon | ||
|
||
|
||
class SvgPushButton(QPushButton): | ||
""" | ||
A widget used to display the contents of Scalable Vector Graphics (SVG) files provided for | ||
associated user action modes, see https://doc.qt.io/qt-5/qicon.html#Mode-enum. | ||
Parameters | ||
---------- | ||
normal: str | ||
The name of the SVG file to add to the button for QIcon.Normal mode. | ||
disabled: str, optional | ||
The name of the SVG file to add to the button for QIcon.Disabled mode. | ||
active: str, optional | ||
The name of the SVG file to add to the button for QIcon.Active mode. | ||
selected: str, optional | ||
The name of the SVG file to add to the button for QIcon.Selected mode. | ||
svg_size: QSize, optional | ||
The display size of the SVG, defaults to filling the entire size of the widget. | ||
""" | ||
|
||
def __init__(self, normal: str, disabled=None, active=None, selected=None, svg_size=None): | ||
super().__init__() | ||
|
||
# Set layout | ||
layout = QHBoxLayout(self) | ||
self.setLayout(layout) | ||
|
||
# Remove margins and spacing | ||
layout.setContentsMargins(0, 0, 0, 0) | ||
layout.setSpacing(0) | ||
|
||
# Add SVG icon and set its size | ||
self.icon = load_icon(normal=normal, disabled=disabled, active=active, selected=selected) | ||
self.setIcon(self.icon) | ||
self.setIconSize(svg_size) if svg_size else self.setIconSize(QSize()) | ||
|
||
|
||
class SvgLabel(QLabel): | ||
""" | ||
A widget used to display the contents of a Scalable Vector Graphics (SVG) file. | ||
Parameters | ||
---------- | ||
filename: str | ||
The name of the SVG file to add to the label. | ||
svg_size: QSize, optional | ||
The display size of the SVG, defaults to filling the entire size of the widget. | ||
""" | ||
|
||
def __init__(self, filename: str, svg_size=None): | ||
super().__init__() | ||
|
||
# Remove margins and spacing | ||
layout = QHBoxLayout(self) | ||
layout.setContentsMargins(0, 0, 0, 0) | ||
layout.setSpacing(0) | ||
self.setLayout(layout) | ||
|
||
# Add SVG and set its size | ||
self.svg = load_svg(filename) | ||
self.svg.setFixedSize(svg_size) if svg_size else self.svg.setFixedSize(QSize()) | ||
layout.addWidget(self.svg) |
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
Oops, something went wrong.