pyqode.core.modes¶
This package contains the core modes.
- class pyqode.core.modes.AutoCompleteMode¶
Bases: pyqode.core.api.mode.Mode
Generic auto complete mode that automatically completes the following symbols:
- ” -> “
- ‘ -> ‘
- ( -> )
- [ -> ]
- { -> }
- class pyqode.core.modes.AutoIndentMode¶
Bases: pyqode.core.api.mode.Mode
Generic indenter mode that indents the text when the user press RETURN.
You can customize this mode by overriding pyqode.core.modes.AutoIndentMode._get_indent()
- class pyqode.core.modes.CaretLineHighlighterMode¶
Bases: pyqode.core.api.mode.Mode
This mode highlights the caret line (active line).
- on_state_changed(state)¶
On state changed we (dis)connect to the cursorPositionChanged signal
- refresh()¶
Updates the current line decoration
- background¶
Background color of the caret line. Default is to use a color slightly darker/lighter than the background color. You can override the automatic color by setting up this property
- class pyqode.core.modes.CaseConverterMode¶
Bases: pyqode.core.api.mode.Mode
Converts selected text to lower case or UPPER case.
- It does so by adding two new menu entries to the editor’s context menu:
- Convert to lower case: ctrl-u
- Convert to UPPER CASE: ctrl+shift+u
- to_lower(*args)¶
Converts selected text to lower
- to_upper(*args)¶
Converts selected text to upper
- class pyqode.core.modes.CheckerMode(worker, delay=500, show_tooltip=True)¶
Bases: pyqode.core.api.mode.Mode, pyqode.qt.QtCore.QObject
Performs a user defined code analysis job using the backend and display the results on the editor instance.
The user defined code analysis job is a simple function with the following signature:
def analysisProcess(data)
where data is the request data:
request_data = { 'code': self.editor.toPlainText(), 'path': self.editor.file.path, 'encoding': self.editor.file.encoding }
and the return value is a tuple made up of the following elements:
(description, status, line, [col], [icon], [color], [path])The background process is ran when the text changed and the ide is an idle state for a few seconds.
You can also request an analysis manually using pyqode.core.modes.CheckerMode.request_analysis()
Messages are displayed as text decorations on the editor. A checker panel will take care of display message icons next to each line.
- add_messages(messages)¶
Adds a message or a list of message.
Parameters: messages – A list of messages or a single message
- clear_messages()¶
Clears all messages.
- remove_message(message)¶
Removes a message.
Parameters: message – Message to remove
- request_analysis()¶
Requests an analysis.
- class pyqode.core.modes.CheckerMessage(description, status, line, col=None, icon=None, color=None, path=None)¶
Bases: builtins.object
Holds data for a message displayed by the pyqode.core.modes.CheckerMode.
- classmethod status_to_string(status)¶
Converts a message status to a string.
Parameters: status – Status to convert (p yqode.core.modes.CheckerMessages) Returns: The status string. Return type: str
- status_string¶
Returns the message status as a string.
Returns: The status string.
- class pyqode.core.modes.CheckerMessages¶
Bases: builtins.object
Enumerates the possible checker message types.
- class pyqode.core.modes.CodeCompletionMode¶
Bases: pyqode.core.api.mode.Mode, pyqode.qt.QtCore.QObject
This mode provides code completion system wich is extensible. It takes care of running the completion request in a background process using one or more completion provider(s).
To implement a code completion for a specific language, you only need to implement new pyqode.core.backend.workers.CodeCompletionWorker.Provider
The completion popup is shown the user press ctrl+space or automatically while the user is typing some code (this can be configured using a series of properties).
- request_completion()¶
Requests a code completion at the current cursor position.
- completion_prefix¶
Returns the current completion prefix
- class pyqode.core.modes.ExtendedSelectionMode¶
Bases: pyqode.core.api.mode.Mode
This mode adds extended selections capabilities to CodeEdit.
Extended selection is a feature that can be found in the Ulipad editor: https://code.google.com/p/ulipad
It consists in adding a few shortcuts and contextual action to do some smarter selections. This mode adds the following new kind of selections:
- word selection: select word under cursor
- extended word selection: select word under cursor including continuation characters such as ”.”.
- matched selection: select text inside quotes or parenthesis
- line selection: select the whole line
- select all: select entire document
Extended selection and matched selection can be performed by combining ctrl or alt with a double click (modifiers are configurable through extended_sel_modifier or matched_sel_modifier).
- class pyqode.core.modes.FileWatcherMode¶
Bases: pyqode.core.api.mode.Mode, pyqode.qt.QtCore.QObject
FileWatcher mode, check if the opened file has changed externally.
- on_state_changed(state)¶
Connects/Disconnects to the mouse_wheel_activated and key_pressed event
- auto_reload¶
Automatically reloads changed files
- class pyqode.core.modes.IndenterMode¶
Bases: pyqode.core.api.mode.Mode
Implements classic indentation/tabulation.
It inserts/removes tabulations (a series of spaces defined by the tabLength settings) at the cursor position if there is no selection, otherwise it fully indents/un-indents selected lines.
To trigger an indentation/un-indentation programatically, you must emit pyqode.core.api.CodeEdit.indent_requested or pyqode.core.api.CodeEdit.unindent_requested.
- indent()¶
Indents text at cursor position.
- indent_selection(cursor)¶
Indent selected text
Parameters: cursor – QTextCursor
- unindent()¶
Un-indents text at cursor position.
- unindent_selection(cursor)¶
Un-indents selected text
- class pyqode.core.modes.OccurrencesHighlighterMode¶
Bases: pyqode.core.api.mode.Mode
This mode highlights occurrences of word under the text text cursor.
The delay before searching for occurrences is configurable.
- background¶
Background or underline color (if underlined is True).
- delay¶
Delay before searching for occurrences. The timer is rearmed as soon as the cursor position changed.
- foreground¶
Foreground color of occurences, not used if underlined is True.
- underlined¶
True to use to underlined occurrences instead of changing the background. Default is True.
If this mode is ON, the foreground color is ignored, the background color is then used as the underline color.
- class pyqode.core.modes.PygmentsSH(document, lexer=None, color_scheme=None)¶
Bases: pyqode.core.api.syntax_highlighter.SyntaxHighlighter
This mode enable syntax highlighting using the pygments library. This is a generic syntax highlighter, it is slower than a native highlighter and does not do any code folding detection. Use it as a fallback for languages that do not have a native highlighter available. Check the other pyqode namespace packages to see what other languages are available (at the time of writing, only python has specialised support).
Warning
There are some issues with multi-line comments, they are not properly highlighted until a full re-highlight is triggered. The text is automatically re-highlighted on save.
- on_install(editor)¶
- set_lexer_from_filename(filename)¶
Change the lexer based on the filename (actually only the extension is needed)
Parameters: filename – Filename or extension
- set_lexer_from_mime_type(mime, **options)¶
Sets the pygments lexer from mime type.
- pygments_style¶
Gets/Sets the pygments style
- pyqode.core.modes.PygmentsSyntaxHighlighter¶
alias of PygmentsSH
- class pyqode.core.modes.RightMarginMode¶
Bases: pyqode.core.api.mode.Mode
Display a right margin at column 80 by default.
- on_state_changed(state)¶
Connects/Disconnects to the painted event of the editor
Parameters: state – Enable state
- color¶
Gets/sets the color of the margin
- position¶
Gets/sets the position of the margin
- class pyqode.core.modes.SmartBackSpaceMode¶
Bases: pyqode.core.api.mode.Mode
Improves backspace behaviour. When you press backspace and there are spaces on the left of the cursor, those spaces will be deleted (at most tab_len spaces). Basically this turns backspace into Shitf+Tab
- class pyqode.core.modes.SymbolMatcherMode¶
Bases: pyqode.core.api.mode.Mode
Do symbols matches highlighting (parenthesis, braces, ...).
Note
This mode requires the document to be filled with pyqode.core.api.TextBlockUserData, i.e. a pyqode.core.api.SyntaxHighlighter must be installed on the editor instance.
- do_symbols_matching()¶
Performs symbols matching.
- symbol_pos(cursor, character='(', symbol_type=0)¶
Find the corresponding symbol position (line, column).
- match_background¶
Background color of matching symbols.
- match_foreground¶
Foreground color of matching symbols.
- unmatch_background¶
Background color of non-matching symbols.
- unmatch_foreground¶
Foreground color of matching symbols.
- class pyqode.core.modes.WordClickMode¶
Bases: pyqode.core.api.mode.Mode, pyqode.qt.QtCore.QObject
This mode adds support for document word click.
It will highlight the click-able word when the user press control and move the mouse over a word.
Detecting whether a word is click-able is the responsability of the subclasses. You must override _check_word_cursor and call _select_word_cursor if this is a click-able word (this process might be asynchrone) otherwise _clear_selection.
pyqode.core.modes.WordClickMode.word_clicked is emitted when the word is clicked by the user (while keeping control pressed).
- on_state_changed(state)¶
Connects/disconnects slots to/from signals when the mode state changed.
- class pyqode.core.modes.ZoomMode¶
Bases: pyqode.core.api.mode.Mode
This mode make it possible to zoom in/out the editor view.
- Here are the controls:
- zoom out: ctrl+- or ctrl+mouse wheel backward
- zoom in: ctrl++ or ctrl+mouse wheel forward
- reset: ctrl + 0
- on_state_changed(state)¶
Connects/Disconnects to the mouse_wheel_activated and key_pressed event