-
Notifications
You must be signed in to change notification settings - Fork 42
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
Re-order widgets in the SourceList on update. #1013
Merged
sssoleileraaa
merged 1 commit into
freedomofpress:master
from
ntoll:reorder-sources-on-update-by-timestamp
Mar 27, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -889,6 +889,22 @@ def show_no_source_selected_message(self): | |
self.no_source_selected.show() | ||
|
||
|
||
class SourceListWidgetItem(QListWidgetItem): | ||
|
||
def __lt__(self, other): | ||
""" | ||
Used for ordering widgets by timestamp of last interaction. | ||
""" | ||
lw = self.listWidget() | ||
me = lw.itemWidget(self) | ||
them = lw.itemWidget(other) | ||
if me and them: | ||
my_ts = arrow.get(me.source.last_updated) | ||
other_ts = arrow.get(them.source.last_updated) | ||
return my_ts < other_ts | ||
return True | ||
|
||
|
||
class SourceList(QListWidget): | ||
""" | ||
Displays the list of sources. | ||
|
@@ -921,6 +937,9 @@ def __init__(self): | |
layout = QVBoxLayout(self) | ||
self.setLayout(layout) | ||
|
||
# Enable ordering. | ||
self.setSortingEnabled(True) | ||
|
||
# To hold references to SourceWidget instances indexed by source UUID. | ||
self.source_widgets = {} | ||
|
||
|
@@ -975,11 +994,13 @@ def update(self, sources: List[Source]) -> List[str]: | |
new_source = SourceWidget(self.controller, source) | ||
self.source_widgets[source.uuid] = new_source | ||
|
||
list_item = QListWidgetItem() | ||
list_item = SourceListWidgetItem() | ||
self.insertItem(0, list_item) | ||
list_item.setSizeHint(new_source.sizeHint()) | ||
self.setItemWidget(list_item, new_source) | ||
|
||
# Sort..! | ||
self.sortItems(Qt.DescendingOrder) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we're resorting the entire source list for every sync, we'll need to test this against 400 and 1000 sources to make sure things don't freeze up |
||
return deleted_uuids | ||
|
||
def initial_update(self, sources: List[Source]): | ||
|
@@ -1003,7 +1024,7 @@ def schedule_source_management(slice_size=slice_size): | |
for source in sources_slice: | ||
new_source = SourceWidget(self.controller, source) | ||
self.source_widgets[source.uuid] = new_source | ||
list_item = QListWidgetItem(self) | ||
list_item = SourceListWidgetItem(self) | ||
list_item.setSizeHint(new_source.sizeHint()) | ||
|
||
self.insertItem(0, list_item) | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice implementation!
cc @creviera for your awareness this impacts #967 - I think merging this and then as part of #967 modifying
SourceWidget.update
to also update alast_updated
field makes sense. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that sounds good to me @redshiftzero