def _variable_suggestions(self, controller, start, ctx): #建议变量 datafile = controller.datafile start_normalized = utils.normalize(start) self._add_kw_arg_vars(controller, ctx.vars) variables = self._retriever.get_variables_from(datafile, ctx) return (v for v in variables if utils.normalize(v.name).startswith(start_normalized))
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 utils.normalize(key).startswith(utils.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 = utils.normalize(start) self._add_kw_arg_vars(controller, ctx.vars) variables = self._retriever.get_variables_from(datafile, ctx) return (v for v in variables if utils.normalize(v.name).startswith(start_normalized))
def _matches_unique_shortname(self, choice, prefix, duplicate_names): if isinstance(choice, VariableInfo): return True if not utils.normalize(choice.name).startswith(utils.normalize(prefix)): return False if utils.normalize(choice.name) in duplicate_names: return False return True
def _get_duplicate_names(self, choices): results = set() normalized_names = [utils.normalize(ch.name) for ch in choices] for choice in choices: normalized = utils.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 utils.normalize(choice.name).startswith( utils.normalize(prefix)): return False if utils.normalize(choice.name) in duplicate_names: return False return True
def highlight_matcher(value, content): if not value or not content: return False selection = normalize(value, ignore=['_']) if not selection: return False target = normalize(content, ignore=['_']) if not target: return False if selection == target: return True return _variable_matches(selection, target)
def _keyword_suggestions(self, datafile, start, ctx): start_normalized = utils.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 = utils.normalize(start) all_kws = chain(self._get_default_keywords(), self._retriever.get_keywords_from(datafile, ctx)) return (sug for sug in all_kws if sug.name_begins_with(start_normalized) or sug.longname_begins_with(start_normalized))
def select_user_keyword_node(self, uk): parent_node = self._get_datafile_node(uk.parent.parent) if not parent_node: return if not self.IsExpanded(parent_node): self._expand_and_render_children(parent_node) node = self._controller.find_node_with_label(parent_node, utils.normalize(uk.name)) if node != self.GetSelection(): self.SelectItem(node)
def longname_begins_with(self, prefix): return utils.normalize(self.longname).startswith(prefix)
def is_unique(gvar):#是否是唯一的 return utils.normalize(gvar.name) not in \ [utils.normalize(lvar.name) for lvar in local_variables]
def _contains(self, string, pattern): return utils.normalize(pattern) in utils.normalize(string)
def name_matches(self, pattern): normalized = utils.normalize(self._undecorate(pattern)) return utils.normalize(self.name[2:-1]).startswith(normalized)
def is_unique(gvar): return utils.normalize(gvar.name) not in \ [utils.normalize(lvar.name) for lvar in local_variables]
def name_begins_with(self, prefix): #名字以什么开始 return utils.normalize(self.name).startswith(prefix)
def __init__(self, initial=None, ignore=(), caseless=True, spaceless=True): self._data = {} self._keys = {} self._normalize = lambda s: utils.normalize(s, ignore, caseless, spaceless) super(utils.NormalizedDict)