本文整理汇总了Python中ninja_ide.core.settings.get_symbols_handler函数的典型用法代码示例。如果您正苦于以下问题:Python get_symbols_handler函数的具体用法?Python get_symbols_handler怎么用?Python get_symbols_handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_symbols_handler函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_symbols_for_class
def get_symbols_for_class(self, file_path, clazzName):
lines = []
with open(file_path) as f:
content = f.read()
ext = file_manager.get_file_extension(file_path)
#obtain a symbols handler for this file extension
symbols_handler = settings.get_symbols_handler(ext)
symbols = symbols_handler.obtain_symbols(content)
if "classes" in symbols:
for claz in symbols['classes']:
if claz != clazzName:
continue
clazz = symbols['classes'][claz]
#type - class name - file_path - lineNumber
lines.append(('<', claz, unicode(file_path),
clazz[0] - 1))
if 'attributes' in clazz[1]:
for attr in clazz[1]['attributes']:
#type - attribute name - file_path - lineNumber
lines.append(('-', attr, unicode(file_path),
clazz[1]['attributes'][attr] - 1))
if 'functions' in clazz[1]:
for func in clazz[1]['functions']:
#type - function name - file_path - lineNumber
lines.append(('>', func, unicode(file_path),
clazz[1]['functions'][func] - 1))
return lines
return []
示例2: update_explorer
def update_explorer(self):
"""Update the symbols in the Symbol Explorer when a file is saved."""
main_container = IDE.get_service('main_container')
if not main_container:
return
editorWidget = main_container.get_current_editor()
if editorWidget:
ext = file_manager.get_file_extension(editorWidget.ID)
#obtain a symbols handler for this file extension
symbols_handler = settings.get_symbols_handler(ext)
if symbols_handler:
source = editorWidget.toPlainText()
if editorWidget.encoding is not None:
source = source.encode(editorWidget.encoding)
if ext == 'py':
args = (source, True)
else:
args = (source,)
symbols = symbols_handler.obtain_symbols(*args)
self.update_symbols(symbols, editorWidget.ID)
#TODO: Should we change the code below similar to the code above?
exts = settings.SYNTAX.get('python')['extension']
if ext in exts or editorWidget.newDocument:
self.update_errors(editorWidget.errors, editorWidget.pep8)
示例3: get_symbols_for_class
def get_symbols_for_class(self, file_path, clazzName):
lines = []
with open(file_path) as f:
content = f.read()
ext = file_manager.get_file_extension(file_path)
#obtain a symbols handler for this file extension
symbols_handler = settings.get_symbols_handler(ext)
symbols = symbols_handler.obtain_symbols(content,
filename=file_path)
if "classes" in symbols:
for claz in symbols['classes']:
if claz != clazzName:
continue
clazz = symbols['classes'][claz]
line_number = clazz[0] - 1
lines.append(ResultItem(type=FILTERS['classes'], name=claz,
path=file_path, lineno=line_number))
if 'attributes' in clazz[1]:
for attr in clazz[1]['attributes']:
line_number = clazz[1]['attributes'][attr] - 1
lines.append(ResultItem(
type=FILTERS['attribs'], name=attr,
path=file_path, lineno=line_number))
if 'functions' in clazz[1]:
for func in clazz[1]['functions']:
line_number = clazz[1]['functions'][func][0] - 1
lines.append(ResultItem(type=FILTERS['functions'],
name=func, path=file_path,
lineno=line_number))
return lines
return []
示例4: _grep_file_locate
def _grep_file_locate(self, file_path, file_name):
#type - file_name - file_path
global mapping_locations
#TODO: Check if the last know state of the file is valid and load that
exts = settings.SYNTAX.get('python')['extension']
file_ext = file_manager.get_file_extension(file_path)
if file_ext not in exts:
mapping_locations[file_path] = [
ResultItem(type=FILTERS['non-python'], name=file_name,
path=file_path, lineno=0)]
else:
mapping_locations[file_path] = [
ResultItem(type=FILTERS['files'], name=file_name,
path=file_path, lineno=0)]
#obtain a symbols handler for this file extension
symbols_handler = settings.get_symbols_handler(file_ext)
if symbols_handler is None:
return
results = []
with open(file_path) as f:
content = f.read()
symbols = symbols_handler.obtain_symbols(content,
filename=file_path)
self.__parse_symbols(symbols, results, file_path)
if results:
mapping_locations[file_path] += results
示例5: _load_symbols
def _load_symbols(self, neditable):
symbols_handler = settings.get_symbols_handler('py')
source = neditable.editor.toPlainText()
source = source.encode(neditable.editor.encoding)
symbols = symbols_handler.get_symbols_simplified(source)
self._symbols_index = sorted(symbols.keys())
symbols = sorted(list(symbols.items()), key=lambda x: x[0])
self.bar.add_symbols(symbols)
line = neditable.editor.textCursor().blockNumber()
self._set_current_symbol(line, True)
示例6: _grep_file_locate
def _grep_file_locate(self, file_path, file_name):
#type - file_name - file_path
global mapping_locations
exts = settings.SYNTAX.get('python')['extension']
if file_manager.get_file_extension(unicode(file_name)) not in exts:
mapping_locations[unicode(file_path)] = [
ResultItem(type=FILTERS['non-python'], name=unicode(file_name),
path=unicode(file_path), lineno=0)]
else:
mapping_locations[unicode(file_path)] = [
ResultItem(type=FILTERS['files'], name=unicode(file_name),
path=unicode(file_path), lineno=0)]
ext = file_manager.get_file_extension(file_path)
#obtain a symbols handler for this file extension
symbols_handler = settings.get_symbols_handler(ext)
if symbols_handler is None:
return
results = []
with open(file_path) as f:
content = f.read()
symbols = symbols_handler.obtain_symbols(content,
filename=file_path)
if "classes" in symbols:
for claz in symbols['classes']:
line_number = symbols['classes'][claz][0] - 1
members = symbols['classes'][claz][1]
results.append(ResultItem(type=FILTERS['classes'],
name=claz, path=unicode(file_path),
lineno=line_number))
if 'attributes' in members:
for attr in members['attributes']:
line_number = members['attributes'][attr] - 1
results.append(ResultItem(type=FILTERS['attribs'],
name=attr, path=unicode(file_path),
lineno=line_number))
if 'functions' in members:
for func in members['functions']:
line_number = members['functions'][func] - 1
results.append(ResultItem(
type=FILTERS['functions'], name=func,
path=unicode(file_path), lineno=line_number))
if 'attributes' in symbols:
for attr in symbols['attributes']:
line_number = symbols['attributes'][attr] - 1
results.append(ResultItem(type=FILTERS['attribs'],
name=attr, path=unicode(file_path),
lineno=line_number))
if 'functions' in symbols:
for func in symbols['functions']:
line_number = symbols['functions'][func] - 1
results.append(ResultItem(
type=FILTERS['functions'], name=func,
path=unicode(file_path), lineno=line_number))
if results:
mapping_locations[unicode(file_path)] += results
示例7: get_symbols_for_class
def get_symbols_for_class(self, file_path, clazzName):
results = []
with open(file_path) as f:
content = f.read()
ext = file_manager.get_file_extension(file_path)
#obtain a symbols handler for this file extension
symbols_handler = settings.get_symbols_handler(ext)
symbols = symbols_handler.obtain_symbols(content,
filename=file_path)
self.__parse_symbols(symbols, results, file_path)
return results
示例8: _load_symbols
def _load_symbols(self, neditable):
symbols_handler = settings.get_symbols_handler('py')
source = neditable.editor.toPlainText()
source = source.encode(neditable.editor.encoding)
symbols, symbols_simplified = symbols_handler.obtain_symbols(
source, simple=True)
self._symbols_index = sorted(symbols_simplified.keys())
symbols_simplified = sorted(
list(symbols_simplified.items()), key=lambda x: x[0])
self.bar.add_symbols(symbols_simplified)
line = neditable.editor.textCursor().blockNumber()
self._set_current_symbol(line, True)
tree_symbols = IDE.get_service('symbols_explorer')
tree_symbols.update_symbols_tree(symbols, neditable.file_path)
示例9: update_explorer
def update_explorer(self):
editorWidget = self.ide.mainContainer.get_actual_editor()
if editorWidget:
ext = file_manager.get_file_extension(editorWidget.ID)
#obtain a symbols handler for this file extension
symbols_handler = settings.get_symbols_handler(ext)
if symbols_handler:
source = unicode(editorWidget.toPlainText())
symbols = symbols_handler.obtain_symbols(source)
self.ide.explorer.update_symbols(symbols, editorWidget.ID)
#TODO: Should we change the code below similar to the code above?
if ext == 'py' or editorWidget.newDocument:
self.ide.explorer.update_errors(
editorWidget.errors, editorWidget.pep8)
示例10: _grep_file_locate
def _grep_file_locate(self, file_path, file_name):
#type - file_name - file_path
global mapping_locations
if file_manager.get_file_extension(unicode(file_name)) != 'py':
mapping_locations[unicode(file_path)] = [('!',
unicode(file_name), unicode(file_path), 0)]
return
mapping_locations[unicode(file_path)] = [('@', unicode(file_name),
unicode(file_path), 0)]
lines = []
with open(file_path) as f:
content = f.read()
ext = file_manager.get_file_extension(file_path)
#obtain a symbols handler for this file extension
symbols_handler = settings.get_symbols_handler(ext)
symbols = symbols_handler.obtain_symbols(content)
if "classes" in symbols:
for claz in symbols['classes']:
clazz = symbols['classes'][claz]
#type - class name - file_path - lineNumber
lines.append(('<', claz, unicode(file_path),
clazz[0] - 1))
if 'attributes' in clazz[1]:
for attr in clazz[1]['attributes']:
#type - attribute name - file_path - lineNumber
lines.append(('-', attr, unicode(file_path),
clazz[1]['attributes'][attr] - 1))
if 'functions' in clazz[1]:
for func in clazz[1]['functions']:
#type - function name - file_path - lineNumber
lines.append(('>', func, unicode(file_path),
clazz[1]['functions'][func] - 1))
if 'attributes' in symbols:
for attr in symbols['attributes']:
#type - attribute name - file_path - lineNumber
lines.append(('-', attr, unicode(file_path),
symbols['attributes'][attr] - 1))
if 'functions' in symbols:
for func in symbols['functions']:
#type - function name - file_path - lineNumber
lines.append(('>', func, unicode(file_path),
symbols['functions'][func] - 1))
if lines:
mapping_locations[unicode(file_path)] += lines
示例11: update_explorer
def update_explorer(self):
"""Update the symbols in the Symbol Explorer when a file is saved."""
editorWidget = self.ide.mainContainer.get_actual_editor()
if editorWidget:
ext = file_manager.get_file_extension(editorWidget.ID)
#obtain a symbols handler for this file extension
symbols_handler = settings.get_symbols_handler(ext)
if symbols_handler:
source = unicode(editorWidget.toPlainText())
if editorWidget.encoding is not None:
source = source.encode(editorWidget.encoding)
symbols = symbols_handler.obtain_symbols(source)
self.ide.explorer.update_symbols(symbols, editorWidget.ID)
#TODO: Should we change the code below similar to the code above?
exts = settings.SYNTAX.get('python')['extension']
if ext in exts or editorWidget.newDocument:
self.ide.explorer.update_errors(
editorWidget.errors, editorWidget.pep8)