Core¶
This page contains the documentation about pcef core classes
CodeEditorWidget¶
- class pcef.core.CodeEditorWidget(parent=None)[source]¶
Base class for the end user editor widgets.
CodeEditorWidget is a PySide.QtGui.QWidget made from a QT designer ui.
It embeds a pcef.code_edit.CodeEdit instance (using widget promotion from the designer) and four zones to add panels.
The editor behaviour and widgets can be enriched by installing modes and panels.
The base class itself does not install any modes or panels by itself. It does not add actions to the text edit context menu neither.
Subclasses defined in the editors module will take care of that.
You can also use the CodeEditorWidget directly and install the modes/panels/actions that you are interested in.
Note
There is a filename attribute defined. This field must be view as a tag object to share the filename to other modules that might need this information. This field is only set if you use the pcef.openFileInEditor()
- PANEL_ZONE_BOTTOM = 1¶
Bottom Panel zone id
- PANEL_ZONE_LEFT = 2¶
Left Panel zone id
- PANEL_ZONE_RIGHT = 3¶
Right Panel zone id
- PANEL_ZONE_TOP = 0¶
Top Panel zone id
- TAB_SIZE = 4¶
The default value used to for indentation. (All indentation modes should
- installMode(mode)[source]¶
Installs a mode on the widget.
Parameters: mode – Mode instance to install.
- installPanel(panel, zone)[source]¶
Installs a Panel on the widget.
Parameters: - panel – Panel instance to install
- zone – The zone where the Panel will be installed (CodeEditorWidget.PANEL_ZONE_XXX)
- mode(identifier)[source]¶
Returns the mode that match the identifier.
Parameters: identifier – Mode identifier Returns: Mode or None Return type: pcef.base.Mode or None
- panel(identifier)[source]¶
Returns the panel that match the identifier.
Parameters: identifier – Panel identifier Returns: Panel or None Return type: pcef.base.Panel or None
- ui = None¶
The designer ui (public so that user may access the internal ui (this might be useful for e.g. people who
CodeEdit¶
- class pcef.code_edit.CodeEdit(parent=None)[source]¶
The code editor text edit. This is a specialized QPlainTextEdit made to expose additional signals, styling and methods. It also provides a custom context menu and methods to add actions, separators and sub-menus.
Most of the code editor functionnalities are provided by installing modes on the PCEF instance.
- Additional signals:
- dirtyChanged(bool)
- focusedIn(QFocusEvent)
- keyPressed(QKeyEvent)
- keyReleased(QKeyEvent)
- mousePressed(QMouseEvent)
- mouseReleased(QMouseEvent)
- newTextSet()
- prePainting(QPaintEvent)
- postPainting(QPaintEvent)
- visibleBlocksChanged()
- addDecoration(decoration)[source]¶
Add a text decoration
Parameters: decoration (pcef.core.TextDecoration) – Text decoration
- dirty¶
Tells whether the editor is dirty(changes have been made to the document)
- dirtyChanged = <PySide.QtCore.Signal object at 0xab1f200>¶
Signal emitted when the dirty state of the document changed
- editor = None¶
Weakref to the editor
- fm = None¶
Shortcut to the fontMetrics
- focusedIn = <PySide.QtCore.Signal object at 0xab1f360>¶
Signal emitted when focusInEvent is is called
- fold(start, end, fold=True)[source]¶
Fold/Unfold a block of text delimitted by start/end line numbers :param start: Start folding line (this line is not fold, only the next ones) :param end: End folding line. :param fold: True to fold, False to unfold
- indent(size)[source]¶
Indent current line or selection
Parameters: size (int) – indent size in spaces
- keyPressEvent(event)[source]¶
Performs indentation if tab key presed, else emits the keyPressed signal
Parameters: event – QKeyEvent
- keyPressed = <PySide.QtCore.Signal object at 0xab1f220>¶
Signal emitted when a key is pressed
- keyReleaseEvent(event)[source]¶
Performs indentation if tab key pressed, else emits the keyPressed signal
Parameters: event – QKeyEvent
- keyReleased = <PySide.QtCore.Signal object at 0xab1f240>¶
Signal emitted when a key is released
- mousePressed = <PySide.QtCore.Signal object at 0xab1f260>¶
Signal emitted when a mouse button is pressed
- mouseReleased = <PySide.QtCore.Signal object at 0xab1f280>¶
Signal emitted when a mouse button is released
- mouseWheelActivated = <PySide.QtCore.Signal object at 0xab1f2a0>¶
Signal emitted on a wheel event
- newTextSet = <PySide.QtCore.Signal object at 0xab1f340>¶
Signal emitted when setPlainText is invoked
- paintEvent(event)[source]¶
Emits prePainting and postPainting signals
Parameters: event – QPaintEvent
- postKeyPressed = <PySide.QtCore.Signal object at 0xab1f300>¶
Signal emitted at the end of the keyPressed event
- postPainting = <PySide.QtCore.Signal object at 0xab1f2e0>¶
Signal emitted after painting the core widget
- prePainting = <PySide.QtCore.Signal object at 0xab1f2c0>¶
Signal emitted before painting the core widget
- removeDecoration(decoration)[source]¶
Remove text decoration.
Parameters: decoration (pcef.core.TextDecoration) – The decoration to remove
- setPlainText(txt)[source]¶
Sets the text edit content and emits newTextSet signal. :param txt: New text to display
- setShowWhitespaces(show)[source]¶
Shows/Hides whitespaces.
Parameters: show (bool) – True to show whitespaces, False to hide them
- tagEncoding = None¶
Tag member used to remeber the filename of the edited text if any
- tagFilename = None¶
Tag member used to remeber the filename of the edited text if any
- visibleBlocksChanged = <PySide.QtCore.Signal object at 0xab1f320>¶
Signal emitted when the list of visible blocks changed
EditorExtension¶
- class pcef.core.EditorExtension(name, description)[source]¶
Base class for editor extension. An extension is a “thing” that can be installed on the QCodeEditorWidget to add new behaviours.
An editor extension is a pcef.style.StyledObject as some extension might need to get access to the editor style and to update their brushes,...
An editor extension is also an object that can be enabled/disabled. Its provides an enable property that automatically call the abstract method onStateChanged.
- description = None¶
Extension description
- editor = None¶
Editor instance
- enabled¶
Tells whether the extension is enabled or not
- install(editor)[source]¶
Installs the extension on the editor.
Warning
For internal use only. User may needs to override this method to have a chance to connect to the editor signals.
Warning
Don’t forget to call super when subclassing
Parameters: editor (pcef.core.CodeEditorWidget) – editor widget instance
- name = None¶
Extension name
Mode¶
- class pcef.core.Mode(name, description)[source]¶
Base class for editor modes.
A mode is a pcef.core.EditorExtension that is is generally a non-visual element (not a QWidget).
Examples of modes are Code completion, syntax highlighting,...
To use a mode, one must install the mode on the editor widget.
Panel¶
- class pcef.core.Panel(name, description, parent)[source]¶
Base class for editor Panel widgets.
A Panel is a QWidget and pcef.core.EditorExtension that can be installed around the text edit widget.
Functions¶
- pcef.openFileInEditor(editor, filename, encoding='utf8', replaceTabsBySpaces=True)[source]¶
Open a file in an editor
Parameters: - editor – Editor instance where the file content will be displayed
- filename – Filename of the file to open
- encoding – Encoding to use to load the file
- replaceTabsBySpaces – True to replace tabs by spaces