Refactor what happens to FileList when the server starts or stops, and also prevent selections when the server starts

This commit is contained in:
Micah Lee 2018-02-07 09:16:55 -08:00
parent acf5c1bb88
commit 4639420dfc
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
2 changed files with 22 additions and 12 deletions

View file

@ -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):

View file

@ -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; }'