The main parceqt module#

The Python parceqt module provides parce parsing and highlighting features for Qt’s QTextDocument.

This module depends on the parce module.

With a few simple function calls you can highlight the syntax of a QTextDocument using parce.

Besides the functions below, the following classes and values are also accessible in this module scope: Cursor, Document, Formatter, SyntaxHighlighter, version, version_string.

worker(doc)[source]#

Return the Worker responsible for tokenizing this QTextDocument.

If no Worker already existed, it is instantiated and becomes a child of the QTextDocument. You can connect to its signals to get notified of changes in the tokenized tree or transformed result.

root(doc, wait=False)[source]#

Get the root element of the tokenized tree of specified text document.

See for more information about the arguments the get_root() method of TreeBuilder.

set_root_lexicon(doc, lexicon)[source]#

Instatiate a Worker for the document if needed, and set its root lexicon.

root_lexicon(doc)[source]#

Return the currently active root lexicon for the QTextDocument.

highlight(doc, theme='default')[source]#

Set the highlighting Theme for the document.

Use a string value to select a Theme by name. Use None to disable highlighting, or use False to force the SyntaxHighlighter to quit.

Of course, highlighting becomes only visible when the document has a root_lexicon set.

adjust_widget(widget)[source]#

Convenience function to set palette and font of a text editing widget.

Sets the widget’s palette and font to the theme of its QTextDocument’s highlighter.

The widget must be a QPlainTextEdit, QTextEdit or QTextBrowser. If its document has not yet a theme set, this function does nothing.

Basically this is as simple as:

formatter = parceqt.Formatter(theme)
widget.setFont(formatter.font())
widget.setPalette(formatter.palette())

but this function is useful when you just set the theme once to a document and want to have its editing widget adjusted.

Also, when you stopped the highlighting, this function neatly switches the widget back to the default palette and font.

cursor(cursor)[source]#

Convenience function to return a Cursor with a Document that wraps a QTextDocument.

The specified cursor must be a QTextCursor. You can alter the document via the parce.Document API.