def select(self, points): # noinspection PyArgumentList if self.data is None: return if self.selection is None: self.selection = np.zeros(len(self.data), dtype=np.uint8) indices = [p.data() for p in points] keys = QApplication.keyboardModifiers() # Remove from selection if keys & Qt.AltModifier: self.selection[indices] = 0 # Append to the last group elif keys & Qt.ShiftModifier and keys & Qt.ControlModifier: self.selection[indices] = np.max(self.selection) # Create a new group elif keys & Qt.ShiftModifier: self.selection[indices] = np.max(self.selection) + 1 # No modifiers: new selection else: self.selection = np.zeros(len(self.data), dtype=np.uint8) self.selection[indices] = 1 self.update_colors(keep_colors=True) if self.label_only_selected: self.update_labels() self.master.selection_changed()
def select(self, points): # noinspection PyArgumentList if self.data is None: return if self.selection is None: self.selection = np.zeros(len(self.data), dtype=np.uint8) indices = [p.data() for p in points] keys = QApplication.keyboardModifiers() # Remove from selection if keys & Qt.AltModifier: self.selection[indices] = 0 # Append to the last group elif keys & Qt.ShiftModifier and keys & Qt.ControlModifier: self.selection[indices] = np.max(self.selection) # Create a new group elif keys & Qt.ShiftModifier: self.selection[indices] = np.max(self.selection) + 1 # No modifiers: new selection else: self.selection = np.zeros(len(self.data), dtype=np.uint8) self.selection[indices] = 1 self.update_colors(keep_colors=True) if self.label_only_selected: self.update_labels() self.master.selection_changed()
def deselect(self): keys = QApplication.keyboardModifiers() if keys & (Qt.ControlModifier | Qt.ShiftModifier | Qt.AltModifier): return for item in self._items: item.set_selected(False) self.__selected_attrs.clear() super().deselect()
def _deselect(self, finished: bool): # When finished, emit selection_changed. keys = QApplication.keyboardModifiers() if keys & Qt.ShiftModifier: return for index in range(len(self.__selection_rects)): self.__selection_rects[index].selection_range = None if self.__selection and finished: self.__selection = set() self.selection_changed.emit([], [])
def select(self, indices): keys = QApplication.keyboardModifiers() indices = set(indices) if keys & Qt.ControlModifier: self.selection ^= indices elif keys & Qt.AltModifier: self.selection -= indices elif keys & Qt.ShiftModifier: self.selection |= indices else: self.selection = indices
def select(self, indices): keys = QApplication.keyboardModifiers() indices = set(indices) if keys & Qt.ControlModifier: self.selection ^= indices elif keys & Qt.AltModifier: self.selection -= indices elif keys & Qt.ShiftModifier: self.selection |= indices else: self.selection = indices
def select_by_indices(self, indices): if self.selection is None: self.selection = np.zeros(self.n_valid, dtype=np.uint8) keys = QApplication.keyboardModifiers() if keys & Qt.AltModifier: self.selection_remove(indices) elif keys & Qt.ShiftModifier and keys & Qt.ControlModifier: self.selection_append(indices) elif keys & Qt.ShiftModifier: self.selection_new_group(indices) else: self.selection_select(indices)
def select_by_indices(self, indices: List): keys = QApplication.keyboardModifiers() if keys & Qt.ControlModifier: self.selection = list(set(self.selection) ^ set(indices)) elif keys & Qt.AltModifier: self.selection = list(set(self.selection) - set(indices)) elif keys & Qt.ShiftModifier: self.selection = list(set(self.selection) | set(indices)) else: self.selection = list(set(indices)) self.__select_bars() self.selection_changed.emit(self.selection)
def select_by_indices(self, indices): if self.selection is None: self.selection = np.zeros(self.n_ids, dtype=np.uint8) keys = QApplication.keyboardModifiers() if keys & Qt.AltModifier: self.selection_remove(indices) elif keys & Qt.ShiftModifier and keys & Qt.ControlModifier: self.selection_append(indices) elif keys & Qt.ShiftModifier: self.selection_new_group(indices) else: self.selection_select(indices)
def modifiers(self, modifiers): """ Context that simulates pressed modifiers Since QTest.keypress requries pressing some key, we simulate pressing "BassBoost" that looks exotic enough to not meddle with anything. """ old_modifiers = QApplication.keyboardModifiers() try: QTest.keyPress(self.widget, Qt.Key_BassBoost, modifiers) yield finally: QTest.keyRelease(self.widget, Qt.Key_BassBoost, old_modifiers)
def modifiers(self, modifiers): """ Context that simulates pressed modifiers Since QTest.keypress requries pressing some key, we simulate pressing "BassBoost" that looks exotic enough to not meddle with anything. """ old_modifiers = QApplication.keyboardModifiers() try: QTest.keyPress(self.widget, Qt.Key_BassBoost, modifiers) yield finally: QTest.keyRelease(self.widget, Qt.Key_BassBoost, old_modifiers)
def _key_pressed(self, event): """ Handle KeyPressed event We only care about CTRL-S in order to save changes :param event: key event """ QsciScintilla.keyPressEvent(self._code_editor, event) if event.key() in [QtCore.Qt.Key_S, QtCore.Qt.Key_Save]: modifiers = QApplication.keyboardModifiers() if modifiers == QtCore.Qt.ControlModifier and self.is_modified: logger.debug("Saving...") self.on_save_changes() self.key_pressed_event(event)
def select(self, indices): for i in self.selection: self._items[i].deselect() keys = QApplication.keyboardModifiers() if keys & Qt.ControlModifier: self.selection.symmetric_difference_update(indices) elif keys & Qt.AltModifier: self.selection.difference_update(indices) elif keys & Qt.ShiftModifier: self.selection.update(indices) else: self.selection = set(indices) for i in self.selection: self._items[i].select() self.master.selection_changed()
def node_key_pressed_event(self, event): """ Sets key events for: * Remove task: :meth:`TaskTreeNode.remove` * Edit task code: :py:meth:`pybpodgui_plugin.models.task.task_dockwindow.TaskDockWindow.edit_btn_evt` :param event: key event """ modifiers = QApplication.keyboardModifiers() if event.key( ) == QtCore.Qt.Key_O and modifiers == QtCore.Qt.ControlModifier: self.edit_btn_evt() elif event.key() in [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return]: self.edit_btn_evt() elif event.key() == QtCore.Qt.Key_Delete: self.remove()
def select(self, points): # noinspection PyArgumentList if self.data is None: return keys = QApplication.keyboardModifiers() if self.selection is None or not keys & ( Qt.ShiftModifier + Qt.ControlModifier + Qt.AltModifier): self.selection = np.full(len(self.data), False, dtype=np.bool) indices = [p.data() for p in points] if keys & Qt.AltModifier: self.selection[indices] = False elif keys & Qt.ControlModifier: self.selection[indices] = ~self.selection[indices] else: # Handle shift and no modifiers self.selection[indices] = True self.update_colors(keep_colors=True) if self.label_only_selected: self.update_labels() self.master.selection_changed()
def select(self, points): # noinspection PyArgumentList if self.data is None: return keys = QApplication.keyboardModifiers() if self.selection is None or not keys & ( Qt.ShiftModifier + Qt.ControlModifier + Qt.AltModifier): self.selection = np.full(len(self.data), False, dtype=np.bool) indices = [p.data() for p in points] if keys & Qt.AltModifier: self.selection[indices] = False elif keys & Qt.ControlModifier: self.selection[indices] = ~self.selection[indices] else: # Handle shift and no modifiers self.selection[indices] = True self.update_colors(keep_colors=True) if self.label_only_selected: self.update_labels() self.master.selection_changed()
def _update_selection(self, p1: QPointF, p2: QPointF, finished: bool): # When finished, emit selection_changed. if len(self.__selection_rects) == 0: return assert self._max_item_width > 0 rect = QRectF(p1, p2).normalized() if self.__orientation == Qt.Vertical: min_max = rect.y(), rect.y() + rect.height() index = int( (p1.x() + self._max_item_width / 2) / self._max_item_width) else: min_max = rect.x(), rect.x() + rect.width() index = int( (-p1.y() + self._max_item_width / 2) / self._max_item_width) index = min(index, len(self.__selection_rects) - 1) index = self._sorted_group_indices[index] self.__selection_rects[index].selection_range = min_max if not finished: return mask = np.bitwise_and(self.__values >= min_max[0], self.__values <= min_max[1]) if self.__group_values is not None: mask = np.bitwise_and(mask, self.__group_values == index) selection = set(np.flatnonzero(mask)) keys = QApplication.keyboardModifiers() if keys & Qt.ShiftModifier: remove_mask = self.__group_values == index selection |= self.__selection - set(np.flatnonzero(remove_mask)) if self.__selection != selection: self.__selection = selection self.selection_changed.emit(sorted(self.__selection), self._selection_ranges)
def mousePressEvent(self, ev: QGraphicsSceneMouseEvent): keys = QApplication.keyboardModifiers() if self.__state == SELECT and not keys & Qt.ShiftModifier: ev.accept() self.sigDeselect.emit() super().mousePressEvent(ev)