def _get_choices(self, value, row): if self._previous_value and value.startswith(self._previous_value): return [(key, val) for key, val in self._previous_choices if normalize(key).startswith(normalize(value))] choices = self._suggestion_source.get_suggestions(value, row) duplicate_names = self._get_duplicate_names(choices) return self._format_choices(choices, value, duplicate_names)
def _variable_suggestions(self, controller, start, ctx): datafile = controller.datafile start_normalized = normalize(start) self._add_kw_arg_vars(controller, ctx.vars) vars = self._retriever.get_variables_from(datafile, ctx) return (v for v in vars if normalize(v.name).startswith(start_normalized))
def _get_duplicate_names(self, choices): results = set() normalized_names = [normalize(ch.name) for ch in choices] for choice in choices: normalized = normalize(choice.name) if normalized_names.count(normalized) > 1: results.add(normalized) return results
def _matches_unique_shortname(self, choice, prefix, duplicate_names): if isinstance(choice, VariableInfo): return True if not normalize(choice.name).startswith(normalize(prefix)): return False if normalize(choice.name) in duplicate_names: return False return True
def _get_choices(self, value, row): if self._previous_value and value.startswith(self._previous_value): return [(key, val) for key, val in self._previous_choices if normalize(key).startswith(normalize(value))] if self._controller and row: choices = self._controller.get_local_namespace_for_row(row).get_suggestions(value) else: choices = self._plugin.content_assist_values(value) # TODO: Remove old functionality when no more needed return self._format_choices(choices, value)
def find_attribute(obj, attr, prefix): attr = str(attr) for i_attr in dir(obj): normalized_i_attr = normalizing.normalize(i_attr, ignore='_') normalized_attr = normalizing.normalize(prefix + attr, ignore='_') if normalized_i_attr == normalized_attr: return getattr(obj, i_attr) try: attr = int(attr, 0) return attr except ValueError: raise RuntimeError('Attribute "%s" in "%s" not found.' % (attr, obj))
def _keyword_suggestions(self, datafile, start, ctx): start_normalized = normalize(start) return ( sug for sug in chain(self._get_default_keywords(), self._retriever.get_keywords_from(datafile, ctx)) if sug.name_begins_with(start_normalized) or sug.longname_begins_with(start_normalized))
def _keyword_suggestions(self, datafile, start, ctx): start_normalized = normalize(start) return (sug for sug in chain(self._get_default_keywords(), self._retriever.get_keywords_from(datafile, ctx)) if sug.name_begins_with(start_normalized) or sug.longname_begins_with(start_normalized))
def longname_begins_with(self, prefix): return normalize(self.longname).startswith(prefix)
def _format(self, choice, prefix): return choice.name if normalize(choice.name).startswith(normalize(prefix)) else choice.longname