Skip to content

Commit

Permalink
Server: Add separate check for takeoff button
Browse files Browse the repository at this point in the history
  • Loading branch information
goldarte committed Jul 5, 2019
1 parent d5dc720 commit f724e9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Server/copter_table_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __setitem__(self, key, value):
class CopterDataModel(QtCore.QAbstractTableModel):
checks = {}
selected_ready_signal = QtCore.pyqtSignal(bool)
selected_takeoff_ready_signal = QtCore.pyqtSignal(bool)

def __init__(self, parent=None):
super(CopterDataModel, self).__init__(parent)
Expand All @@ -50,6 +51,10 @@ def selfchecked_ready(self, contents=()):
contents = contents or self.data_contents
return filter(lambda x: all_checks(x), contents)

def takeoff_ready(self, contents=()):
contents = contents or self.data_contents
return filter(lambda x: takeoff_checks(x), contents)

def rowCount(self, n=None):
return len(self.data_contents)

Expand All @@ -62,7 +67,6 @@ def headerData(self, section, orientation, role=Qt.DisplayRole):
return self.headers[section]

def data(self, index, role=Qt.DisplayRole):
self.selected_ready_signal.emit(set(self.user_selected()).issubset(self.selfchecked_ready()))
row = index.row()
col = index.column()
#print('row {}, col {}, role {}'.format(row, col, role))
Expand All @@ -86,6 +90,8 @@ def data(self, index, role=Qt.DisplayRole):

def update_model(self, index=QtCore.QModelIndex()):
#self.modelReset.emit()
self.selected_ready_signal.emit(set(self.user_selected()).issubset(self.selfchecked_ready()))
self.selected_takeoff_ready_signal.emit(set(self.user_selected()).issubset(self.takeoff_ready()))
self.dataChanged.emit(index, index, (QtCore.Qt.EditRole,))

@QtCore.pyqtSlot()
Expand Down Expand Up @@ -187,6 +193,11 @@ def all_checks(copter_item):
return False
return True

def takeoff_checks(copter_item):
for i in range(3):
if not check_selfcheck(copter_item[2+i]):
return False
return True

class CopterProxyModel(QtCore.QSortFilterProxyModel):
def __init__(self, parent=None):
Expand Down
2 changes: 1 addition & 1 deletion Server/server_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def init_model(self):

# Connect model signals to UI
self.model.selected_ready_signal.connect(self.ui.start_button.setEnabled)
self.model.selected_ready_signal.connect(self.ui.takeoff_button.setEnabled)
self.model.selected_takeoff_ready_signal.connect(self.ui.takeoff_button.setEnabled)

def client_connected(self, client: Client):
self.signals.add_client_signal.emit(CopterData(copter_id=client.copter_id, client=client))
Expand Down

0 comments on commit f724e9e

Please sign in to comment.