Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source widget polish #522

Merged
merged 5 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 41 additions & 27 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,27 @@ def get_current_source(self):
class SourceWidget(QWidget):
"""
Used to display summary information about a source in the list view.

-----------------------------------------------------------------------------
| |
| ----------------------------------------------------------------- |
| | | |
| | | |
| | ------------- ---------------------------- ------------------ | |
| | | ------ | | ------ | | ----------- | | |
| | | |star| | | |name| | | |paperclip| | | |
| | | ------ | | ------ | | ----------- | | |
| | | | | --------- | | ----------- | | |
| | | | | |preview| | | |timestamp| | | |
| | | | | --------- | | ----------- | | |
| | | | | | | | | |
| | | gutter | | summary | | metadata | | |
| | ------------- ---------------------------- ------------------ | |
| | | |
| | source_widget | |
| ----------------------------------------------------------------- |
| SourceWidget |
-----------------------------------------------------------------------------
"""

CSS = '''
Expand Down Expand Up @@ -854,7 +875,7 @@ def __init__(self, source: Source):
self.setStyleSheet(self.CSS)

# Set layout
layout = QVBoxLayout(self)
layout = QHBoxLayout(self)
self.setLayout(layout)

# Remove margins and spacing
Expand All @@ -864,7 +885,7 @@ def __init__(self, source: Source):
# Set up gutter
self.gutter = QWidget()
self.gutter.setObjectName('gutter')
self.gutter.setFixedWidth(30)
self.gutter.setFixedWidth(40)
gutter_layout = QVBoxLayout(self.gutter)
gutter_layout.setContentsMargins(0, 0, 0, 0)
gutter_layout.setSpacing(0)
Expand All @@ -882,43 +903,36 @@ def __init__(self, source: Source):
self.name.setObjectName('source_name')
self.preview = QLabel()
self.preview.setObjectName('preview')
self.preview.setFixedSize(QSize(365, 40))
self.preview.setFixedSize(QSize(312, 60))
self.preview.setWordWrap(True)
summary_layout.addWidget(self.name)
summary_layout.addWidget(self.preview, 1)
summary_layout.addWidget(self.preview)

# Set up metadata
self.metadata = QWidget()
self.metadata.setObjectName('metadata')
self.metadata.setMaximumWidth(30)
self.metadata.setMaximumWidth(60)
metadata_layout = QVBoxLayout(self.metadata)
metadata_layout.setContentsMargins(0, 0, 0, 0)
metadata_layout.setSpacing(0)
self.attached = SvgLabel('paperclip.svg', QSize(14, 16))
self.attached.setObjectName('paperclip')
metadata_layout.addWidget(self.attached)
self.paperclip = SvgLabel('paperclip.svg', QSize(18, 18)) # Set to size provided in the svg
self.paperclip.setObjectName('paperclip')
self.paperclip.setFixedSize(QSize(22, 22))
self.timestamp = QLabel()
self.timestamp.setObjectName('timestamp')
metadata_layout.addWidget(self.paperclip, 0, Qt.AlignRight)
metadata_layout.addWidget(self.timestamp, 0, Qt.AlignRight)
metadata_layout.addStretch()

# Set up source row
self.source_row = QWidget()
source_row_layout = QHBoxLayout(self.source_row)
source_row_layout.setContentsMargins(0, 0, 0, 0)
source_row_layout.setSpacing(0)
source_row_layout.addWidget(self.gutter)
source_row_layout.addWidget(self.summary)
source_row_layout.addWidget(self.metadata)

# Set up timestamp row
self.updated = QLabel()
self.updated.setObjectName('timestamp')

# Set up a source_widget
self.source_widget = QWidget()
self.source_widget.setObjectName('source_widget')
source_widget_layout = QVBoxLayout(self.source_widget)
source_widget_layout.setContentsMargins(0, 10, 10, 10)
source_widget_layout = QHBoxLayout(self.source_widget)
source_widget_layout.setContentsMargins(0, 10, 0, 10)
source_widget_layout.setSpacing(0)
source_widget_layout.addWidget(self.source_row, 1)
source_widget_layout.addWidget(self.updated, 1, Qt.AlignRight)
source_widget_layout.addWidget(self.gutter)
source_widget_layout.addWidget(self.summary)
source_widget_layout.addWidget(self.metadata)

# Add widgets to main layout
layout.addWidget(self.source_widget)
Expand All @@ -936,10 +950,10 @@ def update(self):
"""
Updates the displayed values with the current values from self.source.
"""
self.updated.setText(arrow.get(self.source.last_updated).humanize())
self.timestamp.setText(arrow.get(self.source.last_updated).format('DD MMM'))
self.name.setText(self.source.journalist_designation)
if self.source.document_count == 0:
self.attached.hide()
self.paperclip.hide()

def delete_source(self, event):
if self.controller.api is None:
Expand Down
12 changes: 11 additions & 1 deletion securedrop_client/resources/images/paperclip.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,12 @@ def test_SourceWidget_update_attachment_icon():
sw = SourceWidget(source)

sw.update()
assert not sw.attached.isHidden()
assert not sw.paperclip.isHidden()

source.document_count = 0

sw.update()
assert sw.attached.isHidden()
assert sw.paperclip.isHidden()


def test_SourceWidget_delete_source(mocker, session, source):
Expand Down