pyqode.core.panels

This package contains the core panels

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

Bases: pyqode.core.api.panel.Panel

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.

paintEvent(event)

Fills the panel background.

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

Bases: pyqode.core.api.panel.Panel

This panel displays the document outline and lets the user collapse or expand blocks of code.

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

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.

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)

Paints the fold indicators and the possible fold region background on the folding panel.

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
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)
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.

class pyqode.core.panels.LineNumberPanel

Bases: pyqode.core.api.panel.Panel

The liner number panel displays the document line numbers.

cancel_selection()

Cancel line selection.

leaveEvent(event)

Cancels selection

line_number_area_width()

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

Returns:Widtg
mouseMoveEvent(e)

Updates end of selection if we are currently selecting

mousePressEvent(e)

Starts selecting

mouseReleaseEvent(event)

Cancels selection

paintEvent(event)

Paints the line numbers

sizeHint()

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

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

Bases: pyqode.qt.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

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:

  • pyqode.core.panels.MarkerPanel.add_marker_requested
  • pyqode.core.panels.MarkerPanel.remove_marker_requested
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)

Requests a tooltip if the cursor is currently over a marker.

mousePressEvent(event)

Handle mouse press:

  • emit add marker signal if there were no marker under the mouse cursor
  • emit remove marker signal if there were one or more markers under the mouse cursor.
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)

class pyqode.core.panels.SearchAndReplacePanel

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

This panel allow the user to search and replace some text in the current editor.

It uses the QTextDocument API to search for some text. Search operation is performed in a background thread.

The search panel can also be used programatically.

To do that, the client code first requests a search using requestSearch() and connects to search_finished.

The results of the search can then be retrieved using cptOccurrences and getOccurrences().

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().

close_panel()

Closes the panel

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)
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.
background

Text decoration background

foreground

Text decoration foreground