From 8ab61016d9d10bfbeccd3e1824a3bac404b4900c Mon Sep 17 00:00:00 2001 From: John Hensley Date: Mon, 16 Mar 2020 11:24:27 -0400 Subject: [PATCH] Fix StarToggleButton hover leave The icon was being reset to always-on even if the source weren't starred. This adds a check for that, and also corrects the misleading naming of the attribute determining whether the star API calls should be made when the widget state changes. (If it only takes a weekend for your naming to start tripping you up, it was clearly not thought through.) --- securedrop_client/gui/widgets.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/securedrop_client/gui/widgets.py b/securedrop_client/gui/widgets.py index 433776aad..6d8f52981 100644 --- a/securedrop_client/gui/widgets.py +++ b/securedrop_client/gui/widgets.py @@ -1203,7 +1203,6 @@ def __init__(self, controller: Controller, source: Source): self.source = source self.installEventFilter(self) - self.toggle_event_enabled = True self.setObjectName('star_button') self.setStyleSheet(self.css) @@ -1222,6 +1221,7 @@ def disable(self): to save on state we update the icon's off state image to display on (hack). """ + self.disable_api_call() self.setCheckable(False) if self.source.is_starred: self.set_icon(on='star_on.svg', off='star_on.svg') @@ -1244,6 +1244,7 @@ def enable(self): """ Enable the widget. """ + self.enable_api_call() self.setCheckable(True) self.set_icon(on='star_on.svg', off='star_off.svg') self.setChecked(self.source.is_starred) @@ -1271,7 +1272,8 @@ def eventFilter(self, obj, event): if checkable: self.set_icon(on='star_on.svg', off='star_off.svg') else: - self.set_icon(on='star_on.svg', off='star_on.svg') + if self.source.is_starred: + self.set_icon(on='star_on.svg', off='star_on.svg') return QObject.event(obj, event) def on_authentication_changed(self, authenticated: bool): @@ -1288,7 +1290,7 @@ def on_toggle(self): """ Tell the controller to make an API call to update the source's starred field. """ - if self.toggle_event_enabled: + if self.is_api_call_enabled: self.controller.update_star(self.source, self.on_update) def on_toggle_offline(self): @@ -1313,15 +1315,15 @@ def update(self): Update the star to reflect its source's current state. """ self.controller.session.refresh(self.source) - self.disable_toggle_event() + self.disable_api_call() self.setChecked(self.source.is_starred) - self.enable_toggle_event() + self.enable_api_call() - def disable_toggle_event(self): - self.toggle_event_enabled = False + def disable_api_call(self): + self.is_api_call_enabled = False - def enable_toggle_event(self): - self.toggle_event_enabled = True + def enable_api_call(self): + self.is_api_call_enabled = True class DeleteSourceMessageBox: