def _make_expression_completer(owner, data_type):
model = QStringListModel()
comp = QCompleter(owner)
comp.setCaseSensitivity(Qt.CaseSensitive)
if isinstance(data_type, str):
data_type = uavcan.TYPENAMES[data_type]
# TODO: implement proper completion, requires Python lexer
# TODO: IPython/Jupyter solves the same task splendidly, might make sense to take a closer look at their code
def make_suggestions(t):
"""Builds a flat list of fields in a given data type"""
if t.category == t.CATEGORY_COMPOUND:
out = []
for a in t.fields + t.constants:
if (a.type.category != a.type.CATEGORY_COMPOUND) and \
(a.type.category != a.type.CATEGORY_VOID) and \
(a.type.category != a.type.CATEGORY_ARRAY or
a.type.value_type.category == a.type.value_type.CATEGORY_PRIMITIVE):
out.append(a.name)
out += [(a.name + x) for x in make_suggestions(a.type)]
return [('.' + x) for x in out]
elif t.category == t.CATEGORY_ARRAY:
base = '[0]'
if t.value_type.category == t.CATEGORY_COMPOUND:
return [(base + x) for x in make_suggestions(t.value_type)]
else:
return [base]
return []
suggestions = [(EXPRESSION_VARIABLE_FOR_MESSAGE + x) for x in make_suggestions(data_type)]
model.setStringList(suggestions)
comp.setModel(model)
return comp
评论列表
文章目录