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 74cb643fab
commit 7259232b23
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):