def select(self, indexes, cursor=None, inverted=False, column_alias=None, *, _skip_event=False): if isinstance(indexes, int): indexes = [indexes] else: indexes = sorted(set(indexes)) if cursor is None: # Votr combines row-by-row selection into a single select() call to # be simpler to use, so we try to guess the final cursor position. # When it matters, it's better to specify it explicitly. if indexes: cursor = indexes[-1] elif self.cursor_row_index is not None and not inverted: cursor = self.cursor_row_index else: cursor = 0 if self.cell_selection_mode: if column_alias is None: # If a user turns on JAWS support mode in AIS user preferences, # all tables will be in cell selection mode. column_alias = self.selected_column_alias if len(indexes) != 1: raise AISBehaviorError( 'can\'t select multiple rows in cell selection mode') else: if column_alias is not None: raise AISBehaviorError( 'column selection not supported for this table') if inverted and not (self.multiple_selection and self.select_all_enabled): raise AISBehaviorError( 'inverted selection not supported for this table') if len(indexes) > 1 and not self.multiple_selection: raise AISBehaviorError( 'multiple selection not supported for this table') if self.always_selected and ( (not inverted and len(indexes) == 0) or (inverted and len(indexes) == len(self.loaded_rows))): raise AISBehaviorError( 'empty selection not supported for this table') self.log( 'action', 'Selecting {}{}{} {}{} in {}'.format( 'column {} of '.format(column_alias) if column_alias else '', 'inverted ' if inverted else '', 'rows' if len(indexes) > 1 else 'row', ', '.join(map(str, indexes)), ' with cursor at {}'.format(cursor) if indexes != [cursor] else '', self.id)) was_multiple_selection = len(self.selected_row_indexes) > 1 is_multiple_selection = len(indexes) > 1 active_index_changed = self.cursor_row_index != cursor selection_changed = (self.selected_row_indexes != indexes or self.inverted_selection != inverted or self.selected_column_alias != column_alias) self.selected_row_indexes = indexes self.cursor_row_index = cursor self.inverted_selection = inverted self.selected_column_alias = column_alias if was_multiple_selection != is_multiple_selection: self.dialog.try_interactive(self, "switchMultiple") if active_index_changed: self.active_index_changed = True self.dialog.component_changes(self, True) self._fire_action_command('ACTIVE_ROW_CHANGE') if selection_changed: self.selection_changed = True self.dialog.component_changes(self, True) if selection_changed and not _skip_event: evs = [] if self.edited_cells: if self.last_changed_row_index is not None: self.dialog.component_changes(self, False) if 'EDITED_ROW|' in self.supported_events: self.used_listeners_mask |= 64 evs.append( row_edited_event(self, 'EDITED_ROW', self.last_changed_row_index)) # This only emits a selection event for the final selected row (in # case of multiple selection). That is a bit unfortunate, but WebUI # already had this "problem" when Shift+selecting, so it should be # OK for Votr. You could always call select() many times if needed. evs.append(selection_event(self, cursor, cursor in indexes)) self.dialog.app.send_events(*evs)
def _fire_event(self): self.dialog.component_changes(self, False) ev = selection_event(self, self.selected_index) self.dialog.app.send_events(ev)
def select(self, indexes, cursor=None, inverted=False, column_alias=None, *, _skip_event=False): if isinstance(indexes, int): indexes = [indexes] else: indexes = sorted(set(indexes)) if cursor is None: # Votr combines row-by-row selection into a single select() call to # be simpler to use, so we try to guess the final cursor position. # When it matters, it's better to specify it explicitly. if indexes: cursor = indexes[-1] elif self.cursor_row_index is not None and not inverted: cursor = self.cursor_row_index else: cursor = 0 if self.cell_selection_mode: if column_alias is None: raise TypeError('column_alias is None') if len(indexes) != 1: raise ValueError('must specify exactly one row index') else: if column_alias is not None: raise TypeError('column_alias is not None') if inverted and not (self.multiple_selection and self.select_all_enabled): raise ValueError('inverted selection not supported for this table') if len(indexes) > 1 and not self.multiple_selection: raise ValueError('multiple selection not supported for this table') if self.always_selected and ((not inverted and len(indexes) == 0) or (inverted and len(indexes) == len(self.loaded_rows))): raise ValueError('empty selection not supported for this table') self.log('action', 'Selecting {}{}{} {}{} in {}'.format( 'column {} of '.format(column_alias) if column_alias else '', 'inverted ' if inverted else '', 'rows' if len(indexes) > 1 else 'row', ', '.join(map(str, indexes)), ' with cursor at {}'.format(cursor) if indexes != [cursor] else '', self.id)) was_multiple_selection = len(self.selected_row_indexes) > 1 is_multiple_selection = len(indexes) > 1 active_index_changed = self.cursor_row_index != cursor selection_changed = ( self.selected_row_indexes != indexes or self.inverted_selection != inverted or self.selected_column_alias != column_alias) self.selected_row_indexes = indexes self.cursor_row_index = cursor self.inverted_selection = inverted self.selected_column_alias = column_alias if was_multiple_selection != is_multiple_selection: self.dialog.try_interactive(self, "switchMultiple") if active_index_changed: self.active_index_changed = True self.dialog.component_changes(self, True) self._fire_action_command('ACTIVE_ROW_CHANGE') if selection_changed: self.selection_changed = True self.dialog.component_changes(self, True) if selection_changed and not _skip_event: evs = [] if self.edited_cells: if self.last_changed_row_index is not None: self.dialog.component_changes(self, False) if 'EDITED_ROW|' in self.supported_events: self.used_listeners_mask |= 64 evs.append(row_edited_event(self, 'EDITED_ROW', self.last_changed_row_index)) # This only emits a selection event for the final selected row (in # case of multiple selection). That is a bit unfortunate, but WebUI # already had this "problem" when Shift+selecting, so it should be # OK for Votr. You could always call select() many times if needed. evs.append(selection_event(self, cursor, cursor in indexes)) self.dialog.app.send_events(*evs)