4.41. umbra.ui.highlighters

highlighters.py

Platform:
Windows, Linux, Mac Os X.
Description:
Defines the Application highlighters classes.
Others:
Portions of the code from PyQtWiki: http://diotavelli.net/PyQtWiki/Python%20syntax%20highlighting

4.41.1. Module Attributes

umbra.ui.highlighters.LOGGER

4.41.2. Classes

class umbra.ui.highlighters.Rule(**kwargs)[source]

Bases: foundations.dataStructures.Structure

Defines a storage object for highlighters rule.

Initializes the class.

Parameters:**kwargs (dict) – pattern, format.
class umbra.ui.highlighters.FormatsTree(theme=None)[source]

Bases: object

Defines the formats tree object representing higlighters theme.

Initializes the class.

Parameters:theme (dict) – Theme.
rootNode[source]

Property for self.__rootNode attribute.

Returns:self.__rootNode.
Return type:AbstractCompositeNode
listFormats(node, path=(), formats=None)[source]

Lists the object formats in sorted order.

Parameters:
  • node (AbstractCompositeNode) – Root node to start listing the formats from.
  • path (tuple) – Walked paths.
  • formats (list) – Formats.
Returns:

Formats.

Return type:

list

getFormat(name)[source]

Returns the closest format or closest parent format associated to given name.

Parameters:name (unicode) – Format name.
Returns:Format.
Return type:QTextCharFormat
class umbra.ui.highlighters.AbstractHighlighter(parent=None)[source]

Bases: PyQt4.QtGui.QSyntaxHighlighter

Defines a QSyntaxHighlighter subclass used as a base for highlighters classes.

Initializes the class.

Parameters:parent (QObject) – Widget parent.
formats[source]

Property for self.__formats attribute.

Returns:self.__formats.
Return type:FormatsTree
rules[source]

Property for self.__rules attribute.

Returns:self.__rules.
Return type:tuple or list
highlightBlock(block)[source]

Reimplements the QSyntaxHighlighter.highlightBlock() method.

Parameters:block (QString) – Text block.
highlightText(text, start, end)[source]

Highlights given text.

Parameters:
  • text (QString) – Text.
  • start (int) – Text start index.
  • end (int) – Text end index.
Returns:

Method success.

Return type:

bool

class umbra.ui.highlighters.DefaultHighlighter(parent=None, rules=None, theme=None)[source]

Bases: umbra.ui.highlighters.AbstractHighlighter

Defines a AbstractHighlighter subclass providing syntax highlighting for documents.

Initializes the class.

Parameters:
  • parent (QObject) – Widget parent.
  • rules (tuple or list) – Rules.
  • theme (dict) – Theme.
theme[source]

Property for self.__theme attribute.

Returns:self.__theme.
Return type:dict
highlightBlock(block)[source]

Reimplements the AbstractHighlighter.highlightBlock() method.

Parameters:block (QString) – Text block.
highlightMultilineBlock(block, startPattern, endPattern, state, format)[source]

Highlights given multiline text block.

Parameters:
  • block (QString) – Text block.
  • pattern (QRegExp) – Start regex pattern.
  • pattern – End regex pattern.
  • format (QTextCharFormat) – Format.
  • state (int) – Block state.
Returns:

Current block matching state.

Return type:

bool