pyqode.core.panels package

Module content

This package contains the core panels

Classes

CheckerPanel

class pyqode.core.panels.CheckerPanel

Bases: pyqode.core.api.panel.Panel

Shows messages collected by one or more checker modes

leaveEvent(*args)

Hide tooltip when leaving the panel region.

marker_for_line(line)

Returns the marker that is displayed at the specified line number if any.

Parameters:line – The marker line.
Returns:Marker of None
Return type:pyqode.core.Marker
mouseMoveEvent(event)
paintEvent(event)
sizeHint()

Returns the panel size hint. (fixed with of 16px)

error_icon = None

Error icon

info_icon = None

Info icon

warning_icon = None

Warning icon

EncodingPanel

class pyqode.core.panels.EncodingPanel(add_context_menu=True)

Bases: pyqode.core.api.panel.Panel

Displays a warning when an encoding error occured and let you reload.

This panel display a warning in case encoding/decoding error and give the user the possibility to try out another encoding, to edit any way or to close the editor.

The panel is automatically shown by pyqode.core.managers.FileManager in case of error so that you don’t have to worry about encoding issues. The only think you might do is to provide to your user a way to specify the default encoding, i.e. the one that is tried before showing this panel.

The panel is a simple widget with a label describing the error, an encoding menu and 3 buttons: Retry, Edit anyway and Cancel. It is strongly inspired by the GEdit encoding panel.

You can change the background color and the label foreground color by setting up the color and foreground properties.

It’s up to the client code to handle cancel requests. To do that simply connect cancel_requested signal to remove the editor from your application.

cancel()
clone_settings(original)
enable_caret_line(value=True)
on_install(editor)
on_open_failed(path, encoding)
paintEvent(event)

Fills the panel background.

show()
cancel_requested

Signal emitted when the user pressed on cancel. It is up to the client code to handle this event.

color

Returns the panel color.

foreground

FoldingPanel

class pyqode.core.panels.FoldingPanel(highlight_caret_scope=False)

Bases: pyqode.core.api.panel.Panel

Displays the document outline and lets the user collapse/expand blocks.

The data represented by the panel come from the text block user state and is set by the SyntaxHighlighter mode.

The panel does not expose any function that you can use directly. To interact with the fold tree, you need to modify text block fold level or trigger state using pyqode.core.api.utils.TextBlockHelper or pyqode.core.api.folding

clone_settings(original)
collapse_all()

Collapses all triggers and makes all blocks with fold level > 0 invisible.

expand_all()

Expands all fold triggers.

static find_parent_scope(block)

Find parent scope, if the block is not a fold trigger.

static get_system_bck_color()

Gets a system color for drawing the fold scope background.

leaveEvent(event)

Removes scope decorations and background from the editor and the panel if highlight_caret_scope, else simply update the scope decorations to match the caret scope.

mouseMoveEvent(event)

Detect mouser over indicator and highlight the current scope in the editor (up and down decoration arround the foldable text when the mouse is over an indicator).

Parameters:event – event
mousePressEvent(event)

Folds/unfolds the pressed indicator if any.

on_install(editor)

Add the folding menu to the editor, on install.

Parameters:editor – editor instance on which the mode has been installed to.
on_state_changed(state)

On state changed we (dis)connect to the cursorPositionChanged signal

paintEvent(event)
refresh_decorations(force=False)

Refresh decorations colors. This function is called by the syntax highlighter when the style changed so that we may update our decorations colors according to the new style.

sizeHint()

Returns the widget size hint (based on the editor font size)

toggle_fold_trigger(block)

Toggle a fold trigger block (expand or collapse it).

Parameters:block – The QTextBlock to expand/collapse
collapse_all_triggered
custom_fold_region_background

Custom base color for the fold region background

Returns:QColor
custom_indicators_icons

Gets/sets the custom icon for the fold indicators.

The list of indicators is interpreted as follow:

(COLLAPSED_OFF, COLLAPSED_ON, EXPANDED_OFF, EXPANDED_ON)

To use this property you must first set native_look to False.

Returns:tuple(str, str, str, str)
expand_all_triggered
highlight_caret_scope

True to highlight the caret scope automatically.

(Similar to the Highlight blocks in Qt Creator.

Default is False.

native_look

Defines whether the panel will use native indicator icons and color or use custom one.

If you want to use custom indicator icons and color, you must first set this flag to False.

trigger_state_changed

signal emitted when a fold trigger state has changed, parameters are the concerned text block and the new state (collapsed or not).

LineNumberPanel

class pyqode.core.panels.LineNumberPanel

Bases: pyqode.core.api.panel.Panel

Displays the document line numbers.

cancel_selection()

Cancels line selection.

leaveEvent(event)
line_number_area_width()

Computes the lineNumber area width depending on the number of lines in the document

Returns:Widtg
mouseMoveEvent(e)
mousePressEvent(e)

Starts selecting

mouseReleaseEvent(event)
paintEvent(event)
sizeHint()

Returns the panel size hint (as the panel is on the left, we only need to compute the width

Marker

class pyqode.core.panels.Marker(position, icon='', description='', parent=None)

Bases: PyQt5.QtCore.QObject

A marker is an icon draw on a marker panel at a specific line position and with a possible tooltip.

description

Gets the marker description.

icon

Gets the icon file name. Read-only.

position

Gets the marker position (line number) :type: int

MarkerPanel

class pyqode.core.panels.MarkerPanel

Bases: pyqode.core.api.panel.Panel

General purpose marker panel. This panels takes care of drawing icons at a specific line number.

Use addMarker, removeMarker and clearMarkers to manage the collection of displayed makers.

You can create a user editable panel (e.g. a breakpoints panel) by using the following signals:

add_marker(marker)

Adds the marker to the panel.

Parameters:marker (pyqode.core.modes.Marker) – Marker to add
clear_markers()

Clears the markers list

leaveEvent(*args, **kwargs)

Hide tooltip when leaving the panel region.

marker_for_line(line)

Returns the marker that is displayed at the specified line number if any.

Parameters:line – The marker line.
Returns:Marker of None
Return type:pyqode.core.Marker
mouseMoveEvent(event)
mousePressEvent(event)
paintEvent(event)
remove_marker(marker)

Removes a marker from the panel

Parameters:marker (pyqode.core.Marker) – Marker to remove
sizeHint()

Returns the panel size hint. (fixed with of 16px)

add_marker_requested

Signal emitted when the user clicked in a place where there is no marker.

make_marker_icon

Decorator. Caches a function’s return value each time it is called. If called later with the same arguments, the cached value is returned (not reevaluated).

remove_marker_requested

Signal emitted when the user clicked on an existing marker.

SearchAndReplacePanel

class pyqode.core.panels.SearchAndReplacePanel

Bases: pyqode.core.api.panel.Panel, pyqode.core._forms.search_panel_ui.Ui_SearchPanel

Lets the user search and replace text in the current document.

It uses the backend API to search for some text. Search operation is performed in a background process (the backend process)..

The search panel can also be used programatically. To do that, the client code must first requests a search using requestSearch() and connects to search_finished. The results of the search can then be retrieved using cpt_occurences and get_oOccurrences(). The client code may now navigate through occurrences using select_next() or select_previous(), or replace the occurrences with a specific text using replace() or replace_all().

clone_settings(original)
close_panel()

Closes the panel

eventFilter(obj, event)
focusOutEvent(event)
get_occurences()

Returns the list of text occurrences.

An occurrence is a tuple that contains start and end positions.

Returns:List of tuple(int, int)
on_actionActionSearchAndReplace_triggered()
on_actionSearch_triggered()
on_install(editor)
on_state_changed(state)
on_toolButtonClose_clicked()
replace(text=None)

Replaces the selected occurrence.

Parameters:text – The replacement text. If it is None, the lineEditReplace’s text is used instead.
:return True if the text could be replace properly, False if there is
no more occurrences to replace.
replace_all(text=None)

Replaces all occurrences in the editor’s document.

Parameters:text – The replacement text. If None, the content of the lineEdit replace will be used instead

Requests a search operation.

Parameters:txt – The text to replace. If None, the content of lineEditSearch is used instead.
select_next()

Selects the next occurrence.

Returns:True in case of success, false if no occurrence could be selected.
select_previous()

Selects previous occurrence.

Returns:True in case of success, false if no occurrence could be selected.
STYLESHEET = 'SearchAndReplacePanel\n {\n background-color: %(bck)s;\n color: %(color)s;\n }\n\n QtoolButton\n {\n color: %(color)s;\n background-color: transparent;\n padding: 5px;\n min-height: 24px;\n min-width: 24px;\n border: none;\n }\n\n QtoolButton:hover\n {\n background-color: %(highlight)s;\n border: none;\n border-radius: 5px;\n color: %(color)s;\n }\n\n QtoolButton:pressed, QCheckBox:pressed\n {\n border: 1px solid %(bck)s;\n }\n\n QtoolButton:disabled\n {\n color: %(highlight)s;\n }\n\n QCheckBox\n {\n padding: 4px;\n color: %(color)s;\n }\n\n QCheckBox:hover\n {\n background-color: %(highlight)s;\n color: %(color)s;\n border-radius: 5px;\n }\n '
background

Text decoration background

cpt_occurences = None

Occurrences counter

foreground

Text decoration foreground

search_finished

Signal emitted when a search operation finished

GlobalCheckerPanel

class pyqode.core.panels.GlobalCheckerPanel

Bases: pyqode.core.api.panel.Panel

Displays all checker messages found in the document.

The user can click on a marker to quickly go the the error line.

get_marker_height()

Gets the height of message marker.

get_marker_size()

Gets the size of a message marker. :return: QSize

mousePressEvent(event)
paintEvent(event)

Pains the messages and the visible area on the panel. :param event: paint event infos

sizeHint()

The panel has a fixed width of 8 pixels.