pyqode.python.modes

This package contains a series of python specific modes (calltips, autoindent, code linting,...).

class pyqode.python.modes.PyAutoCompleteMode

Bases: pyqode.core.modes.autocomplete.AutoCompleteMode

Extends pyqode.core.modes.AutoCompleteMode to add support for function docstring and method/function call.

Docstring completion adds a :param sphinx tag foreach parameter in the above function.

Function completion adds ”):” to function definition.

Method completion adds “self):” to method definition.

class pyqode.python.modes.PyAutoIndentMode

Bases: pyqode.core.modes.autoindent.AutoIndentMode

Customised pyqode.core.modes.AutoIndentMode for python that tries its best to follow the pep8 indentation guidelines.

at_block_end(tc, fullline)
at_block_start(tc, line)

Improve QTextCursor.atBlockStart to ignore spaces

between_paren(tc, col)
get_full_line(tc)
get_indent_of_opening_paren(tc, column)
get_last_open_paren_pos(tc, column)
get_last_word(tc)
get_next_char(tc)
get_parent_pos(tc, column)
handle_indent_after_paren(column, line, fullline, tc)

Handle indent between symbols such as parenthesis, braces,...

has_two_empty_line_before(tc)
has_unclosed_paren(tc)
is_in_comment(column, tc, full_line)
is_in_string_def(full_line, column)
is_paren_closed(paren)
is_paren_open(paren)
on_install(editor)
parens_count_for_block(col, block)
class pyqode.python.modes.CalltipsMode

Bases: pyqode.core.api.mode.Mode, pyqode.core.qt.QtCore.QObject

This mode shows function/method call tips in a QToolTip using jedi.Script.call_signatures().

on_state_changed(state)
tooltipDisplayRequested = <pyqode.core.qt.QtCore.Signal object at 0x7fdaac59fd30>
tooltipHideRequested = <pyqode.core.qt.QtCore.Signal object at 0x7fdaac59fd68>
class pyqode.python.modes.CommentsMode

Bases: pyqode.core.api.mode.Mode

Mode that allow to comment/uncomment a set of lines using Ctrl+/.

check_selection(cursor)
comment()

Comments/Uncomments the selected lines or the current lines if there is no selection.

on_key_pressed(key_event)
on_state_changed(state)

Called when the mode is activated/deactivated

class pyqode.python.modes.DocumentAnalyserMode(delay=1000)

Bases: pyqode.core.api.mode.Mode, pyqode.core.qt.QtCore.QObject

This mode analyses the structure of a document (a tree of pyqode.python.backend.workers.Definition.

pyqode.python.modes.DocumentAnalyserMode.document_changed is emitted whenever the document structure changed.

To keep good performances, the analysis task is run when the application is idle for more than 1 second (by default).

on_state_changed(state)
document_changed = <pyqode.core.qt.QtCore.Signal object at 0x7fdaac49e0f0>
flattened_results

Flattens the document structure tree as a simple sequential list.

class pyqode.python.modes.FrostedCheckerMode

Bases: pyqode.core.modes.checker.CheckerMode

This checker mode runs pyflakes on the fly to check your python syntax.

class pyqode.python.modes.Assignment(path, line, column, full_name)

Bases: builtins.object

Assignment definition.

class pyqode.python.modes.GoToAssignmentsMode

Bases: pyqode.core.api.mode.Mode, pyqode.core.qt.QtCore.QObject

Goes to the assignments (using jedi.Script.goto_assignments). If there are more than one assignments, an input dialog is used to ask the user to choose the desired assignment.

This mode will emit pyqode.python.modes.GoToAssignmentsMode.out_of_doc if the definition can not be reached in the current document. IDE will typically open a new editor tab and go to the definition.

on_state_changed(state)
request_goto(tc=None)

Request a go to assignment.

Parameters:tc (QtGui.QTextCursor) – Text cursor which contains the text that we must look for its assignment. Can be None to go to the text that is under the text cursor.
no_results_found = <pyqode.core.qt.QtCore.Signal object at 0x7fdaac49e780>
out_of_doc = <pyqode.core.qt.QtCore.Signal object at 0x7fdaac49e710>
class pyqode.python.modes.PyIndenterMode

Bases: pyqode.core.modes.indenter.IndenterMode

Implements python specific indentation, tab/back-tab always indents/unindents the whole line. This replace the default IndenterMode which we found to be better suited for python code editing.

indent()

Performs an indentation

unindent()

Performs an un-indentation

class pyqode.python.modes.PEP8CheckerMode

Bases: pyqode.core.modes.checker.CheckerMode

This checker mode runs pep8utils.py on the fly to check your python style.

class pyqode.python.modes.PyHighlighterMode(document=None)

Bases: pyqode.core.api.syntax_highlighter.SyntaxHighlighter

Syntax highlighter specifically crafted for the Python programming language.

Contrarily to pyqode.core.modes.PygmentsSyntaxHighlighter this syntax highlighter highlights multi-line comments and docstrings properly.

Its color scheme is entirely configurable through the properties exposed in pyqode.python.style

Note

To detect and remember multi-line strings/docstrings we use QtGui.QTextBlock.userState which is a bitmask combination that store two information:

  • the 7 first bits are used to store the following states:

    • 0: not a multi-line string/docstring
    • 1: start of multi-line string/docstring
    • 2: multi-line string/docstring
  • the 8th bit is used to make the difference between a docstring and a string which are highlighted with a different color.

highlight_block(text)
highlight_spaces(text)
highlight_sphinx_tags(text)
match_multiline(text)
on_install(editor)
on_state_changed(state)
refresh_style()
rehighlight(*args, **kwargs)
DEFAULT_DARK_STYLES
DEFAULT_LIGHT_STYLES
braces = ['\\{', '\\}', '\\(', '\\)', '\\[', '\\]']
builtins = ['__import__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'hex', 'id', 'as', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'list', 'locals', 'long', 'map', 'max', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'property', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip', 'None', 'Ellipsis', 'NotImplemented', 'False', 'True', 'ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'DeprecationWarning', 'EOFError', 'EnvironmentError', 'Exception', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'OverflowWarning', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'VMSError', 'Warning', 'WindowsError', 'ZeroDivisionError']
docstringTags = [':param', ':type', ':return', ':rtype', ':raise', ':except', '@param', '@type', '@return', '@rtype', '@raise', '@except', '.. note', '.. warning']
format = functools.partial(<bound method memoized.__call__ of Returns a QTextCharFormat from a style key. :param style_key: QColor or style key name. >, None)
format_from_word
keywords = ['and', 'assert', 'break', 'continue', 'def', 'class', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'yield', 'None', 'True', 'False', 'with']
operators = ['=', '==', '!=', '<', '<=', '>', '>=', '\\+', '-', '\\*', '/', '//', '\\%', '\\*\\*', '\\+=', '-=', '\\*=', '/=', '\\%=', '\\^', '\\|', '\\&', '\\~', '>>', '<<']
punctuations = ['\\:', '\\,', '\\.']