def remove_participants(self, selection: QItemSelection): if len(self.participants) < 1: return if selection.isEmpty(): start, end = len(self.participants) - 1, len( self.participants) - 1 # delete last element else: start, end = min([rng.top() for rng in selection ]), max([rng.bottom() for rng in selection]) del self.participants[start:end + 1] num_removed = (end + 1) - start for participant in self.participants: if participant.relative_rssi > len(self.participants) - 1: participant.relative_rssi -= num_removed # fix duplicates n = len(self.participants) for p1, p2 in itertools.combinations(self.participants, 2): if p1.relative_rssi == p2.relative_rssi: p1.relative_rssi = next((i for i in range(n) if i not in set( p.relative_rssi for p in self.participants)), 0) self.update() self.participant_edited.emit()
def remove_participants(self, selection: QItemSelection): if len(self.participants) < 1: return if selection.isEmpty(): start, end = len(self.participants) - 1, len(self.participants) - 1 # delete last element else: start, end = min([rng.top() for rng in selection]), max([rng.bottom() for rng in selection]) del self.participants[start:end + 1] num_removed = (end + 1) - start for participant in self.participants: if participant.relative_rssi > len(self.participants) - 1: participant.relative_rssi -= num_removed # fix duplicates n = len(self.participants) for p1, p2 in itertools.combinations(self.participants, 2): if p1.relative_rssi == p2.relative_rssi: p1.relative_rssi = next((i for i in range(n) if i not in set(p.relative_rssi for p in self.participants)), 0) self.update() self.participant_edited.emit()
def onSelectionChanged(self, selection: QItemSelection): if selection.isEmpty(): return item = selection.indexes()[0] data = item.data(ROLE_HTTP_MESSAGE) if data: self.selected.emit(data)
def move_down(self, selection: QItemSelection): if selection.isEmpty() or len(self.participants) < 1: return None, None start, end = min([rng.top() for rng in selection]), max([rng.bottom() for rng in selection]) if end >= len(self.participants) - 1: return None, None for i in reversed(range(start, end + 1)): self.participants[i], self.participants[i + 1] = self.participants[i + 1], self.participants[i] self.update() self.participant_edited.emit() return start, end
def select_one_equation(self, selected: QItemSelection, deselected: QItemSelection): """This type of selection shows all equation details""" # This makes an equation removed behave like an empty selection if self.equation_taken is True: deselected = selected self.equation_taken = RESET self.state_data.update(selected=selected) self.state_data.update(deselected=deselected) # First selection first_selection = deselected.isEmpty() is True and selected.isEmpty() is False # print('First Selection is: ', first_selection) # This means an equation was selected and then another equation was selection normal_selection = deselected.isEmpty() is False and selected.isEmpty() is False # print('Normal Selection is: ', normal_selection) # This means an equation was deselected, but there wasn't a new selection # There are two conditions when this happens. 1) All selections cleared 2) Record is deleted empty_selection = (deselected.isEmpty() is False and selected.isEmpty() is True) and \ self.equation_taken is False # print('Empty Selection is: ', empty_selection) if normal_selection or empty_selection: self.capture_details_current_state() dirty_data = self.state_data['dirty_data'] if dirty_data['new']: up_box = QMessageBox() keys = dirty_data['new'].keys() up_box.setIcon(QMessageBox.Question) up_box.setText('Changes were made') up_box.setWindowTitle('Save Changes') up_box.setDetailedText('Additional details') fmt = '{key}\n\twas: {value}\n\tis: {new_val}\n' msg = '' for key in keys: if key == 'notes': msg += '\tNotes were changed\n' else: msg += fmt.format(key=key, value=dirty_data['old'][key], new_val=dirty_data['new'][key]) up_box.setDetailedText(msg) up_box.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) up_box.setDefaultButton(QMessageBox.Save) # noinspection PyUnresolvedReferences up_box.buttonClicked.connect(self.allow_equation_change) up_box.exec_() else: self.refresh_equation_details() if first_selection: self.refresh_equation_details()
def move_down(self, selection: QItemSelection): if selection.isEmpty() or len(self.participants) < 1: return None, None start, end = min([rng.top() for rng in selection ]), max([rng.bottom() for rng in selection]) if end >= len(self.participants) - 1: return None, None for i in reversed(range(start, end + 1)): self.participants[i], self.participants[i + 1] = self.participants[ i + 1], self.participants[i] self.update() self.participant_edited.emit() return start, end
def __driveListSelectionChanged(self, selected: QItemSelection, deselected: QItemSelection): self.__changeActionAvailabilityBasedOnDriveSelection( not selected.isEmpty())