From 37aad245daa651e3087e74c37d5db9edb7acbd5d Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 7 Feb 2018 16:40:41 +1100 Subject: [PATCH 1/4] Set the File List widget to readonly while running, so items can't be deleted mid-share --- onionshare_gui/server_status.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py index 3f7e390c..32b1aa32 100644 --- a/onionshare_gui/server_status.py +++ b/onionshare_gui/server_status.py @@ -178,6 +178,12 @@ class ServerStatus(QtWidgets.QWidget): self.copy_url_button.hide() self.copy_hidservauth_button.hide() + # Set the File List widget to readonly while running, so items can't be deleted mid-share + if self.status == self.STATUS_STARTED or self.status == self.STATUS_WORKING: + self.file_selection.file_list.setEnabled(False) + else: + self.file_selection.file_list.setEnabled(True) + # Button button_stopped_style = 'QPushButton { background-color: #5fa416; color: #ffffff; padding: 10px; border: 0; border-radius: 5px; }' button_working_style = 'QPushButton { background-color: #4c8211; color: #ffffff; padding: 10px; border: 0; border-radius: 5px; font-style: italic; }' From c28c384e972475fc8ccb4d3f131901af62024455 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 7 Feb 2018 17:34:36 +1100 Subject: [PATCH 2/4] Leave the FileList enabled, but hide the item buttons when the server is working or started --- onionshare_gui/file_selection.py | 12 ++++++------ onionshare_gui/server_status.py | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py index 0ba94b51..22f9be09 100644 --- a/onionshare_gui/file_selection.py +++ b/onionshare_gui/file_selection.py @@ -205,16 +205,16 @@ class FileList(QtWidgets.QListWidget): self.takeItem(itemrow) self.files_updated.emit() - item_button = QtWidgets.QPushButton() - item_button.setDefault(False) - item_button.setFlat(True) - item_button.setIcon( QtGui.QIcon(common.get_resource_path('images/file_delete.png')) ) - item_button.clicked.connect(delete_item) + item.item_button = QtWidgets.QPushButton() + item.item_button.setDefault(False) + item.item_button.setFlat(True) + item.item_button.setIcon( QtGui.QIcon(common.get_resource_path('images/file_delete.png')) ) + item.item_button.clicked.connect(delete_item) # Create an item widget to display on the item item_widget_layout = QtWidgets.QHBoxLayout() item_widget_layout.addStretch() - item_widget_layout.addWidget(item_button) + item_widget_layout.addWidget(item.item_button) item_widget = QtWidgets.QWidget() item_widget.setLayout(item_widget_layout) diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py index 32b1aa32..1ebe4a2a 100644 --- a/onionshare_gui/server_status.py +++ b/onionshare_gui/server_status.py @@ -180,9 +180,11 @@ class ServerStatus(QtWidgets.QWidget): # Set the File List widget to readonly while running, so items can't be deleted mid-share if self.status == self.STATUS_STARTED or self.status == self.STATUS_WORKING: - self.file_selection.file_list.setEnabled(False) + for index in range(self.file_selection.file_list.count()): + self.file_selection.file_list.item(index).item_button.hide() else: - self.file_selection.file_list.setEnabled(True) + for index in range(self.file_selection.file_list.count()): + self.file_selection.file_list.item(index).item_button.show() # Button button_stopped_style = 'QPushButton { background-color: #5fa416; color: #ffffff; padding: 10px; border: 0; border-radius: 5px; }' From d3c88988f40b95b88ac9c1e6d295599f37499321 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 7 Feb 2018 19:18:20 +1100 Subject: [PATCH 3/4] Fix comment to reflect what we're doing with the file list buttons --- onionshare_gui/server_status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py index 1ebe4a2a..036eba35 100644 --- a/onionshare_gui/server_status.py +++ b/onionshare_gui/server_status.py @@ -178,7 +178,7 @@ class ServerStatus(QtWidgets.QWidget): self.copy_url_button.hide() self.copy_hidservauth_button.hide() - # Set the File List widget to readonly while running, so items can't be deleted mid-share + # Hide the FileList delete buttons when a share is running if self.status == self.STATUS_STARTED or self.status == self.STATUS_WORKING: for index in range(self.file_selection.file_list.count()): self.file_selection.file_list.item(index).item_button.hide() From 7259232b23409773b9113510fc03dfb278f8e769 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Wed, 7 Feb 2018 09:16:55 -0800 Subject: [PATCH 4/4] Refactor what happens to FileList when the server starts or stops, and also prevent selections when the server starts --- onionshare_gui/file_selection.py | 26 ++++++++++++++++++++++---- onionshare_gui/server_status.py | 8 -------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py index 22f9be09..9198ebc6 100644 --- a/onionshare_gui/file_selection.py +++ b/onionshare_gui/file_selection.py @@ -101,6 +101,25 @@ class FileList(QtWidgets.QListWidget): self.drop_here_image.hide() self.drop_here_text.hide() + def server_started(self): + """ + Update the GUI when the server starts, by hiding delete buttons. + """ + self.setAcceptDrops(False) + self.setCurrentItem(None) + self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection) + for index in range(self.count()): + self.item(index).item_button.hide() + + def server_stopped(self): + """ + Update the GUI when the server stops, by showing delete buttons. + """ + self.file_list.setAcceptDrops(True) + self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) + for index in range(self.count()): + self.item(index).item_button.show() + def resizeEvent(self, event): """ When the widget is resized, resize the drop files image and text. @@ -267,7 +286,6 @@ class FileSelection(QtWidgets.QVBoxLayout): # Delete button should be hidden if item isn't selected current_item = self.file_list.currentItem() - common.log('FileSelection', 'current_item: {}'.format(current_item)) if not current_item: self.delete_button.hide() else: @@ -298,7 +316,7 @@ class FileSelection(QtWidgets.QVBoxLayout): self.file_list.filenames.pop(itemrow) self.file_list.takeItem(itemrow) self.file_list.files_updated.emit() - + self.file_list.setCurrentItem(None) self.update() @@ -307,7 +325,7 @@ class FileSelection(QtWidgets.QVBoxLayout): Gets called when the server starts. """ self.server_on = True - self.file_list.setAcceptDrops(False) + self.file_list.server_started() self.update() def server_stopped(self): @@ -315,7 +333,7 @@ class FileSelection(QtWidgets.QVBoxLayout): Gets called when the server stops. """ self.server_on = False - self.file_list.setAcceptDrops(True) + self.file_list.server_stopped() self.update() def get_num_files(self): diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py index 78f171d0..1aff79f4 100644 --- a/onionshare_gui/server_status.py +++ b/onionshare_gui/server_status.py @@ -182,14 +182,6 @@ class ServerStatus(QtWidgets.QWidget): self.copy_url_button.hide() self.copy_hidservauth_button.hide() - # Hide the FileList delete buttons when a share is running - if self.status == self.STATUS_STARTED or self.status == self.STATUS_WORKING: - for index in range(self.file_selection.file_list.count()): - self.file_selection.file_list.item(index).item_button.hide() - else: - for index in range(self.file_selection.file_list.count()): - self.file_selection.file_list.item(index).item_button.show() - # Button button_stopped_style = 'QPushButton { background-color: #5fa416; color: #ffffff; padding: 10px; border: 0; border-radius: 5px; }' button_working_style = 'QPushButton { background-color: #4c8211; color: #ffffff; padding: 10px; border: 0; border-radius: 5px; font-style: italic; }'